Index: trunk/FACT++/src/HeadersFTM.h
===================================================================
--- trunk/FACT++/src/HeadersFTM.h	(revision 16782)
+++ trunk/FACT++/src/HeadersFTM.h	(revision 16783)
@@ -43,5 +43,6 @@
             kConfiguring1,
             kConfiguring2,
-            kConfigured,
+            kConfigured1,
+            kConfigured2,
 
             kConfigError1 = 0x101,
Index: trunk/FACT++/src/ftmctrl.cc
===================================================================
--- trunk/FACT++/src/ftmctrl.cc	(revision 16782)
+++ trunk/FACT++/src/ftmctrl.cc	(revision 16783)
@@ -422,5 +422,4 @@
     }
 
-
     template<size_t N>
     void PostCmd(array<uint16_t, N> dat, uint16_t u1=0, uint16_t u2=0, uint16_t u3=0, uint16_t u4=0)
@@ -520,10 +519,11 @@
     }
 
-    void CmdStartRun()
+    void CmdStartRun(bool log=true)
     {
         PostCmd(FTM::kCmdStartRun, FTM::kStartRun);
         CmdGetRegister(0);
 
-        Info("Sending start trigger.");
+        if (log)
+            Info("Sending start trigger.");
     }
 
@@ -917,5 +917,5 @@
     bool SetTriggerInterval(uint32_t val)
     {
-        return SetVal(&fBufStaticData.fTriggerInterval, val,
+        return SetVal(&fStaticData.fTriggerInterval, val,
                       FTM::StaticData::kMaxTriggerInterval);
     }
@@ -923,5 +923,5 @@
     bool SetTriggerDelay(uint32_t val)
     {
-        return SetVal(&fBufStaticData.fDelayTrigger, val,
+        return SetVal(&fStaticData.fDelayTrigger, val,
                       FTM::StaticData::kMaxDelayTrigger);
     }
@@ -929,5 +929,5 @@
     bool SetTimeMarkerDelay(uint32_t val)
     {
-        return SetVal(&fBufStaticData.fDelayTimeMarker, val,
+        return SetVal(&fStaticData.fDelayTimeMarker, val,
                       FTM::StaticData::kMaxDelayTimeMarker);
     }
@@ -935,5 +935,5 @@
     bool SetDeadTime(uint32_t val)
     {
-        return SetVal(&fBufStaticData.fDeadTime, val,
+        return SetVal(&fStaticData.fDeadTime, val,
                       FTM::StaticData::kMaxDeadTime);
     }
@@ -1518,4 +1518,25 @@
     }
 
+    int StartRun()
+    {
+        // This is a workaround... it seems that the FTM ignored the 'trigger on'
+        // as long as it is still sending thresholds to the FTUs (and it seems
+        // that this is the only command/confguration) which gets ignored.
+        // So if we are configuring, we resent this command until we got a
+        // reasonable answer (TriggerOn) back from the FTM.
+        // There is no need to send the command here, because Execute
+        // will be called immediately after this anyway before any
+        // answer could be processed. So it would just guarantee that
+        // the command is sent twice for no reason.
+
+        fFTM.CmdStartRun();
+
+        if (T::GetCurrentState()!=FTM::State::kConfigured1)
+            return T::GetCurrentState();
+
+        fCounterReg = fFTM.GetCounter(FTM::kRegister);
+        return FTM::State::kConfigured2;
+    }
+
     int TakeNevents(const EventImp &evt)
     {
@@ -1637,5 +1658,5 @@
         {
             ostringstream msg;
-            msg << "SetAllThresholds - Value out of range, maximum 0xffff.";
+            msg << "SetSelectedThresholds - Value out of range, maximum 0xffff.";
             T::Warn(msg);
         }
@@ -2035,5 +2056,5 @@
             // the counter for the registers has been increased
             if (fFTM.GetCounter(FTM::kRegister)<=fCounterReg)
-                break;
+                return FTM::State::kConfiguring1;
 
             // If now the state is not idle as expected this means we had
@@ -2053,5 +2074,5 @@
 
         case FTM::State::kConfiguring2:
-        case FTM::State::kConfigured:
+        case FTM::State::kConfigured1:
             // If FTM has received an anwer to the CmdSendStatDat
             // the counter for static data has been increased
@@ -2075,5 +2096,31 @@
 
             // Next state is: wait for the answer to our configuration
-            return FTM::State::kConfigured;
+            return FTM::State::kConfigured1;
+
+        // This state is set by StartRun [START_TRIGGER]
+        case FTM::State::kConfigured2:
+            // No answer to the CmdStartRun received yet... go on waiting
+            if (fFTM.GetCounter(FTM::kRegister)<=fCounterReg)
+                return FTM::State::kConfigured2;
+
+            // Answer received and trigger enable acknowledged
+            if (fFTM.GetState()==ConnectionFTM::kTriggerOn)
+                return FTM::State::kTriggerOn;
+
+            // If the trigger is not enabled, but the configuration
+            // has changed go to error state (should never happen)
+            if (fFTM.GetState()!=ConnectionFTM::kConfigured)
+                return FTM::State::kConfigError2;
+
+            // Send a new command... the previous one might have gone
+            // ignored by the ftm because it was just after a
+            // threshold setting during the configured state
+            fFTM.CmdStartRun(false);
+
+            // Set counter to wait for answer.
+            fCounterReg = fFTM.GetCounter(FTM::kRegister);
+
+            // Go on waiting for a proper acknowledge of the trigger enable
+            return FTM::State::kConfigured2;
 
         case FTM::State::kConfigError1:
@@ -2093,16 +2140,4 @@
         }
 
-        if (T::GetCurrentState()==FTM::State::kConfigured &&
-            fFTM.GetState()==ConnectionFTM::kTriggerOn)
-        {
-//            if (!fFTM.IsLocked())
-//            {
-//                T::Warn("Configuration successfull, but clock conditioner not locked.");
-//                return FTM::State::kConfigError3;
-//            }
-
-            return FTM::State::kTriggerOn;
-        }
-
         return T::GetCurrentState();
     }
@@ -2129,6 +2164,8 @@
         T::AddStateName(FTM::State::kConfiguring2, "Configuring2",
                         "New configuration sent... waiting for response.");
-        T::AddStateName(FTM::State::kConfigured,   "Configured",
+        T::AddStateName(FTM::State::kConfigured1,   "Configured1",
                         "Received answer identical with target configuration.");
+        T::AddStateName(FTM::State::kConfigured2, "Configured2",
+                        "Waiting for acknowledge of trigger enable.");
 
         T::AddStateName(FTM::State::kTriggerOn, "TriggerOn",
@@ -2167,6 +2204,6 @@
             "|val[short]:Value to be set");
 
-        T::AddEvent("START_TRIGGER", FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured)
-            (Wrapper(bind(&ConnectionFTM::CmdStartRun, &fFTM)))
+        T::AddEvent("START_TRIGGER", FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured1, FTM::State::kConfigured2)
+            (bind(&StateMachineFTM::StartRun, this))
             ("start a run (start distributing triggers)");
 
@@ -2184,5 +2221,5 @@
              "|status[bool]:disable or enable that the FTM sends rate reports (yes/no)");
 
-        T::AddEvent("SET_THRESHOLD", "I:2", FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured, FTM::State::kTriggerOn)
+        T::AddEvent("SET_THRESHOLD", "I:2", FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured1, FTM::State::kTriggerOn)
             (bind(&StateMachineFTM::SetThreshold, this, placeholders::_1))
             ("Set the comparator threshold"
@@ -2191,9 +2228,9 @@
 
         T::AddEvent("SET_SELECTED_THRESHOLDS", "I:160", FTM::State::kTriggerOn)
-            (bind(&StateMachineFTM::SetAllThresholds, this, placeholders::_1))
+            (bind(&StateMachineFTM::SetSelectedThresholds, this, placeholders::_1))
             ("Set the comparator thresholds. Only thresholds which are different and >=0 are sent."
              "|Thresholds[counts]:Threshold to be set in binary counts");
 
-        T::AddEvent("SET_ALL_THRESHOLDS", "I:160", FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured)
+        T::AddEvent("SET_ALL_THRESHOLDS", "I:160", FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured1)
             (bind(&StateMachineFTM::SetAllThresholds, this, placeholders::_1))
             ("Set the comparator thresholds"
@@ -2211,5 +2248,5 @@
              "|time[0.5s]:The interval is given in units of 0.5s, i.e. 1 means 0.5s, 2 means 1s, ...");
 
-        T::AddEvent("ENABLE_FTU", "I:1;B:1", FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured)
+        T::AddEvent("ENABLE_FTU", "I:1;B:1", FTM::State::kIdle, FTM::State::kValid)
             (bind(&StateMachineFTM::EnableFTU, this, placeholders::_1))
             ("Enable or disable FTU"
@@ -2352,9 +2389,9 @@
         // A new configure will first stop the FTM this means
         // we can allow it in idle _and_ taking data
-        T::AddEvent("CONFIGURE", "C")(FTM::State::kIdle)(FTM::State::kValid)(FTM::State::kConfiguring1)(FTM::State::kConfiguring2)(FTM::State::kConfigured)(FTM::State::kTriggerOn)
+        T::AddEvent("CONFIGURE", "C")(FTM::State::kIdle)(FTM::State::kValid)(FTM::State::kConfiguring1)(FTM::State::kConfiguring2)(FTM::State::kConfigured1)(FTM::State::kConfigured2)(FTM::State::kTriggerOn)
             (bind(&StateMachineFTM::ConfigureFTM, this, placeholders::_1))
             ("");
 
-        T::AddEvent("RESET_CONFIGURE")(FTM::State::kConfiguring1)(FTM::State::kConfiguring2)(FTM::State::kConfigured)(FTM::State::kConfigError1)(FTM::State::kConfigError2)(FTM::State::kConfigError2)
+        T::AddEvent("RESET_CONFIGURE")(FTM::State::kConfiguring1)(FTM::State::kConfiguring2)(FTM::State::kConfigured1)(FTM::State::kConfigured2)(FTM::State::kConfigError1)(FTM::State::kConfigError2)(FTM::State::kConfigError2)
             (bind(&StateMachineFTM::ResetConfig, this))
             ("Reset states during a configuration or in case of configuration error");
@@ -2362,5 +2399,5 @@
 
 
-        T::AddEvent("RESET_CRATE", "S:1", FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured)
+        T::AddEvent("RESET_CRATE", "S:1", FTM::State::kIdle, FTM::State::kValid)
             (bind(&StateMachineFTM::ResetCrate, this, placeholders::_1))
             ("Reset one of the crates 0-3"
@@ -2407,5 +2444,5 @@
             ("disconnect from ethernet");
 
-        T::AddEvent("RECONNECT", "O", FTM::State::kDisconnected, FTM::State::kConnected, FTM::State::kIdle, FTM::State::kValid, FTM::State::kConfigured)
+        T::AddEvent("RECONNECT", "O", FTM::State::kDisconnected, FTM::State::kConnected, FTM::State::kIdle, FTM::State::kValid)
             (bind(&StateMachineFTM::Reconnect, this, placeholders::_1))
             ("(Re)connect ethernet connection to FTM, a new address can be given"
