diff --git a/README.md b/README.md index 97a87d0..b224c73 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,9 @@ For now there is documentation in English here: https://wiki.hafenmeister.de Placeholder for the next version (at the beginning of the line): ### **WORK IN PROGRESS** --> +### **WORK IN PROGRESS** +* (BenAhrdt) add CRC-8 + ### 1.5.4 (2024-11-15) * (BenAhrdt) add roles and fix responsive issues diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index e7ab714..b061f0d 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -513,6 +513,7 @@ "tooltip": "crcTooltip", "options": [ {"label":"no crc","value":"noCrc"}, + {"label":"CRC-8","value":"CRC-8"}, {"label":"KERMIT","value":"KERMIT"}, {"label":"KERMIT (Little Endian)","value":"KERMIT.LittleEndian"} ], diff --git a/lib/modules/downlinkConfighandler.js b/lib/modules/downlinkConfighandler.js index f5d50ce..0478ec0 100644 --- a/lib/modules/downlinkConfighandler.js +++ b/lib/modules/downlinkConfighandler.js @@ -1,6 +1,6 @@ const fs = require("fs"); const { isDeepStrictEqual } = require("util"); -const {crc16} = require("easy-crc"); +const {crc8, crc16} = require("easy-crc"); class downlinkConfighandlerClass { constructor(adapter) { @@ -339,7 +339,15 @@ class downlinkConfighandlerClass { } } if(crcAlgorithm && crcAlgorithm !== "noCrc"){ - let crc = crc16(crcAlgorithm,Buffer.from(payloadInHex,"hex")).toString(16); + let crc = null; + if(crcAlgorithm === "CRC-8"){ + crc = crc8(crcAlgorithm,Buffer.from(payloadInHex,"hex")).toString(16); + } + else{ + crc = crc16(crcAlgorithm,Buffer.from(payloadInHex,"hex")).toString(16); + } + + // Check for swap if little endian is selected if(crcSwap){ crc = Buffer.from(crc,"hex").reverse().toString("hex"); }