addDevice
This commit is contained in:
@ -150,33 +150,68 @@ static bool setFrontendThresholdCmd(uint8_t argc, char **args) {
|
||||
0, 1023);
|
||||
}
|
||||
|
||||
static bool makeDevice(uint8_t argc, char **args, t_deviceBlock *deviceBlock) {
|
||||
if (argc != 8) {
|
||||
static bool makeDevice(uint8_t argOffset, uint8_t argc, char **args, t_deviceBlock *deviceBlock) {
|
||||
if ((argc - argOffset) != 8) {
|
||||
sendString("wrong number of arguments\n\r");
|
||||
return false;
|
||||
}
|
||||
|
||||
char *deviceName = args[1];
|
||||
char *deviceName = args[1 + argOffset];
|
||||
if (strcmp(deviceName, "help") == 0) {
|
||||
sendString("Arguments are\n\r");
|
||||
sendString("deviceName address period field1 field2 field3 field4\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");
|
||||
sendString("fields: between -1 (not considered) and 254\n\r");
|
||||
return true;
|
||||
}
|
||||
if (strlen(deviceName) >= sizeof(deviceBlock->deviceName)) {
|
||||
sendString("devicename too long\n\r");
|
||||
return false;
|
||||
}
|
||||
strcpy(deviceBlock->deviceName, deviceName);
|
||||
|
||||
long int rawAddress = strtol(args[2], NULL, 10);
|
||||
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");
|
||||
return false;
|
||||
}
|
||||
deviceBlock->consideredField[i] = (int8_t) rawFieldNum;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool addDeviceCmd(uint8_t argc, char **args) {
|
||||
t_deviceBlock deviceBlock;
|
||||
bool retCode = makeDevice(0, argc, args, &deviceBlock);
|
||||
|
||||
sendString("New device would be:\n\r");
|
||||
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++) {
|
||||
sendFormatString(" Considered field: %d\n\r", deviceBlock.consideredField[i]);
|
||||
}
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
const static cmd_t SET_COMMANDS[] = {
|
||||
{ .name = "devicename", .cmdFunc = setDeviceNameCmd,
|
||||
.help = \
|
||||
@ -277,6 +312,10 @@ const cmd_t CONFIG_COMMANDS[] = {
|
||||
" Argument help gives a list of \n\r" \
|
||||
" parameters\n\r"
|
||||
},
|
||||
{ .name = "addDevice", .cmdFunc = addDeviceCmd,
|
||||
.help = \
|
||||
"addDevice ............................ Add a new device to the end of the list\n\r"
|
||||
},
|
||||
{ .name = "restart", .cmdFunc = restartCmd,
|
||||
.help = \
|
||||
"restart .............................. Restart the system,\n\r" \
|
||||
|
Reference in New Issue
Block a user