cmd handler stuff

This commit is contained in:
Wolfgang Hottgenroth 2020-11-16 15:51:00 +01:00
parent 4a71801170
commit ab3a6ac5ac
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <socket.h>
@ -41,29 +42,39 @@ typedef struct {
// clear statistics
bool clearCmd() {
bool clearCmd(char *cmdLine) {
t_mbusCommStats zeroedStats = { .requestCnt = 0, .errorCnt = 0 };
mbusCommSetStats(zeroedStats);
return true;
}
bool globalStatsCmd(char *cmdLine) {
t_mbusCommStats *stats = mbusCommGetStats();
char buf[256];
sprintf(buf, \
"Global statistics\n\r" \
" Requests: %d\n\r" \
" Errors: %d\n\r",
stats->requestCnt, stats->errorCnt
);
send(CMD_SOCK, buf, strlen(buf));
return true;
}
const static cmd_t COMMANDS[] = {
{ .requiredConfigMode = true,
.name = "clear",
.help = \
{ .requiredConfigMode = true, .name = "clear", .cmdFunc = clearCmd,
.help = \
"clear ................................ Clears the global Meterbus\n\r" \
" statistics\n\r" \
" Required configuration mode\n\r",
.cmdFunc = clearCmd
" Required configuration mode\n\r"
},
{ .requiredConfigMode = false,
.name = "END_OF_CMDS",
.help = "",
.cmdFunc = NULL
}
{ .requiredConfigMode = false, .name = "globalStats", .cmdFunc = globalStatsCmd,
.help = \
"globalStats .......................... Show the global statistics\n\r" \
" counters requestCnt and errorCnt\n\r"
},
{ .requiredConfigMode = false, .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
};