udphandler.h
2.88 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 UDPHANDLER_H
#define UDPHANDLER_H
#include <QObject>
#include <QUdpSocket>
#include <QByteArray>
#include <QTimer>
#include "../../app-prime-modbus/include/all_share.h"
class UdpHandler : public QObject
{
Q_OBJECT
oven_control_t control;
oven_state_t state;
static UdpHandler *instance;
public:
static UdpHandler *getInstance() {
if (instance == 0)
{
UdpHandler *u = new UdpHandler;
if (u->init())
instance = u;
}
return instance;
}
bool init();
const oven_control_t &getControl() { return control; }
const oven_state_t &getData() { return state; }
bool burner1() { return (state.onoff_state1 & 0x0001) != 0; }
bool burner2() { return (state.onoff_state1 & 0x0002) != 0; }
bool burner3() { return (state.onoff_state1 & 0x0004) != 0; }
bool burnerFan1() { return (state.onoff_state1 & 0x0008) != 0; }
bool burnerFan2() { return (state.onoff_state1 & 0x0010) != 0; }
bool burnerFan3() { return (state.onoff_state1 & 0x0020) != 0; }
bool convection1() { return (state.onoff_state1 & 0x0040) != 0; }
bool convection2() { return (state.onoff_state1 & 0x0080) != 0; }
bool dv() { return (state.onoff_state2 & 0x0001) != 0; }
bool cfan() { return (state.onoff_state2 & 0x0002) != 0; }
bool wsv() { return (state.onoff_state2 & 0x0004) != 0; }
bool qnv() { return (state.onoff_state2 & 0x0008) != 0; }
bool ssv() { return (state.onoff_state2 & 0x0010) != 0; }
bool snv() { return (state.onoff_state2 & 0x0020) != 0; }
bool hl() { return (state.onoff_state2 & 0x0040) != 0; }
bool dp() { return (state.onoff_state2 & 0x0080) != 0; }
bool ssp() { return (state.onoff_state2 & 0x0100) != 0; }
bool unp() { return (state.onoff_state2 & 0x0200) != 0; }
bool hdm() { return (state.onoff_state2 & 0x0400) != 0; }
bool sgnv() { return (state.onoff_state2 & 0x0800) != 0; }
bool inv() { return (state.onoff_state2 & 0x1000) !=0; }
// 3: H, 2: Error, 1: C, 0: L
int waterLevel() {
return ((state.water_level & 0x08) >> 2)
| ((state.water_level & 0x10) >> 4);
}
int heater() { return (state.onoff_relay_load2 & 0x0F); }
signals:
void changed();
void timeout();
void recovered();
public slots:
void turnOn(int target);
void turnOff(int target);
void set(int target, int value);
void fillControl(oven_control_t &container);
void fillData(oven_state_t &container);
private:
explicit UdpHandler(QObject *parent = 0);
void processDatagram(QByteArray &datagram);
void processControl(oven_control_t *control);
void processState(oven_state_t *state);
QUdpSocket *sock;
QTimer emitTimeoutTimer;
bool emitted;
private slots:
void readPendingDatagrams();
void sendCommand(int cmd, int target, int value);
void emitTimeout();
};
#endif // UDPHANDLER_H