setCANfilter

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
lpettipa
Posts: 8
Joined: Mon Jan 11, 2016 6:39 pm

setCANfilter

Post by lpettipa »

Can anyone provide a simple example of how to use setCANfilter? Say to read only one particular CAN id only?

Adli
Posts: 10
Joined: Tue Sep 22, 2015 1:32 am

Post by Adli »

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: Select all

setCANfilter&#40;0, 268, 0, 00110000, 0111&#41;

Adli
Posts: 10
Joined: Tue Sep 22, 2015 1:32 am

Post by Adli »

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: Select all

if id == 999 then
Full Lua Script

Code: Select all

--500K baud. set your baud rate here.
initCAN&#40;0, 500000&#41; 

setTickRate&#40;30&#41;  --onTick&#40;&#41; will be called at 30Hz.

--this function drains all pending CAN messages
--and outputs messages to the log
function outputCAN&#40;&#41;
	repeat 
		id, ext, data = rxCAN&#40;0, 100&#41;
		if id == 999 then
			print&#40;id ..', '&#41;
			for i = 1,#data do
				print&#40;data&#91;i&#93; ..', '&#41;
			end
			println&#40;''&#41;
		end
	until id == nil
end
 
function onTick&#40;&#41;
	outputCAN&#40;&#41;
end

lpettipa
Posts: 8
Joined: Mon Jan 11, 2016 6:39 pm

Post by lpettipa »

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: Select all

function DEC_HEX&#40;IN&#41;
    local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
    while IN>0 do
        I=I+1
        IN,D=math.floor&#40;IN/B&#41;,math.mod&#40;IN,B&#41;+1
        OUT=string.sub&#40;K,D,D&#41;..OUT
    end
    return OUT
end
just stick this function code in before your looping program.

so your print would look like this:

Code: Select all

println&#40;DEC_HEX&#40;ID&#41;&#41;
ID will print in HEX

lpettipa
Posts: 8
Joined: Mon Jan 11, 2016 6:39 pm

Post by lpettipa »

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......

Post Reply