Skip to content

Commit

Permalink
[text decode] Fix event decoding and add unit tests. (#28376)
Browse files Browse the repository at this point in the history
* Fix id for event report decoding

* Add unit tests for event decoding

* Restyled by clang-format

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed Feb 12, 2024
1 parent 05fa8ed commit 1109108
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/format/protocol_messages.matter
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ client cluster IMProtocol = 0xFFFF0001 {
int64u delta_system_timestamp = 6;
// }

cluster_event_payload data = 2;
cluster_event_payload data = 7;
}

struct EventReportIB {
Expand Down
37 changes: 37 additions & 0 deletions src/lib/format/tests/TestDecoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,43 @@ void TestFullDataDecoding(nlTestSuite * inSuite, void * inContext)
" Channel::ChangeChannel\n"
" match: \"channel name\"\n"
" interaction_model_revison: 1\n");

TestSampleData(inSuite, params, im_protocol_event_software_fault,
"report_data\n"
" event_reports\n"
" Anonymous<>\n"
" event_data\n"
" path\n"
" endpoint_id: 0\n"
" cluster_id: 52 == 'SoftwareDiagnostics'\n"
" event_id: 0 == 'SoftwareFault'\n"
" event_number: 196610\n"
" priority: 1\n"
" epoch_timestamp: 1690566548210\n"
" SoftwareDiagnostics::SoftwareFault\n"
" id: 2454952\n"
" name: \"2454952\"\n"
" faultRecording: hex:467269204A756C2032382031333A34393A30382032303233\n"
" suppress_response: true\n"
" interaction_model_revison: 1\n");

TestSampleData(inSuite, params, im_protocol_event_multipress,
"report_data\n"
" event_reports\n"
" Anonymous<>\n"
" event_data\n"
" path\n"
" endpoint_id: 0\n"
" cluster_id: 59 == 'Switch'\n"
" event_id: 6 == 'MultiPressComplete'\n"
" event_number: 196611\n"
" priority: 1\n"
" epoch_timestamp: 1690566820898\n"
" Switch::MultiPressComplete\n"
" previousPosition: 1\n"
" totalNumberOfPressesCounted: 23\n"
" suppress_response: true\n"
" interaction_model_revison: 1\n");
}

void TestMetaDataOnlyDecoding(nlTestSuite * inSuite, void * inContext)
Expand Down
23 changes: 23 additions & 0 deletions src/lib/format/tests/sample_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ const uint8_t payload_1_8_change_channel[] = { 0x15, 0x28, 0x00, 0x28, 0x01, 0x3
0x00, 0x0C, 0x63, 0x68, 0x61, 0x6E, 0x6E, 0x65, 0x6C, 0x20, 0x6E, 0x61,
0x6D, 0x65, 0x18, 0x18, 0x18, 0x24, 0xFF, 0x01, 0x18 };

// Software fault event:
// id: 2454952, name: "2454952", faultRecording: "467269204A756C2032382031333A34393A30382032303233"
const uint8_t payload_1_5_software_fault_event[] = {
0x15, 0x36, 0x02, 0x15, 0x35, 0x01, 0x37, 0x00, 0x24, 0x01, 0x00, 0x24, 0x02, 0x34, 0x24, 0x03, 0x00, 0x18, 0x26,
0x01, 0x02, 0x00, 0x03, 0x00, 0x24, 0x02, 0x01, 0x27, 0x03, 0xF2, 0x5A, 0x9E, 0x9D, 0x89, 0x01, 0x00, 0x00, 0x35,
0x07, 0x26, 0x00, 0xA8, 0x75, 0x25, 0x00, 0x2C, 0x01, 0x07, 0x32, 0x34, 0x35, 0x34, 0x39, 0x35, 0x32, 0x30, 0x02,
0x18, 0x46, 0x72, 0x69, 0x20, 0x4A, 0x75, 0x6C, 0x20, 0x32, 0x38, 0x20, 0x31, 0x33, 0x3A, 0x34, 0x39, 0x3A, 0x30,
0x38, 0x20, 0x32, 0x30, 0x32, 0x33, 0x18, 0x18, 0x18, 0x18, 0x29, 0x04, 0x24, 0xFF, 0x01, 0x18
};

// A multipress complete event
// previousPosition: 1, totalNumberOfPressesCounted: 23
const uint8_t payload_1_5_multipress_event[] = { 0x15, 0x36, 0x02, 0x15, 0x35, 0x01, 0x37, 0x00, 0x24, 0x01, 0x00, 0x24, 0x02, 0x3B,
0x24, 0x03, 0x06, 0x18, 0x26, 0x01, 0x03, 0x00, 0x03, 0x00, 0x24, 0x02, 0x01, 0x27,
0x03, 0x22, 0x84, 0xA2, 0x9D, 0x89, 0x01, 0x00, 0x00, 0x35, 0x07, 0x24, 0x00, 0x01,
0x24, 0x01, 0x17, 0x18, 0x18, 0x18, 0x18, 0x29, 0x04, 0x24, 0xFF, 0x01, 0x18 };

} // namespace

const SamplePayload secure_channel_mrp_ack = { chip::Protocols::Id(VendorId::Common, 0), 16,
Expand All @@ -127,5 +144,11 @@ const SamplePayload im_protocol_report_data_acl = { chip::Protocols::Id(VendorId
const SamplePayload im_protocol_report_data_window_covering = { chip::Protocols::Id(VendorId::Common, 1), 5,
ByteSpan(payload_1_5_window_covering) };

const SamplePayload im_protocol_event_software_fault = { chip::Protocols::Id(VendorId::Common, 1), 5,
ByteSpan(payload_1_5_software_fault_event) };

const SamplePayload im_protocol_event_multipress = { chip::Protocols::Id(VendorId::Common, 1), 5,
ByteSpan(payload_1_5_multipress_event) };

} // namespace TestData
} // namespace chip
4 changes: 4 additions & 0 deletions src/lib/format/tests/sample_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ extern const SamplePayload im_protocol_report_data_acl;
extern const SamplePayload im_protocol_report_data_window_covering;
extern const SamplePayload im_protocol_invoke_request_change_channel;

// different event reports
extern const SamplePayload im_protocol_event_software_fault;
extern const SamplePayload im_protocol_event_multipress;

} // namespace TestData
} // namespace chip

0 comments on commit 1109108

Please sign in to comment.