Lots of large changes to scripting support, changes to the way
filtering works with ISOTP/UDS messages, updated version number.
This commit is contained in:
@@ -130,7 +130,19 @@ void ISOTP_HANDLER::rapidFrames(const CANConnection* conn, const QVector<CANFram
|
||||
{
|
||||
//only process frames that we've marked are ISOTP frames
|
||||
//unless processAll is true
|
||||
if (isoIDs[thisFrame.ID] || processAll) processFrame(thisFrame);
|
||||
if (processAll) processFrame(thisFrame);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < filters.count(); i++)
|
||||
{
|
||||
if ((thisFrame.bus == filters[i].bus) && ((thisFrame.ID & filters[i].mask) == filters[i].ID))
|
||||
{
|
||||
processFrame(thisFrame);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,18 +339,27 @@ void ISOTP_HANDLER::setProcessAll(bool state)
|
||||
processAll = state;
|
||||
}
|
||||
|
||||
void ISOTP_HANDLER::addID(uint32_t id)
|
||||
void ISOTP_HANDLER::addFilter(int pBusId, uint32_t ID, uint32_t mask)
|
||||
{
|
||||
isoIDs[id] = true;
|
||||
CANFilter filt;
|
||||
filt.ID = ID;
|
||||
filt.bus = pBusId;
|
||||
filt.mask = mask;
|
||||
|
||||
filters.append(filt);
|
||||
}
|
||||
|
||||
void ISOTP_HANDLER::removeID(uint32_t id)
|
||||
void ISOTP_HANDLER::removeFilter(int pBusId, uint32_t ID, uint32_t mask)
|
||||
{
|
||||
isoIDs.remove(id);
|
||||
for (int i = 0; i < filters.count(); i++)
|
||||
{
|
||||
if (filters[i].bus == pBusId && filters[i].ID == ID && filters[i].mask == mask) filters.removeAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
void ISOTP_HANDLER::clearAllIDs()
|
||||
void ISOTP_HANDLER::clearAllFilters()
|
||||
{
|
||||
isoIDs.clear();
|
||||
filters.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "canframemodel.h"
|
||||
#include "isotp_message.h"
|
||||
#include "canfilter.h"
|
||||
|
||||
class ISOTP_HANDLER : public QObject
|
||||
{
|
||||
@@ -22,9 +23,9 @@ public:
|
||||
void sendISOTPFrame(int bus, int ID, QVector<unsigned char> data);
|
||||
void setProcessAll(bool state);
|
||||
void setFlowCtrl(bool state);
|
||||
void addID(uint32_t id);
|
||||
void removeID(uint32_t id);
|
||||
void clearAllIDs();
|
||||
void addFilter(int pBusId, uint32_t ID, uint32_t mask);
|
||||
void removeFilter(int pBusId, uint32_t ID, uint32_t mask);
|
||||
void clearAllFilters();
|
||||
|
||||
public slots:
|
||||
void updatedFrames(int);
|
||||
@@ -37,7 +38,7 @@ signals:
|
||||
private:
|
||||
QList<ISOTP_MESSAGE> messageBuffer;
|
||||
QList<CANFrame> sendingFrames;
|
||||
QMap<uint32_t, bool> isoIDs;
|
||||
QList<CANFilter> filters;
|
||||
const QVector<CANFrame> *modelFrames;
|
||||
bool useExtendedAddressing;
|
||||
bool isReceiving;
|
||||
|
||||
@@ -270,19 +270,18 @@ void UDS_HANDLER::setProcessAllIDs(bool state)
|
||||
isoHandler->setProcessAll(state);
|
||||
}
|
||||
|
||||
void UDS_HANDLER::addID(uint32_t id)
|
||||
void UDS_HANDLER::addFilter(int pBusId, uint32_t ID, uint32_t mask)
|
||||
{
|
||||
isoHandler->addID(id);
|
||||
isoHandler->addFilter(pBusId, ID, mask);
|
||||
}
|
||||
|
||||
void UDS_HANDLER::removeID(uint32_t id)
|
||||
void UDS_HANDLER::removeFilter(int pBusId, uint32_t ID, uint32_t mask)
|
||||
{
|
||||
isoHandler->removeID(id);
|
||||
isoHandler->removeFilter(pBusId, ID, mask);
|
||||
}
|
||||
|
||||
void UDS_HANDLER::clearAllIDs()
|
||||
void UDS_HANDLER::clearAllFilters()
|
||||
{
|
||||
isoHandler->clearAllIDs();
|
||||
isoHandler->clearAllFilters();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -94,9 +94,10 @@ public:
|
||||
void sendUDSFrame(const UDS_MESSAGE &msg);
|
||||
void setProcessAllIDs(bool state);
|
||||
void setFlowCtrl(bool state);
|
||||
void addID(uint32_t id);
|
||||
void removeID(uint32_t id);
|
||||
void clearAllIDs();
|
||||
void addFilter(int pBusId, uint32_t ID, uint32_t mask);
|
||||
void removeFilter(int pBusId, uint32_t ID, uint32_t mask);
|
||||
void clearAllFilters();
|
||||
|
||||
QString getServiceShortDesc(int service);
|
||||
QString getServiceLongDesc(int service);
|
||||
QString getNegativeResponseShort(int respCode);
|
||||
|
||||
+2
-2
@@ -17,14 +17,14 @@ public:
|
||||
uint64_t timestamp;
|
||||
};
|
||||
|
||||
class CANFlt
|
||||
class CANFltObserver
|
||||
{
|
||||
public:
|
||||
quint32 id;
|
||||
quint32 mask;
|
||||
QObject * observer; //used to target the specific object that setup this filter
|
||||
|
||||
bool operator ==(const CANFlt &b) const
|
||||
bool operator ==(const CANFltObserver &b) const
|
||||
{
|
||||
if ( (id == b.id) && (mask == b.mask) && (observer == b.observer) ) return true;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef CONFIG
|
||||
#define CONFIG
|
||||
|
||||
#define VERSION 173
|
||||
#define VERSION 174
|
||||
|
||||
//try to keep this in sync.
|
||||
//SavvyCAN will complain if you connect a GVRET board with a revision
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
struct BusData {
|
||||
CANBus mBus;
|
||||
bool mConfigured;
|
||||
QVector<CANFlt> mTargettedFrames;
|
||||
QVector<CANFltObserver> mTargettedFrames;
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ CANConnection::CANConnection(QString pPort,
|
||||
qRegisterMetaType<CANBus>("CANBus");
|
||||
qRegisterMetaType<CANFrame>("CANFrame");
|
||||
qRegisterMetaType<CANCon::status>("CANCon::status");
|
||||
qRegisterMetaType<CANFlt>("CANFlt");
|
||||
qRegisterMetaType<CANFltObserver>("CANFlt");
|
||||
|
||||
/* set queue size */
|
||||
mQueue.setSize(pQueueLen); /*TODO add check on returned value */
|
||||
@@ -289,7 +289,7 @@ bool CANConnection::addTargettedFrame(int pBusId, uint32_t ID, uint32_t mask, QO
|
||||
return false;
|
||||
|
||||
qDebug() << "Connection is registering a new targetted frame filter, local bus " << pBusId;
|
||||
CANFlt target;
|
||||
CANFltObserver target;
|
||||
target.id = ID;
|
||||
target.mask = mask;
|
||||
target.observer = receiver;
|
||||
@@ -317,7 +317,7 @@ bool CANConnection::removeTargettedFrame(int pBusId, uint32_t ID, uint32_t mask,
|
||||
if(pBusId < -1 || pBusId >= getNumBuses())
|
||||
return false;
|
||||
|
||||
CANFlt target;
|
||||
CANFltObserver target;
|
||||
target.id = ID;
|
||||
target.mask = mask;
|
||||
target.observer = receiver;
|
||||
@@ -329,7 +329,7 @@ bool CANConnection::removeTargettedFrame(int pBusId, uint32_t ID, uint32_t mask,
|
||||
bool CANConnection::removeAllTargettedFrames(QObject *receiver)
|
||||
{
|
||||
for (int i = 0; i < getNumBuses(); i++) {
|
||||
foreach (const CANFlt filt, mBusData_p[i].mTargettedFrames)
|
||||
foreach (const CANFltObserver filt, mBusData_p[i].mTargettedFrames)
|
||||
{
|
||||
if (filt.observer == receiver) mBusData_p[i].mTargettedFrames.removeOne(filt);
|
||||
}
|
||||
@@ -345,7 +345,7 @@ void CANConnection::checkTargettedFrame(CANFrame &frame)
|
||||
if (mBusData_p == 0) return;
|
||||
|
||||
if (mBusData_p[frame.bus].mTargettedFrames.length() == 0) return;
|
||||
foreach (const CANFlt filt, mBusData_p[frame.bus].mTargettedFrames)
|
||||
foreach (const CANFltObserver filt, mBusData_p[frame.bus].mTargettedFrames)
|
||||
{
|
||||
//qDebug() << "Checking filter with id " << filt.id << " mask " << filt.mask;
|
||||
maskedID = frame.ID & filt.mask;
|
||||
|
||||
+1
-1
@@ -396,7 +396,7 @@ void MainWindow::tickGUIUpdate()
|
||||
//{
|
||||
int elapsed = elapsedTime->elapsed();
|
||||
if(elapsed) {
|
||||
framesPerSec = rxFrames * 1000 / elapsed;
|
||||
framesPerSec = (framesPerSec + (rxFrames * 1000 / elapsed)) / 2;
|
||||
elapsedTime->restart();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
class ConnectionWindow;
|
||||
class ISOTP_InterpreterWindow;
|
||||
class ScriptingWindow;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
||||
+146
-2
@@ -7,8 +7,8 @@
|
||||
ScriptContainer::ScriptContainer()
|
||||
{
|
||||
canHelper = new CANScriptHelper(&scriptEngine);
|
||||
isoHelper = new ISOTPScriptHelper;
|
||||
udsHelper = new UDSScriptHelper;
|
||||
isoHelper = new ISOTPScriptHelper(&scriptEngine);
|
||||
udsHelper = new UDSScriptHelper(&scriptEngine);
|
||||
elapsedTime.start();
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||
}
|
||||
@@ -104,6 +104,9 @@ void ScriptContainer::tick()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* CANScriptHandler Methods */
|
||||
|
||||
CANScriptHelper::CANScriptHelper(QJSEngine *engine)
|
||||
@@ -186,3 +189,144 @@ void CANScriptHelper::gotTargettedFrame(const CANFrame &frame)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ISOTPScriptHelper methods */
|
||||
ISOTPScriptHelper::ISOTPScriptHelper(QJSEngine *engine)
|
||||
{
|
||||
scriptEngine = engine;
|
||||
handler = new ISOTP_HANDLER;
|
||||
connect(handler, SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(newISOMessage(ISOTP_MESSAGE)));
|
||||
handler->setReception(true);
|
||||
}
|
||||
|
||||
void ISOTPScriptHelper::clearFilters()
|
||||
{
|
||||
handler->clearAllFilters();
|
||||
}
|
||||
|
||||
void ISOTPScriptHelper::setFilter(QJSValue id, QJSValue mask, QJSValue bus)
|
||||
{
|
||||
uint32_t idVal = id.toUInt();
|
||||
uint32_t maskVal = mask.toUInt();
|
||||
int busVal = bus.toInt();
|
||||
qDebug() << "Called isotp set filter";
|
||||
qDebug() << idVal << "*" << maskVal << "*" << busVal;
|
||||
|
||||
handler->addFilter(busVal, idVal, maskVal);
|
||||
}
|
||||
|
||||
void ISOTPScriptHelper::sendISOTP(QJSValue bus, QJSValue id, QJSValue length, QJSValue data)
|
||||
{
|
||||
ISOTP_MESSAGE msg;
|
||||
msg.extended = false;
|
||||
msg.ID = id.toInt();
|
||||
msg.len = length.toUInt();
|
||||
|
||||
if (!data.isArray()) qDebug() << "data isn't an array";
|
||||
|
||||
for (unsigned int i = 0; i < msg.len; i++)
|
||||
{
|
||||
msg.data[i] = (uint8_t)data.property(i).toInt();
|
||||
}
|
||||
|
||||
msg.bus = (uint32_t)bus.toInt();
|
||||
|
||||
if (msg.ID > 0x7FF) msg.extended = true;
|
||||
|
||||
qDebug() << "sending isotp message from script";
|
||||
handler->sendISOTPFrame(msg.bus, msg.ID, msg.data);
|
||||
}
|
||||
|
||||
void ISOTPScriptHelper::setRxCallback(QJSValue cb)
|
||||
{
|
||||
gotFrameFunction = cb;
|
||||
}
|
||||
|
||||
void ISOTPScriptHelper::newISOMessage(ISOTP_MESSAGE msg)
|
||||
{
|
||||
if (!gotFrameFunction.isCallable()) return; //nothing to do if we can't even call the function
|
||||
//qDebug() << "Got frame in script interface";
|
||||
|
||||
QJSValueList args;
|
||||
args << msg.bus << msg.ID << msg.len;
|
||||
QJSValue dataBytes = scriptEngine->newArray(msg.len);
|
||||
|
||||
for (unsigned int j = 0; j < msg.len; j++) dataBytes.setProperty(j, QJSValue(msg.data[j]));
|
||||
args.append(dataBytes);
|
||||
gotFrameFunction.call(args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* UDSScriptHelper methods */
|
||||
UDSScriptHelper::UDSScriptHelper(QJSEngine *engine)
|
||||
{
|
||||
scriptEngine = engine;
|
||||
handler = new UDS_HANDLER;
|
||||
connect(handler, SIGNAL(newUDSMessage(UDS_MESSAGE)), this, SLOT(newUDSMessage(UDS_MESSAGE)));
|
||||
handler->setReception(true);
|
||||
}
|
||||
|
||||
void UDSScriptHelper::clearFilters()
|
||||
{
|
||||
handler->clearAllFilters();
|
||||
}
|
||||
|
||||
void UDSScriptHelper::setFilter(QJSValue id, QJSValue mask, QJSValue bus)
|
||||
{
|
||||
uint32_t idVal = id.toUInt();
|
||||
uint32_t maskVal = mask.toUInt();
|
||||
int busVal = bus.toInt();
|
||||
qDebug() << "Called uds set filter";
|
||||
qDebug() << idVal << "*" << maskVal << "*" << busVal;
|
||||
|
||||
handler->addFilter(busVal, idVal, maskVal);
|
||||
}
|
||||
|
||||
void UDSScriptHelper::sendUDS(QJSValue bus, QJSValue id, QJSValue service, QJSValue sublen, QJSValue subFunc, QJSValue length, QJSValue data)
|
||||
{
|
||||
UDS_MESSAGE msg;
|
||||
msg.extended = false;
|
||||
msg.ID = id.toInt();
|
||||
msg.len = length.toUInt();
|
||||
msg.service = service.toUInt();
|
||||
msg.subFuncLen = sublen.toUInt();
|
||||
msg.subFunc = subFunc.toUInt();
|
||||
|
||||
if (!data.isArray()) qDebug() << "data isn't an array";
|
||||
|
||||
for (unsigned int i = 0; i < msg.len; i++)
|
||||
{
|
||||
msg.data[i] = (uint8_t)data.property(i).toInt();
|
||||
}
|
||||
|
||||
msg.bus = (uint32_t)bus.toInt();
|
||||
|
||||
if (msg.ID > 0x7FF) msg.extended = true;
|
||||
|
||||
qDebug() << "sending UDS message from script";
|
||||
|
||||
handler->sendUDSFrame(msg);
|
||||
}
|
||||
|
||||
void UDSScriptHelper::setRxCallback(QJSValue cb)
|
||||
{
|
||||
gotFrameFunction = cb;
|
||||
}
|
||||
|
||||
void UDSScriptHelper::newUDSMessage(UDS_MESSAGE msg)
|
||||
{
|
||||
if (!gotFrameFunction.isCallable()) return; //nothing to do if we can't even call the function
|
||||
//qDebug() << "Got frame in script interface";
|
||||
|
||||
QJSValueList args;
|
||||
args << msg.bus << msg.ID << msg.service << msg.subFunc << msg.len;
|
||||
QJSValue dataBytes = scriptEngine->newArray(msg.len);
|
||||
|
||||
for (unsigned int j = 0; j < msg.len; j++) dataBytes.setProperty(j, QJSValue(msg.data[j]));
|
||||
args.append(dataBytes);
|
||||
gotFrameFunction.call(args);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include "can_structs.h"
|
||||
#include "canfilter.h"
|
||||
#include "bus_protocols/isotp_handler.h"
|
||||
#include "bus_protocols/isotp_message.h"
|
||||
#include "bus_protocols/uds_handler.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QJSEngine>
|
||||
@@ -33,17 +36,37 @@ private:
|
||||
class ISOTPScriptHelper: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ISOTPScriptHelper(QJSEngine *engine);
|
||||
public slots:
|
||||
void setFilter(QJSValue id, QJSValue mask, QJSValue bus);
|
||||
void clearFilters();
|
||||
void sendISOTP(QJSValue bus, QJSValue id, QJSValue length, QJSValue data);
|
||||
void setRxCallback(QJSValue cb);
|
||||
private slots:
|
||||
void newISOMessage(ISOTP_MESSAGE msg);
|
||||
private:
|
||||
QJSValue gotFrameFunction;
|
||||
QJSEngine *scriptEngine;
|
||||
ISOTP_HANDLER *handler;
|
||||
};
|
||||
|
||||
class UDSScriptHelper: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
UDSScriptHelper(QJSEngine *engine);
|
||||
public slots:
|
||||
void setFilter(QJSValue id, QJSValue mask, QJSValue bus);
|
||||
void clearFilters();
|
||||
void sendUDS(QJSValue bus, QJSValue id, QJSValue service, QJSValue sublen, QJSValue subFunc, QJSValue length, QJSValue data);
|
||||
void setRxCallback(QJSValue cb);
|
||||
private slots:
|
||||
void newUDSMessage(UDS_MESSAGE msg);
|
||||
private:
|
||||
QJSValue gotFrameFunction;
|
||||
QJSEngine *scriptEngine;
|
||||
UDS_HANDLER *handler;
|
||||
};
|
||||
|
||||
class ScriptContainer : public QObject
|
||||
|
||||
+3
-1
@@ -1,14 +1,16 @@
|
||||
#ifndef SCRIPTINGWINDOW_H
|
||||
#define SCRIPTINGWINDOW_H
|
||||
|
||||
#include "can_structs.h"
|
||||
#include "scriptcontainer.h"
|
||||
#include "can_structs.h"
|
||||
#include "connections/canconnection.h"
|
||||
#include "jsedit.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QJSEngine>
|
||||
|
||||
class ScriptContainer;
|
||||
|
||||
namespace Ui {
|
||||
class ScriptingWindow;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user