Index: trunk/FACT++/src/ftmctrl.cc
===================================================================
--- trunk/FACT++/src/ftmctrl.cc	(revision 10630)
+++ trunk/FACT++/src/ftmctrl.cc	(revision 10631)
@@ -19,4 +19,5 @@
 #include "Converter.h"
 
+#include "FACT.h"
 #include "tools.h"
 
@@ -29,5 +30,4 @@
 
 using namespace std;
-using namespace FTM;
 
 // ------------------------------------------------------------------------
@@ -91,5 +91,5 @@
             return;
 
-        if (fHeader.fType==kDynamicData && !fIsDynamicOut)
+        if (fHeader.fType==FTM::kDynamicData && !fIsDynamicOut)
             return;
 
@@ -153,21 +153,26 @@
 
         Out() << "Received: ";
-        Out() << "H=" << fCounter[kHeader] << "  ";
-        Out() << "S=" << fCounter[kStaticData] << "  ";
-        Out() << "D=" << fCounter[kDynamicData] << "  ";
-        Out() << "F=" << fCounter[kFtuList] << "  ";
-        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.");
-        }
-
+        Out() << "H=" << fCounter[FTM::kHeader] << "  ";
+        Out() << "S=" << fCounter[FTM::kStaticData] << "  ";
+        Out() << "D=" << fCounter[FTM::kDynamicData] << "  ";
+        Out() << "F=" << fCounter[FTM::kFtuList] << "  ";
+        Out() << "E=" << fCounter[FTM::kErrorList] << "  ";
+        Out() << "R=" << fCounter[FTM::kRegister] << endl;
+    }
+
+    bool CheckConsistency()
+    {
+        bool warn1 = false;
+        if (fStaticData.IsEnabled(FTM::StaticData::kPedestal) != (fStaticData.GetSequencePed()  >0) ||
+            fStaticData.IsEnabled(FTM::StaticData::kLPint)    != (fStaticData.GetSequenceLPint()>0) ||
+            fStaticData.IsEnabled(FTM::StaticData::kLPext)    != (fStaticData.GetSequenceLPext()>0))
+        {
+            warn1 = true;
+            fStaticData.Enable(FTM::StaticData::kPedestal, fStaticData.GetSequencePed()>0);
+            fStaticData.Enable(FTM::StaticData::kLPint,    fStaticData.GetSequenceLPint()>0);
+            fStaticData.Enable(FTM::StaticData::kLPext,    fStaticData.GetSequenceLPext()>0);
+        }
+
+        bool warn2 = false;
         const uint16_t ref = fStaticData[0].fPrescaling;
         for (int i=1; i<40; i++)
@@ -175,9 +180,15 @@
             if (fStaticData[i].fPrescaling != ref)
             {
-                Warn("Prescaling not consistent for all boards.");
-                break;
+                warn2 = true;
+                fStaticData[i].fPrescaling = ref;
             }
         }
 
+        if (warn1)
+            Warn("GeneralSettings not consistent with trigger sequence.");
+        if (warn2)
+            Warn("Prescaling not consistent for all boards.");
+
+        return !warn1 && !warn2;
     }
 
@@ -223,8 +234,8 @@
 
             // Check the data integrity
-            if (fHeader.fDelimiter!=kDelimiterStart)
+            if (fHeader.fDelimiter!=FTM::kDelimiterStart)
             {
                 stringstream str;
-                str << "Invalid header received: start delimiter wrong, received " << hex << fHeader.fDelimiter << " expected " << kDelimiterStart << ".";
+                str << "Invalid header received: start delimiter wrong, received " << hex << fHeader.fDelimiter << " expected " << FTM::kDelimiterStart << ".";
                 Error(str);
                 PostClose(false);
@@ -248,5 +259,5 @@
             }
 
-            if (++fCounter[kHeader]==1)
+            if (++fCounter[FTM::kHeader]==1)
                 UpdateFirstHeader();
 
@@ -257,9 +268,9 @@
             switch (fHeader.fType)
             {
-            case kStaticData:
-            case kDynamicData:
-            case kFtuList:
-            case kRegister:
-            case kErrorList:
+            case FTM::kStaticData:
+            case FTM::kDynamicData:
+            case FTM::kFtuList:
+            case FTM::kRegister:
+            case FTM::kErrorList:
                 // This is not very efficient because the space is reallocated
                 // maybe we can check if the capacity of the std::vector
@@ -286,5 +297,5 @@
             stringstream str;
             str << "Invalid data received: end delimiter wrong, received ";
-            str << hex << ntohs(fBuffer.back()) << " expected " << kDelimiterEnd << ".";
+            str << hex << ntohs(fBuffer.back()) << " expected " << FTM::kDelimiterEnd << ".";
             Error(str);
             PostClose(false);
@@ -307,24 +318,28 @@
             switch (fHeader.fType)
             {
-            case kFtuList:
+            case FTM::kFtuList:
                 fFtuList = fBuffer;
                 UpdateFtuList();
                 break;
 
-            case kStaticData:
+            case FTM::kStaticData:
                 fStaticData = fBuffer;
 
-                if (fCounter[kStaticData]==1)
-                    CheckConsistency();
+                if (fCounter[FTM::kStaticData]==1)
+                    if (!CheckConsistency())
+                    {
+                        CmdSendStatDat();
+                        break;
+                    }
 
                 UpdateStaticData();
                 break;
 
-            case kDynamicData:
+            case FTM::kDynamicData:
                 fDynamicData = fBuffer;
                 UpdateDynamicData();
                 break;
 
-            case kRegister:
+            case FTM::kRegister:
                 if (fIsVerbose)
                 {
@@ -335,5 +350,5 @@
                 break;
 
-            case kErrorList:
+            case FTM::kErrorList:
                 fError = fBuffer;
                 UpdateError();
@@ -478,78 +493,78 @@
     void CmdToggleLed()
     {
-        PostCmd(kCmdToggleLed);
+        PostCmd(FTM::kCmdToggleLed);
     }
 
     void CmdPing()
     {
-        PostCmd(kCmdPing);
+        PostCmd(FTM::kCmdPing);
     }
 
     void CmdReqDynDat()
     {
-        PostCmd(kCmdRead, kReadDynamicData);
+        PostCmd(FTM::kCmdRead, FTM::kReadDynamicData);
     }
 
     void CmdReqStatDat()
     {
-        PostCmd(kCmdRead, kReadStaticData);
+        PostCmd(FTM::kCmdRead, FTM::kReadStaticData);
     }
 
     void CmdSendStatDat()
     {
-        PostCmd(fStaticData.HtoN(), kCmdWrite, kWriteStaticData);
-
-        // Request the changed configuration to ensure the
-        // change is distributed in the network
-        //CmdReqStatDat();
-    }
-
-    void CmdStartRun()
-    {
-        PostCmd(kCmdStartRun, kStartRun);
-
-        // Update state information by requesting a new header
-        CmdGetRegister(0);
-    }
-
-    void CmdStopRun()
-    {
-        PostCmd(kCmdStopRun);
-
-        // Update state information by requesting a new header
-        CmdGetRegister(0);
-    }
-
-    void CmdTakeNevents(uint32_t n)
-    {
-        const boost::array<uint16_t, 2> data = {{ uint16_t(n>>16), uint16_t(n&0xffff) }};
-        PostCmd(data, kCmdStartRun, kTakeNevents);
-
-        // Update state information by requesting a new header
-        CmdGetRegister(0);
-    }
-
-    bool CmdSetRegister(uint16_t addr, uint16_t val)
-    {
-        if (addr>kMaxAddr)
-            return false;
-
-        const boost::array<uint16_t, 2> data = {{ addr, val }};
-        PostCmd(data, kCmdWrite, kWriteRegister);
+        PostCmd(fStaticData.HtoN(), FTM::kCmdWrite, FTM::kWriteStaticData);
 
         // Request the changed configuration to ensure the
         // change is distributed in the network
         CmdReqStatDat();
-
-        return true;
-    }
-
-    bool CmdGetRegister(uint16_t addr)
+    }
+
+    void CmdStartRun()
+    {
+        PostCmd(FTM::kCmdStartRun, FTM::kStartRun);
+
+        // Update state information by requesting a new header
+        CmdGetRegister(0);
+    }
+
+    void CmdStopRun()
+    {
+        PostCmd(FTM::kCmdStopRun);
+
+        // Update state information by requesting a new header
+        CmdGetRegister(0);
+    }
+
+    void CmdTakeNevents(uint32_t n)
+    {
+        const boost::array<uint16_t, 2> data = {{ uint16_t(n>>16), uint16_t(n&0xffff) }};
+        PostCmd(data, FTM::kCmdStartRun, FTM::kTakeNevents);
+
+        // Update state information by requesting a new header
+        CmdGetRegister(0);
+    }
+
+    bool CmdSetRegister(uint16_t addr, uint16_t val)
     {
         if (addr>kMaxAddr)
             return false;
 
+        const boost::array<uint16_t, 2> data = {{ addr, val }};
+        PostCmd(data, FTM::kCmdWrite, FTM::kWriteRegister);
+
+        // Request the changed configuration to ensure the
+        // change is distributed in the network
+        CmdReqStatDat();
+
+        return true;
+    }
+
+    bool CmdGetRegister(uint16_t addr)
+    {
+        if (addr>kMaxAddr)
+            return false;
+
         const boost::array<uint16_t, 1> data = {{ addr }};
-        PostCmd(data, kCmdRead, kReadRegister);
+        PostCmd(data, FTM::kCmdRead, FTM::kReadRegister);
 
         return true;
@@ -558,5 +573,5 @@
     bool CmdDisableReports(bool b)
     {
-        PostCmd(kCmdDisableReports, b ? uint16_t(0) : uint16_t(1));
+        PostCmd(FTM::kCmdDisableReports, b ? uint16_t(0) : uint16_t(1));
         return true;
     }
@@ -742,20 +757,24 @@
     bool SetTriggerInterval(uint32_t val)
     {
-        return SetVal(&fStaticData.fTriggerInterval, val, StaticData::kMaxTriggerInterval);
+        return SetVal(&fStaticData.fTriggerInterval, val,
+                      FTM::StaticData::kMaxTriggerInterval);
     }
 
     bool SetTriggerDelay(uint32_t val)
     {
-        return SetVal(&fStaticData.fDelayTrigger, val, StaticData::kMaxDelayTrigger);
+        return SetVal(&fStaticData.fDelayTrigger, val,
+                      FTM::StaticData::kMaxDelayTrigger);
     }
 
     bool SetTimeMarkerDelay(uint32_t val)
     {
-        return SetVal(&fStaticData.fDelayTimeMarker, val, StaticData::kMaxDelayTimeMarker);
+        return SetVal(&fStaticData.fDelayTimeMarker, val,
+                      FTM::StaticData::kMaxDelayTimeMarker);
     }
 
     bool SetDeadTime(uint32_t val)
     {
-        return SetVal(&fStaticData.fDeadTime, val, StaticData::kMaxDeadTime);
+        return SetVal(&fStaticData.fDeadTime, val,
+                      FTM::StaticData::kMaxDeadTime);
     }
 
@@ -770,11 +789,11 @@
         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)
+        fStaticData.Enable(FTM::StaticData::kPedestal, d[0]>0);
+        fStaticData.Enable(FTM::StaticData::kLPext,    d[1]>0);
+        fStaticData.Enable(FTM::StaticData::kLPint,    d[2]>0);
+
+        if (d[0]>FTM::StaticData::kMaxSequence ||
+            d[1]>FTM::StaticData::kMaxSequence ||
+            d[2]>FTM::StaticData::kMaxSequence)
             return false;
 
@@ -790,5 +809,6 @@
     bool SetTriggerCoincidence(uint16_t n, uint16_t win)
     {
-        if (n==0 || n>StaticData::kMaxCoincidence || win>StaticData::kMaxWindow)
+        if (n==0 || n>FTM::StaticData::kMaxCoincidence ||
+            win>FTM::StaticData::kMaxWindow)
             return false;
 
@@ -807,5 +827,6 @@
     bool SetCalibCoincidence(uint16_t n, uint16_t win)
     {
-        if (n==0 || n>StaticData::kMaxCoincidence || win>StaticData::kMaxWindow)
+        if (n==0 || n>FTM::StaticData::kMaxCoincidence ||
+            win>FTM::StaticData::kMaxWindow)
             return false;
 
@@ -855,5 +876,5 @@
         ConnectionFTM::UpdateFirstHeader();
 
-        const DimPassport data(fHeader);
+        const FTM::DimPassport data(fHeader);
         Update(fDimPassport, data);
     }
@@ -863,5 +884,5 @@
         ConnectionFTM::UpdateHeader();
 
-        const DimTriggerCounter data(fHeader);
+        const FTM::DimTriggerCounter data(fHeader);
         Update(fDimTriggerCounter, data);
     }
@@ -871,5 +892,5 @@
         ConnectionFTM::UpdateFtuList();
 
-        const DimFtuList data(fHeader, fFtuList);
+        const FTM::DimFtuList data(fHeader, fFtuList);
         Update(fDimFtuList, data);
     }
@@ -879,5 +900,5 @@
         ConnectionFTM::UpdateStaticData();
 
-        const DimStaticData data(fHeader, fStaticData);
+        const FTM::DimStaticData data(fHeader, fStaticData);
         Update(fDimStaticData, data);
     }
@@ -887,5 +908,5 @@
         ConnectionFTM::UpdateDynamicData();
 
-        const DimDynamicData data(fHeader, fDynamicData);
+        const FTM::DimDynamicData data(fHeader, fDynamicData);
         Update(fDimDynamicData, data);
     }
@@ -895,5 +916,5 @@
         ConnectionFTM::UpdateError();
 
-        const DimError data(fHeader, fError);
+        const FTM::DimError data(fHeader, fError);
         Update(fDimError, data);
     }
@@ -905,10 +926,10 @@
         const uint32_t counter[6] =
         {
-            fCounter[kHeader],
-            fCounter[kStaticData],
-            fCounter[kDynamicData],
-            fCounter[kFtuList],
-            fCounter[kErrorList],
-            fCounter[kRegister],
+            fCounter[FTM::kHeader],
+            fCounter[FTM::kStaticData],
+            fCounter[FTM::kDynamicData],
+            fCounter[FTM::kFtuList],
+            fCounter[FTM::kErrorList],
+            fCounter[FTM::kRegister],
         };
 
@@ -919,11 +940,11 @@
     ConnectionDimFTM(ba::io_service& ioservice, MessageImp &imp) :
         ConnectionFTM(ioservice, imp),
-        fDimPassport      ("FTM_CONTROL/PASSPORT",        "X:1;S:1",      NULL, 0, ""),
-        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, ""),
-        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, ""),
-        fDimCounter       ("FTM_CONTROL/COUNTER",         "I:6",          NULL, 0, "")
+        fDimPassport      ("FTM_CONTROL/PASSPORT",        "X:1;S:1", ""),
+        fDimTriggerCounter("FTM_CONTROL/TRIGGER_COUNTER", "X:1;S:1;S:1;S:2;S:1;S:1;S:21;S:1;S:1", ""),
+        fDimError         ("FTM_CONTROL/ERROR",           "X:1;S:1;S:28", ""),
+        fDimFtuList       ("FTM_CONTROL/FTU_LIST",        "X:1;X:1;S:1;C:4;X:40;C:40;C:40",  ""),
+        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", ""),
+        fDimDynamicData   ("FTM_CONTROL/DYNAMIC_DATA",    "X:1;X:1;F:4;I:160;I:40;S:40;S:40", ""),
+        fDimCounter       ("FTM_CONTROL/COUNTER",         "I:6", "")
     {
     }
@@ -1522,4 +1543,9 @@
     {
         SetEndpoint(conf.Get<string>("addr"));
+
+        fFTM.SetVerbose(conf.Get<bool>("verbose"));
+        fFTM.SetHexOutput(conf.Get<bool>("hex-out"));
+        fFTM.SetDynamicOut(conf.Get<bool>("dynamic-out"));
+
         return true;
     }
@@ -1626,5 +1652,8 @@
     po::options_description control("FTM control options");
     control.add_options()
-        ("addr",      var<string>("localhost:5000"),  "Network address of FTM")
+        ("addr,a",      var<string>("localhost:5000"),  "Network address of FTM")
+        ("verbose,v",   po_switch(),  "Enable 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.")
         ;
 
@@ -1655,51 +1684,28 @@
         "\n"
         "Usage: ftmctrl [-c type] [OPTIONS]\n"
-        "  or:  ftmctrl [OPTIONS]\n"
-        "\n"
-        "Options:\n"
-        "The following describes the available commandline options. "
-        "For further details on how command line option are parsed "
-        "and in which order which configuration sources are accessed "
-        "please refer to the class reference of the Configuration class.";
+        "  or:  ftmctrl [OPTIONS]\n";
     cout << endl;
-
 }
 
 void PrintHelp()
 {
+    /* Additional help text which is printed after the configuration
+     options goes here */
+
+    /*
+     cout << "bla bla bla" << endl << endl;
+     cout << endl;
+     cout << "Environment:" << endl;
+     cout << "environment" << endl;
+     cout << endl;
+     cout << "Examples:" << endl;
+     cout << "test exam" << endl;
+     cout << endl;
+     cout << "Files:" << endl;
+     cout << "files" << endl;
+     cout << endl;
+     */
 }
 
-/*
- The first line of the --version information is assumed to be in one
- of the following formats:
-
-   <version>
-   <program> <version>
-   {GNU,Free} <program> <version>
-   <program> ({GNU,Free} <package>) <version>
-   <program> - {GNU,Free} <package> <version>
-
- and separated from any copyright/author details by a blank line.
-
- Handle multi-line bug reporting sections of the form:
-
-   Report <program> bugs to <addr>
-   GNU <package> home page: <url>
-   ...
-*/
-void PrintVersion(const char *name)
-{
-    cout <<
-        name << " - "PACKAGE_STRING"\n"
-        "\n"
-        "Written by Thomas Bretz et al.\n"
-        "\n"
-        "Report bugs to <"PACKAGE_BUGREPORT">\n"
-        "Home page: "PACKAGE_URL"\n"
-        "\n"
-        "Copyright (C) 2011 by the FACT Collaboration.\n"
-        "This is free software; see the source for copying conditions.\n"
-        << endl;
-}
 /*
 string GetLocalIp()
@@ -1796,5 +1802,5 @@
     if (conf.HasVersion())
     {
-        PrintVersion(argv[0]);
+        FACT::PrintVersion(argv[0]);
         return -1;
     }
