Index: trunk/FACT++/src/smartfact.cc
===================================================================
--- trunk/FACT++/src/smartfact.cc	(revision 13904)
+++ trunk/FACT++/src/smartfact.cc	(revision 13905)
@@ -328,4 +328,5 @@
 
     deque<string> fControlMessageHist;
+    int32_t       fControlScriptDepth;
 
     uint32_t fMcpConfigurationState;   // For consistency
@@ -377,5 +378,5 @@
     deque<float> fRateScanDataHist[41];
 
-    bool fHasError;
+    int fHasError;
 
     // ------------- Initialize variables before the Dim stuff ------------
@@ -520,4 +521,6 @@
     int HandleDimControlMessage(const EventImp &d)
     {
+        cout << "Received1: " << d.GetQoS() << endl;
+
         if (d.GetQoS()==90)
             HandleControlMessageImp(d);
@@ -528,21 +531,24 @@
     void HandleControlStateChange(const EventImp &d)
     {
-        if (d.GetQoS()==-2)
+        DimControl ctrl;
+        ctrl.Handler(d);
+
+        if (d.GetQoS()==-2 && ctrl.scriptdepth==0)
             fControlMessageHist.clear();
 
-        if (d.GetQoS()<0)
-        {
-            DimControl ctrl;
-            ctrl.Handler(d);
+        cout << "Received2: " << d.GetString() << endl;
+        cout << "Received2: " << d.GetQoS() << endl;
+
+        if (d.GetQoS()>=0)
+            return;
 
 #if BOOST_VERSION < 104600
-            const string file = boost::filesystem::path(ctrl.file).filename();
+        const string file = boost::filesystem::path(ctrl.file).filename();
 #else
-            const string file = boost::filesystem::path(ctrl.file).filename().string();
+        const string file = boost::filesystem::path(ctrl.file).filename().string();
 #endif
 
-            const string msg = ctrl.shortmsg+"<br>"+file;
-            HandleControlMessageImp(Event(d, msg.data(), msg.length()+1));
-        }
+        HandleControlMessageImp(Event(d, ctrl.shortmsg.data(), ctrl.shortmsg.length()+1));
+        HandleControlMessageImp(Event(d, file.data(), file.length()+1));
     }
 
@@ -551,5 +557,5 @@
         if (!CheckDataSize(d, "Mcp:Configuration", 16, true))
         {
-            fMcpConfigurationState     = -4;
+            fMcpConfigurationState     = -256;
             fMcpConfigurationMaxTime   = 0;
             fMcpConfigurationMaxEvents = 0;
@@ -1497,7 +1503,4 @@
         //poll_one();
 
-        if (!fDimDNS.online())
-            return kStateDimNetworkNA;
-
         Time now;
         if (now-fLastUpdate<boost::posix_time::seconds(1))
@@ -1510,4 +1513,8 @@
         ostringstream msg;
 
+        if (fHasError==2)
+            msg << "SmartFACT backend initializing." << endl;
+        if (!fDimDNS.online())
+            msg << "DIM network not available.<br/>";
         if (fDimDriveControl.state()>0xff)
             msg << "Drive in ERROR state<br/>";
@@ -1569,4 +1576,7 @@
 
         fHasError = haserror;
+
+        if (!fDimDNS.online())
+            return kStateDimNetworkNA;
 
         // ==============================================================
@@ -1845,4 +1855,5 @@
     StateMachineSmartFACT(ostream &out=cout) : StateMachineDim(out, "SMART_FACT"),
         fPath("www/smartfact/data"),
+        fControlScriptDepth(0),
         fMcpConfigurationMaxTime(0),
         fMcpConfigurationMaxEvents(0),
@@ -1855,5 +1866,5 @@
         fRateScanDataId(0),
         fRateScanBoard(0),
-        fHasError(false),
+        fHasError(2),
         // ---
         fDimMcp         ("MCP"),
@@ -1887,4 +1898,7 @@
         fDimChatServer.Subscribe(*this);
 
+        fDimControl.SetCallback(bind(&StateMachineSmartFACT::HandleControlStateChange, this, placeholders::_1));
+        fDimControl.AddCallback("dotest.dim", bind(&StateMachineSmartFACT::HandleDoTest, this, placeholders::_1));
+
         Subscribe("DIM_CONTROL/MESSAGE")
             (bind(&StateMachineSmartFACT::HandleDimControlMessage,   this, placeholders::_1));
@@ -1962,7 +1976,4 @@
 
         fPath = conf.Get<string>("path");
-
-        fDimControl.SetCallback(bind(&StateMachineSmartFACT::HandleControlStateChange, this, placeholders::_1));
-        fDimControl.AddCallback("dotest.dim", bind(&StateMachineSmartFACT::HandleDoTest, this, placeholders::_1));
 
         return -1;
