added basic tests for callback & filters

This commit is contained in:
canpadawan
2016-06-20 17:35:42 +02:00
parent 1a195fe360
commit adb70d2333
3 changed files with 50 additions and 9 deletions
+40 -6
View File
@@ -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 */