header: function (rawBuf) { var header = zclPacket.header(rawBuf); if (!header) return; else if (header.frameCntl.frameType > 1) // 2, 3 are reserved return; return header; }
bridge._zclIndicationEventBridge = function (controller, srcEp, localEp, payload) { // srcEp maybe remote, maybe local // local ep maybe delegator, maybe zapp var isRemoteEp = false, isDstEpDelegator = false, clusterId = payload.clusterid, zclPacket = payload.data, zclHeader, zclDirection, zclPayload, seqNum, zclBridgedEvent; if (srcEp && srcEp.isZclSupported()) { } else if (localEp && (localEp !== srcEp) && localEp.isZclSupported()) { } isRemoteEp = !!srcEp.isLocal(); isDstEpDelegator = srcEp.isDelegator(); if (isRemoteEp && !isDstEpDelegator) return; // msg is from a remote ep, but this msg is to a local ep, just return and do nothing. // Local ep will handle this message, since the same message is also going to local ep. if (!srcEp.isZclSupported()) return; // unsupport zcl, no further parsing required /* Start ZCL parsing */ zclHeader = zcl.header(zclPacket); // [TODO] need check if header cannot be parse in zcl-packet if (!zclHeader) return; zclDirection = zclHeader.frameCntl.direction; if (0 === zclHeader.frameCntl.frameType) { // 0: foundation zcl.parse(zclPacket, function (err, zclData) { seqNum = zclData.seqNum; zclPayload = zclData.payload; zclBridgedEvent = 'ZCL:' + zclDirection + ':' + clusterId + ':' + seqNum; // zclData.payload // 'ZCL:FOUNDATION:cmd' direction === 0, zcl msg received from client side of node clusters // 'ZCL:FOUNDATION:cmd:seqNum' direction === 1, zcl msg received from server side of node clusters }); } else if (1 === zclHeader.frameCntl.frameType) { // 1: functional zcl.parse(zclPacket, clusterId, function (err, zclData) { seqNum = zclData.seqNum; zclPayload = zclData.payload; zclBridgedEvent = 'ZCL:' + zclDirection + ':' + clusterId + ':' + seqNum; // zclData.payload }); } if (zclBridgedEvent) controller.emit(zclBridgedEvent, zclPayload); // here, deal with public profile or private profile that supports zcl style // zcl.parse(zclPacket, clusterId, function (err, zclMsg) { // if (err) // return; // var frameType = zclMsg.frameCntl.frameType, // direction = zclMsg.frameCntl.direction; // if (frameType === 0) { // FOUNDATION, across entire profile // if (!isRemoteEp) { // controller.emit('ZCL:FOUNDATION', zclMsg); // [TODO] zclMsg need new format? // } else { // if (direction === 0) // zcl msg received from client side of node clusters // controller.emit('ZCL:FOUNDATION:' + zclMsg.cmd, zclMsg); // else if (direction === 1) // zcl msg received from server side of node clusters // controller.emit('ZCL:FOUNDATION:' + zclMsg.cmd + ':' + zclMsg.seqNum, zclMsg); // } // } else if (frameType === 1) { // FUNCTIONAL, cluster-specific // if (!isRemoteEp) { // controller.emit('ZCL:FUNCTIONAL', zclMsg); // [TODO] zclMsg need new format? // } else { // if (direction === 0) // zcl msg received from server side of node clusters // console.log(zclMsg.cmd + ':TODO: Server side of Coord clusters has not been implemented yet!'); // else if (direction === 1) // zcl msg received from client side of node clusters // controller.emit('ZCL:FUNCTIONAL:' + zclMsg.cmd + ':' + zclMsg.seqNum, zclMsg); // } // } else { // console.log('Unrecognized zcl frame type.'); // } // }); };