Skip to content

Commit

Permalink
reserve 2 zcl seq nums and check for direction of incoming msg with s…
Browse files Browse the repository at this point in the history
…eqNum
  • Loading branch information
splitice committed Apr 14, 2023
1 parent 8917f13 commit 5d1dfed
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/Af.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Af extends EventEmitter {

nextZclSeqNum() {
seqNumber += 1; // seqNumber is a private var on the top of this module
if (seqNumber > 255 || seqNumber < 0)
if (seqNumber >= 253 || seqNumber < 0)
seqNumber = 0;

this._seq = seqNumber;
Expand Down Expand Up @@ -110,12 +110,14 @@ class Af extends EventEmitter {
const frameType = msg.zclMsg.frameCntl.frameType;
zclDebug(`0x${msg.srcaddr.toString(16)}:${msg.srcendpoint}->0x00:${msg.dstendpoint} (${msg.zclMsg.seqNum}) ${msg.clusterid} ${frameType === 0 ? 'foundation' : 'functional'}(${msg.zclMsg.cmdId}) ${JSON.stringify(msg.zclMsg.payload)}`);

// for broadcast responses only
this.emit('ZCL:incomingMsg:' + msg.dstendpoint + ':' + msg.zclMsg.seqNum, msg);
if(msg.zclMsg.frameCntl.direction === 1) {
// for broadcast responses only
this.emit('ZCL:incomingMsg:' + msg.dstendpoint + ':' + msg.zclMsg.seqNum, msg);

// { groupid, clusterid, srcaddr, srcendpoint, dstendpoint, wasbroadcast, linkquality, securityuse, timestamp, transseqnumber, zclMsg }
this.emit('ZCL:incomingMsg:' + msg.srcaddr.toString(16) + ':' + msg.srcendpoint + ':' + msg.dstendpoint + ':' + msg.zclMsg.seqNum, msg);
this.emit('ZCL:incomingMsg:' + msg.srcaddr.toString(16) + ':' + msg.srcendpoint + ':' + msg.zclMsg.seqNum, msg);
// { groupid, clusterid, srcaddr, srcendpoint, dstendpoint, wasbroadcast, linkquality, securityuse, timestamp, transseqnumber, zclMsg }
this.emit('ZCL:incomingMsg:' + msg.srcaddr.toString(16) + ':' + msg.srcendpoint + ':' + msg.dstendpoint + ':' + msg.zclMsg.seqNum, msg);
this.emit('ZCL:incomingMsg:' + msg.srcaddr.toString(16) + ':' + msg.srcendpoint + ':' + msg.zclMsg.seqNum, msg);
}

// Necessary, some IAS devices don't respect endpoints
if (remoteEp) {
Expand Down

0 comments on commit 5d1dfed

Please sign in to comment.