Hi.
I'm using this library to parse a stream of NMEA2k messages from an NGT-1 device. I really like this library - great work btw 👍 But, periodically I get bad values for some PGN's, especially PGN 127489 (Engine Parameters, Dynamic). I've been trying to debug the source of the problem for some time now, and after managing to extract RAW NMEA2k messages and writing Go tests I was able to pinpoint the problem. The 'maxValue' checking that is commented out in the raw_message.go seems to fix the problem:
I also got some help by comparing the raw_message.go:extractNumber(..) with the corresponding extractNumberfunction from the canboat project: https://github.com/canboat/canboat/blob/master/analyzer/pgn.c#L253
So my question is why this code block is commented out?
Here is my Go tests which can reproduce the problem raw_message_test.go:
func TestPgn127489NumberExtraction(t *testing.T) {
var msg = RawMessage{new(can.RawMessage)}
msg.Data = []byte{0x00, 0xe8, 0x08, 0xff, 0xff, 0x73, 0x7d, 0x31, 0x0b, 0x0c, 0x00, 0x80, 0x99, 0x56, 0x04, 0xff, 0xff, 0x60, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00, 0x09, 0x03}
msg.Pgn = uint32(127489)
pgnParsed := ParsePacket(msg.RawMessage)
_, ok := pgnParsed.Data[6].(uint64)
if !ok {
t.Errorf("unable to extract 'total engine hours' from valid RawMessage: %+v\n", pgnParsed.Data[6])
}
// This RawMessage is the 'BAD' one with invalid values. Field 6 should be 'nil' with the proper validation.
msg = RawMessage{new(can.RawMessage)}
msg.Data = []byte{0x00, 0xe8, 0x08, 0xff, 0xff, 0x73, 0x7d, 0x31, 0x0b, 0x0f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0x02, 0xff, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x04}
msg.Pgn = uint32(127489)
pgnParsed = ParsePacket(msg.RawMessage)
engineHours, ok := pgnParsed.Data[6].(uint64)
if ok {
t.Errorf("the value for the field 'total engine hours' is invalid: (%d). Need to check maximum value during extraction. RawMessage: %+v\n", engineHours, pgnParsed.Data[6])
}
}
By uncommenting the maxValue validation checking in raw_message.go:extractNumber(..) this test case works.
Hi.
I'm using this library to parse a stream of NMEA2k messages from an NGT-1 device. I really like this library - great work btw 👍 But, periodically I get bad values for some PGN's, especially PGN 127489 (Engine Parameters, Dynamic). I've been trying to debug the source of the problem for some time now, and after managing to extract RAW NMEA2k messages and writing Go tests I was able to pinpoint the problem. The 'maxValue' checking that is commented out in the
raw_message.goseems to fix the problem:argo/nmea2k/raw_message.go
Line 443 in 11aac9a
I also got some help by comparing the
raw_message.go:extractNumber(..)with the correspondingextractNumberfunction from the canboat project: https://github.com/canboat/canboat/blob/master/analyzer/pgn.c#L253So my question is why this code block is commented out?
Here is my Go tests which can reproduce the problem
raw_message_test.go:By uncommenting the maxValue validation checking in
raw_message.go:extractNumber(..)this test case works.