From d92ff3f5ad391f717d031b0e803cdd5902fd4efd Mon Sep 17 00:00:00 2001 From: Andrei Litvin Date: Mon, 31 Jul 2023 10:46:49 -0400 Subject: [PATCH] [text decode] Fix event decoding and add unit tests. (#28376) * Fix id for event report decoding * Add unit tests for event decoding * Restyled by clang-format --------- Co-authored-by: Andrei Litvin Co-authored-by: Restyled.io --- src/lib/format/protocol_messages.matter | 2 +- src/lib/format/tests/TestDecoding.cpp | 37 +++++++++++++++++++++++++ src/lib/format/tests/sample_data.cpp | 23 +++++++++++++++ src/lib/format/tests/sample_data.h | 4 +++ 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/lib/format/protocol_messages.matter b/src/lib/format/protocol_messages.matter index 0346b138fd45b0..786c50d85dffb0 100644 --- a/src/lib/format/protocol_messages.matter +++ b/src/lib/format/protocol_messages.matter @@ -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 { diff --git a/src/lib/format/tests/TestDecoding.cpp b/src/lib/format/tests/TestDecoding.cpp index 7dfc005e8e5988..9ad6f97b6849d5 100644 --- a/src/lib/format/tests/TestDecoding.cpp +++ b/src/lib/format/tests/TestDecoding.cpp @@ -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) diff --git a/src/lib/format/tests/sample_data.cpp b/src/lib/format/tests/sample_data.cpp index b5304198bdda1a..52bfb64a54c085 100644 --- a/src/lib/format/tests/sample_data.cpp +++ b/src/lib/format/tests/sample_data.cpp @@ -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, @@ -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 diff --git a/src/lib/format/tests/sample_data.h b/src/lib/format/tests/sample_data.h index d8bf5864593978..cc74ae09e296fc 100644 --- a/src/lib/format/tests/sample_data.h +++ b/src/lib/format/tests/sample_data.h @@ -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