Skip to content

Commit 2115e09

Browse files
authored
Matter show event name in logs (#21649)
* Matter show event name in logs * Optimize logging * Human readable version
1 parent d15b88f commit 2115e09

File tree

4 files changed

+192
-49
lines changed

4 files changed

+192
-49
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*********************************************************************************\
2+
* Compact form for events
3+
*
4+
\*********************************************************************************/
5+
#include <stddef.h>
6+
#include <stdint.h>
7+
8+
typedef struct {
9+
uint16_t cluster;
10+
uint8_t event;
11+
const char* name;
12+
} matter_event_t;
13+
14+
// Must be sorted, cluster first, then attribute
15+
16+
const matter_event_t matter_Events[] = {
17+
// 0x001F Access Control Cluster
18+
{ 0x001F, 0x00, "AccessControlEntryChanged" },
19+
{ 0x001F, 0x00, "AccessControlExtensionChanged" },
20+
// 0x0025 Actions Cluster
21+
{ 0x0025, 0x00, "StateChanged" },
22+
{ 0x0025, 0x01, "ActionFailed" },
23+
// 0x0028 Basic Information Cluster
24+
{ 0x0028, 0x00, "StartUp" },
25+
{ 0x0028, 0x01, "ShutDown" },
26+
{ 0x0028, 0x02, "Leave" },
27+
{ 0x0028, 0x03, "ReachableChanged" },
28+
// 0x002F Power Source Cluster
29+
{ 0x002F, 0x00, "WiredFaultChange" },
30+
{ 0x002F, 0x01, "BatFaultChange" },
31+
{ 0x002F, 0x02, "BatChargeFaultChange" },
32+
// 0x0033 General Diagnostics Cluster
33+
{ 0x0033, 0x00, "HardwareFaultChange" },
34+
{ 0x0033, 0x01, "RadioFaultChange" },
35+
{ 0x0033, 0x02, "NetworkFaultChange" },
36+
{ 0x0033, 0x03, "BootReason" },
37+
// 0x0034 Software Diagnostics Cluster
38+
{ 0x0034, 0x00, "SoftwareFault" },
39+
// 0x0035 Thread Network Diagnostics Cluster
40+
// { 0x0035, 0x00, "ConnectionStatus" },
41+
// { 0x0035, 0x01, "NetworkFaultChange" },
42+
// 0x0036 Wi-Fi Network Diagnostics Cluster
43+
{ 0x0036, 0x00, "Disconnection" },
44+
{ 0x0036, 0x01, "AssociationFailure" },
45+
{ 0x0036, 0x02, "ConnectionStatus" },
46+
// 0x0038 Time Synchronization Cluster
47+
{ 0x0038, 0x00, "DSTTableEmpty" },
48+
{ 0x0038, 0x01, "DSTStatus" },
49+
{ 0x0038, 0x02, "TimeZoneStatus" },
50+
{ 0x0038, 0x03, "TimeFailure" },
51+
{ 0x0038, 0x04, "MissingTrustedTimeSource" },
52+
// 0x0039 Bridged Device Basic Information Cluster
53+
{ 0x0039, 0x00, "StartUp" },
54+
{ 0x0039, 0x01, "ShutDown" },
55+
{ 0x0039, 0x02, "Leave" },
56+
{ 0x0039, 0x03, "ReachableChanged" },
57+
{ 0xFFFF, 0xFF, NULL }
58+
};

lib/libesp32/berry_matter/src/be_matter_module.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ extern const bclass be_class_Matter_QRCode;
8585
#include "solidify/solidified_Matter_Module.h"
8686

8787
#include "../generate/be_matter_clusters.h"
88+
#include "../generate/be_matter_events.h"
8889
#include "../generate/be_matter_opcodes.h"
8990
#include "../generate/be_matter_vendors.h"
9091

@@ -188,6 +189,16 @@ const char* matter_get_command_name(uint16_t cluster, uint16_t command) {
188189
}
189190
BE_FUNC_CTYPE_DECLARE(matter_get_command_name, "s", "ii")
190191

192+
const char* matter_get_event_name(uint16_t cluster, uint8_t event) {
193+
for (const matter_event_t * ev = matter_Events; ev->cluster != 0xFFFF; ev++) {
194+
if (ev->cluster == cluster && ev->event == event) {
195+
return ev->name;
196+
}
197+
}
198+
return NULL;
199+
}
200+
BE_FUNC_CTYPE_DECLARE(matter_get_event_name, "s", "ii")
201+
191202
// Convert an IP address from string to raw bytes
192203
extern const void* matter_get_ip_bytes(const char* ip_str, size_t* ret_len);
193204
BE_FUNC_CTYPE_DECLARE(matter_get_ip_bytes, "&", "s")
@@ -330,6 +341,7 @@ module matter (scope: global, strings: weak) {
330341
is_attribute_writable, ctype_func(matter_is_attribute_writable)
331342
is_attribute_reportable, ctype_func(matter_is_attribute_reportable)
332343
get_command_name, ctype_func(matter_get_command_name)
344+
get_event_name, ctype_func(matter_get_event_name)
333345
get_opcode_name, ctype_func(matter_get_opcode_name)
334346
TLV, class(be_class_Matter_TLV)
335347
sort, closure(module_matter_sort_closure)

lib/libesp32/berry_matter/src/embedded/Matter_Plugin_0.be

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,21 @@ class Matter_Plugin
195195
event_ib.epoch_timestamp = tasmota.rtc('utc')
196196
if (event_ib.epoch_timestamp < 1700000000) event_ib.epoch_timestamp = nil end # no valid time
197197
event_ib.data = data
198-
var priority_str = (priority == 2) ? "CRIT " : (priority == 1) ? "INFO " : "DEBUG "
199-
log(f"MTR: +Add_Event ({priority_str}) [{event_path.endpoint:02X}]{event_path.cluster:04X}/{event_path.event:04X} ({event_ib.event_number:5i}) - {event_ib.data}", 2)
200-
log(f"MTR: Publishing event {event_ib}", 4)
198+
if tasmota.loglevel(3)
199+
var data_str = str(event_ib.data)
200+
if (cluster == 0x0028) && (event == 0x00)
201+
# put the software version in a readable format
202+
var val = event_ib.data.val
203+
data_str = format("%i.%i.%i.%i", (val >> 24) & 0xFF, (val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)
204+
end
205+
var priority_str = (priority == 2) ? "CRIT " : (priority == 1) ? "INFO " : "DEBUG "
206+
var event_name = matter.get_event_name(cluster, event)
207+
event_name = (event_name != nil) ? "(" + event_name + ") " : ""
208+
log(f"MTR: +Add_Event ({priority_str}{event_ib.event_number:8s}) [{event_path.endpoint:02X}]{event_path.cluster:04X}/{event_path.event:02X} {event_name}- {data_str}", 2)
209+
end
210+
if tasmota.loglevel(4)
211+
log(f"MTR: Publishing event {event_ib}", 4)
212+
end
201213

202214
self.device.events.queue_event(event_ib)
203215
end

lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_0.h

Lines changed: 107 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ be_local_closure(class_Matter_Plugin_every_250ms, /* name */
286286
extern const bclass be_class_Matter_Plugin;
287287
be_local_closure(class_Matter_Plugin_publish_event, /* name */
288288
be_nested_proto(
289-
17, /* nstack */
289+
20, /* nstack */
290290
5, /* argc */
291291
2, /* varg */
292292
0, /* has upvals */
293293
NULL, /* no upvals */
294294
0, /* has sup protos */
295295
&be_class_Matter_Plugin,
296296
1, /* has constants */
297-
( &(const bvalue[27]) { /* constants */
297+
( &(const bvalue[36]) { /* constants */
298298
/* K0 */ be_nested_str_weak(matter),
299299
/* K1 */ be_nested_str_weak(EventDataIB),
300300
/* K2 */ be_nested_str_weak(EventPathIB),
@@ -313,19 +313,28 @@ be_local_closure(class_Matter_Plugin_publish_event, /* name */
313313
/* K15 */ be_nested_str_weak(utc),
314314
/* K16 */ be_const_int(1700000000),
315315
/* K17 */ be_nested_str_weak(data),
316-
/* K18 */ be_const_int(2),
317-
/* K19 */ be_nested_str_weak(CRIT_X20_X20),
318-
/* K20 */ be_const_int(1),
319-
/* K21 */ be_nested_str_weak(INFO_X20_X20),
320-
/* K22 */ be_nested_str_weak(DEBUG_X20),
321-
/* K23 */ be_nested_str_weak(log),
322-
/* K24 */ be_nested_str_weak(MTR_X3A_X20_X2BAdd_Event_X20_X28_X25s_X29_X20_X5B_X2502X_X5D_X2504X_X2F_X2504X_X20_X28_X255i_X29_X20_X2D_X20_X25s),
323-
/* K25 */ be_nested_str_weak(MTR_X3A_X20Publishing_X20event_X20_X25s),
324-
/* K26 */ be_nested_str_weak(queue_event),
316+
/* K18 */ be_nested_str_weak(loglevel),
317+
/* K19 */ be_const_int(3),
318+
/* K20 */ be_const_int(0),
319+
/* K21 */ be_nested_str_weak(val),
320+
/* K22 */ be_nested_str_weak(_X25i_X2E_X25i_X2E_X25i_X2E_X25i),
321+
/* K23 */ be_const_int(2),
322+
/* K24 */ be_nested_str_weak(CRIT_X20_X20),
323+
/* K25 */ be_const_int(1),
324+
/* K26 */ be_nested_str_weak(INFO_X20_X20),
325+
/* K27 */ be_nested_str_weak(DEBUG_X20),
326+
/* K28 */ be_nested_str_weak(get_event_name),
327+
/* K29 */ be_nested_str_weak(_X28),
328+
/* K30 */ be_nested_str_weak(_X29_X20),
329+
/* K31 */ be_nested_str_weak(),
330+
/* K32 */ be_nested_str_weak(log),
331+
/* K33 */ be_nested_str_weak(MTR_X3A_X20_X2BAdd_Event_X20_X28_X25s_X258s_X29_X20_X5B_X2502X_X5D_X2504X_X2F_X2502X_X20_X25s_X2D_X20_X25s),
332+
/* K34 */ be_nested_str_weak(MTR_X3A_X20Publishing_X20event_X20_X25s),
333+
/* K35 */ be_nested_str_weak(queue_event),
325334
}),
326335
be_str_weak(publish_event),
327336
&be_const_str_solidified,
328-
( &(const binstruction[62]) { /* code */
337+
( &(const binstruction[114]) { /* code */
329338
0xB8160000, // 0000 GETNGBL R5 K0
330339
0x8C140B01, // 0001 GETMET R5 R5 K1
331340
0x7C140200, // 0002 CALL R5 1
@@ -354,40 +363,92 @@ be_local_closure(class_Matter_Plugin_publish_event, /* name */
354363
0x4C1C0000, // 0019 LDNIL R7
355364
0x90161807, // 001A SETMBR R5 K12 R7
356365
0x90162204, // 001B SETMBR R5 K17 R4
357-
0x1C1C0712, // 001C EQ R7 R3 K18
358-
0x781E0001, // 001D JMPF R7 #0020
359-
0x581C0013, // 001E LDCONST R7 K19
360-
0x70020004, // 001F JMP #0025
361-
0x1C1C0714, // 0020 EQ R7 R3 K20
362-
0x781E0001, // 0021 JMPF R7 #0024
363-
0x581C0015, // 0022 LDCONST R7 K21
364-
0x70020000, // 0023 JMP #0025
365-
0x581C0016, // 0024 LDCONST R7 K22
366-
0xB8222E00, // 0025 GETNGBL R8 K23
367-
0x60240018, // 0026 GETGBL R9 G24
368-
0x58280018, // 0027 LDCONST R10 K24
369-
0x5C2C0E00, // 0028 MOVE R11 R7
370-
0x88300D03, // 0029 GETMBR R12 R6 K3
371-
0x88340D04, // 002A GETMBR R13 R6 K4
372-
0x88380D05, // 002B GETMBR R14 R6 K5
373-
0x883C0B08, // 002C GETMBR R15 R5 K8
374-
0x88400B11, // 002D GETMBR R16 R5 K17
375-
0x7C240E00, // 002E CALL R9 7
376-
0x58280012, // 002F LDCONST R10 K18
377-
0x7C200400, // 0030 CALL R8 2
378-
0xB8222E00, // 0031 GETNGBL R8 K23
379-
0x60240018, // 0032 GETGBL R9 G24
380-
0x58280019, // 0033 LDCONST R10 K25
381-
0x5C2C0A00, // 0034 MOVE R11 R5
382-
0x7C240400, // 0035 CALL R9 2
383-
0x542A0003, // 0036 LDINT R10 4
384-
0x7C200400, // 0037 CALL R8 2
385-
0x88200109, // 0038 GETMBR R8 R0 K9
386-
0x8820110A, // 0039 GETMBR R8 R8 K10
387-
0x8C20111A, // 003A GETMET R8 R8 K26
388-
0x5C280A00, // 003B MOVE R10 R5
389-
0x7C200400, // 003C CALL R8 2
390-
0x80000000, // 003D RET 0
366+
0xB81E1A00, // 001C GETNGBL R7 K13
367+
0x8C1C0F12, // 001D GETMET R7 R7 K18
368+
0x58240013, // 001E LDCONST R9 K19
369+
0x7C1C0400, // 001F CALL R7 2
370+
0x781E003E, // 0020 JMPF R7 #0060
371+
0x601C0008, // 0021 GETGBL R7 G8
372+
0x88200B11, // 0022 GETMBR R8 R5 K17
373+
0x7C1C0200, // 0023 CALL R7 1
374+
0x54220027, // 0024 LDINT R8 40
375+
0x1C200208, // 0025 EQ R8 R1 R8
376+
0x78220015, // 0026 JMPF R8 #003D
377+
0x1C200514, // 0027 EQ R8 R2 K20
378+
0x78220013, // 0028 JMPF R8 #003D
379+
0x88200B11, // 0029 GETMBR R8 R5 K17
380+
0x88201115, // 002A GETMBR R8 R8 K21
381+
0x60240018, // 002B GETGBL R9 G24
382+
0x58280016, // 002C LDCONST R10 K22
383+
0x542E0017, // 002D LDINT R11 24
384+
0x3C2C100B, // 002E SHR R11 R8 R11
385+
0x543200FE, // 002F LDINT R12 255
386+
0x2C2C160C, // 0030 AND R11 R11 R12
387+
0x5432000F, // 0031 LDINT R12 16
388+
0x3C30100C, // 0032 SHR R12 R8 R12
389+
0x543600FE, // 0033 LDINT R13 255
390+
0x2C30180D, // 0034 AND R12 R12 R13
391+
0x54360007, // 0035 LDINT R13 8
392+
0x3C34100D, // 0036 SHR R13 R8 R13
393+
0x543A00FE, // 0037 LDINT R14 255
394+
0x2C341A0E, // 0038 AND R13 R13 R14
395+
0x543A00FE, // 0039 LDINT R14 255
396+
0x2C38100E, // 003A AND R14 R8 R14
397+
0x7C240A00, // 003B CALL R9 5
398+
0x5C1C1200, // 003C MOVE R7 R9
399+
0x1C200717, // 003D EQ R8 R3 K23
400+
0x78220001, // 003E JMPF R8 #0041
401+
0x58200018, // 003F LDCONST R8 K24
402+
0x70020004, // 0040 JMP #0046
403+
0x1C200719, // 0041 EQ R8 R3 K25
404+
0x78220001, // 0042 JMPF R8 #0045
405+
0x5820001A, // 0043 LDCONST R8 K26
406+
0x70020000, // 0044 JMP #0046
407+
0x5820001B, // 0045 LDCONST R8 K27
408+
0xB8260000, // 0046 GETNGBL R9 K0
409+
0x8C24131C, // 0047 GETMET R9 R9 K28
410+
0x5C2C0200, // 0048 MOVE R11 R1
411+
0x5C300400, // 0049 MOVE R12 R2
412+
0x7C240600, // 004A CALL R9 3
413+
0x4C280000, // 004B LDNIL R10
414+
0x2028120A, // 004C NE R10 R9 R10
415+
0x782A0002, // 004D JMPF R10 #0051
416+
0x002A3A09, // 004E ADD R10 K29 R9
417+
0x0028151E, // 004F ADD R10 R10 K30
418+
0x70020000, // 0050 JMP #0052
419+
0x5828001F, // 0051 LDCONST R10 K31
420+
0x5C241400, // 0052 MOVE R9 R10
421+
0xB82A4000, // 0053 GETNGBL R10 K32
422+
0x602C0018, // 0054 GETGBL R11 G24
423+
0x58300021, // 0055 LDCONST R12 K33
424+
0x5C341000, // 0056 MOVE R13 R8
425+
0x88380B08, // 0057 GETMBR R14 R5 K8
426+
0x883C0D03, // 0058 GETMBR R15 R6 K3
427+
0x88400D04, // 0059 GETMBR R16 R6 K4
428+
0x88440D05, // 005A GETMBR R17 R6 K5
429+
0x5C481200, // 005B MOVE R18 R9
430+
0x5C4C0E00, // 005C MOVE R19 R7
431+
0x7C2C1000, // 005D CALL R11 8
432+
0x58300017, // 005E LDCONST R12 K23
433+
0x7C280400, // 005F CALL R10 2
434+
0xB81E1A00, // 0060 GETNGBL R7 K13
435+
0x8C1C0F12, // 0061 GETMET R7 R7 K18
436+
0x54260003, // 0062 LDINT R9 4
437+
0x7C1C0400, // 0063 CALL R7 2
438+
0x781E0006, // 0064 JMPF R7 #006C
439+
0xB81E4000, // 0065 GETNGBL R7 K32
440+
0x60200018, // 0066 GETGBL R8 G24
441+
0x58240022, // 0067 LDCONST R9 K34
442+
0x5C280A00, // 0068 MOVE R10 R5
443+
0x7C200400, // 0069 CALL R8 2
444+
0x54260003, // 006A LDINT R9 4
445+
0x7C1C0400, // 006B CALL R7 2
446+
0x881C0109, // 006C GETMBR R7 R0 K9
447+
0x881C0F0A, // 006D GETMBR R7 R7 K10
448+
0x8C1C0F23, // 006E GETMET R7 R7 K35
449+
0x5C240A00, // 006F MOVE R9 R5
450+
0x7C1C0400, // 0070 CALL R7 2
451+
0x80000000, // 0071 RET 0
391452
})
392453
)
393454
);

0 commit comments

Comments
 (0)