From ec1eeb7ff9a9df4eac12fee9be4b16e723c31d4f Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 16 Nov 2020 14:56:05 +0100 Subject: [PATCH] cmd handler stuff --- cube/User/Src/cmdHandler.c | 26 +++++++++++++++++++++++++- cube/User/Src/main2.c | 10 +++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cube/User/Src/cmdHandler.c b/cube/User/Src/cmdHandler.c index b06d8f8..52afd86 100644 --- a/cube/User/Src/cmdHandler.c +++ b/cube/User/Src/cmdHandler.c @@ -10,6 +10,7 @@ #include #include #include +#include extern const uint8_t CMD_SOCK; @@ -28,12 +29,25 @@ typedef enum { CH_ERROR } chState_t; + +// clear statistics +bool clearCmd() { + t_mbusCommStats zeroedStats = { .requestCnt = 0, .errorCnt = 0 }; + mbusCommSetStats(zeroedStats); + return true; +} + // returns 0 to continue waiting for input // returns -1 to close the connection // returns 1 to toggle to config mode // returns 2 to toggle back to default mode int8_t cmdExecuteCommand(uint8_t *cmd, bool resetConfigMode) { const static uint8_t GOODBYE_MSG[] = "Good bye\n\r"; + const static uint8_t OK_MSG[] = "OK\n\r"; + const static uint8_t FAILED_MSG[] = "Failed\n\r"; + const static uint8_t REQUIRES_CONFIG_MODE_MGS[] = "Not executed, requires config mode\n\r"; + uint8_t *messageToSend = NULL; + static bool configMode = false; if (resetConfigMode) { @@ -43,7 +57,7 @@ int8_t cmdExecuteCommand(uint8_t *cmd, bool resetConfigMode) { int8_t retCode = 0; coloredMsg(LOG_YELLOW, "cec, cmd is %s", cmd); if (0 == strcmp(cmd, "quit")) { - send(CMD_SOCK, GOODBYE_MSG, sizeof(GOODBYE_MSG)); + messageToSend = GOODBYE_MSG; retCode = -1; } else if (0 == strcmp(cmd, "enable")) { coloredMsg(LOG_YELLOW, "cec, enable config mode"); @@ -53,6 +67,16 @@ int8_t cmdExecuteCommand(uint8_t *cmd, bool resetConfigMode) { coloredMsg(LOG_YELLOW, "cec, disable config mode"); configMode = false; retCode = 2; + } else if (0 == strcmp(cmd, "clear")) { + if (configMode) { + messageToSend = clearCmd() ? OK_MSG : FAILED_MSG; + } else { + messageToSend = REQUIRES_CONFIG_MODE_MGS; + } + } + + if (messageToSend) { + send(CMD_SOCK, messageToSend, sizeof(messageToSend)); } return retCode; diff --git a/cube/User/Src/main2.c b/cube/User/Src/main2.c index d279e99..073362c 100644 --- a/cube/User/Src/main2.c +++ b/cube/User/Src/main2.c @@ -193,14 +193,14 @@ void my_setup_2() { wizInit(); -// mqttCommInit(); + mqttCommInit(); cmdHandlerInit(); -// frontendInit(); -// frontendSetThreshold(240); + frontendInit(); + frontendSetThreshold(240); -// schAdd(scheduleMBusRequest, NULL, 0, 1000); -// schAdd(triggerMBusRequest, NULL, 0, 100); + schAdd(scheduleMBusRequest, NULL, 0, 1000); + schAdd(triggerMBusRequest, NULL, 0, 100); } void my_loop() {