E46 CAN mapping Lua script question
Posted: Sat Sep 23, 2017 8:53 pm
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):
Guessing the data is signed?
Thanks!
Jeff
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
Thanks!
Jeff