Index: trunk/FACT++/src/ftmctrl.cc
===================================================================
--- trunk/FACT++/src/ftmctrl.cc	(revision 10622)
+++ trunk/FACT++/src/ftmctrl.cc	(revision 10623)
@@ -157,6 +157,27 @@
         Out() << "D=" << fCounter[kDynamicData] << "  ";
         Out() << "F=" << fCounter[kFtuList] << "  ";
-        Out() << "E=" << fCounter[kError] << "  ";
+        Out() << "E=" << fCounter[kErrorList] << "  ";
         Out() << "R=" << fCounter[kRegister] << endl;
+    }
+
+    void CheckConsistency()
+    {
+        if (fStaticData.IsEnabled(StaticData::kPedestal) != (fStaticData.GetSequencePed()  >0) ||
+            fStaticData.IsEnabled(StaticData::kLPint)    != (fStaticData.GetSequenceLPint()>0) ||
+            fStaticData.IsEnabled(StaticData::kLPext)    != (fStaticData.GetSequenceLPext()>0))
+        {
+            Warn("GeneralSettings not consistent with trigger sequence.");
+        }
+
+        const uint16_t ref = fStaticData[0].fPrescaling;
+        for (int i=1; i<40; i++)
+        {
+            if (fStaticData[i].fPrescaling != ref)
+            {
+                Warn("Prescaling not consistent for all boards.");
+                break;
+            }
+        }
+
     }
 
@@ -292,6 +313,9 @@
 
             case kStaticData:
-                cout << fBuffer.size() << " " << sizeof(fStaticData) << endl;
                 fStaticData = fBuffer;
+
+                if (fCounter[kStaticData]==1)
+                    CheckConsistency();
+
                 UpdateStaticData();
                 break;
@@ -306,5 +330,6 @@
                 {
                     Out() << endl << kBold << "Register received: " << endl;
-                    Out() << "Value: " << ntohs(fBuffer[0]) << endl;
+                    Out() << "Addr:  " << ntohs(fBuffer[0]) << endl;
+                    Out() << "Value: " << ntohs(fBuffer[1]) << endl;
                 }
                 break;
@@ -477,5 +502,5 @@
         // Request the changed configuration to ensure the
         // change is distributed in the network
-        CmdReqStatDat();
+        //CmdReqStatDat();
     }
 
@@ -735,4 +760,66 @@
     }
 
+    void Enable(FTM::StaticData::GeneralSettings type, bool enable)
+    {
+        fStaticData.Enable(type, enable);
+    }
+
+    bool SetTriggerSeq(const uint8_t d[3])
+    {
+        const uint16_t oldset = fStaticData.fGeneralSettings;
+        const uint16_t oldseq = fStaticData.fTriggerSequence;
+
+        fStaticData.Enable(StaticData::kPedestal, d[0]>0);
+        fStaticData.Enable(StaticData::kLPext,    d[1]>0);
+        fStaticData.Enable(StaticData::kLPint,    d[2]>0);
+
+        if (d[0]>StaticData::kMaxSequence ||
+            d[1]>StaticData::kMaxSequence ||
+            d[2]>StaticData::kMaxSequence)
+            return false;
+
+        fStaticData.fTriggerSequence =
+            (d[0]<<10) | (d[1]<<5) || d[2];
+
+        if (oldseq!=fStaticData.fTriggerSequence || oldset!=fStaticData.fGeneralSettings)
+            CmdSendStatDat();
+
+        return true;
+    }
+
+    bool SetTriggerCoincidence(uint16_t n, uint16_t win)
+    {
+        if (n==0 || n>StaticData::kMaxCoincidence || win>StaticData::kMaxWindow)
+            return false;
+
+        if (n  ==fStaticData.fCoincidencePhysics &&
+            win==fStaticData.fWindowPhysics)
+            return true;
+
+        fStaticData.fCoincidencePhysics = n;
+        fStaticData.fWindowPhysics      = win;
+
+        CmdSendStatDat();
+
+        return true;
+    }
+
+    bool SetCalibCoincidence(uint16_t n, uint16_t win)
+    {
+        if (n==0 || n>StaticData::kMaxCoincidence || win>StaticData::kMaxWindow)
+            return false;
+
+        if (n  ==fStaticData.fCoincidenceCalib &&
+            win==fStaticData.fWindowCalib)
+            return true;
+
+        fStaticData.fCoincidenceCalib = n;
+        fStaticData.fWindowCalib      = win;
+
+        CmdSendStatDat();
+
+        return true;
+    }
+
     int GetState() const { return IsConnected() ? fState : (int)FTM::kDisconnected; }
 };
@@ -822,5 +909,5 @@
             fCounter[kDynamicData],
             fCounter[kFtuList],
-            fCounter[kError],
+            fCounter[kErrorList],
             fCounter[kRegister],
         };
@@ -835,5 +922,5 @@
         fDimTriggerCounter("FTM_CONTROL/TRIGGER_COUNTER", "X:1;L:1",      NULL, 0, ""),
         fDimError         ("FTM_CONTROL/ERROR",           "X:1;S:1;S:28", NULL, 0, ""),
-        fDimFtuList       ("FTM_CONTROL/FTU_LIST",        "X:1;X:1;S:1;C:4;X:40;C:40;C:40", NULL, 0, ""),
+        fDimFtuList       ("FTM_CONTROL/FTU_LIST",        "X:1;X:1;S:1;C:4;X:40;C:40;C:40",  NULL, 0, ""),
         fDimStaticData    ("FTM_CONTROL/STATIC_DATA",     "X:1;S:1;S:1;X:1;S:1;S:3;S:1;S:1;S:1;S:1;S:1;S:1;I:1;S:8;S:80;S:160;S:40;S:40", NULL, 0, ""),
         fDimDynamicData   ("FTM_CONTROL/DYNAMIC_DATA",    "X:1;X:1;F:4;I:160;I:40;S:40;S:40", NULL, 0, ""),
@@ -1102,4 +1189,17 @@
     }
 
+    int SetTriggerSeq(const EventImp &evt)
+    {
+        if (!CheckEventSize(evt.GetSize(), "SetTriggerSeq", 3))
+            return T::kSM_FatalError;
+
+        const uint8_t *data = reinterpret_cast<const uint8_t*>(evt.GetData());
+
+        if (!fFTM.SetTriggerSeq(data))
+            T::Warn("SetTriggerSeq -  Value out of range.");
+
+        return T::GetCurrentState();
+    }
+
     int SetDeadTime(const EventImp &evt)
     {
@@ -1109,4 +1209,40 @@
         if (!fFTM.SetDeadTime(evt.GetInt()))
             T::Warn("SetDeadTime -  Value out of range.");
+
+        return T::GetCurrentState();
+    }
+
+    int SetTriggerCoincidence(const EventImp &evt)
+    {
+        if (!CheckEventSize(evt.GetSize(), "SetTriggerCoincidence", 4))
+            return T::kSM_FatalError;
+
+        const uint16_t *d = reinterpret_cast<const uint16_t*>(evt.GetText());;
+
+        if (!fFTM.SetTriggerCoincidence(d[0], d[1]))
+            T::Warn("SetTriggerCoincidence -  Value out of range.");
+
+        return T::GetCurrentState();
+    }
+
+    int SetCalibCoincidence(const EventImp &evt)
+    {
+        if (!CheckEventSize(evt.GetSize(), "SetCalibCoincidence", 4))
+            return T::kSM_FatalError;
+
+        const uint16_t *d = reinterpret_cast<const uint16_t*>(evt.GetText());;
+
+        if (!fFTM.SetCalibCoincidence(d[0], d[1]))
+            T::Warn("SetCalibCoincidence -  Value out of range.");
+
+        return T::GetCurrentState();
+    }
+
+    int Enable(const EventImp &evt, FTM::StaticData::GeneralSettings type)
+    {
+        if (!CheckEventSize(evt.GetSize(), "Enable", 1))
+            return T::kSM_FatalError;
+
+        fFTM.Enable(type, evt.GetText()[0]!=0);
 
         return T::GetCurrentState();
@@ -1281,4 +1417,40 @@
              "|[]:");
 
+        AddConfiguration("ENABLE_TRIGGER", "B:1", kStateIdle)
+            (boost::bind(&StateMachineFTM::Enable, this, _1, FTM::StaticData::kTrigger))
+            (""
+             "|[]:");
+
+        // FIXME: Switch on/off depending on sequence
+        AddConfiguration("ENABLE_EXT1", "B:1", kStateIdle)
+            (boost::bind(&StateMachineFTM::Enable, this, _1, FTM::StaticData::kExt1))
+            (""
+             "|[]:");
+
+        // FIXME: Switch on/off depending on sequence
+        AddConfiguration("ENABLE_EXT2", "B:1", kStateIdle)
+            (boost::bind(&StateMachineFTM::Enable, this, _1, FTM::StaticData::kExt2))
+            (""
+             "|[]:");
+
+        AddConfiguration("ENABLE_VETO", "B:1", kStateIdle)
+            (boost::bind(&StateMachineFTM::Enable, this, _1, FTM::StaticData::kVeto))
+            (""
+             "|[]:");
+
+        AddConfiguration("SET_TRIGGER_SEQUENCE", "C:3", kStateIdle)
+            (boost::bind(&StateMachineFTM::SetTriggerSeq, this, _1))
+            (""
+             "|[]:");
+
+        AddConfiguration("SET_TRIGGER_COINCIDENCE", "S:2", kStateIdle)
+            (boost::bind(&StateMachineFTM::SetTriggerCoincidence, this, _1))
+            (""
+             "|[]:");
+
+        AddConfiguration("SET_CALIBRATION_COINCIDENCE", "S:2", kStateIdle)
+            (boost::bind(&StateMachineFTM::SetCalibCoincidence, this, _1))
+            (""
+             "|[]:");
 
 
@@ -1329,17 +1501,4 @@
 
         fFTM.StartConnect();
-
-
-        // ENABLE_TRIGGER         bool
-        // ENABLE_EXT1            bool
-        // ENABLE_EXT2            bool
-        // ENABLE_VETO            bool
-        // ---> Enable(bit, bool)
-
-        // SET_TRIGGER_SEQUENCE   val val val
-        // ---> SetTriggerSequence(val, val, val)
-
-        // SET_PRESCALING         idx val
-        // ---> SetPrescaling(idx==-1, val)
     }
 
