Zigbee Protocol Controller 1.6.0
zigpc_counter_plugin_metric.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * # License
3 * <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
4 ******************************************************************************
5 * The licensor of this software is Silicon Laboratories Inc. Your use of this
6 * software is governed by the terms of Silicon Labs Master Software License
7 * Agreement (MSLA) available at
8 * www.silabs.com/about-us/legal/master-software-license-agreement. This
9 * software is distributed to you in Source Code format and is governed by the
10 * sections of the MSLA applicable to Source Code.
11 *
12 *****************************************************************************/
13
15#include "zigpc_gateway.h"
16#include <nlohmann/json.hpp>
17#include <sstream>
18#include <string>
19
21{
22 private:
23 static constexpr char LOG_TAG[] = "diagnostics_metric_counters";
24
25 public:
27 std::string metric_id) :
29 {}
30
32 {
33 size_t capacity = zigpc_gateway_get_counters_capacity();
34 uint16_t counter_array[capacity];
35
36 sl_status_t status
37 = zigpc_gateway_get_counters_list(counter_array, capacity);
38
39 if (status != SL_STATUS_OK) {
40 sl_log_error(LOG_TAG, "Failed to retrieve counters list: 0x%X", status);
41 return;
42 }
43
44 // payload should be as a JSON object: {"KEY" : value, "KEY" : value}
45 nlohmann::json jsn;
46
47 for (uint8_t i = 0U; i < capacity; i++) {
48 const char *label_cstr = zigpc_gateway_get_counters_entry_label(i);
49 if (label_cstr == nullptr) {
50 continue;
51 }
52
53 jsn[std::string(label_cstr)] = counter_array[i];
54 }
55
56 serialized_value = jsn.dump();
58 }
59};
Definition: zigpc_counter_plugin_metric.hpp:21
static constexpr char LOG_TAG[]
Definition: zigpc_counter_plugin_metric.hpp:23
void update_value()
Definition: zigpc_counter_plugin_metric.hpp:31
zigpc_counter_plugin_metric(zigpc_diagnostics_notification &notif, std::string metric_id)
Definition: zigpc_counter_plugin_metric.hpp:26
Abstract top level metric from which all diagnostic metric derive from.
Definition: zigpc_diagnostics_metric.hpp:25
zigpc_diagnostics_notification & on_update_complete
Definition: zigpc_diagnostics_metric.hpp:28
std::string serialized_value
Definition: zigpc_diagnostics_metric.hpp:30
std::string metric_id
Definition: zigpc_diagnostics_metric.hpp:29
Definition: zigpc_diagnostics_notification.hpp:20
virtual void notify(std::string metric_id)
Definition: zigpc_diagnostics_notification.hpp:22
#define sl_log_error(tag, fmtstr,...)
Definition: sl_log.h:145
#define SL_STATUS_OK
No error.
Definition: sl_status.h:49
size_t zigpc_gateway_get_counters_capacity()
Get the counters capacity.
sl_status_t zigpc_gateway_get_counters_list(uint16_t *list, size_t count)
Populate counters values to list provided.
const char * zigpc_gateway_get_counters_entry_label(size_t offset)
Get the label of the counters entry based on the offset passed in.