Ignore:
Timestamp:
05/15/04 16:46:27 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/tcpip
Files:
6 edited

Legend:

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

    r2615 r4076  
    22
    33#include <iostream>
     4
     5#include "MString.h"
    46
    57using namespace std;
     
    5355    }
    5456
    55     cout << "Zd/Az: " << zd << "/" << az << "   ";
    56     cout << "Ra/Dec: " << ra << "/" << dec << "   ";
    57     cout << "Temp: " << temp << "'C   ";
    58     cout << "Hum: " << hum << "%   ";
    59     cout << "SolRad: " << solar << "W/m²   ";
    60     cout << "Wind: " << wind << "km/h" << endl;
    61 
    6257    fHumidity = hum;
    6358    fTemperature = temp;
    6459    fSolarRadiation = solar;
    6560    fWindSpeed = wind;
     61
     62    cout << "Zd/Az: " << zd << "/" << az << "  ";
     63    cout << "Ra/Dec: " << ra/15 << "h/" << dec << "  ";
     64    cout << "SolRad: " << solar << "W/m²" << endl;
    6665
    6766    fComStat = kCmdReceived;
     
    8685}
    8786
    88 bool MCeCoCom::Send(const char *str)
     87bool MCeCoCom::Send(const char *cmd, const char *str)
    8988{
    9089    MTime t;
     
    10099    fT.GetTime(h2, m2, s2, ms2);
    101100
    102     const char *msg =
    103         Form("%s "
     101    MString msg;
     102    msg.Print("%s "
    104103             "%02d %04d %02d %02d %02d %02d %02d %03d "
    105104             "%02d %04d %02d %02d %02d %02d %02d %03d "
    106              "%s\n", (const char*)fCommand,
     105             "%s\n", cmd,
    107106             fStatus,  y1, mon1, d1, h1, m1, s1, ms1,
    108107             fComStat, y2, mon2, d2, h2, m2, s2, ms2,
     
    113112    return rc;
    114113}
     114
     115TString MCeCoCom::GetWeather() const
     116{
     117    if (fSolarRadiation<0 || (double)MTime(-1)-(double)fT>11)
     118        return "";
     119
     120    MString str;
     121    return str.Print("Temp: %.1f'C  Hum: %.1f%%  Wind: %.1fkm/h",
     122                     fTemperature, fHumidity, fWindSpeed);
     123}
     124
     125Int_t MCeCoCom::GetWeatherStatus() const
     126{
     127    if (fSolarRadiation<0 || (double)MTime(-1)-(double)fT>11)
     128        return 0;
     129
     130    Int_t rc = 0;
     131    if (fHumidity>80)
     132        rc++;
     133    if (fWindSpeed>20)
     134        rc++;
     135    if (fWindSpeed>30)
     136        rc++;
     137    if (fWindSpeed>50)
     138        rc++;
     139
     140    return rc;
     141}
  • trunk/MagicSoft/Cosy/tcpip/MCeCoCom.h

    r2615 r4076  
    2424    };
    2525
    26     TString fCommand;     // report string of the current system
     26    //TString fCommand;     // report string of the current system
    2727    MTime   fT;           // time of last report received
    2828    char    fStatus;      // current status of this system
     
    4343public:
    4444    MCeCoCom::MCeCoCom(const char *cmd, MLog &out=gLog)
    45         : MTcpIpIO(out), fCommand(cmd), fStatus(0), fComStat(kNoCmdReceived)
     45        : MTcpIpIO(out), /*fCommand(cmd),*/ fStatus(0), fComStat(kNoCmdReceived), fSolarRadiation(-1)
    4646    {
    4747    }
    4848
    49     bool Send(const char *str);
     49    bool Send(const char *cmd, const char *str);
    5050    void SetStatus(Byte_t s) { fStatus=s; }
    5151
    5252    Float_t GetHumidity() const { return fHumidity; }
    5353    Float_t GetTemperature() const { return fTemperature; }
     54    Float_t GetWindSpeed() const { return fWindSpeed; }
     55
     56    TString GetWeather() const;
     57    Int_t   GetWeatherStatus() const;
    5458};
    5559
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.cc

    r2618 r4076  
    66#include "MAstro.h"
    77#include "MCosy.h"
     8#include "MString.h"
    89
    910using namespace std;
     
    5354    }
    5455
    55     lout << "CC-COMMAND: Track " << ra << "h " << dec << "deg '" << str
    56 << "'" << endl;
     56    cout << "CC-COMMAND " << MTime(-1) << " RADEC " << ra << "h " << dec << "d '" << str << "'" << endl;
    5757
    5858    ra *= 15; // h -> deg
     
    6060    RaDec rd[2] = { RaDec(ra, dec), RaDec(ra, dec) };
    6161
    62     cout << "MDriveCom - TRACK... start." << endl;
     62    //cout << "MDriveCom - TRACK... start." << endl;
    6363    fQueue->PostMsg(WM_TRACK, &rd, sizeof(rd));
    64     cout << "MDriveCom - TRACK... done." << endl;
     64    //cout << "MDriveCom - TRACK... done." << endl;
    6565    return true;
    6666}
     
    8181    }
    8282
    83     lout << "CC-COMMAND: Move " << zd << "deg " << az << "deg" << endl;
     83    cout << "CC-COMMAND " << MTime(-1) << " ZDAZ " << zd << "deg " << az << "deg" << endl;
    8484
    8585    ZdAz za(zd, az);
    8686
    87     cout << "MDriveCom - POSITION... start." << endl;
     87    //cout << "MDriveCom - POSITION... start." << endl;
    8888    fQueue->PostMsg(WM_POSITION, &za, sizeof(za));
    89     cout << "MDriveCom - POSITION... done." << endl;
     89    //cout << "MDriveCom - POSITION... done." << endl;
    9090    return true;
    9191}
     
    9595    if (cmd==(TString)"WAIT" && str.IsNull())
    9696    {
    97         cout << "MDriveCom - WAIT... start." << endl;
     97        //cout << "MDriveCom - WAIT... start." << endl;
     98        cout << "CC-COMMAND " << MTime(-1) << " WAIT" << endl;
    9899        fQueue->PostMsg(WM_WAIT);
    99         cout << "MDriveCom - WAIT... done." << endl;
     100        //cout << "MDriveCom - WAIT... done." << endl;
    100101        return true;
    101102    }
     
    103104    if (cmd==(TString)"STOP!" && str.IsNull())
    104105    {
    105         cout << "MDriveCom - STOP!... start." << endl;
    106         lout << "CC-COMMAND: STOP!" << endl;       
     106        //cout << "MDriveCom - STOP!... start." << endl;
     107        cout << "CC-COMMAND " << MTime(-1) << " STOP!" << endl;
    107108        fQueue->PostMsg(WM_STOP);
    108         cout << "MDriveCom - STOP!... done." << endl;
     109        //cout << "MDriveCom - STOP!... done." << endl;
    109110        return true;
    110111    }
     
    124125    if (cmd.IsNull() && str.IsNull())
    125126    {
    126         cout << "Empty command (single '\\n') received." << endl;
     127        cout << "CC-COMMAND " << MTime(-1) << " Empty command (single '\\n') received." << endl;
    127128        return false;
    128129    }
    129130
    130     cout << "Unknown Command: '" << cmd << "':'" << str << "'" << endl;
     131    cout << "CC-COMMAND " << MTime(-1) << " Syntax error: '" << cmd << "':'" << str << "'" << endl;
    131132    return false;
    132133}
     
    139140    MAstro::Deg2Dms(deg, sgn, d, m, s);
    140141
    141     str += Form("%c %03d %02d %03d ", sgn, d, m, s);
     142    MString txt;
     143    str += txt.Print("%c %03d %02d %03d ", sgn, d, m, s);
    142144}
    143145
     
    148150    // is [deg]
    149151    // er [rad]
     152    const MTime t(-1);
    150153
    151154    rd *= kRad2Deg;
     
    165168        SetStatus(4);
    166169
    167     MTime t;
    168     t.Now();
     170    MString txt;
    169171
    170172    TString str;
     
    172174    Print(str, rd.Dec());   // Dec
    173175    Print(str, 0);          // HA
    174     str += Form("%12.6f ", t.GetMjd()); // mjd
     176    str += txt.Print("%12.6f ", t.GetMjd()); // mjd
    175177    Print(str, so.Zd());
    176178    Print(str, so.Az());
    177179    Print(str, is.Zd());
    178180    Print(str, is.Az());
    179     str += Form("%08.3f ", er.Zd());
    180     str += Form("%08.3f", er.Az());
     181    str += txt.Print("%08.3f ", er.Zd());
     182    str += txt.Print("%08.3f", er.Az());
    181183
    182     return Send(str);
     184    return Send("DRIVE-REPORT", str);
    183185}
     186
     187bool MDriveCom::SendStatus(const char *stat)
     188{
     189    return Send("DRIVE-STATUS", stat);
     190}
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.h

    r2517 r4076  
    3737
    3838    bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er);
     39    bool SendStatus(const char *stat);
    3940};
    4041
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc

    r2517 r4076  
    3333     */
    3434
    35 MTcpIpIO::MTcpIpIO(MLog &out) : MThread(false), Log(out), fRxSocket(NULL), fServSock(NULL)
     35MTcpIpIO::MTcpIpIO(MLog &out)
     36    : MThread(false), Log(out), fRxSocket(NULL), fServSock(NULL), fSendInterval(1000)
    3637{
    3738    fTxSocket = new TSocket("ceco", 7304);
     
    4950    // Now delete all TCP/IP objects
    5051    //
    51     cout << "Delete TxSocket " << fTxSocket << "..." << flush;
     52    //cout << "Delete TxSocket " << fTxSocket << "..." << flush;
    5253    delete fTxSocket;
    53     cout << "Done." << endl;
     54    //cout << "Done." << endl;
    5455    if (fServSock)
    5556    {
    56         cout << "Delete ServSock " << fServSock << "..." << flush;
     57        //cout << "Delete ServSock " << fServSock << "..." << flush;
    5758        delete fServSock;
    58         cout << "Done." << endl;
     59        //cout << "Done." << endl;
    5960    }
    6061    if (fRxSocket)
    6162    {
    62         cout << "Delete RxSocket " << fRxSocket << "..." << flush;
     63        //cout << "Delete RxSocket " << fRxSocket << "..." << flush;
    6364        delete fRxSocket;
    64         cout << "Done." << endl;
     65        //cout << "Done." << endl;
    6566    }
    6667}
     
    6869bool MTcpIpIO::Send(const char *msg)
    6970{
     71    const MTime t(-1);
     72
     73    if ((double)t-(double)fTime<0.001*fSendInterval)
     74        return true;
     75
     76    const Int_t rc = lout.IsOutputDeviceEnabled(MLog::eGui);
     77    lout.DisableOutputDevice(MLog::eGui);
     78    lout.Lock();
     79    lout << msg << flush;
     80    lout.UnLock();
     81    if (rc)
     82        lout.EnableOutputDevice(MLog::eGui);
     83
     84    fTime = t;
     85
    7086    if (!fTxSocket->IsValid())
    7187        return false;
     
    112128            switch (fServSock->GetErrorCode())
    113129            {
    114             case 0: cout << "No error." << endl; break;
     130            case  0: cout << "No error." << endl; break;
    115131            case -1: cout << "low level socket() call failed." << endl; break;
    116132            case -2: cout << "low level bind() call failed." << endl; break;
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h

    r2384 r4076  
    77#ifndef COSY_Log
    88#include "log.h"
     9#endif
     10#ifndef MARS_MTime
     11#include "MTime.h"
    912#endif
    1013
     
    1922    TSocket       *fRxSocket;
    2023    TServerSocket *fServSock;
     24
     25    MTime fTime;
     26    Int_t fSendInterval; // [ms]
    2127
    2228    void Clear();
Note: See TracChangeset for help on using the changeset viewer.