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