ommands
This commit is contained in:
parent
e239655e7f
commit
54e6e448d8
@ -26,7 +26,8 @@ typedef struct {
|
||||
|
||||
typedef enum {
|
||||
MBCRR_TRIGGERED = 0,
|
||||
MBCRR_BUSY = 1
|
||||
MBCRR_BUSY = 1,
|
||||
MBCRR_DISABLED = 2
|
||||
} e_mbusCommRequestResult;
|
||||
|
||||
typedef struct {
|
||||
@ -35,6 +36,7 @@ typedef struct {
|
||||
} t_mbusCommStats;
|
||||
|
||||
e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice);
|
||||
void mbusCommEnable(bool enable);
|
||||
void mbusCommTxCpltCallback(UART_HandleTypeDef *huart);
|
||||
void mbusCommRxCpltCallback(UART_HandleTypeDef *huart);
|
||||
void mbusCommSetStats(t_mbusCommStats stats);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <PontCoopScheduler.h>
|
||||
#include <wizHelper.h>
|
||||
#include <mbusComm.h>
|
||||
#include <loopCtrl.h>
|
||||
|
||||
|
||||
extern const uint8_t CMD_SOCK;
|
||||
@ -61,6 +62,37 @@ bool globalStatsCmd(uint8_t argc, char **args) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mbusCommEnableCmd(uint8_t argc, char **args) {
|
||||
bool retCode = true;
|
||||
if (argc == 2) {
|
||||
if (0 == strcmp("false", args[1])) {
|
||||
mbusCommEnable(false);
|
||||
} else if (0 == strcmp("true", args[1])) {
|
||||
mbusCommEnable(true);
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
bool loopEnableCmd(uint8_t argc, char **args) {
|
||||
bool retCode = true;
|
||||
if (argc == 2) {
|
||||
if (0 == strcmp("false", args[1])) {
|
||||
loopDisable();
|
||||
} else if (0 == strcmp("true", args[1])) {
|
||||
loopEnable();
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
} else {
|
||||
retCode = false;
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
const static cmd_t COMMANDS[] = {
|
||||
{ .requiredConfigMode = true, .name = "clear", .cmdFunc = clearCmd,
|
||||
@ -69,6 +101,19 @@ const static cmd_t COMMANDS[] = {
|
||||
" statistics\n\r" \
|
||||
" Required configuration mode\n\r"
|
||||
},
|
||||
{ .requiredConfigMode = true, .name = "mbusCommEnable", .cmdFunc = mbusCommEnableCmd,
|
||||
.help = \
|
||||
"mbusCommEnable true|false ............ Enables or disables the Meterbus\n\r" \
|
||||
" communication\n\r"
|
||||
},
|
||||
{ .requiredConfigMode = true, .name = "loopEnable", .cmdFunc = loopEnableCmd,
|
||||
.help = \
|
||||
"loopEnable true|false ................ Enables or disables the loop.\n\r" \
|
||||
" Disable Meterbus communication\n\r" \
|
||||
" first if you want to disable the\n\r" \
|
||||
" for a longer time, otherwise the\n\r" \
|
||||
" request will enable it again\n\r"
|
||||
},
|
||||
{ .requiredConfigMode = false, .name = "globalStats", .cmdFunc = globalStatsCmd,
|
||||
.help = \
|
||||
"globalStats .......................... Show the global statistics\n\r" \
|
||||
|
@ -90,6 +90,7 @@ static t_mbusCommHandle mbusCommHandle = { .state = MBCS_IDLE, .retryCnt = 0, .c
|
||||
|
||||
static t_mbusCommStats mbusCommStats = { .requestCnt = 0, .errorCnt = 0 };
|
||||
|
||||
static bool mbusCommEnabled = true;
|
||||
|
||||
void mbusCommSetStats(t_mbusCommStats stats) {
|
||||
mbusCommStats = stats;
|
||||
@ -424,29 +425,37 @@ void mbusCommRxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
}
|
||||
}
|
||||
|
||||
void mbusCommEnable(bool enable) {
|
||||
mbusCommEnabled = enable;
|
||||
}
|
||||
|
||||
e_mbusCommRequestResult mbusCommRequest(t_mbusDevice *mbusDevice) {
|
||||
e_mbusCommRequestResult res = MBCRR_BUSY;
|
||||
|
||||
if (mbusCommHandle.state == MBCS_IDLE) {
|
||||
coloredMsg(LOG_BLUE, "*** NEW REQUEST %s R:%d F:%d GRC:%d GEC:%d ***",
|
||||
mbusDevice->deviceName,
|
||||
mbusDevice->requests,
|
||||
mbusDevice->failures,
|
||||
mbusCommStats.requestCnt,
|
||||
mbusCommStats.errorCnt);
|
||||
if (mbusCommEnabled) {
|
||||
if (mbusCommHandle.state == MBCS_IDLE) {
|
||||
coloredMsg(LOG_BLUE, "*** NEW REQUEST %s R:%d F:%d GRC:%d GEC:%d ***",
|
||||
mbusDevice->deviceName,
|
||||
mbusDevice->requests,
|
||||
mbusDevice->failures,
|
||||
mbusCommStats.requestCnt,
|
||||
mbusCommStats.errorCnt);
|
||||
|
||||
mbusCommHandle.state = MBCS_SEND;
|
||||
mbusCommHandle.retryCnt = 0;
|
||||
mbusCommHandle.cmd = MBUS_QUERY_CMD;
|
||||
mbusCommHandle.addr = mbusDevice->address;
|
||||
mbusCommHandle.device = mbusDevice;
|
||||
mbusDevice->requests += 1;
|
||||
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
|
||||
res = MBCRR_TRIGGERED;
|
||||
mbusCommHandle.state = MBCS_SEND;
|
||||
mbusCommHandle.retryCnt = 0;
|
||||
mbusCommHandle.cmd = MBUS_QUERY_CMD;
|
||||
mbusCommHandle.addr = mbusDevice->address;
|
||||
mbusCommHandle.device = mbusDevice;
|
||||
mbusDevice->requests += 1;
|
||||
schAdd(handleRequestEngine, (void*) &mbusCommHandle, 0, 0);
|
||||
res = MBCRR_TRIGGERED;
|
||||
|
||||
mbusCommStats.requestCnt += 1;
|
||||
mbusCommStats.requestCnt += 1;
|
||||
}
|
||||
} else {
|
||||
res = MBCRR_DISABLED;
|
||||
}
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user