setCANMask/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
imstimpy
Posts: 36
Joined: Tue Nov 24, 2015 11:37 am

setCANMask/setCANFilter

Post by imstimpy »

The documentation partially describes how to use setCANFilter and that it is dependent upon an undocumented setCANMask. If I'm looking at the source code correctly, setCANFilter is implemented but setCANMask is not. If that is the case, is the documentation incorrect and setCANFilter can be set to exclude everything but a supplied ID?

I am trying to write ISO mode $22 packet handling on a bus that is already saturated with RAW communication. I'm currently emulating setCANMask in my own script. When the ECU responds, I pass right through my software filter and process the full packet as expected. When the ECU does not respond, I'm stuck consuming RAW responses. I'm at the point where I have to find a timer to create a timeout condition on my filter when there is no response to my ID.

Here is an example of my filter in need of a timer/candidate to be replaced with setCANFilter/setCANMask:

Code: Select all

repeat
  id, ext, frame = rxCAN&#40;chan&#41;
  if id == nil then
    return
  end
until id == ISO_RXID

imstimpy
Posts: 36
Joined: Tue Nov 24, 2015 11:37 am

Post by imstimpy »

Based upon my research of the stm32, reading numerous posts trying to utilize CAN_FilterInit, my conclusion is setCANfilter ought to be able to provide the filtering I need. However, the posts reference a shift left of 3 or 5, sometimes set the value high or low, depending upon the filter type and data width.

Since setCANfilter forces 32-bit with IdMask mode, how does one manipulate the ID and MASK for the following:
11-bit 0x7e*
29-bit 0x18DA****

I've tried an impossible number of permutations. I can affect the filtering, but cannot explain a logical association between my ID/MASK and the output.
Here is an example of how I'd expect it to work:
setCANfilter(chan, 0, ISO_EXT, 0x18DA0000, 0x1FFF0000)
I believe it should read: 0x18DA0000 == (rxID & 0x1FFF0000) to determine if the rxID is allowed to pass or filtered away.

stieg
Posts: 100
Joined: Fri Dec 20, 2013 1:37 am
Location: Madison, WI
Contact:

Post by stieg »

Hey imstimpy,
The documentation partially describes how to use setCANFilter and that it is dependent upon an undocumented setCANMask. If I'm looking at the source code correctly, setCANFilter is implemented but setCANMask is not. If that is the case, is the documentation incorrect and setCANFilter can be set to exclude everything but a supplied ID?
Dug into this. Indeed the documentation is incorrect. There is no setCANMask Lua method that I can see. So please ignore that and we will update it.
Based upon my research of the stm32, reading numerous posts trying to utilize CAN_FilterInit, my conclusion is setCANfilter ought to be able to provide the filtering I need. However, the posts reference a shift left of 3 or 5, sometimes set the value high or low, depending upon the filter type and data width.

Since setCANfilter forces 32-bit with IdMask mode, how does one manipulate the ID and MASK for the following:
11-bit 0x7e*
29-bit 0x18DA****

I've tried an impossible number of permutations. I can affect the filtering, but cannot explain a logical association between my ID/MASK and the output.
Here is an example of how I'd expect it to work:
setCANfilter(chan, 0, ISO_EXT, 0x18DA0000, 0x1FFF0000)
I believe it should read: 0x18DA0000 == (rxID & 0x1FFF0000) to determine if the rxID is allowed to pass or filtered away.
This appears to be a logical conclusion. I'll ping Brent on this one since he wrote the original code. You may have found a bug with our implementation here. Stay tuned.
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.

imstimpy
Posts: 36
Joined: Tue Nov 24, 2015 11:37 am

Post by imstimpy »

Thanks Andrew. Let me know if there is anything further I can assist with. My project is at a standstill until we can get this resolved.

Frankly, I'm surprised any request/response communications (i.e. OBDII PIDs) work on networks with any significant RAW communication. The CAN API is so low-level, it is not currently possible to send a request and be guaranteed to read only that response. It gets even worse when handling multi-frame packets due to a lack of frame sequencing.

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Hi,

It looks like the main setCANFilter() sets both the CAN mask and filter as part of one call:

Parameters:

setCANfilter(CAN_channel, filter_id, extended_flag, filter, mask)

We'll continue to poke at this. Thanks!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Hi, The Lua documentation for this function incorrectly referenced a setCANMask() function, but the mask itself is the last parameter in the function.

We'll do a round of testing again on the filtering capability, as soon as I link two RCPs together over CAN bus :)
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

imstimpy
Posts: 36
Joined: Tue Nov 24, 2015 11:37 am

Post by imstimpy »

brentp wrote:Hi,

It looks like the main setCANFilter() sets both the CAN mask and filter as part of one call:

Parameters:

setCANfilter(CAN_channel, filter_id, extended_flag, filter, mask)

We'll continue to poke at this. Thanks!
Yes, that is correct. I confirmed it through source code, tracing it all the way down to the utilization of stm32's CAN_FilterInit. However, there is lots of discussion surrounding how the filter and mask should be defined and none of it was working.

I'd love to see functional examples of both 11-bit and 29-bit filter/mask pairs. I could not get the desired behavior for 0x136, any 0x13*, any 0x*1, 0x18DAF110, any 0x18DA, or any 0x*10. I can provide specific examples of the filter/mask pairs, but the behavior I saw made no sense as it related to my pairs.

stieg
Posts: 100
Joined: Fri Dec 20, 2013 1:37 am
Location: Madison, WI
Contact:

Post by stieg »

So just read up on this since I was unfamiliar with this functionality. This was a useful read for me: http://www.cse.dmu.ac.uk/~eg/tele/CanbusIDandMask.html
Since setCANfilter forces 32-bit with IdMask mode, how does one manipulate the ID and MASK for the following:
11-bit 0x7e*
29-bit 0x18DA****
Based on what I read it should be the following

11 bit
Mask: 0xFFFFFFF0
Filter: 0x7E0

That should allow messages 0x7E0 - 0x7EF in (16 in total)

29 bit
Mask: 0xFFFF0000
Filter: 0x18DA0000

That should allow messages 0x18DA0000 - 0x18DAFFFF through (65536 in total).

The latter looks very similar to what you provided above. What was the value of ISO_EXT? Should be 1 for 29 bit addresses
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.

imstimpy
Posts: 36
Joined: Tue Nov 24, 2015 11:37 am

Post by imstimpy »

Stieg, that is all correct except that it doesn't work on the RCP. The only difference between 0x1FFF and 0xFFFF is the upper three bits aren't valid for 29-bit and become ignored.

At first glance, it ought to be that simple, and it is that simple on other hardware. However, the stm32 API appears to require different shifts based upon the filtering mode and filter/mask width. A 29-bit ID of 0x18DA0000, according to some posts, ought to be left-shifted by 3 bits and RCR and something else is masked into the lowest 3 bits resulting in 0xC6D00004 (which also doesn't work). A 16-bit list mode requires a left-shifted by 5, according to a German forum, but the RCP firmware always forces 32-bit ID/mask.

ISO_EXT is 1, however that variable is unused within the RCP firmware.

stieg
Posts: 100
Joined: Fri Dec 20, 2013 1:37 am
Location: Madison, WI
Contact:

Post by stieg »

Filed https://github.com/autosportlabs/RaceCa ... issues/737 to track checking and validating CAN filters. Will you tell us more about how you have things setup. CAN 0 or 1? Address lengths you are trying to use? All of that information may be important in debugging the issue. TIA.
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.

imstimpy
Posts: 36
Joined: Tue Nov 24, 2015 11:37 am

Post by imstimpy »

initCAN(0, 500000)

I'm sending on ISO_TXID = 0x18DA10F1 and looking to receive on ISO_RXID = 0x18DAF110, both 29-bit Honda addressing. I was also experimenting with reading a single RAW_RXID = 0x136.

Attached is my test script for further detail.
Attachments
lua_s2000_test.lua.txt
(5.28 KiB) Downloaded 253 times

imstimpy
Posts: 36
Joined: Tue Nov 24, 2015 11:37 am

Post by imstimpy »

Which firmware release is the fix scheduled for? I'm also curious if you managed to get a good test case. I believe I attempted to replicate the values that would have otherwise been set with the shifts, however they did not work.

stieg
Posts: 100
Joined: Fri Dec 20, 2013 1:37 am
Location: Madison, WI
Contact:

Post by stieg »

Just did merge in the fix 5 minutes ago. Will be part of the next RC for 2.10.0 when that goes out the door. Tested it locally with the script in the linked ticket and got expected output.
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.

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

Post by Adli »

stieg wrote:Just did merge in the fix 5 minutes ago. Will be part of the next RC for 2.10.0 when that goes out the door. Tested it locally with the script in the linked ticket and got expected output.
Good News!

I was struggling with this, specifically with the formatting of the Mask and Filter.
Looking to mask Byte 2 and 3 with 0FFF...

Wont thread jack, ill start another with my specific details, but subbed to this in the mean time.

Ill keep an eye out for 2.10, and hopefully updated documentation?

Thanks!

Post Reply