added basic tests for callback & filters
This commit is contained in:
+40
-6
@@ -1,13 +1,18 @@
|
|||||||
#include <QCanBus>
|
#include <QCanBus>
|
||||||
|
#include <QThread>
|
||||||
|
|
||||||
#include "connectionwindow.h"
|
#include "connectionwindow.h"
|
||||||
#include "ui_connectionwindow.h"
|
#include "ui_connectionwindow.h"
|
||||||
#include "connections/canconfactory.h"
|
#include "connections/canconfactory.h"
|
||||||
|
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
|
||||||
ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ConnectionWindow)
|
ui(new Ui::ConnectionWindow),
|
||||||
|
mRefreshReqOngoing(FALSE)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@@ -75,6 +80,11 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
|
|||||||
mTicker.setInterval(500); /*tick twice a second */
|
mTicker.setInterval(500); /*tick twice a second */
|
||||||
mTicker.setSingleShot(false);
|
mTicker.setSingleShot(false);
|
||||||
mTicker.start();
|
mTicker.start();
|
||||||
|
|
||||||
|
/*test*/
|
||||||
|
/* retrieve pointer on method */
|
||||||
|
int methodIndex = metaObject()->indexOfMethod(QMetaObject::normalizedSignature("refreshCanList()"));
|
||||||
|
mRefreshM = metaObject()->method(methodIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionWindow::~ConnectionWindow()
|
ConnectionWindow::~ConnectionWindow()
|
||||||
@@ -104,17 +114,33 @@ void ConnectionWindow::showEvent(QShowEvent* event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::refreshCanList() {
|
void ConnectionWindow::refreshCanList() {
|
||||||
QList<CANConnection*>::iterator conn_p;
|
|
||||||
QList<CANConnection*>& conns = connModel->getConnections();
|
|
||||||
|
|
||||||
|
QList<CANConnection*>& conns = connModel->getConnections();
|
||||||
CANFrame* frame_p = NULL;
|
CANFrame* frame_p = NULL;
|
||||||
|
|
||||||
for (conn_p = conns.begin(); conn_p != conns.end(); ++conn_p) {
|
foreach (CANConnection* conn_p, conns)
|
||||||
while( (frame_p = (*conn_p)->getQueue().peek() ) ) {
|
{
|
||||||
|
while( (frame_p = conn_p->getQueue().peek() ) ) {
|
||||||
canModel->addFrame(*frame_p, true);
|
canModel->addFrame(*frame_p, true);
|
||||||
(*conn_p)->getQueue().dequeue();
|
conn_p->getQueue().dequeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* erase flag (this should be done before we start dequeuing...) */
|
||||||
|
mRefreshReqOngoing.store(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*test*/
|
||||||
|
void ConnectionWindow::callback(CANCon::cbtype pType)
|
||||||
|
{
|
||||||
|
if(mRefreshReqOngoing.testAndSetRelaxed(FALSE, TRUE))
|
||||||
|
{
|
||||||
|
/* ask for a refresh */
|
||||||
|
mRefreshM.invoke(this, Qt::AutoConnection);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//qDebug() << "skip event";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionWindow::handleNewConn()
|
void ConnectionWindow::handleNewConn()
|
||||||
@@ -272,8 +298,16 @@ void ConnectionWindow::handleOKButton()
|
|||||||
connect(conn_p, SIGNAL(status(CANCon::status)),
|
connect(conn_p, SIGNAL(status(CANCon::status)),
|
||||||
this, SLOT(connectionStatus(CANCon::status)));
|
this, SLOT(connectionStatus(CANCon::status)));
|
||||||
|
|
||||||
|
//conn_p->setCallback(std::bind(&ConnectionWindow::callback, this, std::placeholders::_1));
|
||||||
|
|
||||||
/*TODO add return value and checks */
|
/*TODO add return value and checks */
|
||||||
conn_p->start();
|
conn_p->start();
|
||||||
|
/*{
|
||||||
|
QVector<CANFlt> flters;
|
||||||
|
flters.append({0x305, 0xFFFF, true});
|
||||||
|
conn_p->setFilters(0, flters, false);
|
||||||
|
connect(conn_p, SIGNAL(notify()), this, SLOT(refreshCanList()));
|
||||||
|
}*/
|
||||||
|
|
||||||
for (int i=0 ; i<conn_p->getNumBuses() ; i++) {
|
for (int i=0 ; i<conn_p->getNumBuses() ; i++) {
|
||||||
/* set bus configuration */
|
/* set bus configuration */
|
||||||
|
|||||||
+9
-2
@@ -8,8 +8,9 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
//#include "canconnection_old.h"
|
/*test*/
|
||||||
//#include "serialworker.h"
|
#include <QMetaMethod>
|
||||||
|
/******/
|
||||||
#include "canconnectionmodel.h"
|
#include "canconnectionmodel.h"
|
||||||
#include "canframemodel.h"
|
#include "canframemodel.h"
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ public:
|
|||||||
QString getPortName(); //name of port to connect to
|
QString getPortName(); //name of port to connect to
|
||||||
CANCon::type getConnectionType();
|
CANCon::type getConnectionType();
|
||||||
bool getSWMode();
|
bool getSWMode();
|
||||||
|
void callback(CANCon::cbtype pType);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateBusSettings(CANBus *bus);
|
void updateBusSettings(CANBus *bus);
|
||||||
@@ -68,6 +70,11 @@ private:
|
|||||||
CANFrameModel *canModel;
|
CANFrameModel *canModel;
|
||||||
QTimer mTicker;
|
QTimer mTicker;
|
||||||
|
|
||||||
|
QAtomicInt mRefreshReqOngoing;
|
||||||
|
|
||||||
|
/*test*/
|
||||||
|
QMetaMethod mRefreshM;
|
||||||
|
|
||||||
|
|
||||||
void selectSerial();
|
void selectSerial();
|
||||||
void selectKvaser();
|
void selectKvaser();
|
||||||
|
|||||||
+1
-1
@@ -157,7 +157,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->lbNumFrames->setText("0");
|
ui->lbNumFrames->setText("0");
|
||||||
|
|
||||||
connect(&updateTimer, &QTimer::timeout, this, &MainWindow::tickGUIUpdate);
|
connect(&updateTimer, &QTimer::timeout, this, &MainWindow::tickGUIUpdate);
|
||||||
updateTimer.setInterval(250);
|
updateTimer.setInterval(500); //test 250);
|
||||||
updateTimer.start();
|
updateTimer.start();
|
||||||
|
|
||||||
elapsedTime = new QTime;
|
elapsedTime = new QTime;
|
||||||
|
|||||||
Reference in New Issue
Block a user