| 45 | } |
| 46 | |
| 47 | void ScriptContainer::compileScript() |
| 48 | { |
| 49 | QJSValue result = scriptEngine->evaluate(scriptText, fileName); |
| 50 | |
| 51 | emit sendLog("Compiling script..."); |
| 52 | |
| 53 | canHelper->clearFilters(); |
| 54 | isoHelper->clearFilters(); |
| 55 | udsHelper->clearFilters(); |
| 56 | |
| 57 | if (result.isError()) |
| 58 | { |
| 59 | |
| 60 | emit sendLog("SCRIPT EXCEPTION!"); |
| 61 | emit sendLog("Line: " + result.property("lineNumber").toString()); |
| 62 | emit sendLog(result.property("message").toString()); |
| 63 | emit sendLog("Stack:"); |
| 64 | emit sendLog(result.property("stack").toString()); |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | compiledScript = result; |
| 69 | |
| 70 | //Add a bunch of helper objects into javascript that the scripts |
| 71 | //can use to interact with the CAN buses |
| 72 | QJSValue hostObj = scriptEngine->newQObject(this); |
| 73 | scriptEngine->globalObject().setProperty("host", hostObj); |
| 74 | QJSValue canObj = scriptEngine->newQObject(canHelper); |
| 75 | scriptEngine->globalObject().setProperty("can", canObj); |
| 76 | QJSValue isoObj = scriptEngine->newQObject(isoHelper); |
| 77 | scriptEngine->globalObject().setProperty("isotp", isoObj); |
| 78 | QJSValue udsObj = scriptEngine->newQObject(udsHelper); |
| 79 | scriptEngine->globalObject().setProperty("uds", udsObj); |
| 80 | |
| 81 | //Find out which callbacks the script has created. |
| 82 | setupFunction = scriptEngine->globalObject().property("setup"); |
| 83 | canHelper->setRxCallback(scriptEngine->globalObject().property("gotCANFrame")); |
| 84 | isoHelper->setRxCallback(scriptEngine->globalObject().property("gotISOTPMessage")); |
| 85 | udsHelper->setRxCallback(scriptEngine->globalObject().property("gotUDSMessage")); |
| 86 | |
| 87 | tickFunction = scriptEngine->globalObject().property("tick"); |
| 88 | |
| 89 | if (setupFunction.isCallable()) |
| 90 | { |
| 91 | qDebug() << "setup exists"; |
| 92 | QJSValue res = setupFunction.call(); |
| 93 | if (res.isError()) |
| 94 | { |
| 95 | emit sendLog("Error in setup function on line " + res.property("lineNumber").toString()); |
| 96 | emit sendLog(res.property("message").toString()); |
| 97 | } |
| 98 | } |
| 99 | if (tickFunction.isCallable()) qDebug() << "tick exists"; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | void ScriptContainer::setScriptWindow(ScriptingWindow *win) |
| 104 | { |
no test coverage detected