RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
setCANfilter
Author Message
Reply with quote
Post setCANfilter 
Can anyone provide a simple example of how to use setCANfilter? Say to read only one particular CAN id only?

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

Code:
setCANfilter(0, 268, 0, 00110000, 0111)


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

Code:
if id == 999 then


Full Lua Script


Code:
--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


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

Code:
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


just stick this function code in before your looping program.

so your print would look like this:
Code:
println(DEC_HEX(ID))


ID will print in HEX

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

View user's profile Send private message
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