Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chip-tool] Print DeviceType names next to ids #35445

Merged
merged 6 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 12 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,16 @@ 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}}
{{#if class}}
XToripuru marked this conversation as resolved.
Show resolved Hide resolved
case {{asHex code 8}}: return "{{caption}}";
{{/if}}
{{/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);
23 changes: 22 additions & 1 deletion examples/chip-tool/templates/partials/StructLoggerImpl.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,37 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const ch
DataModelLogger::LogString(label, indent, "{");
{{#zcl_struct_items}}
{
{{#if (isEqual label "DeviceType") }}
{{#if (isEqual parent.name "DeviceTypeStruct") }}
XToripuru marked this conversation as resolved.
Show resolved Hide resolved
std::string item = std::to_string(value.{{asLowerCamelCase label}}) + " (" + DeviceTypeIdToText(value.{{asLowerCamelCase label}}) + ")";
DataModelLogger::LogString("{{asUpperCamelCase label}}", indent + 1, item);
{{else}}
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);
}
{{/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, "}");

return CHIP_NO_ERROR;
}

XToripuru marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading