cmd handler stuff
This commit is contained in:
@ -10,6 +10,7 @@
|
|||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
#include <PontCoopScheduler.h>
|
#include <PontCoopScheduler.h>
|
||||||
#include <wizHelper.h>
|
#include <wizHelper.h>
|
||||||
|
#include <mbusComm.h>
|
||||||
|
|
||||||
|
|
||||||
extern const uint8_t CMD_SOCK;
|
extern const uint8_t CMD_SOCK;
|
||||||
@ -28,12 +29,25 @@ typedef enum {
|
|||||||
CH_ERROR
|
CH_ERROR
|
||||||
} chState_t;
|
} 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 0 to continue waiting for input
|
||||||
// returns -1 to close the connection
|
// returns -1 to close the connection
|
||||||
// returns 1 to toggle to config mode
|
// returns 1 to toggle to config mode
|
||||||
// returns 2 to toggle back to default mode
|
// returns 2 to toggle back to default mode
|
||||||
int8_t cmdExecuteCommand(uint8_t *cmd, bool resetConfigMode) {
|
int8_t cmdExecuteCommand(uint8_t *cmd, bool resetConfigMode) {
|
||||||
const static uint8_t GOODBYE_MSG[] = "Good bye\n\r";
|
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;
|
static bool configMode = false;
|
||||||
|
|
||||||
if (resetConfigMode) {
|
if (resetConfigMode) {
|
||||||
@ -43,7 +57,7 @@ int8_t cmdExecuteCommand(uint8_t *cmd, bool resetConfigMode) {
|
|||||||
int8_t retCode = 0;
|
int8_t retCode = 0;
|
||||||
coloredMsg(LOG_YELLOW, "cec, cmd is %s", cmd);
|
coloredMsg(LOG_YELLOW, "cec, cmd is %s", cmd);
|
||||||
if (0 == strcmp(cmd, "quit")) {
|
if (0 == strcmp(cmd, "quit")) {
|
||||||
send(CMD_SOCK, GOODBYE_MSG, sizeof(GOODBYE_MSG));
|
messageToSend = GOODBYE_MSG;
|
||||||
retCode = -1;
|
retCode = -1;
|
||||||
} else if (0 == strcmp(cmd, "enable")) {
|
} else if (0 == strcmp(cmd, "enable")) {
|
||||||
coloredMsg(LOG_YELLOW, "cec, enable config mode");
|
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");
|
coloredMsg(LOG_YELLOW, "cec, disable config mode");
|
||||||
configMode = false;
|
configMode = false;
|
||||||
retCode = 2;
|
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;
|
return retCode;
|
||||||
|
@ -193,14 +193,14 @@ void my_setup_2() {
|
|||||||
|
|
||||||
wizInit();
|
wizInit();
|
||||||
|
|
||||||
// mqttCommInit();
|
mqttCommInit();
|
||||||
cmdHandlerInit();
|
cmdHandlerInit();
|
||||||
|
|
||||||
// frontendInit();
|
frontendInit();
|
||||||
// frontendSetThreshold(240);
|
frontendSetThreshold(240);
|
||||||
|
|
||||||
// schAdd(scheduleMBusRequest, NULL, 0, 1000);
|
schAdd(scheduleMBusRequest, NULL, 0, 1000);
|
||||||
// schAdd(triggerMBusRequest, NULL, 0, 100);
|
schAdd(triggerMBusRequest, NULL, 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_loop() {
|
void my_loop() {
|
||||||
|
Reference in New Issue
Block a user