Index: trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc	(revision 2379)
+++ trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc	(revision 2384)
@@ -41,5 +41,5 @@
 
         // skip solar_irr_Wm2, wind_speed, UPS
-        float zd, az, dec, ra, temp, hum;
+		float zd, az, dec, ra, temp, hum;
         n=sscanf(str.Data(),
                  "%f %f %f %f %f %*f %*f %f %*f %n",
Index: trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h	(revision 2379)
+++ trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h	(revision 2384)
@@ -34,12 +34,12 @@
 
     bool InterpreteStr(TString str);
-    bool Send(const char *str);
 
 public:
-    MCeCoCom::MCeCoCom(const char *cmd)
-        : MTcpIpIO(), fCommand(cmd), fStatus(0), fComStat(kNoCmdReceived)
+    MCeCoCom::MCeCoCom(const char *cmd, MLog &out=gLog)
+        : MTcpIpIO(out), fCommand(cmd), fStatus(0), fComStat(kNoCmdReceived)
     {
     }
 
+    bool Send(const char *str);
     void SetStatus(Byte_t s) { fStatus=s; }
 };
Index: trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc	(revision 2379)
+++ trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc	(revision 2384)
@@ -2,4 +2,7 @@
 
 #include <iostream>
+
+#include "coord.h"
+#include "Slalib.h"
 
 using namespace std;
@@ -31,2 +34,49 @@
     return false;
 }
+
+void MDriveCom::Print(TString &str, Double_t deg) const
+{
+    Char_t sgn;
+    UShort_t d, m, s;
+
+    Slalib::Deg2Dms(deg, sgn, d, m, s);
+
+    str += Form("%c %03d %02d %03d ", sgn, d, m, s);
+}
+
+bool MDriveCom::SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er)
+{
+    // so [rad]
+    // is [deg]
+    // er [rad]
+
+    so *= kRad2Deg;
+    er *= kRad2Deg;
+
+    // Set status flag
+    if (stat&kError)
+        SetStatus(0);
+    if (stat&kStopped)
+        SetStatus(1);
+    if (stat&kStopping || stat&kMoving)
+        SetStatus(3);
+    if (stat&kTracking)
+        SetStatus(4);
+
+    Timer t;
+    t.Now();
+
+    TString str;
+    Print(str, rd.Ra());    // Ra
+    Print(str, rd.Dec());   // Dec
+    Print(str, 0);          // HA
+    str += Form("%12.6f ", t.GetMjd()); // mjd
+    Print(str, so.Zd());
+    Print(str, so.Az());
+    Print(str, is.Zd());
+    Print(str, is.Az());
+    str += Form("%08.3f ", er.Zd());
+    str += Form("%08.3f", er.Az());
+
+    return Send(str);
+}
Index: trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MDriveCom.h	(revision 2379)
+++ trunk/MagicSoft/Cosy/tcpip/MDriveCom.h	(revision 2384)
@@ -6,11 +6,26 @@
 #endif
 
+class RaDec;
+class ZdAz;
+
 class MDriveCom : public MCeCoCom
 {
 private:
     bool InterpreteCmd(TString cmd, TString str);
+    void Print(TString &str, Double_t deg) const;
 
 public:
-    MDriveCom() : MCeCoCom("DRIVE-REPORT") {}
+    enum
+    {
+        kError    = 0x01,
+        kMoving   = 0x02,
+        kTracking = 0x04,
+        kStopping = 0x08,
+        kStopped  = 0x10
+    };
+
+    MDriveCom(MLog &out=gLog) : MCeCoCom("DRIVE-REPORT", out) {}
+
+    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 2379)
+++ trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc	(revision 2384)
@@ -31,5 +31,5 @@
      */
 
-MTcpIpIO::MTcpIpIO() : MThread(false), fRxSocket(NULL), fServSock(NULL)
+MTcpIpIO::MTcpIpIO(MLog &out) : MThread(false), Log(out), fRxSocket(NULL), fServSock(NULL)
 {
     fTxSocket = new TSocket("ceco", 7304);
@@ -38,5 +38,19 @@
 MTcpIpIO::~MTcpIpIO()
 {
+    cout << "Delete TxSocket..." << flush;
     delete fTxSocket;
+    cout << "Done." << endl;
+    if (fServSock)
+    {
+        cout << "Delete ServSock..." << flush;
+        delete fServSock;
+        cout << "Done." << endl;
+    }
+    if (fRxSocket)
+    {
+        cout << "Delete RxSocket..." << flush;
+        delete fRxSocket;
+        cout << "Done." << endl;
+    }
 }
 
@@ -68,4 +82,11 @@
 }
 
+void MTcpIpIO::Clear()
+{
+    char c;
+    while (fRxSocket->RecvRaw(&c, 1)>0 && !HasStopFlag())
+        usleep(1);
+}
+
 void *MTcpIpIO::Thread()
 {
@@ -87,4 +108,5 @@
             }
             delete fServSock;
+            fServSock=NULL;
             usleep(5000000);
             continue;
@@ -105,4 +127,5 @@
         {
             delete fServSock;
+            fServSock=NULL;
             continue;
         }
@@ -113,4 +136,6 @@
             delete fServSock;
             delete fRxSocket;
+            fServSock = NULL;
+            fRxSocket = NULL;
             continue;
         }
@@ -119,4 +144,6 @@
 
         fRxSocket->SetOption(kNoBlock, 1);
+
+        Clear();
 
         TString str;
@@ -160,4 +187,6 @@
         delete fServSock;
         delete fRxSocket;
+        fServSock = NULL;
+        fRxSocket = NULL;
     }
 
Index: trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h	(revision 2379)
+++ trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h	(revision 2384)
@@ -5,4 +5,7 @@
 #include "MThread.h"
 #endif
+#ifndef COSY_Log
+#include "log.h"
+#endif
 
 class TString;
@@ -10,5 +13,5 @@
 class TServerSocket;
 
-class MTcpIpIO : public MThread
+class MTcpIpIO : public MThread, public Log
 {
 private:
@@ -17,6 +20,8 @@
     TServerSocket *fServSock;
 
+    void Clear();
+
 public:
-    MTcpIpIO();
+    MTcpIpIO(MLog &out=gLog);
     ~MTcpIpIO();
 
Index: trunk/MagicSoft/Cosy/tcpip/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/Makefile	(revision 2379)
+++ trunk/MagicSoft/Cosy/tcpip/Makefile	(revision 2384)
@@ -20,5 +20,5 @@
 # @endcode 
 
-INCLUDES = -I. -I../base
+INCLUDES = -I. -I../base -I../catalog
 
 # @code 
