QCanBusDevice::Filter Struct
struct QCanBusDevice::FilterQCanBusDevice::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));成员类型文档
enum Filter::FormatFilter
flags Filter::FormatFilters
该枚举描述了用于过滤传入 CAN 总线帧的格式模式。
| 常量 | 值 | 描述 |
|---|---|---|
QCanBusDevice::Filter::MatchBaseFormat | 0x0001 | CAN 总线帧必须使用基本帧格式(11 位标识符)。 |
QCanBusDevice::Filter::MatchExtendedFormat | 0x0002 | CAN 总线帧必须使用扩展帧格式(29 位标识符)。 |
QCanBusDevice::Filter::MatchBaseAndExtendedFormat | 0x0003 | CAN 总线帧可以采用基本帧格式或扩展帧格式。 |
FormatFilters 类型是QFlags<FormatFilter> 的 typedef。它存储 FormatFilter 值的按“或”运算组合。
成员变量文档
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
该变量存储了应用于过滤器帧标识符和接收帧的位掩码。
如果以下表达式的结果为true ,则这两个帧ID匹配:
(receivedFrameId & frameIdMask) == (frameId & frameIdMask)默认情况下,该字段设置为0x0 。
另请参阅 frameId 。
QCanBusFrame::FrameType Filter::type
该变量存储待过滤帧的类型。
将此变量设置为QCanBusFrame::InvalidFrame 即可匹配任何CAN总线帧类型。若type等于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 。
© 2026 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.