Skip to content

Commit

Permalink
Updated XML per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarkov committed Jan 25, 2024
1 parent b0ef8c1 commit 97cff56
Show file tree
Hide file tree
Showing 16 changed files with 480 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ limitations under the License.
<item fieldId="3" name="StartTime" type="epoch_s" default="0" optional="false" isNullable="true"/>
<item fieldId="4" name="Duration" type="int16u" default="0" optional="false" isNullable="true"/>
<item fieldId="5" name="MessageText" type="char_string" length="256" optional="false"/>
<item fieldId="6" name="Responses" type="MessageResponseOptionStruct" array="true" optional="true"/>
<item fieldId="6" name="Responses" type="MessageResponseOptionStruct" array="true" length="4" optional="true"/>
</struct>

<struct name="MessageResponseOptionStruct">
Expand All @@ -77,13 +77,13 @@ limitations under the License.
<client tick="false" init="false">true</client>
<server tick="false" init="false">true</server>
<globalAttribute side="either" code="0xFFFD" value="3"/><!-- Revision -->
<attribute side="server" code="0x0000" define="MESSAGES_CLUSTER_MESSAGES" type="ARRAY" entryType="MessageStruct" writable="false" max="8" optional="false">Messages</attribute>
<attribute side="server" code="0x0000" define="LIST_MESSAGES" type="array" entryType="MessageStruct" length="8" writable="true" optional="false">Messages</attribute>
<attribute side="server" code="0x0001" define="MESSAGES_CLUSTER_ACTIVE_MESSAGES_IDS" type="ARRAY" entryType="octet_string" max="8" writable="false" optional="false">ActiveMessageIDs</attribute>
<command source="client" code="0x00" name="PresentMessagesRequest" isFabricScoped="true" optional="false">
<description>
Command for requesting messages be presented
</description>
<arg name="Messages" type="MessageStruct" array="true" optional="false"/>
<arg name="Messages" type="octet_string" array="true" optional="false"/>
</command>
<command source="client" code="0x01" name="CancelMessagesRequest" isFabricScoped="true" optional="false">
<description>
Expand Down
4 changes: 2 additions & 2 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -4437,7 +4437,7 @@ provisional cluster Messages = 151 {
nullable FutureMessagePreferenceEnum futureMessagesPreference = 3;
}

readonly attribute MessageStruct messages[] = 0;
attribute MessageStruct messages[] = 0;
readonly attribute octet_string activeMessageIDs[] = 1;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
Expand All @@ -4447,7 +4447,7 @@ provisional cluster Messages = 151 {
readonly attribute int16u clusterRevision = 65533;

request struct PresentMessagesRequestRequest {
MessageStruct messages[] = 0;
octet_string messages[] = 0;
}

request struct CancelMessagesRequestRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29208,16 +29208,16 @@ public long initWithDevice(long devicePtr, int endpointId) {
return 0L;
}

public void presentMessagesRequest(DefaultClusterCallback callback, ArrayList<ChipStructs.MessagesClusterMessageStruct> messages) {
public void presentMessagesRequest(DefaultClusterCallback callback, ArrayList<byte[]> messages) {
presentMessagesRequest(callback, messages, 0);
}

public void presentMessagesRequest(DefaultClusterCallback callback, ArrayList<ChipStructs.MessagesClusterMessageStruct> messages, int timedInvokeTimeoutMs) {
public void presentMessagesRequest(DefaultClusterCallback callback, ArrayList<byte[]> messages, int timedInvokeTimeoutMs) {
final long commandId = 0L;

ArrayList<StructElement> elements = new ArrayList<>();
final long messagesFieldID = 0L;
BaseTLVType messagestlvValue = ArrayType.generateArrayType(messages, (elementmessages) -> elementmessages.encodeTlv());
BaseTLVType messagestlvValue = ArrayType.generateArrayType(messages, (elementmessages) -> new ByteArrayType(elementmessages));
elements.add(new StructElement(messagesFieldID, messagestlvValue));

StructType value = new StructType(elements);
Expand Down Expand Up @@ -29290,6 +29290,15 @@ public void onSuccess(byte[] tlv) {
}, MESSAGES_ATTRIBUTE_ID, isFabricFiltered);
}

public void writeMessagesAttribute(DefaultClusterCallback callback, ArrayList<ChipStructs.MessagesClusterMessageStruct> value) {
writeMessagesAttribute(callback, value, 0);
}

public void writeMessagesAttribute(DefaultClusterCallback callback, ArrayList<ChipStructs.MessagesClusterMessageStruct> value, int timedWriteTimeoutMs) {
BaseTLVType tlvValue = ArrayType.generateArrayType(value, (elementvalue) -> elementvalue.encodeTlv());
writeAttribute(new WriteAttributesCallbackImpl(callback), MESSAGES_ATTRIBUTE_ID, tlvValue, timedWriteTimeoutMs);
}

public void subscribeMessagesAttribute(
MessagesAttributeCallback callback, int minInterval, int maxInterval) {
ChipAttributePath path = ChipAttributePath.newInstance(endpointId, clusterId, MESSAGES_ATTRIBUTE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23725,11 +23725,13 @@ public Map<String, Map<String, InteractionInfo>> getCommandMap() {

Map<String, CommandParameterInfo> messagespresentMessagesRequestCommandParams = new LinkedHashMap<String, CommandParameterInfo>();

CommandParameterInfo messagespresentMessagesRequestmessagesCommandParameterInfo = new CommandParameterInfo("messages", ArrayList.class, ArrayList.class);
messagespresentMessagesRequestCommandParams.put("messages",messagespresentMessagesRequestmessagesCommandParameterInfo);
InteractionInfo messagespresentMessagesRequestInteractionInfo = new InteractionInfo(
(cluster, callback, commandArguments) -> {
((ChipClusters.MessagesCluster) cluster)
.presentMessagesRequest((DefaultClusterCallback) callback
, (ArrayList<ChipStructs.MessagesClusterMessageStruct>)
, (ArrayList<byte[]>)
commandArguments.get("messages")
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import matter.controller.SubscribeRequest
import matter.controller.SubscriptionState
import matter.controller.UIntSubscriptionState
import matter.controller.UShortSubscriptionState
import matter.controller.WriteRequest
import matter.controller.WriteRequests
import matter.controller.WriteResponse
import matter.controller.cluster.structs.*
import matter.controller.model.AttributePath
import matter.controller.model.CommandPath
Expand Down Expand Up @@ -102,7 +105,7 @@ class MessagesCluster(private val controller: MatterController, private val endp
}

suspend fun presentMessagesRequest(
messages: List<MessagesClusterMessageStruct>,
messages: List<ByteArray>,
timedInvokeTimeout: Duration? = null
) {
val commandId: UInt = 0u
Expand All @@ -113,7 +116,7 @@ class MessagesCluster(private val controller: MatterController, private val endp
val TAG_MESSAGES_REQ: Int = 0
tlvWriter.startArray(ContextSpecificTag(TAG_MESSAGES_REQ))
for (item in messages.iterator()) {
item.toTlv(AnonymousTag, tlvWriter)
tlvWriter.put(AnonymousTag, item)
}
tlvWriter.endArray()
tlvWriter.endStructure()
Expand Down Expand Up @@ -195,6 +198,53 @@ class MessagesCluster(private val controller: MatterController, private val endp
return MessagesAttribute(decodedValue)
}

suspend fun writeMessagesAttribute(
value: List<MessagesClusterMessageStruct>,
timedWriteTimeout: Duration? = null
) {
val ATTRIBUTE_ID: UInt = 0u

val tlvWriter = TlvWriter()
tlvWriter.startArray(AnonymousTag)
for (item in value.iterator()) {
item.toTlv(AnonymousTag, tlvWriter)
}
tlvWriter.endArray()

val writeRequests: WriteRequests =
WriteRequests(
requests =
listOf(
WriteRequest(
attributePath =
AttributePath(endpointId, clusterId = CLUSTER_ID, attributeId = ATTRIBUTE_ID),
tlvPayload = tlvWriter.getEncoded()
)
),
timedRequest = timedWriteTimeout
)

val response: WriteResponse = controller.write(writeRequests)

when (response) {
is WriteResponse.Success -> {
logger.log(Level.FINE, "Write command succeeded")
}
is WriteResponse.PartialWriteFailure -> {
val aggregatedErrorMessage =
response.failures.joinToString("\n") { failure ->
"Error at ${failure.attributePath}: ${failure.ex.message}"
}

response.failures.forEach { failure ->
logger.log(Level.WARNING, "Error at ${failure.attributePath}: ${failure.ex.message}")
}

throw IllegalStateException("Write command failed with errors: \n$aggregatedErrorMessage")
}
}
}

suspend fun subscribeMessagesAttribute(
minInterval: Int,
maxInterval: Int
Expand Down
Loading

0 comments on commit 97cff56

Please sign in to comment.