Page 1 of 1

E46 CAN mapping Lua script question

Posted: Sat Sep 23, 2017 8:53 pm
by jaytee
I was going through the E46 CAN mapping Lua script and it's a great reference as I work through the mappings for my car. Had a question with the handling of the data in a couple cases.

Why is the data bitwise AND in the examples below (bit.band):

Code: Select all

function processWheel(id, data, offset)
  --wheel speed is 13 bits long, little endian
  --low byte high byte
  --76543210 76543210
  --11111111 11111XXX
  local highByte = bit.band(data[offset + 2], 0x1F)
  local lowByte = data[offset + 1]
  local value = highByte * 256 + lowByte
  value = value * 0.0625
  --convert to MPH. comment to keep KPH
  value = value * 0.621371
  setChannel(id, value)
end

Code: Select all

function fuelFilter(value)
  --adjust for 7 bit value
  value = bit.band(value, 0x7F)
  --convert liters to %. tank holds 62.83 liters
  return value / 0.6283
end
Guessing the data is signed?


Thanks!

Jeff

Posted: Fri Oct 06, 2017 3:55 am
by zandr
The E46 has a ton of weird bit-stealing going on, where there's a 12 or 13-bit value, and the remaining bits are flags for some related (or unrelated) value.

I don't remember what's in the rest of the wheel speed bytes off the top of my head. I do know that they stole the high bit of the fuel value for the low-fuel light. (so somewhere around 10L remaining the value will suddenly jump by 128)

BMW likes to use the high bit for sign, rather than something sensible like twos complement.

Posted: Wed Oct 11, 2017 4:26 pm
by brentp
The steering angle sensor for E46 - and later as we found out - Porsche as well, uses that uncommon sign-magnitude format - so we added that to the direct mapping capabilities as a supported data type.
https://wiki.autosportlabs.com/CAN_Bus_Integration