Filter Class

(QCanBusDevice::Filter)

The QCanBusDevice::Filter struct defines a filter for CAN bus messages. More...

Header: #include <Filter>
qmake: QT += serialbus
Since: Qt 5.6

Public Types

enum FormatFilter { MatchBaseFormat, MatchExtendedFormat, MatchBaseAndExtendedFormat }
flags FormatFilters

Public Variables

FormatFilter format = MatchBaseAndExtendedFormat
quint32 frameId = 0
quint32 frameIdMask = 0
QCanBusFrame::FrameType type = QCanBusFrame::InvalidFrame

Detailed Description

The QCanBusDevice::Filter struct defines a filter for CAN bus messages.

A list of QCanBusDevice::Filter instances is passed to QCanBusDevice::setConfigurationParameter() to enable filtering. If a received CAN message matches at least one of the filters in the list, the QCanBusDevice will accept it.

The example below demonstrates how to use the struct:

QCanBusDevice::Filter filter;
QList<QCanBusDevice::Filter> filterList;

// filter all CAN bus packages with id 0x444 (base) or 0xXXXXX444 (extended)
filter.frameId = 0x444u;
filter.frameIdMask = 0x7FFu;
filter.format = QCanBusDevice::Filter::MatchBaseAndExtendedFormat;
filter.type = QCanBusFrame::InvalidFrame;
filterList.append(filter);

// filter all DataFrames with extended CAN bus package format
filter.frameId = 0x0;
filter.frameIdMask = 0x0;
filter.format = QCanBusDevice::Filter::MatchExtendedFormat;
filter.type = QCanBusFrame::DataFrame;
filterList.append(filter);

// apply filter
device->setConfigurationParameter(QCanBusDevice::RawFilterKey, QVariant::fromValue(filterList));

Member Type Documentation

enum Filter::FormatFilter
flags Filter::FormatFilters

This enum describes the format pattern, which is used to filter incoming CAN bus messages.

ConstantValueDescription
QCanBusDevice::Filter::MatchBaseFormat0x0001The CAN bus message must use the base message format (11 bit identifier).
QCanBusDevice::Filter::MatchExtendedFormat0x0002The CAN bus message must use the extended message format (29 bit identifier).
QCanBusDevice::Filter::MatchBaseAndExtendedFormat0x0003The CAN bus message can have a base or an extended message format.

The FormatFilters type is a typedef for QFlags<FormatFilter>. It stores an OR combination of FormatFilter values.

Member Variable Documentation

FormatFilter Filter::format = MatchBaseAndExtendedFormat

This variable holds the message format of the matching CAN bus message.

By default this field is set to QCanBusDevice::Filter::MatchBaseAndExtendedFormat.

quint32 Filter::frameId = 0

This variable holds the frame id used to filter the incoming messages.

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

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

By default this field is set to 0x0.

See also frameIdMask.

quint32 Filter::frameIdMask = 0

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

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

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

By default this field is set to 0x0.

See also frameId.

QCanBusFrame::FrameType Filter::type = QCanBusFrame::InvalidFrame

This variable holds the type of the message to be filtered.

Any CAN bus message type can be matched by setting this variable to QCanBusFrame::InvalidFrame. The filter object is invalid if type is equal to QCanBusFrame::UnknownFrame.

By default this field is set to QCanBusFrame::InvalidFrame.

See also QCanBusFrame::FrameType.

© 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.