From 056a9e9edc8054900155a787a963083e5c23b790 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Thu, 17 Dec 2020 16:32:17 +0100 Subject: [PATCH] deleteDevice --- cube/User/Src/configCmds.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cube/User/Src/configCmds.c b/cube/User/Src/configCmds.c index 48924d0..46e0157 100644 --- a/cube/User/Src/configCmds.c +++ b/cube/User/Src/configCmds.c @@ -225,6 +225,22 @@ static bool addDeviceCmd(uint8_t argc, char **args) { return retCode; } +static bool deleteDeviceCmd(uint8_t argc, char **args) { + long int rawIndex = strtol(args[1], NULL, 10); + if (rawIndex < 0 || rawIndex > getConfig()->numOfDeviceBlocks) { + sendFormatString("illegal index, must be greater 0 and less %d\n\r", getConfig()->numOfDeviceBlocks); + return false; + } + uint8_t index = (uint8_t) rawIndex; + + t_deviceBlock deviceBlock; + eepromReadDeviceBlock(index, &deviceBlock); + deviceBlock.period = -1; + eepromWriteDeviceBlock(index, &deviceBlock); + + return true; +} + static bool changeDeviceCmd(uint8_t argc, char **args) { if (strcmp(args[1], "help") == 0) { sendString("First argument: index of device in list\n\r"); @@ -265,7 +281,7 @@ static bool listDevicesCmd(uint8_t argc, char **args) { for (uint8_t i = 0; i < getConfig()->numOfDeviceBlocks; i++) { t_deviceBlock deviceBlock; eepromReadDeviceBlock(i, &deviceBlock); - sendFormatString(" Index: %d\n\r", i); + sendFormatString("Index: %d\n\r", i); sendFormatString(" Name: %s, Address: %d, Period: %d\n\r", deviceBlock.deviceName, deviceBlock.address, deviceBlock.period); for (uint8_t i = 0; i < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; i++) { @@ -393,6 +409,11 @@ const cmd_t CONFIG_COMMANDS[] = { .help = \ "listDevices .......................... List the configured devices\n\r" }, + { .name = "deleteDevice", .cmdFunc = deleteDeviceCmd, + .help = \ + "deleteDevice ......................... Delete a device\n\r" \ + " Argument: index\n\r" + }, { .name = "restart", .cmdFunc = restartCmd, .help = \ "restart .............................. Restart the system,\n\r" \