Index: trunk/FACT++/src/ftmctrl.cc
===================================================================
--- trunk/FACT++/src/ftmctrl.cc	(revision 10678)
+++ trunk/FACT++/src/ftmctrl.cc	(revision 10679)
@@ -44,4 +44,6 @@
     bool fIsDynamicOut;
     bool fIsHexOutput;
+
+//    string fDefaultSetup;
 
     // --verbose
@@ -197,6 +199,4 @@
     void HandleReceivedData(const bs::error_code& err, size_t bytes_received, int /*type*/)
     {
-        cout << "Data received " << err << " " << bytes_received << endl;
-
         // Do not schedule a new read if the connection failed.
         if (bytes_received==0 || err)
@@ -315,6 +315,4 @@
             UpdateCounter();
 
-            cout << "TYPE=" << fHeader.fType << endl;
-
             switch (fHeader.fType)
             {
@@ -391,4 +389,7 @@
         fBuffer.resize(sizeof(FTM::Header)/2);
         AsyncRead(ba::buffer(fBuffer));
+
+//        if (!fDefaultSetup.empty())
+//            LoadStaticData(fDefaultSetup);
 
         // Get a header and configdata!
@@ -592,5 +593,10 @@
         fIsDynamicOut = b;
     }
-
+/*
+    void SetDefaultSetup(const string &file)
+    {
+        fDefaultSetup = file;
+    }
+*/
     bool LoadStaticData(string name)
     {
@@ -799,5 +805,5 @@
 
         fStaticData.fTriggerSequence =
-            (d[0]<<10) | (d[1]<<5) || d[2];
+            (uint16_t(d[0])<<10) | (uint16_t(d[1])<<5) | uint16_t(d[2]);
 
         if (oldseq!=fStaticData.fTriggerSequence || oldset!=fStaticData.fGeneralSettings)
@@ -807,16 +813,13 @@
     }
 
-    bool SetTriggerCoincidence(uint16_t n, uint16_t win)
-    {
-        if (n==0 || n>FTM::StaticData::kMaxCoincidence ||
-            win>FTM::StaticData::kMaxWindow)
+    bool SetTriggerCoincidence(uint16_t n)
+    {
+        if (n==0 || n>FTM::StaticData::kMaxCoincidence)
             return false;
 
-        if (n  ==fStaticData.fCoincidencePhysics &&
-            win==fStaticData.fWindowPhysics)
+        if (n==fStaticData.fCoincidencePhysics)
             return true;
 
         fStaticData.fCoincidencePhysics = n;
-        fStaticData.fWindowPhysics      = win;
 
         CmdSendStatDat();
@@ -825,16 +828,43 @@
     }
 
-    bool SetCalibCoincidence(uint16_t n, uint16_t win)
-    {
-        if (n==0 || n>FTM::StaticData::kMaxCoincidence ||
-            win>FTM::StaticData::kMaxWindow)
+    bool SetTriggerWindow(uint16_t win)
+    {
+        if (win>FTM::StaticData::kMaxWindow)
             return false;
 
-        if (n  ==fStaticData.fCoincidenceCalib &&
-            win==fStaticData.fWindowCalib)
+        if (win==fStaticData.fWindowPhysics)
             return true;
 
+        fStaticData.fWindowPhysics = win;
+
+        CmdSendStatDat();
+
+        return true;
+    }
+
+    bool SetCalibCoincidence(uint16_t n)
+    {
+        if (n==0 || n>FTM::StaticData::kMaxCoincidence)
+            return false;
+
+        if (n==fStaticData.fCoincidenceCalib)
+            return true;
+
         fStaticData.fCoincidenceCalib = n;
-        fStaticData.fWindowCalib      = win;
+
+        CmdSendStatDat();
+
+        return true;
+    }
+
+    bool SetCalibWindow(uint16_t win)
+    {
+        if (win>FTM::StaticData::kMaxWindow)
+            return false;
+
+        if (win==fStaticData.fWindowCalib)
+            return true;
+
+        fStaticData.fWindowCalib = win;
 
         CmdSendStatDat();
@@ -1236,10 +1266,8 @@
     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]))
+        if (!CheckEventSize(evt.GetSize(), "SetTriggerCoincidence", 2))
+            return T::kSM_FatalError;
+
+        if (!fFTM.SetTriggerCoincidence(evt.GetUShort()))
             T::Warn("SetTriggerCoincidence -  Value out of range.");
 
@@ -1249,14 +1277,35 @@
     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]))
+        if (!CheckEventSize(evt.GetSize(), "SetCalibCoincidence", 2))
+            return T::kSM_FatalError;
+
+        if (!fFTM.SetCalibCoincidence(evt.GetUShort()))
             T::Warn("SetCalibCoincidence -  Value out of range.");
 
         return T::GetCurrentState();
     }
+
+    int SetTriggerWindow(const EventImp &evt)
+    {
+        if (!CheckEventSize(evt.GetSize(), "SetTriggerWindow", 2))
+            return T::kSM_FatalError;
+
+        if (!fFTM.SetTriggerWindow(evt.GetUShort()))
+            T::Warn("SetTriggerWindow -  Value out of range.");
+
+        return T::GetCurrentState();
+    }
+
+    int SetCalibWindow(const EventImp &evt)
+    {
+        if (!CheckEventSize(evt.GetSize(), "SetCalibWindow", 2))
+            return T::kSM_FatalError;
+
+        if (!fFTM.SetCalibWindow(evt.GetUShort()))
+            T::Warn("SetCalibWindow -  Value out of range.");
+
+        return T::GetCurrentState();
+    }
+
 
     int Enable(const EventImp &evt, FTM::StaticData::GeneralSettings type)
@@ -1467,13 +1516,21 @@
              "|LPext[int]:number of triggers of the external light pulser");
 
-        AddConfiguration("SET_TRIGGER_COINCIDENCE", "S:2", kStateIdle)
+        AddConfiguration("SET_TRIGGER_COINCIDENCE", "S:1", kStateIdle)
             (boost::bind(&StateMachineFTM::SetTriggerCoincidence, this, _1))
             ("Setup the coincidence condition for physcis triggers"
              "|N[int]:Number of requirered coincident triggers from sum-patches (1-40)");
 
-        AddConfiguration("SET_CALIBRATION_COINCIDENCE", "S:2", kStateIdle)
+        AddConfiguration("SET_TRIGGER_WINDOW", "S:1", kStateIdle)
+            (boost::bind(&StateMachineFTM::SetTriggerWindow, this, _1))
+            ("");
+
+        AddConfiguration("SET_CALIBRATION_COINCIDENCE", "S:1", kStateIdle)
             (boost::bind(&StateMachineFTM::SetCalibCoincidence, this, _1))
             ("Setup the coincidence condition for artificial (calibration) triggers"
              "|N[int]:Number of requirered coincident triggers from sum-patches (1-40)");
+
+        AddConfiguration("SET_CALIBRATION_WINDOW", "S:1", kStateIdle)
+            (boost::bind(&StateMachineFTM::SetCalibWindow, this, _1))
+            ("");
 
 
@@ -1549,4 +1606,6 @@
         fFTM.SetHexOutput(conf.Get<bool>("hex-out"));
         fFTM.SetDynamicOut(conf.Get<bool>("dynamic-out"));
+
+//        fFTM.SetDefaultSetup(conf.Get<string>("default-setup"));
 
         return true;
@@ -1654,8 +1713,9 @@
     po::options_description control("FTM control options");
     control.add_options()
-        ("addr,a",      var<string>("localhost:5000"),  "Network address of FTM")
-        ("quiet,q",     po_switch(), "Disable printing contents of all received messages (except dynamic data) in clear text.")
-        ("hex-out",     po_switch(), "Enable printing contents of all printed messages also as hex data.")
-        ("dynamic-out", po_switch(), "Enable printing received dynamic data.")
+        ("addr,a",        var<string>("localhost:5000"),  "Network address of FTM")
+        ("quiet,q",       po_switch(),   "Disable printing contents of all received messages (except dynamic data) in clear text.")
+        ("hex-out",       po_switch(),   "Enable printing contents of all printed messages also as hex data.")
+        ("dynamic-out",   po_switch(),   "Enable printing received dynamic data.")
+//        ("default-setup", var<string>(), "Binary file with static data loaded whenever a connection to the FTM was established.")
         ;
 
