Skip to content

Commit

Permalink
add CRC-8
Browse files Browse the repository at this point in the history
  • Loading branch information
BenAhrdt committed Nov 23, 2024
1 parent 2d6e777 commit cf8fd1a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
],
Expand Down
12 changes: 10 additions & 2 deletions lib/modules/downlinkConfighandler.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit cf8fd1a

Please sign in to comment.