Committer:
Wimpie
Date:
Sun Apr 17 17:25:56 2011 +0000
Revision:
3:5ae3c983f241
Parent:
2:0306beaf5ff7
Child:
4:c16866ed9508

        

Who changed what in which revision?

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