mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-12 13:26:31 +00:00
Zigbee allow spaces in names
This commit is contained in:
parent
f70822b54d
commit
cc25c1abfe
@ -446,6 +446,36 @@ char* RemoveSpace(char* p) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove spaces at the beginning and end of the string (but not in the middle)
|
||||||
|
char* TrimSpace(char *p) {
|
||||||
|
// Remove white-space character (' ','\t','\n','\v','\f','\r')
|
||||||
|
char* write = p;
|
||||||
|
char* read = p;
|
||||||
|
char ch = '.';
|
||||||
|
|
||||||
|
// skip all leading spaces
|
||||||
|
while (isspace(*read)) {
|
||||||
|
read++;
|
||||||
|
}
|
||||||
|
// copy the rest
|
||||||
|
do {
|
||||||
|
ch = *read++;
|
||||||
|
*write++ = ch;
|
||||||
|
} while (ch != '\0');
|
||||||
|
// move to end
|
||||||
|
read = p + strlen(p);
|
||||||
|
// move backwards
|
||||||
|
while (p != read) {
|
||||||
|
read--;
|
||||||
|
if (isspace(*read)) {
|
||||||
|
*read = '\0';
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
char* RemoveControlCharacter(char* p) {
|
char* RemoveControlCharacter(char* p) {
|
||||||
// Remove control character (0x00 .. 0x1F and 0x7F)
|
// Remove control character (0x00 .. 0x1F and 0x7F)
|
||||||
char* write = p;
|
char* write = p;
|
||||||
|
@ -651,7 +651,7 @@ Z_Device & Z_Devices::parseDeviceFromName(const char * param, uint16_t * parsed_
|
|||||||
size_t param_len = strlen(param);
|
size_t param_len = strlen(param);
|
||||||
char dataBuf[param_len + 1];
|
char dataBuf[param_len + 1];
|
||||||
strcpy(dataBuf, param);
|
strcpy(dataBuf, param);
|
||||||
RemoveSpace(dataBuf);
|
TrimSpace(dataBuf);
|
||||||
if (parsed_shortaddr != nullptr) { *parsed_shortaddr = BAD_SHORTADDR; } // if it goes wrong, mark as bad
|
if (parsed_shortaddr != nullptr) { *parsed_shortaddr = BAD_SHORTADDR; } // if it goes wrong, mark as bad
|
||||||
|
|
||||||
if ((dataBuf[0] >= '0') && (dataBuf[0] <= '9') && (strlen(dataBuf) < 4)) {
|
if ((dataBuf[0] >= '0') && (dataBuf[0] <= '9') && (strlen(dataBuf) < 4)) {
|
||||||
|
@ -1091,13 +1091,13 @@ void ZigbeeMapAllDevices(void) {
|
|||||||
//
|
//
|
||||||
void CmndZbMap(void) {
|
void CmndZbMap(void) {
|
||||||
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
||||||
RemoveSpace(XdrvMailbox.data);
|
TrimSpace(XdrvMailbox.data);
|
||||||
|
|
||||||
if (strlen(XdrvMailbox.data) == 0) {
|
if (strlen(XdrvMailbox.data) == 0) {
|
||||||
ZigbeeMapAllDevices();
|
ZigbeeMapAllDevices();
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
} else {
|
} else {
|
||||||
CmndZbBindState_or_Map(true);
|
CmndZbBindState_or_Map(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1301,7 +1301,7 @@ void CmndZbInfo_inner(const Z_Device & device) {
|
|||||||
}
|
}
|
||||||
void CmndZbInfo(void) {
|
void CmndZbInfo(void) {
|
||||||
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
||||||
RemoveSpace(XdrvMailbox.data);
|
TrimSpace(XdrvMailbox.data);
|
||||||
|
|
||||||
if (strlen(XdrvMailbox.data) == 0) {
|
if (strlen(XdrvMailbox.data) == 0) {
|
||||||
// if empty, dump for all values
|
// if empty, dump for all values
|
||||||
@ -1352,7 +1352,7 @@ void CmndZbSave(void) {
|
|||||||
//
|
//
|
||||||
void CmndZbLoad(void) {
|
void CmndZbLoad(void) {
|
||||||
// can be called before Zigbee is initialized
|
// can be called before Zigbee is initialized
|
||||||
RemoveSpace(XdrvMailbox.data);
|
TrimSpace(XdrvMailbox.data);
|
||||||
|
|
||||||
bool ret = true;;
|
bool ret = true;;
|
||||||
if (strcmp(XdrvMailbox.data, "*") == 0) {
|
if (strcmp(XdrvMailbox.data, "*") == 0) {
|
||||||
@ -1373,7 +1373,7 @@ void CmndZbLoad(void) {
|
|||||||
//
|
//
|
||||||
void CmndZbUnload(void) {
|
void CmndZbUnload(void) {
|
||||||
// can be called before Zigbee is initialized
|
// can be called before Zigbee is initialized
|
||||||
RemoveSpace(XdrvMailbox.data);
|
TrimSpace(XdrvMailbox.data);
|
||||||
|
|
||||||
bool ret = ZbUnload(XdrvMailbox.data);
|
bool ret = ZbUnload(XdrvMailbox.data);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -1466,7 +1466,7 @@ void CmndZbcie(void) {
|
|||||||
// ZbRestore {"Device":"0x5ADF","Name":"Petite_Lampe","IEEEAddr":"0x90FD9FFFFE03B051","ModelId":"TRADFRI bulb E27 WS opal 980lm","Manufacturer":"IKEA of Sweden","Endpoints":["0x01","0xF2"]}
|
// ZbRestore {"Device":"0x5ADF","Name":"Petite_Lampe","IEEEAddr":"0x90FD9FFFFE03B051","ModelId":"TRADFRI bulb E27 WS opal 980lm","Manufacturer":"IKEA of Sweden","Endpoints":["0x01","0xF2"]}
|
||||||
void CmndZbRestore(void) {
|
void CmndZbRestore(void) {
|
||||||
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
||||||
RemoveSpace(XdrvMailbox.data);
|
TrimSpace(XdrvMailbox.data);
|
||||||
|
|
||||||
if (strlen(XdrvMailbox.data) == 0) {
|
if (strlen(XdrvMailbox.data) == 0) {
|
||||||
// if empty, log values for all devices
|
// if empty, log values for all devices
|
||||||
@ -1703,7 +1703,7 @@ void CmndZbStatus(void) {
|
|||||||
//
|
//
|
||||||
void CmndZbData(void) {
|
void CmndZbData(void) {
|
||||||
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
||||||
RemoveSpace(XdrvMailbox.data);
|
TrimSpace(XdrvMailbox.data);
|
||||||
|
|
||||||
if (strlen(XdrvMailbox.data) == 0) {
|
if (strlen(XdrvMailbox.data) == 0) {
|
||||||
// if empty, log values for all devices
|
// if empty, log values for all devices
|
||||||
@ -1748,7 +1748,7 @@ void CmndZbConfig(void) {
|
|||||||
int8_t zb_txradio_dbm = Settings->zb_txradio_dbm;
|
int8_t zb_txradio_dbm = Settings->zb_txradio_dbm;
|
||||||
|
|
||||||
// if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
// if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
|
||||||
RemoveSpace(XdrvMailbox.data);
|
TrimSpace(XdrvMailbox.data);
|
||||||
if (strlen(XdrvMailbox.data) > 0) {
|
if (strlen(XdrvMailbox.data) > 0) {
|
||||||
JsonParser parser(XdrvMailbox.data);
|
JsonParser parser(XdrvMailbox.data);
|
||||||
JsonParserObject root = parser.getRootObject();
|
JsonParserObject root = parser.getRootObject();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user