E46 CAN mapping Lua script question

Discussions on CAN mapping for ECUs, sensors, PDMs, and more.
Post Reply
jaytee
Posts: 26
Joined: Mon Jul 10, 2017 1:25 am
Location: Atlanta, GA

E46 CAN mapping Lua script question

Post 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

zandr
Posts: 3
Joined: Tue Feb 24, 2015 10:22 pm

Post 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.

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post 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
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply