Index: /trunk/FACT++/src/fadctrl.cc
===================================================================
--- /trunk/FACT++/src/fadctrl.cc	(revision 16105)
+++ /trunk/FACT++/src/fadctrl.cc	(revision 16106)
@@ -153,6 +153,4 @@
         }
 
-        EventBuilderWrapper::This->debugStream(fSlot*7, fBuffer.data(), bytes_received);
-
         if (type==kReadHeader)
         {
@@ -183,5 +181,5 @@
             UpdateEventHeader();
 
-            EventBuilderWrapper::This->debugHead(fSlot*7, fEventHeader);
+            EventBuilderWrapper::This->debugHead(fEventHeader);
 
             fBuffer.resize(fEventHeader.fPackageLength-sizeof(FAD::EventHeader)/2);
@@ -911,14 +909,4 @@
     }
 
-    int SetDebugEb(const EventImp &evt)
-    {
-        if (!CheckEventSize(evt.GetSize(), "SetDebugEb", 1))
-            return T::kSM_FatalError;
-
-        SetDebugLog(evt.GetBool());
-
-        return T::GetCurrentState();
-    }
-
     const BoardList::iterator GetSlot(uint16_t slot)
     {
@@ -1022,24 +1010,4 @@
         for (int i=slot[0]; i<=slot[1]; i++)
             SetIgnore(i, block);
-
-        return T::GetCurrentState();
-    }
-
-    int SetDumpStream(const EventImp &evt)
-    {
-        if (!CheckEventSize(evt.GetSize(), "SetDumpStream", 1))
-            return T::kSM_FatalError;
-
-        SetDebugStream(evt.Get<uint8_t>());
-
-        return T::GetCurrentState();
-    }
-
-    int SetDumpRecv(const EventImp &evt)
-    {
-        if (!CheckEventSize(evt.GetSize(), "SetDumpRecv", 1))
-            return T::kSM_FatalError;
-
-        SetDebugRead(evt.Get<uint8_t>());
 
         return T::GetCurrentState();
@@ -1099,4 +1067,6 @@
         }
 
+        fConfigTimer = Time(Time::none);
+
         // Now the old run is stopped already. So all other servers can start a new run
         // (Note that we might need another step which only checks if the continous trigger
@@ -1107,6 +1077,4 @@
         // T::Info(" ==> TODO: Insert/update run configuration in database!");
 
-        fConfigTimer = Time();
-
         return FAD::State::kConfiguring1;
     }
@@ -1190,7 +1158,7 @@
             switch (fStatus2[idx])
             {
-            case 0:  str << "1-7:not connected)"; break;
-            case 8:  str << "1-7:connected)";     break;
-            default: str << "1-7:connecting [" << (int)(fStatus2[idx]-1) << "])"; break;
+            case 0:  str << "1:disconnected)"; break;
+            case 8:  str << "1:connected)";     break;
+            default: str << "1:connecting)";    break;
             }
 
@@ -1201,5 +1169,5 @@
                 str << " [data_ignored]";
 
-            if (fStatusC[idx])
+            if (fad->IsConnected() && fStatus2[idx]==8 && fad->IsConfigured())
                 str << " [configured]";
 
@@ -1394,5 +1362,4 @@
     vector<uint8_t> fStatus1;
     vector<uint8_t> fStatus2;
-    vector<uint8_t> fStatusC;
     bool            fStatusT;
 
@@ -1458,19 +1425,18 @@
             // ----- Event builder -----
 
+            stat2[idx] = 0; // disconnected
             if (!runs)
                 continue;
 
-            stat2[idx] = GetNumConnected(idx);
-
-            if (runs && IsConnecting(idx))
+            if (IsConnecting(idx))
             {
                 nconnecting2++;
-                stat2[idx]++;
+                stat2[idx] = 1; // connecting
             }
 
             if (IsConnected(idx))
             {
-                stat2[idx]++;
                 nconnected2++;
+                stat2[idx] = 8; // connected
             }
         }
@@ -1533,5 +1499,18 @@
                 // and really sees the software trigger
                 // FIXME: Do we need this to be configurable?
-                if (Time()-fConfigTimer<boost::posix_time::milliseconds(3000))
+                //if (Time()-fConfigTimer<boost::posix_time::milliseconds(3000))
+
+                // Wait until the configuration commands to all boards
+                // have been sent and achknowledged
+                for (BoardList::iterator it=fBoards.begin(); it!=fBoards.end(); it++)
+                    if (!it->second->IsTxQueueEmpty())
+                        return FAD::State::kConfiguring1;
+
+                if (!fConfigTimer)
+                    fConfigTimer = Time();
+
+                // Wait a short moment to ensure that all board have processed
+                // the received data
+                if (Time()-fConfigTimer<boost::posix_time::milliseconds(250))
                     return FAD::State::kConfiguring1;
 
@@ -1584,14 +1563,15 @@
                 // (means the the event builder has received its
                 // first event)
-                if (!IsRunStarted() && nconfigured==nconnected1)
+                if (IsRunWaiting() && nconfigured==nconnected1)
                     return FAD::State::kConfigured;
 
-                if (IsRunStarted())
-                    T::Message("Run successfully started... (gotNewRun called)");
+                if (!IsRunWaiting())
+                    T::Message("Run successfully started... first data received.");
                 if (nconfigured!=nconnected1)
                     T::Message("Configuration of some boards changed.");
             }
 
-            return GetNumFilesOpen()>0 && IsRunFileOpen() ? FAD::State::kWritingData : FAD::State::kConnected;
+            // FIXME: Rename WritingData to TakingData
+            return IsRunInProgress() ? FAD::State::kWritingData : FAD::State::kConnected;
         }
 
@@ -1649,5 +1629,5 @@
     StateMachineFAD(ostream &out=cout) :
         T(out, "FAD_CONTROL"), EventBuilderWrapper(*static_cast<MessageImp*>(this)), ba::io_service::work(static_cast<ba::io_service&>(*this)),
-        fStatus1(40), fStatus2(40), fStatusC(40), fStatusT(false),
+        fStatus1(40), fStatus2(40), fStatusT(false),
         fDimStartRun("FAD_CONTROL/START_RUN", "X:1;X:1",
                                               "Run numbers"
@@ -1821,23 +1801,8 @@
 	     "|debug[bool]:disable or enable debug output for transmitted data (yes/no)");
 
-        T::AddEvent("SET_DEBUG_EVENT_BUILDER_OUT", "B:1")
-            (bind(&StateMachineFAD::SetDebugEb, this, placeholders::_1))
-            ("Enable or disable the debug output from the event builder"
-             "|enable[bool]:Enable/Disable (yes/no)");
-
         T::AddEvent("PRINT_EVENT", "S:1")
             (bind(&StateMachineFAD::PrintEvent, this, placeholders::_1))
             ("Print (last) event"
              "|board[short]:slot from which the event should be printed (-1 for all)");
-
-        T::AddEvent("DUMP_STREAM", "B:1")
-            (bind(&StateMachineFAD::SetDumpStream, this, placeholders::_1))
-            ("For debugging purpose: the binary data stream read from the sockets 0-7 can be dumped to files."
-             "|switch[bool]:Enable (yes) or disable (no)");
-
-        T::AddEvent("DUMP_RECV", "B:1")
-            (bind(&StateMachineFAD::SetDumpRecv, this, placeholders::_1))
-            ("For debugging purpose: the times when data has been receives are dumped to a file."
-             "|switch[bool]:Enable (yes) or disable (no)");
 
         T::AddEvent("BLOCK_TRANSMISSION", "S:1;B:1")
