Removed a few more warnings, switched the way CAN callbacks work.
This commit is contained in:
@@ -107,7 +107,6 @@ HEADERS += mainwindow.h \
|
||||
connections/connectionwindow.h \
|
||||
re/graphingwindow.h \
|
||||
re/newgraphdialog.h \
|
||||
ui/bisectwindow.h \
|
||||
bisectwindow.h
|
||||
|
||||
FORMS += ui/candatagrid.ui \
|
||||
|
||||
+11
-1
@@ -1,6 +1,7 @@
|
||||
#ifndef CAN_STRUCTS_H
|
||||
#define CAN_STRUCTS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -16,10 +17,19 @@ public:
|
||||
uint64_t timestamp;
|
||||
};
|
||||
|
||||
struct CANFlt
|
||||
class CANFlt
|
||||
{
|
||||
public:
|
||||
quint32 id;
|
||||
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
|
||||
|
||||
@@ -37,9 +37,7 @@ CANConManager::~CANConManager()
|
||||
|
||||
|
||||
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);
|
||||
emit connectionStatusUpdated(getNumBuses());
|
||||
}
|
||||
@@ -47,7 +45,7 @@ void CANConManager::add(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);
|
||||
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
|
||||
//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
|
||||
bool CANConManager::addTargettedFrame(int pBusId, const CANFlt &target)
|
||||
bool CANConManager::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver)
|
||||
{
|
||||
int tempBusVal;
|
||||
int busBase = 0;
|
||||
int busBase = 0;
|
||||
|
||||
foreach (CANConnection* conn, mConns)
|
||||
{
|
||||
if (pBusId == -1) conn->addTargettedFrame(pBusId, target);
|
||||
if (pBusId == -1) conn->addTargettedFrame(pBusId, ID, mask, receiver);
|
||||
else
|
||||
{
|
||||
tempBusVal = pBusId >> busBase;
|
||||
tempBusVal &= ((1 << conn->getNumBuses()) - 1);
|
||||
if (tempBusVal) {
|
||||
qDebug() << "Forwarding targetted frame setting to a connection object";
|
||||
conn->addTargettedFrame(tempBusVal, target);
|
||||
conn->addTargettedFrame(tempBusVal, ID, mask, receiver);
|
||||
}
|
||||
}
|
||||
busBase += conn->getNumBuses();
|
||||
@@ -206,43 +204,31 @@ bool CANConManager::addTargettedFrame(int pBusId, const CANFlt &target)
|
||||
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 busBase = 0;
|
||||
|
||||
foreach (CANConnection* conn, mConns)
|
||||
{
|
||||
if (pBusId == -1) conn->removeTargettedFrame(pBusId, target);
|
||||
if (pBusId == -1) conn->removeTargettedFrame(pBusId, ID, mask, receiver);
|
||||
else
|
||||
{
|
||||
tempBusVal = pBusId >> busBase;
|
||||
tempBusVal &= ((1 << conn->getNumBuses()) - 1);
|
||||
if (tempBusVal) conn->removeTargettedFrame(tempBusVal, target);
|
||||
if (tempBusVal) conn->removeTargettedFrame(tempBusVal, ID, mask, receiver);
|
||||
}
|
||||
busBase += conn->getNumBuses();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
bool CANConManager::removeAllTargettedFrames(QObject *receiver)
|
||||
{
|
||||
int busBase = 0;
|
||||
|
||||
foreach (CANConnection* conn, mConns)
|
||||
{
|
||||
if (conn != sender()) busBase += conn->getNumBuses();
|
||||
else break;
|
||||
conn->removeAllTargettedFrames(receiver);
|
||||
}
|
||||
|
||||
qDebug() << "Targetted frame, offset was " << busBase << " id was " << frame.ID;
|
||||
|
||||
frame.bus += busBase;
|
||||
|
||||
emit targettedFrameReceived(frame);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* @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.
|
||||
*/
|
||||
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
|
||||
* @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.
|
||||
*/
|
||||
bool removeTargettedFrame(int pBusId, const CANFlt &target);
|
||||
bool removeTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QObject *receiver);
|
||||
|
||||
bool removeAllTargettedFrames(QObject *receiver);
|
||||
|
||||
signals:
|
||||
void framesReceived(CANConnection* pConn_p, QVector<CANFrame>& pFrames);
|
||||
void targettedFrameReceived(CANFrame frame);
|
||||
void connectionStatusUpdated(int conns);
|
||||
|
||||
private slots:
|
||||
void refreshCanList();
|
||||
void gotTargettedFrame(CANFrame frame);
|
||||
|
||||
private:
|
||||
explicit CANConManager(QObject *parent = 0);
|
||||
|
||||
@@ -256,19 +256,21 @@ void CANConnection::setCapSuspended(bool 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()) ) {
|
||||
bool ret;
|
||||
QMetaObject::invokeMethod(this, "addTargettedFrame",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(bool, ret),
|
||||
Q_ARG(int , pBusId),
|
||||
Q_ARG(const CANFlt&, target));
|
||||
Q_ARG(int, pBusId),
|
||||
Q_ARG(uint32_t , ID),
|
||||
Q_ARG(uint32_t , mask),
|
||||
Q_ARG(QObject *, receiver));
|
||||
return ret;
|
||||
}
|
||||
|
||||
*/
|
||||
/* sanity checks */
|
||||
if(pBusId < -1 || pBusId >= (1 << getNumBuses()))
|
||||
return false;
|
||||
@@ -277,6 +279,10 @@ bool CANConnection::addTargettedFrame(int pBusId, const CANFlt &target)
|
||||
{
|
||||
if ( (pBusId == -1) || (pBusId && (1 << i)) ) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -284,27 +290,47 @@ bool CANConnection::addTargettedFrame(int pBusId, const CANFlt &target)
|
||||
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()) ) {
|
||||
bool ret;
|
||||
QMetaObject::invokeMethod(this, "addTargettedFrame",
|
||||
QMetaObject::invokeMethod(this, "removeTargettedFrame",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(bool, ret),
|
||||
Q_ARG(int , pBusId),
|
||||
Q_ARG(const CANFlt&, target));
|
||||
Q_ARG(int, pBusId),
|
||||
Q_ARG(uint32_t , ID),
|
||||
Q_ARG(uint32_t , mask),
|
||||
Q_ARG(QObject *, receiver));
|
||||
return ret;
|
||||
}
|
||||
|
||||
*/
|
||||
/* sanity checks */
|
||||
if(pBusId < -1 || pBusId >= (1 << getNumBuses()))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < getNumBuses(); i++)
|
||||
{
|
||||
//if (pBusId == -1 || (pBusId && (1 << i)))
|
||||
//mBusData_p[i].mTargettedFrames.removeOne(target);
|
||||
if (pBusId == -1 || (pBusId && (1 << i)))
|
||||
{
|
||||
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;
|
||||
@@ -318,8 +344,7 @@ void CANConnection::checkTargettedFrame(CANFrame &frame)
|
||||
maskedID = frame.ID & filt.mask;
|
||||
if (maskedID == filt.id) {
|
||||
qDebug() << "In connection object I got a targetted frame. Forwarding it.";
|
||||
emit targettedFrameReceived(frame);
|
||||
return; //only match once then stop.
|
||||
QMetaObject::invokeMethod(filt.observer, "gotTargettedFrame",Qt::QueuedConnection, Q_ARG(CANFrame, frame));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
* @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.
|
||||
*/
|
||||
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
|
||||
* @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.
|
||||
*/
|
||||
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:
|
||||
|
||||
|
||||
@@ -27,22 +27,19 @@ FirmwareUploaderWindow::FirmwareUploaderWindow(const QVector<CANFrame> *frames,
|
||||
timer = new QTimer();
|
||||
timer->setInterval(100); //100ms without a reply will cause us to attempt a resend
|
||||
|
||||
CANFlt firmwareFilter;
|
||||
firmwareFilter.id = 0x100;
|
||||
firmwareFilter.mask = 0x7F0;
|
||||
CANConManager::getInstance()->addTargettedFrame(-1, firmwareFilter);
|
||||
CANConManager::getInstance()->addTargettedFrame(-1, 0x100, 0x7F0, this);
|
||||
//MainWindow::getReference()->setTargettedID(baseAddress + 0x10);
|
||||
|
||||
connect(MainWindow::getReference(), SIGNAL(framesUpdated(int)), this, SLOT(updatedFrames(int)));
|
||||
connect(ui->btnLoadFile, SIGNAL(clicked(bool)), this, SLOT(handleLoadFile()));
|
||||
connect(ui->btnStartStop, SIGNAL(clicked(bool)), this, SLOT(handleStartStopTransfer()));
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(timerElapsed()));
|
||||
connect(CANConManager::getInstance(), SIGNAL(targettedFrameReceived(CANFrame)), this, SLOT(gotTargettedFrame(CANFrame)));
|
||||
}
|
||||
|
||||
FirmwareUploaderWindow::~FirmwareUploaderWindow()
|
||||
{
|
||||
timer->stop();
|
||||
CANConManager::getInstance()->removeAllTargettedFrames(this);
|
||||
delete timer;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1051,8 +1051,8 @@ bool FrameFileIO::saveCANDOFile(QString filename, const QVector<CANFrame>* frame
|
||||
ms = (thisFrame.timestamp / 1000);
|
||||
data[0] = (((ms / 1000) % 60) << 2) + ((ms % 1000) >> 8);
|
||||
data[1] = (char)(ms & 0xFF);
|
||||
data[2] = 0xFF;
|
||||
data[3] = 0xFF;
|
||||
data[2] = (char)0xFF;
|
||||
data[3] = (char)0xFF;
|
||||
for (int l = 0; l < 8; l++) data[4 + l] = 0;
|
||||
outFile->write(data);
|
||||
|
||||
@@ -1064,7 +1064,7 @@ bool FrameFileIO::saveCANDOFile(QString filename, const QVector<CANFrame>* frame
|
||||
qApp->processEvents();
|
||||
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);
|
||||
if (!thisFrame.extended)
|
||||
|
||||
@@ -382,7 +382,7 @@ void FlowViewWindow::updatedFrames(int numFrames)
|
||||
if (!foundID.contains(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)
|
||||
@@ -495,7 +495,7 @@ void FlowViewWindow::refreshIDList()
|
||||
if (!foundID.contains(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
|
||||
|
||||
+1
-3
@@ -77,9 +77,7 @@ void ScriptContainer::setFilter(QJSValue id, QJSValue mask, QJSValue bus)
|
||||
foreach(const CANFilter& flt, filters)
|
||||
{
|
||||
if(flt.bus==i) {
|
||||
canFlt.id = idVal;
|
||||
canFlt.mask = maskVal;
|
||||
conn_p->addTargettedFrame(busVal, canFlt);
|
||||
conn_p->addTargettedFrame(busVal, idVal, maskVal, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user