Skip to content

Commit

Permalink
build packet using buffer (not concentrate)
Browse files Browse the repository at this point in the history
  • Loading branch information
splitice committed Sep 14, 2023
1 parent 0c73a2d commit 107f95a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/Af.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class Af extends EventEmitter {
throw err
}

if (!mandatoryEvent) {
if (!areq) {
return rsp
}

Expand Down
25 changes: 15 additions & 10 deletions lib/Packet.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* jshint node: true */
'use strict';

var Concentrate = require('concentrate'),
DChunks = require('dissolve-chunks'),
var DChunks = require('dissolve-chunks'),
ru = DChunks.Rule;

var FoundPayload = require('./packet/Foundation'),
Expand Down Expand Up @@ -109,16 +108,22 @@ ZclFrame.prototype.frame = function (frameCntl, manufCode, seqNum, cmdId, payloa
if (!isNumber(manufCode)) throw new TypeError('manufCode should be a number');
if (!isNumber(seqNum)) throw new TypeError('seqNum should be a number');

var frameCntlOctet = (frameCntl.frameType & 0x03) | ((frameCntl.manufSpec << 2) & 0x04) | ((frameCntl.direction << 3) & 0x08) | ((frameCntl.disDefaultRsp << 4) & 0x10),
dataBuf = Concentrate().uint8(frameCntlOctet);
const frameCntlOctet = (frameCntl.frameType & 0x03) | ((frameCntl.manufSpec << 2) & 0x04) | ((frameCntl.direction << 3) & 0x08) | ((frameCntl.disDefaultRsp << 4) & 0x10);

if (frameCntl.manufSpec === 1) {
dataBuf = dataBuf.uint16(manufCode);
const dataBuf = Buffer.allocUnsafeSlow((frameCntl.manufSpec === 1?5:3) + payload.length);
dataBuf[0] = frameCntlOctet;
if(frameCntl.manufSpec === 1){
dataBuf.writeUInt16LE(manufCode, 1);
dataBuf[3] = seqNum;
dataBuf[4] = cmdId;
payload.copy(dataBuf, 5);
return dataBuf
}

dataBuf = dataBuf.uint8(seqNum).uint8(cmdId).buffer(payload);

return dataBuf.result();

dataBuf[1] = seqNum;
dataBuf[2] = cmdId;
payload.copy(dataBuf, 3);
return dataBuf
};

/*************************************************************************************************/
Expand Down

0 comments on commit 107f95a

Please sign in to comment.