Committer:
Wimpie
Date:
Thu Dec 30 16:02:59 2010 +0000
Revision:
0:313c9e399e12
Child:
2:0306beaf5ff7

        

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 #define Sync 0xAA // Synchronisation bytes
Wimpie 0:313c9e399e12 24 #define FLength 6 // Framelength
Wimpie 0:313c9e399e12 25 #define FOffset 10 // Offset start of Frames
Wimpie 0:313c9e399e12 26 #define FSeptet 4 // Septet byte in Frame
Wimpie 0:313c9e399e12 27 #define ResolAddress 0x3271 // Address of the controller
Wimpie 0:313c9e399e12 28 #define SENSORNOTCONNECTED 8888
Wimpie 0:313c9e399e12 29
Wimpie 0:313c9e399e12 30 #include "mbed.h"
Wimpie 0:313c9e399e12 31
Wimpie 0:313c9e399e12 32 /** @defgroup API The VBus API */
Wimpie 0:313c9e399e12 33
Wimpie 0:313c9e399e12 34 /** VBus module
Wimpie 0:313c9e399e12 35 * @author Wim De Roeve
Wimpie 0:313c9e399e12 36 *
Wimpie 0:313c9e399e12 37 * Example:
Wimpie 0:313c9e399e12 38 * @code
Wimpie 0:313c9e399e12 39 * #include "mbed.h"
Wimpie 0:313c9e399e12 40 * #include "VBus.h"
Wimpie 0:313c9e399e12 41 *
Wimpie 0:313c9e399e12 42 * Serial pc(USBTX, USBRX);
Wimpie 0:313c9e399e12 43 * VBus ResolBS(p9, p10);
Wimpie 0:313c9e399e12 44 *
Wimpie 0:313c9e399e12 45 * int main() {
Wimpie 0:313c9e399e12 46 *
Wimpie 0:313c9e399e12 47 * While(1){
Wimpie 0:313c9e399e12 48 * if (ResolBS.Read()) {
Wimpie 0:313c9e399e12 49 *
Wimpie 0:313c9e399e12 50 * pc.printf("T collector = %.1f\r\n",ResolBS.Sensor1_temp);
Wimpie 0:313c9e399e12 51 * pc.printf("T store = %.1f\r\n",ResolBS.Sensor2_temp);
Wimpie 0:313c9e399e12 52 * pc.printf("T3 = %.1f\r\n",ResolBS.Sensor3_temp);
Wimpie 0:313c9e399e12 53 * pc.printf("T4 = %.1f\r\n",ResolBS.Sensor4_temp);
Wimpie 0:313c9e399e12 54 * }
Wimpie 0:313c9e399e12 55 * }
Wimpie 0:313c9e399e12 56 * }
Wimpie 0:313c9e399e12 57 * @endcode
Wimpie 0:313c9e399e12 58 */
Wimpie 0:313c9e399e12 59
Wimpie 0:313c9e399e12 60 class VBus {
Wimpie 0:313c9e399e12 61 public:
Wimpie 0:313c9e399e12 62 //! VBus constructor.
Wimpie 0:313c9e399e12 63 /**
Wimpie 0:313c9e399e12 64 * The VBus constructor is used to initialise the VBus object.
Wimpie 0:313c9e399e12 65 *
Wimpie 0:313c9e399e12 66 * @param tx The TX pin the VBus is connected to p9, p13, p28
Wimpie 0:313c9e399e12 67 * @param rx The RX pin the GPS is connected to p10, p14, p27.
Wimpie 0:313c9e399e12 68 */
Wimpie 0:313c9e399e12 69
Wimpie 0:313c9e399e12 70 VBus(PinName tx, PinName rx);
Wimpie 0:313c9e399e12 71
Wimpie 0:313c9e399e12 72 uint16_t networkaddress;
Wimpie 0:313c9e399e12 73 float Sensor1_temp;
Wimpie 0:313c9e399e12 74 float Sensor2_temp;
Wimpie 0:313c9e399e12 75 float Sensor3_temp;
Wimpie 0:313c9e399e12 76 float Sensor4_temp;
Wimpie 0:313c9e399e12 77
Wimpie 0:313c9e399e12 78 char PumpSpeed1; // in %
Wimpie 0:313c9e399e12 79 char PumpSpeed2; // in %
Wimpie 0:313c9e399e12 80 char RelaisMask;
Wimpie 0:313c9e399e12 81 char ErrorMask;
Wimpie 0:313c9e399e12 82 uint16_t SystemTime;
Wimpie 0:313c9e399e12 83 char System;
Wimpie 0:313c9e399e12 84 char OptionPostPulse;
Wimpie 0:313c9e399e12 85 char OptionThermostat;
Wimpie 0:313c9e399e12 86 char OptionWMZ;
Wimpie 0:313c9e399e12 87 uint16_t OperatingHoursRelais1;
Wimpie 0:313c9e399e12 88 uint16_t OperatingHoursRelais2;
Wimpie 0:313c9e399e12 89
Wimpie 0:313c9e399e12 90
Wimpie 0:313c9e399e12 91 void Init(int addr);
Wimpie 0:313c9e399e12 92 bool Read();
Wimpie 0:313c9e399e12 93
Wimpie 0:313c9e399e12 94 protected:
Wimpie 0:313c9e399e12 95 Serial _Serial;
Wimpie 0:313c9e399e12 96
Wimpie 0:313c9e399e12 97 private:
Wimpie 0:313c9e399e12 98
Wimpie 0:313c9e399e12 99 unsigned char Buffer[80];
Wimpie 0:313c9e399e12 100 volatile unsigned char Bufferlength;
Wimpie 0:313c9e399e12 101
Wimpie 0:313c9e399e12 102 unsigned int Destination_address ;
Wimpie 0:313c9e399e12 103 unsigned int Source_address;
Wimpie 0:313c9e399e12 104 unsigned char ProtocolVersion;
Wimpie 0:313c9e399e12 105 unsigned int Command ;
Wimpie 0:313c9e399e12 106 unsigned char Framecnt ;
Wimpie 0:313c9e399e12 107 unsigned char Septet ;
Wimpie 0:313c9e399e12 108 unsigned char Checksum ;
Wimpie 0:313c9e399e12 109
Wimpie 0:313c9e399e12 110 float m_timeout;
Wimpie 0:313c9e399e12 111 Timer m_timer;
Wimpie 0:313c9e399e12 112
Wimpie 0:313c9e399e12 113 void InjectSeptet(unsigned char *Buffer, int Offset, int Length);
Wimpie 0:313c9e399e12 114 void FrameOutput (void);
Wimpie 0:313c9e399e12 115 void make_Header (unsigned int DAdr,unsigned int SAdr,unsigned char Ver,unsigned int Cmd,unsigned char AFrames);
Wimpie 0:313c9e399e12 116
Wimpie 0:313c9e399e12 117 };
Wimpie 0:313c9e399e12 118
Wimpie 0:313c9e399e12 119
Wimpie 0:313c9e399e12 120
Wimpie 0:313c9e399e12 121
Wimpie 0:313c9e399e12 122