Skip to content

Commit b1829ff

Browse files
authored
[chip-tool] Print DeviceType names next to ids (project-chip#35445)
* Add DeviceTypeIdToText and it's usage * Update Zap-generated files * Minor ZAP fixes * Update Zap-generated files * Revert empty line * Update missing Zap-generated files
1 parent 02316de commit b1829ff

File tree

7 files changed

+196
-11
lines changed

7 files changed

+196
-11
lines changed

examples/chip-tool/templates/logging/DataModelLogger-src.zapt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{> header}}
22

33
#include <commands/clusters/DataModelLogger.h>
4+
#include <zap-generated/cluster/logging/EntryToText.h>
45

56
using namespace chip::app::Clusters;
67

examples/chip-tool/templates/logging/EntryToText-src.zapt

+10
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,14 @@ char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId i
8181
{{/zcl_clusters}}
8282
default: return "Unknown";
8383
}
84+
}
85+
86+
char const * DeviceTypeIdToText(chip::DeviceTypeId id) {
87+
switch(id)
88+
{
89+
{{#zcl_device_types}}
90+
case {{asHex code 8}}: return "{{caption}}";
91+
{{/zcl_device_types}}
92+
default: return "Unknown";
93+
}
8494
}

examples/chip-tool/templates/logging/EntryToText.zapt

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ char const * AttributeIdToText(chip::ClusterId cluster, chip::AttributeId id);
1010

1111
char const * AcceptedCommandIdToText(chip::ClusterId cluster, chip::CommandId id);
1212

13-
char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId id);
13+
char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId id);
14+
15+
char const * DeviceTypeIdToText(chip::DeviceTypeId id);

examples/chip-tool/templates/partials/StructLoggerImpl.zapt

+22
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,34 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const ch
33
DataModelLogger::LogString(label, indent, "{");
44
{{#zcl_struct_items}}
55
{
6+
{{#if (isEqual type "devtype_id") }}
7+
{{#if isNullable }}
8+
if (value.{{asLowerCamelCase label}}.IsNull())
9+
{
10+
CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}});
11+
if (err != CHIP_NO_ERROR)
12+
{
13+
DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for '{{asUpperCamelCase label}}'");
14+
return err;
15+
}
16+
}
17+
else
18+
{
19+
std::string item = std::to_string(value.{{asLowerCamelCase label}}.Value()) + " (" + DeviceTypeIdToText(value.{{asLowerCamelCase label}}.Value()) + ")";
20+
DataModelLogger::LogString("{{asUpperCamelCase label}}", indent + 1, item);
21+
}
22+
{{else}}
23+
std::string item = std::to_string(value.{{asLowerCamelCase label}}) + " (" + DeviceTypeIdToText(value.{{asLowerCamelCase label}}) + ")";
24+
DataModelLogger::LogString("{{asUpperCamelCase label}}", indent + 1, item);
25+
{{/if}}
26+
{{else}}
627
CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}});
728
if (err != CHIP_NO_ERROR)
829
{
930
DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for '{{asUpperCamelCase label}}'");
1031
return err;
1132
}
33+
{{/if}}
1234
}
1335
{{/zcl_struct_items}}
1436
DataModelLogger::LogString(indent, "}");

zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp

+15-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.cpp

+143
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.h

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)