Files at this revision

API Documentation at this revision

Comitter:
Wimpie
Date:
Sun Apr 17 17:25:56 2011 +0000
Parent:
2:0306beaf5ff7
Child:
4:c16866ed9508
Commit message:

Changed in this revision

VBus.cpp Show annotated file Show diff for this revision Revisions of this file
VBus.h Show annotated file Show diff for this revision Revisions of this file
--- a/VBus.cpp	Fri Dec 31 13:52:58 2010 +0000
+++ b/VBus.cpp	Sun Apr 17 17:25:56 2011 +0000
@@ -34,6 +34,9 @@
 
 VBus::VBus(PinName tx, PinName rx)
         : _Serial(tx, rx) {
+    _sdcard=false;
+    _all=false;
+    ClearMax();
     Init(0);
 }
 
@@ -50,6 +53,10 @@
 
 }
 
+void VBus::SDcardAvailable(bool status) {
+    _sdcard=status;
+}
+
 void  VBus::InjectSeptet(unsigned char *Buffer, int Offset, int Length) {
     for (unsigned int i = 0; i < Length; i++) {
         if (Septet & (1 << i)) {
@@ -207,6 +214,15 @@
 
             ///******************* End of frames ****************
 
+            if (Sensor1_temp>Sensor1_temp_max)
+                Sensor1_temp_max=Sensor1_temp;
+            if (Sensor2_temp>Sensor2_temp_max)
+                Sensor2_temp_max=Sensor2_temp;
+            if (Sensor3_temp>Sensor3_temp_max)
+                Sensor3_temp_max=Sensor3_temp;
+            if (Sensor4_temp>Sensor4_temp_max)
+                Sensor4_temp_max=Sensor4_temp;
+
 #if DEBUG
 
             pc_VBus.traceOut("\r\nSensor 1 %f", Sensor1_temp);
@@ -232,6 +248,54 @@
     return !quit;
 }
 
+void VBus::SaveToSDcard(char* datetime, char* date,char* dayfn) {
+#if DEBUG
+    pc_VBus.traceOut("save ULX code=%i\r\n",code);
+#endif
+
+    char fn[16];
+    strcpy(fn,"/sd/vb");
+    strcat(fn,dayfn);
+    strcat(fn,".js");
+
+    //****************
+    // vbyymmdd.js
+    //
+    // detailed dayinfo , each 5 minutes
+    //
+    // vb[i++]="dd.mm.yy hh:mm:ss|v1;v2;v3;v4;v5;v6;v7;...
+    //
+    //****************
+
+    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,
+            Sensor1_temp, Sensor2_temp,Sensor3_temp, Sensor4_temp,
+            PumpSpeed1,PumpSpeed2,
+            RelaisMask,ErrorMask,SystemTime,System,OptionPostPulse,
+            OptionThermostat, OptionWMZ, OperatingHoursRelais1,OperatingHoursRelais2,
+            34);
+
+    if (_sdcard) {
+        FILE *fp = fopen(fn, "a");
+        if (fp) {
+            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,
+                    Sensor1_temp, Sensor2_temp,Sensor3_temp, Sensor4_temp,
+                    PumpSpeed1,PumpSpeed2,
+                    RelaisMask,ErrorMask,SystemTime,System,OptionPostPulse,
+                    OptionThermostat, OptionWMZ, OperatingHoursRelais1,OperatingHoursRelais2,
+                    34);
+
+            fclose(fp);
+        }
+    }
+}
+
+void VBus::ClearMax() {
+    Sensor1_temp_max=0.0;
+    Sensor2_temp_max=0.0;
+    Sensor3_temp_max=0.0;
+    Sensor4_temp_max=0.0;
+}
+
 void VBus::make_Header (unsigned int DAdr,unsigned int SAdr,unsigned char Ver,unsigned int Cmd,unsigned char AFrames) {
     unsigned char Buffer[10]={Sync,(uint8_t)DAdr,DAdr>>8,(uint8_t)SAdr,SAdr>>8,Ver,(uint8_t)Cmd,Cmd>>8,AFrames};
     Buffer[9]=CalcCrc(Buffer,1,8);
@@ -254,10 +318,10 @@
 float CalcTemp(char Byte1, char Byte2) {
     int v;
     v = Byte1 << 8 | Byte2;
-    
+
     if (Byte1 == 0xFF)  // negatief value
-      v = v - 0x10000;  
-      
+        v = v - 0x10000;
+
     if (v==SENSORNOTCONNECTED)
         v=0;
     return (float)((float) v * 0.1);
--- a/VBus.h	Fri Dec 31 13:52:58 2010 +0000
+++ b/VBus.h	Sun Apr 17 17:25:56 2011 +0000
@@ -20,6 +20,9 @@
     THE SOFTWARE.
 */
 
+#ifndef VBUS_H
+#define VBUS_H
+
 #define Sync  0xAA  // Synchronisation bytes
 #define FLength 6  // Framelength
 #define FOffset 10 // Offset start of Frames
@@ -75,6 +78,11 @@
     float Sensor3_temp;
     float Sensor4_temp;
 
+    float Sensor1_temp_max;
+    float Sensor2_temp_max;
+    float Sensor3_temp_max;
+    float Sensor4_temp_max;
+
     char PumpSpeed1;  // in  %
     char PumpSpeed2;  //  in %
     char RelaisMask;
@@ -86,10 +94,13 @@
     char OptionWMZ;
     uint16_t OperatingHoursRelais1;
     uint16_t OperatingHoursRelais2;
-
-
+    uint16_t OperatingHoursRelais1Today;
+    
     void Init(int addr);
     bool Read();
+    void SaveToSDcard(char* datetime, char* date,char* dayfn);
+    void SDcardAvailable(bool status);
+    void ClearMax();
 
 protected:
     Serial _Serial;
@@ -110,11 +121,15 @@
     float m_timeout;
     Timer m_timer;
 
+    bool _sdcard;
+    bool _all;
+
     void InjectSeptet(unsigned char *Buffer, int Offset, int Length);
     void FrameOutput (void);
     void make_Header (unsigned int DAdr,unsigned int SAdr,unsigned char Ver,unsigned int Cmd,unsigned char AFrames);
 
 };
+#endif