Concatenate standard and extended filter

This forum covers issues concerning multiple software products.
Ales1000
Posts: 19
Joined: Fri 4. Oct 2019, 09:01

Concatenate standard and extended filter

Post by Ales1000 » Mon 14. Sep 2020, 13:26

Hello,

I would like to ask you, is it somehow possible to concatenate filter for CAN messages with 11-bit and 29-bit ID?

For example make interval of interest for IDs=<0x111,0x9FF>

I tried to use FilterMessages(4) method with PCAN_MODE_EXTENDED flag, but if I try to pass IDs in interval <0,0x7FF>, the filter seems to be NOT valid.

I also tried to use once FilterMessages(4) method with PCAN_MODE_STANDARD fo IDs in interval <0,0x7FF> and FilterMessages(4) method with PCAN_MODE_EXTENDED flag for bigger IDs. This seems, that the last filter overrides the former filter.

I understand that CAN message with EXTENDED ID looks different than with STANDARD ID, but the same method is used for receiving. There is no CAN_Read_Extended method, from this I assume, that desired functionality must be possible.

The second question: Why use PCAN_FILTER_CUSTOM flag? I read this in the manual, but it looks to be the same as PCAN_FILTER_CLOSE

Thank you.

Ales

M.Heidemann
Sales & Support
Sales & Support
Posts: 486
Joined: Fri 20. Sep 2019, 13:31

Re: Concatenate standard and extended filter

Post by M.Heidemann » Mon 14. Sep 2020, 13:56

Hello Ales,

Please provide us with following information:

Wich OS do you use?

Which software/api do you use and which version?

Which version of the PCAN-driver do you use?

Which Hardware on which firmware version do you use?


Best Regards

Marvin

Ales1000
Posts: 19
Joined: Fri 4. Oct 2019, 09:01

Re: Concatenate standard and extended filter

Post by Ales1000 » Mon 14. Sep 2020, 14:05

Hello Marvin,

Windows 10/Linux (Debian)

PCANBasic API for both of them. The newest one PCAN-Basic V4.4.1.413.

The newest one: 4.2.1.16433

PCAN-USB Pro FD and PCAN-PCI Express FD

Thank you.

Ales

M.Heidemann
Sales & Support
Sales & Support
Posts: 486
Joined: Fri 20. Sep 2019, 13:31

Re: Concatenate standard and extended filter

Post by M.Heidemann » Mon 14. Sep 2020, 14:51

Hello Ales,

thank you for the given information:

To quote the PCANbasic documentation (FilterMessages):
There is only one filter for standard and extended CAN messages. It seems that the ID from a standard message uses the most significant 11 bits (bit 18 to 28) of the 29 bits. I.e. the standard ID 400h is also received by indicating an extended ID 10000000h. For this reason it is not recommended to mix standard and extended filters, since it can increase the risk of receiving unwanted messages.
My recommendation here would be to implement the filter in application (e.g if a "filtered" id is read, do not take any action, the messages will be out of the recveivebuffer but not processed), this will get rid of the hardware-filter beheaviour and undwanted filter results.

As to you second question:

PCAN_Filter_Custom can only be gotten, it returns True if acceptance filter was modified.


Best Regards

Marvin
Last edited by K.Wagner on Mon 14. Sep 2020, 15:15, edited 1 time in total.
Reason: Quote formatting for better reading

Ales1000
Posts: 19
Joined: Fri 4. Oct 2019, 09:01

Re: Concatenate standard and extended filter

Post by Ales1000 » Mon 14. Sep 2020, 15:13

Hello Marvin,

thank you for response. I had read the manual several times before I have wrote this post. I do not understand it clearly. How can be ID=0x400 indicated by ID=0x10000000? What happen then when message with ID 0x10000000 come?

Yeah, implementing filter in API is the way, but it may be slower than using Firmware in HW and also I think that this HW approach prevent to fulling recieve buffer. Also, I wanted to avoid redundant code.

Sorry, but the second answer is not still clear to me. What is different if I use

Code: Select all

iBuffer = PCANBasic::PCAN_FILTER_CUSTOM; //Filter was closed once by SetValue(4)
instead of

Code: Select all

iBuffer = PCANBasic::PCAN_FILTER_CLOSE;
in following code (filter was closed once by SetValue(4))

Code: Select all

...
result = PCANBasic::SetValue(PCANBasic::PCAN_USBBUS1,TPCANParameter::PCAN_MESSAGE_FILTER, iBuffer, sizeof(iBuffer));
if (result != TPCANStatus::PCAN_ERROR_OK)
{
 ...
}
else
{
...
    result = PCANBasic::FilterMessages(PCANBasic::PCAN_USBBUS1, 2, 5, TPCANMode::PCAN_MODE_STANDARD);
..
Last edited by K.Wagner on Mon 14. Sep 2020, 15:17, edited 1 time in total.
Reason: Code formatting for better reading

K.Wagner
Software Development
Software Development
Posts: 768
Joined: Wed 22. Sep 2010, 13:36

Re: Concatenate standard and extended filter

Post by K.Wagner » Mon 14. Sep 2020, 15:50

Hello,
Ales1000 wrote:
Mon 14. Sep 2020, 15:13
I had read the manual several times before I have wrote this post. I do not understand it clearly. How can be ID=0x400 indicated by ID=0x10000000? What happen then when message with ID 0x10000000 come?
As stated in the help from where the information above is quoted, this behavior is related to the SJA1000 CAN controller which is used in our devices. This controller has only one filter (acceptance mask / acceptance code) for both 11-bit and 29-bit CAN Ids. The combination of code and mask used to allow the reception of the standard ID 0x400 also allows the reception of the extended Id 0x10000000. If you want more information on this please check the acceptance filter section of the SJA1000 Application Notes
Ales1000 wrote:
Mon 14. Sep 2020, 15:13
Sorry, but the second answer is not still clear to me. What is different if I use
CODE: SELECT ALL

iBuffer = PCANBasic::PCAN_FILTER_CUSTOM; //Filter was closed once by SetValue(4)
instead of
CODE: SELECT ALL

iBuffer = PCANBasic::PCAN_FILTER_CLOSE;
in following code (filter was closed once by SetValue(4))
CODE: SELECT ALL

...
result = PCANBasic::SetValue(PCANBasic::PCAN_USBBUS1,TPCANParameter::PCAN_MESSAGE_FILTER, iBuffer, sizeof(iBuffer));
if (result != TPCANStatus::PCAN_ERROR_OK)
{
...
}
else
{
...
result = PCANBasic::FilterMessages(PCANBasic::PCAN_USBBUS1, 2, 5, TPCANMode::PCAN_MODE_STANDARD);
..
As Marvin already wrote, PCAN_FILTER_CUSTOM is a value that can only be read. If you try to use CAN_SetValue(PCAN_USBBUS1,PCAN_MESSAGE_FILTER, ...) using als paramter PCAN_FILTER_CUSTOM, then the funcion call will fail with the error PCAN_ERROR_ILLPARAMVAL, and no changes are made to the current configured filter.
Best regards,
Keneth

Ales1000
Posts: 19
Joined: Fri 4. Oct 2019, 09:01

Re: Concatenate standard and extended filter

Post by Ales1000 » Tue 15. Sep 2020, 08:32

Hello,

thank you fo answer and for manual. I looked to filter section.

Now I know, that I can put only one filter. I want to handle also extended IDs, so I choose PCAN_MODE_EXTENDED flag. Tell me please, how to handle the smaller IDs then? Which mask I have to add to IDs or what else should be done? Can I use one filter for accepting both 11-bit and 29-bit CAN IDs? If I use PCAN_MODE_EXTENDED flag, I can only accept extended frames IDs (0x800 and grater).

Ales

K.Wagner
Software Development
Software Development
Posts: 768
Joined: Wed 22. Sep 2010, 13:36

Re: Concatenate standard and extended filter

Post by K.Wagner » Tue 15. Sep 2020, 09:45

Hello,

as we said more times, mixing standard and extended id filters is not a good idea, so there is not a simple answer for this. The best way you can go is to open the filter and do the filtering per software. The messages being received have a property TYPE which tells you if they are STD or EXT ones (among other things).
Best regards,
Keneth

Ales1000
Posts: 19
Joined: Fri 4. Oct 2019, 09:01

Re: Concatenate standard and extended filter

Post by Ales1000 » Tue 15. Sep 2020, 11:31

Hello,

ok, so I can't do this by operation like this (0x001|(1<<31)) for receiving message ID=0x001 with EXTENDED filter flag? If not, I do not understand purpose of this filter, because it is so usuall, that you have mixed CAN-FD or CAN-HIGH messages with STD or EXT flags and you may want to read only few of them.

Ales

K.Wagner
Software Development
Software Development
Posts: 768
Joined: Wed 22. Sep 2010, 13:36

Re: Concatenate standard and extended filter

Post by K.Wagner » Tue 15. Sep 2020, 12:37

Hello,
Ales1000 wrote:
Tue 15. Sep 2020, 11:31
so I can't do this by operation like this (0x001|(1<<31)) for receiving message ID=0x001 with EXTENDED filter flag?
If you want to directly set the acceptance mask and acceptance code as stated in the SJA1000, then you can do this by using the parameter PCAN_ACCEPTANCE_FILTER_29BIT. This pass the given values unmodified to the driver, i.e the calculation of this values is on your side. Information on this can be found in the file PCAN-Parameter_documentation.pdf at page 49, and in the API documentation under Types/TPCANParameter/PCAN_ACCEPTANCE_FILTER_29BIT.
Ales1000 wrote:
Tue 15. Sep 2020, 11:31
I do not understand purpose of this filter, because it is so usuall, that you have mixed CAN-FD or CAN-HIGH messages with STD or EXT flags and you may want to read only few of them.
The filter behavior is as specified for the acceptance filter of the SJA1000 CAN controller, as mentioned several times. This filter is not perfect but was the best at the time the hardware was developed (> 22 years), so hardware and driver are based on it. This is a fact. As described in the SJA1000 specifications, only one filter is used for both 11- and 29-bit Ids, so you may get more messages than expected. This not match all cases of use out of there. This is also a fact.
For these reasons, the most people just open the hardware filter to get all messages and just filter out those unwanted per software; even our own software PCAN-Explorer does so, without a problem (also a fact).

So, to sum up:
  1. The filtering in our driver is based on the SJA1000 CAN controller, which means, it has the same limitations.
  2. The SJA1000 Controller uses a 32-bit mask and a 32-bit code for filtering.
  3. The filter functionality in PCAN-Basic is intended to do simple filtering, which definitely doesn't include mixing STD and EXT IDs.
  4. Mask and code can be directly set using the parameter PCAN_ACCEPTANCE_FILTER_29BIT.
  5. We recommend to configure a filter as best as it pass and do additional filtering over software, to get best results of performance.
Best regards,
Keneth

Locked