linklayer / pyvit

pyvit: Python Vehicle Interface Toolkit
Other
506 stars 149 forks source link

Decoder support for big(?) endian values #14

Closed ulabs-sgiroux closed 7 years ago

ulabs-sgiroux commented 7 years ago

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]

ulabs-sgiroux commented 7 years ago

I can confirm my signal is indeed msbit first.

frame_value in bus.py (https://github.com/linklayer/pyvit/blob/3782e3186b8686c27c453cfec1b6e758c49e83b8/pyvit/bus.py#L57)

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

ericevenchick commented 7 years ago

Closing this for now as the database stuff is very much WIP and might be replaced with Kayak / DBC formats...