Repository navigation
Expand file tree
/
Copy pathupscontroller.h
More file actions
98 lines (73 loc) · 1.82 KB
/
Copy pathupscontroller.h
File metadata and controls
98 lines (73 loc) · 1.82 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
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
#ifndef UPSCONTROLLER_H
#define UPSCONTROLLER_H
#include <QObject>
#include <QTimer>
#include <QFile>
#include <QTextStream>
#include <QSharedPointer>
#include <QFileSystemWatcher>
#include "nutclient.h"
//#include "serialmanager/serialportwatcher.h"
#include <qserialportinfo.h>
#include <QModbusRtuSerialMaster>
#include <QModbusDataUnit>
#define MAX_CONNECTIONS_TRIED 3
#define NEXT_CONNECTION_WAIT_SECS 1
#define MODBUS_SLAVE_ID 1
#define MB_SLAVE = 0x01
#define MB_PORT = "/dev/ttySAI"
#define MB_REG_ALARM 5
#define MB_REG_BATTERY 64
#define MB_REG_ONLINE 730
#define MB_ALARM_AC_BIT 14
class QModbusClient;
class QModbusReply;
enum UPS_CLIENT {
NONE = 0,
NUT,
MODBUS
};
enum UPS_STATE {
OUT = 0,
TEST_CONNECTION,
TEST_OK,
TEST_FAIL,
CHECK,
WAITING,
ERROR
};
class UpsController : public QObject
{
Q_OBJECT
public:
UpsController(QObject *parent = nullptr, const QString &upsDeviceName = "salicru");
signals:
void newUpsState(const QString& upsState);
public slots:
void sendUpsCommand();
void MODBUSresponse();
void MBtestRequest();
void MBtestResponse();
protected slots:
protected:
private:
nut::Client* m_nutClient;
QTimer m_pollSaiStatusTimer;
QString upsDeviceName;
UPS_STATE ups_state = UPS_STATE::OUT;
UPS_CLIENT available_clients[2] = { UPS_CLIENT::MODBUS, UPS_CLIENT::NUT };
size_t current_client = 0; // get first client
QModbusClient *modbusDevice = nullptr;
QString mb_portname = "";
QList<QSerialPortInfo> available_ports;
int current_port = 0;
int connection_tries = 0;
void connect_client();
void doWork();
bool getNextClient();
bool checkMODBUSPort();
void onlineRT3();
QString stateName(UPS_STATE state);
void changeState(UPS_STATE newstate);
};
#endif // UPSCONTROLLER_H