1#include "main-header.h"
2#include "metrics/metrics.h"
4static uint8_t mbuf[256];
13 struct metric metrics[METRIC_COUNT];
16#define SEND_FREQUENCY_SECS 120
17static long int metric_send_counter;
22 memset(&metricset, 0,
sizeof(metricset));
23 metric_send_counter = 0;
26static struct metric *find_metric_entry(
int mnum) {
30 for (i = 0; i < METRIC_COUNT; i++) {
31 struct metric *m = &metricset.metrics[i];
32 if (m->metric_number == mnum) {
35 if ((res == NULL) && (m->metric_number == 0)) {
40 res->metric_number = mnum;
45void metric_set_by_number(
int metric, uint32_t value) {
49 printf(
"No metric available\r\n");
55void metric_inc_by_number(
int metric) {
59 printf(
"No metric available\r\n");
74 com->target = CLOUD_SERVER;
76 com->flags = COMFLAGS_DATA | COMFLAGS_SUCCESS;
80 shifter_init(sh, (uint8_t *)&mbuf,
sizeof(mbuf));
82 shift_into_uint8(sh, 1);
83 for (i = 0; i < METRIC_COUNT; i++) {
84 struct metric *m = &metricset.metrics[i];
85 if (m->metric_number == 0) {
88 shift_into_uint8(sh, m->metric_number);
89 shift_into_uint8(sh, m->number_type);
90 shift_into_uint32(sh, m->integer);
92 shift_into_uint8(sh, 0);
93 if (shift_error(sh) != 0) {
94 printf(
"[metric] Shifter error: %i\r\n", shift_error(sh));
98 printf(
"[metric] sending %i bytes\r\n", sh->validbytes);
104 if (mculib_has_time_passed(SEND_FREQUENCY_SECS, &metric_send_counter)) {
int send_command(struct command *com)
send a command to another module (or broadcast)
void free_command(struct command *com)
free a command
void command_init(struct command *com)
initialize a command structure with default values
struct command * alloc_command()
allocate a free command
int command_add_binary_arg(struct command *com, const int len, const byte *srcbuf)
adds a binary parameter to command returns 0 if ok otherwise errorcode