Decoder support for big(?) endian values
ulabs-sgiroux opened this issue · 2 comments
I'm not sure of the byte ordering for candump files (e.g. (time) interface msg_id#msg_Data) but I have a signal which spans bytes 6 and 7 (reading left to right) with 6 being the most significant byte.
My database.json's signal starts at bit 40, and has a bit_length of 16 but I believe the parser is treating bit 40 as the LSB (instead of MSB in my case)
Reference:
{
"messages": [
{
"name": "test msg",
"id": "0x080",
"signals":
{
"40":
{
"name": "MSB Data",
"bit_length": 16,
"factor": 1,
"offset": 0
}
}
}
]
}
ID=0x080, DLC=8, Data=[90, 00, 7D, 00, 00, 80, 0E, F7]
I can confirm my signal is indeed msbit first.
frame_value in bus.py (
Line 57 in 3782e31
Current:
a = [1,2,3]
frame_value = 0
for i in range(0, len(a))
frame_value = frame_value + (a[i] << 8 * i)
"{0:b}".format(frame_value)
0000 0011 0000 0010 0000 0001
[3,2,1]
For MSB:
a = [1,2,3]
frame_value = 0
for i in range(0, len(a))
frame_value = frame_value + (a[len(a)-i-1] << 8 * i)
"{0:b}".format(frame_value)
0000 0001 0000 0010 0000 0011
[1,2,3]
So for a 9-bit signal with frame data SHOULD look like:
Data=[0x00, 0x00, ...] => 0
Data=[0x00, 0x64, ...] => 100
Data=[0x01, 0x10, ...] => 272
Closing this for now as the database stuff is very much WIP and might be replaced with Kayak / DBC formats...