Fixed up ability to send frames while not connected and to show frames

that were sent within the same window as received frames. Added a new
scripting window that can be used to create scripts that send and
receive messages at runtime - not done but sort of working.
This commit is contained in:
Collin Kidder
2015-11-30 20:35:08 -05:00
parent 3fb702e22e
commit 0ff076de3a
17 changed files with 577 additions and 48 deletions
+99
View File
@@ -0,0 +1,99 @@
#include "scriptcontainer.h"
#include <QJSValueIterator>
#include <QDebug>
ScriptContainer::ScriptContainer()
{
fileName = QString();
filePath = QString();
scriptText = QString();
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
}
void ScriptContainer::compileScript()
{
QJSValue result = scriptEngine.evaluate(scriptText, fileName);
if (result.isError() && errorWidget)
{
errorWidget->clear();
errorWidget->addItem("SCRIPT EXCEPTION!");
errorWidget->addItem("Line: " + result.property("lineNumber").toString());
errorWidget->addItem(result.property("message").toString());
errorWidget->addItem("Stack:");
errorWidget->addItem(result.property("stack").toString());
}
else
{
compiledScript = result;
QJSValue hostObj = scriptEngine.newQObject(this);
scriptEngine.globalObject().setProperty("host", hostObj);
setupFunction = scriptEngine.globalObject().property("setup");
gotFrameFunction = scriptEngine.globalObject().property("gotFrame");
tickFunction = scriptEngine.globalObject().property("tick");
if (setupFunction.isCallable())
{
qDebug() << "setup exists";
QJSValue res = setupFunction.call();
if (res.isError())
{
errorWidget->addItem("Error in setup function on line " + res.property("lineNumber").toString());
errorWidget->addItem(res.property("message").toString());
}
}
if (gotFrameFunction.isCallable()) qDebug() << "gotFrame exists";
if (tickFunction.isCallable()) qDebug() << "tick exists";
}
}
void ScriptContainer::setErrorWidget(QListWidget *list)
{
errorWidget = list;
}
void ScriptContainer::setFilter(QJSValue id, QJSValue mask, QJSValue bus)
{
qDebug() << "Called set filter";
qDebug() << id.toInt() << "*" << mask.toInt() << "*" << bus.toInt();
}
void ScriptContainer::setTickInterval(QJSValue interval)
{
int intervalValue = interval.toInt();
qDebug() << "called set tick interval with value " << intervalValue;
if (intervalValue > 0)
{
timer.setInterval(intervalValue);
timer.start();
}
else timer.stop();
}
void ScriptContainer::clearFilters()
{
qDebug() << "Called clear filters";
}
void ScriptContainer::sendFrame(QJSValue id, QJSValue length, QJSValue data)
{
qDebug() << "called send frame";
}
void ScriptContainer::tick()
{
if (tickFunction.isCallable())
{
qDebug() << "Calling tick function";
QJSValue res = tickFunction.call();
if (res.isError())
{
errorWidget->addItem("Error in tick function on line " + res.property("lineNumber").toString());
errorWidget->addItem(res.property("message").toString());
}
}
}