incomplete changeDevice function

This commit is contained in:
2020-12-17 09:34:34 +01:00
parent 7b79103ed8
commit 12db917466

View File

@ -150,16 +150,9 @@ static bool setFrontendThresholdCmd(uint8_t argc, char **args) {
0, 1023);
}
static bool makeDevice(uint8_t argc, char **args, t_deviceBlock *deviceBlock, uint8_t *index) {
static bool makeDevice(uint8_t argOffset, uint8_t argc, char **args, t_deviceBlock *deviceBlock) {
if (strcmp(args[1], "help") == 0) {
sendString("Arguments are\n\r");
if (index) {
sendString("index ");
}
sendString("deviceName address period field1 field2 field3 field4\n\r");
if (index) {
sendString("index: index in list of devices\n\r");
}
sendString("deviceName: max. length = 16\n\r");
sendString("address: between 1 and 254\n\r");
sendString("period: in seconds, between 0 (disabled) and 86400 (1 day)\n\r");
@ -167,16 +160,6 @@ static bool makeDevice(uint8_t argc, char **args, t_deviceBlock *deviceBlock, ui
return false;
}
uint8_t argOffset = 0;
if (index) {
argOffset = 1;
long int rawIndex = strtol(args[1], NULL, 10);
if (rawIndex < 0 || rawIndex > MAX_MBUS_DEVICES) {
sendString("illegal index\n\r");
return false;
}
*index = (uint8_t) rawIndex;
}
if ((argc - argOffset) != 8) {
sendString("wrong number of arguments\n\r");
@ -218,7 +201,7 @@ static bool makeDevice(uint8_t argc, char **args, t_deviceBlock *deviceBlock, ui
static bool addDeviceCmd(uint8_t argc, char **args) {
t_deviceBlock deviceBlock;
bool retCode = makeDevice(argc, args, &deviceBlock, NULL);
bool retCode = makeDevice(0, argc, args, &deviceBlock);
if (retCode) {
sendString("New device would be:\n\r");
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
@ -232,9 +215,15 @@ static bool addDeviceCmd(uint8_t argc, char **args) {
}
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);
return makeDevice(0, argc, args, NULL);
}
t_deviceBlock deviceBlock;
uint8_t index;
bool retCode = makeDevice(argc, args, &deviceBlock, &index);
bool retCode = makeDevice(1, argc, args, &deviceBlock);
if (retCode) {
sendString("Changed device would be:\n\r");
sendFormatString(" Index: %d\n\r", index);