Got frame reception and sending working (preliminarily)

This commit is contained in:
Collin Kidder
2015-12-02 19:50:26 -05:00
parent c2e5df6087
commit d324177a7b
2 changed files with 15 additions and 5 deletions
+14 -5
View File
@@ -15,9 +15,11 @@ ScriptContainer::ScriptContainer()
void ScriptContainer::compileScript() void ScriptContainer::compileScript()
{ {
QJSValue result = scriptEngine.evaluate(scriptText, fileName); QJSValue result = scriptEngine.evaluate(scriptText, fileName);
errorWidget->clear();
if (result.isError() && errorWidget) if (result.isError() && errorWidget)
{ {
errorWidget->clear();
errorWidget->addItem("SCRIPT EXCEPTION!"); errorWidget->addItem("SCRIPT EXCEPTION!");
errorWidget->addItem("Line: " + result.property("lineNumber").toString()); errorWidget->addItem("Line: " + result.property("lineNumber").toString());
errorWidget->addItem(result.property("message").toString()); errorWidget->addItem(result.property("message").toString());
@@ -95,9 +97,11 @@ void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSV
if (frame.len < 0) frame.len = 0; if (frame.len < 0) frame.len = 0;
if (frame.len > 8) frame.len = 8; if (frame.len > 8) frame.len = 8;
if (!data.isArray()) qDebug() << "data isn't an array";
for (int i = 0; i < frame.len; i++) for (int i = 0; i < frame.len; i++)
{ {
frame.data[i] = (uint8_t)data.property(0).toInt(); frame.data[i] = (uint8_t)data.property(i).toInt();
} }
frame.bus = bus.toInt(); frame.bus = bus.toInt();
@@ -106,18 +110,23 @@ void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSV
if (frame.ID > 0x7FF) frame.extended = true; if (frame.ID > 0x7FF) frame.extended = true;
//qDebug() << "Sending frame from script";
emit sendCANFrame(&frame, frame.bus); emit sendCANFrame(&frame, frame.bus);
} }
void ScriptContainer::gotFrame(const CANFrame &frame) void ScriptContainer::gotFrame(const CANFrame &frame)
{ {
if (!gotFrameFunction.isCallable()) return; //nothing to do if we can't even call the function if (!gotFrameFunction.isCallable()) return; //nothing to do if we can't even call the function
//qDebug() << "Got frame in script interface";
for (int i = 0; i < filters.length(); i++) for (int i = 0; i < filters.length(); i++)
{ {
if (filters[i].checkFilter(frame.ID, frame.bus)) if (filters[i].checkFilter(frame.ID, frame.bus))
{ {
QJSValueList args; QJSValueList args;
args << frame.bus << frame.ID << frame.len << frame.data; args << frame.bus << frame.ID << frame.len;
QJSValue dataBytes = scriptEngine.newArray(frame.len);
for (int j = 0; j < frame.len; j++) dataBytes.setProperty(j, QJSValue(frame.data[j]));
args.append(dataBytes);
gotFrameFunction.call(args); gotFrameFunction.call(args);
return; //as soon as one filter matches we jump out return; //as soon as one filter matches we jump out
} }
@@ -128,7 +137,7 @@ void ScriptContainer::tick()
{ {
if (tickFunction.isCallable()) if (tickFunction.isCallable())
{ {
qDebug() << "Calling tick function"; //qDebug() << "Calling tick function";
QJSValue res = tickFunction.call(); QJSValue res = tickFunction.call();
if (res.isError()) if (res.isError())
{ {
+1
View File
@@ -34,6 +34,7 @@ void ScriptingWindow::updatedFrames(int numFrames)
//-1 means all frames deleted and -2 means a full refresh, neither of which we care about here. //-1 means all frames deleted and -2 means a full refresh, neither of which we care about here.
if (numFrames > 0) if (numFrames > 0)
{ {
qDebug() << "Got frames into script window: " << numFrames;
//for every new frame pass it on to each script container. The container will determine if it needs to actually //for every new frame pass it on to each script container. The container will determine if it needs to actually
//notify the script and do that if applicable. //notify the script and do that if applicable.
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++) for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)