CanFilter

Description

The CanFilter object represents a filter for CAN frames. CAN frame filtering happens at the driver and hardware level and is thus very efficient. This can be used on CAN nodes which need to receive CAN frames for their own frame id only.

This object was introduced in InCore 2.0.

› Inherits:Object

Properties

format

This property holds the frame format of the matching CAN bus frame.

› Type:Format
› Default:CanFilter.MatchBaseAndExtendedFormat
› Signal:formatChanged()
› Attributes:Writable

frameId

This property holds the frame id used to filter the incoming frames.

The frameId is used in conjunction with frameIdMask. The matching is successful if the following evaluates to true:

(receivedFrameId & frameIdMask) == (frameId & frameIdMask)

› Type:UnsignedInteger
› Default:0
› Signal:frameIdChanged()
› Attributes:Writable

frameIdMask

This property holds the bit mask that is applied to the frame id of the filter and the received frame.

The two frame ids are matching if the following evaluates to true:

(receivedFrameId & frameIdMask) == (frameId & frameIdMask)

› Type:UnsignedInteger
› Default:0
› Signal:frameIdMaskChanged()
› Attributes:Writable

type

This property holds the type of the frame to be filtered. Any CAN bus frame type can be matched by setting this property to CanFrame.InvalidFrame. The filter object is invalid if type is equal to CanFrame.UnknownFrame.

› Type:CanFrame.Type
› Default:CanFrame.InvalidFrame
› Signal:typeChanged()
› Attributes:Writable

Enumerations

Format

This enumeration describes the format pattern, which is used to filter incoming CanFrame.

Name Value Description
CanFilter.MatchBaseFormat 1 The CAN bus frame must use the base frame format (11 bit identifier).
CanFilter.MatchExtendedFormat 2 The CAN bus frame must use the extended frame format (29 bit identifier).
CanFilter.MatchBaseAndExtendedFormat 3 The CAN bus frame can have a base or an extended frame format.

Example

import InCore.Foundation 2.5
import InCore.IO 2.5

Application {

    CanBus {
        // assume nodes encode their address in bits 8..10 and message type in bits 0..7 of the CAN frame id
        // then this configuration will make the bus receive only frames (any message type) from slave 4 and
        // error frames from any slave
        rawFilters: [
            CanFilter {
                type: CanFrame.DataFrame
                frameId: 4 << 8
                frameIdMask: 0xff00
            },
            CanFilter {
                type: CanFrame.ErrorFrame
            }
        ]

        onFrameReceived: {
            console.log("Received CAN frame with ID", currentFrame.frameId, "and payload", currentFrame.payload.hex)
        }
    }
}