User | Revision | Line number | New contents of line |
Wimpie |
0:313c9e399e12
|
1
|
/*
|
Wimpie |
4:c16866ed9508
|
2
|
Copyright (c) 2010 Wimpie
|
Wimpie |
4:c16866ed9508
|
3
|
|
Wimpie |
4:c16866ed9508
|
4
|
Based on the VBus� Protocol Specification see http://goo.gl/HP6ZY
|
Wimpie |
4:c16866ed9508
|
5
|
and http://hobbyelektronik.org/w/index.php/VBus-Decoder
|
Wimpie |
4:c16866ed9508
|
6
|
|
Wimpie |
4:c16866ed9508
|
7
|
VBus� en Resol� are registrated trademarks see http://www.resol.de
|
Wimpie |
4:c16866ed9508
|
8
|
|
Wimpie |
4:c16866ed9508
|
9
|
Debugtrace.h -> http://mbed.org/users/snatch59/programs/DebugTrace/gpdz54
|
Wimpie |
0:313c9e399e12
|
10
|
|
Wimpie |
0:313c9e399e12
|
11
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Wimpie |
0:313c9e399e12
|
12
|
of this software and associated documentation files (the "Software"), to deal
|
Wimpie |
0:313c9e399e12
|
13
|
in the Software without restriction, including without limitation the rights
|
Wimpie |
0:313c9e399e12
|
14
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
Wimpie |
0:313c9e399e12
|
15
|
copies of the Software, and to permit persons to whom the Software is
|
Wimpie |
0:313c9e399e12
|
16
|
furnished to do so, subject to the following conditions:
|
Wimpie |
0:313c9e399e12
|
17
|
|
Wimpie |
0:313c9e399e12
|
18
|
The above copyright notice and this permission notice shall be included in
|
Wimpie |
0:313c9e399e12
|
19
|
all copies or substantial portions of the Software.
|
Wimpie |
0:313c9e399e12
|
20
|
|
Wimpie |
0:313c9e399e12
|
21
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
Wimpie |
0:313c9e399e12
|
22
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
Wimpie |
0:313c9e399e12
|
23
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
Wimpie |
0:313c9e399e12
|
24
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
Wimpie |
0:313c9e399e12
|
25
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
Wimpie |
0:313c9e399e12
|
26
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
Wimpie |
0:313c9e399e12
|
27
|
THE SOFTWARE.
|
Wimpie |
0:313c9e399e12
|
28
|
*/
|
Wimpie |
0:313c9e399e12
|
29
|
|
Wimpie |
0:313c9e399e12
|
30
|
#include "VBus.h"
|
Wimpie |
2:0306beaf5ff7
|
31
|
#define DEBUG 0
|
Wimpie |
0:313c9e399e12
|
32
|
|
Wimpie |
0:313c9e399e12
|
33
|
#if DEBUG
|
Wimpie |
4:c16866ed9508
|
34
|
#include "DebugTrace.h"
|
Wimpie |
4:c16866ed9508
|
35
|
DebugTrace pc_VBus(ON, TO_SERIAL);
|
Wimpie |
0:313c9e399e12
|
36
|
#endif
|
Wimpie |
0:313c9e399e12
|
37
|
|
Wimpie |
0:313c9e399e12
|
38
|
static uint8_t CalcCrc(const unsigned char *Buffer, int Offset, int Length);
|
Wimpie |
0:313c9e399e12
|
39
|
float CalcTemp(char Byte1, char Byte2);
|
Wimpie |
0:313c9e399e12
|
40
|
|
Wimpie |
0:313c9e399e12
|
41
|
VBus::VBus(PinName tx, PinName rx)
|
Wimpie |
0:313c9e399e12
|
42
|
: _Serial(tx, rx) {
|
Wimpie |
3:5ae3c983f241
|
43
|
_sdcard=false;
|
Wimpie |
3:5ae3c983f241
|
44
|
_all=false;
|
Wimpie |
3:5ae3c983f241
|
45
|
ClearMax();
|
Wimpie |
0:313c9e399e12
|
46
|
Init(0);
|
Wimpie |
0:313c9e399e12
|
47
|
}
|
Wimpie |
0:313c9e399e12
|
48
|
|
Wimpie |
0:313c9e399e12
|
49
|
void VBus::Init(int addr=0) {
|
Wimpie |
0:313c9e399e12
|
50
|
|
Wimpie |
0:313c9e399e12
|
51
|
_Serial.baud(9600);
|
Wimpie |
0:313c9e399e12
|
52
|
_Serial.format(8,Serial::None,1);
|
Wimpie |
0:313c9e399e12
|
53
|
m_timeout=2;
|
Wimpie |
0:313c9e399e12
|
54
|
|
Wimpie |
0:313c9e399e12
|
55
|
if (addr!=0)
|
Wimpie |
0:313c9e399e12
|
56
|
networkaddress=addr;
|
Wimpie |
0:313c9e399e12
|
57
|
else
|
Wimpie |
0:313c9e399e12
|
58
|
networkaddress=ResolAddress;
|
Wimpie |
0:313c9e399e12
|
59
|
|
Wimpie |
0:313c9e399e12
|
60
|
}
|
Wimpie |
0:313c9e399e12
|
61
|
|
Wimpie |
3:5ae3c983f241
|
62
|
void VBus::SDcardAvailable(bool status) {
|
Wimpie |
3:5ae3c983f241
|
63
|
_sdcard=status;
|
Wimpie |
3:5ae3c983f241
|
64
|
}
|
Wimpie |
3:5ae3c983f241
|
65
|
|
Wimpie |
0:313c9e399e12
|
66
|
void VBus::InjectSeptet(unsigned char *Buffer, int Offset, int Length) {
|
Wimpie |
0:313c9e399e12
|
67
|
for (unsigned int i = 0; i < Length; i++) {
|
Wimpie |
0:313c9e399e12
|
68
|
if (Septet & (1 << i)) {
|
Wimpie |
0:313c9e399e12
|
69
|
Buffer [Offset + i] |= 0x80;
|
Wimpie |
0:313c9e399e12
|
70
|
}
|
Wimpie |
0:313c9e399e12
|
71
|
}
|
Wimpie |
0:313c9e399e12
|
72
|
}
|
Wimpie |
0:313c9e399e12
|
73
|
|
Wimpie |
0:313c9e399e12
|
74
|
bool VBus::Read() {
|
Wimpie |
0:313c9e399e12
|
75
|
int F;
|
Wimpie |
0:313c9e399e12
|
76
|
char c;
|
Wimpie |
0:313c9e399e12
|
77
|
bool start,stop,quit;
|
Wimpie |
0:313c9e399e12
|
78
|
|
Wimpie |
0:313c9e399e12
|
79
|
start = true;
|
Wimpie |
0:313c9e399e12
|
80
|
stop = false;
|
Wimpie |
0:313c9e399e12
|
81
|
quit = false;
|
Wimpie |
0:313c9e399e12
|
82
|
Bufferlength=0;
|
Wimpie |
0:313c9e399e12
|
83
|
|
Wimpie |
0:313c9e399e12
|
84
|
m_timer.reset();
|
Wimpie |
0:313c9e399e12
|
85
|
m_timer.start();
|
Wimpie |
0:313c9e399e12
|
86
|
|
Wimpie |
0:313c9e399e12
|
87
|
while ((!stop) and (!quit)) {
|
Wimpie |
0:313c9e399e12
|
88
|
if (_Serial.readable()) {
|
Wimpie |
0:313c9e399e12
|
89
|
c=_Serial.getc();
|
Wimpie |
0:313c9e399e12
|
90
|
|
Wimpie |
0:313c9e399e12
|
91
|
if (c == Sync) {
|
Wimpie |
0:313c9e399e12
|
92
|
if (start) {
|
Wimpie |
0:313c9e399e12
|
93
|
start=false;
|
Wimpie |
0:313c9e399e12
|
94
|
Bufferlength=0;
|
Wimpie |
0:313c9e399e12
|
95
|
//#if DEBUG
|
Wimpie |
0:313c9e399e12
|
96
|
// pc_VBus.traceOut("\r\n");
|
Wimpie |
0:313c9e399e12
|
97
|
//#endif
|
Wimpie |
0:313c9e399e12
|
98
|
} else {
|
Wimpie |
0:313c9e399e12
|
99
|
if (Bufferlength<20) {
|
Wimpie |
0:313c9e399e12
|
100
|
m_timer.stop();
|
Wimpie |
0:313c9e399e12
|
101
|
m_timer.reset();
|
Wimpie |
0:313c9e399e12
|
102
|
m_timer.start();
|
Wimpie |
0:313c9e399e12
|
103
|
Bufferlength=0;
|
Wimpie |
0:313c9e399e12
|
104
|
} else
|
Wimpie |
0:313c9e399e12
|
105
|
stop=true;
|
Wimpie |
0:313c9e399e12
|
106
|
}
|
Wimpie |
0:313c9e399e12
|
107
|
}
|
Wimpie |
0:313c9e399e12
|
108
|
//#if DEBUG
|
Wimpie |
0:313c9e399e12
|
109
|
// pc_VBus.traceOut("%X ",c);
|
Wimpie |
0:313c9e399e12
|
110
|
//#endif
|
Wimpie |
0:313c9e399e12
|
111
|
if ((!start) and (!stop)) {
|
Wimpie |
0:313c9e399e12
|
112
|
Buffer[Bufferlength]=c;
|
Wimpie |
0:313c9e399e12
|
113
|
Bufferlength++;
|
Wimpie |
0:313c9e399e12
|
114
|
}
|
Wimpie |
0:313c9e399e12
|
115
|
}
|
Wimpie |
0:313c9e399e12
|
116
|
if ((m_timeout > 0) && (m_timer.read() > m_timeout )) {
|
Wimpie |
0:313c9e399e12
|
117
|
quit=true;
|
Wimpie |
0:313c9e399e12
|
118
|
//#if DEBUG
|
Wimpie |
0:313c9e399e12
|
119
|
// pc_VBus.traceOut("Timeout %i",m_timer.read());
|
Wimpie |
0:313c9e399e12
|
120
|
//#endif
|
Wimpie |
0:313c9e399e12
|
121
|
}
|
Wimpie |
0:313c9e399e12
|
122
|
}
|
Wimpie |
0:313c9e399e12
|
123
|
|
Wimpie |
0:313c9e399e12
|
124
|
m_timer.stop();
|
Wimpie |
0:313c9e399e12
|
125
|
|
Wimpie |
0:313c9e399e12
|
126
|
#if DEBUG
|
Wimpie |
0:313c9e399e12
|
127
|
|
Wimpie |
0:313c9e399e12
|
128
|
pc_VBus.traceOut("\r\nBuffer %i \r\n",Bufferlength);
|
Wimpie |
1:d37117275b0b
|
129
|
for (int i=0; i<Bufferlength;i++) {
|
Wimpie |
0:313c9e399e12
|
130
|
pc_VBus.traceOut("%X ",Buffer[i]);
|
Wimpie |
0:313c9e399e12
|
131
|
}
|
Wimpie |
0:313c9e399e12
|
132
|
pc_VBus.traceOut("\r\n");
|
Wimpie |
0:313c9e399e12
|
133
|
|
Wimpie |
0:313c9e399e12
|
134
|
#endif
|
Wimpie |
0:313c9e399e12
|
135
|
if (!quit) {
|
Wimpie |
0:313c9e399e12
|
136
|
Destination_address = Buffer[2] << 8;
|
Wimpie |
0:313c9e399e12
|
137
|
Destination_address |= Buffer[1];
|
Wimpie |
0:313c9e399e12
|
138
|
Source_address = Buffer[4] << 8;
|
Wimpie |
0:313c9e399e12
|
139
|
Source_address |= Buffer[3];
|
Wimpie |
0:313c9e399e12
|
140
|
ProtocolVersion = (Buffer[5]>>4) + (Buffer[5] &(1<<15));
|
Wimpie |
0:313c9e399e12
|
141
|
|
Wimpie |
0:313c9e399e12
|
142
|
Command = Buffer[7] << 8;
|
Wimpie |
0:313c9e399e12
|
143
|
Command |= Buffer[6];
|
Wimpie |
0:313c9e399e12
|
144
|
Framecnt = Buffer[8];
|
Wimpie |
0:313c9e399e12
|
145
|
Checksum = Buffer[9]; //TODO check if Checksum is OK
|
Wimpie |
0:313c9e399e12
|
146
|
#if DEBUG
|
Wimpie |
0:313c9e399e12
|
147
|
pc_VBus.traceOut("\r\nDestination %X",Destination_address);
|
Wimpie |
0:313c9e399e12
|
148
|
pc_VBus.traceOut("\r\nSource %X",Source_address);
|
Wimpie |
0:313c9e399e12
|
149
|
pc_VBus.traceOut("\r\nProtocol version %X",ProtocolVersion);
|
Wimpie |
0:313c9e399e12
|
150
|
pc_VBus.traceOut("\r\nCommand %X",Command);
|
Wimpie |
0:313c9e399e12
|
151
|
pc_VBus.traceOut("\r\nFramecnt %X", Framecnt);
|
Wimpie |
0:313c9e399e12
|
152
|
pc_VBus.traceOut("\r\nChecksum %X\r\n", Checksum);
|
Wimpie |
0:313c9e399e12
|
153
|
#endif
|
Wimpie |
0:313c9e399e12
|
154
|
// only analyse Commands 0x100 = Packet Contains data for slave
|
Wimpie |
0:313c9e399e12
|
155
|
// with correct length = 10 bytes for HEADER and 6 Bytes for each frame
|
Wimpie |
0:313c9e399e12
|
156
|
|
Wimpie |
0:313c9e399e12
|
157
|
if ((Command==0x0100) and (Bufferlength==10+Framecnt*6)) {
|
Wimpie |
0:313c9e399e12
|
158
|
|
Wimpie |
4:c16866ed9508
|
159
|
// Frame info for the Resol ConergyDT5
|
Wimpie |
0:313c9e399e12
|
160
|
// check VBusprotocol specification for other products
|
Wimpie |
4:c16866ed9508
|
161
|
|
Wimpie |
4:c16866ed9508
|
162
|
// This library is made for the ConergyDT5 (0x3271)
|
Wimpie |
4:c16866ed9508
|
163
|
|
Wimpie |
4:c16866ed9508
|
164
|
//Offset Size Mask Name Factor Unit
|
Wimpie |
4:c16866ed9508
|
165
|
//0 2 Temperature sensor 1 0.1 �C
|
Wimpie |
4:c16866ed9508
|
166
|
//2 2 Temperature sensor 2 0.1 �C
|
Wimpie |
4:c16866ed9508
|
167
|
//4 2 Temperature sensor 3 0.1 �C
|
Wimpie |
4:c16866ed9508
|
168
|
//6 2 Temperature sensor 4 0.1 �C
|
Wimpie |
4:c16866ed9508
|
169
|
//8 1 Pump speed pump 1 1
|
Wimpie |
4:c16866ed9508
|
170
|
//9 1 Pump speed pump 2 1
|
Wimpie |
4:c16866ed9508
|
171
|
//10 1 Relay mask 1
|
Wimpie |
4:c16866ed9508
|
172
|
//11 1 Error mask 1
|
Wimpie |
4:c16866ed9508
|
173
|
//12 2 System time 1
|
Wimpie |
4:c16866ed9508
|
174
|
//14 1 Scheme 1
|
Wimpie |
4:c16866ed9508
|
175
|
//15 1 1 Option PostPulse 1
|
Wimpie |
4:c16866ed9508
|
176
|
//15 1 2 Option thermostat 1
|
Wimpie |
4:c16866ed9508
|
177
|
//15 1 4 Option HQM 1
|
Wimpie |
4:c16866ed9508
|
178
|
//16 2 Operating hours relay 1 1
|
Wimpie |
4:c16866ed9508
|
179
|
//18 2 Operating hours relay 2 1
|
Wimpie |
4:c16866ed9508
|
180
|
//20 2 Heat quantity 1 Wh
|
Wimpie |
4:c16866ed9508
|
181
|
//22 2 Heat quantity 1000 Wh
|
Wimpie |
4:c16866ed9508
|
182
|
//24 2 Heat quantity 1000000 Wh
|
Wimpie |
4:c16866ed9508
|
183
|
//26 2 Version 0.01
|
Wimpie |
0:313c9e399e12
|
184
|
//
|
Wimpie |
0:313c9e399e12
|
185
|
// Each frame has 6 bytes
|
Wimpie |
0:313c9e399e12
|
186
|
// byte 1 to 4 are data bytes -> MSB of each bytes
|
Wimpie |
0:313c9e399e12
|
187
|
// byte 5 is a septet and contains MSB of bytes 1 to 4
|
Wimpie |
0:313c9e399e12
|
188
|
// byte 6 is a checksum
|
Wimpie |
0:313c9e399e12
|
189
|
//
|
Wimpie |
0:313c9e399e12
|
190
|
//******************* Frame 1 *******************
|
Wimpie |
0:313c9e399e12
|
191
|
|
Wimpie |
0:313c9e399e12
|
192
|
F=FOffset;
|
Wimpie |
0:313c9e399e12
|
193
|
|
Wimpie |
0:313c9e399e12
|
194
|
Septet=Buffer[F+FSeptet];
|
Wimpie |
0:313c9e399e12
|
195
|
InjectSeptet(Buffer,F,4);
|
Wimpie |
0:313c9e399e12
|
196
|
|
Wimpie |
0:313c9e399e12
|
197
|
// 'collector1' Temperatur Sensor 1, 15 bits, factor 0.1 in C
|
Wimpie |
0:313c9e399e12
|
198
|
Sensor1_temp =CalcTemp(Buffer[F+1], Buffer[F]);
|
Wimpie |
0:313c9e399e12
|
199
|
// 'store1' Temperature sensor 2, 15 bits, factor 0.1 in C
|
Wimpie |
0:313c9e399e12
|
200
|
Sensor2_temp =CalcTemp(Buffer[F+3], Buffer[F+2]);
|
Wimpie |
0:313c9e399e12
|
201
|
|
Wimpie |
0:313c9e399e12
|
202
|
//******************* Frame 2 *******************
|
Wimpie |
0:313c9e399e12
|
203
|
F=FOffset+FLength;
|
Wimpie |
0:313c9e399e12
|
204
|
|
Wimpie |
0:313c9e399e12
|
205
|
Septet=Buffer[F+FSeptet];
|
Wimpie |
0:313c9e399e12
|
206
|
InjectSeptet(Buffer,F,4);
|
Wimpie |
0:313c9e399e12
|
207
|
|
Wimpie |
0:313c9e399e12
|
208
|
Sensor3_temp =CalcTemp(Buffer[F+1], Buffer[F]);
|
Wimpie |
0:313c9e399e12
|
209
|
Sensor4_temp =CalcTemp(Buffer[F+3], Buffer[F+2]);
|
Wimpie |
0:313c9e399e12
|
210
|
|
Wimpie |
0:313c9e399e12
|
211
|
//******************* Frame 3 *******************
|
Wimpie |
0:313c9e399e12
|
212
|
F=FOffset+FLength*2;
|
Wimpie |
0:313c9e399e12
|
213
|
|
Wimpie |
0:313c9e399e12
|
214
|
Septet=Buffer[F+FSeptet];
|
Wimpie |
0:313c9e399e12
|
215
|
InjectSeptet(Buffer,F,4);
|
Wimpie |
0:313c9e399e12
|
216
|
|
Wimpie |
0:313c9e399e12
|
217
|
PumpSpeed1 = (Buffer[F] & 0X7F);
|
Wimpie |
0:313c9e399e12
|
218
|
PumpSpeed2 = (Buffer[F+1] & 0X7F);
|
Wimpie |
0:313c9e399e12
|
219
|
RelaisMask = Buffer[F+2];
|
Wimpie |
0:313c9e399e12
|
220
|
ErrorMask = Buffer[F+3];
|
Wimpie |
0:313c9e399e12
|
221
|
|
Wimpie |
0:313c9e399e12
|
222
|
//******************* Frame 4 *******************
|
Wimpie |
0:313c9e399e12
|
223
|
F=FOffset+FLength*3;
|
Wimpie |
0:313c9e399e12
|
224
|
|
Wimpie |
0:313c9e399e12
|
225
|
Septet=Buffer[F+FSeptet];
|
Wimpie |
0:313c9e399e12
|
226
|
InjectSeptet(Buffer,F,4);
|
Wimpie |
4:c16866ed9508
|
227
|
#if DEBUG
|
Wimpie |
4:c16866ed9508
|
228
|
pc_VBus.traceOut("\r\nFrame 4 %i %i %i %i ",Buffer[F],Buffer[F+1],Buffer[F+2],Buffer[F+3]);
|
Wimpie |
4:c16866ed9508
|
229
|
#endif
|
Wimpie |
0:313c9e399e12
|
230
|
SystemTime = Buffer[F+1] << 8 | Buffer[F];
|
Wimpie |
4:c16866ed9508
|
231
|
Scheme = Buffer[F+2];
|
Wimpie |
0:313c9e399e12
|
232
|
|
Wimpie |
0:313c9e399e12
|
233
|
OptionPostPulse = (Buffer[F+3] & 0x01);
|
Wimpie |
0:313c9e399e12
|
234
|
OptionThermostat = ((Buffer[F+3] & 0x02) >> 1);
|
Wimpie |
4:c16866ed9508
|
235
|
OptionHQM = ((Buffer[F+3] & 0x04) >> 2);
|
Wimpie |
0:313c9e399e12
|
236
|
|
Wimpie |
0:313c9e399e12
|
237
|
//******************* Frame 5 *******************
|
Wimpie |
0:313c9e399e12
|
238
|
F=FOffset+FLength*4;
|
Wimpie |
0:313c9e399e12
|
239
|
|
Wimpie |
0:313c9e399e12
|
240
|
Septet=Buffer[F+FSeptet];
|
Wimpie |
0:313c9e399e12
|
241
|
InjectSeptet(Buffer,F,4);
|
Wimpie |
4:c16866ed9508
|
242
|
#if DEBUG
|
Wimpie |
4:c16866ed9508
|
243
|
pc_VBus.traceOut("\r\nFrame 5 %i %i %i %i ",Buffer[F],Buffer[F+1],Buffer[F+2],Buffer[F+3]);
|
Wimpie |
4:c16866ed9508
|
244
|
#endif
|
Wimpie |
0:313c9e399e12
|
245
|
OperatingHoursRelais1=Buffer[F+1] << 8 | Buffer[F];
|
Wimpie |
0:313c9e399e12
|
246
|
OperatingHoursRelais2=Buffer[F+3] << 8| Buffer[F+2];
|
Wimpie |
0:313c9e399e12
|
247
|
|
Wimpie |
4:c16866ed9508
|
248
|
//******************* Frame 6 *******************
|
Wimpie |
4:c16866ed9508
|
249
|
F=FOffset+FLength*5;
|
Wimpie |
4:c16866ed9508
|
250
|
|
Wimpie |
4:c16866ed9508
|
251
|
Septet=Buffer[F+FSeptet];
|
Wimpie |
4:c16866ed9508
|
252
|
InjectSeptet(Buffer,F,4);
|
Wimpie |
4:c16866ed9508
|
253
|
#if DEBUG
|
Wimpie |
4:c16866ed9508
|
254
|
pc_VBus.traceOut("\r\nFrame 6 %i %i %i %i ",Buffer[F],Buffer[F+1],Buffer[F+2],Buffer[F+3]);
|
Wimpie |
4:c16866ed9508
|
255
|
#endif
|
Wimpie |
4:c16866ed9508
|
256
|
HeatQuantity=(Buffer[F+1] << 8 | Buffer[F])+(Buffer[F+3] << 8| Buffer[F+2])*1000;
|
Wimpie |
4:c16866ed9508
|
257
|
|
Wimpie |
4:c16866ed9508
|
258
|
//******************* Frame 7 *******************
|
Wimpie |
4:c16866ed9508
|
259
|
F=FOffset+FLength*6;
|
Wimpie |
4:c16866ed9508
|
260
|
|
Wimpie |
4:c16866ed9508
|
261
|
Septet=Buffer[F+FSeptet];
|
Wimpie |
4:c16866ed9508
|
262
|
InjectSeptet(Buffer,F,4);
|
Wimpie |
4:c16866ed9508
|
263
|
#if DEBUG
|
Wimpie |
4:c16866ed9508
|
264
|
pc_VBus.traceOut("\r\nFrame 7 %i %i %i %i ",Buffer[F],Buffer[F+1],Buffer[F+2],Buffer[F+3]);
|
Wimpie |
4:c16866ed9508
|
265
|
#endif
|
Wimpie |
4:c16866ed9508
|
266
|
HeatQuantity=HeatQuantity+(Buffer[F+1] << 8 | Buffer[F])*1000000;
|
Wimpie |
4:c16866ed9508
|
267
|
Version=Buffer[F+3] << 8| Buffer[F+2];
|
Wimpie |
4:c16866ed9508
|
268
|
|
Wimpie |
0:313c9e399e12
|
269
|
///******************* End of frames ****************
|
Wimpie |
0:313c9e399e12
|
270
|
|
Wimpie |
3:5ae3c983f241
|
271
|
if (Sensor1_temp>Sensor1_temp_max)
|
Wimpie |
3:5ae3c983f241
|
272
|
Sensor1_temp_max=Sensor1_temp;
|
Wimpie |
3:5ae3c983f241
|
273
|
if (Sensor2_temp>Sensor2_temp_max)
|
Wimpie |
3:5ae3c983f241
|
274
|
Sensor2_temp_max=Sensor2_temp;
|
Wimpie |
3:5ae3c983f241
|
275
|
if (Sensor3_temp>Sensor3_temp_max)
|
Wimpie |
3:5ae3c983f241
|
276
|
Sensor3_temp_max=Sensor3_temp;
|
Wimpie |
3:5ae3c983f241
|
277
|
if (Sensor4_temp>Sensor4_temp_max)
|
Wimpie |
3:5ae3c983f241
|
278
|
Sensor4_temp_max=Sensor4_temp;
|
Wimpie |
3:5ae3c983f241
|
279
|
|
Wimpie |
0:313c9e399e12
|
280
|
#if DEBUG
|
Wimpie |
0:313c9e399e12
|
281
|
|
Wimpie |
4:c16866ed9508
|
282
|
/* pc_VBus.traceOut("\r\nSensor 1 %f", Sensor1_temp);
|
Wimpie |
4:c16866ed9508
|
283
|
pc_VBus.traceOut("\r\nSensor 2 %f", Sensor2_temp);
|
Wimpie |
4:c16866ed9508
|
284
|
pc_VBus.traceOut("\r\nSensor 3 %f", Sensor3_temp);
|
Wimpie |
4:c16866ed9508
|
285
|
pc_VBus.traceOut("\r\nSensor 4 %f", Sensor4_temp);
|
Wimpie |
4:c16866ed9508
|
286
|
pc_VBus.traceOut("\r\nPumpSpeed1 %i", PumpSpeed1);
|
Wimpie |
4:c16866ed9508
|
287
|
pc_VBus.traceOut("\r\nPumpSpeed2 %i", PumpSpeed2);
|
Wimpie |
4:c16866ed9508
|
288
|
pc_VBus.traceOut("\r\nRelaismask %i", RelaisMask);
|
Wimpie |
4:c16866ed9508
|
289
|
pc_VBus.traceOut("\r\nErrorMask %i", ErrorMask);
|
Wimpie |
4:c16866ed9508
|
290
|
pc_VBus.traceOut("\r\nSystemTime %i", SystemTime);
|
Wimpie |
4:c16866ed9508
|
291
|
pc_VBus.traceOut("\r\nSystem %i", Scheme);
|
Wimpie |
4:c16866ed9508
|
292
|
pc_VBus.traceOut("\r\nOptionPostPulse %i", OptionPostPulse);
|
Wimpie |
4:c16866ed9508
|
293
|
pc_VBus.traceOut("\r\nOptionThermostat %i", OptionThermostat);
|
Wimpie |
4:c16866ed9508
|
294
|
pc_VBus.traceOut("\r\nOptionHQM %i", OptionHQM);
|
Wimpie |
4:c16866ed9508
|
295
|
pc_VBus.traceOut("\r\nOperatingHoursRelais1 %i", OperatingHoursRelais1);
|
Wimpie |
4:c16866ed9508
|
296
|
pc_VBus.traceOut("\r\nOperatingHoursRelais2 %i", OperatingHoursRelais2);*/
|
Wimpie |
4:c16866ed9508
|
297
|
pc_VBus.traceOut("\r\nHeatQuantity %i", HeatQuantity);
|
Wimpie |
0:313c9e399e12
|
298
|
|
Wimpie |
0:313c9e399e12
|
299
|
#endif
|
Wimpie |
0:313c9e399e12
|
300
|
}
|
Wimpie |
0:313c9e399e12
|
301
|
}
|
Wimpie |
0:313c9e399e12
|
302
|
|
Wimpie |
0:313c9e399e12
|
303
|
return !quit;
|
Wimpie |
0:313c9e399e12
|
304
|
}
|
Wimpie |
0:313c9e399e12
|
305
|
|
Wimpie |
3:5ae3c983f241
|
306
|
void VBus::SaveToSDcard(char* datetime, char* date,char* dayfn) {
|
Wimpie |
4:c16866ed9508
|
307
|
char fn[17];
|
Wimpie |
3:5ae3c983f241
|
308
|
strcpy(fn,"/sd/vb");
|
Wimpie |
3:5ae3c983f241
|
309
|
strcat(fn,dayfn);
|
Wimpie |
4:c16866ed9508
|
310
|
strcat(fn,".csv");
|
Wimpie |
3:5ae3c983f241
|
311
|
|
Wimpie |
3:5ae3c983f241
|
312
|
//****************
|
Wimpie |
4:c16866ed9508
|
313
|
// filename vbyymmdd.csv
|
Wimpie |
3:5ae3c983f241
|
314
|
//
|
Wimpie |
4:c16866ed9508
|
315
|
// detailed dayinfo, each 5 minutes
|
Wimpie |
3:5ae3c983f241
|
316
|
//
|
Wimpie |
4:c16866ed9508
|
317
|
// dd.mm.yy hh:mm:ss;v1;v2;v3;v4;v5;v6;v7;...
|
Wimpie |
3:5ae3c983f241
|
318
|
//
|
Wimpie |
3:5ae3c983f241
|
319
|
//****************
|
Wimpie |
4:c16866ed9508
|
320
|
#if DEBUG
|
Wimpie |
4:c16866ed9508
|
321
|
pc_VBus.traceOut("%s;%4.1f;%4.1f;%4.1f;%4.1f;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i%;%i;%i\r\n",datetime,
|
Wimpie |
4:c16866ed9508
|
322
|
Sensor1_temp, Sensor2_temp,Sensor3_temp, Sensor4_temp,
|
Wimpie |
4:c16866ed9508
|
323
|
PumpSpeed1,PumpSpeed2,
|
Wimpie |
4:c16866ed9508
|
324
|
RelaisMask,ErrorMask,SystemTime,Scheme,OptionPostPulse,
|
Wimpie |
4:c16866ed9508
|
325
|
OptionThermostat, OptionHQM, OperatingHoursRelais1,OperatingHoursRelais2,HeatQuantity,Version
|
Wimpie |
4:c16866ed9508
|
326
|
);
|
Wimpie |
4:c16866ed9508
|
327
|
#endif
|
Wimpie |
3:5ae3c983f241
|
328
|
|
Wimpie |
3:5ae3c983f241
|
329
|
if (_sdcard) {
|
Wimpie |
3:5ae3c983f241
|
330
|
FILE *fp = fopen(fn, "a");
|
Wimpie |
3:5ae3c983f241
|
331
|
if (fp) {
|
Wimpie |
4:c16866ed9508
|
332
|
fprintf(fp,"%s;%4.1f;%4.1f;%4.1f;%4.1f;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i;%i%;%i;%i\r\n",datetime,
|
Wimpie |
3:5ae3c983f241
|
333
|
Sensor1_temp, Sensor2_temp,Sensor3_temp, Sensor4_temp,
|
Wimpie |
3:5ae3c983f241
|
334
|
PumpSpeed1,PumpSpeed2,
|
Wimpie |
4:c16866ed9508
|
335
|
RelaisMask,ErrorMask,SystemTime,Scheme,OptionPostPulse,
|
Wimpie |
4:c16866ed9508
|
336
|
OptionThermostat, OptionHQM, OperatingHoursRelais1,OperatingHoursRelais2,HeatQuantity,Version
|
Wimpie |
4:c16866ed9508
|
337
|
);
|
Wimpie |
3:5ae3c983f241
|
338
|
fclose(fp);
|
Wimpie |
3:5ae3c983f241
|
339
|
}
|
Wimpie |
3:5ae3c983f241
|
340
|
}
|
Wimpie |
3:5ae3c983f241
|
341
|
}
|
Wimpie |
3:5ae3c983f241
|
342
|
|
Wimpie |
3:5ae3c983f241
|
343
|
void VBus::ClearMax() {
|
Wimpie |
3:5ae3c983f241
|
344
|
Sensor1_temp_max=0.0;
|
Wimpie |
3:5ae3c983f241
|
345
|
Sensor2_temp_max=0.0;
|
Wimpie |
3:5ae3c983f241
|
346
|
Sensor3_temp_max=0.0;
|
Wimpie |
3:5ae3c983f241
|
347
|
Sensor4_temp_max=0.0;
|
Wimpie |
3:5ae3c983f241
|
348
|
}
|
Wimpie |
3:5ae3c983f241
|
349
|
|
Wimpie |
0:313c9e399e12
|
350
|
void VBus::make_Header (unsigned int DAdr,unsigned int SAdr,unsigned char Ver,unsigned int Cmd,unsigned char AFrames) {
|
Wimpie |
0:313c9e399e12
|
351
|
unsigned char Buffer[10]={Sync,(uint8_t)DAdr,DAdr>>8,(uint8_t)SAdr,SAdr>>8,Ver,(uint8_t)Cmd,Cmd>>8,AFrames};
|
Wimpie |
0:313c9e399e12
|
352
|
Buffer[9]=CalcCrc(Buffer,1,8);
|
Wimpie |
0:313c9e399e12
|
353
|
for (unsigned bo=0;bo<=9;bo++) {
|
Wimpie |
0:313c9e399e12
|
354
|
_Serial.putc(Buffer[bo]);
|
Wimpie |
0:313c9e399e12
|
355
|
}
|
Wimpie |
0:313c9e399e12
|
356
|
}
|
Wimpie |
0:313c9e399e12
|
357
|
|
Wimpie |
0:313c9e399e12
|
358
|
static uint8_t CalcCrc(const unsigned char *Buffer, int Offset, int Length) {
|
Wimpie |
0:313c9e399e12
|
359
|
static uint8_t Crc= 0x7F;
|
Wimpie |
0:313c9e399e12
|
360
|
|
Wimpie |
0:313c9e399e12
|
361
|
for (unsigned int i = 0; i < Length; i++) {
|
Wimpie |
0:313c9e399e12
|
362
|
Crc = (Crc - Buffer [Offset + i]) & 0x7F;
|
Wimpie |
0:313c9e399e12
|
363
|
}
|
Wimpie |
0:313c9e399e12
|
364
|
return Crc;
|
Wimpie |
0:313c9e399e12
|
365
|
}
|
Wimpie |
0:313c9e399e12
|
366
|
|
Wimpie |
0:313c9e399e12
|
367
|
float CalcTemp(char Byte1, char Byte2) {
|
Wimpie |
0:313c9e399e12
|
368
|
int v;
|
Wimpie |
0:313c9e399e12
|
369
|
v = Byte1 << 8 | Byte2;
|
Wimpie |
3:5ae3c983f241
|
370
|
|
Wimpie |
4:c16866ed9508
|
371
|
if (Byte1 == 0xFF)
|
Wimpie |
3:5ae3c983f241
|
372
|
v = v - 0x10000;
|
Wimpie |
3:5ae3c983f241
|
373
|
|
Wimpie |
0:313c9e399e12
|
374
|
if (v==SENSORNOTCONNECTED)
|
Wimpie |
0:313c9e399e12
|
375
|
v=0;
|
Wimpie |
0:313c9e399e12
|
376
|
return (float)((float) v * 0.1);
|
Wimpie |
0:313c9e399e12
|
377
|
} |