ChangeDevice
This commit is contained in:
@ -24,6 +24,7 @@ typedef struct __attribute__((__packed__)) s_configBlock {
|
|||||||
} t_configBlock;
|
} t_configBlock;
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_MBUS_DEVICES 16
|
||||||
#define MBUSDEVICE_NAMELENGTH 16
|
#define MBUSDEVICE_NAMELENGTH 16
|
||||||
#define MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS 4
|
#define MBUSDEVICE_NUM_OF_CONSIDEREDFIELDS 4
|
||||||
|
|
||||||
|
@ -150,11 +150,16 @@ static bool setFrontendThresholdCmd(uint8_t argc, char **args) {
|
|||||||
0, 1023);
|
0, 1023);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool makeDevice(uint8_t argOffset, uint8_t argc, char **args, t_deviceBlock *deviceBlock) {
|
static bool makeDevice(uint8_t argc, char **args, t_deviceBlock *deviceBlock, uint8_t *index) {
|
||||||
char *deviceName = args[1 + argOffset];
|
if (strcmp(args[1], "help") == 0) {
|
||||||
if (strcmp(deviceName, "help") == 0) {
|
|
||||||
sendString("Arguments are\n\r");
|
sendString("Arguments are\n\r");
|
||||||
|
if (index) {
|
||||||
|
sendString("index ");
|
||||||
|
}
|
||||||
sendString("deviceName address period field1 field2 field3 field4\n\r");
|
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("deviceName: max. length = 16\n\r");
|
||||||
sendString("address: between 1 and 254\n\r");
|
sendString("address: between 1 and 254\n\r");
|
||||||
sendString("period: in seconds, between 0 (disabled) and 86400 (1 day)\n\r");
|
sendString("period: in seconds, between 0 (disabled) and 86400 (1 day)\n\r");
|
||||||
@ -162,11 +167,23 @@ static bool makeDevice(uint8_t argOffset, uint8_t argc, char **args, t_deviceBlo
|
|||||||
return false;
|
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) {
|
if ((argc - argOffset) != 8) {
|
||||||
sendString("wrong number of arguments\n\r");
|
sendString("wrong number of arguments\n\r");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *deviceName = args[1 + argOffset];
|
||||||
if (strlen(deviceName) >= sizeof(deviceBlock->deviceName)) {
|
if (strlen(deviceName) >= sizeof(deviceBlock->deviceName)) {
|
||||||
sendString("devicename too long\n\r");
|
sendString("devicename too long\n\r");
|
||||||
return false;
|
return false;
|
||||||
@ -201,7 +218,7 @@ static bool makeDevice(uint8_t argOffset, uint8_t argc, char **args, t_deviceBlo
|
|||||||
|
|
||||||
static bool addDeviceCmd(uint8_t argc, char **args) {
|
static bool addDeviceCmd(uint8_t argc, char **args) {
|
||||||
t_deviceBlock deviceBlock;
|
t_deviceBlock deviceBlock;
|
||||||
bool retCode = makeDevice(0, argc, args, &deviceBlock);
|
bool retCode = makeDevice(argc, args, &deviceBlock, NULL);
|
||||||
if (retCode) {
|
if (retCode) {
|
||||||
sendString("New device would be:\n\r");
|
sendString("New device would be:\n\r");
|
||||||
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
|
sendFormatString(" Name: %s, Address: %d, Period: %d\n\r",
|
||||||
@ -214,6 +231,25 @@ static bool addDeviceCmd(uint8_t argc, char **args) {
|
|||||||
return retCode;
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool changeDeviceCmd(uint8_t argc, char **args) {
|
||||||
|
t_deviceBlock deviceBlock;
|
||||||
|
uint8_t index;
|
||||||
|
bool retCode = makeDevice(argc, args, &deviceBlock, &index);
|
||||||
|
if (retCode) {
|
||||||
|
sendString("Changed device would be:\n\r");
|
||||||
|
sendFormatString(" Index: %d\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[] = {
|
const static cmd_t SET_COMMANDS[] = {
|
||||||
{ .name = "devicename", .cmdFunc = setDeviceNameCmd,
|
{ .name = "devicename", .cmdFunc = setDeviceNameCmd,
|
||||||
.help = \
|
.help = \
|
||||||
@ -318,6 +354,10 @@ const cmd_t CONFIG_COMMANDS[] = {
|
|||||||
.help = \
|
.help = \
|
||||||
"addDevice ............................ Add a new device to the end of the list\n\r"
|
"addDevice ............................ Add a new device to the end of the list\n\r"
|
||||||
},
|
},
|
||||||
|
{ .name = "changeDevice", .cmdFunc = changeDeviceCmd,
|
||||||
|
.help = \
|
||||||
|
"changeDevice ......................... Change a new device by index\n\r"
|
||||||
|
},
|
||||||
{ .name = "restart", .cmdFunc = restartCmd,
|
{ .name = "restart", .cmdFunc = restartCmd,
|
||||||
.help = \
|
.help = \
|
||||||
"restart .............................. Restart the system,\n\r" \
|
"restart .............................. Restart the system,\n\r" \
|
||||||
|
Reference in New Issue
Block a user