forked from OpenPanzerProject/OP-Config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.h
74 lines (57 loc) · 2.7 KB
/
console.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
#ifndef CONSOLE_H
#define CONSOLE_H
#include <QtCore/QtGlobal>
#include <QtSerialPort/QSerialPort> // Serial port
#include <QDebug.h>
#include <arduino_compat.h> // Gives us Arduino-like data type names
#define MAX_CONSOLE_ERRORCOUNT 10 // How many communication errors do we permit before simply disconnecting
struct ConsolePortSettings {
QString name;
QString stringBaudRate;
//qint32 baudRate;
QSerialPort::BaudRate baudRate;
QSerialPort::DataBits dataBits;
QString stringDataBits;
QSerialPort::Parity parity;
QString stringParity;
QSerialPort::StopBits stopBits;
QString stringStopBits;
QSerialPort::FlowControl flowControl;
QString stringFlowControl;
};
class Console : public QObject // By inheriting from QObject, the class can use signal and slot mechanism
{
Q_OBJECT // need this macro for QObject to work
public:
explicit Console(); // Constructor
// Functions
void begin(); // Init
void updatePortSettings(QString comName); // For now just updates the COM port to use (other settings are hard-coded)
void openSerial(void); // Open serial port and attempt to connect to device
void closeSerial(void); // Close serial port and tell device Goodbye
boolean isConnected(void); // returns connection status
void toggleDTR(void);
// Vars
ConsolePortSettings currentPortSettings;
signals:
void ConnectionChanged(boolean connected); // Signal for anytime we connect or disconnect
void AnyData(void); // This doesn't necessarily mean a sentence has arrived, but we use this to restart the watchdog
void CommError(QString, QSerialPort::SerialPortError); // Signal for errors that need to be displayer to the user
private:
// Vars
// ---------------------------------------------------------------------------------------------------->>
QSerialPort *serial;
int NumErrors;
boolean Connected;
QByteArray responseData;
// Reading data
// ---------------------------------------------------------------------------------------------------->>
void ClearResponseData(void);
private slots:
// Serial Slots
// ---------------------------------------------------------------------------------------------------->>
void readData(void);
void handleError(QSerialPort::SerialPortError error);
void ProcessConnectionChange(boolean connected);
};
#endif // CONSOLE_H