From 34ed2e464d73fc4d7a5d1c520ceff2aab324090d Mon Sep 17 00:00:00 2001 From: Scott Bender Date: Wed, 7 Aug 2024 19:32:03 -0400 Subject: [PATCH] fix: candump format #3 failing to parse --- lib/stringMsg.js | 2 +- lib/stringMsg.test.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/stringMsg.js b/lib/stringMsg.js index cef0e76..131457b 100644 --- a/lib/stringMsg.js +++ b/lib/stringMsg.js @@ -285,7 +285,7 @@ exports.parseCandump3 = (input) => { const [ timestamp, bus, canFrame ] = input.split(' ') const [ canId, data ] = canFrame.split('#') return buildMsg( - parseCanIdStr(canId), 'candump3', arrBuff(data), { timestamp, bus } + parseCanIdStr(canId), 'candump3', Buffer.from(data, 'hex'), { timestamp, bus } ) } diff --git a/lib/stringMsg.test.js b/lib/stringMsg.test.js index 144efbd..efd0be9 100644 --- a/lib/stringMsg.test.js +++ b/lib/stringMsg.test.js @@ -1,6 +1,6 @@ const { encodeActisense, encodeYDRAW, parseActisense, parseCandump1, parseCandump2, - parsePCDIN, parsePDGY, parseN2kString, parsePDGYdebug, parseYDRAW, encodeActisenseN2KACSII, parseActisenseN2KASCII + parsePCDIN, parsePDGY, parseN2kString, parsePDGYdebug, parseYDRAW, encodeActisenseN2KACSII, parseActisenseN2KASCII, parseCandump3 } = require('./stringMsg') /* globals describe test expect */ @@ -61,6 +61,33 @@ describe('parseMultiLineCandump', () => { }) }) +describe('parseMultiLineCandumpV3', () => { + test('multi line messages', () => { + const msgs = [ + '(0000000000.352000) vcan0 09F20101#601A00B706670D0B', + '(0000000000.353000) vcan0 09F20101#6186BA042600105F', + '(0000000000.354000) vcan0 09F20101#62090000008F027F', + '(0000000000.355000) vcan0 09F20101#63000000007F7FFF' + ] + let res + msgs.forEach((msg) => { + res = parseCandump3(msg) + }) + console.log(res.data.toString('hex')) + expect(res).toEqual({ + bus: "vcan0", + canId: 166854913, + data: Buffer.from('63000000007f7fff', 'hex'), + dst: 255, + format: 'candump3', + src: 1, + pgn: 127489, + prio: 2, + timestamp: '(0000000000.355000)' + }) + }) +}) + describe('parseActisense', () => { test('basic msg', () => { const msg = '2016-04-09T16:41:09.078Z,3,127257,17,255,8,00,ff,7f,52,00,21,fe,ff'