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