forked from collin80/SavvyCAN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialworker.h
93 lines (81 loc) · 2.13 KB
/
serialworker.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
#ifndef SERIALWORKER_H
#define SERIALWORKER_H
#include <QDateTime>
#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QTimer>
#include "can_structs.h"
#include "canframemodel.h"
namespace SERIALSTATE {
enum STATE //keep this enum synchronized with the Arduino firmware project
{
IDLE,
GET_COMMAND,
BUILD_CAN_FRAME,
TIME_SYNC,
GET_DIG_INPUTS,
GET_ANALOG_INPUTS,
SET_DIG_OUTPUTS,
SETUP_CANBUS,
GET_CANBUS_PARAMS,
GET_DEVICE_INFO,
SET_SINGLEWIRE_MODE
};
}
using namespace SERIALSTATE;
class SerialWorker : public QObject
{
Q_OBJECT
public:
SerialWorker(CANFrameModel *model, QObject *parent = 0);
~SerialWorker();
void readSettings();
void targetFrameID(int);
signals: //we emit signals
void error(const QString &);
void frameUpdateTick(int, int); //update interested parties about the # of frames that have come in
void connectionSuccess(int, int);
void connectionFailure();
void deviceInfo(int, int);
void gotTargettedFrame(int);
private slots: //we receive things in slots
void readSerialData();
void connectionTimeout();
void handleTick();
void handleReconnect();
public slots:
void setSerialPort(QSerialPortInfo*);
void closeSerialPort();
void sendFrame(const CANFrame *, int);
void sendFrameBatch(const QList<CANFrame> *);
void updateBaudRates(int, int);
void stopFrameCapture();
void startFrameCapture(); //only need to call this if previously stopped. Otherwise it's the default
private:
QString portName;
bool quit;
bool connected;
bool capturing;
bool doValidation;
bool gotValidated;
bool isAutoRestart;
QSerialPort *serial;
QSerialPortInfo *currentPort;
CANFrameModel *canModel;
QTimer *ticker;
QTime *elapsedTime;
int framesPerSec;
int gotFrames;
int targetID;
STATE rx_state;
int rx_step;
CANFrame *buildFrame;
int can0Baud, can1Baud;
bool can0Enabled, can1Enabled;
int deviceBuildNum;
int deviceSingleWireMode;
void procRXChar(unsigned char);
void sendCommValidation();
};
#endif // SERIALTHREAD_H