RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
E46 CAN mapping Lua script question
Author Message
Reply with quote
Post E46 CAN mapping Lua script question 
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:
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:
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

View user's profile Send private message
Reply with quote
Post  
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.

View user's profile Send private message
Reply with quote
Post  
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
Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum