2017-07-12 15:01:00 -06:00
|
|
|
require('core-js/fn/array/from');
|
|
|
|
|
2017-06-22 21:38:38 -06:00
|
|
|
function determineByteStateChangeTimes(hexData, time, msgSize, lastParsedMessage) {
|
2017-06-23 19:29:31 -06:00
|
|
|
const byteStateChangeCounts = Array(msgSize).fill(0);
|
|
|
|
let byteStateChangeTimes;
|
|
|
|
|
2017-06-22 21:38:38 -06:00
|
|
|
if(!lastParsedMessage) {
|
2017-06-23 19:29:31 -06:00
|
|
|
byteStateChangeTimes = Array(msgSize).fill(time);
|
2017-06-22 21:38:38 -06:00
|
|
|
} else {
|
2017-06-23 19:29:31 -06:00
|
|
|
byteStateChangeTimes = Array.from(lastParsedMessage.byteStateChangeTimes);
|
2017-06-22 21:38:38 -06:00
|
|
|
|
|
|
|
for(let i = 0; i < byteStateChangeTimes.length; i++) {
|
|
|
|
const currentData = hexData.substr(i * 2, 2),
|
|
|
|
prevData = lastParsedMessage.hexData.substr(i * 2, 2);
|
|
|
|
|
|
|
|
if(currentData != prevData) {
|
|
|
|
byteStateChangeTimes[i] = time;
|
2017-06-23 19:29:31 -06:00
|
|
|
byteStateChangeCounts[i] = 1;
|
2017-06-22 21:38:38 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-23 19:29:31 -06:00
|
|
|
|
|
|
|
return {byteStateChangeTimes, byteStateChangeCounts};
|
2017-06-22 21:38:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function parseMessage(dbc, time, address, data, timeStart, lastParsedMessage) {
|
|
|
|
const hexData = Buffer.from(data).toString('hex');
|
|
|
|
const msgSpec = dbc.messages.get(address);
|
|
|
|
const msgSize = msgSpec ? msgSpec.size : 8;
|
|
|
|
const relTime = time - timeStart;
|
|
|
|
|
2017-06-23 19:29:31 -06:00
|
|
|
const {byteStateChangeTimes, byteStateChangeCounts} = determineByteStateChangeTimes(hexData,
|
2017-06-22 21:38:38 -06:00
|
|
|
relTime,
|
|
|
|
msgSize,
|
|
|
|
lastParsedMessage)
|
2017-06-23 19:29:31 -06:00
|
|
|
const msgEntry = {time: time,
|
|
|
|
signals: dbc.getSignalValues(address, data),
|
|
|
|
relTime,
|
|
|
|
hexData,
|
|
|
|
byteStateChangeTimes}
|
|
|
|
|
|
|
|
return {msgEntry, byteStateChangeCounts};
|
2017-06-13 18:40:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const BIG_ENDIAN_START_BITS = [];
|
|
|
|
for(let i = 0; i < 64; i += 8) {
|
|
|
|
for(let j = 7; j > -1; j--) {
|
|
|
|
BIG_ENDIAN_START_BITS.push(i + j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function bigEndianBitIndex(matrixBitIndex) {
|
|
|
|
return BIG_ENDIAN_START_BITS.indexOf(matrixBitIndex);
|
|
|
|
}
|
|
|
|
|
2017-06-25 22:05:40 -06:00
|
|
|
function matrixBitNumber(bigEndianIndex) {
|
|
|
|
return BIG_ENDIAN_START_BITS[bigEndianIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {bigEndianBitIndex, matrixBitNumber, parseMessage}
|