diff --git a/cube/User/Inc/cmdHelper.h b/cube/User/Inc/cmdHelper.h new file mode 100644 index 0000000..744b324 --- /dev/null +++ b/cube/User/Inc/cmdHelper.h @@ -0,0 +1,23 @@ +#ifndef _CMDHELPER_H_ +#define _CMDHELPER_H_ + +#include +#include + + +typedef bool (*cmdFunc_t)(uint8_t argc, char **args); + +typedef struct { + char name[16]; + char help[512]; + cmdFunc_t cmdFunc; +} cmd_t; + +void sendString(const char *buf); +bool sendFormatString(const char *format, ...); + +const cmd_t *getRegularCommands(); +const cmd_t *getAdminCommands(); +const cmd_t *getConfigCommands(); + +#endif /* _CMDHELPER_H_ */ diff --git a/cube/User/Src/adminCmds.c b/cube/User/Src/adminCmds.c new file mode 100644 index 0000000..92e9dca --- /dev/null +++ b/cube/User/Src/adminCmds.c @@ -0,0 +1,81 @@ +#include +#include +#include + +#include +#include + + +// 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 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; +} + + + +const 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 cmd_t *getAdminCommands() { + return ADMIN_COMMANDS; +} \ No newline at end of file diff --git a/cube/User/Src/configCmds.c b/cube/User/Src/configCmds.c new file mode 100644 index 0000000..b063b4d --- /dev/null +++ b/cube/User/Src/configCmds.c @@ -0,0 +1,76 @@ +#include +#include + +#include +#include + + +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 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 } +}; + + + +const cmd_t *getConfigCommands() { + return CONFIG_COMMANDS; +} \ No newline at end of file diff --git a/cube/User/Src/regularCmds.c b/cube/User/Src/regularCmds.c new file mode 100644 index 0000000..5e8d578 --- /dev/null +++ b/cube/User/Src/regularCmds.c @@ -0,0 +1,37 @@ +#include +#include + +#include + + +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; +} + + + +const 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 cmd_t *getRegularCommands() { + return COMMANDS; +} \ No newline at end of file