Ignore:
Timestamp:
11/17/03 13:40:14 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc

    r2384 r2517  
    55#include "coord.h"
    66#include "Slalib.h"
     7#include "MCosy.h"
    78
    89using namespace std;
    910
     11bool MDriveCom::ReadAngle(TString &str, Double_t &ret)
     12{
     13    Char_t  sgn;
     14    Int_t   d, len;
     15    UInt_t  m;
     16    Float_t s;
     17
     18    // Skip whitespaces before %c and after %f
     19    int n=sscanf(str.Data(), " %c %d %d %f %n", &sgn, &d, &m, &s, &len);
     20
     21    if (n!=4 || (sgn!='+' && sgn!='-'))
     22        return false;
     23
     24    str.Remove(0, len);
     25
     26    ret = Slalib::Dms2Deg(d, m, s, sgn);
     27    return true;
     28}
     29
     30bool MDriveCom::ReadPosition(TString &str, Double_t &d1, Double_t &d2)
     31{
     32    if (!ReadAngle(str, d1))
     33        return false;
     34
     35    if (!ReadAngle(str, d2))
     36        return false;
     37
     38    return true;
     39}
     40
     41bool MDriveCom::CommandRADEC(TString &str)
     42{
     43    Double_t ra, dec;
     44    if (!ReadPosition(str, ra, dec))
     45    {
     46        cout << "ERROR - Reading position from RADEC" << endl;
     47        return false;
     48    }
     49    if (!str.IsNull())
     50    {
     51        cout << "ERROR - Too many bytes in command RADEC" << endl;
     52        return false;
     53    }
     54
     55    cout << "CC-COMMAND: Track " << ra << "h " << dec << "deg '" << str << "'" << endl;
     56
     57    ra *= 15; // h -> deg
     58
     59    RaDec rd[2] = { RaDec(ra, dec), RaDec(ra, dec) };
     60
     61    cout << "MDriveCom - TRACK... start." << endl;
     62    fQueue->PostMsg(WM_TRACK, &rd, sizeof(rd));
     63    cout << "MDriveCom - TRACK... done." << endl;
     64    return true;
     65}
     66
     67bool MDriveCom::CommandZDAZ(TString &str)
     68{
     69    Double_t zd, az;
     70    if (!ReadPosition(str, zd, az))
     71    {
     72        cout << "ERROR - Reading position from ZDAZ" << endl;
     73        return false;
     74    }
     75
     76    if (!str.IsNull())
     77    {
     78        cout << "ERROR - Too many bytes in command ZDAZ" << endl;
     79        return false;
     80    }
     81
     82    cout << "CC-COMMAND: Move " << zd << "deg " << az << "deg" << endl;
     83
     84    ZdAz za(zd, az);
     85
     86    cout << "MDriveCom - POSITION... start." << endl;
     87    fQueue->PostMsg(WM_POSITION, &za, sizeof(za));
     88    cout << "MDriveCom - POSITION... done." << endl;
     89    return true;
     90}
     91
    1092bool MDriveCom::InterpreteCmd(TString cmd, TString str)
    1193{
    12     if (cmd==(TString)"STOP!")
     94    if (cmd==(TString)"WAIT" && str.IsNull())
    1395    {
    14         cout << "Stop! " << str << endl;
     96        cout << "MDriveCom - WAIT... start." << endl;
     97        fQueue->PostMsg(WM_WAIT);
     98        cout << "MDriveCom - WAIT... done." << endl;
     99        return true;
     100    }
     101
     102    if (cmd==(TString)"STOP!" && str.IsNull())
     103    {
     104        cout << "MDriveCom - STOP!... start." << endl;
     105        fQueue->PostMsg(WM_STOP);
     106        cout << "MDriveCom - STOP!... done." << endl;
    15107        return true;
    16108    }
    17109
    18110    if (cmd==(TString)"RADEC")
     111        return CommandRADEC(str);
     112
     113    if (cmd==(TString)"ZDAZ")
     114        return CommandZDAZ(str);
     115
     116    if (cmd==(TString)"PREPS")
    19117    {
    20         cout << "RaDec: " << str << endl;
     118        cout << "Prepos: " << str << endl;
    21119        return true;
    22120    }
    23     if (cmd==(TString)"ZDAZ")
     121
     122    if (cmd.IsNull() && str.IsNull())
    24123    {
    25         cout << "ZdAz: " << str << endl;
    26         return true;
     124        cout << "Empty command (single '\\n') received." << endl;
     125        return false;
    27126    }
    28     if (cmd==(TString)"PREPS")
    29     {
    30         cout << "Preposs: " << str << endl;
    31         return true;
    32     }
    33     cout << "Unknown Command: " << cmd << str << endl;
     127
     128    cout << "Unknown Command: '" << cmd << "':'" << str << "'" << endl;
    34129    return false;
    35130}
Note: See TracChangeset for help on using the changeset viewer.