Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCanBusDevice not filtering

QCanBusDevice not filtering

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 813 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by ocgltd
    #1

    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?

    jsulmJ 1 Reply Last reply
    1
    • ocgltdO ocgltd

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      ocgltdO 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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.

        ocgltdO Offline
        ocgltdO Offline
        ocgltd
        wrote on last edited by ocgltd
        #3

        @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?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Moocow
          wrote on last edited by
          #4

          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
              }
          }
          
          ocgltdO 1 Reply Last reply
          0
          • M Moocow

            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
                }
            }
            
            ocgltdO Offline
            ocgltdO Offline
            ocgltd
            wrote on last edited by
            #5

            @Moocow Are you also using SocketCAN ? Or a different driver (like peakCAN)? Hopefully someone knowledgeable from Qt responds with a clue...

            M 1 Reply Last reply
            0
            • ocgltdO ocgltd

              @Moocow Are you also using SocketCAN ? Or a different driver (like peakCAN)? Hopefully someone knowledgeable from Qt responds with a clue...

              M Offline
              M Offline
              Moocow
              wrote on last edited by
              #6

              @ocgltd I'm using the "vectorcan" plugin with a CAN interface unit from Vector. Haven't been able to try this with different hardware.

              M 1 Reply Last reply
              0
              • M Moocow

                @ocgltd I'm using the "vectorcan" plugin with a CAN interface unit from Vector. Haven't been able to try this with different hardware.

                M Offline
                M Offline
                Moocow
                wrote on last edited by
                #7

                After looking further into the documentation, it appears the Vector plugin does not support the RawFilterKey with setConfigurationParameter()...

                ocgltdO 1 Reply Last reply
                0
                • M Moocow

                  After looking further into the documentation, it appears the Vector plugin does not support the RawFilterKey with setConfigurationParameter()...

                  ocgltdO Offline
                  ocgltdO Offline
                  ocgltd
                  wrote on last edited by ocgltd
                  #8

                  @Moocow From what I can find in the documentation SocketCAN should support filtering, so still no answer as to why this isn't working. Hopefully someone from Qt will chime in.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved