Skip to content

Commit

Permalink
fix: candump format #3 failing to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 committed Aug 7, 2024
1 parent a9d1f92 commit 34ed2e4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/stringMsg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
)
}

Expand Down
29 changes: 28 additions & 1 deletion lib/stringMsg.test.js
Original file line number Diff line number Diff line change
@@ -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 */
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 34ed2e4

Please sign in to comment.