Index: /trunk/FACT++/src/smartfact.cc
===================================================================
--- /trunk/FACT++/src/smartfact.cc	(revision 13991)
+++ /trunk/FACT++/src/smartfact.cc	(revision 13992)
@@ -193,5 +193,5 @@
         const string arr = isday ?
             fSunSetDarkTime.MinutesTo(time)+"&darr;" :
-            fSunRiseDayTime.MinutesTo(time)+"&uarr;";
+            fSunRiseDarkTime.MinutesTo(time)+"&uarr;";
 
         description += " ["+arr+"]";
@@ -384,4 +384,6 @@
 
     bool fFtmControlFtuOk;
+
+    deque<float> fRateControlThreshold;
 
     uint64_t  fRateScanDataId;
@@ -414,4 +416,5 @@
     DimDescribedState fDimRateScan;
     DimDescribedState fDimChatServer;
+    DimDescribedState fDimSkypeClient;
 
     // -------------------------------------------------------------------
@@ -612,5 +615,5 @@
         ofstream(fPath+"/"+name+".data") << out.str();
 
-        WriteBinary(d, "magicweather-"+name+"-hist", fMagicWeatherHist[i], max-min, min);
+        WriteBinary(d, "hist-magicweather-"+name, fMagicWeatherHist[i], max-min, min);
     }
 
@@ -709,5 +712,5 @@
         const double scale = stat.max>0 ? pow(10, ceil(log10(stat.max))) : 0;
 
-        WriteBinary(d, "tng-dust-hist", fTngWeatherDustHist, scale);
+        WriteBinary(d, "hist-tng-dust", fTngWeatherDustHist, scale);
 
         ostringstream out;
@@ -776,5 +779,5 @@
             fDriveControlTrackingDevHist.pop_front();
 
-        WriteBinary(d, "control-deviation-hist", fDriveControlTrackingDevHist, 120);
+        WriteBinary(d, "hist-control-deviation", fDriveControlTrackingDevHist, 120);
 
         ostringstream out;
@@ -873,5 +876,5 @@
 
         // Write the 160 patch values to a file
-        WriteBinary(d, "feedback-deviation", dev, 1);
+        WriteBinary(d, "cam-feedback-deviation", dev, 1);
 
         const Statistics stat(dev, 3);
@@ -913,7 +916,7 @@
 
         if (fDimBiasControl.state()==BIAS::State::kVoltageOn)
-            WriteBinary(d, "biascontrol-voltage", val, 10, 65);
+            WriteBinary(d, "cam-biascontrol-voltage", val, 10, 65);
         else
-            WriteBinary(d, "biascontrol-voltage", val, 75);
+            WriteBinary(d, "cam-biascontrol-voltage", val, 75);
 
         ostringstream out;
@@ -989,5 +992,5 @@
 
         // Write the 160 patch values to a file
-        WriteBinary(d, "biascontrol-current", val, 100);
+        WriteBinary(d, "cam-biascontrol-current", val, 100);
 
         const Statistics stat(v, 0, 3);
@@ -1003,5 +1006,5 @@
 
         // write the history to a file
-        WriteBinary(d, "biascontrol-current-hist", fBiasControlCurrentHist, 100);
+        WriteBinary(d, "hist-biascontrol-current", fBiasControlCurrentHist, 100);
 
         const string col0 = cal ? HTML::kGreen : HTML::kWhite;
@@ -1148,9 +1151,9 @@
         // FIXME: Add statistics for all kind of rates
 
-        WriteBinary(d, "ftmcontrol-triggerrate-hist",
+        WriteBinary(d, "hist-ftmcontrol-triggerrate",
                     fFtmControlTriggerRateHist, 100);
-        WriteBinary(d, "ftmcontrol-boardrates",
+        WriteBinary(d, "cam-ftmcontrol-boardrates",
                     vector<float>(brates, brates+40), 10);
-        WriteBinary(d, "ftmcontrol-patchrates",
+        WriteBinary(d, "cam-ftmcontrol-patchrates",
                     vector<float>(prates, prates+160), 10);
 
@@ -1194,6 +1197,6 @@
         vector<uint16_t> vecb(dat.fMultiplicity, dat.fMultiplicity+40);
 
-        WriteBinary(d, "ftmcontrol-thresholds-patch", vecp, 1000);
-        WriteBinary(d, "ftmcontrol-thresholds-board", vecb, 1000);
+        WriteBinary(d, "cam-ftmcontrol-thresholds-patch", vecp, 1000);
+        WriteBinary(d, "cam-ftmcontrol-thresholds-board", vecb,  100);
 
         const Statistics statp(vecp);
@@ -1207,10 +1210,18 @@
         out << HTML::kWhite << '\t' << statb.min << '\n';
         out << HTML::kWhite << '\t' << statb.med << '\n';
-        //out << HTML::kWhite << '\t' << statb.avg << '\n';
         out << HTML::kWhite << '\t' << statb.max << '\n';
+        ofstream(fPath+"/thresholds-board.data") << out.str();
+
+        ostringstream out;
+        out << d.GetJavaDate() << '\n';
         out << HTML::kWhite << '\t' << statp.min << '\n';
         out << HTML::kWhite << '\t' << statp.med << '\n';
-        //out << HTML::kWhite << '\t' << statp.avg << '\n';
         out << HTML::kWhite << '\t' << statp.max << '\n';
+        ofstream(fPath+"/thresholds-patch.data") << out.str();
+
+        ostringstream out;
+        out << d.GetJavaDate() << '\n';
+        out << HTML::kWhite << '\t' << statb.med << '\n';
+        out << HTML::kWhite << '\t' << statp.med << '\n';
         ofstream(fPath+"/thresholds.data") << out.str();
 
@@ -1321,7 +1332,7 @@
         switch (fFadControlDrsStep)
         {
-        case 0:  WriteBinary(d, "fadcontrol-eventdata", max, 2,   -1); break;
-        case 1:  WriteBinary(d, "fadcontrol-eventdata", max, 2,    0); break;
-        default: WriteBinary(d, "fadcontrol-eventdata", max, 0.25, 0); break;
+        case 0:  WriteBinary(d, "cam-fadcontrol-eventdata", max, 2,   -1); break;
+        case 1:  WriteBinary(d, "cam-fadcontrol-eventdata", max, 2,    0); break;
+        default: WriteBinary(d, "cam-fadcontrol-eventdata", max, 0.25, 0); break;
         }
 
@@ -1384,5 +1395,5 @@
         ofstream(fPath+"/fsc.data") << out.str();
 
-        WriteBinary(d, "fsccontrol-temperature-hist",
+        WriteBinary(d, "hist-fsccontrol-temperature",
                     fFscControlTemperatureHist, 10);
 
@@ -1440,6 +1451,6 @@
         fRateScanBoard %= 40;
 
-        WriteBinary(d, "ratescan-hist",  fRateScanDataHist[0],                10, -2);
-        WriteBinary(d, "ratescan-board", fRateScanDataHist[fRateScanBoard+1], 10, -4);
+        WriteBinary(d, "hist-ratescan",      fRateScanDataHist[0],                10, -2);
+        WriteBinary(d, "cam-ratescan-board", fRateScanDataHist[fRateScanBoard+1], 10, -4);
 
         ostringstream out;
@@ -1459,4 +1470,20 @@
 
         ofstream(fPath+"/ratescan_board.data") << out.str();
+
+        return GetCurrentState();
+    }
+
+    int HandleRateControlThreshold(const EventImp &d)
+    {
+        if (!CheckDataSize(d, "RateControl:Threshold", 2))
+            return GetCurrentState();
+
+        const uint16_t th = d.Get<uint16_t>();
+
+        fRateControlThreshold.push_back(th);
+        if (fRateControlThreshold.size()>300)
+            fRateControlThreshold.pop_front();
+
+        WriteBinary(d, "hist-ratecontrol-threshold", fRateControlThreshold, 1000);
 
         return GetCurrentState();
@@ -1502,4 +1529,5 @@
         Out() << fDimDataLogger   << endl;
         Out() << fDimDriveControl << endl;
+        Out() << fDimTimeCheck    << endl;
         Out() << fDimFadControl   << endl;
         Out() << fDimFtmControl   << endl;
@@ -1512,4 +1540,5 @@
         Out() << fDimRateScan     << endl;
         Out() << fDimChatServer   << endl;
+        Out() << fDimSkypeClient  << endl;
 
         return GetCurrentState();
@@ -1962,4 +1991,5 @@
             out << GetStateHtml(fDimDataLogger,   1);
             out << GetStateHtml(fDimDriveControl, 2);
+            out << GetStateHtml(fDimTimeCheck,    1);
             out << GetStateHtml(fDimFadControl,   FAD::State::kConnected);
             out << GetStateHtml(fDimFtmControl,   FTM::State::kConnected);
@@ -1972,4 +2002,5 @@
             out << GetStateHtml(fDimRateScan,     4);
             out << GetStateHtml(fDimChatServer,   1);
+            out << GetStateHtml(fDimSkypeClient,  1);
 
             out << HTML::kGreen << '\t' << dt.str().substr(0, dt.str().length()-7) << '\n';
@@ -2087,4 +2118,7 @@
             (bind(&StateMachineSmartFACT::HandleFtmFtuList,          this, placeholders::_1));
 
+        Subscribe("RATE_CONTROL/THRESHOLD")
+            (bind(&StateMachineSmartFACT::HandleRateControlThreshold,this, placeholders::_1));
+
         Subscribe("RATE_SCAN/DATA")
             (bind(&StateMachineSmartFACT::HandleRateScanData,        this, placeholders::_1));
