Index: trunk/FACT++/src/smartfact.cc
===================================================================
--- trunk/FACT++/src/smartfact.cc	(revision 13936)
+++ trunk/FACT++/src/smartfact.cc	(revision 13944)
@@ -40,10 +40,28 @@
 
 // ------------------------------------------------------------------------
-
-const static string kHtmlWhite  = "#ffffff";
-const static string kHtmlYellow = "#fffff0";
-const static string kHtmlRed    = "#fff8f0";
-const static string kHtmlGreen  = "#f0fff0";
-const static string kHtmlBlue   = "#f0f0ff";
+/*
+template<class T>
+    class buffer : public deque<T>
+    {
+        int32_t max_size;
+
+    public:
+        buffer(int32_t max=-1) : max_size(max) { }
+        const T &operator=(const T &t) const { push_back(t); if (max_size>0 && deque<T>::size()>max_size) deque<T>::pop_front(); }
+        operator T() const { return deque<T>::size()>0 ? deque<T>::back() : T(); }
+        bool valid() const { return deque<T>::size()>0; }
+    };
+*/
+
+// ------------------------------------------------------------------------
+
+namespace HTML
+{
+    const static string kWhite  = "#ffffff";
+    const static string kYellow = "#fffff0";
+    const static string kRed    = "#fff8f0";
+    const static string kGreen  = "#f0fff0";
+    const static string kBlue   = "#f0f0ff";
+};
 
 // ========================================================================
@@ -190,9 +208,9 @@
         switch (state)
         {
-        case 0: case 1:  color = kHtmlGreen;   break;
-        case 2: case 3:  color = kHtmlYellow;  break;
-        case 4:          color = kHtmlRed;     break;
-        case 5: case 6:  color = kHtmlYellow;  break;
-        case 7: case 8:  color = kHtmlGreen;   break;
+        case 0: case 1:  color = HTML::kGreen;   break;
+        case 2: case 3:  color = HTML::kYellow;  break;
+        case 4:          color = HTML::kRed;     break;
+        case 5: case 6:  color = HTML::kYellow;  break;
+        case 7: case 8:  color = HTML::kGreen;   break;
         }
 #endif
@@ -260,7 +278,7 @@
 
         if (!visible || disk<25)
-            color = kHtmlGreen;
+            color = HTML::kGreen;
         else
-            color = disk>75 ? kHtmlRed : kHtmlYellow;
+            color = disk>75 ? HTML::kRed : HTML::kYellow;
 
         string arr;
@@ -523,5 +541,5 @@
         out << setprecision(3);
         out << d.GetJavaDate() << '\n';
-        out << "#ffffff\t";
+        out << HTML::kWhite << '\t';
 
         for (auto it=fControlMessageHist.begin(); it!=fControlMessageHist.end(); it++)
@@ -535,4 +553,7 @@
     int HandleDimControlMessage(const EventImp &d)
     {
+        if (d.GetSize()==0)
+            return GetCurrentState();
+
         if (d.GetQoS()==90)
             HandleControlMessageImp(d);
@@ -543,8 +564,8 @@
     void HandleControlStateChange(const EventImp &d)
     {
-        DimControl ctrl;
-        ctrl.Handler(d);
-
-        if (d.GetQoS()==-2 && ctrl.scriptdepth==0)
+        if (d.GetSize()==0)
+            return;
+
+        if (d.GetQoS()==-2 && fDimControl.scriptdepth==0)
             fControlMessageHist.clear();
 
@@ -553,10 +574,10 @@
 
 #if BOOST_VERSION < 104600
-        const string file = boost::filesystem::path(ctrl.file).filename();
+        const string file = boost::filesystem::path(fDimControl.file).filename();
 #else
-        const string file = boost::filesystem::path(ctrl.file).filename().string();
+        const string file = boost::filesystem::path(fDimControl.file).filename().string();
 #endif
 
-        HandleControlMessageImp(Event(d, ctrl.shortmsg.data(), ctrl.shortmsg.length()+1));
+        HandleControlMessageImp(Event(d, fDimControl.shortmsg.data(), fDimControl.shortmsg.length()+1));
         if (!file.empty())
             HandleControlMessageImp(Event(d, file.data(), file.length()+1));
@@ -594,8 +615,8 @@
         out << d.GetJavaDate() << '\n';
 
-        out << "#ffffff\t" << fMagicWeatherHist[i].back() << '\n';
-        out << "#ffffff\t" << stat.min << '\n';
-        out << "#ffffff\t" << stat.avg << '\n';
-        out << "#ffffff\t" << stat.max << '\n';
+        out << HTML::kWhite << '\t' << fMagicWeatherHist[i].back() << '\n';
+        out << HTML::kWhite << '\t' << stat.min << '\n';
+        out << HTML::kWhite << '\t' << stat.avg << '\n';
+        out << HTML::kWhite << '\t' << stat.max << '\n';
 
         ofstream(fPath+"/"+name+".data") << out.str();
@@ -636,10 +657,10 @@
         out << astro.color << '\t' << astro.description << '\n';
         out << setprecision(2);
-        out << (astro.isday?kHtmlWhite:moon.color) << '\t' << moon.description << '\n';
+        out << (astro.isday?HTML::kWhite:moon.color) << '\t' << moon.description << '\n';
         out << setprecision(3);
         for (int i=0; i<6; i++)
-            out << "#ffffff\t" << fMagicWeatherHist[i].back() << '\n';
-        out << "#ffffff\t" << dir[idx] << '\n';
-        out << "#ffffff\t";
+            out << HTML::kWhite << '\t' << fMagicWeatherHist[i].back() << '\n';
+        out << HTML::kWhite << '\t' << dir[idx] << '\n';
+        out << HTML::kWhite << '\t';
         if (fTngWeatherDustHist.size()>0)
             out << fTngWeatherDustHist.back() << '\t' << fTngWeatherDustTime.GetAsStr("%H:%M") << '\n';
@@ -651,18 +672,18 @@
         out.str("");
         out << astro.time.JavaDate() << '\n';
-        out << kHtmlWhite << '\t' << astro.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t' << astro.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t' << astro.fSunRiseCivil.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t' << astro.fSunRiseDayTime.GetAsStr("%H:%M") << '\n';
-
-        out << kHtmlWhite << '\t' << astro.fSunSetDayTime.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t' << astro.fSunSetCivil.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t' << astro.fSunSetAstronomical.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t' << astro.fSunSetDarkTime.GetAsStr("%H:%M") << '\n';
-
-        out << kHtmlWhite << '\t' << moon.fMoonRise.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t' << moon.fMoonTransit.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t' << moon.fMoonSet.GetAsStr("%H:%M") << '\n';
-        out << kHtmlWhite << '\t';
+        out << HTML::kWhite << '\t' << astro.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << astro.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << astro.fSunRiseCivil.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << astro.fSunRiseDayTime.GetAsStr("%H:%M") << '\n';
+
+        out << HTML::kWhite << '\t' << astro.fSunSetDayTime.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << astro.fSunSetCivil.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << astro.fSunSetAstronomical.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << astro.fSunSetDarkTime.GetAsStr("%H:%M") << '\n';
+
+        out << HTML::kWhite << '\t' << moon.fMoonRise.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << moon.fMoonTransit.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t' << moon.fMoonSet.GetAsStr("%H:%M") << '\n';
+        out << HTML::kWhite << '\t';
 
         ofstream(fPath+"/astro.data") << out.str();
@@ -765,12 +786,12 @@
         out << d.GetJavaDate() << '\n';
 
-        out << kHtmlWhite << '\t' << fDriveControlSourceName << '\n';
+        out << HTML::kWhite << '\t' << fDriveControlSourceName << '\n';
         out << setprecision(5);
-        out << kHtmlWhite << '\t' << Ra  << '\n';
-        out << kHtmlWhite << '\t' << Dec << '\n';
+        out << HTML::kWhite << '\t' << Ra  << '\n';
+        out << HTML::kWhite << '\t' << Dec << '\n';
         out << setprecision(3);
-        out << kHtmlWhite << '\t' << Zd  << '\n';
-        out << kHtmlWhite << '\t' << Az  << '\n';
-        out << kHtmlWhite << '\t' << dev << '\n';
+        out << HTML::kWhite << '\t' << Zd  << '\n';
+        out << HTML::kWhite << '\t' << Az  << '\n';
+        out << HTML::kWhite << '\t' << dev << '\n';
 
         fDriveControlMoonDist = -1;
@@ -781,9 +802,9 @@
             const double angle = moon.Angle(Ra, Dec);
 
-            string col = kHtmlGreen;
+            string col = HTML::kGreen;
             if (angle<20 || angle>140)
-                col = kHtmlYellow;
+                col = HTML::kYellow;
             if (angle<10 || angle>150)
-                col = kHtmlRed;
+                col = HTML::kRed;
             out << col << '\t' << setprecision(3) << angle << '\n';
 
@@ -791,5 +812,5 @@
         }
         else
-            out << kHtmlWhite << "\t&mdash; \n";
+            out << HTML::kWhite << "\t&mdash; \n";
 
         ofstream(fPath+"/tracking.data") << out.str();
@@ -815,11 +836,11 @@
         out << d.GetJavaDate() << '\n';
 
-        out << "#ffffff\t" << fDriveControlSourceName << '\n';
+        out << HTML::kWhite << '\t' << fDriveControlSourceName << '\n';
         out << setprecision(5);
-        out << "#ffffff\t" << ra  << '\n';
-        out << "#ffffff\t" << dec << '\n';
+        out << HTML::kWhite << '\t' << ra  << '\n';
+        out << HTML::kWhite << '\t' << dec << '\n';
         out << setprecision(3);
-        out << "#ffffff\t" << woff << '\n';
-        out << "#ffffff\t" << wang << '\n';
+        out << HTML::kWhite << '\t' << woff << '\n';
+        out << HTML::kWhite << '\t' << wang << '\n';
 
         ofstream(fPath+"/source.data") << out.str();
@@ -863,11 +884,11 @@
         ostringstream out;
         out << d.GetJavaDate() << '\n';
-        out << kHtmlWhite << '\t' << fFeedbackUserOffset << '\n';
+        out << HTML::kWhite << '\t' << fFeedbackUserOffset << '\n';
         out << setprecision(3);
-        out << kHtmlWhite << '\t' << fFeedbackTempOffset << '\n';
-        out << kHtmlWhite << '\t' << stat.min << '\n';
-        out << kHtmlWhite << '\t' << stat.med << '\n';
-        out << kHtmlWhite << '\t' << stat.avg << '\n';
-        out << kHtmlWhite << '\t' << stat.max << '\n';
+        out << HTML::kWhite << '\t' << fFeedbackTempOffset << '\n';
+        out << HTML::kWhite << '\t' << stat.min << '\n';
+        out << HTML::kWhite << '\t' << stat.med << '\n';
+        out << HTML::kWhite << '\t' << stat.avg << '\n';
+        out << HTML::kWhite << '\t' << stat.max << '\n';
         ofstream(fPath+"/feedback.data") << out.str();
 
@@ -904,8 +925,8 @@
         out << setprecision(3);
         out << d.GetJavaDate() << '\n';
-        out << kHtmlWhite << '\t' << stat.min << '\n';
-        out << kHtmlWhite << '\t' << stat.med << '\n';
-        out << kHtmlWhite << '\t' << stat.avg << '\n';
-        out << kHtmlWhite << '\t' << stat.max << '\n';
+        out << HTML::kWhite << '\t' << stat.min << '\n';
+        out << HTML::kWhite << '\t' << stat.med << '\n';
+        out << HTML::kWhite << '\t' << stat.avg << '\n';
+        out << HTML::kWhite << '\t' << stat.max << '\n';
         ofstream(fPath+"/voltage.data") << out.str();
 
@@ -954,5 +975,5 @@
             }
 
-        // Divide by number of summed channels, concert to mW
+        // Divide by number of summed channels, convert to mW
         power_apd /= 317e-3; // [mW]
 
@@ -989,5 +1010,5 @@
         WriteBinary(d, "biascontrol-current-hist", fBiasControlCurrentHist, 100);
 
-        const string col0 = cal ? kHtmlGreen : kHtmlWhite;
+        const string col0 = cal ? HTML::kGreen : HTML::kWhite;
 
         string col1 = col0;
@@ -1024,5 +1045,5 @@
         out << col3 << '\t' << stat.avg << '\n';
         out << col4 << '\t' << stat.max << '\n';
-        out << kHtmlWhite << '\t' << power_tot << "W [" << power_apd << "mW]\n";
+        out << HTML::kWhite << '\t' << power_tot << "W [" << power_apd << "mW]\n";
         ofstream(fPath+"/current.data") << out.str();
 
@@ -1093,8 +1114,8 @@
             switch (c[i])
             {
-            case '.': col[i]=kHtmlWhite;  break;
-            case '-': col[i]=kHtmlRed;    break;
-            case '+': col[i]=kHtmlYellow; break;
-            case '*': col[i]=kHtmlGreen;  break;
+            case '.': col[i]=HTML::kWhite;  break;
+            case '-': col[i]=HTML::kRed;    break;
+            case '+': col[i]=HTML::kYellow; break;
+            case '*': col[i]=HTML::kGreen;  break;
             }
 
@@ -1142,5 +1163,5 @@
         out << setprecision(3);
         out << d.GetJavaDate() << '\n';
-        out << "#ffffff\t" << fFtmControlTriggerRateCam << '\n';
+        out << HTML::kWhite << '\t' << fFtmControlTriggerRateCam << '\n';
 
         ofstream(fPath+"/trigger.data") << out.str();
@@ -1151,16 +1172,16 @@
         out.str("");
         out << d.GetJavaDate() << '\n';
-        out << kHtmlWhite << '\t' << bstat.min << '\n';
-        out << kHtmlWhite << '\t' << bstat.med << '\n';
-        out << kHtmlWhite << '\t' << bstat.avg << '\n';
-        out << kHtmlWhite << '\t' << bstat.max << '\n';
+        out << HTML::kWhite << '\t' << bstat.min << '\n';
+        out << HTML::kWhite << '\t' << bstat.med << '\n';
+        out << HTML::kWhite << '\t' << bstat.avg << '\n';
+        out << HTML::kWhite << '\t' << bstat.max << '\n';
         ofstream(fPath+"/boardrates.data") << out.str();
 
         out.str("");
         out << d.GetJavaDate() << '\n';
-        out << kHtmlWhite << '\t' << pstat.min << '\n';
-        out << kHtmlWhite << '\t' << pstat.med << '\n';
-        out << kHtmlWhite << '\t' << pstat.avg << '\n';
-        out << kHtmlWhite << '\t' << pstat.max << '\n';
+        out << HTML::kWhite << '\t' << pstat.min << '\n';
+        out << HTML::kWhite << '\t' << pstat.med << '\n';
+        out << HTML::kWhite << '\t' << pstat.avg << '\n';
+        out << HTML::kWhite << '\t' << pstat.max << '\n';
         ofstream(fPath+"/patchrates.data") << out.str();
 
@@ -1189,18 +1210,18 @@
         ostringstream out;
         out << d.GetJavaDate() << '\n';
-        out << kHtmlWhite << '\t' << statb.min << '\n';
-        out << kHtmlWhite << '\t' << statb.med << '\n';
-        //out << kHtmlWhite << '\t' << statb.avg << '\n';
-        out << kHtmlWhite << '\t' << statb.max << '\n';
-        out << kHtmlWhite << '\t' << statp.min << '\n';
-        out << kHtmlWhite << '\t' << statp.med << '\n';
-        //out << kHtmlWhite << '\t' << statp.avg << '\n';
-        out << kHtmlWhite << '\t' << statp.max << '\n';
+        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';
+        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.data") << out.str();
 
         out.str("");
         out << d.GetJavaDate() << '\n';
-        out << kHtmlWhite << '\t' << dat.fTriggerInterval << '\n';
-        out << kHtmlWhite << '\t';
+        out << HTML::kWhite << '\t' << dat.fTriggerInterval << '\n';
+        out << HTML::kWhite << '\t';
         if (dat.HasPedestal())
             out << dat.fTriggerSeqPed;
@@ -1219,10 +1240,10 @@
         out << '\n';
 
-        out << kHtmlWhite << '\t' << (dat.HasTrigger()?"on":"off") << " / " << (dat.HasExt1()?"on":"off") << " / " << (dat.HasExt2()?"on":"off") << '\n';
-        out << kHtmlWhite << '\t' << (dat.HasVeto()?"on":"off") << " / " << (dat.HasClockConditioner()?"time cal":"marker") << '\n';
-        out << kHtmlWhite << '\t' << dat.fMultiplicityPhysics << " / " << dat.fMultiplicityCalib << '\n';
-        out << kHtmlWhite << '\t' << dat.fWindowPhysics << '\t' << dat.fWindowCalib << '\n';
-        out << kHtmlWhite << '\t' << dat.fDelayTrigger << '\t' << dat.fDelayTimeMarker << '\n';
-        out << kHtmlWhite << '\t' << dat.fDeadTime << '\n';
+        out << HTML::kWhite << '\t' << (dat.HasTrigger()?"on":"off") << " / " << (dat.HasExt1()?"on":"off") << " / " << (dat.HasExt2()?"on":"off") << '\n';
+        out << HTML::kWhite << '\t' << (dat.HasVeto()?"on":"off") << " / " << (dat.HasClockConditioner()?"time cal":"marker") << '\n';
+        out << HTML::kWhite << '\t' << dat.fMultiplicityPhysics << " / " << dat.fMultiplicityCalib << '\n';
+        out << HTML::kWhite << '\t' << dat.fWindowPhysics << '\t' << dat.fWindowCalib << '\n';
+        out << HTML::kWhite << '\t' << dat.fDelayTrigger << '\t' << dat.fDelayTimeMarker << '\n';
+        out << HTML::kWhite << '\t' << dat.fDeadTime << '\n';
 
         int64_t vp = dat.fPrescaling[0];
@@ -1232,7 +1253,7 @@
 
         if (vp<0)
-            out << kHtmlYellow << "\tdifferent\n";
+            out << HTML::kYellow << "\tdifferent\n";
         else
-            out << kHtmlWhite  << "\t" << 0.5*vp << "\n";
+            out << HTML::kWhite  << '\t' << 0.5*vp << "\n";
 
         ofstream(fPath+"/ftm.data") << out.str();
@@ -1257,5 +1278,5 @@
         for (int i=0; i<4; i++)
         {
-            out << kHtmlWhite << '\t';
+            out << HTML::kWhite << '\t';
             for (int j=0; j<10; j++)
                 if (sdata.IsActive(i*10+j))
@@ -1358,11 +1379,11 @@
         out << setprecision(3);
         out << d.GetJavaDate() << '\n';
-        out << "#ffffff\t" << fFscControlHumidityAvg << '\n';
-        out << "#ffffff\t" << min      << '\n';
-        out << "#ffffff\t" << avg      << '\n';
-        out << "#ffffff\t" << max      << '\n';
-        out << "#ffffff\t" << stat.min << '\n';
-        out << "#ffffff\t" << stat.avg << '\n';
-        out << "#ffffff\t" << stat.max << '\n';
+        out << HTML::kWhite << '\t' << fFscControlHumidityAvg << '\n';
+        out << HTML::kWhite << '\t' << min      << '\n';
+        out << HTML::kWhite << '\t' << avg      << '\n';
+        out << HTML::kWhite << '\t' << max      << '\n';
+        out << HTML::kWhite << '\t' << stat.min << '\n';
+        out << HTML::kWhite << '\t' << stat.avg << '\n';
+        out << HTML::kWhite << '\t' << stat.max << '\n';
 
         ofstream(fPath+"/fsc.data") << out.str();
@@ -1430,8 +1451,8 @@
         out << setprecision(3);
         out << d.GetJavaDate() << '\n';
-        out << "#ffffff\t" << fFtmBoardThresholdMed << '\n';
-        out << "#ffffff\t" << fFtmPatchThresholdMed << '\n';
-        out << "#ffffff\t" << pow(10, fRateScanDataHist[0].back()) << '\n';
-        out << "#ffffff\t" << max << '\n';
+        out << HTML::kWhite << '\t' << fFtmBoardThresholdMed << '\n';
+        out << HTML::kWhite << '\t' << fFtmPatchThresholdMed << '\n';
+        out << HTML::kWhite << '\t' << pow(10, fRateScanDataHist[0].back()) << '\n';
+        out << HTML::kWhite << '\t' << max << '\n';
 
         ofstream(fPath+"/ratescan.data") << out.str();
@@ -1439,6 +1460,6 @@
         out.str("");
         out << d.GetJavaDate() << '\n';
-        out << "#ffffff\t" << int(fRateScanBoard) << '\n';
-        out << "#ffffff\t" << pow(10, fRateScanDataHist[fRateScanBoard+1].back()) << '\n';
+        out << HTML::kWhite << '\t' << int(fRateScanBoard) << '\n';
+        out << HTML::kWhite << '\t' << pow(10, fRateScanDataHist[fRateScanBoard+1].back()) << '\n';
 
         ofstream(fPath+"/ratescan_board.data") << out.str();
@@ -1452,11 +1473,12 @@
     {
         ostringstream out;
-        out << d.GetJavaDate() << '\t' << fHasError << '\n';
+        out << d.GetJavaDate() << '\n';
+
         switch (d.GetQoS())
         {
-        case -3: out << kHtmlWhite << "\tNot running\n";               break;
-        case -2: out << kHtmlBlue  << "\tLoading\n";                   break;
-        case -1: out << kHtmlBlue  << "\tStarted\n";                   break;
-        default: out << kHtmlGreen << "\tRunning [" << d.GetQoS() << "]\n"; break;
+        case -3: out << HTML::kWhite << "\tNot running\n"; break;
+        case -2: out << HTML::kBlue  << "\tLoading\n";     break;
+        case -1: out << HTML::kBlue  << "\tStarted\n";     break;
+        default: out << HTML::kGreen << "\tRunning [" << d.GetQoS() << "]\n"; break;
         }
 
@@ -1466,4 +1488,5 @@
     // -------------------------------------------------------------------
 
+    /*
     bool CheckEventSize(size_t has, const char *name, size_t size)
     {
@@ -1475,5 +1498,5 @@
         Fatal(msg);
         return false;
-    }
+    }*/
 
     int Print() const
@@ -1501,8 +1524,8 @@
     {
         if (!state.online())
-            return kHtmlWhite+"\t&mdash;\n";
+            return HTML::kWhite+"\t&mdash;\n";
 
         if (&state==&fDimControl)
-            return kHtmlGreen +'\t'+(state.state()<-2?"Idle":fDimControl.shortmsg)+'\n';
+            return HTML::kGreen +'\t'+(state.state()<-2?"Idle":fDimControl.shortmsg)+'\n';
 
         const State rc = state.description();
@@ -1512,17 +1535,17 @@
         {
             ostringstream out;
-            out << kHtmlWhite << '\t' << state.state() << '\n';
+            out << HTML::kWhite << '\t' << state.state() << '\n';
             return out.str();
         }
 
         //ostringstream msg;
-        //msg << kHtmlWhite << '\t' << rc.name << " [" << rc.index << "]\n";
+        //msg << HTML::kWhite << '\t' << rc.name << " [" << rc.index << "]\n";
         //return msg.str();
 
         if (rc.index<1)
-            return kHtmlWhite + "\t&mdash;\n";
-
-
-        return (rc.index<green?kHtmlYellow:kHtmlGreen) + '\t' + rc.name + '\n';
+            return HTML::kWhite + "\t&mdash;\n";
+
+
+        return (rc.index<green?HTML::kYellow:HTML::kGreen) + '\t' + rc.name + '\n';
     }
 
@@ -1618,5 +1641,5 @@
         out << now.JavaDate() << '\t' << haserror << '\t' << (fDimControl.state()>-3) << '\n';
         out << setprecision(3);
-        out << kHtmlWhite << '\t' << msg.str() << '\n';
+        out << HTML::kWhite << '\t' << msg.str() << '\n';
 
         if (haserror || fHasError)
@@ -1637,12 +1660,12 @@
         if (fDimMcp.state()>=MCP::State::kIdle) // Idle
         {
-            string col = kHtmlBlue;
+            string col = HTML::kBlue;
             if (fMcpConfigurationState!=MCP::State::kIdle &&       // Idle
                 fMcpConfigurationState!=MCP::State::kTriggerOn &&  // Trigger On
                 fMcpConfigurationState!=MCP::State::kTakingData)  // Taking Data
-                col = kHtmlYellow;
+                col = HTML::kYellow;
             else
                 if (fDimFadControl.state()==FAD::State::kWritingData)
-                    col = kHtmlGreen;
+                    col = HTML::kGreen;
 
             out << col << '\t';
@@ -1735,5 +1758,5 @@
         }
         else
-            out << kHtmlWhite;
+            out << HTML::kWhite;
         out << '\n';
 
@@ -1743,15 +1766,15 @@
             const double dev = fDriveControlTrackingDevHist.size()>0 ? fDriveControlTrackingDevHist.back() : 0;
             const State rc = fDimDriveControl.description();
-            string col = kHtmlGreen;
+            string col = HTML::kGreen;
             if (rc.index==6) // Moving
-                col = kHtmlBlue;
+                col = HTML::kBlue;
             if (rc.index==5) // Armed
-                col = kHtmlWhite;
+                col = HTML::kWhite;
             if (rc.index==7) // Tracking
             {
                 if (dev>60)   // ~1.5mm
-                    col = kHtmlYellow;
+                    col = HTML::kYellow;
                 if (dev>100)  // ~1/4 of a pixel ~ 2.5mm
-                    col = kHtmlRed;
+                    col = HTML::kRed;
             }
             out << col << '\t';
@@ -1771,13 +1794,13 @@
         }
         else
-            out << kHtmlWhite << '\n';
+            out << HTML::kWhite << '\n';
 
         // ------------------- FSC ------------------
         if (fDimFscControl.state()>FSC::State::kDisconnected && fFscControlTemperatureHist.size()>0)
         {
-            out << kHtmlGreen << '\t' << fFscControlTemperatureHist.back() << '\n';
+            out << HTML::kGreen << '\t' << fFscControlTemperatureHist.back() << '\n';
         }
         else
-            out << kHtmlWhite << '\n';
+            out << HTML::kWhite << '\n';
 
         // --------------- MagicWeather -------------
@@ -1786,18 +1809,18 @@
             /*
             const float diff = fMagicWeatherHist[kTemp].back()-fMagicWeatherHist[kDew].back();
-            string col1 = kHtmlRed;
+            string col1 = HTML::kRed;
             if (diff>0.3)
-                col1 = kHtmlYellow;
+                col1 = HTML::kYellow;
             if (diff>0.7)
-                col1 = kHtmlGreen;
+                col1 = HTML::kGreen;
                 */
 
             const float wind = fMagicWeatherHist[kGusts].back();
             const float hum  = fMagicWeatherHist[kHum].back();
-            string col = kHtmlGreen;
+            string col = HTML::kGreen;
             if (wind>35 || hum>95)
-                col = kHtmlYellow;
+                col = HTML::kYellow;
             if (wind>50 || hum>98)
-                col = kHtmlRed;
+                col = HTML::kRed;
 
             out << col << '\t';
@@ -1808,14 +1831,14 @@
         }
         else
-            out << kHtmlWhite << "\n";
+            out << HTML::kWhite << "\n";
 
         // --------------- FtmControl -------------
         if (fDimFtmControl.state()==FTM::State::kTriggerOn)
         {
-            string col = kHtmlGreen;
+            string col = HTML::kGreen;
             if (fFtmControlTriggerRateCam<15)
-                col = kHtmlYellow;
+                col = HTML::kYellow;
             if (fFtmControlTriggerRateCam>100)
-                col = kHtmlRed;
+                col = HTML::kRed;
 
             out << col << '\t' << fFtmControlTriggerRateCam << '\t';
@@ -1823,5 +1846,5 @@
         }
         else
-            out << kHtmlWhite << '\n';
+            out << HTML::kWhite << '\n';
 
         // --------------- BiasControl -------------
@@ -1834,13 +1857,13 @@
             const bool oc  = fDimBiasControl.state()==BIAS::State::kOverCurrent;
 
-            string col = fBiasControlVoltageMed>3?kHtmlGreen:kHtmlWhite;
+            string col = fBiasControlVoltageMed>3?HTML::kGreen:HTML::kWhite;
             if (fBiasControlCurrentMax>65)
-                col = kHtmlYellow;
+                col = HTML::kYellow;
             if (fBiasControlCurrentMax>80)
-                col = kHtmlRed;
+                col = HTML::kRed;
 
             // Bias in overcurrent => Red
             if (fDimBiasControl.state()==BIAS::State::kOverCurrent)
-                col = kHtmlRed;
+                col = HTML::kRed;
 
             // MCP in ReadyForDatataking/Configuring/Configured/TriggerOn/TakingData
@@ -1849,5 +1872,5 @@
                 fDimBiasControl.state()!=BIAS::State::kVoltageOn &&
                 fDimBiasControl.state()!=BIAS::State::kVoltageOff)
-                col = kHtmlRed;
+                col = HTML::kRed;
 
             const bool cal = fFeedbackCalibration.size();
@@ -1856,5 +1879,5 @@
             if (fDimFeedback.state()==13)
             {
-                out << kHtmlBlue << '\t';
+                out << HTML::kBlue << '\t';
                 out << "***\t";
                 out << "***\t";
@@ -1884,5 +1907,5 @@
         }
         else
-            out << kHtmlWhite << '\n';
+            out << HTML::kWhite << '\n';
 
         ofstream(fPath+"/fact.data") << out.str();
@@ -1894,5 +1917,5 @@
 
         if (!fDimDNS.online())
-            out << kHtmlWhite << "\tOffline\n\n\n\n\n\n\n\n\n\n\n\n\n";
+            out << HTML::kWhite << "\tOffline\n\n\n\n\n\n\n\n\n\n\n\n\n";
         else
         {
@@ -1900,5 +1923,5 @@
             dt << (Time()-fRunTime);
 
-            out << kHtmlGreen << '\t' << fDimDNS.version() << '\n';
+            out << HTML::kGreen << '\t' << fDimDNS.version() << '\n';
 
             out << GetStateHtml(fDimControl,      0);
@@ -1917,5 +1940,5 @@
             out << GetStateHtml(fDimChatServer,   1);
 
-            out << kHtmlGreen << '\t' << dt.str().substr(0, dt.str().length()-7) << '\n';
+            out << HTML::kGreen << '\t' << dt.str().substr(0, dt.str().length()-7) << '\n';
         }
 
@@ -2135,35 +2158,11 @@
         return -1;
 
-    //try
-    {
-        // No console access at all
-        if (!conf.Has("console"))
-        {
-//            if (conf.Get<bool>("no-dim"))
-//                return RunShell<LocalStream, StateMachine, ConnectionFSC>(conf);
-//            else
-                return RunShell<LocalStream>(conf);
-        }
-        // Cosole access w/ and w/o Dim
-/*        if (conf.Get<bool>("no-dim"))
-        {
-            if (conf.Get<int>("console")==0)
-                return RunShell<LocalShell, StateMachine, ConnectionFSC>(conf);
-            else
-                return RunShell<LocalConsole, StateMachine, ConnectionFSC>(conf);
-        }
-        else
-*/        {
-            if (conf.Get<int>("console")==0)
-                return RunShell<LocalShell>(conf);
-            else
-                return RunShell<LocalConsole>(conf);
-        }
-    }
-    /*catch (std::exception& e)
-    {
-        cerr << "Exception: " << e.what() << endl;
-        return -1;
-    }*/
+    if (!conf.Has("console"))
+        return RunShell<LocalStream>(conf);
+
+    if (conf.Get<int>("console")==0)
+        return RunShell<LocalShell>(conf);
+    else
+        return RunShell<LocalConsole>(conf);
 
     return 0;
