setCANfilter
setCANfilter
Can anyone provide a simple example of how to use setCANfilter? Say to read only one particular CAN id only?
Ping - Also Interested.
Right now im achieving this using the logging script provided in the wiki - but im chasing a CAN stream of data that needs to be masked, and this seems like the only way?
I'd like to work this into a specific channel (Say ID 268) and mask 2 bytes (#2,3) with 0FFF...
Cant seem to use Hex, so can i use 1+0?
Right now im achieving this using the logging script provided in the wiki - but im chasing a CAN stream of data that needs to be masked, and this seems like the only way?
I'd like to work this into a specific channel (Say ID 268) and mask 2 bytes (#2,3) with 0FFF...
Cant seem to use Hex, so can i use 1+0?
Code: Select all
setCANfilter(0, 268, 0, 00110000, 0111)
FYI, my code for logging a single CAD ID is below, shown with ID 999, adapted from ASL RCP2 Wiki
https://wiki.autosportlabs.com/CAN_Bus_logger#Script
The key change is
Full Lua Script
https://wiki.autosportlabs.com/CAN_Bus_logger#Script
The key change is
Code: Select all
if id == 999 then
Code: Select all
--500K baud. set your baud rate here.
initCAN(0, 500000)
setTickRate(30) --onTick() will be called at 30Hz.
--this function drains all pending CAN messages
--and outputs messages to the log
function outputCAN()
repeat
id, ext, data = rxCAN(0, 100)
if id == 999 then
print(id ..', ')
for i = 1,#data do
print(data[i] ..', ')
end
println('')
end
until id == nil
end
function onTick()
outputCAN()
end
Adli,
I didn't know how to do hex either - but learned today - very easy. So if DEC=1280 (which is hex 500), were you would enter 1280, enter 0x500. Worked for me.
But if you print the can ID, it will still be in DEC. So I used this little function I found on google:
just stick this function code in before your looping program.
so your print would look like this:
ID will print in HEX
I didn't know how to do hex either - but learned today - very easy. So if DEC=1280 (which is hex 500), were you would enter 1280, enter 0x500. Worked for me.
But if you print the can ID, it will still be in DEC. So I used this little function I found on google:
Code: Select all
function DEC_HEX(IN)
local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
while IN>0 do
I=I+1
IN,D=math.floor(IN/B),math.mod(IN,B)+1
OUT=string.sub(K,D,D)..OUT
end
return OUT
end
so your print would look like this:
Code: Select all
println(DEC_HEX(ID))
so I'm trying to read values off a really busy CAN bus on a few specific ID's. Using the same method as Adli. Not sure it will help anyone else, but my tick rate was 100, and not much was coming thru - set tick rate to 1000, and now data is flowing.
This is not a solution - I think setCANfilter is the solution, awaiting firmware rev 2.10 to fix this......
This is not a solution - I think setCANfilter is the solution, awaiting firmware rev 2.10 to fix this......