Merge pull request #15411 from ascillato/ZB_CIE_and_Zone_Enroll

Add ZigBee CIE Registration and Zones Enrollment Commands
This commit is contained in:
s-hadinger 2022-04-20 19:10:10 +02:00 committed by GitHub
commit bbda258f2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 4 deletions

View File

@ -659,6 +659,8 @@
#define D_CMND_ZIGBEE_DATA "Data"
#define D_CMND_ZIGBEE_SCAN "Scan"
#define D_JSON_ZIGBEE_SCAN "ZbScan"
#define D_CMND_ZIGBEE_CIE "CIE"
#define D_CMND_ZIGBEE_ENROLL "Enroll"
// Commands xdrv_25_A4988_Stepper.ino
#define D_CMND_MOTOR "MOTOR"

View File

@ -1412,6 +1412,7 @@ void Z_SendSingleAttributeRead(uint16_t shortaddr, uint16_t groupaddr, uint16_t
// Write CIE address
//
void Z_WriteCIEAddress(uint16_t shortaddr, uint16_t groupaddr, uint16_t cluster, uint8_t endpoint, uint32_t value) {
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Sending CIE Address for Cluster %d in Endpoint %d of Device 0x%04X"), cluster, endpoint, shortaddr);
ZCLMessage zcl(12); // message is 12 bytes
zcl.shortaddr = shortaddr;
zcl.cluster = 0x0500;
@ -1428,15 +1429,15 @@ void Z_WriteCIEAddress(uint16_t shortaddr, uint16_t groupaddr, uint16_t cluster,
//
// Write CIE address
// Send CIE Zone Enroll Response
//
void Z_SendCIEZoneEnrollResponse(uint16_t shortaddr, uint16_t groupaddr, uint16_t cluster, uint8_t endpoint, uint32_t value) {
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Sending Enroll Zone %d"), Z_B0(value));
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Sending Enroll Zone %d for Cluster %d in Endpoint %d of Device 0x%04X"), Z_B0(value), cluster, endpoint, shortaddr);
ZCLMessage zcl(2); // message is 2 bytes
zcl.shortaddr = shortaddr;
zcl.cluster = 0x0500;
zcl.endpoint = endpoint;
zcl.cmd = 0x00, // Zone Enroll Response
zcl.cmd = 0x00; // Zone Enroll Response
zcl.clusterSpecific = true;
zcl.needResponse = true;
zcl.direct = false; // discover route

View File

@ -39,7 +39,7 @@ const char kZbCommands[] PROGMEM = D_PRFX_ZB "|" // prefix
D_CMND_ZIGBEE_BIND "|" D_CMND_ZIGBEE_UNBIND "|" D_CMND_ZIGBEE_PING "|" D_CMND_ZIGBEE_MODELID "|"
D_CMND_ZIGBEE_LIGHT "|" D_CMND_ZIGBEE_OCCUPANCY "|"
D_CMND_ZIGBEE_RESTORE "|" D_CMND_ZIGBEE_BIND_STATE "|" D_CMND_ZIGBEE_MAP "|" D_CMND_ZIGBEE_LEAVE "|"
D_CMND_ZIGBEE_CONFIG "|" D_CMND_ZIGBEE_DATA "|" D_CMND_ZIGBEE_SCAN
D_CMND_ZIGBEE_CONFIG "|" D_CMND_ZIGBEE_DATA "|" D_CMND_ZIGBEE_SCAN "|" D_CMND_ZIGBEE_ENROLL "|" D_CMND_ZIGBEE_CIE
;
SO_SYNONYMS(kZbSynonyms,
@ -61,6 +61,7 @@ void (* const ZigbeeCommand[])(void) PROGMEM = {
&CmndZbLight, &CmndZbOccupancy,
&CmndZbRestore, &CmndZbBindState, &CmndZbMap, &CmndZbLeave,
&CmndZbConfig, &CmndZbData, &CmndZbScan,
&CmndZbenroll, &CmndZbcie,
};
/********************************************************************************************/
@ -1331,6 +1332,42 @@ void CmndZbScan(void) {
ResponseCmndDone();
}
void CmndZbenroll(void) {
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
if ((XdrvMailbox.data_len) && (ArgC() > 1)) { // Process parameter entry
char argument[XdrvMailbox.data_len];
Z_Device & device = zigbee_devices.parseDeviceFromName(ArgV(argument, 1));
int enrollEndpoint = atoi(ArgV(argument, 2));
if (!device.valid()) { ResponseCmndChar_P(PSTR(D_ZIGBEE_UNKNOWN_DEVICE)); return; }
Z_SendCIEZoneEnrollResponse(device.shortaddr, 0, 500, enrollEndpoint, 1);
ResponseCmndDone();
} else {
ResponseCmndError();
}
}
void CmndZbcie(void) {
if (zigbee.init_phase) { ResponseCmndChar_P(PSTR(D_ZIGBEE_NOT_STARTED)); return; }
if ((XdrvMailbox.data_len) && (ArgC() > 1)) { // Process parameter entry
char argument[XdrvMailbox.data_len];
Z_Device & device = zigbee_devices.parseDeviceFromName(ArgV(argument, 1));
int enrollEndpoint = atoi(ArgV(argument, 2));
if (!device.valid()) { ResponseCmndChar_P(PSTR(D_ZIGBEE_UNKNOWN_DEVICE)); return; }
Z_WriteCIEAddress(device.shortaddr, 0, 500, enrollEndpoint, 0);
ResponseCmndDone();
} else {
ResponseCmndError();
}
}
// Restore a device configuration previously exported via `ZbStatus2``
// Format:
// Either the entire `ZbStatus3` export, or an array or just the device configuration.