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
+12 -26
View File
@@ -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;
}
+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
* @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);
+40 -15
View File
@@ -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));
}
}
}
+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
* @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: