set int32 value
This commit is contained in:
parent
9bd23218d5
commit
296c6270c0
@ -8,7 +8,7 @@
|
||||
typedef bool (*cmdFunc_t)(uint8_t argc, char **args);
|
||||
|
||||
typedef struct {
|
||||
char name[16];
|
||||
char name[24];
|
||||
char help[512];
|
||||
cmdFunc_t cmdFunc;
|
||||
} cmd_t;
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
@ -13,6 +14,8 @@ static bool showConfigCmd(uint8_t argc, char **args) {
|
||||
|
||||
t_configBlock configBlock;
|
||||
eepromReadConfigBlock(&configBlock);
|
||||
sendString("This is the saved configuration.\n\r");
|
||||
sendString("It is not necessarily the active configuration.\n\r");
|
||||
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],
|
||||
@ -54,14 +57,14 @@ static bool showConfigCmd(uint8_t argc, char **args) {
|
||||
|
||||
|
||||
|
||||
static bool setStringParameterCmd(uint8_t argc, char **args, size_t offset) {
|
||||
static bool setStringParameterCmd(uint8_t argc, char **args, size_t offset, size_t length) {
|
||||
bool retCode = true;
|
||||
|
||||
t_configBlock configBlock;
|
||||
char *parameterName = args[1];
|
||||
char *newParameterValue = args[2];
|
||||
if (strlen(newParameterValue) >= sizeof(configBlock.deviceName)) { // FIXME
|
||||
sendFormatString("given new value for %s is too long\n\r", parameterName);
|
||||
if (strlen(newParameterValue) >= length) {
|
||||
sendString("given new value for is too long\n\r");
|
||||
retCode = false;
|
||||
} else {
|
||||
sendFormatString("set %s to %s\n\r", parameterName, newParameterValue);
|
||||
@ -74,35 +77,78 @@ static bool setStringParameterCmd(uint8_t argc, char **args, size_t offset) {
|
||||
return retCode;
|
||||
}
|
||||
|
||||
static bool setInt32ParameterCmd(uint8_t argc, char **args, size_t offset, int32_t minV, int32_t maxV) {
|
||||
bool retCode = true;
|
||||
|
||||
t_configBlock configBlock;
|
||||
char *parameterName = args[1];
|
||||
char *newParameterValue = args[2];
|
||||
long int value = strtol(newParameterValue, NULL, 10);
|
||||
if (value < minV) {
|
||||
sendString("value is too small\n\r");
|
||||
retCode = false;
|
||||
} else if (value > maxV) {
|
||||
sendString("value is too large\n\r");
|
||||
} else {
|
||||
int32_t v = (int32_t) value;
|
||||
sendFormatString("set %s to %ld\n\r", parameterName, v);
|
||||
|
||||
eepromReadConfigBlock(&configBlock);
|
||||
*((int32_t*)(((uint8_t*)&configBlock) + offset)) = v;
|
||||
eepromWriteConfigBlock(&configBlock);
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
||||
static bool setDeviceNameCmd(uint8_t argc, char **args) {
|
||||
return setStringParameterCmd(argc, args, offsetof(t_configBlock, deviceName));
|
||||
return setStringParameterCmd(argc, args,
|
||||
offsetof(t_configBlock, deviceName),
|
||||
sizeof(((t_configBlock*)0)->deviceName));
|
||||
}
|
||||
|
||||
static bool setBrokerNameCmd(uint8_t argc, char **args) {
|
||||
return setStringParameterCmd(argc, args, offsetof(t_configBlock, brokerName));
|
||||
return setStringParameterCmd(argc, args,
|
||||
offsetof(t_configBlock, brokerName),
|
||||
sizeof(((t_configBlock*)0)->brokerName));
|
||||
}
|
||||
|
||||
static bool setSyslogServerCmd(uint8_t argc, char **args) {
|
||||
return setStringParameterCmd(argc, args, offsetof(t_configBlock, syslogServerName));
|
||||
return setStringParameterCmd(argc, args,
|
||||
offsetof(t_configBlock, syslogServerName),
|
||||
sizeof(((t_configBlock*)0)->syslogServerName));
|
||||
}
|
||||
|
||||
static bool setWatchdogTopicCmd(uint8_t argc, char **args) {
|
||||
return setStringParameterCmd(argc, args, offsetof(t_configBlock, watchdogTopic));
|
||||
return setStringParameterCmd(argc, args,
|
||||
offsetof(t_configBlock, watchdogTopic),
|
||||
sizeof(((t_configBlock*)0)->watchdogTopic));
|
||||
}
|
||||
|
||||
static bool setStartupTopicCmd(uint8_t argc, char **args) {
|
||||
return setStringParameterCmd(argc, args, offsetof(t_configBlock, startupTopic));
|
||||
return setStringParameterCmd(argc, args,
|
||||
offsetof(t_configBlock, startupTopic),
|
||||
sizeof(((t_configBlock*)0)->startupTopic));
|
||||
}
|
||||
|
||||
static bool setStatusTopicCmd(uint8_t argc, char **args) {
|
||||
return setStringParameterCmd(argc, args, offsetof(t_configBlock, statusTopic));
|
||||
return setStringParameterCmd(argc, args,
|
||||
offsetof(t_configBlock, statusTopic),
|
||||
sizeof(((t_configBlock*)0)->statusTopic));
|
||||
}
|
||||
|
||||
static bool setMbusDataTopicCmd(uint8_t argc, char **args) {
|
||||
return setStringParameterCmd(argc, args, offsetof(t_configBlock, mbusDataTopic));
|
||||
return setStringParameterCmd(argc, args,
|
||||
offsetof(t_configBlock, mbusDataTopic),
|
||||
sizeof(((t_configBlock*)0)->mbusDataTopic));
|
||||
}
|
||||
|
||||
static bool setFrontendThresholdCmd(uint8_t argc, char **args) {
|
||||
return setInt32ParameterCmd(argc, args,
|
||||
offsetof(t_configBlock, frontendThreshold),
|
||||
0, 1023);
|
||||
}
|
||||
|
||||
const static cmd_t SET_COMMANDS[] = {
|
||||
{ .name = "devicename", .cmdFunc = setDeviceNameCmd,
|
||||
@ -133,6 +179,10 @@ const static cmd_t SET_COMMANDS[] = {
|
||||
.help = \
|
||||
"mbusdatatopic ........................ MBus Data Topic\n\r"
|
||||
},
|
||||
{ .name = "frontendthreshold", .cmdFunc = setFrontendThresholdCmd,
|
||||
.help = \
|
||||
"frontendthreshold ........................ Frontend Threshold (default: 240)\n\r"
|
||||
},
|
||||
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user