Ignore:
Timestamp:
02/13/08 19:44:39 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Cosy/tcpip
Files:
4 edited

Legend:

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

    r8856 r8862  
    4848
    4949public:
    50     MCeCoCom(MLog *out)
    51         : MTcpIpIO("ceco", 7304, 7404), fOut(out), fStatus(0), fComStat(kNoCmdReceived),
     50    MCeCoCom(const char *addr, MLog *out)
     51        : MTcpIpIO(addr, 7304, 7404), fOut(out), fStatus(0), fComStat(kNoCmdReceived),
    5252        fHumidity(0), fTemperature(0), fWindSpeed(0), fSolarRadiation(-1),
    5353        fAlarmCounter(0)
  • trunk/MagicSoft/Cosy/tcpip/MDriveCom.h

    r8816 r8862  
    4141    };
    4242
    43     MDriveCom(MsgQueue *q, MLog *out) : MCeCoCom(out), fQueue(q) {}
     43    MDriveCom(MsgQueue *q, const char *addr, MLog *out) : MCeCoCom(addr, out), fQueue(q) {}
    4444
    4545    bool SendReport(UInt_t stat, RaDec rd, ZdAz so, ZdAz is, ZdAz er);
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.cc

    r8856 r8862  
    88#include "MLog.h"
    99#include "MLogManip.h"
     10
     11#include "MString.h"
    1012
    1113#undef DEBUG
     
    5557}
    5658
     59TString MTcpIpO::GetSocketAddress(const TSocket &s)
     60{
     61    if (!s.IsValid())
     62        return "n/a";
     63
     64    const TInetAddress &a = s.GetInetAddress();
     65    if (!a.IsValid())
     66        return "undefined";
     67
     68    return MString::Format("%s:%d", a.GetHostAddress(), a.GetPort());
     69}
     70
     71TString MTcpIpO::GetSocketAddress() const
     72{
     73    return GetSocketAddress(*fTxSocket);
     74}
     75
    5776bool MTcpIpO::SendFrame(TSocket &tx, const char *msg, int len)
    5877{
    5978    if (!tx.IsValid())
    6079    {
    61         //cout << "*!* Transmit socket invalid!" << endl;
     80        //gLog << warn << "WARNING - No transmission to " << GetSocketAddress(tx) << " possible." << endl;
    6281        return false;
    6382    }
     
    6685    if (l<0)
    6786    {
    68         cout << "ERROR - Sending Message" << endl;
     87        gLog << err << "ERROR - Sending TCP/IP frame to " << GetSocketAddress(tx) << endl;
    6988        return false;
    7089    }
     
    7291    if (l!=len)
    7392    {
    74         cout << "Send wrong number (" << l << ") of Bytes." << endl;
     93        gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << GetSocketAddress(tx) << endl;
    7594        return false;
    7695    }
     
    86105{
    87106    //    R__LOCKGUARD2(myMutex);
    88 
     107#ifdef DEBUG
    89108    cout << "Connecting to " << addr << ":" << port << endl;
     109#endif
    90110
    91111    // FIXME: Set tx-socket to nonblocking?
    92112    TSocket tx(addr, port);
    93     //    return SendFrame(tx, msg, len);
    94 
     113    return SendFrame(tx, msg, len);
     114/*
    95115    if (!tx.IsValid())
    96116    {
    97         //cout << "*!* Transmit socket invalid!" << endl;
    98         return false;
    99     }
    100 
    101     cout << "Sending to " << addr << ":" << port << endl;
     117        gLog << warn << "WARNING - No transmission to " << addr << ":" << port << " possible." << endl;
     118        return false;
     119    }
     120
     121    gLog << dbg << "Sending to " << addr << ":" << port << endl;
    102122
    103123    const Int_t l = tx.SendRaw(msg, len, kDontBlock);
    104124    if (l<0)
    105125    {
    106         cout << "ERROR - Sending Message" << endl;
     126        gLog << err << "ERROR - Sending TCP/IP frame to " << addr << ":" << port << endl;
    107127        return false;
    108128    }
     
    110130    if (l!=len)
    111131    {
    112         cout << "Send wrong number (" << l << ") of Bytes." << endl;
     132        gLog << err << "ERROR - Sent wrong number (" << l << ") of bytes to " << addr << ":" << port << endl;
    113133        return false;
    114134    }
     
    119139
    120140    return true;
     141    */
    121142}
    122143
     
    188209    gLog << inf << "- Starting receiver on port " << fPortRx << "..." << endl;
    189210
     211//    if (fPortRx==7404)
     212//    {
     213//        gLog << err << "CeCo communication skipped." << endl;
     214//        return 0;
     215//    }
     216
    190217    TServerSocket *fServSock=NULL;
    191218    TSocket       *fRxSocket=NULL;
     
    197224        if (!fServSock->IsValid())
    198225        {
    199             cout << "ServerSocket on port " << fPortRx << " invalid: ";
     226            gLog << err << "ServerSocket on port " << fPortRx << " invalid: ";
    200227            switch (fServSock->GetErrorCode())
    201228            {
    202             case  0: cout << "No error." << endl; break;
    203             case -1: cout << "low level socket() call failed." << endl; break;
    204             case -2: cout << "low level bind() call failed." << endl; break;
    205             case -3: cout << "low level listen() call failed." << endl; break;
    206             default: cout << "Unknown." << endl; break;
     229            case  0: gLog << "No error." << endl; break;
     230            case -1: gLog << "low level socket() call failed." << endl; break;
     231            case -2: gLog << "low level bind() call failed." << endl; break;
     232            case -3: gLog << "low level listen() call failed." << endl; break;
     233            default: gLog << "Unknown." << endl; break;
    207234            }
    208235            delete fServSock;
     
    214241        fServSock->SetOption(kNoBlock, 1);
    215242
    216         cout << "Waiting for connection on port " << fPortRx << "..." << endl;
     243        gLog << all << "Waiting for connection on port " << fPortRx << "..." << endl;
    217244//        while (!HasStopFlag() && (Long_t)fRxSocket<=0)
    218245        while (!IsThreadCanceled() && (Long_t)fRxSocket<=0)
     
    247274        }
    248275
    249         cout << "Connection established on port " << fPortRx << "." << endl;
     276        gLog << all << "Connection established on port " << fPortRx << "." << endl;
    250277
    251278        fRxSocket->SetOption(kNoBlock, 1);
  • trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h

    r8856 r8862  
    4040    ~MTcpIpO();
    4141
    42     static bool SendFrame(TSocket &tx, const char *msg, int len);
    43     static bool SendFrame(const char *addr, int port, const char *msg, int len);
     42    static TString GetSocketAddress(const TSocket &s);
     43    static bool    SendFrame(TSocket &tx, const char *msg, int len);
     44    static bool    SendFrame(const char *addr, int port, const char *msg, int len);
    4445
    45     bool Send(const char *msg, int len);
     46    TString GetSocketAddress() const;
     47    bool    Send(const char *msg, int len);
    4648};
    4749
Note: See TracChangeset for help on using the changeset viewer.