forked from m000c400/Mitsubishi-CN105-Protocol-Decode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEcodanCommandQueue.h
207 lines (168 loc) · 3.72 KB
/
EcodanCommandQueue.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <queue>
class DecodeFunctions
{
DecodeTemperature();
DecodeEnums();
}
struct Ecodanstatus
{
String value;
String lastvalue;
byte PacketType;
byte Command;
byte VarIndex;
byte VarType;
DecodeFunctions::DecodeFunction()
char VarShortName[5];
char VarLongName[40];
char noSpacesName[40];
//enumStr;
};
typedef struct _MessageStruct
{
uint8_t SyncByte;
uint8_t PacketType;
uint8_t Preamble[PREAMBLESIZE];
uint8_t PayloadSize;
uint8_t Payload[MAXDATABLOCKSIZE];
uint8_t Checksum;
} MessageStruct;
class ECODANENCODER
{
public:
Loop(); // AutoRun (timer)
// If(!connected) ConnectHeatpump();
// Encode();
// ECODANCOMMANDQUEUE::pushCommandMsg(MessageStruct *command);
CommandProcessor(topic);
// If(!connected) ConnectHeatpump();
// Encode();
// ECODANCOMMANDQUEUE::pushCommandMsg(MessageStruct *command);
private:
void ConnectHeatpump();
uint8_t HeatpumpConnected;
struct commandItem
{
byte VarIndex;
byte VarType;
EncodeFunctions::EncodeFunction()
byte SetType;
char VarLongName[35];
byte packetMask[packetBufferSize];
};
commandItem commandItems[] = { … constructor…};
Encode(MessageStruct * command);
// commandItems[MessageStruct.Command];
// EncodeFunction();
// ECODANCOMMANDQUEUE::pushCommandMsg(MessageStruct * command)
class EncodeFunctions()
EncodeTemperature
EncodeEnums(…)
}
class ECODANDECODER
{
public:
Loop(); // timer
// ECODANCOMMANDQUEUE::PopReceiveMsg(MessageStruct *command)
// Decode()
GetEcodanstatus();
private:
Ecodanstatus status[]; // { … constructor…};
}
class ECODANSERIALQUEUE
{
public:
ECODANSERIALQUEUE(Stream *HeatPumpStream);
void loop();
bool pushTxMsg(MessageStruct *msg);
bool popRxMsg(MessageStruct *msg);
private:
void Connect();
void Write_serial(); // looped
void Read_Serial(); // looped
Stream *DeviceStream;
bool sending;
queue<MessageStruct> TxQueue;
queue<MessageStruct> RxQueue;
}
ECODANSERIALQUEUE::ECODANSERIALQUEUE(void)
{
DeviceStream = HeatPumpStream;
DeviceStream.begin(SERIAL_BAUD, SERIAL_CONFIG, D3, D4);
pinMode(D3, INPUT_PULLUP);
}
void ECODANSERIALQUEUE::loop()
{
if (!Connected)
{
Connect();
}
else
{
Write_serial();
Read_Serial();
}
}
bool ECODANSERIALQUEUE::pushTxMsg(MessageStruct* msg)
{
}
bool ECODANSERIALQUEUE::popRxMsg(MessageStruct* msg)
{
}
bool ECODANSERIALQUEUE::Connect()
{
// Write_serial()
// if (data[1] == 0x7a){
// connectedToHP = true;
// }
}
{
bool foundStart = false;
int dataSum = 0;
byte checksum = 0;
byte dataLength = 0;
while (DeviceStream.available() > 0 && !foundStart)
{
data[0] = DeviceStream.read();
if (data[0] == HEADER[0])
{
foundStart = true;
}
}
if (!foundStart)
{
return RCVD_PKT_FAIL;
}
for (int i = 1; i < 5; i++) //read header
{
data[i] = DeviceStream.read();
}
dataLength = data[4] + 5;
for (int i = 5; i < dataLength; i++)
{
data[i] = DeviceStream.read(); // read the payload data
}
data[dataLength] = DeviceStream.read(); // read checksum byte
for (int i = 0; i < dataLength; i++) // sum up the header bytes...
{
dataSum += data[i];
}
checksum = (0xfc - dataSum) & 0xff; // calculate checksum
if (data[dataLength] == checksum)
{ // we have a correct packet
return RCVD_PKT_CONNECT_SUCCESS;
}
else
{
Telnet.println("CRC ERROR");
}
return RCVD_PKT_FAIL;
// push Rx Msg
sending = false;
}
// unsigned long sendCommandReadTime = 0; //set to millis value during send, allow to wait millis for answer
// Stream *DeviceStream;
// uint8_t Connected;
// bool sending;
// queue< MessageStruct > TxQueue;
// queue< MessageStruct > RxQueue;