Index: trunk/FACT++/src/smartfact.cc
===================================================================
--- trunk/FACT++/src/smartfact.cc	(revision 13643)
+++ trunk/FACT++/src/smartfact.cc	(revision 13675)
@@ -19,8 +19,4 @@
 #include "HeadersFTM.h"
 
-namespace ba    = boost::asio;
-namespace bs    = boost::system;
-namespace dummy = ba::placeholders;
-
 using namespace std;
 
@@ -60,6 +56,6 @@
     Time     fMcpConfigurationRunStart;
 
-    enum weather_t { kWeatherBegin=0, kTemp = kWeatherBegin, kDew, kHum, kPress, kWind, kGusts, kDir, kWeatherEnd = kDir };
-    deque<float> fMagicWeatherHist[kWeatherEnd+1];
+    enum weather_t { kWeatherBegin=0, kTemp = kWeatherBegin, kDew, kHum, kPress, kWind, kGusts, kDir, kWeatherEnd = kDir+1 };
+    deque<float> fMagicWeatherHist[kWeatherEnd];
 
     vector<float> fFeedbackCalibration;
@@ -240,4 +236,6 @@
 
         ofstream fout("www/"+fname+".bin");
+        fout << offset << '\n';
+        fout << offset+scale << '\n';
         fout.write(ptr, val.size()*sizeof(uint8_t));
     }
@@ -255,5 +253,9 @@
         template<class T>
             Statistics(const T &t, size_t offset_min=0, size_t offset_max=0)
-        {
+            : min(0), max(0), med(0), avg(0)
+        {
+            if (t.size()==0)
+                return;
+
             T copy(t);
             sort(copy.begin(), copy.end());
@@ -294,5 +296,5 @@
         ostringstream out;
         out << setprecision(3);
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
 
         out << "#ffffff\t" << fMagicWeatherHist[i].back() << '\n';
@@ -312,5 +314,5 @@
 
         // Store a history of the last 300 entries
-        for (int i=kWeatherBegin; i<=kWeatherEnd; i++)
+        for (int i=kWeatherBegin; i<kWeatherEnd; i++)
         {
             fMagicWeatherHist[i].push_back(d.ptr<float>(2)[i]);
@@ -330,5 +332,5 @@
 
         ostringstream out;
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
         for (int i=0; i<6; i++)
             out << "#ffffff\t" << fMagicWeatherHist[i].back() << '\n';
@@ -367,5 +369,5 @@
 
         ostringstream out;
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
 
         out << setprecision(5);
@@ -373,6 +375,5 @@
         out << az << '\n';
 
-        ofstream fout("www/drive-pointing.txt");
-        fout << out.str();
+        ofstream("www/drive-pointing.txt") << out.str();
     }
 
@@ -411,5 +412,5 @@
 
         ostringstream out;
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
 
         out << "#ffffff\t" << fDriveControlSourceName << '\n';
@@ -421,6 +422,5 @@
         out << "#ffffff\t" << wang << '\n';
 
-        ofstream fout("www/drive.txt");
-        fout << out.str();
+        ofstream("www/drive.txt") << out.str();
     }
 
@@ -462,5 +462,5 @@
         ostringstream out;
         out << setprecision(3);
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
         out << kHtmlWhite << '\t' << stat.min << '\n';
         out << kHtmlWhite << '\t' << stat.med << '\n';
@@ -513,5 +513,5 @@
         ostringstream out;
         out << setprecision(3);
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
         out << kHtmlWhite << '\t' << stat.min << '\n';
         out << kHtmlWhite << '\t' << stat.med << '\n';
@@ -524,4 +524,8 @@
     {
         if (!CheckDataSize(d, "FtmControl:TriggerRates", 24+160+640+8))
+            return;
+
+        // New run started
+        if (d.get<float>(20)<0)
             return;
 
@@ -547,5 +551,5 @@
         ostringstream out;
         out << setprecision(3);
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
         out << "#ffffff\t" << fFtmControlTriggerRateCam << '\n';
 
@@ -556,5 +560,5 @@
 
         out.str("");
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
         out << kHtmlWhite << '\t' << bstat.min << '\n';
         out << kHtmlWhite << '\t' << bstat.med << '\n';
@@ -564,5 +568,5 @@
 
         out.str("");
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
         out << kHtmlWhite << '\t' << pstat.min << '\n';
         out << kHtmlWhite << '\t' << pstat.med << '\n';
@@ -570,6 +574,4 @@
         out << kHtmlWhite << '\t' << pstat.max << '\n';
         ofstream("www/patchrates.txt") << out.str();
-
-
     }
 
@@ -584,5 +586,5 @@
         //const float *pos = d.ptr<float>(1440*sizeof(float)*3);
 
-        vector<float> max(320, -2000);
+        vector<float> max(320, -2);
         for (int i=0; i<1440; i++)
         {
@@ -591,13 +593,14 @@
 
             const int idx = (fPixelMap.hw(i).hw()/9)*2+fPixelMap.hw(i).group();
-            if (dat[i]>max[idx])
-                max[idx]=dat[i];
+            const double v = dat[i]/1000;
+            if (v>max[idx])
+                max[idx]=v;
         }
 
         switch (d.qos)
         {
-        case 0:  WriteBinary("fadcontrol-eventdata", max, 2000, -1000); break;
-        case 1:  WriteBinary("fadcontrol-eventdata", max, 2000,     0); break;
-        default: WriteBinary("fadcontrol-eventdata", max,  250,     0); break;
+        case 0:  WriteBinary("fadcontrol-eventdata", max, 2,   -1); break;
+        case 1:  WriteBinary("fadcontrol-eventdata", max, 2,    0); break;
+        default: WriteBinary("fadcontrol-eventdata", max, 0.25, 0); break;
         }
     }
@@ -646,5 +649,5 @@
         ostringstream out;
         out << setprecision(3);
-        out << uint64_t(d.time.UnixTime()*1000) << '\n';
+        out << d.time.JavaDate() << '\n';
         out << "#ffffff\t" << min      << '\n';
         out << "#ffffff\t" << avg      << '\n';
@@ -815,5 +818,5 @@
 
         ostringstream out;
-        out << uint64_t(nearbyint(now.UnixTime()*1000)) << '\n';
+        out << now.JavaDate() << '\n';
         out << setprecision(3);
 
@@ -897,5 +900,5 @@
 
         // --------------- MagicWeather -------------
-        if (fDimMagicWeather.state()==3)
+        if (fDimMagicWeather.state()==3 && fMagicWeatherHist[kWeatherBegin].size()>0)
         {
             /*
@@ -938,7 +941,8 @@
 
         // --------------- BiasControl -------------
-        if (fDimBiasControl.state()==5 || // Ramping
-            fDimBiasControl.state()==7 || // On
-            fDimBiasControl.state()==9)   // Off
+        if (fDimBiasControl.state()==BIAS::kRamping     ||
+            fDimBiasControl.state()==BIAS::kOverCurrent ||
+            fDimBiasControl.state()==BIAS::kVoltageOn   ||
+            fDimBiasControl.state()==BIAS::kVoltageOff)
         {
             string col = fBiasControlVoltageMed>3?kHtmlGreen:kHtmlWhite;
@@ -950,4 +954,6 @@
             if (fFeedbackCalibration.size()==0)
                 col = kHtmlBlue;
+            if (fDimBiasControl.state()==BIAS::kOverCurrent)
+                col = kHtmlRed;
 
             if (fDimFeedback.state()==13)
@@ -956,5 +962,4 @@
                 out << "***\t";
                 out << "***\t";
-                out << "---\n";
             }
             else
@@ -963,6 +968,6 @@
                 out << fBiasControlCurrentMed << '\t';
                 out << fBiasControlCurrentMax << '\t';
-                out << fBiasControlVoltageMed << '\n';
             }
+            out << fBiasControlVoltageMed << '\n';
         }
         else
@@ -977,5 +982,5 @@
 
         out.str("");
-        out << uint64_t(nearbyint(now.UnixTime()*1000)) << '\n';
+        out << now.JavaDate() << '\n';
 
         if (fDim.state()==0)
