Skip to content

Commit

Permalink
[chip-tool] Print DeviceType names next to ids (project-chip#35445)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
XToripuru authored Sep 10, 2024
1 parent 02316de commit b1829ff
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{> header}}

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

using namespace chip::app::Clusters;

Expand Down
10 changes: 10 additions & 0 deletions examples/chip-tool/templates/logging/EntryToText-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId i
{{/zcl_clusters}}
default: return "Unknown";
}
}

char const * DeviceTypeIdToText(chip::DeviceTypeId id) {
switch(id)
{
{{#zcl_device_types}}
case {{asHex code 8}}: return "{{caption}}";
{{/zcl_device_types}}
default: return "Unknown";
}
}
4 changes: 3 additions & 1 deletion examples/chip-tool/templates/logging/EntryToText.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ char const * AttributeIdToText(chip::ClusterId cluster, chip::AttributeId id);

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

char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId id);
char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId id);

char const * DeviceTypeIdToText(chip::DeviceTypeId id);
22 changes: 22 additions & 0 deletions examples/chip-tool/templates/partials/StructLoggerImpl.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const ch
DataModelLogger::LogString(label, indent, "{");
{{#zcl_struct_items}}
{
{{#if (isEqual type "devtype_id") }}
{{#if isNullable }}
if (value.{{asLowerCamelCase label}}.IsNull())
{
CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}});
if (err != CHIP_NO_ERROR)
{
DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for '{{asUpperCamelCase label}}'");
return err;
}
}
else
{
std::string item = std::to_string(value.{{asLowerCamelCase label}}.Value()) + " (" + DeviceTypeIdToText(value.{{asLowerCamelCase label}}.Value()) + ")";
DataModelLogger::LogString("{{asUpperCamelCase label}}", indent + 1, item);
}
{{else}}
std::string item = std::to_string(value.{{asLowerCamelCase label}}) + " (" + DeviceTypeIdToText(value.{{asLowerCamelCase label}}) + ")";
DataModelLogger::LogString("{{asUpperCamelCase label}}", indent + 1, item);
{{/if}}
{{else}}
CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}});
if (err != CHIP_NO_ERROR)
{
DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for '{{asUpperCamelCase label}}'");
return err;
}
{{/if}}
}
{{/zcl_struct_items}}
DataModelLogger::LogString(indent, "}");
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

143 changes: 143 additions & 0 deletions zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1829ff

Please sign in to comment.