linux

canAccept

Syntax


#include <canlib.h>
canStatus canAccept(int handle, long envelope, int flag);

Description

This routine sets the hardware acceptance filters in the CAN controller.

Parameters

handle
An open handle to a CAN circuit.
envelope
The mask or code to set.
flag
Any one of the following values:
ValueMeaning
canFILTER_SET_CODE_STDSets the code for standard (11-bit) identifiers.
canFILTER_SET_MASK_STDSets the mask for standard (11-bit) identifiers.
canFILTER_SET_CODE_EXTSets the code for extended (29-bit) identifiers.
canFILTER_SET_MASK_EXTSets the mask for extended (29-bit) identifiers.
Return Value

canOK (zero) if success
canERR_xxx (negative) if failure.

Code and Mask format

A binary 1 in a mask means "the corresponding bit in the code is relevant"

A binary 0 in a mask means "the corresponding bit in the code is not relevant"

A relevant binary 1 in a code means "the corresponding bit in the identifier must be 1"

A relevant binary 0 in a code means "the corresponding bit in the identifier must be 0"

In other words, the message is accepted if ((code XOR id) AND mask) == 0.

Notes
  • You can set the extended code and mask only on CAN controllers that support extended identifiers.
  • Not all CAN controllers support different masks for standard and extended CAN identifiers.
  • If you want to remove a filter, call canAccept with the mask set to 0.
Related Topics

An example.