Changeset 2384 for trunk


Ignore:
Timestamp:
10/15/03 17:28:35 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/Makefile

    r1953 r2384  
    3939SUBDIRS = \
    4040        main     \
     41        tcpip    \
    4142        gui      \
    4243        catalog  \
     
    114115        @cd videodev; make mrproper; cd ..
    115116        @echo "cd .."
     117        @echo "cd tcpip"
     118        @cd tcpip; make mrproper; cd ..
     119        @echo "cd .."
    116120        @echo "cd catalog"
    117121        @cd catalog; make mrproper; cd ..
  • trunk/MagicSoft/Cosy/base/log.h

    r920 r2384  
    1 #ifndef LOG_H
    2 #define LOG_H
     1#ifndef COSY_Log
     2#define COSY_Log
    33
    44#include <ostream.h>
    55
     6#ifndef MARS_MLog
    67#include "MLog.h"
     8#endif
    79
    810//#ifndef __CINT__
  • trunk/MagicSoft/Cosy/base/timer.h

    r2278 r2384  
    1010    friend ostream &operator<<(ostream &out, Timer &t);
    1111private:
    12     double fMs;
    13     double fDiv;
     12    double fMs;  // Microsec in units of sec as returned by gettimeofday
     13    int fSecs;   // Seconds as returned by gettimeofday
    1414
    15     int fSec;
    16     int fSecs;
    17     int fMin;
    18     int fHor;
    19     int fDay;
    20     int fMon;
    21     int fYea;
     15    int fSec;    // Sec of time
     16    int fMin;    // Min of time
     17    int fHor;    // Hor of time
     18    int fDay;    // Day of time
     19    int fMon;    // Mon of time
     20    int fYea;    // Yea of time
    2221
    23     double fMjd;
     22    double fDiv; // Division of day
     23    double fMjd; // MJD
    2424
    2525    char fDateStr[30];
     
    2828
    2929public:
    30     Timer() : fMs(0), fSec(0), fSecs(0), fMin(0), fHor(0), fDay(0), fMon(0), fYea(0), fMjd(0) {}
     30    Timer(int d, int m, int y, int h, int min, int s, double ms)
     31        : fMs(ms), fSecs(0), fSec(s), fMin(m), fHor(h), fDay(d), fMon(m), fYea(y), fDiv(0), fMjd(0) {}
     32    Timer() : fMs(0), fSecs(0), fSec(0), fMin(0), fHor(0), fDay(0), fMon(0), fYea(0), fDiv(0), fMjd(0) {}
    3133    Timer(double t);
    3234    Timer(struct timeval *tv);
     
    3537    void SetTimer(int tv_sec, double tv_usec);
    3638    void SetTimer(const struct timeval *tv);
     39    void SetTimer(int y, int m, int d, int h, int min, int s, double ms)
     40    {
     41        fMs = ms;
     42        fSec = s;
     43        fMin = min;
     44        fHor = h;
     45        fDay = d;
     46        fMon = m;
     47        fYea = y;
     48    }
    3749
    3850    void GetTimeval(struct timeval *tv) const;
     
    5264    int M() const { return fMin; }
    5365    int S() const { return fSec; }
     66    int MilliSec() const { return (int)(fMs*1000); }
     67    double MicroSec() const { return fMs; }
    5468
    5569    const char *GetTimeStr();
  • trunk/MagicSoft/Cosy/cosy.cc

    r2278 r2384  
    1515#include "MStarguider.h"
    1616
    17 #define EXPERT
     17//#define EXPERT
     18#define HAVE_CAMERA
    1819
    1920#define clog(txt) \
     
    100101
    101102    clog("- Starting Camera.");
     103#ifdef HAVE_CAMERA
    102104    MStarguider *client=new MStarguider(MObservatory::kMagic1);
    103105    Camera *cam = new Camera(*client);
     
    106108    cosy->SetStarguider(client);
    107109    client->SetCosy(cosy);
    108 
     110#endif
    109111    clog("- Starting mainloop.");
    110112#ifndef EXPERT
     
    112114#endif
    113115    app->Run(kTRUE);
    114 
     116#ifdef HAVE_CAMERA
    115117    client->SetCosy(NULL);
    116118    cosy->SetStarguider(NULL);
     
    120122    delete cam;
    121123    delete client;
    122 
     124#endif
    123125    clog("- Stopping cosy.");
    124126    cosy->Stop();
  • trunk/MagicSoft/Cosy/gui/MGCosy.cc

    r2280 r2384  
    2626#include "MCosy.h"
    2727#include "MGList.h"
     28#include "MDriveCom.h"
    2829#include "MGAccuracy.h"
    2930#include "MGCoordinates.h"
     
    3435
    3536#undef DEBUG
    36 #define EXPERT
     37//#define EXPERT
     38//#define HAS_DEMO
    3739
    3840ClassImp(MGCosy);
     
    4143#define IDM_TEXT   2
    4244#define IDM_ASPECT 3
     45
    4346
    4447enum
     
    386389    TGCompositeFrame *tf6 = fTab->AddTab("Gear");
    387390#endif
    388     /*TGCompositeFrame *tf3 =*/// fTab->AddTab("Demo");
     391#ifdef HAS_DEMO
     392    /*TGCompositeFrame *tf3 =*/ fTab->AddTab("Demo");
     393#endif
    389394
    390395    fCZdAz = new MGCoordinates(tf1, kETypeZdAz);
     
    984989void MGCosy::UpdateZdAz(ZdAz &soll)
    985990{
    986     soll *= 360/2/TMath::Pi();
     991    soll *= kRad2Deg;
    987992
    988993    static Int_t zd=~0;
     
    10551060    UpdateZdAz(soll);
    10561061
    1057 #define kError     0x01
    1058 #define kMoving    0x02
    1059 #define kTracking  0x04
    1060 #define kStopping  0x08
    1061 #define kStopped   0x10
    1062 
    1063     EnableLabel(fError,    stat&kError);
    1064     EnableLabel(fMoving,   stat&kMoving);
    1065     EnableLabel(fTracking, stat&kTracking);
    1066     EnableLabel(fStopping, stat&kStopping);
    1067     EnableLabel(fStopped,  stat&kStopped);
    1068     EnableLabel(fRaSoll,   stat&kTracking);
    1069     EnableLabel(fDecSoll,  stat&kTracking);
    1070     EnableLabel(fZdSoll,   stat&kMoving);
    1071     EnableLabel(fAzSoll,   stat&kMoving);
     1062    EnableLabel(fError,    stat&MDriveCom::kError);
     1063    EnableLabel(fMoving,   stat&MDriveCom::kMoving);
     1064    EnableLabel(fTracking, stat&MDriveCom::kTracking);
     1065    EnableLabel(fStopping, stat&MDriveCom::kStopping);
     1066    EnableLabel(fStopped,  stat&MDriveCom::kStopped);
     1067    EnableLabel(fRaSoll,   stat&MDriveCom::kTracking);
     1068    EnableLabel(fDecSoll,  stat&MDriveCom::kTracking);
     1069    EnableLabel(fZdSoll,   stat&MDriveCom::kMoving);
     1070    EnableLabel(fAzSoll,   stat&MDriveCom::kMoving);
    10721071
    10731072    SetLabelColor(fAvailMac1, stat2&0x01);
     
    10781077    SetLabelColor(fAvailSe3,  stat2&0x20);
    10791078
    1080     if (stat&kTracking)
     1079    if (stat&MDriveCom::kTracking)
    10811080    {
    10821081        fAccuracy->Update(pos, acc);
     
    11871186// ************************** For demo purpose **********************
    11881187//
    1189 /*
     1188#ifdef HAS_DEMO
     1189
    11901190#include <TRandom.h>
    11911191class MDemo : public MThread
     
    12001200    void SetQueue(MsgQueue *q) { fQueue = q; }
    12011201
     1202    bool Wait(int s, int m)
     1203    {
     1204        int i = 0;
     1205        while (!HasStopFlag() && i++<m)
     1206            usleep(s);
     1207        if (HasStopFlag())
     1208            return false;
     1209        return true;
     1210    }
     1211
     1212    bool Move(float zd, float az, int s, int m)
     1213    {
     1214        ZdAz dest1(zd, az);
     1215        fQueue->PostMsg(WM_POSITION1, &dest1, sizeof(dest1));
     1216        return Wait(s, m); // 30s?
     1217    }
     1218
    12021219    virtual void *Thread()
    12031220    {
    1204         while (1)
     1221        if (!Move(90, -65, 1000000, 27))
     1222            return NULL;
     1223
     1224        Int_t i=1;
     1225        while (i-->0)
    12051226        {
    12061227            Timer tm;
    12071228            tm.Now();
    12081229
    1209             //fQueue->PostMsg(WM_STOP, 0, 0);
    1210 
    1211             ZdAz dest1((float)fRand.Integer(120)-60., 0);//fRand.Integer(25)+90);
    1212 
    1213             cout << "Demo: Zd=" << dest1.Zd() << "° Az=" << dest1.Az() << "°" << endl;
    1214 
    1215             fQueue->PostMsg(WM_POSITION, &dest1, sizeof(dest1));
    1216 
    1217             int i = 0;
    1218             while (!HasStopFlag() && i++<5)  // 30s
    1219                 usleep(1000000);
    1220             if (HasStopFlag())
     1230            if (!Move(75, -80, 1000000, 13))
    12211231                break;
    1222 
    1223             //ZdAz dest2(5, 30);
    1224             //fQueue->PostMsg(WM_POSITION, &dest2, sizeof(dest2));
    1225             //if (HasStopFlag())
    1226             //    break;
     1232            if (!Move(60, -65, 1000000, 13))
     1233                break;
     1234            if (!Move(75, -50, 1000000, 13))
     1235                break;
     1236            if (!Move(90, -65, 1000000, 13))
     1237                break;
    12271238        }
     1239        if (!Move(60, -65, 1000000, 17))
     1240            return NULL;
     1241        if (!Move(90, -65, 1000000, 19))
     1242            return NULL;
     1243        if (!Move(90, -10, 1000000, 28))
     1244            return NULL;
     1245
    12281246        cout << "Demo Thread: done." << endl;
    12291247        return NULL;
     
    12481266    demo.Stop();
    12491267}
    1250 */
     1268#endif //HAS_DEMO
     1269
    12511270/*
    12521271void MGCosy::StartCalib()
     
    13441363                    fQueue->Proc(WM_GEAR, (void*)1);
    13451364                    return kTRUE;
    1346                     /*
     1365#ifdef HAS_DEMO
    13471366                case 5:
    13481367                    StartDemo();
    13491368                    return kTRUE;
    1350                     */
     1369#endif
    13511370                }
    13521371                return kTRUE;
     
    13541373            case kPB_STOP:
    13551374                cout << "Sending stop movement msg." << endl;
    1356                 //StopDemo();
     1375#ifdef HAS_DEMO
     1376                StopDemo();
     1377#endif
    13571378                fQueue->PostMsg(WM_STOP, 0, 0);
    13581379                if (fTab->GetCurrent()==3)
  • trunk/MagicSoft/Cosy/gui/MGImage.cc

    r2278 r2384  
    5252    fDefGC  = gVirtualX->CreateGC(fId, 0);
    5353    fImage  = (XImage*)gVirtualX->CreateImage(fWidth, fHeight);
     54
     55    cout << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
    5456}
    5557
     
    8284}
    8385
    84 void MGImage::DrawImg(const byte *buffer)
     86void MGImage::DrawImg32(char *d, char *s, char *e)
    8587{
    86     if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
    87         return;
    88 
    89     char *d = fImage->data;
    90     char *e = (char*)(buffer+fWidth*fHeight);
    91     char *s = (char*)buffer;
    92 
    93     // FIXME: This loop depends on the screen color depth
     88    // d=destination, s=source, e=end
    9489    while (s<e)
    9590    {
     
    9994        d++;
    10095    }
    101 
    102     SetBit(kNeedRedraw);
    103 
    104     pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
    10596}
    10697
    107 void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
     98void MGImage::DrawColImg32(char *d, char *s1, char *s2, char *e)
    10899{
    109     if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
    110         return;
    111 
    112     char *d  = fImage->data;
    113     char *e  = (char*)(gbuf+fWidth*fHeight);
    114     char *s1 = (char*)gbuf;
    115     char *s2 = (char*)cbuf;
    116 
    117     // FROM libAfterImage:
    118     // -------------------
    119     //#define ALPHA_TRANSPARENT         0x00
    120     //#define ALPHA_SEMI_TRANSPARENT    0x7F
    121     //#define ALPHA_SOLID               0xFF
    122     // * Lowermost 8 bits - Blue channel
    123     // * bits 8 to 15     - Green channel
    124     // * bits 16 to 23    - Red channel
    125     // * bits 24 to 31    - Alpha channel
    126     //#define ARGB32_White              0xFFFFFFFF
    127     //#define ARGB32_Black              0xFF000000
    128 
    129     // FIXME: This loop depends on the screen color depth
     100    // d=destination, s1=source1, s2=source2, e=end
    130101    while (s1<e)
    131102    {
     
    147118        }
    148119    }
     120}
     121
     122void MGImage::DrawImg(const byte *buffer)
     123{
     124    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
     125        return;
     126
     127    switch (gVirtualX->GetDepth())
     128    {
     129    case 32:
     130        DrawImg32(fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
     131        break;
     132    default:
     133        cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
     134    }
    149135
    150136    SetBit(kNeedRedraw);
     
    152138    pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
    153139}
     140
     141void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
     142{
     143    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
     144        return;
     145
     146    // FROM libAfterImage:
     147    // -------------------
     148    //#define ALPHA_TRANSPARENT         0x00
     149    //#define ALPHA_SEMI_TRANSPARENT    0x7F
     150    //#define ALPHA_SOLID               0xFF
     151    // * Lowermost 8 bits - Blue channel
     152    // * bits 8 to 15     - Green channel
     153    // * bits 16 to 23    - Red channel
     154    // * bits 24 to 31    - Alpha channel
     155    //#define ARGB32_White              0xFFFFFFFF
     156    //#define ARGB32_Black              0xFF000000
     157
     158    // FIXME: This loop depends on the screen color depth
     159    switch (gVirtualX->GetDepth())
     160    {
     161    case 32:
     162        DrawColImg32(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
     163        break;
     164    default:
     165        cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
     166    }
     167
     168    SetBit(kNeedRedraw);
     169
     170    pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
     171}
  • trunk/MagicSoft/Cosy/gui/MGImage.h

    r2278 r2384  
    3535    enum { kNeedRedraw = BIT(17) };
    3636
     37    void DrawImg32(char *d, char *s, char *e);
     38    void DrawColImg32(char *d, char *s1, char *s2, char *e);
     39
    3740public:
    3841    MGImage(const TGWindow* p, UInt_t w, UInt_t h, UInt_t options = kSunkenFrame, ULong_t back = fgDefaultFrameBackground);
  • trunk/MagicSoft/Cosy/gui/Makefile

    r2278 r2384  
    2121
    2222INCLUDES = -I. -I.. -I../base -I../slalib -I../candrv -I../incl \
    23            -I../catalog -I../videodev -I../main -I../caos
     23           -I../catalog -I../videodev -I../main -I../caos -I../tcpip
    2424
    2525# @code
  • trunk/MagicSoft/Cosy/main/MCosy.cc

    r2278 r2384  
    1818
    1919#include "MGCosy.h"
     20#include "MDriveCom.h"
    2021#include "MStarguider.h"
    2122#include "SlaStars.h"
     
    5253
    5354#define EXPERT
     55//#undef EXPERT
    5456
    5557double MCosy::Rad2SE(double rad) const
     
    296298        return;
    297299
    298     SetStatus(MCosy::kMoving);
     300    SetStatus(MDriveCom::kMoving);
    299301
    300302    if (axe1) fMac2->StartRelPos(rd.Zd());
     
    364366    if (!HasError())
    365367    {
    366         SetStatus(MCosy::kStopped);
     368        SetStatus(MDriveCom::kStopped);
    367369        return;
    368370    }
     
    371373    // If there is an error, the error status is set to Error.
    372374    //
    373     SetStatus(MCosy::kError);
     375    SetStatus(MDriveCom::kError);
    374376
    375377    /*
     
    391393     // Set motor status to stopped
    392394     //
    393      SetStatus(MCosy::kStopped);
     395     SetStatus(MDriveCom::kStopped);
    394396     */
    395397}
     
    471473
    472474    int i;
    473     for (i=0; i<10 && !(Break() || HasError() || HasZombie()); i++)
     475    for (i=0; i<(track?1:10) && !(Break() || HasError() || HasZombie()); i++)
    474476    {
    475477
     
    511513            t.Now();
    512514            lout << t << " - Positioning done in " << i << (i==1?" step.":" steps.") << endl;
    513             SetStatus(MCosy::kStopped);
     515            SetStatus(MDriveCom::kStopped);
    514516            return TRUE;
    515517        }
     
    560562            fMac2->SetAcceleration(0.4*vr);// 0.4
    561563            fMac2->SetDeceleration(0.4*vr);// 0.4
    562             SetPosVelocity(fabs(rd.Ratio()), 0.2); // 0.175
     564            SetPosVelocity(fabs(rd.Ratio()), 0.2); // fast: 0.6, slow: 0.2
    563565#else
    564566            fMac2->SetAcceleration(0.2*vr);
     
    592594        StopMovement();
    593595    else
    594         SetStatus(MCosy::kStopped);
     596        SetStatus(MDriveCom::kStopped);
    595597
    596598    t.Now();
     
    662664        return false;
    663665
    664     SetStatus(MCosy::kMoving | MCosy::kTracking);
     666    SetStatus(MDriveCom::kMoving | MDriveCom::kTracking);
    665667
    666668    fMac2->SetRpmMode(TRUE);
     
    10421044    // Set status to Stopping
    10431045    //
    1044     SetStatus(MCosy::kStopping);
     1046    SetStatus(MDriveCom::kStopping);
    10451047
    10461048    //
     
    10951097    // Set status to Stopping
    10961098    //
    1097     SetStatus(MCosy::kStopping);
     1099    SetStatus(MDriveCom::kStopping);
    10981100
    10991101    //
     
    12811283        return (void*)0x7777;
    12821284
     1285    case WM_POSITION1:
     1286        cout << "WM_Position1: start." << endl;
     1287        {
     1288            if (!CheckNetwork())
     1289                return (void*)0xebb0;
     1290
     1291            ZdAz dest = *((ZdAz*)mp);
     1292            SetPosition(dest*kDeg2Rad, kTRUE);
     1293        }
     1294        cout << "WM_Position: done. (return 0x7777)" << endl;
     1295        return (void*)0x7777;
     1296
    12831297    case WM_TESTSE:
    12841298        cout << "WM_TestSe: start." << endl;
     
    13411355            TEnv env(".cosyrc");
    13421356
    1343             SetStatus(MCosy::kMoving);
     1357            SetStatus(MDriveCom::kMoving);
    13441358
    13451359            fMac1->SetHome(250000, env.GetValue("Az_MaxTime2ReachHome[s]", 100));
     
    13481362            lout << "SETHOME DONE" << endl;
    13491363
    1350             SetStatus(HasError() ? MCosy::kError : MCosy::kStopped);
     1364            SetStatus(HasError() ? MDriveCom::kError : MDriveCom::kStopped);
    13511365
    13521366            fAz->SetPreset();
     
    18331847
    18341848    if (HasError())
    1835         SetStatus(MCosy::kError);
     1849        SetStatus(MDriveCom::kError);
    18361850
    18371851    lout.UpdateGui();
     
    18491863        DisplayHistGear(!trigger);
    18501864
     1865    // FIXME: Not thread safe!
     1866    static int i=0;
     1867    if (i++==8)
     1868    {
     1869        fCom->SendReport(fStatus, fRaDec, fZdAzSoll, bendist, fTrackingError);
     1870        i=0;
     1871    }
    18511872    return kTRUE;
    18521873}
     
    21032124
    21042125MCosy::MCosy(int mode, const char *dev, const int baud, MLog &out)
    2105 : 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)
     2126: 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)
    21062127{
    21072128    TEnv env(".cosyrc");
     
    21582179    *tpout << /*"20 1013.25 300 0.5 0.55 0.0065" <<*/ endl;
    21592180    // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
     2181
     2182    fCom = new MDriveCom(out);
     2183    fCom->Start();
    21602184}
    21612185
     
    21892213
    21902214    delete fUpdateGui;
     2215    delete fCom;
    21912216
    21922217    cout << "Deleting Nodes." << endl;
  • trunk/MagicSoft/Cosy/main/MCosy.h

    r2278 r2384  
    3030#define WM_DISPLAY      0x100d
    3131#define WM_TRACKPOS     0x100e
     32#define WM_POSITION1    0x100f
    3233
    3334class ShaftEncoder;
     
    3738class TH1;
    3839class MStarguider;
     40class MDriveCom;
    3941
    4042class MTTalk : public MThread
     
    6163
    6264private:
    63     enum
    64     {
    65         kError    = 0x01,
    66         kMoving   = 0x02,
    67         kTracking = 0x04,
    68         kStopping = 0x08,
    69         kStopped  = 0x10
    70     };
    71 
    7265    const MObservatory::LocationName_t fObservatory;
    7366
     
    8275    Macs *fMac3;
    8376
    84     MGCosy *fWin;
     77    MGCosy    *fWin;
     78    MDriveCom *fCom;
    8579
    8680    TTimer *fUpdateGui;
  • trunk/MagicSoft/Cosy/main/Makefile

    r2278 r2384  
    2121
    2222INCLUDES = -I. -I../base -I.. -I../gui -I../catalog -I../devdrv \
    23            -I../candrv -I../incl -I../videodev -I../caos
     23           -I../candrv -I../incl -I../videodev -I../caos -I../tcpip
    2424
    2525# @code
  • trunk/MagicSoft/Cosy/tcpip/MCeCoCom.cc

    r2379 r2384  
    4141
    4242        // skip solar_irr_Wm2, wind_speed, UPS
    43         float zd, az, dec, ra, temp, hum;
     43                float zd, az, dec, ra, temp, hum;
    4444        n=sscanf(str.Data(),
    4545                 "%f %f %f %f %f %*f %*f %f %*f %n",
  • trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h

    r2379 r2384  
    3434
    3535    bool InterpreteStr(TString str);
    36     bool Send(const char *str);
    3736
    3837public:
    39     MCeCoCom::MCeCoCom(const char *cmd)
    40         : MTcpIpIO(), fCommand(cmd), fStatus(0), fComStat(kNoCmdReceived)
     38    MCeCoCom::MCeCoCom(const char *cmd, MLog &out=gLog)
     39        : MTcpIpIO(out), fCommand(cmd), fStatus(0), fComStat(kNoCmdReceived)
    4140    {
    4241    }
    4342
     43    bool Send(const char *str);
    4444    void SetStatus(Byte_t s) { fStatus=s; }
    4545};
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc

    r2379 r2384  
    22
    33#include <iostream>
     4
     5#include "coord.h"
     6#include "Slalib.h"
    47
    58using namespace std;
     
    3134    return false;
    3235}
     36
     37void MDriveCom::Print(TString &str, Double_t deg) const
     38{
     39    Char_t sgn;
     40    UShort_t d, m, s;
     41
     42    Slalib::Deg2Dms(deg, sgn, d, m, s);
     43
     44    str += Form("%c %03d %02d %03d ", sgn, d, m, s);
     45}
     46
     47bool MDriveCom::SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er)
     48{
     49    // so [rad]
     50    // is [deg]
     51    // er [rad]
     52
     53    so *= kRad2Deg;
     54    er *= kRad2Deg;
     55
     56    // Set status flag
     57    if (stat&kError)
     58        SetStatus(0);
     59    if (stat&kStopped)
     60        SetStatus(1);
     61    if (stat&kStopping || stat&kMoving)
     62        SetStatus(3);
     63    if (stat&kTracking)
     64        SetStatus(4);
     65
     66    Timer t;
     67    t.Now();
     68
     69    TString str;
     70    Print(str, rd.Ra());    // Ra
     71    Print(str, rd.Dec());   // Dec
     72    Print(str, 0);          // HA
     73    str += Form("%12.6f ", t.GetMjd()); // mjd
     74    Print(str, so.Zd());
     75    Print(str, so.Az());
     76    Print(str, is.Zd());
     77    Print(str, is.Az());
     78    str += Form("%08.3f ", er.Zd());
     79    str += Form("%08.3f", er.Az());
     80
     81    return Send(str);
     82}
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.h

    r2379 r2384  
    66#endif
    77
     8class RaDec;
     9class ZdAz;
     10
    811class MDriveCom : public MCeCoCom
    912{
    1013private:
    1114    bool InterpreteCmd(TString cmd, TString str);
     15    void Print(TString &str, Double_t deg) const;
    1216
    1317public:
    14     MDriveCom() : MCeCoCom("DRIVE-REPORT") {}
     18    enum
     19    {
     20        kError    = 0x01,
     21        kMoving   = 0x02,
     22        kTracking = 0x04,
     23        kStopping = 0x08,
     24        kStopped  = 0x10
     25    };
     26
     27    MDriveCom(MLog &out=gLog) : MCeCoCom("DRIVE-REPORT", out) {}
     28
     29    bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er);
    1530};
    1631
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc

    r2379 r2384  
    3131     */
    3232
    33 MTcpIpIO::MTcpIpIO() : MThread(false), fRxSocket(NULL), fServSock(NULL)
     33MTcpIpIO::MTcpIpIO(MLog &out) : MThread(false), Log(out), fRxSocket(NULL), fServSock(NULL)
    3434{
    3535    fTxSocket = new TSocket("ceco", 7304);
     
    3838MTcpIpIO::~MTcpIpIO()
    3939{
     40    cout << "Delete TxSocket..." << flush;
    4041    delete fTxSocket;
     42    cout << "Done." << endl;
     43    if (fServSock)
     44    {
     45        cout << "Delete ServSock..." << flush;
     46        delete fServSock;
     47        cout << "Done." << endl;
     48    }
     49    if (fRxSocket)
     50    {
     51        cout << "Delete RxSocket..." << flush;
     52        delete fRxSocket;
     53        cout << "Done." << endl;
     54    }
    4155}
    4256
     
    6882}
    6983
     84void MTcpIpIO::Clear()
     85{
     86    char c;
     87    while (fRxSocket->RecvRaw(&c, 1)>0 && !HasStopFlag())
     88        usleep(1);
     89}
     90
    7091void *MTcpIpIO::Thread()
    7192{
     
    87108            }
    88109            delete fServSock;
     110            fServSock=NULL;
    89111            usleep(5000000);
    90112            continue;
     
    105127        {
    106128            delete fServSock;
     129            fServSock=NULL;
    107130            continue;
    108131        }
     
    113136            delete fServSock;
    114137            delete fRxSocket;
     138            fServSock = NULL;
     139            fRxSocket = NULL;
    115140            continue;
    116141        }
     
    119144
    120145        fRxSocket->SetOption(kNoBlock, 1);
     146
     147        Clear();
    121148
    122149        TString str;
     
    160187        delete fServSock;
    161188        delete fRxSocket;
     189        fServSock = NULL;
     190        fRxSocket = NULL;
    162191    }
    163192
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h

    r2379 r2384  
    55#include "MThread.h"
    66#endif
     7#ifndef COSY_Log
     8#include "log.h"
     9#endif
    710
    811class TString;
     
    1013class TServerSocket;
    1114
    12 class MTcpIpIO : public MThread
     15class MTcpIpIO : public MThread, public Log
    1316{
    1417private:
     
    1720    TServerSocket *fServSock;
    1821
     22    void Clear();
     23
    1924public:
    20     MTcpIpIO();
     25    MTcpIpIO(MLog &out=gLog);
    2126    ~MTcpIpIO();
    2227
  • trunk/MagicSoft/Cosy/tcpip/Makefile

    r2379 r2384  
    2020# @endcode
    2121
    22 INCLUDES = -I. -I../base
     22INCLUDES = -I. -I../base -I../catalog
    2323
    2424# @code
Note: See TracChangeset for help on using the changeset viewer.