Skip to content

Commit

Permalink
Update per comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarkov committed Jan 25, 2024
1 parent e14a44c commit 486327b
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 195 deletions.
13 changes: 6 additions & 7 deletions src/app/zap-templates/zcl/data-model/chip/messages-cluster.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,18 @@ limitations under the License.
</command>
<event side="server" code="0x00" name="MessageQueued" priority="info" optional="false">
<description>This event SHALL be generated when the message is confirmed by the user, or when the expiration date of the message is reached.</description>
<field id="0" name="MessageID" type="octet_string"/>
<field id="0" name="MessageID" type="octet_string" length="16"/>
</event>
<event side="server" code="0x01" name="MessagePresented" priority="info" optional="false">
<description>This event SHALL be generated when the message is presented to the user.</description>
<field id="0" name="MessageID" type="octet_string"/>
<field id="0" name="MessageID" type="octet_string" length="16"/>
</event>
<event side="server" code="0x02" name="MessageComplete" priority="info" optional="false">
<description>This event SHALL be generated when the message is confirmed by the user, or when the expiration date of the message is reached.</description>
<field id="0" name="MessageID" type="octet_string"/>
<field id="2" name="Timestamp" type="epoch_s"/>
<field id="3" name="ResponseID" type="int32u" isNullable="true"/>
<field id="4" name="Reply" type="long_char_string" length="256" isNullable="true"/>
<field id="5" name="FutureMessagesPref" type="FutureMessagePreferenceEnum" isNullable="true"/>
<field id="0" name="MessageID" type="octet_string" optional="false"/>
<field id="1" name="ResponseID" type="int32u" isNullable="true" optional="true"/>
<field id="2" name="Reply" type="char_string" length="256" isNullable="true" optional="true"/>
<field id="3" name="FutureMessagesPreference" type="FutureMessagePreferenceEnum" isNullable="true" optional="false"/>
</event>
</cluster>
</configurator>
7 changes: 3 additions & 4 deletions src/controller/data_model/controller-clusters.matter
Original file line number Diff line number Diff line change
Expand Up @@ -4432,10 +4432,9 @@ provisional cluster Messages = 151 {

info event MessageComplete = 2 {
octet_string messageID = 0;
epoch_s timestamp = 2;
nullable int32u responseID = 3;
nullable long_char_string reply = 4;
nullable FutureMessagePreferenceEnum futureMessagesPref = 5;
optional nullable int32u responseID = 1;
optional nullable char_string reply = 2;
nullable FutureMessagePreferenceEnum futureMessagesPreference = 3;
}

readonly attribute MessageStruct messages[] = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3854,37 +3854,32 @@ public String toString() {
}
public static class MessagesClusterMessageCompleteEvent {
public byte[] messageID;
public Long timestamp;
public @Nullable Long responseID;
public @Nullable String reply;
public @Nullable Integer futureMessagesPref;
public @Nullable Optional<Long> responseID;
public @Nullable Optional<String> reply;
public @Nullable Integer futureMessagesPreference;
private static final long MESSAGE_I_D_ID = 0L;
private static final long TIMESTAMP_ID = 2L;
private static final long RESPONSE_I_D_ID = 3L;
private static final long REPLY_ID = 4L;
private static final long FUTURE_MESSAGES_PREF_ID = 5L;
private static final long RESPONSE_I_D_ID = 1L;
private static final long REPLY_ID = 2L;
private static final long FUTURE_MESSAGES_PREFERENCE_ID = 3L;

public MessagesClusterMessageCompleteEvent(
byte[] messageID,
Long timestamp,
@Nullable Long responseID,
@Nullable String reply,
@Nullable Integer futureMessagesPref
@Nullable Optional<Long> responseID,
@Nullable Optional<String> reply,
@Nullable Integer futureMessagesPreference
) {
this.messageID = messageID;
this.timestamp = timestamp;
this.responseID = responseID;
this.reply = reply;
this.futureMessagesPref = futureMessagesPref;
this.futureMessagesPreference = futureMessagesPreference;
}

public StructType encodeTlv() {
ArrayList<StructElement> values = new ArrayList<>();
values.add(new StructElement(MESSAGE_I_D_ID, new ByteArrayType(messageID)));
values.add(new StructElement(TIMESTAMP_ID, new UIntType(timestamp)));
values.add(new StructElement(RESPONSE_I_D_ID, responseID != null ? new UIntType(responseID) : new NullType()));
values.add(new StructElement(REPLY_ID, reply != null ? new StringType(reply) : new NullType()));
values.add(new StructElement(FUTURE_MESSAGES_PREF_ID, futureMessagesPref != null ? new UIntType(futureMessagesPref) : new NullType()));
values.add(new StructElement(RESPONSE_I_D_ID, responseID != null ? responseID.<BaseTLVType>map((nonOptionalresponseID) -> new UIntType(nonOptionalresponseID)).orElse(new EmptyType()) : new NullType()));
values.add(new StructElement(REPLY_ID, reply != null ? reply.<BaseTLVType>map((nonOptionalreply) -> new StringType(nonOptionalreply)).orElse(new EmptyType()) : new NullType()));
values.add(new StructElement(FUTURE_MESSAGES_PREFERENCE_ID, futureMessagesPreference != null ? new UIntType(futureMessagesPreference) : new NullType()));

return new StructType(values);
}
Expand All @@ -3894,44 +3889,37 @@ public static MessagesClusterMessageCompleteEvent decodeTlv(BaseTLVType tlvValue
return null;
}
byte[] messageID = null;
Long timestamp = null;
@Nullable Long responseID = null;
@Nullable String reply = null;
@Nullable Integer futureMessagesPref = null;
@Nullable Optional<Long> responseID = null;
@Nullable Optional<String> reply = null;
@Nullable Integer futureMessagesPreference = null;
for (StructElement element: ((StructType)tlvValue).value()) {
if (element.contextTagNum() == MESSAGE_I_D_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.ByteArray) {
ByteArrayType castingValue = element.value(ByteArrayType.class);
messageID = castingValue.value(byte[].class);
}
} else if (element.contextTagNum() == TIMESTAMP_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
timestamp = castingValue.value(Long.class);
}
} else if (element.contextTagNum() == RESPONSE_I_D_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
responseID = castingValue.value(Long.class);
responseID = Optional.of(castingValue.value(Long.class));
}
} else if (element.contextTagNum() == REPLY_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.String) {
StringType castingValue = element.value(StringType.class);
reply = castingValue.value(String.class);
reply = Optional.of(castingValue.value(String.class));
}
} else if (element.contextTagNum() == FUTURE_MESSAGES_PREF_ID) {
} else if (element.contextTagNum() == FUTURE_MESSAGES_PREFERENCE_ID) {
if (element.value(BaseTLVType.class).type() == TLVType.UInt) {
UIntType castingValue = element.value(UIntType.class);
futureMessagesPref = castingValue.value(Integer.class);
futureMessagesPreference = castingValue.value(Integer.class);
}
}
}
return new MessagesClusterMessageCompleteEvent(
messageID,
timestamp,
responseID,
reply,
futureMessagesPref
futureMessagesPreference
);
}

Expand All @@ -3942,17 +3930,14 @@ public String toString() {
output.append("\tmessageID: ");
output.append(Arrays.toString(messageID));
output.append("\n");
output.append("\ttimestamp: ");
output.append(timestamp);
output.append("\n");
output.append("\tresponseID: ");
output.append(responseID);
output.append("\n");
output.append("\treply: ");
output.append(reply);
output.append("\n");
output.append("\tfutureMessagesPref: ");
output.append(futureMessagesPref);
output.append("\tfutureMessagesPreference: ");
output.append(futureMessagesPreference);
output.append("\n");
output.append("}\n");
return output.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,93 +17,102 @@
package chip.devicecontroller.cluster.eventstructs

import chip.devicecontroller.cluster.*
import java.util.Optional
import matter.tlv.ContextSpecificTag
import matter.tlv.Tag
import matter.tlv.TlvReader
import matter.tlv.TlvWriter

class MessagesClusterMessageCompleteEvent(
val messageID: ByteArray,
val timestamp: ULong,
val responseID: ULong?,
val reply: String?,
val futureMessagesPref: UInt?
val responseID: Optional<ULong>?,
val reply: Optional<String>?,
val futureMessagesPreference: UInt?
) {
override fun toString(): String = buildString {
append("MessagesClusterMessageCompleteEvent {\n")
append("\tmessageID : $messageID\n")
append("\ttimestamp : $timestamp\n")
append("\tresponseID : $responseID\n")
append("\treply : $reply\n")
append("\tfutureMessagesPref : $futureMessagesPref\n")
append("\tfutureMessagesPreference : $futureMessagesPreference\n")
append("}\n")
}

fun toTlv(tlvTag: Tag, tlvWriter: TlvWriter) {
tlvWriter.apply {
startStructure(tlvTag)
put(ContextSpecificTag(TAG_MESSAGE_I_D), messageID)
put(ContextSpecificTag(TAG_TIMESTAMP), timestamp)
if (responseID != null) {
put(ContextSpecificTag(TAG_RESPONSE_I_D), responseID)
if (responseID.isPresent) {
val optresponseID = responseID.get()
put(ContextSpecificTag(TAG_RESPONSE_I_D), optresponseID)
}
} else {
putNull(ContextSpecificTag(TAG_RESPONSE_I_D))
}
if (reply != null) {
put(ContextSpecificTag(TAG_REPLY), reply)
if (reply.isPresent) {
val optreply = reply.get()
put(ContextSpecificTag(TAG_REPLY), optreply)
}
} else {
putNull(ContextSpecificTag(TAG_REPLY))
}
if (futureMessagesPref != null) {
put(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREF), futureMessagesPref)
if (futureMessagesPreference != null) {
put(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE), futureMessagesPreference)
} else {
putNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREF))
putNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE))
}
endStructure()
}
}

companion object {
private const val TAG_MESSAGE_I_D = 0
private const val TAG_TIMESTAMP = 2
private const val TAG_RESPONSE_I_D = 3
private const val TAG_REPLY = 4
private const val TAG_FUTURE_MESSAGES_PREF = 5
private const val TAG_RESPONSE_I_D = 1
private const val TAG_REPLY = 2
private const val TAG_FUTURE_MESSAGES_PREFERENCE = 3

fun fromTlv(tlvTag: Tag, tlvReader: TlvReader): MessagesClusterMessageCompleteEvent {
tlvReader.enterStructure(tlvTag)
val messageID = tlvReader.getByteArray(ContextSpecificTag(TAG_MESSAGE_I_D))
val timestamp = tlvReader.getULong(ContextSpecificTag(TAG_TIMESTAMP))
val responseID =
if (!tlvReader.isNull()) {
tlvReader.getULong(ContextSpecificTag(TAG_RESPONSE_I_D))
if (tlvReader.isNextTag(ContextSpecificTag(TAG_RESPONSE_I_D))) {
Optional.of(tlvReader.getULong(ContextSpecificTag(TAG_RESPONSE_I_D)))
} else {
Optional.empty()
}
} else {
tlvReader.getNull(ContextSpecificTag(TAG_RESPONSE_I_D))
null
}
val reply =
if (!tlvReader.isNull()) {
tlvReader.getString(ContextSpecificTag(TAG_REPLY))
if (tlvReader.isNextTag(ContextSpecificTag(TAG_REPLY))) {
Optional.of(tlvReader.getString(ContextSpecificTag(TAG_REPLY)))
} else {
Optional.empty()
}
} else {
tlvReader.getNull(ContextSpecificTag(TAG_REPLY))
null
}
val futureMessagesPref =
val futureMessagesPreference =
if (!tlvReader.isNull()) {
tlvReader.getUInt(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREF))
tlvReader.getUInt(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE))
} else {
tlvReader.getNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREF))
tlvReader.getNull(ContextSpecificTag(TAG_FUTURE_MESSAGES_PREFERENCE))
null
}

tlvReader.exitContainer()

return MessagesClusterMessageCompleteEvent(
messageID,
timestamp,
responseID,
reply,
futureMessagesPref
futureMessagesPreference
)
}
}
Expand Down
Loading

0 comments on commit 486327b

Please sign in to comment.