DataModelLogger-src.zapt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. {{> header}}
  2. #include <commands/clusters/DataModelLogger.h>
  3. using namespace chip::app::Clusters;
  4. {{#zcl_structs}}
  5. {{#if has_more_than_one_cluster}}
  6. {{> struct_logger_impl namespace="detail"}}
  7. {{/if}}
  8. {{/zcl_structs}}
  9. {{#zcl_clusters}}
  10. {{#zcl_structs}}
  11. {{#unless has_more_than_one_cluster}}
  12. {{> struct_logger_impl namespace=(as_camel_cased ../name false)}}
  13. {{/unless}}
  14. {{/zcl_structs}}
  15. {{/zcl_clusters}}
  16. {{#zcl_clusters}}
  17. {{#zcl_events}}
  18. CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const {{asUpperCamelCase parent.name}}::Events::{{asUpperCamelCase name}}::DecodableType & value)
  19. {
  20. DataModelLogger::LogString(label, indent, "{");
  21. {{#zcl_event_fields}}
  22. {
  23. CHIP_ERROR err = DataModelLogger::LogValue("{{asUpperCamelCase name}}", indent + 1, value.{{asLowerCamelCase name}});
  24. if (err != CHIP_NO_ERROR)
  25. {
  26. DataModelLogger::LogString(indent + 1, "Event truncated due to invalid value for '{{asUpperCamelCase name}}'");
  27. return err;
  28. }
  29. }
  30. {{/zcl_event_fields}}
  31. DataModelLogger::LogString(indent, "}");
  32. return CHIP_NO_ERROR;
  33. }
  34. {{/zcl_events}}
  35. {{/zcl_clusters}}
  36. {{#zcl_clusters}}
  37. {{#zcl_commands_source_server}}
  38. CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & value)
  39. {
  40. DataModelLogger::LogString(label, indent, "{");
  41. {{#zcl_command_arguments}}
  42. ReturnErrorOnFailure(DataModelLogger::LogValue("{{asLowerCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}}));
  43. {{/zcl_command_arguments}}
  44. DataModelLogger::LogString(indent, "}");
  45. return CHIP_NO_ERROR;
  46. }
  47. {{/zcl_commands_source_server}}
  48. {{/zcl_clusters}}
  49. CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data)
  50. {
  51. ChipLogProgress(chipTool, "Endpoint: %u Cluster: " ChipLogFormatMEI " Attribute " ChipLogFormatMEI " DataVersion: %" PRIu32, path.mEndpointId,
  52. ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mAttributeId), path.mDataVersion.ValueOr(0));
  53. switch (path.mClusterId)
  54. {
  55. {{#zcl_clusters}}
  56. {{#zcl_attributes_server}}
  57. {{#first}}
  58. case {{asUpperCamelCase parent.name}}::Id:
  59. {
  60. switch(path.mAttributeId)
  61. {
  62. {{/first}}
  63. case {{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::Id:
  64. {
  65. {{zapTypeToDecodableClusterObjectType type ns=parent.name forceNotOptional=true}} value;
  66. ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value));
  67. return DataModelLogger::LogValue("{{name}}", 1, value);
  68. }
  69. {{#last}}
  70. }
  71. break;
  72. }
  73. {{/last}}
  74. {{/zcl_attributes_server}}
  75. {{/zcl_clusters}}
  76. default:
  77. break;
  78. }
  79. ChipLogProgress(chipTool, " Don't know how to log atribute value");
  80. return CHIP_NO_ERROR;
  81. }
  82. CHIP_ERROR DataModelLogger::LogCommand(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data)
  83. {
  84. ChipLogProgress(chipTool, "Endpoint: %u Cluster: " ChipLogFormatMEI " Command " ChipLogFormatMEI, path.mEndpointId,
  85. ChipLogValueMEI(path.mClusterId), ChipLogValueMEI(path.mCommandId));
  86. switch (path.mClusterId)
  87. {
  88. {{#zcl_clusters}}
  89. {{#zcl_commands_source_server}}
  90. {{#first}}
  91. case {{asUpperCamelCase parent.name}}::Id:
  92. {
  93. switch(path.mCommandId)
  94. {
  95. {{/first}}
  96. case {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Id:
  97. {
  98. {{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType value;
  99. ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value));
  100. return DataModelLogger::LogValue("{{name}}", 1, value);
  101. }
  102. {{#last}}
  103. }
  104. break;
  105. }
  106. {{/last}}
  107. {{/zcl_commands_source_server}}
  108. {{/zcl_clusters}}
  109. default:
  110. break;
  111. }
  112. ChipLogProgress(chipTool, " Don't know how to log command response data");
  113. return CHIP_NO_ERROR;
  114. }
  115. CHIP_ERROR DataModelLogger::LogEvent(const chip::app::EventHeader & header, chip::TLV::TLVReader * data)
  116. {
  117. ChipLogProgress(chipTool, "Endpoint: %u Cluster: " ChipLogFormatMEI " Event " ChipLogFormatMEI, header.mPath.mEndpointId,
  118. ChipLogValueMEI(header.mPath.mClusterId), ChipLogValueMEI(header.mPath.mEventId));
  119. ChipLogProgress(chipTool, " Event number: %" PRIu64, header.mEventNumber);
  120. if (header.mPriorityLevel == chip::app::PriorityLevel::Info)
  121. {
  122. ChipLogProgress(chipTool, " Priority: Info");
  123. }
  124. else if (header.mPriorityLevel == chip::app::PriorityLevel::Critical)
  125. {
  126. ChipLogProgress(chipTool, " Priority: Critical");
  127. }
  128. else if (header.mPriorityLevel == chip::app::PriorityLevel::Debug)
  129. {
  130. ChipLogProgress(chipTool, " Priority: Debug");
  131. }
  132. else
  133. {
  134. ChipLogProgress(chipTool, " Priority: Unknown");
  135. }
  136. ChipLogProgress(chipTool, " Timestamp: %" PRIu64, header.mTimestamp.mValue);
  137. switch (header.mPath.mClusterId)
  138. {
  139. {{#zcl_clusters}}
  140. {{#zcl_events}}
  141. {{#first}}
  142. case {{asUpperCamelCase parent.name}}::Id:
  143. {
  144. switch(header.mPath.mEventId)
  145. {
  146. {{/first}}
  147. case {{asUpperCamelCase parent.name}}::Events::{{asUpperCamelCase name}}::Id:
  148. {
  149. {{zapTypeToDecodableClusterObjectType name ns=parent.name forceNotOptional=true}} value;
  150. ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value));
  151. return DataModelLogger::LogValue("{{name}}", 1, value);
  152. }
  153. {{#last}}
  154. }
  155. break;
  156. }
  157. {{/last}}
  158. {{/zcl_events}}
  159. {{/zcl_clusters}}
  160. default:
  161. break;
  162. }
  163. ChipLogProgress(chipTool, " Don't know how to log event data");
  164. return CHIP_NO_ERROR;
  165. }