Removed a few more warnings, switched the way CAN callbacks work.

This commit is contained in:
Collin Kidder
2016-12-30 14:24:17 -05:00
parent 7222870b1e
commit 2758fa8a09
10 changed files with 96 additions and 66 deletions
-1
View File
@@ -107,7 +107,6 @@ HEADERS += mainwindow.h \
connections/connectionwindow.h \ connections/connectionwindow.h \
re/graphingwindow.h \ re/graphingwindow.h \
re/newgraphdialog.h \ re/newgraphdialog.h \
ui/bisectwindow.h \
bisectwindow.h bisectwindow.h
FORMS += ui/candatagrid.ui \ FORMS += ui/candatagrid.ui \
+11 -1
View File
@@ -1,6 +1,7 @@
#ifndef CAN_STRUCTS_H #ifndef CAN_STRUCTS_H
#define CAN_STRUCTS_H #define CAN_STRUCTS_H
#include <QObject>
#include <QVector> #include <QVector>
#include <stdint.h> #include <stdint.h>
@@ -16,10 +17,19 @@ public:
uint64_t timestamp; uint64_t timestamp;
}; };
struct CANFlt class CANFlt
{ {
public:
quint32 id; quint32 id;
quint32 mask; quint32 mask;
QObject * observer; //used to target the specific object that setup this filter
bool operator ==(const CANFlt &b) const
{
if ( (id == b.id) && (mask == b.mask) && (observer == b.observer) ) return true;
return false;
}
}; };
struct J1939ID struct J1939ID
+10 -24
View File
@@ -38,8 +38,6 @@ CANConManager::~CANConManager()
void CANConManager::add(CANConnection* pConn_p) void CANConManager::add(CANConnection* pConn_p)
{ {
//connect(pConn_p, SIGNAL(notify()), this, SLOT(refreshCanList()));
connect(pConn_p, SIGNAL(targettedFrameReceived(CANFrame)), this, SLOT(gotTargettedFrame(CANFrame)));
mConns.append(pConn_p); mConns.append(pConn_p);
emit connectionStatusUpdated(getNumBuses()); emit connectionStatusUpdated(getNumBuses());
} }
@@ -47,7 +45,7 @@ void CANConManager::add(CANConnection* pConn_p)
void CANConManager::remove(CANConnection* pConn_p) void CANConManager::remove(CANConnection* pConn_p)
{ {
disconnect(pConn_p, 0, this, 0); //disconnect(pConn_p, 0, this, 0);
mConns.removeOne(pConn_p); mConns.removeOne(pConn_p);
emit connectionStatusUpdated(getNumBuses()); emit connectionStatusUpdated(getNumBuses());
} }
@@ -184,21 +182,21 @@ bool CANConManager::sendFrames(const QList<CANFrame>& pFrames)
//For each device associated with buses go through and see if that device has a bus //For each device associated with buses go through and see if that device has a bus
//that the filter should apply to. If so forward the data on but fudge //that the filter should apply to. If so forward the data on but fudge
//the bus numbers if bus wasn't -1 so that they're local to the device //the bus numbers if bus wasn't -1 so that they're local to the device
bool CANConManager::addTargettedFrame(int pBusId, const CANFlt &target) bool CANConManager::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
{ {
int tempBusVal; int tempBusVal;
int busBase = 0; int busBase = 0;
foreach (CANConnection* conn, mConns) foreach (CANConnection* conn, mConns)
{ {
if (pBusId == -1) conn->addTargettedFrame(pBusId, target); if (pBusId == -1) conn->addTargettedFrame(pBusId, ID, mask, receiver);
else else
{ {
tempBusVal = pBusId >> busBase; tempBusVal = pBusId >> busBase;
tempBusVal &= ((1 << conn->getNumBuses()) - 1); tempBusVal &= ((1 << conn->getNumBuses()) - 1);
if (tempBusVal) { if (tempBusVal) {
qDebug() << "Forwarding targetted frame setting to a connection object"; qDebug() << "Forwarding targetted frame setting to a connection object";
conn->addTargettedFrame(tempBusVal, target); conn->addTargettedFrame(tempBusVal, ID, mask, receiver);
} }
} }
busBase += conn->getNumBuses(); busBase += conn->getNumBuses();
@@ -206,43 +204,31 @@ bool CANConManager::addTargettedFrame(int pBusId, const CANFlt &target)
return true; return true;
} }
bool CANConManager::removeTargettedFrame(int pBusId, const CANFlt &target) bool CANConManager::removeTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
{ {
int tempBusVal; int tempBusVal;
int busBase = 0; int busBase = 0;
foreach (CANConnection* conn, mConns) foreach (CANConnection* conn, mConns)
{ {
if (pBusId == -1) conn->removeTargettedFrame(pBusId, target); if (pBusId == -1) conn->removeTargettedFrame(pBusId, ID, mask, receiver);
else else
{ {
tempBusVal = pBusId >> busBase; tempBusVal = pBusId >> busBase;
tempBusVal &= ((1 << conn->getNumBuses()) - 1); tempBusVal &= ((1 << conn->getNumBuses()) - 1);
if (tempBusVal) conn->removeTargettedFrame(tempBusVal, target); if (tempBusVal) conn->removeTargettedFrame(tempBusVal, ID, mask, receiver);
} }
busBase += conn->getNumBuses(); busBase += conn->getNumBuses();
} }
return true; return true;
} }
/* bool CANConManager::removeAllTargettedFrames(QObject *receiver)
* A connected CANConnection object has passed us a frame that one or more
* other objects are interested in. Fix up the bus number to be a system global bus
* number instead of connection local bus number then send it off again.
*/
void CANConManager::gotTargettedFrame(CANFrame frame)
{ {
int busBase = 0;
foreach (CANConnection* conn, mConns) foreach (CANConnection* conn, mConns)
{ {
if (conn != sender()) busBase += conn->getNumBuses(); conn->removeAllTargettedFrames(receiver);
else break;
} }
qDebug() << "Targetted frame, offset was " << busBase << " id was " << frame.ID; return true;
frame.bus += busBase;
emit targettedFrameReceived(frame);
} }
+10 -6
View File
@@ -39,27 +39,31 @@ public:
/** /**
* @brief Add a new filter for the targetted frames. If a frame matches it will immediately be sent via the targettedFrameReceived signal * @brief Add a new filter for the targetted frames. If a frame matches it will immediately be sent via the targettedFrameReceived signal
* @param pBusId - Which bus to bond to. -1 for any, otherwise a bitfield of buses (but 0 = first bus, etc) * @param pBusId - Which bus to bond to. -1 for any, otherwise a bitfield of buses (but 0 = first bus, etc)
* @param target - The filter to use for selected targetted frames * @param ID - 11 or 29 bit ID to match against
* @param mask - 11 or 29 bit mask used for filter
* @param receiver - Pointer to a QObject that wants to receive notification when filter is matched
* @return true if filter was able to be added, false otherwise. * @return true if filter was able to be added, false otherwise.
*/ */
bool addTargettedFrame(int pBusId, const CANFlt &target); bool addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver);
/** /**
* @brief Try to find a matching filter in the list and remove it, no longer targetting those frames * @brief Try to find a matching filter in the list and remove it, no longer targetting those frames
* @param pBusId - Which bus to bond to. Doesn't have to match the call to addTargettedFrame exactly. You could disconnect just one bus for instance. * @param pBusId - Which bus to bond to. Doesn't have to match the call to addTargettedFrame exactly. You could disconnect just one bus for instance.
* @param target - The filter that was set * @param ID - 11 or 29 bit ID to match against
* @param mask - 11 or 29 bit mask used for filter
* @param receiver - Pointer to a QObject that wants to receive notification when filter is matched
* @return true if filter was found and deleted, false otherwise. * @return true if filter was found and deleted, false otherwise.
*/ */
bool removeTargettedFrame(int pBusId, const CANFlt &target); bool removeTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver);
bool removeAllTargettedFrames(QObject *receiver);
signals: signals:
void framesReceived(CANConnection* pConn_p, QVector<CANFrame>& pFrames); void framesReceived(CANConnection* pConn_p, QVector<CANFrame>& pFrames);
void targettedFrameReceived(CANFrame frame);
void connectionStatusUpdated(int conns); void connectionStatusUpdated(int conns);
private slots: private slots:
void refreshCanList(); void refreshCanList();
void gotTargettedFrame(CANFrame frame);
private: private:
explicit CANConManager(QObject *parent = 0); explicit CANConManager(QObject *parent = 0);
+38 -13
View File
@@ -256,19 +256,21 @@ void CANConnection::setCapSuspended(bool pIsSuspended) {
mIsCapSuspended = pIsSuspended; mIsCapSuspended = pIsSuspended;
} }
bool CANConnection::addTargettedFrame(int pBusId, const CANFlt &target) bool CANConnection::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
{ {
/* make sure we execute in mThread context */ /*
if( mThread_p && (mThread_p != QThread::currentThread()) ) { if( mThread_p && (mThread_p != QThread::currentThread()) ) {
bool ret; bool ret;
QMetaObject::invokeMethod(this, "addTargettedFrame", QMetaObject::invokeMethod(this, "addTargettedFrame",
Qt::BlockingQueuedConnection, Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, ret), Q_RETURN_ARG(bool, ret),
Q_ARG(int, pBusId), Q_ARG(int, pBusId),
Q_ARG(const CANFlt&, target)); Q_ARG(uint32_t , ID),
Q_ARG(uint32_t , mask),
Q_ARG(QObject *, receiver));
return ret; return ret;
} }
*/
/* sanity checks */ /* sanity checks */
if(pBusId < -1 || pBusId >= (1 << getNumBuses())) if(pBusId < -1 || pBusId >= (1 << getNumBuses()))
return false; return false;
@@ -277,6 +279,10 @@ bool CANConnection::addTargettedFrame(int pBusId, const CANFlt &target)
{ {
if ( (pBusId == -1) || (pBusId && (1 << i)) ) { if ( (pBusId == -1) || (pBusId && (1 << i)) ) {
qDebug() << "Connection is registering a new targetted frame filter"; qDebug() << "Connection is registering a new targetted frame filter";
CANFlt target;
target.id = ID;
target.mask = mask;
target.observer = receiver;
mBusData_p[i].mTargettedFrames.append(target); mBusData_p[i].mTargettedFrames.append(target);
} }
} }
@@ -284,27 +290,47 @@ bool CANConnection::addTargettedFrame(int pBusId, const CANFlt &target)
return true; return true;
} }
bool CANConnection::removeTargettedFrame(int pBusId, const CANFlt &target) bool CANConnection::removeTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
{ {
/* make sure we execute in mThread context */ /*
if( mThread_p && (mThread_p != QThread::currentThread()) ) { if( mThread_p && (mThread_p != QThread::currentThread()) ) {
bool ret; bool ret;
QMetaObject::invokeMethod(this, "addTargettedFrame", QMetaObject::invokeMethod(this, "removeTargettedFrame",
Qt::BlockingQueuedConnection, Qt::BlockingQueuedConnection,
Q_RETURN_ARG(bool, ret), Q_RETURN_ARG(bool, ret),
Q_ARG(int, pBusId), Q_ARG(int, pBusId),
Q_ARG(const CANFlt&, target)); Q_ARG(uint32_t , ID),
Q_ARG(uint32_t , mask),
Q_ARG(QObject *, receiver));
return ret; return ret;
} }
*/
/* sanity checks */ /* sanity checks */
if(pBusId < -1 || pBusId >= (1 << getNumBuses())) if(pBusId < -1 || pBusId >= (1 << getNumBuses()))
return false; return false;
for (int i = 0; i < getNumBuses(); i++) for (int i = 0; i < getNumBuses(); i++)
{ {
//if (pBusId == -1 || (pBusId && (1 << i))) if (pBusId == -1 || (pBusId && (1 << i)))
//mBusData_p[i].mTargettedFrames.removeOne(target); {
CANFlt target;
target.id = ID;
target.mask = mask;
target.observer = receiver;
mBusData_p[i].mTargettedFrames.removeAll(target);
}
}
return true;
}
bool CANConnection::removeAllTargettedFrames(QObject *receiver)
{
for (int i = 0; i < getNumBuses(); i++) {
foreach (const CANFlt filt, mBusData_p[i].mTargettedFrames)
{
if (filt.observer == receiver) mBusData_p[i].mTargettedFrames.removeOne(filt);
}
} }
return true; return true;
@@ -318,8 +344,7 @@ void CANConnection::checkTargettedFrame(CANFrame &frame)
maskedID = frame.ID & filt.mask; maskedID = frame.ID & filt.mask;
if (maskedID == filt.id) { if (maskedID == filt.id) {
qDebug() << "In connection object I got a targetted frame. Forwarding it."; qDebug() << "In connection object I got a targetted frame. Forwarding it.";
emit targettedFrameReceived(frame); QMetaObject::invokeMethod(filt.observer, "gotTargettedFrame",Qt::QueuedConnection, Q_ARG(CANFrame, frame));
return; //only match once then stop.
} }
} }
} }
+15 -4
View File
@@ -151,18 +151,29 @@ public slots:
/** /**
* @brief Add a new filter for the targetted frames. If a frame matches it will immediately be sent via the targettedFrameReceived signal * @brief Add a new filter for the targetted frames. If a frame matches it will immediately be sent via the targettedFrameReceived signal
* @param pBusId - Which bus to bond to. -1 for any, otherwise a bitfield of buses (but 0 = first bus, etc) * @param pBusId - Which bus to bond to. -1 for any, otherwise a bitfield of buses (but 0 = first bus, etc)
* @param target - The filter to use for selected targetted frames * @param ID - 11 or 29 bit ID to match against
* @param mask - 11 or 29 bit mask used for filter
* @param receiver - Pointer to a QObject that wants to receive notification when filter is matched
* @return true if filter was able to be added, false otherwise. * @return true if filter was able to be added, false otherwise.
*/ */
bool addTargettedFrame(int pBusId, const CANFlt &target); bool addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver);
/** /**
* @brief Try to find a matching filter in the list and remove it, no longer targetting those frames * @brief Try to find a matching filter in the list and remove it, no longer targetting those frames
* @param pBusId - Which bus to bond to. Doesn't have to match the call to addTargettedFrame exactly. You could disconnect just one bus for instance. * @param pBusId - Which bus to bond to. Doesn't have to match the call to addTargettedFrame exactly. You could disconnect just one bus for instance.
* @param target - The filter that was set * @param ID - 11 or 29 bit ID to match against
* @param mask - 11 or 29 bit mask used for filter
* @param receiver - Pointer to a QObject that wants to receive notification when filter is matched
* @return true if filter was found and deleted, false otherwise. * @return true if filter was found and deleted, false otherwise.
*/ */
bool removeTargettedFrame(int pBusId, const CANFlt &target); bool removeTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver);
/**
* @brief Removes all registered filters for the passed receiver
* @param receiver - Pointer to a QObject that registered one or more filters
* @return true if filter(s) was/were found and deleted, false otherwise.
*/
bool removeAllTargettedFrames(QObject *receiver);
protected: protected:
+2 -5
View File
@@ -27,22 +27,19 @@ FirmwareUploaderWindow::FirmwareUploaderWindow(const QVector<CANFrame> *frames,
timer = new QTimer(); timer = new QTimer();
timer->setInterval(100); //100ms without a reply will cause us to attempt a resend timer->setInterval(100); //100ms without a reply will cause us to attempt a resend
CANFlt firmwareFilter; CANConManager::getInstance()->addTargettedFrame(-1, 0x100, 0x7F0, this);
firmwareFilter.id = 0x100;
firmwareFilter.mask = 0x7F0;
CANConManager::getInstance()->addTargettedFrame(-1, firmwareFilter);
//MainWindow::getReference()->setTargettedID(baseAddress + 0x10); //MainWindow::getReference()->setTargettedID(baseAddress + 0x10);
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int))); connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
connect(ui->btnLoadFile, SIGNAL(clicked(bool)), this, SLOT(handleLoadFile())); connect(ui->btnLoadFile, SIGNAL(clicked(bool)), this, SLOT(handleLoadFile()));
connect(ui->btnStartStop, SIGNAL(clicked(bool)), this, SLOT(handleStartStopTransfer())); connect(ui->btnStartStop, SIGNAL(clicked(bool)), this, SLOT(handleStartStopTransfer()));
connect(timer, SIGNAL(timeout()), this, SLOT(timerElapsed())); connect(timer, SIGNAL(timeout()), this, SLOT(timerElapsed()));
connect(CANConManager::getInstance(), SIGNAL(targettedFrameReceived(CANFrame)), this, SLOT(gotTargettedFrame(CANFrame)));
} }
FirmwareUploaderWindow::~FirmwareUploaderWindow() FirmwareUploaderWindow::~FirmwareUploaderWindow()
{ {
timer->stop(); timer->stop();
CANConManager::getInstance()->removeAllTargettedFrames(this);
delete timer; delete timer;
delete ui; delete ui;
} }
+3 -3
View File
@@ -1051,8 +1051,8 @@ bool FrameFileIO::saveCANDOFile(QString filename, const QVector<CANFrame>* frame
ms = (thisFrame.timestamp / 1000); ms = (thisFrame.timestamp / 1000);
data[0] = (((ms / 1000) % 60) << 2) + ((ms % 1000) >> 8); data[0] = (((ms / 1000) % 60) << 2) + ((ms % 1000) >> 8);
data[1] = (char)(ms & 0xFF); data[1] = (char)(ms & 0xFF);
data[2] = 0xFF; data[2] = (char)0xFF;
data[3] = 0xFF; data[3] = (char)0xFF;
for (int l = 0; l < 8; l++) data[4 + l] = 0; for (int l = 0; l < 8; l++) data[4 + l] = 0;
outFile->write(data); outFile->write(data);
@@ -1064,7 +1064,7 @@ bool FrameFileIO::saveCANDOFile(QString filename, const QVector<CANFrame>* frame
qApp->processEvents(); qApp->processEvents();
lineCounter = 0; lineCounter = 0;
} }
for (int j = 0; j < 8; j++) data[4 + j] = 0xFF; for (int j = 0; j < 8; j++) data[4 + j] = (char)0xFF;
thisFrame = frames->at(c); thisFrame = frames->at(c);
if (!thisFrame.extended) if (!thisFrame.extended)
+2 -2
View File
@@ -382,7 +382,7 @@ void FlowViewWindow::updatedFrames(int numFrames)
if (!foundID.contains(thisFrame.ID)) if (!foundID.contains(thisFrame.ID))
{ {
foundID.append(thisFrame.ID); foundID.append(thisFrame.ID);
QListWidgetItem* item = new QListWidgetItem(Utility::formatNumber(thisFrame.ID), ui->listFrameID); /*QListWidgetItem* item =*/ new QListWidgetItem(Utility::formatNumber(thisFrame.ID), ui->listFrameID);
} }
if (thisFrame.ID == refID) if (thisFrame.ID == refID)
@@ -495,7 +495,7 @@ void FlowViewWindow::refreshIDList()
if (!foundID.contains(id)) if (!foundID.contains(id))
{ {
foundID.append(id); foundID.append(id);
QListWidgetItem* item = new QListWidgetItem(Utility::formatNumber(id), ui->listFrameID); /*QListWidgetItem* item = */ new QListWidgetItem(Utility::formatNumber(id), ui->listFrameID);
} }
} }
//default is to sort in ascending order //default is to sort in ascending order
+1 -3
View File
@@ -77,9 +77,7 @@ void ScriptContainer::setFilter(QJSValue id, QJSValue mask, QJSValue bus)
foreach(const CANFilter& flt, filters) foreach(const CANFilter& flt, filters)
{ {
if(flt.bus==i) { if(flt.bus==i) {
canFlt.id = idVal; conn_p->addTargettedFrame(busVal, idVal, maskVal, this);
canFlt.mask = maskVal;
conn_p->addTargettedFrame(busVal, canFlt);
} }
} }
} }