Skip to content

Instantly share code, notes, and snippets.

@dfrankland
Forked from TheUbuntuGuy/fuckuanova.py
Last active April 25, 2017 00:36
Show Gist options
  • Save dfrankland/9e1cd45d18bf8c37f1aa90a0104aaa19 to your computer and use it in GitHub Desktop.
Save dfrankland/9e1cd45d18bf8c37f1aa90a0104aaa19 to your computer and use it in GitHub Desktop.
Decode Anova Precision Cooker WiFi Packets
const decoder = packetBuf => {
const bytes = [...packetBuf];
const { string: command } = bytes.reduce(
({ chksum, string }, byte, index) => {
let newChecksum = chksum;
let newString = string;
if (index === bytes.length - 2) {
newChecksum &= (2 ** 8) - 1; // eslint-disable-line no-bitwise
if (byte !== newChecksum) {
throw new Error(`Chksum: FAIL. Read: ${byte} != calc'd: ${chksum}`);
}
}
if (index > 1 && index < bytes.length - 2) {
newChecksum += byte;
const n = (index - 1) % 7;
const newByte = (
(byte >> n) | // eslint-disable-line no-bitwise
(
( // eslint-disable-line no-bitwise
byte & ( // eslint-disable-line no-bitwise
(2 ** n) - 1
)
) <<
(8 - n)
)
);
newString += String.fromCharCode(newByte);
}
return { chksum: newChecksum, string: newString };
},
{ chksum: 0, string: '' } // eslint-disable-line comma-dangle
);
return command;
};
console.log(decoder(Buffer.from('680cce95a3022d1920c6859346a13316', 'hex'))); // get id card
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment