blob: cbce6c27abf767d2b38c060e9f0e815191ce7e50 [file] [log] [blame]
{{> header}}
#include <commands/clusters/DataModelLogger.h>
#include <zap-generated/cluster/logging/EntryToText.h>
using namespace chip::app::Clusters;
{{#zcl_structs}}
{{#if has_more_than_one_cluster}}
{{> struct_logger_impl namespace="detail"}}
{{else if has_no_clusters}}
{{> struct_logger_impl namespace="Globals"}}
{{/if}}
{{/zcl_structs}}
{{#zcl_clusters}}
{{#zcl_structs}}
{{#unless has_more_than_one_cluster}}
{{> struct_logger_impl namespace=(as_camel_cased ../name false)}}
{{/unless}}
{{/zcl_structs}}
{{/zcl_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}}
{{#zcl_clusters}}
{{#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}}
{{/zcl_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)
{
{{#zcl_clusters}}
{{#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));
{{#if (isEqual name "ServerList")}}
return DataModelLogger::LogClusterId("{{name}}", 1, value);
{{else if (isEqual name "ClientList")}}
return DataModelLogger::LogClusterId("{{name}}", 1, value);
{{else if (isEqual name "AttributeList")}}
return DataModelLogger::LogAttributeId("{{name}}", 1, value, {{asUpperCamelCase parent.name}}::Id);
{{else if (isEqual name "AcceptedCommandList")}}
return DataModelLogger::LogAcceptedCommandId("{{name}}", 1, value, {{asUpperCamelCase parent.name}}::Id);
{{else if (isEqual name "GeneratedCommandList")}}
return DataModelLogger::LogGeneratedCommandId("{{name}}", 1, value, {{asUpperCamelCase parent.name}}::Id);
{{else}}
return DataModelLogger::LogValue("{{name}}", 1, value);
{{/if}}
}
{{#last}}
}
break;
}
{{/last}}
{{/zcl_attributes_server}}
{{/zcl_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)
{
{{#zcl_clusters}}
{{#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}}
{{/zcl_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)
{
{{#zcl_clusters}}
{{#zcl_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}}
{{/zcl_events}}
{{/zcl_clusters}}
default:
break;
}
ChipLogProgress(chipTool, " Don't know how to log event data");
return CHIP_NO_ERROR;
}