set devicename
This commit is contained in:
@ -51,13 +51,57 @@ static bool showConfigCmd(uint8_t argc, char **args) {
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
||||
static bool setDeviceNameCmd(uint8_t argc, char **args) {
|
||||
bool retCode = true;
|
||||
|
||||
char *newDeviceName = args[2];
|
||||
if (strlen(newDeviceName) >= sizeof(t_configBlock.deviceName)) {
|
||||
sendString("given new device name is too long\n\r");
|
||||
retCode = false;
|
||||
} else {
|
||||
sendFormatString("set device name to %s\n\r", newDeviceName);
|
||||
|
||||
t_configBlock configBlock;
|
||||
eepromReadConfigBlock(&configBlock);
|
||||
strcpy(configBlock.deviceName, newDeviceName);
|
||||
eepromWriteConfigBlock(&configBlock);
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
const cmd_t SET_COMMANDS[] = {
|
||||
{ .name = "devicename", .cmdFunc = setDeviceNameCmd,
|
||||
.help = \
|
||||
"devicename ........................... Name of this device\n\r"
|
||||
},
|
||||
{ .name = "END_OF_CMDS", .help = "",.cmdFunc = NULL }
|
||||
};
|
||||
const char[] UNKNOWN_PARAMETER = "unknown parameter";
|
||||
|
||||
static bool setCmd(uint8_t argc, char **args) {
|
||||
bool retCode = false;
|
||||
uint8_t *messageToSend = NULL;
|
||||
|
||||
if (argc >= 2) {
|
||||
if (0 == strcmp("?", args[1])) {
|
||||
sendString("You can set the following parameters:\n\r");
|
||||
retCode = true;
|
||||
} else {
|
||||
uint8_t cmdIdx = 0;
|
||||
while (true) {
|
||||
cmd_t command = SET_COMMANDS[cmdIdx];
|
||||
if (0 == strcmp("END_OF_CMDS", command.name)) {
|
||||
messageToSend = (uint8_t*) UNKNOWN_PARAMETER;
|
||||
break;
|
||||
}
|
||||
if (0 == strcmp(cmd, command.name)) {
|
||||
messageToSend = command.cmdFunc(argc, args) ? (uint8_t*)OK_MSG : (uint8_t*)FAILED_MSG;
|
||||
break;
|
||||
}
|
||||
cmdIdx++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +118,7 @@ static bool restartCmd(uint8_t argc, char **args) {
|
||||
|
||||
const cmd_t CONFIG_COMMANDS[] = {
|
||||
{ .name = "show", .cmdFunc = showConfigCmd,
|
||||
.help = \
|
||||
.help = \
|
||||
"show ................................. Show the configuration\n\r"
|
||||
},
|
||||
{ .name = "set", .cmdFunc = setCmd,
|
||||
|
Reference in New Issue
Block a user