QCanBusDevice::Filter Struct

struct QCanBusDevice::Filter

QCanBusDevice::Filter 结构定义了 CAN 总线帧的过滤器。更多

公共类型

enum FormatFilter { MatchBaseFormat, MatchExtendedFormat, MatchBaseAndExtendedFormat }
flags FormatFilters

公共变量

QCanBusDevice::Filter::FormatFilter format
QCanBusFrame::FrameId frameId
QCanBusFrame::FrameId frameIdMask
QCanBusFrame::FrameType type
bool operator!=(const QCanBusDevice::Filter &a, const QCanBusDevice::Filter &b)
bool operator==(const QCanBusDevice::Filter &a, const QCanBusDevice::Filter &b)

详细说明

QCanBusDevice::Filter 实例列表传递给QCanBusDevice::setConfigurationParameter() 以启用过滤功能。如果接收到的 CAN 帧至少与列表中的一个过滤器匹配,QCanBusDevice 就会接受它。

下面的示例演示了如何使用该结构体:

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));

成员类型文档

枚举 Filter::FormatFilter
flags Filter::FormatFilters

该枚举描述格式模式,用于过滤传入的 CAN 总线帧。

常量说明
QCanBusDevice::Filter::MatchBaseFormat0x0001CAN 总线帧必须使用基本帧格式(11 位标识符)。
QCanBusDevice::Filter::MatchExtendedFormat0x0002CAN 总线帧必须使用扩展帧格式(29 位标识符)。
QCanBusDevice::Filter::MatchBaseAndExtendedFormat0x0003CAN 总线帧可以使用基本帧格式或扩展帧格式。

FormatFilters 类型是QFlags<FormatFilter> 的类型定义。它存储格式过滤器值的 OR 组合。

成员变量文档

QCanBusDevice::Filter::FormatFilter Filter::format

该变量用于保存匹配 CAN 总线帧的帧格式。

默认情况下,该字段设置为QCanBusDevice::Filter::MatchBaseAndExtendedFormat

QCanBusFrame::FrameId Filter::frameId

该变量包含用于过滤接收到的帧的帧 ID。

frameId 与frameIdMask 结合使用。如果下面的值为true ,则匹配成功:

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

默认情况下,此字段设置为0x0

另请参阅 frameIdMask

QCanBusFrame::FrameId Filter::frameIdMask

该变量保存应用于过滤器帧 ID 和接收帧的位掩码。

如果下面的值为true ,则这两个帧 id 匹配:

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

默认情况下,此字段设置为0x0

另请参阅 frameId

QCanBusFrame::FrameType Filter::type

该变量表示要过滤的帧的类型。

通过将该变量设置为QCanBusFrame::InvalidFrame ,可以匹配任何 CAN 总线帧类型。如果类型等于QCanBusFrame::UnknownFrame ,则过滤对象无效。

默认情况下,该字段设置为QCanBusFrame::InvalidFrame

另请参阅 QCanBusFrame::FrameType

相关非成员

[constexpr noexcept] bool operator!=(const QCanBusDevice::Filter &a, const QCanBusDevice::Filter &b)

如果过滤器a 不等于过滤器b ,则返回true ,否则返回false

[constexpr noexcept] bool operator==(const QCanBusDevice::Filter &a, const QCanBusDevice::Filter &b)

如果过滤器a 等于过滤器b ,则返回true ,否则返回false

© 2025 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.