I noticed certain signals were getting decoded incorrectly from one of my DBC files. I tracked this down to signed values that have less bits than the corresponding rust type. For instance if I have a signed signal foo with 4 bits (corresponding to a rust i8):
If I try to set a value of -3, it correctly gets encoded in fn set_foo to the bits [1, 0, 1, 1]. Then in fn foo_raw it was first loading the data as a u8, and since the 4 most significant bits get dropped, the value gets read in as 13 rather than 253. So when that value gets converted to an i8 the result is 13 instead of -3. It seems like bitvec::field::BitSlice::load_le<i8>, on the other hand, works correctly without the intermediate conversion to a u8
I noticed certain signals were getting decoded incorrectly from one of my DBC files. I tracked this down to signed values that have less bits than the corresponding rust type. For instance if I have a signed signal
foo
with 4 bits (corresponding to a rust i8):If I try to set a value of -3, it correctly gets encoded in
fn set_foo
to the bits[1, 0, 1, 1]
. Then infn foo_raw
it was first loading the data as au8
, and since the 4 most significant bits get dropped, the value gets read in as13
rather than253
. So when that value gets converted to ani8
the result is13
instead of-3
. It seems likebitvec::field::BitSlice::load_le<i8>
, on the other hand, works correctly without the intermediate conversion to au8