-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpumpinterface.h
More file actions
58 lines (43 loc) · 1.51 KB
/
pumpinterface.h
File metadata and controls
58 lines (43 loc) · 1.51 KB
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
#ifndef PUMPINTERFACE_H
#define PUMPINTERFACE_H
#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QThread>
#include "pumpcommandworker.h"
#include "pumpcommands.h"
struct Pump {
int address;
QString name;
};
class PumpInterface : public QObject {
Q_OBJECT
public:
explicit PumpInterface(QObject *parent = nullptr);
~PumpInterface();
bool connectToPumps(const QString &portName, qint32 baudRate = QSerialPort::Baud19200); // initiates connections
void broadcastCommand(PumpCommand cmd, QString value = 0); // for basic stuff, like versions
void sendToPump(const QString &name, PumpCommand cmd, QString value = 0);
void shutdown();
void setPhases(const QVector<QVector<PumpPhase>> &phases);
bool startPumps(int phase);
bool stopPumps();
public slots:
void handlePumpCommand(const QString& name, PumpCommand cmd, QString value);
signals:
void sendCommandToQueue(const AddressedCommand& command);
void dataReceived(const QString &data);
void errorOccurred(const QString &message);
private slots:
void handleReadyRead();
void handleError(QSerialPort::SerialPortError error);
private:
QThread *workerThread;
PumpCommandWorker *commandWorker;
QByteArray serialBuffer;
QSerialPort *serial;
QVector<Pump> pumps;
QByteArray buildCommand(PumpCommand cmd, QString value);
bool sendCommand(int addr, PumpCommand cmd, QString value = 0);
};
#endif // PUMPINTERFACE_H