Page 1 of 1

Help with bitOp

Posted: Sun Jul 09, 2017 8:03 pm
by Mustangkev
I have an individual bit mapped in the can mapping section but I need to reference it in the LUA script. Can anyone convert this in to a Lua script for me? I am trying to use the cruise control button to start and stop logging. The cruise control dash light is on can ID 1349 and the 4th bit of the first byte. I tried to do this by using the E46 clutch example but I can't get it to work. Here is the channel, Can and filter text that I have in my E46 LUA script that doesn't work.

cruiseId = addChannel("Cruise", 10, 0, 0, 1)

function cruiseFilter(value)
return bit.rshift(, 0x01), 3)

[1349] = function(data) map_chan(cruiseId, data, 0, 1, 1,0,cruiseFilter) end,

This is the working cruise channel from the can mapping.

"add": 0.0,
"bigEndian": false,
"bm": true,
"bus": 0,
"div": 1.0,
"filtId": 0,
"id": 1349,
"idMask": 0,
"len": 1,
"max": 1,
"min": 0,
"mult": 1.0,
"nm": "Cruise",
"offset": 3,
"prec": 0,
"sr": 10,
"type": 0,
"ut": ""

Posted: Fri Jul 14, 2017 12:36 am
by brentp
Basically the easiest way to do it is filter the value using the AND mask (band() ) and then just checking if it's zero (bit not set) or non zero (bit is set).

Try it with just the band() and watch the data using a println() output to the console - that should help you get further!