device configuration prepared
This commit is contained in:
parent
f019f7eb77
commit
765c3b077c
@ -37,7 +37,7 @@ BUILD_DIR = build
|
|||||||
######################################
|
######################################
|
||||||
# C sources
|
# C sources
|
||||||
C_SOURCES = \
|
C_SOURCES = \
|
||||||
User/Src/config.c User/Src/oled.c User/Src/cmdHandler.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/ports.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
|
User/Src/regularCmds.c User/Src/adminCmds.c User/Src/configCmds.c User/Src/config.c User/Src/oled.c User/Src/cmdHandler.c User/Src/eeprom.c User/Src/frontend.c User/Src/logger.c User/Src/loopCtrl.c User/Src/main2.c User/Src/mbusComm.c User/Src/mbusParserExt.c User/Src/mqttComm.c User/Src/ports.c User/Src/ringbuffer.c User/Src/show.c User/Src/utils.c User/Src/wizHelper.c hottislib/PontCoopScheduler.c \
|
||||||
libmbus/mbus/mbus-protocol.c \
|
libmbus/mbus/mbus-protocol.c \
|
||||||
Core/Src/main.c \
|
Core/Src/main.c \
|
||||||
Core/Src/gpio.c \
|
Core/Src/gpio.c \
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <cmdHandler.h>
|
#include <cmdHandler.h>
|
||||||
|
#include <cmdHelper.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -12,10 +13,6 @@
|
|||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
#include <PontCoopScheduler.h>
|
#include <PontCoopScheduler.h>
|
||||||
#include <wizHelper.h>
|
#include <wizHelper.h>
|
||||||
#include <mbusComm.h>
|
|
||||||
#include <loopCtrl.h>
|
|
||||||
#include <config.h>
|
|
||||||
#include <eeprom.h>
|
|
||||||
|
|
||||||
extern const uint8_t CMD_SOCK;
|
extern const uint8_t CMD_SOCK;
|
||||||
|
|
||||||
@ -33,21 +30,11 @@ typedef enum {
|
|||||||
CH_ERROR
|
CH_ERROR
|
||||||
} chState_t;
|
} chState_t;
|
||||||
|
|
||||||
|
void sendString(const char *buf) {
|
||||||
typedef bool (*cmdFunc_t)(uint8_t argc, char **args);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char name[16];
|
|
||||||
char help[512];
|
|
||||||
cmdFunc_t cmdFunc;
|
|
||||||
} cmd_t;
|
|
||||||
|
|
||||||
|
|
||||||
static void sendString(const char *buf) {
|
|
||||||
send(CMD_SOCK, (uint8_t*)buf, strlen(buf));
|
send(CMD_SOCK, (uint8_t*)buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sendFormatString(const char *format, ...) {
|
bool sendFormatString(const char *format, ...) {
|
||||||
bool retCode = true;
|
bool retCode = true;
|
||||||
va_list vl;
|
va_list vl;
|
||||||
va_start(vl, format);
|
va_start(vl, format);
|
||||||
@ -59,162 +46,6 @@ static bool sendFormatString(const char *format, ...) {
|
|||||||
return retCode;
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear statistics
|
|
||||||
static bool clearCmd(uint8_t argc, char **args) {
|
|
||||||
t_mbusCommStats zeroedStats = { .mbusRequestCnt = 0, .mbusErrorCnt = 0, .uartOctetCnt = 0, .uartOverrunCnt = 0, .uartFramingErrCnt = 0, .uartParityErrCnt = 0, .uartNoiseErrCnt = 0 };
|
|
||||||
mbusCommSetStats(zeroedStats);
|
|
||||||
coloredMsg(LOG_YELLOW, true, "ch cc global statistics cleared");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool globalStatsCmd(uint8_t argc, char **args) {
|
|
||||||
t_mbusCommStats *stats = mbusCommGetStats();
|
|
||||||
sendFormatString(\
|
|
||||||
"Global statistics\n\r" \
|
|
||||||
" Meterbus Requests: %ld\n\r" \
|
|
||||||
" Meterbus Errors: %ld\n\r" \
|
|
||||||
" UART Octets: %ld\n\r" \
|
|
||||||
" UART Overruns: %ld\n\r" \
|
|
||||||
" UART Framing Errs: %ld\n\r" \
|
|
||||||
" UART Parity Errs: %ld\n\r" \
|
|
||||||
" UART Noise Errs: %ld\n\r",
|
|
||||||
stats->mbusRequestCnt, stats->mbusErrorCnt,
|
|
||||||
stats->uartOctetCnt, stats->uartOverrunCnt, stats->uartFramingErrCnt, stats->uartParityErrCnt, stats->uartNoiseErrCnt
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool mbusCommEnableCmd(uint8_t argc, char **args) {
|
|
||||||
bool retCode = true;
|
|
||||||
if (argc == 2) {
|
|
||||||
if (0 == strcmp("false", args[1])) {
|
|
||||||
mbusCommEnable(false);
|
|
||||||
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication disabled");
|
|
||||||
} else if (0 == strcmp("true", args[1])) {
|
|
||||||
mbusCommEnable(true);
|
|
||||||
coloredMsg(LOG_YELLOW, true, "ch mcec Meterbus communication enabled");
|
|
||||||
} else {
|
|
||||||
retCode = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
retCode = false;
|
|
||||||
}
|
|
||||||
return retCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool loopEnableCmd(uint8_t argc, char **args) {
|
|
||||||
bool retCode = true;
|
|
||||||
if (argc == 2) {
|
|
||||||
if (0 == strcmp("false", args[1])) {
|
|
||||||
loopDisable();
|
|
||||||
coloredMsg(LOG_YELLOW, true, "ch lec loop disabled");
|
|
||||||
} else if (0 == strcmp("true", args[1])) {
|
|
||||||
loopEnable();
|
|
||||||
coloredMsg(LOG_YELLOW, true, "ch lec loop enabled");
|
|
||||||
} else {
|
|
||||||
retCode = false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
retCode = false;
|
|
||||||
}
|
|
||||||
return retCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool showConfigCmd(uint8_t argc, char **args) {
|
|
||||||
bool retCode = true;
|
|
||||||
|
|
||||||
t_configBlock configBlock;
|
|
||||||
eepromReadConfigBlock(&configBlock);
|
|
||||||
sendFormatString("configMagic: %lx\n\r", configBlock.configMagic);
|
|
||||||
sendFormatString("deviceName: %s\n\r", configBlock.deviceName);
|
|
||||||
sendFormatString("MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n\r", configBlock.macAddress[0],
|
|
||||||
configBlock.macAddress[1],
|
|
||||||
configBlock.macAddress[2],
|
|
||||||
configBlock.macAddress[3],
|
|
||||||
configBlock.macAddress[4],
|
|
||||||
configBlock.macAddress[5]);
|
|
||||||
sendFormatString("frontend threshold: %ld\n\r", configBlock.frontendThreshold);
|
|
||||||
sendFormatString("broker: %s\n\r", configBlock.brokerName);
|
|
||||||
sendFormatString("watchdogTopic: %s\n\r", configBlock.watchdogTopic);
|
|
||||||
sendFormatString("startupTopic: %s\n\r", configBlock.startupTopic);
|
|
||||||
sendFormatString("statusTopic: %s\n\r", configBlock.statusTopic);
|
|
||||||
sendFormatString("mbusDataTopic: %s\n\r", configBlock.mbusDataTopic);
|
|
||||||
sendFormatString("syslog server: %s\n\r", configBlock.syslogServerName);
|
|
||||||
sendFormatString("device block cnt: %d\n\r", configBlock.numOfDeviceBlocks);
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < configBlock.numOfDeviceBlocks; i++) {
|
|
||||||
t_deviceBlock tmpDeviceBlock;
|
|
||||||
eepromReadDeviceBlock(i, &tmpDeviceBlock);
|
|
||||||
if (tmpDeviceBlock.deviceMagic == DEVICE_MAGIC) {
|
|
||||||
sendFormatString("device %d: \n\r", i);
|
|
||||||
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
|
|
||||||
tmpDeviceBlock.deviceName, tmpDeviceBlock.address, tmpDeviceBlock.period);
|
|
||||||
sendFormatString(" Considered Fields: %d %d %d %d\n\r",
|
|
||||||
tmpDeviceBlock.consideredField[0],
|
|
||||||
tmpDeviceBlock.consideredField[1],
|
|
||||||
tmpDeviceBlock.consideredField[2],
|
|
||||||
tmpDeviceBlock.consideredField[3]);
|
|
||||||
if (tmpDeviceBlock.deviceMagic != DEVICE_MAGIC) {
|
|
||||||
sendString(" DEVICE MAGIC DOES NOT MATCH\n\r");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return retCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool restartCmd(uint8_t argc, char **args) {
|
|
||||||
HAL_NVIC_SystemReset();
|
|
||||||
// you want come here ...
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const static cmd_t COMMANDS[] = {
|
|
||||||
{ .name = "globalStats", .cmdFunc = globalStatsCmd,
|
|
||||||
.help = \
|
|
||||||
"globalStats .......................... Show the global statistics\n\r" \
|
|
||||||
" counters requestCnt and errorCnt\n\r"
|
|
||||||
},
|
|
||||||
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
const static cmd_t ADMIN_COMMANDS[] = {
|
|
||||||
{ .name = "clear", .cmdFunc = clearCmd,
|
|
||||||
.help = \
|
|
||||||
"clear ................................ Clears the global Meterbus\n\r" \
|
|
||||||
" statistics\n\r"
|
|
||||||
},
|
|
||||||
{ .name = "mbusCommEnable", .cmdFunc = mbusCommEnableCmd,
|
|
||||||
.help = \
|
|
||||||
"mbusCommEnable true|false ............ Enables or disables the Meterbus\n\r" \
|
|
||||||
" communication\n\r"
|
|
||||||
},
|
|
||||||
{ .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"
|
|
||||||
},
|
|
||||||
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
const static cmd_t CONFIG_COMMANDS[] = {
|
|
||||||
{ .name = "show", .cmdFunc = showConfigCmd,
|
|
||||||
.help = \
|
|
||||||
"show ................................. Show the configuration\n\r"
|
|
||||||
},
|
|
||||||
{ .name = "restart", .cmdFunc = restartCmd,
|
|
||||||
.help = \
|
|
||||||
"restart .............................. Restart the system,\n\r" \
|
|
||||||
" Required to reload config\n\r"
|
|
||||||
},
|
|
||||||
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// 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 admin mode
|
// returns 1 to toggle to admin mode
|
||||||
@ -251,11 +82,11 @@ static int8_t cmdExecuteCommand(uint8_t *cmdLine, bool resetSpecialModes) {
|
|||||||
configMode = false;
|
configMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_t const * commands = COMMANDS;
|
cmd_t const * commands = getRegularCommands();
|
||||||
if (adminMode) {
|
if (adminMode) {
|
||||||
commands = ADMIN_COMMANDS;
|
commands = getAdminCommands();
|
||||||
} else if (configMode) {
|
} else if (configMode) {
|
||||||
commands = CONFIG_COMMANDS;
|
commands = getConfigCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
coloredMsg(LOG_YELLOW, false, "ch cec cmdLine is %s", cmdLine);;
|
coloredMsg(LOG_YELLOW, false, "ch cec cmdLine is %s", cmdLine);;
|
||||||
@ -482,9 +313,9 @@ static void cmdHandlerEngine(void *handle) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CH_DISCONNECT_WAIT:
|
case CH_DISCONNECT_WAIT:
|
||||||
coloredMsg(LOG_YELLOW, false, "ch che waiting after disconnect");
|
//coloredMsg(LOG_YELLOW, false, "ch che waiting after disconnect");
|
||||||
sockState = getSn_SR(CMD_SOCK);
|
sockState = getSn_SR(CMD_SOCK);
|
||||||
coloredMsg(LOG_YELLOW, false, "ch che sockState is 0x%02x", sockState);
|
//coloredMsg(LOG_YELLOW, false, "ch che sockState is 0x%02x", sockState);
|
||||||
if (sockState == SOCK_CLOSED) {
|
if (sockState == SOCK_CLOSED) {
|
||||||
coloredMsg(LOG_YELLOW, true, "ch che socket is closed now");
|
coloredMsg(LOG_YELLOW, true, "ch che socket is closed now");
|
||||||
state = CH_INIT;
|
state = CH_INIT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user