From db4cc3022f815ecf77ad1d5ddf1cc90d04f9b238 Mon Sep 17 00:00:00 2001 From: Daniel Wippermann Date: Sat, 8 Jul 2023 09:27:07 +0200 Subject: [PATCH] Add `SpecificationFile#getPacketTemplate`. --- src/specification-file.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/specification-file.js b/src/specification-file.js index 5afb42b..21167e9 100644 --- a/src/specification-file.js +++ b/src/specification-file.js @@ -569,6 +569,21 @@ class SpecificationFile { this.packetTemplates = packetTemplates; } + getPacketTemplate(destinationAddress, sourceAddress, command) { + return this.packetTemplates.find(pt => { + if ((pt.destinationAddress & pt.destinationMask) !== (destinationAddress & pt.destinationMask)) { + // nop + } else if ((pt.sourceAddress & pt.sourceMask) !== (sourceAddress & pt.sourceMask)) { + // nop + } else if (pt.command !== command) { + // nop + } else { + return true; + } + return false; + }); + } + getRawValue(pt, ptf, buffer, start, end) { let rawValue = 0, valid = false; for (const part of ptf.parts) {