diff --git a/cube/User/Src/configCmds.c b/cube/User/Src/configCmds.c index 6cb8233..e6217d2 100644 --- a/cube/User/Src/configCmds.c +++ b/cube/User/Src/configCmds.c @@ -167,40 +167,51 @@ static bool makeDevice(uint8_t argOffset, uint8_t argc, char **args, t_deviceBlo } char *deviceName = args[1 + argOffset]; - if (strlen(deviceName) >= sizeof(deviceBlock->deviceName)) { - sendString("devicename too long\n\r"); - return false; - } - strcpy(deviceBlock->deviceName, deviceName); - - long int rawAddress = strtol(args[2 + argOffset], NULL, 10); - if (rawAddress < 1 || rawAddress > 254) { - sendString("illegal address\n\r"); - return false; - } - deviceBlock->address = (uint8_t)rawAddress; - - long int rawPeriod = strtol(args[3 + argOffset], NULL, 10); - if (rawPeriod < 0 || rawPeriod > 86400) { - sendString("illegal period\n\r"); - return false; - } - deviceBlock->period = (int32_t) rawPeriod; - - for (uint8_t i = 0; i < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; i++) { - long int rawFieldNum = strtol(args[4 + i + argOffset], NULL, 10); - if (rawFieldNum < -1 || rawFieldNum > 127) { - sendString("illegal considered field index\n\r"); + if (strcmp(deviceName, "*") != 0) { + if (strlen(deviceName) >= sizeof(deviceBlock->deviceName)) { + sendString("devicename too long\n\r"); return false; } - deviceBlock->consideredField[i] = (int8_t) rawFieldNum; + strcpy(deviceBlock->deviceName, deviceName); + } + + char *rawAddressStr = args[2 + argOffset]; + if (strcmp(rawAddressStr, "*") != 0) { + long int rawAddress = strtol(rawAddressStr, NULL, 10); + if (rawAddress < 1 || rawAddress > 254) { + sendString("illegal address\n\r"); + return false; + } + deviceBlock->address = (uint8_t)rawAddress; + } + + char *rawPeriodStr = args[3 + argOffset]; + if (strcmp(rawPeriodStr, "*") != 0) { + long int rawPeriod = strtol(rawPeriodStr, NULL, 10); + if (rawPeriod < 0 || rawPeriod > 86400) { + sendString("illegal period\n\r"); + return false; + } + deviceBlock->period = (int32_t) rawPeriod; + } + + for (uint8_t i = 0; i < MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS; i++) { + char *rawFieldNumStr = args[4 + i + argOffset]; + if (strcmp(rawFieldNumStr, "*") != 0) { + long int rawFieldNum = strtol(rawFieldNumStr, NULL, 10); + if (rawFieldNum < -1 || rawFieldNum > 127) { + sendString("illegal considered field index\n\r"); + return false; + } + deviceBlock->consideredField[i] = (int8_t) rawFieldNum; + } } return true; } static bool addDeviceCmd(uint8_t argc, char **args) { - t_deviceBlock deviceBlock; + t_deviceBlock deviceBlock = { .deviceName = "", .address = 0, .period = 0, .consideredField = { -1, -1, -1, -1}}; bool retCode = makeDevice(0, argc, args, &deviceBlock); if (retCode) { sendString("New device would be:\n\r"); @@ -218,6 +229,7 @@ static bool changeDeviceCmd(uint8_t argc, char **args) { if (strcmp(args[1], "help")) { sendString("First argument: index of device in list\n\r"); sendFormatString("Between 0 and %d\n\r", getConfig()->numOfDeviceBlocks); + sendString("For further arguments use a * to keep the value\n\r"); return makeDevice(0, argc, args, NULL); } @@ -229,7 +241,8 @@ static bool changeDeviceCmd(uint8_t argc, char **args) { uint8_t index = (uint8_t) rawIndex; t_deviceBlock deviceBlock; - uint8_t index; + eepromReadDeviceBlock(index, &deviceBlock); + bool retCode = makeDevice(1, argc, args, &deviceBlock); if (retCode) { sendString("Changed device would be:\n\r");