dsc-itv2-client 1.0.27 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsc-itv2-client",
3
3
  "author": "fajitacat",
4
- "version": "1.0.27",
4
+ "version": "1.0.29",
5
5
  "description": "Reverse engineered DSC ITV2 Protocol Client Library for TL280R Communicator - Monitor and control DSC alarm panels",
6
6
  "main": "src/index.js",
7
7
  "type": "module",
package/src/ITV2Client.js CHANGED
@@ -943,13 +943,13 @@ export class ITV2Client extends EventEmitter {
943
943
  _log(message) {
944
944
  if (this.logLevel === 'verbose') {
945
945
  const timestamp = new Date().toISOString();
946
- console.log(`[${timestamp}] ${message}`);
946
+ console.log(`dsc itv2: [${timestamp}] ${message}`);
947
947
  }
948
948
  }
949
949
 
950
950
  _logMinimal(message) {
951
951
  if (this.logLevel === 'minimal' || this.logLevel === 'verbose') {
952
- console.log(message);
952
+ console.log(`dsc itv2: ${message}`);
953
953
  }
954
954
  }
955
955
 
@@ -966,7 +966,7 @@ export class ITV2Client extends EventEmitter {
966
966
  .join('');
967
967
 
968
968
  const offset = i.toString(16).padStart(4, '0').toUpperCase();
969
- console.log(`${offset} ${hex.padEnd(48)} |${ascii}|`);
969
+ console.log(`dsc itv2: ${offset} ${hex.padEnd(48)} |${ascii}|`);
970
970
  }
971
971
  }
972
972
  }
@@ -845,18 +845,21 @@ export class ITv2Session {
845
845
  * @returns {Buffer} - Complete packet ready to send
846
846
  */
847
847
  buildCommandRequest(innerCommand, innerPayload = Buffer.alloc(0)) {
848
- // Get next application sequence number
849
- const appSeq = this.appSequence;
850
- this.appSequence = (this.appSequence + 1) & 0xFF;
851
-
852
- // Build 0x0800 payload: [AppSeqNum][CommandToRequest BE][InnerPayload]
853
- const payload = Buffer.alloc(3 + innerPayload.length);
848
+ // Predict the appSeq that buildCommand will assign (it increments before using).
849
+ // The inner 0x0800 AppSequenceNumber MUST match the outer frame appSeq
850
+ // the panel uses the inner appSeq to correlate follow-up data responses.
851
+ const appSeq = (this.appSequence + 1) & 0xFF;
852
+
853
+ // Build 0x0800 payload: [AppSeqNum][CommandToRequest 2B BE][ByteArray(InnerPayload)]
854
+ // SDK uses StoreByteArray with sizeMode=-1 (VarBytes length prefix)
855
+ const wrappedPayload = this.encodeByteArray(innerPayload);
856
+ const payload = Buffer.alloc(3 + wrappedPayload.length);
854
857
  payload[0] = appSeq;
855
858
  payload.writeUInt16BE(innerCommand, 1); // Command in big-endian (per SDK CUInt16Map::StoreValue)
856
- innerPayload.copy(payload, 3);
859
+ wrappedPayload.copy(payload, 3);
857
860
 
858
861
  this.log(`[Session] Building 0x0800 Command Request: innerCmd=0x${innerCommand.toString(16)}, appSeq=${appSeq}`);
859
- this.log(`[Session] Inner payload: ${innerPayload.toString('hex')}`);
862
+ this.log(`[Session] Inner payload: ${innerPayload.toString('hex')}, wrapped: ${wrappedPayload.toString('hex')}`);
860
863
 
861
864
  return this.buildCommand(CMD.STATUS_REQUEST, payload);
862
865
  }