ISOTP and Scripting bug fixes

This commit is contained in:
Collin Kidder
2018-02-04 18:11:25 -05:00
parent 028a108169
commit 96b73bd1ca
5 changed files with 70 additions and 23 deletions
+7 -1
View File
@@ -9,6 +9,7 @@ ISOTP_HANDLER::ISOTP_HANDLER()
processAll = false; processAll = false;
lastSenderBus = 0; lastSenderBus = 0;
lastSenderID = 0; lastSenderID = 0;
issuedMultiFrame = false;
modelFrames = MainWindow::getReference()->getCANFrameModel()->getListReference(); modelFrames = MainWindow::getReference()->getCANFrameModel()->getListReference();
@@ -60,6 +61,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QVector<unsigned char> data)
if (data.length() < 8) if (data.length() < 8)
{ {
issuedMultiFrame = false;
frame.bus = bus; frame.bus = bus;
frame.extended = false; frame.extended = false;
frame.ID = ID; frame.ID = ID;
@@ -71,6 +73,7 @@ void ISOTP_HANDLER::sendISOTPFrame(int bus, int ID, QVector<unsigned char> data)
} }
else //need to send a multi-part ISO_TP message - Respects timing and frame number based flow control else //need to send a multi-part ISO_TP message - Respects timing and frame number based flow control
{ {
issuedMultiFrame = true;
frame.bus = bus; frame.bus = bus;
frame.ID = ID; frame.ID = ID;
frame.extended = false; frame.extended = false;
@@ -200,6 +203,7 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame)
msg.ID = ID; msg.ID = ID;
msg.timestamp = frame.timestamp; msg.timestamp = frame.timestamp;
msg.isReceived = frame.isReceived; msg.isReceived = frame.isReceived;
issuedMultiFrame = true;
frameLen = frameLen << 8; frameLen = frameLen << 8;
if (useExtendedAddressing) if (useExtendedAddressing)
{ {
@@ -220,7 +224,7 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame)
messageBuffer.append(msg); messageBuffer.append(msg);
//The sending ID is set to the last ID we used to send from this class which is //The sending ID is set to the last ID we used to send from this class which is
//very likely to be correct. But, caution, there is a chance that it isn't. Beware. //very likely to be correct. But, caution, there is a chance that it isn't. Beware.
if (issueFlowMsgs && lastSenderID > 0) if (issueFlowMsgs && lastSenderID > 0 && issuedMultiFrame)
{ {
CANFrame outFrame; CANFrame outFrame;
outFrame.bus = lastSenderBus; outFrame.bus = lastSenderBus;
@@ -260,6 +264,7 @@ void ISOTP_HANDLER::processFrame(const CANFrame &frame)
if (pMsg->len <= pMsg->data.count()) if (pMsg->len <= pMsg->data.count())
{ {
//qDebug() << "Emitting multiframe ISOTP message"; //qDebug() << "Emitting multiframe ISOTP message";
issuedMultiFrame = false;
emit newISOMessage(*pMsg); emit newISOMessage(*pMsg);
} }
break; break;
@@ -300,6 +305,7 @@ void ISOTP_HANDLER::checkNeedFlush(uint64_t ID)
//used to pass by reference but now newISOMessage should pass by value which makes it easier to use cross thread //used to pass by reference but now newISOMessage should pass by value which makes it easier to use cross thread
//qDebug() << "Flushing a partial frame"; //qDebug() << "Flushing a partial frame";
emit newISOMessage(messageBuffer[i]); emit newISOMessage(messageBuffer[i]);
issuedMultiFrame = false;
messageBuffer.removeAt(i); messageBuffer.removeAt(i);
return; return;
} }
+1
View File
@@ -46,6 +46,7 @@ private:
int framesUntilFlow; int framesUntilFlow;
bool processAll; bool processAll;
bool issueFlowMsgs; bool issueFlowMsgs;
bool issuedMultiFrame;
QTimer frameTimer; QTimer frameTimer;
uint32_t lastSenderID; uint32_t lastSenderID;
uint32_t lastSenderBus; uint32_t lastSenderBus;
+53 -19
View File
@@ -6,15 +6,47 @@
ScriptContainer::ScriptContainer() ScriptContainer::ScriptContainer()
{ {
canHelper = new CANScriptHelper(&scriptEngine); qDebug() << "Script Container Constructor";
isoHelper = new ISOTPScriptHelper(&scriptEngine); scriptEngine = new QJSEngine();
udsHelper = new UDSScriptHelper(&scriptEngine); canHelper = new CANScriptHelper(scriptEngine);
isoHelper = new ISOTPScriptHelper(scriptEngine);
udsHelper = new UDSScriptHelper(scriptEngine);
connect(&timer, SIGNAL(timeout()), this, SLOT(tick())); connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
} }
ScriptContainer::~ScriptContainer()
{
qDebug() << "Script Container Destructor " << (uint64_t)this << "c: " << (uint64_t)canHelper;
timer.stop();
disconnect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
if (scriptEngine)
{
scriptText = "";
compileScript();
//delete scriptEngine; //doing this here seems to cause a crash. No crash if you don't.
//scriptEngine = NULL;
}
if (canHelper)
{
delete canHelper;
canHelper = NULL;
}
if (isoHelper)
{
delete isoHelper;
isoHelper = NULL;
}
if (udsHelper)
{
delete udsHelper;
udsHelper = NULL;
}
qDebug() << "end of destruct";
}
void ScriptContainer::compileScript() void ScriptContainer::compileScript()
{ {
QJSValue result = scriptEngine.evaluate(scriptText, fileName); QJSValue result = scriptEngine->evaluate(scriptText, fileName);
emit sendLog("Compiling script..."); emit sendLog("Compiling script...");
@@ -37,22 +69,22 @@ void ScriptContainer::compileScript()
//Add a bunch of helper objects into javascript that the scripts //Add a bunch of helper objects into javascript that the scripts
//can use to interact with the CAN buses //can use to interact with the CAN buses
QJSValue hostObj = scriptEngine.newQObject(this); QJSValue hostObj = scriptEngine->newQObject(this);
scriptEngine.globalObject().setProperty("host", hostObj); scriptEngine->globalObject().setProperty("host", hostObj);
QJSValue canObj = scriptEngine.newQObject(canHelper); QJSValue canObj = scriptEngine->newQObject(canHelper);
scriptEngine.globalObject().setProperty("can", canObj); scriptEngine->globalObject().setProperty("can", canObj);
QJSValue isoObj = scriptEngine.newQObject(isoHelper); QJSValue isoObj = scriptEngine->newQObject(isoHelper);
scriptEngine.globalObject().setProperty("isotp", isoObj); scriptEngine->globalObject().setProperty("isotp", isoObj);
QJSValue udsObj = scriptEngine.newQObject(udsHelper); QJSValue udsObj = scriptEngine->newQObject(udsHelper);
scriptEngine.globalObject().setProperty("uds", udsObj); scriptEngine->globalObject().setProperty("uds", udsObj);
//Find out which callbacks the script has created. //Find out which callbacks the script has created.
setupFunction = scriptEngine.globalObject().property("setup"); setupFunction = scriptEngine->globalObject().property("setup");
canHelper->setRxCallback(scriptEngine.globalObject().property("gotCANFrame")); canHelper->setRxCallback(scriptEngine->globalObject().property("gotCANFrame"));
isoHelper->setRxCallback(scriptEngine.globalObject().property("gotISOTPMessage")); isoHelper->setRxCallback(scriptEngine->globalObject().property("gotISOTPMessage"));
udsHelper->setRxCallback(scriptEngine.globalObject().property("gotUDSMessage")); udsHelper->setRxCallback(scriptEngine->globalObject().property("gotUDSMessage"));
tickFunction = scriptEngine.globalObject().property("tick"); tickFunction = scriptEngine->globalObject().property("tick");
if (setupFunction.isCallable()) if (setupFunction.isCallable())
{ {
@@ -117,7 +149,7 @@ void ScriptContainer::updateValuesTable(QTableWidget *widget)
foreach (QString paramName, scriptParams) foreach (QString paramName, scriptParams)
{ {
valu = scriptEngine.globalObject().property(paramName).toString(); valu = scriptEngine->globalObject().property(paramName).toString();
qDebug() << paramName << " - " << valu; qDebug() << paramName << " - " << valu;
bool found = false; bool found = false;
for (int i = 0; i < widget->rowCount(); i++) for (int i = 0; i < widget->rowCount(); i++)
@@ -152,7 +184,7 @@ void ScriptContainer::updateParameter(QString name, QString value)
{ {
qDebug() << name << " * " << value; qDebug() << name << " * " << value;
QJSValue val(value); QJSValue val(value);
scriptEngine.globalObject().setProperty(name, val); scriptEngine->globalObject().setProperty(name, val);
} }
@@ -249,6 +281,7 @@ ISOTPScriptHelper::ISOTPScriptHelper(QJSEngine *engine)
handler = new ISOTP_HANDLER; handler = new ISOTP_HANDLER;
connect(handler, SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(newISOMessage(ISOTP_MESSAGE))); connect(handler, SIGNAL(newISOMessage(ISOTP_MESSAGE)), this, SLOT(newISOMessage(ISOTP_MESSAGE)));
handler->setReception(true); handler->setReception(true);
handler->setFlowCtrl(true);
} }
void ISOTPScriptHelper::clearFilters() void ISOTPScriptHelper::clearFilters()
@@ -319,6 +352,7 @@ UDSScriptHelper::UDSScriptHelper(QJSEngine *engine)
handler = new UDS_HANDLER; handler = new UDS_HANDLER;
connect(handler, SIGNAL(newUDSMessage(UDS_MESSAGE)), this, SLOT(newUDSMessage(UDS_MESSAGE))); connect(handler, SIGNAL(newUDSMessage(UDS_MESSAGE)), this, SLOT(newUDSMessage(UDS_MESSAGE)));
handler->setReception(true); handler->setReception(true);
handler->setFlowCtrl(true);
} }
void UDSScriptHelper::clearFilters() void UDSScriptHelper::clearFilters()
+2 -1
View File
@@ -77,6 +77,7 @@ class ScriptContainer : public QObject
public: public:
ScriptContainer(); ScriptContainer();
virtual ~ScriptContainer();
void setScriptWindow(ScriptingWindow *win); void setScriptWindow(ScriptingWindow *win);
QString fileName; QString fileName;
@@ -102,7 +103,7 @@ private slots:
void tick(); void tick();
private: private:
QJSEngine scriptEngine; QJSEngine *scriptEngine;
QJSValue compiledScript; QJSValue compiledScript;
QJSValue setupFunction; QJSValue setupFunction;
QJSValue tickFunction; QJSValue tickFunction;
+7 -2
View File
@@ -204,7 +204,7 @@ void ScriptingWindow::loadNewScript()
QString justFileName = fileList[fileList.length() - 1]; QString justFileName = fileList[fileList.length() - 1];
ui->listLoadedScripts->addItem(justFileName); ui->listLoadedScripts->addItem(justFileName);
container = new ScriptContainer; container = new ScriptContainer();
container->fileName = justFileName; container->fileName = justFileName;
container->filePath = filename; container->filePath = filename;
container->scriptText = contents; container->scriptText = contents;
@@ -223,7 +223,7 @@ void ScriptingWindow::createNewScript()
{ {
ScriptContainer *container; ScriptContainer *container;
container = new ScriptContainer; container = new ScriptContainer();
container->fileName = "UNNAMED_" + QString::number((qrand() % 10000)) + ".js"; container->fileName = "UNNAMED_" + QString::number((qrand() % 10000)) + ".js";
container->filePath = QString(); container->filePath = QString();
@@ -238,6 +238,8 @@ void ScriptingWindow::createNewScript()
void ScriptingWindow::deleteCurrentScript() void ScriptingWindow::deleteCurrentScript()
{ {
ScriptContainer* thisScript;
int sel = ui->listLoadedScripts->currentRow(); int sel = ui->listLoadedScripts->currentRow();
if (sel < 0) return; if (sel < 0) return;
@@ -250,7 +252,10 @@ void ScriptingWindow::deleteCurrentScript()
{ {
case QMessageBox::Yes: case QMessageBox::Yes:
ui->listLoadedScripts->takeItem(sel); ui->listLoadedScripts->takeItem(sel);
thisScript = scripts.at(sel);
scripts.removeAt(sel); scripts.removeAt(sel);
delete thisScript; //causes a seg fault. Seems to be due to currently running javascript code. No idea how to stop code from running
thisScript = NULL;
currentScript = NULL; currentScript = NULL;
if (ui->listLoadedScripts->count() > 0) if (ui->listLoadedScripts->count() > 0)