blob: 5bff45c9951f7dcaae43cf450e76f6b56987a185 [file] [log] [blame]
{{> header}}
#include <commands/clusters/DataModelLogger.h>
using namespace chip::app::Clusters;
{{#structs_with_clusters groupByStructName=1}}
CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const chip::app::Clusters::{{#unless (is_number_greater_than structClusterCount 1)}}{{as_camel_cased clusterName false}}{{else}}detail{{/unless}}::Structs::{{name}}::DecodableType & value)
{
DataModelLogger::LogString(label, indent, "{");
{{#zcl_struct_items}}
{
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;
}
}
{{/zcl_struct_items}}
DataModelLogger::LogString(indent, "}");
return CHIP_NO_ERROR;
}
{{/structs_with_clusters}}
{{#zcl_clusters}}
{{#zcl_events}}
CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const {{asUpperCamelCase parent.name}}::Events::{{asUpperCamelCase name}}::DecodableType & value)
{
DataModelLogger::LogString(label, indent, "{");
{{#zcl_event_fields}}
{
CHIP_ERROR err = DataModelLogger::LogValue("{{asUpperCamelCase name}}", indent + 1, value.{{asLowerCamelCase name}});
if (err != CHIP_NO_ERROR)
{
DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for '{{asUpperCamelCase name}}'");
return err;
}
}
{{/zcl_event_fields}}
DataModelLogger::LogString(indent, "}");
return CHIP_NO_ERROR;
}
{{/zcl_events}}
{{/zcl_clusters}}
{{#chip_client_clusters includeAll=true}}
{{#zcl_commands_source_server}}
CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & value)
{
DataModelLogger::LogString(label, indent, "{");
{{#zcl_command_arguments}}
ReturnErrorOnFailure(DataModelLogger::LogValue("{{asLowerCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}}));
{{/zcl_command_arguments}}
DataModelLogger::LogString(indent, "}");
return CHIP_NO_ERROR;
}
{{/zcl_commands_source_server}}
{{/chip_client_clusters}}
CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data)
{
ChipLogProgress(chipTool, "Endpoint: %u Cluster: " ChipLogFormatMEI " Attribute " ChipLogFormatMEI " DataVersion: %" PRIu32, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId), path.mDataVersion.ValueOr(0));
switch (path.mClusterId)
{
{{#chip_client_clusters includeAll=true}}
{{#zcl_attributes_server}}
{{#first}}
case {{asUpperCamelCase parent.name}}::Id:
{
switch(path.mAttributeId)
{
{{/first}}
case {{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::Id:
{
{{zapTypeToDecodableClusterObjectType type ns=parent.name forceNotOptional=true}} value;
ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value));
return DataModelLogger::LogValue("{{name}}", 1, value);
}
{{#last}}
}
break;
}
{{/last}}
{{/zcl_attributes_server}}
{{/chip_client_clusters}}
default:
break;
}
ChipLogProgress(chipTool, " Don't know how to log atribute value");
return CHIP_NO_ERROR;
}
CHIP_ERROR DataModelLogger::LogCommand(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data)
{
ChipLogProgress(chipTool, "Endpoint: %u Cluster: " ChipLogFormatMEI " Command " ChipLogFormatMEI, path.mEndpointId,
ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mCommandId));
switch (path.mClusterId)
{
{{#chip_client_clusters includeAll=true}}
{{#zcl_commands_source_server}}
{{#first}}
case {{asUpperCamelCase parent.name}}::Id:
{
switch(path.mCommandId)
{
{{/first}}
case {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Id:
{
{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType value;
ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value));
return DataModelLogger::LogValue("{{name}}", 1, value);
}
{{#last}}
}
break;
}
{{/last}}
{{/zcl_commands_source_server}}
{{/chip_client_clusters}}
default:
break;
}
ChipLogProgress(chipTool, " Don't know how to log command response data");
return CHIP_NO_ERROR;
}
CHIP_ERROR DataModelLogger::LogEvent(const chip::app::EventHeader & header, chip::TLV::TLVReader * data)
{
ChipLogProgress(chipTool, "Endpoint: %u Cluster: " ChipLogFormatMEI " Event " ChipLogFormatMEI, header.mPath.mEndpointId,
ChipLogValueMEI(header.mPath.mClusterId), ChipLogValueMEI(header.mPath.mEventId));
ChipLogProgress(chipTool, " Event number: %" PRIu64, header.mEventNumber);
if (header.mPriorityLevel == chip::app::PriorityLevel::Info)
{
ChipLogProgress(chipTool, " Priority: Info");
}
else if (header.mPriorityLevel == chip::app::PriorityLevel::Critical)
{
ChipLogProgress(chipTool, " Priority: Critical");
}
else if (header.mPriorityLevel == chip::app::PriorityLevel::Debug)
{
ChipLogProgress(chipTool, " Priority: Debug");
}
else
{
ChipLogProgress(chipTool, " Priority: Unknown");
}
ChipLogProgress(chipTool, " Timestamp: %" PRIu64, header.mTimestamp.mValue);
switch (header.mPath.mClusterId)
{
{{#chip_client_clusters includeAll=true}}
{{#chip_server_cluster_events}}
{{#first}}
case {{asUpperCamelCase parent.name}}::Id:
{
switch(header.mPath.mEventId)
{
{{/first}}
case {{asUpperCamelCase parent.name}}::Events::{{asUpperCamelCase name}}::Id:
{
{{zapTypeToDecodableClusterObjectType name ns=parent.name forceNotOptional=true}} value;
ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value));
return DataModelLogger::LogValue("{{name}}", 1, value);
}
{{#last}}
}
break;
}
{{/last}}
{{/chip_server_cluster_events}}
{{/chip_client_clusters}}
default:
break;
}
ChipLogProgress(chipTool, " Don't know how to log event data");
return CHIP_NO_ERROR;
}