Index: trunk/FACT++/src/drivectrl.cc
===================================================================
--- trunk/FACT++/src/drivectrl.cc	(revision 12308)
+++ trunk/FACT++/src/drivectrl.cc	(revision 12309)
@@ -55,16 +55,19 @@
     struct DimTPoint
     {
-        double fNominalAlt;
-        double fNominalAz;
-
-        double fCurrentAlt;
-        double fCurrentAz;
-
-        double fDevZd;
-        double fDevAz;
-
         double fRa;
         double fDec;
 
+        double fNominalZd;
+        double fNominalAz;
+
+        double fPointingZd;
+        double fPointingAz;
+
+        double fFeedbackZd;
+        double fFeedbackAz;
+
+        uint16_t fNumLeds;
+        uint16_t fNumRings;
+ 
         double fCenterX;
         double fCenterY;
@@ -75,11 +78,5 @@
         double fStarMag;
 
-        double fBrightness;
         double fRealMag;
-
-        uint16_t fNumLeds;
-        uint16_t fNumRings;
-        uint16_t fNumStars;
-        uint16_t fNumCorrelated;
 
     } __attribute__((__packed__));
@@ -131,5 +128,5 @@
     }
 
-    virtual void UpdateTPoint(const Time &, const Drive::DimTPoint &)
+    virtual void UpdateTPoint(const Time &, const Drive::DimTPoint &, const string &)
     {
     }
@@ -260,4 +257,9 @@
             const Time t2 = ReadTime(stream);
 
+            char type;
+            stream >> type;
+            if (type != 'T')
+                return;
+
             double az1, alt1, az2, alt2, ra, dec, dzd, daz;
             stream >> az1 >> alt1 >> az2 >> alt2 >> ra >> dec >> dzd >> daz;
@@ -281,12 +283,18 @@
             Drive::DimTPoint tpoint;
 
-            tpoint.fNominalAz  = az1;
-            tpoint.fNominalAlt = alt1;
-            tpoint.fCurrentAz  = az2;
-            tpoint.fCurrentAlt = alt2;
-            tpoint.fDevAz      = daz;
-            tpoint.fDevZd      = dzd;
             tpoint.fRa         = ra;
             tpoint.fDec        = dec;
+
+            tpoint.fNominalZd  = 90-alt1-dzd;
+            tpoint.fNominalAz  = 90-az1 +daz;
+
+            tpoint.fPointingZd = 90-alt1;
+            tpoint.fPointingAz = az1;
+ 
+            tpoint.fFeedbackZd = 90-alt2;
+            tpoint.fFeedbackAz = az2;
+
+            tpoint.fNumLeds    = nled;
+            tpoint.fNumRings   = nring;
 
             tpoint.fCenterX    = cx;
@@ -298,14 +306,7 @@
             tpoint.fStarMag    = smag;
 
-            tpoint.fBrightness = bright;
-
-            tpoint.fNumCorrelated = ncor;
-            tpoint.fNumLeds       = nled;
-            tpoint.fNumRings      = nring;
-            tpoint.fNumStars      = nstar;
-
-            tpoint.fRealMag = mag;
-
-            UpdteTPoint(t1, tpoint);
+            tpoint.fRealMag    = mag;
+
+            UpdateTPoint(t1, tpoint, name);
 
             return;
@@ -383,5 +384,5 @@
                 ra, dec, ha,
                 zd1, az1,
-                zd_err, az_err
+                zd_err/3600, az_err/3600
             }};
             UpdateTracking(Time(mjd), track);
@@ -533,16 +534,11 @@
     DimDescribedService fDimPointing;
     DimDescribedService fDimTracking;
-
-    template<size_t N>
-        void Update(DimDescribedService &svc, const Time &t, const array<double, N> &arr) const
-    {
-        svc.setData(arr);
-        svc.Update(t);
-    }
+    DimDescribedService fDimTPoint;
 
     virtual void UpdatePointing(const Time &t,
                                 const array<double, 2> &arr)
     {
-        Update(fDimPointing, t, arr);
+        fDimPointing.setData(arr);
+        fDimPointing.Update(t);
     }
 
@@ -550,5 +546,17 @@
                                 const array<double, 7> &arr)
     {
-        Update(fDimTracking, t, arr);
+        fDimTracking.setData(arr);
+        fDimTracking.Update(t);
+    }
+    virtual void UpdateTPoint(const Time &t,
+                              const Drive::DimTPoint &data,
+                              const string &name)
+    {
+        vector<char> dim(sizeof(data)+name.length()+1);
+        memcpy(dim.data(), &data, sizeof(data));
+        memcpy(dim.data()+sizeof(data), name.c_str(), name.length()+1);
+
+        fDimTPoint.setData(dim);
+        fDimTPoint.Update(t);
     }
 
@@ -556,6 +564,34 @@
     ConnectionDimDrive(ba::io_service& ioservice, MessageImp &imp) :
         ConnectionDrive(ioservice, imp),
-        fDimPointing("FTM_CONTROL/POINTING_POSITION", "D:2", ""),
-        fDimTracking("FTM_CONTROL/TRACKING_POSITION", "D:7", "")
+        fDimPointing("DRIVE_CONTROL/POINTING_POSITION", "D:1;D:1",
+                     "|Zd[deg]:Zenith distance (encoder readout)"
+                     "|Az[deg]:Azimuth angle (encoder readout)"),
+        fDimTracking("DRIVE_CONTROL/TRACKING_POSITION", "D:1;D:1;D:1;D:1;D:1;D:1;D:1",
+                     "|Ra[h]:Command right ascension"
+                     "|Dec[deg]:Command declination"
+                     "|Ha[h]:Corresponding hour angle"
+                     "|Zd[deg]:Nominal zenith distance"
+                     "|Az[deg]:Nominal azimuth angle"
+                     "|dZd[deg]:Control deviation Zd"
+                     "|dAz[deg]:Control deviation Az"),
+        fDimTPoint("DRIVE_CONTROL/TPOINT", "D:1;D:1;D:1;D:1;D:1;D:1;D:1;D:1;S:1;D:1;D:1;D:1;D:1;D:1;D:1;D:1;C",
+                   "|Ra[h]:Command right ascension"
+                   "|Dec[deg]:Command declination"
+                   "|Zd_nom[deg]:Nominal zenith distance"
+                   "|Az_nom[deg]:Nominal azimuth angle"
+                   "|Zd_cur[deg]:Current zenith distance (calculated from image)"
+                   "|Az_cur[deg]:Current azimuth angle (calculated from image)"
+                   "|Zd_enc[deg]:Feedback zenith axis (from encoder)"
+                   "|Az_enc[deg]:Feedback azimuth angle (from encoder)"
+                   "|N_leds[cnt]:Number of detected LEDs"
+                   "|N_rings[cnt]:Number of rings used to calculate the camera center"
+                   "|Xc[pix]:X position of center in CCD camera frame"
+                   "|Yc[pix]:Y position of center in CCD camera frame"
+                   "|Ic[au]:Average intensity (LED intensity weighted with their frequency of occurance in the calculation)"
+                   "|Xs[pix]:X position of start in CCD camera frame"
+                   "|Ys[pix]:Y position of star in CCD camera frame"
+                   "|Ms[mag]:Artifical magnitude of star (calculated form image))"
+                   "|Mc[mag]:Catalog magnitude of star")
+
     {
     }
@@ -746,17 +782,17 @@
         // State names
         AddStateName(kStateDisconnected, "Disconnected",
-                     "");
+                     "No connection to cosy");
 
         AddStateName(kStateConnected, "Connected",
-                     "");
+                     "Cosy connected, drive stopped");
 
         AddStateName(kStateArmed, "Armed",
-                     "");
+                     "Cosy armed, drive stopped");
 
         AddStateName(kStateMoving, "Moving",
-                     "");
+                     "Telescope moving");
 
         AddStateName(kStateTracking, "Tracking",
-                     "");
+                     "Telescope tracking");
 
         // kStateIdle
@@ -787,49 +823,51 @@
         T::AddEvent("MOVE_TO", "D:2", kStateArmed)  // ->ZDAZ
             (bind(&StateMachineDrive::SendCoordinates, this, placeholders::_1, kPoint))
-            (""
-             "|zd[deg]:"
-             "|az[deg]:");
+            ("Move the telescope to the given local coordinates"
+             "|Zd[deg]:Zenith distance"
+             "|Az[deg]:Azimuth");
 
         T::AddEvent("TRACK", "D:2", kStateArmed)   // ->RADEC/GRB
             (bind(&StateMachineDrive::SendCoordinates, this, placeholders::_1, kTrackSlow))
-            (""
-             "|ra[h]:"
-             "|dec[deg]:");
+            ("Move the telescope to the given sky coordinates and start tracking them"
+             "|Ra[h]:Right ascension"
+             "|Dec[deg]:Declination");
 
         T::AddEvent("MOON", kStateArmed)
             (bind(&StateMachineDrive::SendCommand, this, "MOON 0 0"))
-            ("");
+            ("Start tracking the moon");
         T::AddEvent("VENUS", kStateArmed)
             (bind(&StateMachineDrive::SendCommand, this, "CELEST 2 0 0"))
-            ("");
+            ("Start tracking Venus");
         T::AddEvent("MARS", kStateArmed)
             (bind(&StateMachineDrive::SendCommand, this, "CELEST 4 0 0"))
-            ("");
+            ("Start tracking Mars");
         T::AddEvent("JUPITER", kStateArmed)
             (bind(&StateMachineDrive::SendCommand, this, "CELEST 5 0 0"))
-            ("");
+            ("Start tracking Jupiter");
         T::AddEvent("SATURN", kStateArmed)
             (bind(&StateMachineDrive::SendCommand, this, "CELEST 6 0 0"))
-            ("");
-
-        T::AddEvent("TPOINT")
+            ("Start tracking Saturn");
+
+        T::AddEvent("TAKE_TPOINT")
             (bind(&StateMachineDrive::SendCommand, this, "TPOIN FACT 0"))
-            ("");
+            ("Take a TPoint");
 
         T::AddEvent("SET_LED_BRIGHTNESS", "I:2")
             (bind(&StateMachineDrive::SetLedBrightness, this, placeholders::_1))
-            ("");
+            ("Set the LED brightness of the top and bottom leds"
+             "|top[au]:Allowed range 0-32767 for top LEDs"
+             "|bot[au]:Allowed range 0-32767 for bottom LEDs");
 
         T::AddEvent("LEDS_OFF")
             (bind(&StateMachineDrive::SendCommand, this, "LEDS 0 0"))
-            ("");
+            ("Switch off TPoint LEDs");
 
         T::AddEvent("STOP")
             (bind(&StateMachineDrive::SendCommand, this, "STOP!"))
-            ("");
-
-        T::AddEvent("ARM", kStateConnected)
-            (bind(&StateMachineDrive::SendCommand, this, "ARM lock"))
-            ("");
+            ("Stop any kind of movement.");
+
+//        T::AddEvent("ARM", kStateConnected)
+//            (bind(&StateMachineDrive::SendCommand, this, "ARM lock"))
+//            ("");
 
 
@@ -872,88 +910,9 @@
 #include "Main.h"
 
-/*
-void RunThread(StateMachineImp *io_service)
-{
-    // This is necessary so that the StateMachien Thread can signal the
-    // Readline to exit
-    io_service->Run();
-    Readline::Stop();
-}
-*/
-/*
-template<class S, class T>
-int RunDim(Configuration &conf)
-{
-    WindowLog wout;
-
-    ReadlineColor::PrintBootMsg(wout, conf.GetName(), false);
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    // Start io_service.Run to use the StateMachineImp::Run() loop
-    // Start io_service.run to only use the commandHandler command detaching
-    StateMachineDrive<S, T> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    io_service.Run();
-
-    return 0;
-}
-*/
 
 template<class T, class S, class R>
 int RunShell(Configuration &conf)
 {
-    return Main<T, StateMachineDrive<S, R>>(conf);
-/*
-    static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
-
-    WindowLog &win  = shell.GetStreamIn();
-    WindowLog &wout = shell.GetStreamOut();
-
-    if (conf.Has("log"))
-        if (!wout.OpenLogFile(conf.Get<string>("log")))
-            win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
-
-    StateMachineDrive<S, R> io_service(wout);
-    if (!io_service.EvalConfiguration(conf))
-        return -1;
-
-    shell.SetReceiver(io_service);
-
-    boost::thread t(bind(RunThread, &io_service));
-    // boost::thread t(bind(&StateMachineDrive<S>::Run, &io_service));
-
-    if (conf.Has("cmd"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("cmd");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.ProcessLine(*it);
-    }
-
-    if (conf.Has("exec"))
-    {
-        const vector<string> v = conf.Get<vector<string>>("exec");
-        for (vector<string>::const_iterator it=v.begin(); it!=v.end(); it++)
-            shell.Execute(*it);
-    }
-
-    if (conf.Get<bool>("quit"))
-        shell.Stop();
-
-    shell.Run();                 // Run the shell
-    io_service.Stop();           // Signal Loop-thread to stop
-    // io_service.Close();       // Obsolete, done by the destructor
-
-    // Wait until the StateMachine has finished its thread
-    // before returning and destroying the dim objects which might
-    // still be in use.
-    t.join();
-
-    return 0;
-    */
+    return Main::execute<T, StateMachineDrive<S, R>>(conf);
 }
 
@@ -964,5 +923,5 @@
         ("no-dim,d",  po_switch(),    "Disable dim services")
         ("addr,a",  var<string>("localhost:7404"),  "Network address of FTM")
-        ("quiet,q", po_bool(),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
+        ("quiet,q", po_bool(true),  "Disable printing contents of all received messages (except dynamic data) in clear text.")
         ;
 
@@ -996,4 +955,6 @@
 void PrintHelp()
 {
+//    Main::PrintHelp<StateMachineFTM<StateMachine, ConnectionFTM>>();
+
     /* Additional help text which is printed after the configuration
      options goes here */
