Index: /trunk/Cosy/Changelog
===================================================================
--- /trunk/Cosy/Changelog	(revision 10030)
+++ /trunk/Cosy/Changelog	(revision 10031)
@@ -31,4 +31,43 @@
    * */Makefile, Makefile*:
      - removed necessity of defining OSTYPE
+
+   * Makefile.rules:
+     - replaced cvs by svn
+
+   * tpoint/TPointGui.cc:
+     - included stdlib.h
+
+   * devdrv/dkc.[h,cc]:
+     - added five-byte error massages from IndraDrive
+     + for errnum and errinf are no coded with 1+5 byte
+       instead of 2+4
+     - added UPS information to PDO3, consequently changed fStatusPDO3
+       from BYTE_t to WORD_t
+     + fixed in the SPS that the armed status was not transmitted in the
+       correct byte
+     - adapted inline functions accordingly
+
+   * cosy.cc:
+     - added a debug line to see when the gui is up 
+     - removed receiver port from instantiation of Ethernet
+
+   * candrv/ethernet.[h,cc]:
+     - replaced bidirectional Tcp/Ip sockets by an unidirectional one,
+       thus only one party (cosy) connects (to the SPS)
+     - removed dependancy on MTcpIpI and replaced by new class MTcpIpOI
+     - removed obsolete fTxAddress and fTxPort
+     - only start thread if it is not already running to prevent parallel
+       connection attempts on the same socket
+     + IsConnectionstablished is not evaluated yet
+
+   * tcpip/MTcpIpIO.[h,cc]:
+     - removed empty destructor of MTcpIpIO
+     - changed typical reconnection time from 30s to 3s. This seems 
+       more reasonably adapted to human behaviour
+     - added new class MTcpIpOI which is a bi-directional communication
+       channel via TCP/IP
+
+   * main/MCosy.cc:
+     - correctly propagate the pdo3 status
 
 
Index: /trunk/Cosy/candrv/ethernet.cc
===================================================================
--- /trunk/Cosy/candrv/ethernet.cc	(revision 10030)
+++ /trunk/Cosy/candrv/ethernet.cc	(revision 10031)
@@ -55,6 +55,6 @@
 //  and switch the can bus communication on
 //
-Ethernet::Ethernet(const char *addr, const int tx, const int rx, CanOpen *receiver)
-    : MTcpIpI(rx), /*MTcpIpO(addr, tx),*/ Interface(receiver), fTxAddress(addr), fTxPort(tx)
+Ethernet::Ethernet(const char *addr, const int tx, CanOpen *receiver)
+    : MTcpIpOI(addr, tx), Interface(receiver)
 {
     gLog << inf2 << "- Ethernet initialized." << endl;
@@ -68,5 +68,5 @@
 Ethernet::~Ethernet()
 {
-    MTcpIpI::CancelThread();
+    CancelThread();
     gLog << inf2 << "- Ethernet stopped." << endl;
 }
@@ -79,11 +79,12 @@
 
     Message msg;
+    msg.len = 0;
     msg.cmd = M_BCAN_RX_ind;
     msg.data[0] = 0;
     msg.data[1] = 0;
 
-    const TString address = MTcpIpO::GetSocketAddress(rx);
-
-    while (!MTcpIpI::IsThreadCanceled())
+    const TString address = GetSocketAddress(rx);
+
+    while (!IsThreadCanceled())
     {
         unsigned char c;
@@ -280,26 +281,9 @@
     st.Start();
 #endif
-    MTcpIpO::SendFrame(fTxAddress, fTxPort, (char*)(msg.data+1), msg.len-1);
-//    Send((char*)(msg.data+1), msg.len-1);
+
+    Send((char*)(msg.data+1), msg.len-1);
+
 #ifdef DEBUG
     st.Print();
 #endif
-    //Send((char*)(msg.data+1), msg.len-1);
-
-    /*
-    const WORD_t desc = MsgDescr(cobid, 8, rtr);
-
-    Message msg;
-
-    msg.cmd = M_BCAN_TX_req;
-
-    msg.len = 12;
-    msg.data[0]  = 0;
-    msg.data[1]  = 0;
-    msg.data[2]  = word_to_msb(desc);
-    msg.data[3]  = word_to_lsb(desc);
-
-    memcpy(&msg.data[4], m, 8);
-
-    while (!Send(&msg));*/
-}
+}
Index: /trunk/Cosy/candrv/ethernet.h
===================================================================
--- /trunk/Cosy/candrv/ethernet.h	(revision 10030)
+++ /trunk/Cosy/candrv/ethernet.h	(revision 10031)
@@ -10,21 +10,16 @@
 #endif
 
-class Ethernet : public MTcpIpI, /*public MTcpIpO,*/ public Interface
+class Ethernet : public MTcpIpOI, public Interface
 {
 private:
-    TString fTxAddress;
-    Int_t   fTxPort;
-
     // Send interface based on MTcpIpI
     Bool_t ReadSocket(TSocket &rx);
 
     // Start/stop communication inherited from Interface
-    void Start() { MTcpIpI::RunThread(); }
-    void Stop()  { MTcpIpI::CancelThread(); }
-
-    Bool_t HasConnection() const { return MTcpIpI::IsConnectionEstablished(); }
+    void Start() { if (!IsThreadRunning()) RunThread(); }
+    void Stop()  { CancelThread(); }
 
 public:
-    Ethernet(const char *addr, const int tx, const int rx, CanOpen *receiver);
+    Ethernet(const char *addr, const int tx, CanOpen *receiver);
     virtual ~Ethernet();
 
Index: /trunk/Cosy/cosy.cc
===================================================================
--- /trunk/Cosy/cosy.cc	(revision 10030)
+++ /trunk/Cosy/cosy.cc	(revision 10031)
@@ -253,5 +253,5 @@
     com->SetMsgQueue(cosy);
 
-    Interface *interface = new Ethernet(sps, 5357, 5358, cosy);
+    Interface *interface = new Ethernet(sps, 5357, cosy);
     // Interface *interface = new VmodIcan(cosy, "/dev/dpm_00", 125);
 
@@ -259,4 +259,6 @@
 
     cosy->Start(env);
+
+    gLog << all << "- MCosy started." << endl;
 
     // FIXME: Is this the right position?
Index: /trunk/Cosy/tcpip/MTcpIpIO.cc
===================================================================
--- /trunk/Cosy/tcpip/MTcpIpIO.cc	(revision 10030)
+++ /trunk/Cosy/tcpip/MTcpIpIO.cc	(revision 10031)
@@ -67,8 +67,4 @@
 }
 
-MTcpIpIO::~MTcpIpIO()
-{
-}
-
 TString MTcpIpO::GetSocketAddress(const TSocket &s)
 {
@@ -192,5 +188,87 @@
 
         MThread::Sleep(wait); // Wait a ms
-        if (wait<30000000) // 30s
+        if (wait<3000000) // 3s
+            wait *= 2;
+    }
+
+    return 1;
+}
+
+Int_t MTcpIpOI::Thread()
+{
+    fConnectionEstablished = kFALSE;
+
+    const TInetAddress &a = fTxSocket->GetInetAddress();
+    if (!a.IsValid())
+    {
+        gLog << err << "- MTcpIpOI::Thread - ERROR: Send socket address invalid." << endl;
+        return 0;
+    }
+
+    gLog << inf << "- MTcpIpOI::Thread created connecting to " << a.GetHostAddress() << ":" << fPortTx << endl;
+
+    Int_t wait = 1000; /// Wait a ms
+
+    MTimeout timeout(fTimeout);
+
+    while (!IsThreadCanceled())
+    {
+        if (fTxSocket->IsValid())
+        {
+            fConnectionEstablished = kTRUE;
+            fTimeout = 1000;
+
+            // Get connection on port fPortRx and redirected
+            // Check for pending data (every ms)
+            switch (fTxSocket->Select(TSocket::kRead, 1))
+            {
+            case kTRUE:  // Data pending... go on reading
+                if (!ReadSocket(*fTxSocket))
+                {
+                    gLog << warn << MTime(-1) << " WARNING - Connection lost to " << MTcpIpO::GetSocketAddress(*fTxSocket) << endl;
+                    fTxSocket->Close();
+                    continue;
+                }
+                timeout.Start(fTimeout);
+                continue;
+
+            case kFALSE: // Time out, no data yet, go on waiting
+              if (timeout.HasTimedOut())
+              {
+                  gLog << warn << MTime(-1) << " WARNING - Connection to " << MTcpIpO::GetSocketAddress(*fTxSocket) << " timed out after " << fTimeout << "ms." << endl;
+                  fTxSocket->Close();
+                  continue;
+              }
+              continue;
+
+            default:  // Error occurance
+                gLog << err << "TSocket::Select returned an error: " << strerror(errno) << endl;
+                fTxSocket->Close();
+                continue;
+            }
+        }
+
+        fConnectionEstablished = kFALSE;
+
+#ifdef DEBUG
+        cout << "- Reopen send socket to " << a.GetHostAddress() << ":" << fPortTx << endl;
+#endif
+
+        fMutex.Lock();
+
+        delete fTxSocket;
+
+        fTxSocket = new TSocket(a.GetHostAddress(), fPortTx);
+        fTxSocket->SetOption(kNoBlock, 1);
+
+        fMutex.UnLock();
+
+        timeout.Start(fTimeout);
+
+        if (fTxSocket->IsValid())
+            continue;
+
+        MThread::Sleep(wait); // Wait a ms
+        if (wait<3000000) // 3s
             wait *= 2;
     }
Index: /trunk/Cosy/tcpip/MTcpIpIO.h
===================================================================
--- /trunk/Cosy/tcpip/MTcpIpIO.h	(revision 10030)
+++ /trunk/Cosy/tcpip/MTcpIpIO.h	(revision 10031)
@@ -46,5 +46,5 @@
 class MTcpIpO : public MThread
 {
-private:
+protected:
     TSocket *fTxSocket;
     TMutex   fMutex;
@@ -73,8 +73,21 @@
 public:
     MTcpIpIO(const char *addr, Int_t tx, Int_t rx, UInt_t timeout=5000);
-    ~MTcpIpIO();
 
     virtual bool InterpreteStr(TString str);
 };
 
+class MTcpIpOI : public MTcpIpO
+{
+private:
+    Int_t Thread();
+    virtual Bool_t ReadSocket(TSocket &rx) = 0;
+
+    Bool_t fConnectionEstablished;
+    Int_t  fTimeout;    // [ms] Timeout to listen for data to be received
+public:
+    MTcpIpOI(const char *addr, Int_t tx, UInt_t timeout=5000) : MTcpIpO(addr, tx), fConnectionEstablished(kFALSE), fTimeout(timeout) { }
+
+    Bool_t IsConnectionEstablished() const { return fConnectionEstablished; }
+};
+
 #endif
