-
Notifications
You must be signed in to change notification settings - Fork 293
/
scriptcontainer.h
118 lines (101 loc) · 2.87 KB
/
scriptcontainer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef SCRIPTCONTAINER_H
#define SCRIPTCONTAINER_H
#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>
#include <QTimer>
#include <qlistwidget.h>
class ScriptingWindow;
class CANScriptHelper: public QObject
{
Q_OBJECT
public:
CANScriptHelper(QJSEngine *engine);
public slots:
void setFilter(QJSValue id, QJSValue mask, QJSValue bus);
void clearFilters();
void sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSValue data);
void setRxCallback(QJSValue cb);
private slots:
void gotTargettedFrame(const CANFrame &frame);
private:
QList<CANFilter> filters;
QJSValue gotFrameFunction;
QJSEngine *scriptEngine;
};
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
{
Q_OBJECT
public:
ScriptContainer();
virtual ~ScriptContainer();
void setScriptWindow(ScriptingWindow *win);
QString fileName;
QString filePath;
QString scriptText;
/*
Anything registered as a public slot on this class and that takes either no arguments
or only QJSValue arguments will be callable from scripts via host.XXX calls. So, have at it, champ.
*/
public slots:
void compileScript();
void setTickInterval(QJSValue interval);
void log(QJSValue logString);
void addParameter(QJSValue name);
void updateValuesTable(QTableWidget *widget);
void updateParameter(QString name, QString value);
signals:
void sendLog(QString text);
private slots:
void tick();
private:
QJSEngine *scriptEngine;
QJSValue compiledScript;
QJSValue setupFunction;
QJSValue tickFunction;
QTimer timer;
ScriptingWindow *window;
CANScriptHelper *canHelper;
ISOTPScriptHelper *isoHelper;
UDSScriptHelper *udsHelper;
QVector<QString> scriptParams;
};
#endif // SCRIPTCONTAINER_H