Created
April 28, 2024 08:12
-
-
Save lmmendes/118f09e149a6d2412b1caa09a5f95485 to your computer and use it in GitHub Desktop.
Portisch RF-Bridge Decode 0xB1 sniffed data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* The following script decodes 0xB1 to 0xB0 | |
* For more information on 0xB1 to 0xB0 decoding see https://github.com/Portisch/RF-Bridge-EFM8BB1/wiki/Decode-0xB1-sniffed-data | |
* | |
* The following site can also be used for decoding https://bbconv.hrbl.pl/ | |
* | |
*/ | |
const readline = require('readline').createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
readline.question('Input Raw B1 string:\n Like: AA B1 04 017C 046A 0BCC 2378 3818190908181908190909090908190819081818190909091A 55 \n\n', B1Data => { | |
console.log(`\nReceived "${B1Data}"\n`); | |
readline.close(); | |
var B0Data = ParseB1(B1Data); | |
console.log(`Parsed B0: ${B0Data.payload}\n`);; | |
}); | |
function ParseB1(B1Received) { | |
if (B1Received) { | |
var OUTmsg = {}; | |
if (B1Received.indexOf("AA B1") !== -1) { | |
OUTmsg.payload = parseRF(B1Received, 8); | |
var OUTmsgNoSpaces = Object.assign({}, OUTmsg); | |
OUTmsgNoSpaces.payload = OUTmsgNoSpaces.payload;// .replace(/ /g, ""); | |
return OUTmsgNoSpaces; | |
} | |
} | |
} | |
function parseRF(szInpStr, repVal) { | |
const debug = false; | |
const verbose = true; | |
if (debug) { console.warn(`szInpStr: ${szInpStr}`); } | |
if (verbose) { console.warn(`Repeat: ${repVal}`); } | |
szInpStr = szInpStr.replace(/ /g, ""); | |
var iNbrOfBuckets = parseInt(szInpStr.slice(4, 6), 16); | |
var arrBuckets = []; | |
if (verbose) { console.warn(`Number of buckets: ${iNbrOfBuckets}`); } | |
var szOutAux = ` ${hex2string(iNbrOfBuckets, 2)} `; | |
szOutAux += `${hex2string(repVal, 2)} `; | |
for (let i = 0; i < iNbrOfBuckets; i++) { | |
szOutAux += szInpStr.slice(6 + i * 4, 10 + i * 4) + " " | |
arrBuckets.push(parseInt(szInpStr.slice(6 + i * 4, 10 + i * 4), 16)) | |
} | |
if (verbose) { console.warn(`arrBuckets: ${arrBuckets}`); } | |
szOutAux += szInpStr.slice(6 + iNbrOfBuckets * 4, -2); | |
var szDataStr = szOutAux.replace(/ /g, ""); | |
szOutAux += " 55"; | |
var iLength = parseInt(szDataStr.length / 2); | |
szOutAux = "AA B0 " + hex2string(iLength, 2) + szOutAux; | |
return szOutAux.toUpperCase(); | |
} | |
function hex2string(hex, amount) { | |
var string = parseInt(hex).toString(16); | |
string = ("00000000" + string).slice(amount * -1); | |
return string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment