split commands
This commit is contained in:
parent
765c3b077c
commit
fe1b2e5b40
23
cube/User/Inc/cmdHelper.h
Normal file
23
cube/User/Inc/cmdHelper.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef _CMDHELPER_H_
|
||||||
|
#define _CMDHELPER_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
|
||||||
|
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_ */
|
81
cube/User/Src/adminCmds.c
Normal file
81
cube/User/Src/adminCmds.c
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#include <cmdHelper.h>
|
||||||
|
#include <logger.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <mbusComm.h>
|
||||||
|
#include <loopCtrl.h>
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
76
cube/User/Src/configCmds.c
Normal file
76
cube/User/Src/configCmds.c
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include <cmdHelper.h>
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
|
#include <eeprom.h>
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
37
cube/User/Src/regularCmds.c
Normal file
37
cube/User/Src/regularCmds.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include <cmdHelper.h>
|
||||||
|
#include <logger.h>
|
||||||
|
|
||||||
|
#include <mbusComm.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user