Committer:
Wimpie
Date:
Wed May 04 20:15:25 2011 +0000
Revision:
4:c16866ed9508
Parent:
3:5ae3c983f241
added HeatQuantity

Who changed what in which revision?

UserRevisionLine numberNew 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 0:313c9e399e12 8
Wimpie 0:313c9e399e12 9 Permission is hereby granted, free of charge, to any person obtaining a copy
Wimpie 0:313c9e399e12 10 of this software and associated documentation files (the "Software"), to deal
Wimpie 0:313c9e399e12 11 in the Software without restriction, including without limitation the rights
Wimpie 0:313c9e399e12 12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Wimpie 0:313c9e399e12 13 copies of the Software, and to permit persons to whom the Software is
Wimpie 0:313c9e399e12 14 furnished to do so, subject to the following conditions:
Wimpie 0:313c9e399e12 15
Wimpie 0:313c9e399e12 16 The above copyright notice and this permission notice shall be included in
Wimpie 0:313c9e399e12 17 all copies or substantial portions of the Software.
Wimpie 0:313c9e399e12 18
Wimpie 0:313c9e399e12 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Wimpie 0:313c9e399e12 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Wimpie 0:313c9e399e12 21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Wimpie 0:313c9e399e12 22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Wimpie 0:313c9e399e12 23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Wimpie 0:313c9e399e12 24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Wimpie 0:313c9e399e12 25 THE SOFTWARE.
Wimpie 0:313c9e399e12 26 */
Wimpie 0:313c9e399e12 27
Wimpie 3:5ae3c983f241 28 #ifndef VBUS_H
Wimpie 3:5ae3c983f241 29 #define VBUS_H
Wimpie 3:5ae3c983f241 30
Wimpie 0:313c9e399e12 31 #define Sync 0xAA // Synchronisation bytes
Wimpie 0:313c9e399e12 32 #define FLength 6 // Framelength
Wimpie 0:313c9e399e12 33 #define FOffset 10 // Offset start of Frames
Wimpie 0:313c9e399e12 34 #define FSeptet 4 // Septet byte in Frame
Wimpie 4:c16866ed9508 35 #define ResolAddress 0x3271 // ConergyDT5 (0x3271) Address of the controller
Wimpie 0:313c9e399e12 36 #define SENSORNOTCONNECTED 8888
Wimpie 0:313c9e399e12 37
Wimpie 0:313c9e399e12 38 #include "mbed.h"
Wimpie 0:313c9e399e12 39
Wimpie 0:313c9e399e12 40 /** @defgroup API The VBus API */
Wimpie 0:313c9e399e12 41
Wimpie 0:313c9e399e12 42 /** VBus module
Wimpie 0:313c9e399e12 43 *
Wimpie 0:313c9e399e12 44 * Example:
Wimpie 0:313c9e399e12 45 * @code
Wimpie 0:313c9e399e12 46 * #include "mbed.h"
Wimpie 0:313c9e399e12 47 * #include "VBus.h"
Wimpie 0:313c9e399e12 48 *
Wimpie 0:313c9e399e12 49 * Serial pc(USBTX, USBRX);
Wimpie 4:c16866ed9508 50 * VBus ResolBS(NC, p10);
Wimpie 0:313c9e399e12 51 *
Wimpie 0:313c9e399e12 52 * int main() {
Wimpie 0:313c9e399e12 53 *
Wimpie 2:0306beaf5ff7 54 * while(1){
Wimpie 0:313c9e399e12 55 * if (ResolBS.Read()) {
Wimpie 0:313c9e399e12 56 *
Wimpie 0:313c9e399e12 57 * pc.printf("T collector = %.1f\r\n",ResolBS.Sensor1_temp);
Wimpie 0:313c9e399e12 58 * pc.printf("T store = %.1f\r\n",ResolBS.Sensor2_temp);
Wimpie 0:313c9e399e12 59 * pc.printf("T3 = %.1f\r\n",ResolBS.Sensor3_temp);
Wimpie 0:313c9e399e12 60 * pc.printf("T4 = %.1f\r\n",ResolBS.Sensor4_temp);
Wimpie 0:313c9e399e12 61 * }
Wimpie 0:313c9e399e12 62 * }
Wimpie 0:313c9e399e12 63 * }
Wimpie 0:313c9e399e12 64 * @endcode
Wimpie 0:313c9e399e12 65 */
Wimpie 0:313c9e399e12 66
Wimpie 0:313c9e399e12 67 class VBus {
Wimpie 0:313c9e399e12 68 public:
Wimpie 0:313c9e399e12 69 //! VBus constructor.
Wimpie 0:313c9e399e12 70 /**
Wimpie 0:313c9e399e12 71 * The VBus constructor is used to initialise the VBus object.
Wimpie 0:313c9e399e12 72 *
Wimpie 4:c16866ed9508 73 * @param tx The TX pin is NOT connected
Wimpie 4:c16866ed9508 74 * @param rx The RX pin is connected to p10 or p14 or p27.
Wimpie 0:313c9e399e12 75 */
Wimpie 0:313c9e399e12 76
Wimpie 0:313c9e399e12 77 VBus(PinName tx, PinName rx);
Wimpie 4:c16866ed9508 78 /**
Wimpie 4:c16866ed9508 79 * The VBus destructor
Wimpie 4:c16866ed9508 80 */
Wimpie 4:c16866ed9508 81 // virtual ~VBus();
Wimpie 0:313c9e399e12 82
Wimpie 4:c16866ed9508 83
Wimpie 4:c16866ed9508 84 /**
Wimpie 4:c16866ed9508 85 * Read
Wimpie 4:c16866ed9508 86 * Reads all the device parameters (Sensors, Pumpspeed, RelaisMask)
Wimpie 4:c16866ed9508 87 **/
Wimpie 4:c16866ed9508 88 bool Read();
Wimpie 4:c16866ed9508 89 /**
Wimpie 4:c16866ed9508 90 * SaveToSDcard
Wimpie 4:c16866ed9508 91 * Saves the device parameters to a textfile /sd/vb20110101.txt
Wimpie 4:c16866ed9508 92 **/
Wimpie 4:c16866ed9508 93 void SaveToSDcard(char* datetime, char* date,char* dayfn);
Wimpie 4:c16866ed9508 94 void SDcardAvailable(bool status);
Wimpie 4:c16866ed9508 95 /**
Wimpie 4:c16866ed9508 96 * ClearMax
Wimpie 4:c16866ed9508 97 * Clears the maximum values
Wimpie 4:c16866ed9508 98 **/
Wimpie 4:c16866ed9508 99 void ClearMax();
Wimpie 4:c16866ed9508 100
Wimpie 4:c16866ed9508 101 uint16_t networkaddress;
Wimpie 0:313c9e399e12 102 float Sensor1_temp;
Wimpie 0:313c9e399e12 103 float Sensor2_temp;
Wimpie 0:313c9e399e12 104 float Sensor3_temp;
Wimpie 0:313c9e399e12 105 float Sensor4_temp;
Wimpie 0:313c9e399e12 106
Wimpie 3:5ae3c983f241 107 float Sensor1_temp_max;
Wimpie 3:5ae3c983f241 108 float Sensor2_temp_max;
Wimpie 3:5ae3c983f241 109 float Sensor3_temp_max;
Wimpie 3:5ae3c983f241 110 float Sensor4_temp_max;
Wimpie 3:5ae3c983f241 111
Wimpie 0:313c9e399e12 112 char PumpSpeed1; // in %
Wimpie 0:313c9e399e12 113 char PumpSpeed2; // in %
Wimpie 0:313c9e399e12 114 char RelaisMask;
Wimpie 0:313c9e399e12 115 char ErrorMask;
Wimpie 0:313c9e399e12 116 uint16_t SystemTime;
Wimpie 4:c16866ed9508 117 char Scheme;
Wimpie 0:313c9e399e12 118 char OptionPostPulse;
Wimpie 0:313c9e399e12 119 char OptionThermostat;
Wimpie 4:c16866ed9508 120 char OptionHQM;
Wimpie 0:313c9e399e12 121 uint16_t OperatingHoursRelais1;
Wimpie 0:313c9e399e12 122 uint16_t OperatingHoursRelais2;
Wimpie 4:c16866ed9508 123 uint32_t HeatQuantity;
Wimpie 4:c16866ed9508 124 uint16_t Version;
Wimpie 3:5ae3c983f241 125 uint16_t OperatingHoursRelais1Today;
Wimpie 0:313c9e399e12 126
Wimpie 0:313c9e399e12 127 protected:
Wimpie 0:313c9e399e12 128 Serial _Serial;
Wimpie 0:313c9e399e12 129
Wimpie 0:313c9e399e12 130 private:
Wimpie 0:313c9e399e12 131
Wimpie 0:313c9e399e12 132 unsigned char Buffer[80];
Wimpie 0:313c9e399e12 133 volatile unsigned char Bufferlength;
Wimpie 0:313c9e399e12 134
Wimpie 0:313c9e399e12 135 unsigned int Destination_address ;
Wimpie 0:313c9e399e12 136 unsigned int Source_address;
Wimpie 0:313c9e399e12 137 unsigned char ProtocolVersion;
Wimpie 0:313c9e399e12 138 unsigned int Command ;
Wimpie 0:313c9e399e12 139 unsigned char Framecnt ;
Wimpie 0:313c9e399e12 140 unsigned char Septet ;
Wimpie 0:313c9e399e12 141 unsigned char Checksum ;
Wimpie 0:313c9e399e12 142
Wimpie 0:313c9e399e12 143 float m_timeout;
Wimpie 0:313c9e399e12 144 Timer m_timer;
Wimpie 0:313c9e399e12 145
Wimpie 3:5ae3c983f241 146 bool _sdcard;
Wimpie 3:5ae3c983f241 147 bool _all;
Wimpie 3:5ae3c983f241 148
Wimpie 4:c16866ed9508 149 void Init(int addr);
Wimpie 0:313c9e399e12 150 void InjectSeptet(unsigned char *Buffer, int Offset, int Length);
Wimpie 0:313c9e399e12 151 void FrameOutput (void);
Wimpie 0:313c9e399e12 152 void make_Header (unsigned int DAdr,unsigned int SAdr,unsigned char Ver,unsigned int Cmd,unsigned char AFrames);
Wimpie 0:313c9e399e12 153
Wimpie 0:313c9e399e12 154 };
Wimpie 3:5ae3c983f241 155 #endif
Wimpie 0:313c9e399e12 156
Wimpie 0:313c9e399e12 157
Wimpie 0:313c9e399e12 158
Wimpie 0:313c9e399e12 159
Wimpie 0:313c9e399e12 160