Index: trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc	(revision 2516)
+++ trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc	(revision 2517)
@@ -11,66 +11,75 @@
 }
 
+bool MCeCoCom::InterpreteReport(TString &str)
+{
+    int y, m, d, h, min, s, ms, len;
+
+    int n=sscanf(str.Data(),
+                 "%02d %04d %02d %02d %02d %02d %02d %03d %n",
+                 &fCCStatus, &y, &m, &d, &h, &min, &s, &ms, &len);
+    if (n!=8)
+    {
+        cout << "Communication Problem: Wrong number of arguments" << endl;
+        fComStat = kComProblem;
+        return false;
+    }
+    str.Remove(0, len);
+
+    fT.SetTimer(y, m, d, h, min, s, ms/1000.);
+
+    // Remove the 30 tokens of the subsystem status
+    //  table 12.1 p59
+    for (int i=0; i<30; i++)
+        str.Remove(0, str.First(' ')+1);
+
+    // skip solar_irr_Wm2, wind_speed, UPS
+    float zd, az, dec, ra, temp, solar, wind, hum;
+    n=sscanf(str.Data(),
+             "%f %f %f %f %f %f %f %f %*f %*f %n",
+             &zd, &az, &dec, &ra, &temp, &solar, &wind, &hum, &len);
+    if (n!=8)
+    {
+        cout << "Communication Problem: Wrong number of arguments" << endl;
+        fComStat = kComProblem;
+        return false;
+    }
+    str.Remove(0, len);
+
+    if (str!=(TString)"OVER")
+    {
+        cout << "Communication Problem: Termination (OVER) too far away." << endl;
+        fComStat = kComProblem;
+        return false;
+    }
+
+    cout << "Zd/Az: " << zd << "/" << az << "   ";
+    cout << "Ra/Dec: " << ra << "/" << dec << "   ";
+    cout << "Temp: " << temp << "'C   ";
+    cout << "Hum: " << hum << "%   ";
+    cout << "SolRad: " << solar << "W/m²   ";
+    cout << "Wind: " << wind << "km/h" << endl;
+
+    fHumidity = hum;
+    fTemperature = temp;
+    fSolarRadiation = solar;
+    fWindSpeed = wind;
+
+    fComStat = kCmdReceived;
+    return true;
+}
+
 bool MCeCoCom::InterpreteStr(TString str)
 {
     const Ssiz_t tok  = str.First(' ');
-    const TString cmd = str(0, tok);
-    str.Remove(0, tok+1);
+    const TString cmd = tok<0 ? str : str(0, tok);
+    if (tok<0)
+        str = "";
+    else
+        str.Remove(0, tok+1);
 
     if (cmd==(TString)"CC-REPORT" && str.EndsWith("OVER"))
-    {
-        cout << cmd << ": " << str << endl;
-        int y, m, d, h, min, s, ms, len;
+        return InterpreteReport(str);
 
-        int n=sscanf(str.Data(),
-                     "%02d %04d %02d %02d %02d %02d %02d %03d %n",
-                     &fCCStatus, &y, &m, &d, &h, &min, &s, &ms, &len);
-        if (n!=8)
-        {
-            cout << "Communication Problem: Wrong number of arguments" << endl;
-            fComStat = kComProblem;
-            return false;
-        }
-        str.Remove(0, len+1);
-
-        fT.SetTimer(y, m, d, h, min, s, ms/1000.);
-
-        // Remove the 29 tokens of the subsystem status
-        //  table 12.1 p59
-        for (int i=0; i<29; i++)
-            str.Remove(0, str.First(' ')+1);
-
-        // skip solar_irr_Wm2, wind_speed, UPS
-		float zd, az, dec, ra, temp, hum;
-        n=sscanf(str.Data(),
-                 "%f %f %f %f %f %*f %*f %f %*f %n",
-                 &zd, &az, &dec, &ra, &temp, &hum, &len);
-        if (n!=6)
-        {
-            cout << "Communication Problem: Wrong number of arguments" << endl;
-            fComStat = kComProblem;
-            return false;
-        }
-        str.Remove(0, len);
-
-        if (str!=(TString)"OVER")
-        {
-            cout << "Communication Problem: Termination (OVER) not found." << endl;
-            fComStat = kComProblem;
-            return false;
-        }
-
-        cout << "Zd/Az: " << zd << "/" << az << "   ";
-        cout << "Ra/Dec: " << ra << "/" << dec << "   ";
-        cout << "Temp:  " << temp << "'C   ";
-        cout << "Hum: " << hum << "%" << endl;
-
-        fHumidity = hum;
-        fTemperature = temp;
-
-        fComStat = kCmdReceived;
-        return true;
-    }
-
-    const bool rc = InterpreteCmd(cmd, str);
+    const bool rc = InterpreteCmd(cmd, str.Strip(TString::kBoth));
     fComStat = rc ? kCmdReceived : kComProblem;
     return rc;
Index: trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h	(revision 2516)
+++ trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h	(revision 2517)
@@ -31,9 +31,12 @@
     ComStatus_t fComStat; // communication status
 
-    Float_t fHumidity;    // [%]
-    Float_t fTemperature; // degrees celsius
+    Float_t fHumidity;       // [%]
+    Float_t fTemperature;    // [deg] celsius
+    Float_t fWindSpeed;      // [km/h]
+    Float_t fSolarRadiation; // [W/m^2] IR-Radiation
 
     virtual bool InterpreteCmd(TString cmd, TString str);
 
+    bool InterpreteReport(TString &str);
     bool InterpreteStr(TString str);
 
Index: trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc	(revision 2516)
+++ trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc	(revision 2517)
@@ -5,31 +5,126 @@
 #include "coord.h"
 #include "Slalib.h"
+#include "MCosy.h"
 
 using namespace std;
 
+bool MDriveCom::ReadAngle(TString &str, Double_t &ret)
+{
+    Char_t  sgn;
+    Int_t   d, len;
+    UInt_t  m;
+    Float_t s;
+
+    // Skip whitespaces before %c and after %f
+    int n=sscanf(str.Data(), " %c %d %d %f %n", &sgn, &d, &m, &s, &len);
+
+    if (n!=4 || (sgn!='+' && sgn!='-'))
+        return false;
+
+    str.Remove(0, len);
+
+    ret = Slalib::Dms2Deg(d, m, s, sgn);
+    return true;
+}
+
+bool MDriveCom::ReadPosition(TString &str, Double_t &d1, Double_t &d2)
+{
+    if (!ReadAngle(str, d1))
+        return false;
+
+    if (!ReadAngle(str, d2))
+        return false;
+
+    return true;
+}
+
+bool MDriveCom::CommandRADEC(TString &str)
+{
+    Double_t ra, dec;
+    if (!ReadPosition(str, ra, dec))
+    {
+        cout << "ERROR - Reading position from RADEC" << endl;
+        return false;
+    }
+    if (!str.IsNull())
+    {
+        cout << "ERROR - Too many bytes in command RADEC" << endl;
+        return false;
+    }
+
+    cout << "CC-COMMAND: Track " << ra << "h " << dec << "deg '" << str << "'" << endl;
+
+    ra *= 15; // h -> deg
+
+    RaDec rd[2] = { RaDec(ra, dec), RaDec(ra, dec) };
+
+    cout << "MDriveCom - TRACK... start." << endl;
+    fQueue->PostMsg(WM_TRACK, &rd, sizeof(rd));
+    cout << "MDriveCom - TRACK... done." << endl;
+    return true;
+}
+
+bool MDriveCom::CommandZDAZ(TString &str)
+{
+    Double_t zd, az;
+    if (!ReadPosition(str, zd, az))
+    {
+        cout << "ERROR - Reading position from ZDAZ" << endl;
+        return false;
+    }
+
+    if (!str.IsNull())
+    {
+        cout << "ERROR - Too many bytes in command ZDAZ" << endl;
+        return false;
+    }
+
+    cout << "CC-COMMAND: Move " << zd << "deg " << az << "deg" << endl;
+
+    ZdAz za(zd, az);
+
+    cout << "MDriveCom - POSITION... start." << endl;
+    fQueue->PostMsg(WM_POSITION, &za, sizeof(za));
+    cout << "MDriveCom - POSITION... done." << endl;
+    return true;
+}
+
 bool MDriveCom::InterpreteCmd(TString cmd, TString str)
 {
-    if (cmd==(TString)"STOP!")
+    if (cmd==(TString)"WAIT" && str.IsNull())
     {
-        cout << "Stop! " << str << endl;
+        cout << "MDriveCom - WAIT... start." << endl;
+        fQueue->PostMsg(WM_WAIT);
+        cout << "MDriveCom - WAIT... done." << endl;
+        return true;
+    }
+
+    if (cmd==(TString)"STOP!" && str.IsNull())
+    {
+        cout << "MDriveCom - STOP!... start." << endl;
+        fQueue->PostMsg(WM_STOP);
+        cout << "MDriveCom - STOP!... done." << endl;
         return true;
     }
 
     if (cmd==(TString)"RADEC")
+        return CommandRADEC(str);
+
+    if (cmd==(TString)"ZDAZ")
+        return CommandZDAZ(str);
+
+    if (cmd==(TString)"PREPS")
     {
-        cout << "RaDec: " << str << endl;
+        cout << "Prepos: " << str << endl;
         return true;
     }
-    if (cmd==(TString)"ZDAZ")
+
+    if (cmd.IsNull() && str.IsNull())
     {
-        cout << "ZdAz: " << str << endl;
-        return true;
+        cout << "Empty command (single '\\n') received." << endl;
+        return false;
     }
-    if (cmd==(TString)"PREPS")
-    {
-        cout << "Preposs: " << str << endl;
-        return true;
-    }
-    cout << "Unknown Command: " << cmd << str << endl;
+
+    cout << "Unknown Command: '" << cmd << "':'" << str << "'" << endl;
     return false;
 }
Index: trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MDriveCom.h	(revision 2516)
+++ trunk/MagicSoft/Cosy/tcpip/MDriveCom.h	(revision 2517)
@@ -8,10 +8,19 @@
 class RaDec;
 class ZdAz;
+class MsgQueue;
 
 class MDriveCom : public MCeCoCom
 {
 private:
+    MsgQueue *fQueue;
+
+    bool ReadAngle(TString &str, Double_t &d);
+    bool ReadPosition(TString &str, Double_t &d1, Double_t &d2);
+
     bool InterpreteCmd(TString cmd, TString str);
     void Print(TString &str, Double_t deg) const;
+
+    bool CommandRADEC(TString &str);
+    bool CommandZDAZ(TString &str);
 
 public:
@@ -25,5 +34,5 @@
     };
 
-    MDriveCom(MLog &out=gLog) : MCeCoCom("DRIVE-REPORT", out) {}
+    MDriveCom(MsgQueue *q, MLog &out=gLog) : MCeCoCom("DRIVE-REPORT", out), fQueue(q) {}
 
     bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er);
Index: trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc	(revision 2516)
+++ trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc	(revision 2517)
@@ -40,10 +40,19 @@
 MTcpIpIO::~MTcpIpIO()
 {
-    cout << "Delete TxSocket..." << flush;
+    //
+    // Make sure, that no loop waiting for connection
+    // is running anymore!
+    //
+    Stop();
+
+    //
+    // Now delete all TCP/IP objects
+    //
+    cout << "Delete TxSocket " << fTxSocket << "..." << flush;
     delete fTxSocket;
     cout << "Done." << endl;
     if (fServSock)
     {
-        cout << "Delete ServSock..." << flush;
+        cout << "Delete ServSock " << fServSock << "..." << flush;
         delete fServSock;
         cout << "Done." << endl;
@@ -51,5 +60,5 @@
     if (fRxSocket)
     {
-        cout << "Delete RxSocket..." << flush;
+        cout << "Delete RxSocket " << fRxSocket << "..." << flush;
         delete fRxSocket;
         cout << "Done." << endl;
@@ -123,6 +132,10 @@
             if (fRxSocket==0)
                 cout << "Error: TServerSock::Accept" << endl;
-            usleep(1);
-        }
+            usleep(10);
+        }
+
+        // Can happen in case of HasStopFlag()
+        if (fRxSocket==(void*)-1)
+            fRxSocket=NULL;
 
         if (fRxSocket==NULL)
Index: trunk/MagicSoft/Cosy/tcpip/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/Makefile	(revision 2516)
+++ trunk/MagicSoft/Cosy/tcpip/Makefile	(revision 2517)
@@ -20,5 +20,5 @@
 # @endcode 
 
-INCLUDES = -I. -I../base -I../catalog
+INCLUDES = -I. -I../base -I../catalog -I../main -I../candrv -I../incl
 
 # @code 
