Skip to content

Instantly share code, notes, and snippets.

@bendtherules
Created July 13, 2023 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendtherules/4500b2c02ef6bc2f236828ed22af8844 to your computer and use it in GitHub Desktop.
Save bendtherules/4500b2c02ef6bc2f236828ed22af8844 to your computer and use it in GitHub Desktop.
Parse Bluetooth DMM Multimeter string (Baba AD-900)
// Reference - https://github.com/ludwich66/Bluetooth-DMM/wiki/Protocol-all-Variants
// From my multimeter - Baba AD-900 (Generic name - ZOYI ZT-300AB)
// rawString = '1B-84-70-A1-49-DA-B8-7B-66-DA-3A' // few mv //mv enabled both mV and V flag
rawString = '1B-84-70-D1-3D-2B-75-7F-66-FA-3A'; // 3.764 V // enabled V flag
function zeroPad(num, places) {
return String(num).padStart(places, '0');
}
function getBit(str, binIndex) {
return str[binIndex];
}
function parseRawString(rawString) {
const rawParts = rawString.split('-').map(val => parseInt(val, 16));
// eslint-disable-next-line max-len
const keysXOR = [ parseInt('41', 16), parseInt('21', 16), parseInt('73', 16), parseInt('55', 16), parseInt('a2', 16), parseInt('c1', 16), parseInt('32', 16), parseInt('71', 16), parseInt('66', 16), parseInt('aa', 16), parseInt('3b', 16) ];
// eslint-disable-next-line no-bitwise
const partsXOR = rawParts.map((rawVal, index)=> rawVal ^ keysXOR[index]);
const partsBin = partsXOR.map(val => val.toString(2));
const partsBinPadded = partsBin.map(t => zeroPad(t, 8));
const fullBinStr = partsBinPadded.join('');
return fullBinStr;
}
let finalParsedStr = parseRawString(rawString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment