QCanBusDevice not filtering
-
I have a QCanBusDevice (using SocketCAN) which is successfully receiving frames. I then clear all filters like this:
m_device->setConfigurationParameter(QCanBusDevice::RawFilterKey, QVariant::fromValue(QList<QCanBusDevice::Filter>()));but my device is STILL receiving frames. Why? My understanding is that by default the device has a filter of id 0x00 and mask 0x00 (so accept all frames). But shouldn't my command above effectively remove all filters (so NOTHING should be captured)?
Or do I misunderstand how filters work?
-
I have a QCanBusDevice (using SocketCAN) which is successfully receiving frames. I then clear all filters like this:
m_device->setConfigurationParameter(QCanBusDevice::RawFilterKey, QVariant::fromValue(QList<QCanBusDevice::Filter>()));but my device is STILL receiving frames. Why? My understanding is that by default the device has a filter of id 0x00 and mask 0x00 (so accept all frames). But shouldn't my command above effectively remove all filters (so NOTHING should be captured)?
Or do I misunderstand how filters work?
-
@ocgltd "Passing an empty list clears all previously set filters including default filters" - according to documentation you're removing all filters, so you will receive everything. At least this is my understanding.
@jsulm If I interpret the documentation correctly, the "filters" define which frames are ALLOWED through (if the id & filter match) as described here. So why:
-
if the default filter (which I interpret as id 0x00 mask 0x00) is in place do I receive ALL frames.
-
if no filter is in place (as shown above) do I receive ALL frames.
Something doesn't make sense...one of the above should result in NO frames being accepted. The documentation isn't clear what the "default filter" is but the reference to accepting all frames makes me think 0x00/0x00 is the default since that would match all ID's.
As a test, what filter (id/mask) can I put in place to ensure NO frames are received?
-
-
I'm having the same issue. Receiving all CAN frames regardless of filter. Here is the code I'm working with (version 6.4.0 btw):
if (QCanBus::instance()->plugins().contains(QStringLiteral("vectorcan"))) { QString errorString = QString("Error"); canDevice = QCanBus::instance()->createDevice(QStringLiteral("vectorcan"), QStringLiteral("can0"), &errorString); if (!canDevice) { qDebug() << "Error: " << errorString << Qt::endl; } else { QCanBusDevice::Filter filter; QList<QCanBusDevice::Filter> filterList; filter.frameId = 0x18FFC281; filter.frameIdMask = 0x00FFFFFF; filter.format = QCanBusDevice::Filter::MatchExtendedFormat; filter.type = QCanBusFrame::DataFrame; filterList.append(filter); //apply filter canDevice->setConfigurationParameter(QCanBusDevice::RawFilterKey, QVariant::fromValue(filterList)); //set baud rate canDevice->setConfigurationParameter(QCanBusDevice::BitRateKey, QVariant(250000)); bool connected = canDevice->connectDevice(); if (connected) { connect(canDevice, &QCanBusDevice::framesReceived, this, &CANHandler::ProcessFramesReceived); } else { qDebug() << "Error connecting to device." << Qt::endl; } } }And the slot function:
void CANHandler::ProcessFramesReceived() { while(canDevice->framesAvailable()) { QCanBusFrame frame = canDevice->readFrame(); qDebug() << QString::number(frame.frameId(), 16) << Qt::endl; //every CAN message on the bus appears here } } -
I'm having the same issue. Receiving all CAN frames regardless of filter. Here is the code I'm working with (version 6.4.0 btw):
if (QCanBus::instance()->plugins().contains(QStringLiteral("vectorcan"))) { QString errorString = QString("Error"); canDevice = QCanBus::instance()->createDevice(QStringLiteral("vectorcan"), QStringLiteral("can0"), &errorString); if (!canDevice) { qDebug() << "Error: " << errorString << Qt::endl; } else { QCanBusDevice::Filter filter; QList<QCanBusDevice::Filter> filterList; filter.frameId = 0x18FFC281; filter.frameIdMask = 0x00FFFFFF; filter.format = QCanBusDevice::Filter::MatchExtendedFormat; filter.type = QCanBusFrame::DataFrame; filterList.append(filter); //apply filter canDevice->setConfigurationParameter(QCanBusDevice::RawFilterKey, QVariant::fromValue(filterList)); //set baud rate canDevice->setConfigurationParameter(QCanBusDevice::BitRateKey, QVariant(250000)); bool connected = canDevice->connectDevice(); if (connected) { connect(canDevice, &QCanBusDevice::framesReceived, this, &CANHandler::ProcessFramesReceived); } else { qDebug() << "Error connecting to device." << Qt::endl; } } }And the slot function:
void CANHandler::ProcessFramesReceived() { while(canDevice->framesAvailable()) { QCanBusFrame frame = canDevice->readFrame(); qDebug() << QString::number(frame.frameId(), 16) << Qt::endl; //every CAN message on the bus appears here } } -
@Moocow Are you also using SocketCAN ? Or a different driver (like peakCAN)? Hopefully someone knowledgeable from Qt responds with a clue...
-
@ocgltd I'm using the "vectorcan" plugin with a CAN interface unit from Vector. Haven't been able to try this with different hardware.
-
After looking further into the documentation, it appears the Vector plugin does not support the RawFilterKey with setConfigurationParameter()...