Index: trunk/MagicSoft/Cosy/Changelog
===================================================================
--- trunk/MagicSoft/Cosy/Changelog	(revision 9434)
+++ trunk/MagicSoft/Cosy/Changelog	(revision 9435)
@@ -1,3 +1,62 @@
                                                                   -*-*- END -*-*-
+
+ 2009/04/29 Thomas Bretz (La Palma)
+
+   * cosy.cc:
+     - added possibility to switch the ccd cameras on and off remote
+     - read setup from the resource file instead of the commandline
+
+   * caos/Rings.[h,cc]:
+     - added return value to CalcRings
+
+   * catalog/StarCatalog.h:
+     - Store rotation angle
+
+   * devdrv/DevdrvLinkDef.h, Makefile:
+     - removed macs*
+     - removed shaftencoder*
+
+   * devdrv/dkc.cc:
+     - simplified the interface to the sps (removed obsolete SDOs,
+       removed obsolete subindices)
+     - removed obsolete SetDeceleration
+
+   * main/MCaos.[h,cc]:
+     - keep number of detected leds and number of detected rings
+     - make many variables a data member which can now be setup
+       from a resource file
+     - derived from MParContainer
+
+   * main/MCosy.[h,cc]:
+     - replaced SetDecelartion for pressing stop by SetAcceleration
+     - implemented WM_STARGTPOINT
+     - implemented WM_STARGMODE
+     - allow shutdown even if no connection to SPS
+
+   * main/MStargHistograms.[h,cc]:
+     - removed old obsoelte code
+
+   * main/MStarguider.[h,cc]:
+     - removed old obsolete code (StargFindStar and RoqueLampAna)
+     - moved some build in default setup to the resource file
+     - removed AMC trigger
+     - allow some setup from resource file
+     - implemented StartStarguider for remote switching of starguider
+       mode
+     - implemented DoTPoint for remote TPoint procedure
+     - some more code cleanup
+
+   * main/MTracking.cc:
+     - removed obsolete include of shaftencoder.h
+
+   * tcpip/MCeCoCom.cc:
+     - removed check for OVER
+     - use TString::Length instead of strlen(TString&)
+
+   * tcpip/MDriveCom.[h,cc]:
+     - implemented TPOINT command and STGMD command
+     - send number of LEDs and rings instead of x/y in starguider report
+
+
 
  2009/04/22 Thomas Bretz (La Palma)
Index: trunk/MagicSoft/Cosy/caos/Rings.cc
===================================================================
--- trunk/MagicSoft/Cosy/caos/Rings.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/caos/Rings.cc	(revision 9435)
@@ -44,9 +44,7 @@
                 n++;
             }
-
-    //    Expand(n);
 }
 
-void Rings::CalcRings(Leds &leds, Float_t min, Float_t max)
+Int_t Rings::CalcRings(Leds &leds, Float_t min, Float_t max)
 {
     CalcCenters(leds, min, max);
@@ -57,4 +55,6 @@
     for (int j=0; j<n; j++)
         leds(j).CalcPhi(fCenter);
+
+    return GetEntries();
 }
 
Index: trunk/MagicSoft/Cosy/caos/Rings.h
===================================================================
--- trunk/MagicSoft/Cosy/caos/Rings.h	(revision 9434)
+++ trunk/MagicSoft/Cosy/caos/Rings.h	(revision 9435)
@@ -25,5 +25,5 @@
     void SetMinNumberLeds(Short_t n) { fMinNumberLeds=n; }
 
-    void CalcRings(Leds &leds, Float_t min=-1, Float_t max=-1);
+    Int_t CalcRings(Leds &leds, Float_t min=-1, Float_t max=-1);
 
     void Print(Option_t *o=NULL) const;
Index: trunk/MagicSoft/Cosy/catalog/StarCatalog.h
===================================================================
--- trunk/MagicSoft/Cosy/catalog/StarCatalog.h	(revision 9434)
+++ trunk/MagicSoft/Cosy/catalog/StarCatalog.h	(revision 9435)
@@ -30,4 +30,5 @@
     double   fSinAngle;
     double   fCosAngle;
+    double   fAngle;
 
     float    fLimitMag; // [M] limiting magnitude for display
@@ -57,6 +58,8 @@
     void  SetPixSize(const double pixsize);
     void  SetLimitMag(const float mag);
-    void  SetRotationAngle(const float angle) { fSinAngle = sin(angle/kRad2Deg); fCosAngle = cos(angle/kRad2Deg); }
+    void  SetRotationAngle(const double angle) { fSinAngle = sin(angle/kRad2Deg); fCosAngle = cos(angle/kRad2Deg); fAngle=angle; }
     void  Reload();
+
+    double GetRotationAngle() { return fAngle; }
 
     double GetPixSize() const;
Index: trunk/MagicSoft/Cosy/cosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/cosy.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/cosy.cc	(revision 9435)
@@ -6,4 +6,5 @@
 #include <TApplication.h>
 #include <TObjectTable.h>
+#include <TSocket.h>
 
 #include "ethernet.h"
@@ -63,4 +64,42 @@
 }
 
+enum Ports_t {
+    kPortTPoint     = 4,
+    kPortStarguider = 5,
+};
+
+Bool_t SwitchCamera(const TString ip, Ports_t port, Bool_t on)
+{
+    if (ip.IsNull())
+        return kTRUE;
+
+    TSocket s(ip, 80);
+    if (!s.IsValid())
+    {
+        gLog << err << "ERROR - Could not connect to " << ip << " to switch " << (on?"on":"off") << " " << (port==kPortTPoint?"TPoint":"Starguider") << " ccd." << endl;
+        return kFALSE;
+    }
+
+    TString msg = Form("GET /ov.html?cmd=1&p=%d&s=%d HTTP/1.1\r\n", port, on?1:0);
+
+    if (s.SendRaw(msg.Data(), msg.Length()) == -1)
+    {
+        gLog << err << "ERROR - Could not talk to " << ip << " to switch " << (on?"on":"off") << " " << (port==kPortTPoint?"TPoint":"Starguider") << " ccd." << endl;
+        return kFALSE;
+    }
+
+    char buf[8192];
+
+    if (s.RecvRaw(buf, 8192) == -1)
+      return kFALSE;
+
+    // FIXME: Eval buffer
+
+    gLog << all << "- " << (port==kPortTPoint?"TPoint":"Starguider") << " ccd switched " << (on?"on":"off") << "." << endl;
+
+   return kTRUE;
+}
+
+
 /* ---------------------------------------------------------------------- */
 int main(int argc, char **argv)
@@ -88,12 +127,8 @@
     }
 
-    const Int_t   channel       = arg.GetIntAndRemove("--channel=", 0);
     const Bool_t  kDebugMem     = arg.HasOnlyAndRemove("--debug-mem");
     const Bool_t  kDebugThreads = arg.HasOnlyAndRemove("--debug-threads");
-    const TString sps           = arg.GetStringAndRemove("--sps=", "sps");
-    const TString ceco          = arg.GetStringAndRemove("--cc=", "161.72.130.60"); // ceco
     const Int_t   ceco_tx       = arg.GetIntAndRemove("--cc-tx=", 7314);//7304);
     const Int_t   ceco_rx       = arg.GetIntAndRemove("--cc-rx=", 7414);//7404);
-    const TString pointing      = arg.GetStringAndRemove("--pointing-model=", "bending2.txt"); // ceco
     const TString kConfig       = arg.GetStringAndRemove("--config=", ".cosyrc"); // ceco
     Int_t  kDebugEnv = arg.HasOnlyAndRemove("--debug-env") ? 1 : 0;
@@ -120,4 +155,10 @@
         return 0xfe;
     }
+
+    const Int_t   channel     = env.GetValue("DefaultCameraChannel", 0);
+    const TString sps         = env.GetValue("IpAddressSPS", "sps");
+    const TString ceco        = env.GetValue("IpAddressCentralControl", "161.72.130.60");
+    const TString powerswitch = env.GetValue("IpAddressPowerSwitch", "");
+    const TString pointing    = env.GetValue("PointingModel", "bending.txt");
 
     // And move the resource options from the command line to the MEnv
@@ -218,6 +259,11 @@
     if (channel>=0)
     {
-        gLog << all << "- Starting Camera." << endl;
+        SwitchCamera(powerswitch, kPortTPoint,     kTRUE);
+        SwitchCamera(powerswitch, kPortStarguider, kTRUE);
+
+        gLog << all << "- Starting Starguider." << endl;
+
         client=new MStarguider(MObservatory::kMagic1, channel);
+        client->SetupEnv(env);
         //client.SetDriveCom(&com);
         cosy->SetStarguider(client);
@@ -238,4 +284,7 @@
         gLog << all << "- Stopping starg." << endl;
         delete client;
+
+        SwitchCamera(powerswitch, kPortTPoint,     kFALSE);
+        SwitchCamera(powerswitch, kPortStarguider, kFALSE);
     }
 
Index: trunk/MagicSoft/Cosy/devdrv/DevdrvLinkDef.h
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/DevdrvLinkDef.h	(revision 9434)
+++ trunk/MagicSoft/Cosy/devdrv/DevdrvLinkDef.h	(revision 9435)
@@ -6,6 +6,4 @@
 
 #pragma link C++ class Dkc+;
-#pragma link C++ class Macs+;
-#pragma link C++ class ShaftEncoder+;
 
 #endif
Index: trunk/MagicSoft/Cosy/devdrv/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/Makefile	(revision 9434)
+++ trunk/MagicSoft/Cosy/devdrv/Makefile	(revision 9435)
@@ -17,5 +17,5 @@
 #------------------------------------------------------------------------------
 
-SRCFILES = shaftencoder.cc macs.cc dkc.cc
+SRCFILES = dkc.cc
 
 ############################################################
Index: trunk/MagicSoft/Cosy/devdrv/dkc.cc
===================================================================
--- trunk/MagicSoft/Cosy/devdrv/dkc.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/devdrv/dkc.cc	(revision 9435)
@@ -190,12 +190,4 @@
         return;
 
-    case 0x100c:
-        gLog << inf2 << "- " << GetNodeName() << ": Guard time:" << dec << val << endl;
-        return;
-
-    case 0x100d:
-        gLog << inf2 << "- " << GetNodeName() << ": Life time factor:" << dec << val << endl;
-        return;
-
     case 0x2002:
         gLog << inf2 << GetNodeName() << ": Current velocity: " << dec << val << endl;
@@ -264,63 +256,15 @@
         break;
 
-    case 0x100c:
-        switch (subidx)
-        {
-        case 0:
-            //lout << ddev(MLog::eGui);
-            gLog << inf2 << "- " << GetNodeName() << ": Guard time set." << endl;
-            //lout << edev(MLog::eGui);
-            return;
-        }
-        break;
-
-    case 0x100d:
-        switch (subidx)
-        {
-        case 0:
-            //lout << ddev(MLog::eGui);
-            gLog << inf2 << "- " << GetNodeName() << ": Life time factor set." << endl;
-            //lout << edev(MLog::eGui);
-            return;
-        }
-        break;
-
-    case 0x1800:
-        switch (subidx)
-        {
-        case 1:
-            //lout << ddev(MLog::eGui);
-            gLog << inf2 << "- " << GetNodeName() << ": Status of PDO1 set." << endl;
-            //lout << edev(MLog::eGui);
-            return;
-        }
-        break;
-
     case 0x2002:
-        switch (subidx)
-        {
-        case 0:
-            //lout << ddev(MLog::eGui);
-            gLog << inf2 << "- " << GetNodeName() << ": Velocity set." << endl;
-            //lout << edev(MLog::eGui);
-            return;
-        }
-        break;
+        //lout << ddev(MLog::eGui);
+        gLog << inf2 << "- " << GetNodeName() << ": Velocity set." << endl;
+        //lout << edev(MLog::eGui);
+        return;
 
     case 0x2003:
-        switch (subidx)
-        {
-        case 0:
-            //lout << ddev(MLog::eGui);
-            gLog << inf2 << "- " << GetNodeName() << ": Acceleration set." << endl;
-            //lout << edev(MLog::eGui);
-            return;
-        case 1:
-            //lout << ddev(MLog::eGui);
-            gLog << inf2 << "- " << GetNodeName() << ": Deceleration set." << endl;
-            //lout << edev(MLog::eGui);
-            return;
-        }
-        break;
+        //lout << ddev(MLog::eGui);
+        gLog << inf2 << "- " << GetNodeName() << ": Acceleration set." << endl;
+        //lout << edev(MLog::eGui);
+        return;
 
     case 0x3006:
@@ -359,21 +303,4 @@
         return;
 
-    case 0x6003:
-        switch (subidx)
-        {
-        case 0:
-            //lout << ddev(MLog::eGui);
-            gLog << inf2 << "- " << GetNodeName() << ": Absolute positioning started." << endl;
-            //lout << edev(MLog::eGui);
-            return;
-
-        case 1:
-            //lout << ddev(MLog::eGui);
-            gLog << inf2 << "- " << GetNodeName() << ": Relative positioning started." << endl;
-            //lout << edev(MLog::eGui);
-            return;
-        }
-        break;
-
     case 0x6004:
         switch (subidx)
@@ -421,11 +348,4 @@
 }
 
-void Dkc::SetPDO1On(BYTE_t flag)
-{
-    gLog << inf2 << "- " << GetNodeName() << ": " << (flag?"Enable":"Disable") << " PDO1." << endl;
-    SendSDO(0x1800, 1, (LWORD_t)(flag?0:1)<<31); 
-    WaitForSdo(0x1800, 1);           
-}
-
 void Dkc::StartNode()
 {
@@ -468,5 +388,4 @@
     WaitForSdo(0x1003, 2);
 
-    SetPDO1On(TRUE);
     /*
     if (HasError())
@@ -528,5 +447,5 @@
     gLog << dbg << "- Setting velocity to: " << vel << endl;
     SendSDO(0x2002, vel);     // velocity
-    WaitForSdo(0x2002, 0);
+    WaitForSdo(0x2002);
 }
 
@@ -535,5 +454,5 @@
     gLog << dbg << "- Setting velocity to: " << vel*100 << "%" << endl;
     SendSDO(0x2002, (LWORD_t)(vel*fVelMax+0.5));     // velocity
-    WaitForSdo(0x2002, 0);
+    WaitForSdo(0x2002);
 }
 
@@ -544,5 +463,5 @@
     WaitForSdo(0x2003, 0);
 }
-
+/*
 void Dkc::SetDeceleration(LWORD_t dec)
 {
@@ -551,5 +470,5 @@
     WaitForSdo(0x2003, 1);
 }
-
+*/
 void Dkc::SetRpmMode(BYTE_t mode)
 {
Index: trunk/MagicSoft/Cosy/main/MCaos.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCaos.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MCaos.cc	(revision 9435)
@@ -333,8 +333,11 @@
 }
 
-Ring MCaos::Run(byte *img, bool printl, bool printr, const ZdAz &pos, const MTime &t, Int_t box, Double_t cut)
+Ring MCaos::Run(byte *img, bool printl, bool printr, const ZdAz &pos, const MTime &t)
 {
     Leds &leds = *fLeds;
     leds.Clear();
+
+    fNumDetectedLEDs  = 0;
+    fNumDetectedRings = 0;
 
     /*
@@ -351,5 +354,5 @@
 
     //          img  width height radius sigma
-    FilterLed f(img, 768, 576, box, cut);
+    FilterLed f(img, 768, 576, fSizeBox, fCut);
 
     Int_t first=0;
@@ -359,4 +362,6 @@
         const Led &l0 = fPositions(i);
         f.Execute(leds, TMath::FloorNint(l0.GetX()), TMath::FloorNint(l0.GetY()));
+
+        fNumDetectedLEDs = leds.GetEntries();
 
         // Loop over newly found Leds
@@ -389,5 +394,5 @@
 // rwagner
 //    rings.CalcRings(leds, 158, 164);
-    rings.CalcRings(leds, fMinRadius, fMaxRadius);
+    fNumDetectedRings = rings.CalcRings(leds, fMinRadius, fMaxRadius);
 
     const Ring &center = rings.GetCenter();
@@ -488,2 +493,28 @@
 }
 
+
+Int_t MCaos::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    if (IsEnvDefined(env, prefix, "File", print))
+        ReadResources(GetEnvValue(env, prefix, "File", "ledsxxx.txt"));
+
+    if (IsEnvDefined(env, prefix, "RadiusMin", print))
+        fMinRadius = GetEnvValue(env, prefix, "RadiusMin", fMinRadius);
+
+    if (IsEnvDefined(env, prefix, "RadiusMax", print))
+        fMaxRadius = GetEnvValue(env, prefix, "RadiusMax", fMaxRadius);
+
+    if (IsEnvDefined(env, prefix, "MinNumberLeds", print))
+        fMaxRadius = GetEnvValue(env, prefix, "MinNumberLeds", fMinNumberLeds);
+
+    if (IsEnvDefined(env, prefix, "SizeBox", print))
+        fSizeBox = GetEnvValue(env, prefix, "SizeBox", fSizeBox);
+
+    if (IsEnvDefined(env, prefix, "CleaningLevel", print))
+        fCut = GetEnvValue(env, prefix, "CleaningLevel", fCut);
+
+    if (IsEnvDefined(env, prefix, "ArcsecPerPixel", print))
+        fArcsecPerPixel = GetEnvValue(env, prefix, "ArcsecPerPixel", fArcsecPerPixel);
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Cosy/main/MCaos.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCaos.h	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MCaos.h	(revision 9435)
@@ -2,4 +2,7 @@
 #define CAOS_MCaos
 
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
 #ifndef CAOS_Leds
 #include "Leds.h"
@@ -21,5 +24,5 @@
 class ZdAz;
 
-class MCaos
+class MCaos : public MParContainer
 {
 private:
@@ -45,14 +48,22 @@
     TGraph        *fGraphr;
 
-    Short_t       fMinNumberLeds;
-    Double_t      fMinRadius;
-    Double_t      fMaxRadius;
+    Short_t       fMinNumberLeds;      // minimum number of detected leds required
+    Double_t      fMinRadius;          // minimum radius for cut in ring radius
+    Double_t      fMaxRadius;          // maximum radius for cut in ring radius
+    UShort_t      fSizeBox;            // Size of the search box (side length in units of pixels)
+    Double_t      fCut;                // Cleaning level (sigma above noise)
+    Double_t      fArcsecPerPixel;     // Conversion from arcseconds to pixel
+
+    Int_t fNumDetectedLEDs;
+    Int_t fNumDetectedRings;
 
 public:
-    MCaos() : fFile(NULL), fHistpr(NULL), fMinNumberLeds(5), fMinRadius(265), fMaxRadius(268)
+    MCaos(const char *name=0, const char *title=0)
+        : fFile(NULL), fHistpr(NULL), fMinNumberLeds(5),
+        fMinRadius(265), fMaxRadius(268), fSizeBox(19), fCut(3.0)
     {
         fLeds = new Leds;
     }
-    
+
     ~MCaos()
     {
@@ -72,14 +83,11 @@
     void CloseFile();
     
-    void SetMinNumberRings(Short_t n) 
+    void SetMinNumberLeds(Short_t n)
     {
 	fMinNumberLeds = n;
     }
 
-    void SetRadii(Double_t min, Double_t max) 
-    {  
-	fMinRadius=min;
-	fMaxRadius=max;
-    }
+    void SetMinRadius(Double_t min) { fMinRadius=min; }
+    void SetMaxRadius(Double_t max) { fMaxRadius=max; }
 
     void InitHistograms();
@@ -88,6 +96,13 @@
     void ResetHistograms();
 
+    Int_t GetNumDetectedLEDs() const  { return fNumDetectedLEDs; }
+    Int_t GetNumDetectedRings() const { return fNumDetectedRings; }
+
+    Double_t GetArcsecPerPixel() const { return fArcsecPerPixel; }
+
     Ring Run(byte *img, bool printl, bool printr, const ZdAz &pos, 
-	     const MTime &t, Int_t box, Double_t cut);
+             const MTime &t);
+
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE);
 };
 
Index: trunk/MagicSoft/Cosy/main/MCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MCosy.cc	(revision 9435)
@@ -1,2 +1,3 @@
+#include "MCosy.h"
 #include "MCosy.h"
 
@@ -388,6 +389,6 @@
     {
         // FIXME: Makes sense?
-        fMac1->SetDeceleration(TMath::Nint(0.03*1000000000));
-        fMac2->SetDeceleration(TMath::Nint(0.09*1000000000));
+        fMac1->SetAcceleration(TMath::Nint(0.03*1000000000));
+        fMac2->SetAcceleration(TMath::Nint(0.09*1000000000));
 
         fMac1->SetRpmMode(FALSE);
@@ -509,4 +510,14 @@
         }
         return 0xca1b;
+
+    case WM_STARGTPOINT:
+        if (fStarguider)
+            fStarguider->StartTPoint();
+        return 0xca1c;
+
+    case WM_STARGMODE:
+        if (fStarguider)
+            fStarguider->StartStarguider();
+        return 0xca1c;
 
     case WM_TRACKPOS:
@@ -712,6 +723,6 @@
         if (!CheckNetwork())
         {
-            gLog << err << "ERROR: Cannot shutdown CANbus network." << endl;
-            return 0xebb0;
+            gLog << err << "ERROR: Cannot shutdown network." << endl;
+            gLog <<        "       Please shutdown the drive system manually" << endl;
         }
         TerminateApp();
Index: trunk/MagicSoft/Cosy/main/MCosy.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MCosy.h	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MCosy.h	(revision 9435)
@@ -44,4 +44,6 @@
 #define WM_PREPS        0x1012
 #define WM_ARM          0x1013
+#define WM_STARGTPOINT  0x1014
+#define WM_STARGMODE    0x1015
 
 class Dkc;
Index: trunk/MagicSoft/Cosy/main/MStargHistograms.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MStargHistograms.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MStargHistograms.cc	(revision 9435)
@@ -71,10 +71,4 @@
         tree->Branch("CenterX.",    &fCenterX,        "fCenterX/D");
         tree->Branch("CenterY.",    &fCenterY,       "fCenterY/D");
-	// Center of Camera, offset from arb coords, in Zd, Az, deg
-//        tree->Branch("CenterZd.",    &fCenterZd,        "fCenterZd/D");
-//        tree->Branch("CenterAz.",    &fCenterAz,       "fCenterAz/D");
-	// Position of Star in Camera in Zd, Az
-        tree->Branch("StarZd.",    &fStarZd,        "fStarZd/D");
-        tree->Branch("StarAz.",    &fStarAz,       "fStarAz/D");
 	// number of spots found
         tree->Branch("Spots.",      &fSpots,       "fSpots/D");
@@ -82,5 +76,4 @@
         tree->Branch("Stars.",      &fStars,       "fStars/D");
         tree->Branch("Bright.",      &fBright,       "fBright/D");
-
 
         cout << "Root file '" << name << "' open." << endl;
@@ -108,25 +101,5 @@
 }
 
-void MStargHistograms::InitHistograms()
-{
-    
-}
-
-void MStargHistograms::DeleteHistograms()
-{
-
-}
-
-void MStargHistograms::ShowHistograms()
-{
-
-}
-
-void MStargHistograms::ResetHistograms()
-{
-  
-}
-
-void MStargHistograms::Fill(Leds &spots, MStarList &stars, ZdAz &d, ZdAz sao, Ring &center,  ZdAz &star, Double_t bright, const ZdAz &pos, const MTime &t)
+void MStargHistograms::Fill(Leds &spots, MStarList &stars, ZdAz &d, ZdAz sao, Ring &center,  Double_t bright, const ZdAz &pos, const MTime &t)
 {
       // FIXME!
@@ -134,6 +107,4 @@
       fEvtTime = t-t0;
     
-      //    cout << "@ evttime " << fEvtTime << endl;
-
       if (fFile && spots.GetEntries()>0)
       {
@@ -147,26 +118,10 @@
 	  fCenterX    = center.GetX();
 	  fCenterY    = center.GetY();
-	  //fCenterZd   = centerzdaz.Zd();
-	  //fCenterAz   = centerzdaz.Az();
-	  fStarZd     = star.Zd();
-	  fStarAz     = star.Az();
 	  fStars      = stars.GetRealEntries();
 	  fSpots      = spots.GetEntries();
 	  fBright     = bright;
 
-  	//  cout << " Evttime=" << fEvtTime 
-//  	     << " ZD=" << fZenithDist 
-//  	     << " Az=" << fAzimuth 
-//  	     << " NomZd=" << fNomZd 
-//  	     << " NomAz=" << fNomAz 
-//  	     << " dZd=" << fdZd 
-//  	     << " dAz=" << fdAz 
-//  	     << " OffsX=" << fOffsetX
-//  	     << " OffsY=" << fOffsetY
-//  	     <<endl;
-	
           TTree *t = (TTree*)fFile->Get("Data");
           t->Fill();
       }
-         
 }
Index: trunk/MagicSoft/Cosy/main/MStargHistograms.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MStargHistograms.h	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MStargHistograms.h	(revision 9435)
@@ -31,9 +31,4 @@
     Double_t       fSpots;
     Double_t       fBright;
-//    Double_t       fCenterZd;
-//    Double_t       fCenterAz;
-    Double_t       fStarZd;
-    Double_t       fStarAz;
-
 
 public:
@@ -43,15 +38,9 @@
 
     void Fill(Leds &spots, MStarList &stars, ZdAz &d, ZdAz sao, 
-	      Ring &center, /*ZdAz &centerzdaz,*/ ZdAz &star, Double_t bright,
-	      const ZdAz &pos, const MTime &t);
+              Ring &center, Double_t bright,
+              const ZdAz &pos, const MTime &t);
 
     void OpenFile();
     void CloseFile();
-
-    void InitHistograms();
-    void DeleteHistograms();
-    void ShowHistograms();
-    void ResetHistograms();
-
 };
 
Index: trunk/MagicSoft/Cosy/main/MStarguider.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MStarguider.cc	(revision 9435)
@@ -9,7 +9,8 @@
 #include <TGraph.h>
 #include <TTimer.h>
+#include <TEnv.h>
 #include <TSystem.h>
 #include <TFile.h> // temp writeout of histos
-#include <TSocket.h>
+//#include <TSocket.h>
 
 #include <TGMenu.h>
@@ -111,6 +112,4 @@
     IDM_kStargAnalysis,
     IDM_kStargCaosFilter,
-    IDM_kStargFindStar,
-    IDM_kRoqueLampAna,
     IDM_kStarguiderMode,
     IDM_kTpointMode
@@ -273,9 +272,7 @@
     fDisplay->AddEntry("Starguider",            IDM_kStarguider);
     fDisplay->AddEntry("Starguider LED Filter", IDM_kStargCaosFilter);
-    fDisplay->AddEntry("Starguider Find Star",  IDM_kStargFindStar);
     fDisplay->AddSeparator();    
     if (channel>=0)
         fDisplay->AddPopup("&Input",   fChannel);
-    fDisplay->DisableEntry(IDM_kStargFindStar);
     fDisplay->CheckEntry(IDM_kStretch);
     fDisplay->Associate(this);
@@ -298,5 +295,4 @@
     fSetup->Associate(this);
 
-    fOperations->AddEntry("Roque Lamp Analysis", IDM_kRoqueLampAna);
     fOperations->AddEntry("Starguider Analysis", IDM_kStargAnalysis);
     fOperations->DisableEntry(IDM_kStargAnalysis);
@@ -400,46 +396,27 @@
     AddFrame(fDZdAzText);
 
-#ifdef EXPERT
-    l = new TGLabel(this, "Mispointing/FindStar (Experts Only!)");
-    l->SetTextJustify(kTextLeft);
-    l->Move(240+12+20, fMenu->GetDefaultHeight()+722+3*20-5);
-    AddFrame(l);
-#endif
-
     // Set input box for rotation angle
-    const Double_t angle = -0.2;
-    fSao->SetRotationAngle(angle);
-
-    TString txt;
-    txt += angle;
-
-    fAngle = new TGTextEntry(this, txt, IDM_kAngle);
+    fAngle = new TGTextEntry(this, "           ", IDM_kAngle);
     fAngle->SetAlignment(kTextCenterX);
     fAngle->Move(547-410, fMenu->GetDefaultHeight()+667);
     AddFrame(fAngle);
 
+    SetRotationAngle(-0.2);
+
     // Set input box for pixel size
-    const Double_t pixsize = 48.9; // used to be 23.4
-
-    fSao->SetPixSize(pixsize);
-
-    txt = "";
-    txt += pixsize;
-
-    fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
+    fPixSize = new TGTextEntry(this, "           ", IDM_kPixSize);
     fPixSize->SetAlignment(kTextCenterX);
     fPixSize->Move(547-410, fMenu->GetDefaultHeight()+690);
     AddFrame(fPixSize);
 
+    SetPixSize(48.9);
+
     // Set input box for cleaning cut
-    const Double_t cut = 3.0;
-
-    txt = "";
-    txt += cut;
-
-    fCut = new TGTextEntry(this, txt, IDM_kCut);
+    fCut = new TGTextEntry(this, "           ", IDM_kCut);
     fCut->SetAlignment(kTextCenterX);
     fCut->Move(547-410, fMenu->GetDefaultHeight()+713);
     AddFrame(fCut);
+
+    SetCut(3.0);
 
     // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
@@ -505,5 +482,7 @@
       fDx((768-kZOOM)/2),
       fDy((512-kZOOM)/2),
-      fStatus(MDriveCom::kStandby)
+      fStatus(MDriveCom::kStandby),
+      fRadius(200),
+      fTPointFromCC(0)
 {
     gLog << warn << " #### FIXME: Make MCaos Thread safe!" << endl;
@@ -513,20 +492,9 @@
     SetCleanup();
 
-    fAmcSocket = new TSocket("amc", 7307);
-
     fSao = new StarCatalog(obs);
     fRaDec = new RaDec(180, 40);
 
-    //    fStargLeds = new MStargLeds;
-    //    fStargLeds->ReadResources();
-
     fCaos = new MCaos;
-    fCaos->ReadResources();
-    fCaos->SetRadii(237.9, 239.9);
-
     fStargCaos = new MCaos;
-    fStargCaos->ReadResources("stargleds.txt");
-    fStargCaos->SetMinNumberRings(3);
-    fStargCaos->SetRadii(158,164);
 
     fStargHistograms = new MStargHistograms();
@@ -539,5 +507,5 @@
     fTime.Now();
 
-    fTimeFromTp.Set(1970,1,1);
+    fTimeFromTp.Clear();
     fAltAzOffsetFromTp = AltAz(-1000,-1000);
                                              
@@ -550,4 +518,45 @@
 }
 
+void MStarguider::SetRotationAngle(Double_t angle)
+{
+    fSao->SetRotationAngle(angle);
+
+    TString txt;
+    txt += angle;
+
+    fAngle->SetText(txt);
+}
+
+void MStarguider::SetPixSize(Double_t size)
+{
+    fSao->SetPixSize(size);
+
+    TString txt;
+    txt += size;
+
+    fPixSize->SetText(txt);
+}
+
+void MStarguider::SetCut(Double_t cut)
+{
+    TString txt;
+    txt += cut;
+
+    fCut->SetText(txt);
+}
+
+void MStarguider::SetupEnv(TEnv &env)
+{
+    fCaos->ReadEnv(env, "TPointLeds", kTRUE);
+    fStargCaos->ReadEnv(env, "StarguiderLeds", kTRUE);
+
+    SetRotationAngle(env.GetValue("Starguider.RotationAngle", fSao->GetRotationAngle()));
+    SetCut(env.GetValue("Starguider.CleaningLevel", atof(fCut->GetText())));
+
+    SetPixSize(env.GetValue("StarguiderLeds.ArcsecPerPixel", fSao->GetPixSize()));
+
+    fRadius = env.GetValue("Leds.Radius", fRadius);
+}
+
 MStarguider::~MStarguider()
 {
@@ -564,5 +573,4 @@
     delete fCaos;
     delete fStargCaos;
-    //    delete fStargLeds;
     delete fStargHistograms;
     delete fSao;
@@ -578,30 +586,5 @@
         delete fOutRq;
 
-    delete fAmcSocket;
-
     gLog << inf2 << "Camera Display destroyed." << endl;
-}
-
-bool MStarguider::SendAmcTrigger(const char *msg)
-{
-    if (!fAmcSocket->IsValid())
-        return false;
-
-    TString txt("TRIGGER ");
-    txt += msg;
-
-    const Int_t len = fAmcSocket->SendRaw(txt.Data(), txt.Length());
-    if (len<0)
-    {
-        gLog << err << "ERROR - Sending Trigger to Amc" << endl;
-        return false;
-    }
-    if (len!=txt.Length())
-    {
-        gLog << err << "Send wrong number (" << len << ") of Bytes to Amc." << endl;
-        return false;
-    }
-
-    return true;
 }
 
@@ -763,5 +746,4 @@
         SwitchOff(fDisplay, IDM_kStarguider);
         SwitchOff(fDisplay, IDM_kStargCaosFilter);
-        fDisplay->DisableEntry(IDM_kStargFindStar);
     }
     else
@@ -858,21 +840,4 @@
                 return kTRUE;
 
-	   case IDM_kRoqueLampAna:
-  	        Toggle(fOperations, IDM_kRoqueLampAna);
-                if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
-                    fDisplay->CheckEntry(IDM_kStargCaosFilter);
-                else
-                    fDisplay->UnCheckEntry(IDM_kStargCaosFilter);
-		  
-		return kTRUE;
-
-           case IDM_kStargFindStar:
-	        Toggle(fDisplay, IDM_kStargFindStar);         
-                if (fDisplay->IsEntryChecked(IDM_kStargFindStar))
-                    fSZdAz->MapWindow();
-                else
-                    fSZdAz->UnmapWindow();
-                return kTRUE;
-
             case IDM_kStarguider:
                 Toggle(fDisplay, IDM_kStarguider);
@@ -892,8 +857,6 @@
                     //uncheck not needed items
                     //general
-                    fDisplay->UnCheckEntry(IDM_kStargFindStar);
                     SwitchOff(fDisplay, IDM_kFilter);
                     SwitchOff(fChannel, IDM_kChannel3);
-                    SwitchOff(fOperations, IDM_kRoqueLampAna);
                     SwitchOff(fOperations, IDM_kStargAnalysis);
 
@@ -930,5 +893,4 @@
                     fDisplay->EnableEntry(IDM_kFindStar);
                     fChannel->EnableEntry(IDM_kChannel3);
-                    fOperations->EnableEntry(IDM_kRoqueLampAna);
                 }
                 return kTRUE;
@@ -941,8 +903,6 @@
                     //unchecking not needed items
                     //general
-                    fDisplay->UnCheckEntry(IDM_kStargFindStar);
                     SwitchOff(fDisplay, IDM_kFilter);
                     SwitchOff(fChannel, IDM_kChannel3);
-                    SwitchOff(fOperations, IDM_kRoqueLampAna);
 
                     //from starguider
@@ -981,5 +941,4 @@
                     fChannel->EnableEntry(IDM_kChannel1);
                     fChannel->EnableEntry(IDM_kChannel3);
-                    fOperations->EnableEntry(IDM_kRoqueLampAna);
 
                     //tpoint
@@ -1013,5 +972,4 @@
                 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
                 {
-                    fDisplay->EnableEntry(IDM_kStargFindStar);
                     SwitchOff(fDisplay, IDM_kCaosFilter);
                     SwitchOff(fDisplay, IDM_kFindStar);
@@ -1023,5 +981,4 @@
                     fDisplay->EnableEntry(IDM_kFindStar);
                     fDisplay->EnableEntry(IDM_kCaosFilter);
-                    fDisplay->DisableEntry(IDM_kStargFindStar);
                 }
                 return kTRUE;
@@ -1338,19 +1295,7 @@
     AltAz pos0 = fSao->CalcAltAzFromPix(768/2,    576/2)*kRad2Deg;
     AltAz pos1 = fSao->CalcAltAzFromPix(768/2+mx, 576/2+my)*kRad2Deg;
-/*
-    ofstream fout1("pointingpos.txt");
-    fout1 << setprecision(10) << fSao->GetMjd()-52000 << " ";
-    if (fCosy)
-        fout1 << fCosy->GetPointingPos() << " ";
-    fout1 << -pos1.Alt() << " " << pos1.Az() << endl;
- */
+
     pos1 -= pos0;
-/*
-    ofstream fout2("tracking_error.txt", ios::app);
-    fout2 << setprecision(10) << fSao->GetMjd()-52000 << " ";
-    if (fCosy)
-        fout2 << fCosy->GetPointingPos() << " ";
-    fout2 << -pos1.Alt() << " " << pos1.Az() << endl;
-  */
+
     return ZdAz(-pos1.Alt(), pos1.Az());
 }
@@ -1360,19 +1305,15 @@
 {
     num = leds.GetEntries();
-    //cout << "Num: " << num << endl;
     if (num < 3) //was 1
     {
         gLog << warn << "Sorry, less than 3 detected spot in FOV!" << endl;
-        if (fStargTPoint->IsDown())
-            fStargTPoint->SetDown(kFALSE);
+        fStargTPoint->SetDown(kFALSE);
         return 0;
     }
 
-    //cout << "Cat: " << stars.GetRealEntries() << endl;
     if (stars.GetRealEntries() < 3)
     {
         gLog << warn << "Sorry, less than 3 stars in FOV!" << endl;
-        if (fStargTPoint->IsDown())
-            fStargTPoint->SetDown(kFALSE);
+        fStargTPoint->SetDown(kFALSE);
         return 0;
     }
@@ -1433,19 +1374,10 @@
     d = TrackingError(x, y, mag, numcor);
     if (numcor<1)
+    {
+        fStargTPoint->SetDown(kFALSE);
         return 0;
-
-    //cout << "Cor: " << numcor << endl;
+    }
 
     fDZdAz->SetCoordinates(d);
-
-    //
-    // Calculated offsets
-    //
-
-#ifdef EXPERT
-    // round= floor(x+.5)
-    cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
-    cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
-#endif
 
     //
@@ -1476,5 +1408,5 @@
     // Get tracking coordinates
     const XY    xy = fCRaDec->GetCoordinates();
-    const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
+    const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad());
 
     // From the star position in the camera we calculate the Alt/Az
@@ -1485,17 +1417,12 @@
     //correction with offset from last tpoint measurement
     za0 -= fAltAzOffsetFromTp;
-    MTime t2 = fTimeFromTp;
 
     //if the difference between the tpoint and the starguider tpoint
     //is too big, the starguider tpoint is not stored
-    cout << "     mjd difference: " << t.GetMjd()-t2.GetMjd() << endl;
-//        cout << "t: " << setprecision(11) << t.GetMjd() << endl;
-//        cout << "t2: " << setprecision(11) << t2.GetMjd() << endl;
-    if ((t.GetMjd()-t2.GetMjd())>0.001) //1min20sec
-    {
-        cout << "     time difference between tpoint and starguider-tpoint > 1 min *" <<
-            t.GetMjd()-t2.GetMjd() << "s) " << endl;
+    if ((t.GetMjd()-fTimeFromTp.GetMjd())>0.001) //1min20sec
+    {
+        cout << "     time difference between tpoint and starguider-tpoint > 1m20s" << endl;
         cout << "     => starguider tpoint hasn't been stored. " << endl;
-        cout << "     Please repeat whole procedure. " << endl;
+        cout << "        Please repeat whole procedure. " << endl;
         return numcor;
     }
@@ -1503,9 +1430,9 @@
 
     // Write real pointing position
-    cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
+    //cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
     *fOutStargTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
 
     // Write system pointing position
-    cout << "     SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;
+    //cout << "     SE-Pos: " << 90-cpos.Zd() << "° " << cpos.Az() << "°" << endl;
     *fOutStargTp << fmod(cpos.Az()+360, 360) << " " << 90-cpos.Zd();
 
@@ -1517,57 +1444,14 @@
     *fOutStargTp << endl;
 
-    fTimeFromTp.Set(1970,1,1);
+    fTimeFromTp.Clear();
 
     return numcor;
 }
 
-XY MStarguider::FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t, Double_t cut, Int_t box, XY SearchCenter)
-{
-    // Set search Paremeters (FIXME: Get them from user input!)
-    f.SetCut(cut);  // 3.5
-    f.SetBox(box);  // 70
-
-    // Try to find Led in this area
-    Leds leds;
-    f.FindStar(leds, (Int_t)SearchCenter.X(), (Int_t)SearchCenter.Y(), true);
-
-    // Check whether star found
-    Led *star = (Led*)leds.At(0);
-    if (!star || leds.GetEntries()<1)
-        return XY(.0,.0);
-
-//    cout << "Found Roque Lamp @ " << flush;
-    star->Print();
-    f.MarkPoint(star->GetX(), star->GetY(), 500);
-
-//    cout << "RoquePos: " << star->GetX() << "," << star->GetY() << endl;
-
-    XY roquepos(star->GetX(), star->GetY());
-    XY relroquepos(roquepos.X()-CameraCenter.GetX(), roquepos.Y()-CameraCenter.GetY());
-
-    // If no file open: open new Roque Lamp file
-    if (!fOutRq)
-    {
-        const TString name = MCosy::GetFileName("tpoint", "roquelamp", "txt");
-        cout << "Starg_RoqueLamp File ********* " << name << " ********** " << endl;
-        fOutRq = new ofstream(name);
-        *fOutRq << "# Magic Roque Lamp file  " << t << endl;
-    }
-
-    return relroquepos;
-}
-
-ZdAz MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, Double_t cut, Int_t box, Double_t scalefactor = 1.0)
-{
-    // Set search Paremeters (FIXME: Get them from user input!)
-    f.SetCut(cut);  // 3.5
-    f.SetBox(box);  // 70
-
-    // Try to find Led in this area
+void MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t)
+{
+    // Try to find the star
     Leds leds;
     f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY(), true);
-
-    if (leds.GetEntries()<0)
-        return ZdAz(0, 0);
 
     // Check whether star found
@@ -1580,11 +1464,12 @@
             gLog << warn << "No star found. Couldn't take a tpoint." << endl;
         }
-        return ZdAz(.0,.0);
-    }
+        return;
+    }
+
     cout << "Found star @ " << flush;
     star->Print();
     f2.MarkPoint(star->GetX(), star->GetY(), 2<<2);
 
-    // Initialize Star Catalog on th camera plane
+    // Initialize Star Catalog on the camera plane
     MGeomCamMagic geom;
     MAstroCamera ac;
@@ -1595,35 +1480,20 @@
 
     // Get tracking coordinates
-    const XY    xy = fCRaDec->GetCoordinates();
-    const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
+    const XY xy = fCRaDec->GetCoordinates();  // [h, deg]
+    const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad());
 
     ac.SetRaDec(rd.Ra(), rd.Dec());
 
+    // Convert from Pixel to millimeter (1pix=2.6mm) [deg/pix / deg/mm = mm/pix]
+    // Correct for abberation.
+    const Double_t conv = fCaos->GetArcsecPerPixel()/3600/geom.GetConvMm2Deg()/ 1.0713;
+
     // Adapt coordinate system (GUIs and humans are counting Y in different directions)
-    Double_t x = star->GetX()-center.GetX();
-    Double_t y = center.GetY()-star->GetY();
-
-#ifdef EXPERT
-    cout << "STAR-Offset: " << MTime(-1) << " dx=" << x << "pix  dy=" << y << "pix" << endl;
-#endif
-
-    // MAKE SURE THAT THIS VALUE CAN BE SETUP
-    // (Scalefactor describes the difference between the tpoint (=1)
-    //  and the starguider (!=1) camera
-    // Convert from Pixel to millimeter (1pix=2.6mm)
-    x *= (2.58427 * scalefactor);
-    y *= (2.58427 * scalefactor);
-
-    // Correct for abberation.
-    x /= 1.0713;
-    y /= 1.0713;
+    const Double_t dx = (star->GetX()-center.GetX())*conv;
+    const Double_t dy = (center.GetY()-star->GetY())*conv;
 
     // Convert offset from camera plane into local ccordinates
     Double_t dzd, daz;
-    ac.GetDiffZdAz(x, y, dzd, daz);
-
-#ifdef EXPERT
-    cout << "STAR-Offset: " << MTime(-1) << " dZd=" << dzd << "d  dAz=" << daz << "d" << endl;
-#endif
+    ac.GetDiffZdAz(dx, dy, dzd, daz);
 
     ZdAz zdaz(dzd,daz);
@@ -1631,5 +1501,6 @@
     // Check TPoint data set request
     if (!fTPoint->IsDown())
-        return zdaz;
+        return;
+
     fTPoint->SetDown(kFALSE);
 
@@ -1641,5 +1512,5 @@
         //
         const TString name = MCosy::GetFileName("tpoint", "tpoint", "txt");
-        cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
+        cout << "TPoint File ********* " << name << " ********** " << endl;
 
         fOutTp = new ofstream(name);
@@ -1652,5 +1523,5 @@
 
     // Output Ra/Dec the drive system thinks that it is currently tracking
-    cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl;
+    //cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl;
 
     // From the star position in the camera we calculate the Alt/Az
@@ -1664,16 +1535,14 @@
     fTimeFromTp=t;
 
-
     // From the Shaftencoders we get the current 'pointing' position
     // as it is seen by the drive system (system pointing position)
-    // FIXME????
-    const ZdAz za1 = fCosy->GetSePos()*TMath::TwoPi();
+    const ZdAz za1 = fCosy->GetSePos()*360; // [deg]
 
     // Write real pointing position
-    cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
+    //cout << "     Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
     *fOutTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
 
     // Write system pointing position
-    cout << "     SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
+    //cout << "     SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
     *fOutTp << fmod(za1.Az()+360, 360) << " " << 90-za1.Zd();
 
@@ -1684,5 +1553,5 @@
     *fOutTp << " " << star->GetMag();
     *fOutTp << endl;
-
+/*
     MLog &outrep = *fCosy->GetOutRep();
     if (outrep.Lock("MStarguider::FindStar"))
@@ -1695,10 +1564,10 @@
         outrep << star->GetX() << " " << star->GetY() << " ";
         outrep << center.GetX() << " " << center.GetY() << " ";
-        outrep << x*1.0713/2.58427 << " " << y*1.0713/2.58427 << " " << star->GetMag();
+        outrep << dx/conv << " " << dy/conv << " " << star->GetMag();
         outrep << setprecision(11) << t.GetMjd() << endl;
         outrep.UnLock("MStarguider::FindStar");
-    }
+    }*/
     
-    return zdaz;
+//    return zdaz;
 }
 
@@ -1730,4 +1599,109 @@
 
     return true;
+}
+
+void MStarguider::DrawZoomImage(const byte *img)
+{
+    byte zimg[kZOOM*kZOOM];
+    for (int y=0; y<kZOOM; y++)
+        for (int x=0; x<kZOOM; x++)
+            zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768];
+
+    fZoomImage->DrawImg(zimg);
+}
+
+void MStarguider::DrawCosyImage(const byte *img)
+{
+    if (!fCosy)
+        return;
+
+    byte simg[(768/2-1)*(576/2-1)];
+    for (int y=0; y<576/2-1; y++)
+        for (int x=0; x<768/2-1; x++)
+            simg[x+y*(768/2-1)] = ((unsigned int)img[2*x+2*y*768]+img[2*x+2*y*768+1]+img[2*x+2*(y+1)*768]+img[2*x+2*(y+1)*768+1])/4;
+
+    fCosy->GetWin()->GetImage()->DrawImg(simg);
+}
+
+void MStarguider::StartStarguider()
+{
+    // Switch to starguider mode
+    cout << " * Switching to Starguider mode" << endl;
+    fMode->UnCheckEntry(IDM_kStarguiderMode);
+    ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0);
+}
+
+Bool_t MStarguider::DoTPoint()
+{
+    if (fTPointFromCC<0)
+        return kTRUE;
+
+    switch (++fTPointFromCC)
+    {
+    case 1:
+        fTimeFromTp.Clear();
+        fNumStarsDetected = 0;
+
+        cout << " * Switching to TPoint mode" << endl;
+        // Switch to tpoint mode
+        fMode->UnCheckEntry(IDM_kTpointMode);
+        ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kTpointMode, 0);
+        return kFALSE;
+
+    case 2:
+        cout << " * Waiting one frame" << endl;
+        // Wait one frame
+        return kFALSE;
+
+    case 3:
+        cout << " * Taking TPoint" << endl;
+        fTPoint->SetDown(); // kTRUE
+        return kTRUE;
+
+    case 4:
+        if (!fTimeFromTp) // TPoint failed
+            break;
+
+        // Switch to starguider mode
+        cout << " * Switching to Starguider mode" << endl;
+        fMode->UnCheckEntry(IDM_kStarguiderMode);
+        ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0);
+        return kFALSE;
+
+    case 5:
+        cout << " * Waiting one frame" << endl;
+        // Wait one frame
+        return kFALSE;
+
+    case 6:
+        cout << " * Taking Starguider TPoint" << endl;
+        fStargTPoint->SetDown(); // kTRUE
+        return kTRUE;
+
+    case 7:
+        cout << " * Send Report" << endl;
+        break;
+    }
+
+    // Send report
+    fTPointFromCC = -1;
+
+    if (!fCosy)
+        return kTRUE;
+
+    MDriveCom *com = fCosy->GetDriveCom();
+    if (!com)
+        return kTRUE;
+
+    // nominalaz, nominalel, realaz, realel, nomra, nomdec,
+    // diffaz, diffel, mjd, numleds, artmag
+
+    //fTimeFromTp.Clear();
+    //fStatus==MDriveCom::kMonitoring
+    //fNumStarsDetected   = numstars;
+    //fNumStarsCorrelated = rc;
+    com->SendTPoint(fNumStarsCorrelated>0);
+
+    return kTRUE;
 }
 
@@ -1778,4 +1752,9 @@
         f.Execute();
 
+    DoTPoint();
+
+    Int_t numleds = 0;
+    Int_t numrings = 0;
+
     // Find Center of Camera for Caos and Tpoints
     Ring center(768/2, 576/2);
@@ -1787,7 +1766,9 @@
         if (fCosy)
             pos = fCosy->GetPointingPos();
-        center = fCaos->Run(img, printl, printr, pos, t, 19, 3.0);
-	cout << "Caos Filter Camera center position: " << center.GetX() << " " << center.GetY() << " (R=" << center.GetR() << ")" << endl;
-
+
+        center = fCaos->Run(img, printl, printr, pos, t);
+
+        numleds  = fCaos->GetNumDetectedLEDs();
+        numrings = fCaos->GetNumDetectedRings();
     }
 
@@ -1796,33 +1777,18 @@
         center.GetX()>0 && center.GetY()>0)
     {
-        // SCALE FACTOR ASSUMED TO BE 70
-        FindStar(f, f2, center, t, 3/*3.5*/, 70);
-        SendAmcTrigger("TPoint");
-    }
-
-    byte zimg[kZOOM*kZOOM];
-    for (int y=0; y<kZOOM; y++)
-        for (int x=0; x<kZOOM; x++)
-            zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768];
-
-    fZoomImage->DrawImg(zimg);
-
-    if (fCosy)
-    {
-	byte simg[(768/2-1)*(576/2-1)];
-	for (int y=0; y<576/2-1; y++)
-	    for (int x=0; x<768/2-1; x++)
-		simg[x+y*(768/2-1)] = ((unsigned int)img[2*x+2*y*768]+img[2*x+2*y*768+1]+img[2*x+2*(y+1)*768]+img[2*x+2*(y+1)*768+1])/4;	
-
-	fCosy->GetWin()->GetImage()->DrawImg(simg);
-    }
+        // Set search Paremeters (FIXME: Get them from user input!)
+        f.SetCut(3.0);
+        f.SetBox(70);
+
+        FindStar(f, f2, center, t);
+    }
+
+    DrawZoomImage(img);
+    DrawCosyImage(img);
+
+    // Position corresponding to the camera center (53.2, 293.6)
+    Ring sgcenter(53.2, 293.6); // Center of camera in SG picture [px]
 
     // Find Center of Camera in Starfield Camera picture 
-
-    Ring sgcenter(53.2, 293.6); // Center of camera in SG picture [px]
-    //ZdAz sgcenterzdaz(0, 0);    // Center of camera in SG picture [deg]
-    //                            // (0,0)_deg is at (53.2, 293.6)_px
-    ZdAz star(0, 0);            // Star on curtain in [deg]
-
     if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter))
     {
@@ -1831,99 +1797,9 @@
             pos = fCosy->GetPointingPos();
 
-        sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t, 19, 3.0); // [px]
-
-        //const Float_t pixsize = atof(fPixSize->GetText()); // [arcsec/px]
-
-        // BE CAREFULL: This transformation is WRONG. It is just
-        // a transformation of units, but this implies, that the
-        // coordiante axis in both units look the same. This is
-        // wrong exspecially near the zenith were az-lines are highly
-        // curved around the zenith!
-        //sgcenterzdaz.Zd((sgcenter.GetY()-293.6) * pixsize /3600 );
-	//sgcenterzdaz.Az((sgcenter.GetX()-53.2)  * pixsize /3600 );
-#ifdef EXPERT
-	cout << "- LEDs imply offset of Zd=" 
-	     << sgcenter.GetX()-53.2 << "pix Az=" 
-	     << sgcenter.GetY()-293.6<< "pix" << endl; 	
-#endif
-        if (fDisplay->IsEntryChecked(IDM_kStargFindStar) &&
-            sgcenter.GetX()>0 && sgcenter.GetY()>0)
-        {
-            star = FindStar(f, f2, sgcenter, t, 4.5, 30, 267/161.9); // [deg]
-#ifdef EXPERT
-            cout << "- Star is found to be off Zd=" << star.Zd()*60 << "' Az="
-                << star.Az()*60 << "'" << endl;
-#endif
-            fSZdAz->SetCoordinates(star); // Mispointing found from Camera
-
-            SendAmcTrigger("Starguider");
-        }
-    }
-
-// Find Roque Lamp
-
-    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
-    {
-
-        Double_t imageclean = 1.5;
-        Int_t    boxradius = 60;
-	//Double_t scalefactor = 1;
-	XY searchcenter(768/2-1,576/2+25);
-
-	XY roquelamp = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
-
-        if (fOutRq)
-        {
-            ZdAz pos = fCosy->GetPointingPos();
-
-            *fOutRq << "RoqueLampDirect:    " << MTime(-1) << "  "
-                << pos.Zd() << " " << pos.Az() << "   "
-                << roquelamp.X() << " " << roquelamp.Y() << endl;
-        }
-
-        cout << "Starguider Camera Center: " << sgcenter.GetX() << "," << sgcenter.GetY() << endl;
-	cout << ">=>=>=> Roque Lamp found at:         >=>=>=> (" << roquelamp.X() << "," 
-	     << roquelamp.Y() << ") <=<=<=<" << endl;
-
-    }
-
-    // Find Spot on Camera Center in Starguider camera
-    if (fOperations->IsEntryChecked(IDM_kRoqueLampAna))
-    {
-        XY cameraspot(0,0);
-
-        Double_t imageclean = 5;
-	Int_t    boxradius = 60;
-	//Double_t scalefactor = 1;
-	//	XY searchcenter(sgcenter.GetX(),sgcenter.GetY());
-	XY searchcenter(60.,290.);
-
-	cameraspot = FindRoqueLamp(f, f2, sgcenter, t, imageclean, boxradius, searchcenter);
-
-        if (fOutRq)
-        {
-            ZdAz pos = fCosy->GetPointingPos();
-
-            *fOutRq << "RoqueLampReflected: "  << MTime(-1) << "  "
-                << pos.Zd() << " " << pos.Az() << "   "
-                << cameraspot.X() << " " << cameraspot.Y() << endl;
-        }
-
-        cout << ">>>>> Spot on Magic camera found at: >>>>> (" << cameraspot.X() << ","
-	     << cameraspot.Y() << ") <<<<<" << endl;
-
-        f2.DrawCircle(sgcenter, 5.0, 0x0fa);
-        f2.DrawCircle(sgcenter, 115.0, 0x0fa);
-    }
-    // we calculate the offset given by the three ETH Leds visible to
-    // the guide camera
-    // This is an (inferior, obsolete) alternative to the StarCaosFilter
-    // Led offset;
-    // if (fDisplay->IsEntryChecked(IDM_kStargLEDFilter))	
-    //	fStargLeds->Run(img,offset);
-
-    // Position corresponding to the camera center (53.2, 293.6)
-    //Ring skycenter(392, 318);
-    // MStarList spots;
+        sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t); // [px]
+
+        numleds  = fStargCaos->GetNumDetectedLEDs();
+        numrings = fStargCaos->GetNumDetectedRings();
+    }
 
     // we obtain a list of stars in the FOV from the SAO catalog
@@ -1932,6 +1808,6 @@
         MTime time(*tm);
 
-	XY xy = fCRaDec->GetCoordinates();  //[h,  deg]
-	fRaDec->Set(xy.X()*360/24, xy.Y()); //[deg,deg]
+        XY xy = fCRaDec->GetCoordinates();  //[h,  deg]
+	fRaDec->Set(xy.X()*15, xy.Y());     //[deg,deg]
 
 	UpdatePosZoom();
@@ -1941,14 +1817,7 @@
   	fCZdAz->SetCoordinates(fSao->GetZdAz());
 
-  	MStarList stars;
     	fSao->SetBox(230); // Region of interest around center
 
-        // very careful: If center of camera cannot be determined
-	// sgcenter jumps to (0,0)  
-
-        //Please never change this offsets!!!
-        // 53.2 and 293.6 are the "preliminary" camera center
-        // -9 and 28.5 are the offsets of the pointing position in the sky
-
+        // If center of camera cannot be determined sgcenter is (0,0)
         const Bool_t centerisvalid = sgcenter.GetX()>0 && sgcenter.GetY()>0;
 //        if (centerisvalid)
@@ -1956,11 +1825,15 @@
 //                            sgcenter.GetY() - 293.6);
 
+	// We determine the ideal starfield using camera sagging info
+        // from the LEDs
+        //Please never change this offsets!!!
+        // 53.2 and 293.6 are the "preliminary" camera center
+        // -9 and 28.5 are the offsets of the pointing position in the sky
+        const XY off(sgcenter.GetX()- 53.2-9,
+                     sgcenter.GetY()-293.6+28.5);
+
     	// we obtain stars in the effective star FOV and draw them.
     	// coordinates are video frame coords.
-	// We determine the ideal starfield using camera sagging info
-        // from the LEDs
-        const XY off(sgcenter.GetX()- 53.2-9,
-                     sgcenter.GetY()-293.6+28.5);
-
+  	MStarList stars;
         fSao->CalcStars(stars, 530, 292, TMath::FloorNint(off.X()), TMath::FloorNint(off.Y()));
 	fSao->DrawStars(stars, cimg);
@@ -2015,7 +1888,6 @@
 
             if (fOperations->IsEntryChecked(IDM_kStargAnalysis))
-                fStargHistograms->Fill(spots, stars, fD,
-                                       fSao->GetZdAz(), sgcenter, /*sgcenterzdaz,*/
-                                       star, bright, fPos, t);
+                fStargHistograms->Fill(spots, stars, fD, fSao->GetZdAz(),
+                                       sgcenter, bright, fPos, t);
 
             fNumStarsDetected   = numstars;
@@ -2028,5 +1900,5 @@
                     com->SendStargReport(fStatus, fD, fSao->GetZdAz(),
                                          sgcenter, numstars, rc, bright,
-                                         time.GetMjd(), 0, 0);    // Report
+                                         time.GetMjd(), numleds, numrings);    // Report
             }
 
@@ -2068,6 +1940,5 @@
     if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
         fDisplay->IsEntryChecked(IDM_kCatalog)    ||
-        fDisplay->IsEntryChecked(IDM_kFindStar)   ||
-        fOperations->IsEntryChecked(IDM_kRoqueLampAna))
+        fDisplay->IsEntryChecked(IDM_kFindStar))
         fImage->DrawColImg(img, cimg);
     else
Index: trunk/MagicSoft/Cosy/main/MStarguider.h
===================================================================
--- trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MStarguider.h	(revision 9435)
@@ -21,5 +21,5 @@
 class TGButton;
 class TString;
-class TSocket;
+//class TSocket;
 
 class TTimer;
@@ -111,5 +111,4 @@
     MCaos         *fCaos;
     MCaos         *fStargCaos;
-    TSocket       *fAmcSocket;
     MStargHistograms *fStargHistograms;
     
@@ -133,5 +132,8 @@
     Double_t fLastBright;
 
-    void SetPixSize(const double pixsize);
+    Double_t fRadius; // LED radius [cm]
+
+    Int_t fTPointFromCC;
+
     void Toggle(TGPopupMenu *p, UInt_t id);
     void SwitchOff(TGPopupMenu *p, UInt_t id);
@@ -141,30 +143,22 @@
     void ToggleCaosFilter();
     void SetChannel();
-    //void GetCoordinates();
     Int_t CalcTrackingError(Leds &, MStarList &, ZdAz &, MTime &, double &bright, Int_t &num);
-    //void CalcTrackingError(Leds &, MStarList &);
     ZdAz TrackingError(TArrayF &alt, TArrayF &az, TArrayF &mag, Int_t &num) const;
     bool Interpolate(const unsigned long n, byte *img) const;
+    void FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t);
 
-    XY FindRoqueLamp(FilterLed &f, FilterLed &f2, Ring &CameraCenter, MTime &t,
-                     Double_t cut, Int_t box, XY SearchCenter);
-
-    ZdAz FindStar(FilterLed &f, FilterLed &f2, Ring &center, MTime &t, 
-		  Double_t cut, Int_t box, Double_t scalefactor);
-
-    //void InitHists();
-    //void InitGraphs();
     void InitGui(Int_t channel);
 
-    bool SendAmcTrigger(const char *msg);
-
-    //void OpenFile();
-
-    //void ResetHists();
-    //void DisplayAnalysis();
     void UpdatePosZoom();
+    void DrawZoomImage(const byte *img);
+    void DrawCosyImage(const byte *img);
 
     Bool_t HandleTimer(TTimer *t);
-    //Bool_t HandleKey(Event_t* event);
+
+    void SetRotationAngle(Double_t angle);
+    void SetPixSize(Double_t size);
+    void SetCut(Double_t cut);
+
+    Bool_t DoTPoint();
 
 public:
@@ -172,5 +166,5 @@
     virtual ~MStarguider();
 
-    //void Update();
+    void SetupEnv(TEnv &env);
 
     void Layout();
@@ -180,5 +174,4 @@
 
     Bool_t HandleDoubleClick(Event_t *event);
-    //Bool_t HandleButton(Event_t *);
 
     void SetPointingPosition(RaDec rd);
@@ -195,4 +188,7 @@
     void Print(Option_t *o) const { }
 
+    void StartTPoint() { if (fTPointFromCC<0) fTPointFromCC=0; }
+    void StartStarguider();
+
     ClassDef(MStarguider, 0)
 };
Index: trunk/MagicSoft/Cosy/main/MTracking.cc
===================================================================
--- trunk/MagicSoft/Cosy/main/MTracking.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/main/MTracking.cc	(revision 9435)
@@ -4,5 +4,5 @@
 
 #include "dkc.h"
-#include "shaftencoder.h"
+//#include "shaftencoder.h"
 
 #include "MCosy.h"
Index: trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc	(revision 9435)
@@ -42,4 +42,11 @@
 bool MCeCoCom::InterpreteReport(TString &str)
 {
+    if (!str.EndsWith("OVER"))
+    {
+        cout << "Communication Problem: Termination (OVER) not found." << endl;
+        fComStat = kComProblem;
+        return false;
+    }
+
     int y, m, d, h, min, s, ms, len;
 
@@ -74,4 +81,5 @@
         return false;
     }
+/*
     str.Remove(0, len);
 
@@ -82,4 +90,5 @@
         return false;
     }
+ */
 
     fHumidity = hum;
@@ -142,5 +151,5 @@
 
     // Send report to CC
-    const bool rc = Send(msg, strlen(msg));
+    const bool rc = Send(msg.Data(), msg.Length());
     fComStat = rc ? kNoCmdReceived : kComProblem;
 
Index: trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc	(revision 9434)
+++ trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc	(revision 9435)
@@ -148,4 +148,18 @@
 {
     cout << "CC-COMMAND " << MTime(-1) << " TPOIN " << str << endl;
+
+    if (fQueue)
+        fQueue->PostMsg(WM_TPOINT);//, (void*)str.Data(), str.Length()+1);
+
+    return true;
+}
+
+bool MDriveCom::CommandSTGMD(TString &str)
+{
+    cout << "CC-COMMAND " << MTime(-1) << "STGMD" << endl;
+
+    if (fQueue)
+        fQueue->PostMsg(WM_STARGMODE);//, (void*)str.Data(), str.Length()+1);
+
     return true;
 }
@@ -220,4 +234,7 @@
     if (cmd==(TString)"ARM")
         return CommandARM(str);
+
+    if (cmd==(TString)"STGMD")
+        return CommandSTGMD(str);
 
     if (cmd.IsNull() && str.IsNull())
@@ -278,5 +295,5 @@
     str += armed ? "1 " : "0 ";
 
-    return SendRep("DRIVE-REPORT", str, kFALSE);
+    return SendRep("DRIVE-REPORT", str.Data(), kFALSE);
 }
 
@@ -286,5 +303,5 @@
 }
 
-bool MDriveCom::SendStargReport(UInt_t stat, ZdAz miss, ZdAz nompos, Ring center, Int_t num, Int_t n, Double_t bright, Double_t mjd, Double_t x, Double_t y)
+bool MDriveCom::SendStargReport(UInt_t stat, ZdAz miss, ZdAz nompos, Ring center, Int_t num, Int_t n, Double_t bright, Double_t mjd, Int_t numleds, Int_t numrings)
 {
     // miss   [deg]
@@ -305,14 +322,14 @@
     str += MString::Format("%05.3f ", miss.Zd());       //[arcmin]
     str += MString::Format("%05.3f ", miss.Az());       //[arcmin]
-    Print(str, nompos.Zd());                      //[deg]
-    Print(str, nompos.Az());                      //[deg]
-    str += MString::Format("%05.1f ",   center.GetX()); //number
-    str += MString::Format("%05.1f ",   center.GetY()); //number
-    str += MString::Format("%04d ",   n);               //number of correleated stars
-    str += MString::Format("%03.1f ",  bright);
+    Print(str, nompos.Zd());                            //[deg]
+    Print(str, nompos.Az());                            //[deg]
+    str += MString::Format("%05.1f ",   center.GetX()); //
+    str += MString::Format("%05.1f ",   center.GetY()); //
+    str += MString::Format("%04d ",   n);               // number of correleated stars
+    str += MString::Format("%03.1f ",  bright);         // arbitrary sky brightness
     str += MString::Format("%12.6f ", t.GetMjd());      // mjd
-    str += MString::Format("%.1f ", x);
-    str += MString::Format("%.1f ", y);
-    str += MString::Format("%04d ", num);               //number of detected stars
+    str += MString::Format("%d ", numleds);             // number of detected leds
+    str += MString::Format("%d ", numrings);            // number of detected rings
+    str += MString::Format("%04d ", num);               // number of detected stars
 
     return SendRep("STARG-REPORT", str, kTRUE);
@@ -321,36 +338,23 @@
 bool MDriveCom::SendTPoint(UInt_t stat)
 {
+    //const MTime t(-1);
+
+    SetStatus(stat);
     /*
-    // miss   [deg]
-    // nompos [deg]
-    const MTime t(-1);
-
-    miss *= 60;        // [arcmin]
-
-    // Set status flag
-    if (stat&kError)
-        SetStatus(0);
-    if (stat&kStandby)
-        SetStatus(2);
-    if (stat&kMonitoring)
-        SetStatus(4);
-    
-    MString txt;
-
-    TString str;
-    str += txt.Print("%05.3f ", miss.Zd());       //[arcmin]
-    str += txt.Print("%05.3f ", miss.Az());       //[arcmin]
-    Print(str, nompos.Zd());                      //[deg]
-    Print(str, nompos.Az());                      //[deg]
-    str += txt.Print("%05.1f ",   center.GetX()); //number
-    str += txt.Print("%05.1f ",   center.GetY()); //number
-    str += txt.Print("%04d ",   n);               //number of correleated stars
-    str += txt.Print("%03.1f ",  bright);
-    str += txt.Print("%12.6f ", t.GetMjd());      // mjd
-    str += txt.Print("%.1f ", x);
-    str += txt.Print("%.1f ", y);
-    str += txt.Print("%04d ", num);               //number of detected stars
-    */
-
+     TString str;
+     str += name;  // star name
+     str += " ";
+     str += nominalaz;
+     str += nominalel;
+     str += realaz;
+     str += realel;
+     str += nomra;
+     str += nomdec;
+     str += diffaz;
+     str += diffel;
+     str += mjd;
+     str += numleds;
+     str += artmag;
+     */
     return SendRep("TPOINT-REPORT", "", kTRUE);
 }
Index: trunk/MagicSoft/Cosy/tcpip/MDriveCom.h
===================================================================
--- trunk/MagicSoft/Cosy/tcpip/MDriveCom.h	(revision 9434)
+++ trunk/MagicSoft/Cosy/tcpip/MDriveCom.h	(revision 9435)
@@ -29,4 +29,5 @@
     bool CommandARM(TString &str);
     bool CommandTPOINT(TString &str);
+    bool CommandSTGMD(TString &str);
 
 public:
@@ -49,5 +50,5 @@
 
     bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er, Bool_t armed);
-    bool SendStargReport(UInt_t stat, ZdAz miss, ZdAz nompos, Ring center, Int_t num, Int_t n, Double_t bright, Double_t mjd, Double_t x, Double_t y);
+    bool SendStargReport(UInt_t stat, ZdAz miss, ZdAz nompos, Ring center, Int_t num, Int_t n, Double_t bright, Double_t mjd, Int_t numleds, Int_t numrings);
     bool SendTPoint(UInt_t stat);
     bool SendStatus(const char *stat);
