Skip to content

Instantly share code, notes, and snippets.

@gregjhogan
Created December 19, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gregjhogan/7070b860aaded1ebf7e7ae74be5c8a19 to your computer and use it in GitHub Desktop.
Save gregjhogan/7070b860aaded1ebf7e7ae74be5c8a19 to your computer and use it in GitHub Desktop.
cabana fingerprint
const fs = require('fs');
const content = fs.readFileSync('./data.csv', 'utf8');
const messages = content
.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0 && line !== 'time,addr,bus,data')
.map(line => line.split(','))
.map(msg => ({
addr: parseInt(msg[1]),
bus: parseInt(msg[2]),
data: msg[3].replace(/0+$/, '')
}))
.filter(msg => msg.bus === 0);
const lengths = {};
for (let msg of messages) {
const len = Math.ceil(msg.data.length / 2);
if (len === 0) {
continue;
}
lengths[msg.addr] = Math.max(lengths[msg.addr] || 0, len);
}
const fingerprint = Object.keys(lengths)
.map(key => key + 'L: ' + lengths[key])
.join(', ');
console.log(fingerprint);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment