Diff: VBus.cpp
- Revision:
- 3:5ae3c983f241
- Parent:
- 2:0306beaf5ff7
- Child:
- 4:c16866ed9508
--- 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);