Index: /trunk/MagicSoft/Cosy/Makefile
===================================================================
--- /trunk/MagicSoft/Cosy/Makefile	(revision 2383)
+++ /trunk/MagicSoft/Cosy/Makefile	(revision 2384)
@@ -39,4 +39,5 @@
 SUBDIRS = \
         main     \
+        tcpip    \
         gui      \
         catalog  \
@@ -114,4 +115,7 @@
 	@cd videodev; make mrproper; cd ..
 	@echo "cd .."
+	@echo "cd tcpip"
+	@cd tcpip; make mrproper; cd ..
+	@echo "cd .."
 	@echo "cd catalog"
 	@cd catalog; make mrproper; cd ..
Index: /trunk/MagicSoft/Cosy/base/log.h
===================================================================
--- /trunk/MagicSoft/Cosy/base/log.h	(revision 2383)
+++ /trunk/MagicSoft/Cosy/base/log.h	(revision 2384)
@@ -1,8 +1,10 @@
-#ifndef LOG_H
-#define LOG_H
+#ifndef COSY_Log
+#define COSY_Log
 
 #include <ostream.h>
 
+#ifndef MARS_MLog
 #include "MLog.h"
+#endif
 
 //#ifndef __CINT__
Index: /trunk/MagicSoft/Cosy/base/timer.h
===================================================================
--- /trunk/MagicSoft/Cosy/base/timer.h	(revision 2383)
+++ /trunk/MagicSoft/Cosy/base/timer.h	(revision 2384)
@@ -10,16 +10,16 @@
     friend ostream &operator<<(ostream &out, Timer &t);
 private:
-    double fMs;
-    double fDiv;
+    double fMs;  // Microsec in units of sec as returned by gettimeofday
+    int fSecs;   // Seconds as returned by gettimeofday
 
-    int fSec;
-    int fSecs;
-    int fMin;
-    int fHor;
-    int fDay;
-    int fMon;
-    int fYea;
+    int fSec;    // Sec of time
+    int fMin;    // Min of time
+    int fHor;    // Hor of time
+    int fDay;    // Day of time
+    int fMon;    // Mon of time
+    int fYea;    // Yea of time
 
-    double fMjd;
+    double fDiv; // Division of day
+    double fMjd; // MJD
 
     char fDateStr[30];
@@ -28,5 +28,7 @@
 
 public:
-    Timer() : fMs(0), fSec(0), fSecs(0), fMin(0), fHor(0), fDay(0), fMon(0), fYea(0), fMjd(0) {}
+    Timer(int d, int m, int y, int h, int min, int s, double ms)
+        : fMs(ms), fSecs(0), fSec(s), fMin(m), fHor(h), fDay(d), fMon(m), fYea(y), fDiv(0), fMjd(0) {}
+    Timer() : fMs(0), fSecs(0), fSec(0), fMin(0), fHor(0), fDay(0), fMon(0), fYea(0), fDiv(0), fMjd(0) {}
     Timer(double t);
     Timer(struct timeval *tv);
@@ -35,4 +37,14 @@
     void SetTimer(int tv_sec, double tv_usec);
     void SetTimer(const struct timeval *tv);
+    void SetTimer(int y, int m, int d, int h, int min, int s, double ms)
+    {
+        fMs = ms;
+        fSec = s;
+        fMin = min;
+        fHor = h;
+        fDay = d;
+        fMon = m;
+        fYea = y;
+    }
 
     void GetTimeval(struct timeval *tv) const;
@@ -52,4 +64,6 @@
     int M() const { return fMin; }
     int S() const { return fSec; }
+    int MilliSec() const { return (int)(fMs*1000); }
+    double MicroSec() const { return fMs; }
 
     const char *GetTimeStr();
Index: /trunk/MagicSoft/Cosy/cosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/cosy.cc	(revision 2383)
+++ /trunk/MagicSoft/Cosy/cosy.cc	(revision 2384)
@@ -15,5 +15,6 @@
 #include "MStarguider.h"
 
-#define EXPERT
+//#define EXPERT
+#define HAVE_CAMERA
 
 #define clog(txt) \
@@ -100,4 +101,5 @@
 
     clog("- Starting Camera.");
+#ifdef HAVE_CAMERA
     MStarguider *client=new MStarguider(MObservatory::kMagic1);
     Camera *cam = new Camera(*client);
@@ -106,5 +108,5 @@
     cosy->SetStarguider(client);
     client->SetCosy(cosy);
-
+#endif
     clog("- Starting mainloop.");
 #ifndef EXPERT
@@ -112,5 +114,5 @@
 #endif
     app->Run(kTRUE);
-
+#ifdef HAVE_CAMERA
     client->SetCosy(NULL);
     cosy->SetStarguider(NULL);
@@ -120,5 +122,5 @@
     delete cam;
     delete client;
-
+#endif
     clog("- Stopping cosy.");
     cosy->Stop();
Index: /trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 2383)
+++ /trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 2384)
@@ -26,4 +26,5 @@
 #include "MCosy.h"
 #include "MGList.h"
+#include "MDriveCom.h"
 #include "MGAccuracy.h"
 #include "MGCoordinates.h"
@@ -34,5 +35,6 @@
 
 #undef DEBUG
-#define EXPERT
+//#define EXPERT
+//#define HAS_DEMO
 
 ClassImp(MGCosy);
@@ -41,4 +43,5 @@
 #define IDM_TEXT   2
 #define IDM_ASPECT 3
+
 
 enum
@@ -386,5 +389,7 @@
     TGCompositeFrame *tf6 = fTab->AddTab("Gear");
 #endif
-    /*TGCompositeFrame *tf3 =*/// fTab->AddTab("Demo");
+#ifdef HAS_DEMO
+    /*TGCompositeFrame *tf3 =*/ fTab->AddTab("Demo");
+#endif
 
     fCZdAz = new MGCoordinates(tf1, kETypeZdAz);
@@ -984,5 +989,5 @@
 void MGCosy::UpdateZdAz(ZdAz &soll)
 {
-    soll *= 360/2/TMath::Pi();
+    soll *= kRad2Deg;
 
     static Int_t zd=~0;
@@ -1055,19 +1060,13 @@
     UpdateZdAz(soll);
 
-#define kError     0x01
-#define kMoving    0x02
-#define kTracking  0x04
-#define kStopping  0x08
-#define kStopped   0x10
-
-    EnableLabel(fError,    stat&kError);
-    EnableLabel(fMoving,   stat&kMoving);
-    EnableLabel(fTracking, stat&kTracking);
-    EnableLabel(fStopping, stat&kStopping);
-    EnableLabel(fStopped,  stat&kStopped);
-    EnableLabel(fRaSoll,   stat&kTracking);
-    EnableLabel(fDecSoll,  stat&kTracking);
-    EnableLabel(fZdSoll,   stat&kMoving);
-    EnableLabel(fAzSoll,   stat&kMoving);
+    EnableLabel(fError,    stat&MDriveCom::kError);
+    EnableLabel(fMoving,   stat&MDriveCom::kMoving);
+    EnableLabel(fTracking, stat&MDriveCom::kTracking);
+    EnableLabel(fStopping, stat&MDriveCom::kStopping);
+    EnableLabel(fStopped,  stat&MDriveCom::kStopped);
+    EnableLabel(fRaSoll,   stat&MDriveCom::kTracking);
+    EnableLabel(fDecSoll,  stat&MDriveCom::kTracking);
+    EnableLabel(fZdSoll,   stat&MDriveCom::kMoving);
+    EnableLabel(fAzSoll,   stat&MDriveCom::kMoving);
 
     SetLabelColor(fAvailMac1, stat2&0x01);
@@ -1078,5 +1077,5 @@
     SetLabelColor(fAvailSe3,  stat2&0x20);
 
-    if (stat&kTracking)
+    if (stat&MDriveCom::kTracking)
     {
         fAccuracy->Update(pos, acc);
@@ -1187,5 +1186,6 @@
 // ************************** For demo purpose **********************
 //
-/*
+#ifdef HAS_DEMO
+
 #include <TRandom.h>
 class MDemo : public MThread
@@ -1200,30 +1200,48 @@
     void SetQueue(MsgQueue *q) { fQueue = q; }
 
+    bool Wait(int s, int m)
+    {
+        int i = 0;
+        while (!HasStopFlag() && i++<m)
+            usleep(s);
+        if (HasStopFlag())
+            return false;
+        return true;
+    }
+
+    bool Move(float zd, float az, int s, int m)
+    {
+        ZdAz dest1(zd, az);
+        fQueue->PostMsg(WM_POSITION1, &dest1, sizeof(dest1));
+        return Wait(s, m); // 30s?
+    }
+
     virtual void *Thread()
     {
-        while (1)
+        if (!Move(90, -65, 1000000, 27))
+            return NULL;
+
+        Int_t i=1;
+        while (i-->0)
         {
             Timer tm;
             tm.Now();
 
-            //fQueue->PostMsg(WM_STOP, 0, 0);
-
-            ZdAz dest1((float)fRand.Integer(120)-60., 0);//fRand.Integer(25)+90);
-
-            cout << "Demo: Zd=" << dest1.Zd() << "° Az=" << dest1.Az() << "°" << endl;
-
-            fQueue->PostMsg(WM_POSITION, &dest1, sizeof(dest1));
-
-            int i = 0;
-            while (!HasStopFlag() && i++<5)  // 30s
-                usleep(1000000);
-            if (HasStopFlag())
+            if (!Move(75, -80, 1000000, 13))
                 break;
-
-            //ZdAz dest2(5, 30);
-            //fQueue->PostMsg(WM_POSITION, &dest2, sizeof(dest2));
-            //if (HasStopFlag())
-            //    break;
+            if (!Move(60, -65, 1000000, 13))
+                break;
+            if (!Move(75, -50, 1000000, 13))
+                break;
+            if (!Move(90, -65, 1000000, 13))
+                break;
         }
+        if (!Move(60, -65, 1000000, 17))
+            return NULL;
+        if (!Move(90, -65, 1000000, 19))
+            return NULL;
+        if (!Move(90, -10, 1000000, 28))
+            return NULL;
+
         cout << "Demo Thread: done." << endl;
         return NULL;
@@ -1248,5 +1266,6 @@
     demo.Stop();
 }
-*/
+#endif //HAS_DEMO
+
 /*
 void MGCosy::StartCalib()
@@ -1344,9 +1363,9 @@
                     fQueue->Proc(WM_GEAR, (void*)1);
                     return kTRUE;
-                    /*
+#ifdef HAS_DEMO
                 case 5:
                     StartDemo();
                     return kTRUE;
-                    */
+#endif
                 }
                 return kTRUE;
@@ -1354,5 +1373,7 @@
             case kPB_STOP:
                 cout << "Sending stop movement msg." << endl;
-                //StopDemo();
+#ifdef HAS_DEMO
+                StopDemo();
+#endif
                 fQueue->PostMsg(WM_STOP, 0, 0);
                 if (fTab->GetCurrent()==3)
Index: /trunk/MagicSoft/Cosy/gui/MGImage.cc
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGImage.cc	(revision 2383)
+++ /trunk/MagicSoft/Cosy/gui/MGImage.cc	(revision 2384)
@@ -52,4 +52,6 @@
     fDefGC  = gVirtualX->CreateGC(fId, 0);
     fImage  = (XImage*)gVirtualX->CreateImage(fWidth, fHeight);
+
+    cout << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
 }
 
@@ -82,14 +84,7 @@
 }
 
-void MGImage::DrawImg(const byte *buffer)
+void MGImage::DrawImg32(char *d, char *s, char *e)
 {
-    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
-        return;
-
-    char *d = fImage->data;
-    char *e = (char*)(buffer+fWidth*fHeight);
-    char *s = (char*)buffer;
-
-    // FIXME: This loop depends on the screen color depth
+    // d=destination, s=source, e=end
     while (s<e)
     {
@@ -99,33 +94,9 @@
         d++;
     }
-
-    SetBit(kNeedRedraw);
-
-    pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
 }
 
-void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
+void MGImage::DrawColImg32(char *d, char *s1, char *s2, char *e)
 {
-    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
-        return;
-
-    char *d  = fImage->data;
-    char *e  = (char*)(gbuf+fWidth*fHeight);
-    char *s1 = (char*)gbuf;
-    char *s2 = (char*)cbuf;
-
-    // FROM libAfterImage:
-    // -------------------
-    //#define ALPHA_TRANSPARENT      	0x00
-    //#define ALPHA_SEMI_TRANSPARENT 	0x7F
-    //#define ALPHA_SOLID            	0xFF
-    // * Lowermost 8 bits - Blue channel
-    // * bits 8 to 15     - Green channel
-    // * bits 16 to 23    - Red channel
-    // * bits 24 to 31    - Alpha channel
-    //#define ARGB32_White    		0xFFFFFFFF
-    //#define ARGB32_Black    		0xFF000000
-
-    // FIXME: This loop depends on the screen color depth
+    // d=destination, s1=source1, s2=source2, e=end
     while (s1<e)
     {
@@ -147,4 +118,19 @@
         }
     }
+}
+
+void MGImage::DrawImg(const byte *buffer)
+{
+    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
+        return;
+
+    switch (gVirtualX->GetDepth())
+    {
+    case 32:
+        DrawImg32(fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
+        break;
+    default:
+        cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
+    }
 
     SetBit(kNeedRedraw);
@@ -152,2 +138,34 @@
     pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
 }
+
+void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
+{
+    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
+        return;
+
+    // FROM libAfterImage:
+    // -------------------
+    //#define ALPHA_TRANSPARENT      	0x00
+    //#define ALPHA_SEMI_TRANSPARENT 	0x7F
+    //#define ALPHA_SOLID            	0xFF
+    // * Lowermost 8 bits - Blue channel
+    // * bits 8 to 15     - Green channel
+    // * bits 16 to 23    - Red channel
+    // * bits 24 to 31    - Alpha channel
+    //#define ARGB32_White    		0xFFFFFFFF
+    //#define ARGB32_Black    		0xFF000000
+
+    // FIXME: This loop depends on the screen color depth
+    switch (gVirtualX->GetDepth())
+    {
+    case 32:
+        DrawColImg32(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
+        break;
+    default:
+        cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
+    }
+
+    SetBit(kNeedRedraw);
+
+    pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
+}
Index: /trunk/MagicSoft/Cosy/gui/MGImage.h
===================================================================
--- /trunk/MagicSoft/Cosy/gui/MGImage.h	(revision 2383)
+++ /trunk/MagicSoft/Cosy/gui/MGImage.h	(revision 2384)
@@ -35,4 +35,7 @@
     enum { kNeedRedraw = BIT(17) };
 
+    void DrawImg32(char *d, char *s, char *e);
+    void DrawColImg32(char *d, char *s1, char *s2, char *e);
+
 public:
     MGImage(const TGWindow* p, UInt_t w, UInt_t h, UInt_t options = kSunkenFrame, ULong_t back = fgDefaultFrameBackground);
Index: /trunk/MagicSoft/Cosy/gui/Makefile
===================================================================
--- /trunk/MagicSoft/Cosy/gui/Makefile	(revision 2383)
+++ /trunk/MagicSoft/Cosy/gui/Makefile	(revision 2384)
@@ -21,5 +21,5 @@
 
 INCLUDES = -I. -I.. -I../base -I../slalib -I../candrv -I../incl \
-	   -I../catalog -I../videodev -I../main -I../caos
+	   -I../catalog -I../videodev -I../main -I../caos -I../tcpip
 
 # @code 
Index: /trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- /trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 2383)
+++ /trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 2384)
@@ -18,4 +18,5 @@
 
 #include "MGCosy.h"
+#include "MDriveCom.h"
 #include "MStarguider.h"
 #include "SlaStars.h"
@@ -52,4 +53,5 @@
 
 #define EXPERT
+//#undef EXPERT
 
 double MCosy::Rad2SE(double rad) const
@@ -296,5 +298,5 @@
         return;
 
-    SetStatus(MCosy::kMoving);
+    SetStatus(MDriveCom::kMoving);
 
     if (axe1) fMac2->StartRelPos(rd.Zd());
@@ -364,5 +366,5 @@
     if (!HasError())
     {
-        SetStatus(MCosy::kStopped);
+        SetStatus(MDriveCom::kStopped);
         return;
     }
@@ -371,5 +373,5 @@
     // If there is an error, the error status is set to Error.
     //
-    SetStatus(MCosy::kError);
+    SetStatus(MDriveCom::kError);
 
     /*
@@ -391,5 +393,5 @@
      // Set motor status to stopped
      //
-     SetStatus(MCosy::kStopped);
+     SetStatus(MDriveCom::kStopped);
      */
 }
@@ -471,5 +473,5 @@
 
     int i;
-    for (i=0; i<10 && !(Break() || HasError() || HasZombie()); i++)
+    for (i=0; i<(track?1:10) && !(Break() || HasError() || HasZombie()); i++)
     {
 
@@ -511,5 +513,5 @@
             t.Now();
             lout << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;
-            SetStatus(MCosy::kStopped);
+            SetStatus(MDriveCom::kStopped);
             return TRUE;
         }
@@ -560,5 +562,5 @@
             fMac2->SetAcceleration(0.4*vr);// 0.4
             fMac2->SetDeceleration(0.4*vr);// 0.4
-            SetPosVelocity(fabs(rd.Ratio()), 0.2); // 0.175
+            SetPosVelocity(fabs(rd.Ratio()), 0.2); // fast: 0.6, slow: 0.2
 #else
             fMac2->SetAcceleration(0.2*vr);
@@ -592,5 +594,5 @@
         StopMovement();
     else
-        SetStatus(MCosy::kStopped);
+        SetStatus(MDriveCom::kStopped);
 
     t.Now();
@@ -662,5 +664,5 @@
         return false;
 
-    SetStatus(MCosy::kMoving | MCosy::kTracking);
+    SetStatus(MDriveCom::kMoving | MDriveCom::kTracking);
 
     fMac2->SetRpmMode(TRUE);
@@ -1042,5 +1044,5 @@
     // Set status to Stopping
     //
-    SetStatus(MCosy::kStopping);
+    SetStatus(MDriveCom::kStopping);
 
     //
@@ -1095,5 +1097,5 @@
     // Set status to Stopping
     //
-    SetStatus(MCosy::kStopping);
+    SetStatus(MDriveCom::kStopping);
 
     //
@@ -1281,4 +1283,16 @@
         return (void*)0x7777;
 
+    case WM_POSITION1:
+        cout << "WM_Position1: start." << endl;
+        {
+            if (!CheckNetwork())
+                return (void*)0xebb0;
+
+            ZdAz dest = *((ZdAz*)mp);
+            SetPosition(dest*kDeg2Rad, kTRUE);
+        }
+        cout << "WM_Position: done. (return 0x7777)" << endl;
+        return (void*)0x7777;
+
     case WM_TESTSE:
         cout << "WM_TestSe: start." << endl;
@@ -1341,5 +1355,5 @@
             TEnv env(".cosyrc");
 
-            SetStatus(MCosy::kMoving);
+            SetStatus(MDriveCom::kMoving);
 
             fMac1->SetHome(250000, env.GetValue("Az_MaxTime2ReachHome[s]", 100));
@@ -1348,5 +1362,5 @@
             lout << "SETHOME DONE" << endl;
 
-            SetStatus(HasError() ? MCosy::kError : MCosy::kStopped);
+            SetStatus(HasError() ? MDriveCom::kError : MDriveCom::kStopped);
 
             fAz->SetPreset();
@@ -1833,5 +1847,5 @@
 
     if (HasError())
-        SetStatus(MCosy::kError);
+        SetStatus(MDriveCom::kError);
 
     lout.UpdateGui();
@@ -1849,4 +1863,11 @@
         DisplayHistGear(!trigger);
 
+    // FIXME: Not thread safe!
+    static int i=0;
+    if (i++==8)
+    {
+        fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError);
+        i=0;
+    }
     return kTRUE;
 }
@@ -2103,5 +2124,5 @@
 
 MCosy::MCosy(int mode, const char *dev, const int baud, MLog &out)
-: Network(dev, baud, out), fObservatory(MObservatory::kMagic1), fStarguider(NULL), fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0), fBackground(kBgdNone), fStatus(kStopped)
+: Network(dev, baud, out), fObservatory(MObservatory::kMagic1), fStarguider(NULL), fZd1(0), fZd2(0), fAz(0), fMac1(0), fMac2(0), fMac3(0), fBackground(kBgdNone), fStatus(MDriveCom::kStopped)
 {
     TEnv env(".cosyrc");
@@ -2158,4 +2179,7 @@
     *tpout << /*"20 1013.25 300 0.5 0.55 0.0065" <<*/ endl;
     // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
+
+    fCom = new MDriveCom(out);
+    fCom->Start();
 }
 
@@ -2189,4 +2213,5 @@
 
     delete fUpdateGui;
+    delete fCom;
 
     cout << "Deleting Nodes." << endl;
Index: /trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- /trunk/MagicSoft/Cosy/main/MCosy.h	(revision 2383)
+++ /trunk/MagicSoft/Cosy/main/MCosy.h	(revision 2384)
@@ -30,4 +30,5 @@
 #define WM_DISPLAY      0x100d
 #define WM_TRACKPOS     0x100e
+#define WM_POSITION1    0x100f
 
 class ShaftEncoder;
@@ -37,4 +38,5 @@
 class TH1;
 class MStarguider;
+class MDriveCom;
 
 class MTTalk : public MThread
@@ -61,13 +63,4 @@
 
 private:
-    enum
-    {
-        kError    = 0x01,
-        kMoving   = 0x02,
-        kTracking = 0x04,
-        kStopping = 0x08,
-        kStopped  = 0x10
-    };
-
     const MObservatory::LocationName_t fObservatory;
 
@@ -82,5 +75,6 @@
     Macs *fMac3;
 
-    MGCosy *fWin;
+    MGCosy    *fWin;
+    MDriveCom *fCom;
 
     TTimer *fUpdateGui;
Index: /trunk/MagicSoft/Cosy/main/Makefile
===================================================================
--- /trunk/MagicSoft/Cosy/main/Makefile	(revision 2383)
+++ /trunk/MagicSoft/Cosy/main/Makefile	(revision 2384)
@@ -21,5 +21,5 @@
 
 INCLUDES = -I. -I../base -I.. -I../gui -I../catalog -I../devdrv \
-	   -I../candrv -I../incl -I../videodev -I../caos
+	   -I../candrv -I../incl -I../videodev -I../caos -I../tcpip
 
 # @code 
Index: /trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc
===================================================================
--- /trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc	(revision 2383)
+++ /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 2383)
+++ /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 2383)
+++ /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 2383)
+++ /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 2383)
+++ /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 2383)
+++ /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 2383)
+++ /trunk/MagicSoft/Cosy/tcpip/Makefile	(revision 2384)
@@ -20,5 +20,5 @@
 # @endcode 
 
-INCLUDES = -I. -I../base
+INCLUDES = -I. -I../base -I../catalog
 
 # @code 
