Index: /trunk/MagicSoft/Cosy/candrv/canopen.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/canopen.cc	(revision 8812)
+++ /trunk/MagicSoft/Cosy/candrv/canopen.cc	(revision 8813)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz <mailto:tbretz@astro.uni-wuerzburg.de>, 2003
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2008
 !
 !
@@ -32,6 +32,8 @@
 #include "canopen.h"
 
-#include <iostream> // cout
-#include <iomanip>  // setw, setfill
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "interface.h"
 
 ClassImp(CanOpen);
@@ -44,7 +46,7 @@
 // PDO combinations
 //
-CanOpen::CanOpen(const char *dev, const int baud, MLog &out) : VmodIcan(dev, baud, out)
-{
-    lout << "- CanOpen initialized." << endl;
+CanOpen::CanOpen() : fInterface(0)
+{
+    gLog << inf << "- CanOpen initialized." << endl;
 }
 
@@ -55,10 +57,30 @@
 CanOpen::~CanOpen()
 {
-    lout << "- CanOpen destroyed." << endl;
-}
-
-// --------------------------------------------------------------------------
-//
-// This overloads VmodIcan::HandleCanMessage. It is called if a can
+    gLog << inf << "- CanOpen destroyed." << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Start the interface
+//
+void CanOpen::Start()
+{
+    if (fInterface)
+        fInterface->Start();
+}
+
+// --------------------------------------------------------------------------
+//
+// Stop the interface
+//
+void CanOpen::Stop()
+{
+    if (fInterface)
+        fInterface->Stop();
+}
+
+// --------------------------------------------------------------------------
+//
+// This overloads Interface::HandleCanMessage. It is called if a can
 // message was received with all message relevant data (COBId, data, time)
 // It distributes the data depending on its function code to several
@@ -69,5 +91,5 @@
 //  HandlePDO1/2/3/4:handles received PDOs
 //
-void CanOpen::HandleCanMessage(WORD_t cobid, BYTE_t *data, timeval_t *tv)
+void CanOpen::HandleCanMessage(WORD_t cobid, const BYTE_t *data, const timeval_t &tv)
 {
     const WORD_t fcode = cobid >> 7;
@@ -105,4 +127,5 @@
             const WORD_t  subidx = data[3];
 
+            cout << "SND NODE: " << (int)node << " " << flush;
             HandleSDO(node, cmd, idx, subidx, dat, tv);
 
@@ -145,4 +168,161 @@
 // --------------------------------------------------------------------------
 //
+// Does a basic message processing and hadles the so called command (cmd)
+// stamp of the message. This is some kind of message type which is send
+// by the can interface
+//
+void CanOpen::HandleMessage(const Message &msg, const timeval_t &tv)
+{
+    //
+    // Decode message
+    //
+    const WORD_t desc  = msg.data[2]<<8 | msg.data[3];
+    const BYTE_t rtr   = (desc>>4)&1;
+    const BYTE_t len   = desc&0xf;
+    const WORD_t cobid = desc>>5;
+
+    switch (msg.cmd) // FROM mican.h
+    {
+    case M_MSG_LOST:
+        cout << "Interface reports: " << dec << (int)msg.data[0] << " msg(s) lost!" << endl;
+        return;
+
+    case M_BCAN_TX_con:  /* confirm (+/-) transmission */
+        cout << "Interface reports: CTXcon=0x35" << endl;
+        cout << "This normally means, that the transmission of the following CAN frame failed:" << hex << endl;
+        cout << "Descr: 0x" << cobid << dec;
+        cout << "  Rtr: "   << (rtr?"Yes":"No");
+        cout << "  Len: "   << (int)len << endl;
+        return;
+
+    case M_BCAN_EVENT_ind:
+        cout << "Interface reports: CEVTind=0x37: " << hex;
+        switch (msg.data[0]) // error indicator
+        {
+        case 0x01:
+            cout << "Error interrup occured" << endl;
+            cout << "This means noisy network normally. Please check the bus termination." << endl;
+            switch (msg.data[1]) // msg type (board depending)
+            {
+            case 2: // SJA1000
+                cout << dec;
+                cout << "ModeReg=" << (int)msg.data[2] << ", ";
+                cout << "StatReg=" << (int)msg.data[3] << ", ";
+                cout << "RxErrCnt=" << (int)msg.data[4] << ", ";
+                cout << "TxErrCnt=" << (int)msg.data[5] << endl;
+            }
+            //FIXME? TerminateApp();
+            return;
+        case 0x02:
+            cout << "Overrun interrup occured" << endl;
+            return;
+        case 0x04:
+            cout << "Interrupts lost" << endl;
+            return;
+        case 0x08:
+            cout << "Send queue full" << endl;
+            return;
+        case 0x10:
+            cout << "CANbus bus-error" << endl;
+            return;
+        }
+        return;
+    case M_BCAN_RX_ind:
+        //
+        // Message is a message from the Can bus
+        //
+        //cout << "HandleCanMessage " << cobid << endl;
+        HandleCanMessage(cobid, &msg.data[4], tv);
+        return;
+    }
+
+    //
+    // Nothing of the above happened
+    //
+    cout << hex;
+    cout << "Cmd=0x"    << (int)msg.cmd << ":  ";
+    cout << "Descr: 0x" << cobid << dec;
+    cout << "  Rtr: "   << (rtr?"Yes":"No");
+    cout << "  Len: "   << (int)len << endl;
+
+    cout << "As Raw Data:" << hex << setfill('0');
+    for (int i=0; i<msg.len; i++)
+        cout << " " << setw(2) << (int)(msg.data[i]) << flush;
+    cout << endl;
+}
+
+bool CanOpen::WaitForSdos(WORDS_t ms)
+{
+    // 0: unlimited
+    // <0: don't do a real wait.
+    if (ms<0)
+    {
+        fSdoList.DelAll();
+        return true;
+    }
+
+    MTimeout t(ms);
+    while (fSdoList.IsPending() &&
+           !StopWaitingForSDO() &&
+           !t.HasTimedOut())
+        usleep(1);
+
+    bool rc = true;
+    if (ms && t.HasTimedOut())
+    {
+        cout << "WaitForSdos timed out." << endl;
+        rc = false;
+    }
+    /*
+     if (StopWaitingForSDO())
+     {
+     cout << "WaitForSdos stopped." << endl;
+     rc = false;
+     }
+     */
+    if ((ms && t.HasTimedOut()) || StopWaitingForSDO())
+        fSdoList.DelAll();
+
+    return rc;
+}
+
+bool CanOpen::WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms)
+{
+    // 0: unlimited
+    // <0: don't do a real wait.
+
+    if (ms<0)
+    {
+        fSdoList.Del(node, idx, subidx);
+        return true;
+    }
+
+    MTimeout t(ms);
+    while (fSdoList.IsPending(node, idx, subidx) &&
+           !StopWaitingForSDO() &&
+           !t.HasTimedOut())
+        usleep(1);
+
+    bool rc = true;
+    if (ms && t.HasTimedOut())
+    {
+        cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " timed out." << endl;
+        rc = false;
+    }
+    /*
+     if (StopWaitingForSDO())
+     {
+     cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " stopped." << endl;
+     rc = false;
+     }
+     */
+    if ((ms && t.HasTimedOut()) || StopWaitingForSDO())
+        fSdoList.Del(node, idx, subidx);
+
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
 // Enables can messaged for a given node ID and function code.
 //
@@ -152,5 +332,6 @@
         return;
 
-    EnableCobId(CobId(node, fcode), flag);
+    if (fInterface)
+        fInterface->EnableCobId(CobId(node, fcode), flag);
 }
 
@@ -260,6 +441,6 @@
 //
 void CanOpen::SendPDO1(BYTE_t node,
-              BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
-              BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
+              BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
+              BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
 {
     BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
@@ -272,6 +453,6 @@
 //
 void CanOpen::SendPDO2(BYTE_t node,
-              BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
-              BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
+              BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
+              BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
 {
     BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
@@ -284,6 +465,6 @@
 //
 void CanOpen::SendPDO3(BYTE_t node,
-              BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
-              BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
+              BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
+              BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
 {
     BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
@@ -296,6 +477,6 @@
 //
 void CanOpen::SendPDO4(BYTE_t node,
-              BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
-              BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0)
+              BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
+              BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
 {
     BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
@@ -394,4 +575,46 @@
 // --------------------------------------------------------------------------
 //
+// This is IcSendReqBCAN from the Janz software
+//
+//  /*
+//   * IcSendReqBCAN - Send a CANbus message
+//   *
+//   * Issue request to send a CAN message. <Spec> controls whether to send with
+//   * or without spec/confirmation.
+//   * .CS
+//   *    spec     action
+//   *      0      send only
+//   *      1      send with confirmation to the host.
+//   *      2      send and echo message to the host.
+//   *      3      send and generate both echo and confirmation.
+//   * .CE
+//   *
+//   * SERVICE: CTXreq, CTXCreq, CTXEreq, CTXCEreq
+//   *
+//   * NOTE:
+//   * Raw ICANOS version of the firmware only.
+//   */
+//
+void CanOpen::SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr)
+{
+    if (fInterface)
+        fInterface->SendCanFrame(cobid, m, rtr);
+}
+
+// --------------------------------------------------------------------------
+//
+// Sends a can frame with the given cobid and the given eight bytes
+// through the can network
+//
+void CanOpen::SendCanFrame(WORD_t cobid,
+                           BYTE_t m0, BYTE_t m1, BYTE_t m2, BYTE_t m3,
+                           BYTE_t m4, BYTE_t m5, BYTE_t m6, BYTE_t m7)
+{
+    BYTE_t msg[8] = { m0, m1, m2, m3, m4, m5, m6, m7 };
+    SendCanFrame(cobid, msg);
+}
+
+// --------------------------------------------------------------------------
+//
 // Decodes node and function code into a CobId
 //
Index: /trunk/MagicSoft/Cosy/candrv/canopen.h
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/canopen.h	(revision 8812)
+++ /trunk/MagicSoft/Cosy/candrv/canopen.h	(revision 8813)
@@ -9,9 +9,8 @@
 #include "sdolist.h"
 #endif
-#ifndef COSY_VmodIcan
-#include "vmodican.h"
+
+#ifndef COSY_MTimeout
+#include "MTimeout.h"
 #endif
-
-#include "MTimeout.h"
 
 #ifdef __CINT__
@@ -65,27 +64,41 @@
 #define kDontWait      (-1)
 
-class CanOpen : public VmodIcan
+class Interface;
+
+typedef struct timeval timeval_t;
+
+class CanOpen
 {
 private:
-    PendingSDOList fSdoList;
+    Interface     *fInterface;      // Handle to the I/O interface
+    PendingSDOList fSdoList;        // List for pending SDOs
+    TCondition     fPdoCond[32][4]; // one for every PDO of every node
 
-    TCondition fPdoCond[32][4]; // one for every PDO of every node
-//    pthread_cond_t  fPdoCond[32][4];
-//    pthread_mutex_t fPdoMux[32][4];
+protected:
+    virtual void Start();           // Start CanOpen communication
+    virtual void Stop();            // Stop  CanOpen communcation
 
-    void HandleCanMessage(WORD_t cobid, BYTE_t *data, timeval_t *tv);
+private:
+    //
+    // Handle can objects arrived at the CanOpen interface
+    //
+    virtual void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv)=0;
+    virtual void HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0;
+    virtual void HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0;
+    virtual void HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0;
+    virtual void HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv)=0;
+    virtual void HandleNodeguard(BYTE_t node, const timeval_t &tv)=0;
+    virtual void HandleEmergency(BYTE_t node, const timeval_t &tv)=0;
 
-    virtual void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)=0;
-    virtual void HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv)=0;
-    virtual void HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv)=0;
-    virtual void HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv)=0;
-    virtual void HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv)=0;
-    virtual void HandleNodeguard(BYTE_t node, timeval_t *tv)=0;
-    virtual void HandleEmergency(BYTE_t node, timeval_t *tv)=0;
+    // Handle message arrived at the CanOpen interface and split into can objects
+    virtual void HandleCanMessage(WORD_t cobid, const BYTE_t *data, const timeval_t &tv);
 
 public:
-    CanOpen(const char *dev, const int baud, MLog &out=gLog);
+    CanOpen();
     virtual ~CanOpen();
 
+    void SetInterface(Interface *f) { fInterface=f; } // Set Handle to the interface
+
+    // Send a Process Data Object (PDO) to the CanOpen bus
     void SendPDO1(BYTE_t node, BYTE_t data[8]);
     void SendPDO2(BYTE_t node, BYTE_t data[8]);
@@ -105,4 +118,5 @@
                   BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
 
+    // Send a Service Data Object (SDO) to a CanOpen device (aka. write parameter)
     void SendSDO(BYTE_t node, WORD_t idx, BYTE_t subidx, BYTE_t val, bool store);
     void SendSDO(BYTE_t node, WORD_t idx, BYTE_t subidx, WORD_t val, bool store);
@@ -113,11 +127,12 @@
     void SendSDO(BYTE_t node, WORD_t idx, LWORD_t val, bool store)  { SendSDO(node, idx, 0, val, store); }
 
+    // Send other objects
     void SendNMT(BYTE_t node, BYTE_t cmd);
     void SendNodeguard(BYTE_t node);
 
+    // Request a Service Data Object (SDO) from a CanOpen device (aka. read parameter)
     void RequestSDO(BYTE_t node, WORD_t idx, BYTE_t subidx=0);
 
-    void EnableCanMsg(BYTE_t node, BYTE_t fcode, int flag=TRUE);
-
+    // Enable interface for pass-through of a kind of can-object
     void EnableSdoRx(BYTE_t node);
     void EnablePdo1Rx(BYTE_t node);
@@ -128,4 +143,8 @@
     void EnableNodeguard(BYTE_t node);
 
+    // Enable interface for pass-through of a can-object
+    void EnableCanMsg(BYTE_t node, BYTE_t fcode, int flag=TRUE);
+
+    // Wait until the next Pdo object has arrived
     void WaitForNextPdo1(BYTE_t node) { node -= 1; fPdoCond[node][0].Wait(); }
     void WaitForNextPdo2(BYTE_t node) { node -= 1; fPdoCond[node][1].Wait(); }
@@ -133,81 +152,20 @@
     void WaitForNextPdo4(BYTE_t node) { node -= 1; fPdoCond[node][3].Wait(); }
 
-    //
-    // This function must
-    //
+    // Wait for arrival of a return to a given Sdo (or all axpected Sdos)
+    bool WaitForSdos(WORDS_t ms=500);
+    bool WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms=500);
+
     virtual int StopWaitingForSDO() const { return FALSE; }
 
-    bool WaitForSdos(WORDS_t ms=500)
-    {
-        // 0: unlimited
-        // <0: don't do a real wait.
-        if (ms<0)
-        {
-            fSdoList.DelAll();
-            return true;
-        }
+    // Low level function to send rawcan frames
+    void SendCanFrame(WORD_t cobid, BYTE_t m[8], BYTE_t rtr=0);
+    void SendCanFrame(WORD_t cobid,
+                      BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
+                      BYTE_t m4=0, BYTE_t m5=0, BYTE_t m6=0, BYTE_t m7=0);
 
-        MTimeout t(ms);
-        while (fSdoList.IsPending() &&
-               !StopWaitingForSDO() &&
-               !t.HasTimedOut())
-            usleep(1);
+    // Extract the CanOpen message from the message delivered by the interface
+    void HandleMessage(const Message &msg, const timeval_t &tv);
 
-        bool rc = true;
-        if (ms && t.HasTimedOut())
-        {
-            cout << "WaitForSdos timed out." << endl;
-            rc = false;
-        }
-        /*
-         if (StopWaitingForSDO())
-        {
-            cout << "WaitForSdos stopped." << endl;
-            rc = false;
-        }
-        */
-        if ((ms && t.HasTimedOut()) || StopWaitingForSDO())
-            fSdoList.DelAll();
-
-        return rc;
-    }
-
-    bool WaitForSdo(BYTE_t node, WORD_t idx, BYTE_t subidx, WORDS_t ms=500)
-    {
-        // 0: unlimited
-        // <0: don't do a real wait.
-
-        if (ms<0)
-        {
-            fSdoList.Del(node, idx, subidx);
-            return true;
-        }
-
-        MTimeout t(ms);
-        while (fSdoList.IsPending(node, idx, subidx) &&
-               !StopWaitingForSDO() &&
-               !t.HasTimedOut())
-            usleep(1);
-
-        bool rc = true;
-        if (ms && t.HasTimedOut())
-        {
-            cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " timed out." << endl;
-            rc = false;
-        }
-        /*
-        if (StopWaitingForSDO())
-        {
-            cout << "WaitForSdo Node #" << (int)node << " " << idx << "/" << (int)subidx << " stopped." << endl;
-            rc = false;
-            }
-            */
-        if ((ms && t.HasTimedOut()) || StopWaitingForSDO())
-            fSdoList.Del(node, idx, subidx);
-
-        return rc;
-    }
-
-public:
+    // Compile CobId from node and function code
     WORD_t CobId(BYTE_t node, BYTE_t fcode) const;
 
Index: /trunk/MagicSoft/Cosy/candrv/network.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/network.cc	(revision 8812)
+++ /trunk/MagicSoft/Cosy/candrv/network.cc	(revision 8813)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz <mailto:tbretz@uni-sw.gwdg.de>, 2001
-!
-!   Copyright: MAGIC Software Development, 2000-2001
+!   Author(s): Thomas Bretz, 2001 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2008
 !
 !
@@ -32,8 +32,10 @@
 #include "network.h"
 
-#include <iostream.h> // cout
-#include <iomanip.h>  // setw, setfill
+#include <iostream> // cout
+#include <iomanip>  // setw, setfill
 
 ClassImp(Network);
+
+using namespace std;
 
 // --------------------------------------------------------------------------
@@ -44,10 +46,10 @@
 void Network::Start()
 {
-    lout << "- Starting network." << endl;
-
-    VmodIcan::Start();
+    gLog << "- Starting network." << endl;
+
+    CanOpen::Start();
     InitNodes();
 
-    lout << "- Network started." << endl;
+    gLog << "- Network started." << endl;
 }
 
@@ -58,10 +60,10 @@
 void Network::Stop()
 {
-    lout << "- Stopping network." << endl;
+    gLog << "- Stopping network." << endl;
 
     StopNodes();
-    VmodIcan::Stop();
-
-    lout << "- Network stopped." << endl;
+    CanOpen::Stop();
+
+    gLog << "- Network stopped." << endl;
 }
 
@@ -70,10 +72,10 @@
 // Initialize the network, set all nodes to NULL (n/a)
 //
-Network::Network(const char *dev, const int baud, MLog &out) : CanOpen(dev, baud, out)
-{
-    for (int i=0; i<32; i++)
-        fNodes[i] = NULL;
-
-    lout << "- Network initialized." << endl;
+Network::Network() : CanOpen()
+{
+    memset(fNodes,           0, 32*sizeof(*fNodes));
+    memset(fNodeInitialized, 0, 32*sizeof(*fNodeInitialized));
+
+    gLog << "- Network initialized." << endl;
 }
 
@@ -87,5 +89,5 @@
 //  HandleSDOError: Handles error occursion (see CanOpen standard)
 //
-void Network::HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)
+void Network::HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv)
 {
     if (fNodes[node])
@@ -123,5 +125,5 @@
 // Distributes PDO1 messages to the correspoding node calling HandlePDO1
 //
-void Network::HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv)
+void Network::HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv)
 {
     if (!fNodes[node])
@@ -141,5 +143,5 @@
 // Distributes PDO2 messages to the correspoding node calling HandlePDO2
 //
-void Network::HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv)
+void Network::HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv)
 {
     if (!fNodes[node])
@@ -159,5 +161,5 @@
 // Distributes PDO3 messages to the correspoding node calling HandlePDO3
 //
-void Network::HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv)
+void Network::HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv)
 {
     if (!fNodes[node])
@@ -177,5 +179,5 @@
 // Distributes PDO4 messages to the correspoding node calling HandlePDO4
 //
-void Network::HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv)
+void Network::HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv)
 {
     if (!fNodes[node])
@@ -196,5 +198,5 @@
 // HandleNodeguard
 //
-void Network::HandleNodeguard(BYTE_t node, timeval_t *tv)
+void Network::HandleNodeguard(BYTE_t node, const timeval_t &tv)
 {
     if (!fNodes[node])
@@ -212,5 +214,5 @@
 // HandleEmergency
 //
-void Network::HandleEmergency(BYTE_t node, timeval_t *tv)
+void Network::HandleEmergency(BYTE_t node, const timeval_t &tv)
 {
     if (!fNodes[node])
@@ -250,12 +252,12 @@
         if (fNodes[i])
         {
-            lout << "- Setting up Node #" << dec << i << " (";
-            lout << fNodes[i]->GetNodeName() << ")" << endl;
+            gLog << "- Setting up Node #" << dec << i << " (";
+            gLog << fNodes[i]->GetNodeName() << ")" << endl;
             if (fNodes[i]->InitDevice(this))
                 fNodeInitialized[i] = TRUE;
             else
-                lout << "- " << fNodes[i]->GetNodeName() << ": InitDevice failed." << endl;
+                gLog << "- " << fNodes[i]->GetNodeName() << ": InitDevice failed." << endl;
         }
-    lout << "- All Nodes setup." << endl;
+    gLog << "- All Nodes setup." << endl;
 }
 
@@ -269,9 +271,9 @@
         if (fNodes[i] && fNodeInitialized[i])
         {
-            lout << "- Stopping Node #" << dec << i;
-            lout << " (" << fNodes[i]->GetNodeName() << ")" << endl;
+            gLog << "- Stopping Node #" << dec << i;
+            gLog << " (" << fNodes[i]->GetNodeName() << ")" << endl;
             fNodes[i]->StopDevice();
         }
-    lout << "- All Nodes stopped." << endl;
+    gLog << "- All Nodes stopped." << endl;
 }
 
@@ -290,10 +292,10 @@
             continue;
 
-        lout << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName() << "' ";
+        gLog << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName() << "' ";
 
         if (fNodes[i]->GetError() <= 0)
-            lout << "Error occured." << endl;
+            gLog << "Error occured." << endl;
         else
-            lout << "has error #" << fNodes[i]->GetError() << endl;
+            gLog << "has error #" << fNodes[i]->GetError() << endl;
     }
 }
@@ -320,6 +322,6 @@
             continue;
 
-        //lout << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName();
-        //lout << "' has error #" << fNodes[i]->GetError() << endl;
+        //gLog << "- Node #" << dec << i << " '" << fNodes[i]->GetNodeName();
+        //gLog << "' has error #" << fNodes[i]->GetError() << endl;
     }
 
@@ -350,5 +352,5 @@
     bool rc = true;
 
-    lout << "- Trying to reboot all Zombies..." << endl;
+    gLog << "- Trying to reboot all Zombies..." << endl;
     for (int i=0; i<32; i++)
         if (fNodes[i])
@@ -356,10 +358,10 @@
                 if (!fNodes[i]->Reboot())
                 {
-                    lout << "- Failed to reboot " << fNodes[i]->GetNodeName() << "." << endl;
+                    gLog << "- Failed to reboot " << fNodes[i]->GetNodeName() << "." << endl;
                     rc = false;
                 }
 
     if (rc)
-        lout << "- All Zombies rebooted." << endl;
+        gLog << "- All Zombies rebooted." << endl;
 
     return rc;
Index: /trunk/MagicSoft/Cosy/candrv/network.h
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/network.h	(revision 8812)
+++ /trunk/MagicSoft/Cosy/candrv/network.h	(revision 8813)
@@ -15,11 +15,11 @@
     int fNodeInitialized[32];
 
-    void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, timeval *tv);
-    void HandlePDO1(BYTE_t node, BYTE_t *data, timeval_t *tv);
-    void HandlePDO2(BYTE_t node, BYTE_t *data, timeval_t *tv);
-    void HandlePDO3(BYTE_t node, BYTE_t *data, timeval_t *tv);
-    void HandlePDO4(BYTE_t node, BYTE_t *data, timeval_t *tv);
-    void HandleNodeguard(BYTE_t node, timeval_t *tv);
-    void HandleEmergency(BYTE_t node, timeval_t *tv);
+    void HandleSDO(BYTE_t node, BYTE_t cmd, WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval &tv);
+    void HandlePDO1(BYTE_t node, const BYTE_t *data, const timeval_t &tv);
+    void HandlePDO2(BYTE_t node, const BYTE_t *data, const timeval_t &tv);
+    void HandlePDO3(BYTE_t node, const BYTE_t *data, const timeval_t &tv);
+    void HandlePDO4(BYTE_t node, const BYTE_t *data, const timeval_t &tv);
+    void HandleNodeguard(BYTE_t node, const timeval_t &tv);
+    void HandleEmergency(BYTE_t node, const timeval_t &tv);
 
     void InitNodes();
@@ -27,5 +27,5 @@
 
 public:
-    Network(const char *dev, const int baud, MLog &out=gLog);
+    Network();
 
     void SetNode(NodeDrv *drv);
@@ -34,6 +34,6 @@
     NodeDrv *GetNode(int i)    { return fNodes[i]; }
 
-    virtual void Start();
-    virtual void Stop();
+    void Start();
+    void Stop();
 
     void PrintError() const;
Index: /trunk/MagicSoft/Cosy/candrv/nodedrv.cc
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 8812)
+++ /trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 8813)
@@ -54,4 +54,6 @@
 #include "MLogManip.h"
 
+#include "MThread.h"
+
 ClassImp(NodeDrv);
 
@@ -145,5 +147,5 @@
 // it in the 'non-standard' CANOpen communication with the MACS)
 //
-void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv)
+void NodeDrv::HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv)
 {
     const Bool_t gui = lout.IsOutputDeviceEnabled(MLog::eGui);
@@ -175,5 +177,5 @@
 // Prints the received SDo from this device
 //
-void NodeDrv::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv)
+void NodeDrv::HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv)
 {
     cout << "SdoRx: Idx=0x"<< hex << idx << "/" << (int)subidx;
@@ -496,5 +498,5 @@
         : MThread(false), fGuardTime(guard/1000.), fLifeTimeFactor(ltf), fIsCanOpen(canopen), fDrv(drv) { }
 
-    void Reset(timeval_t *tv=NULL)
+    void Reset(const timeval_t *tv=NULL)
     {
         MTime t;
@@ -587,8 +589,8 @@
 // guard time times lifetimefactor.
 //
-void NodeDrv::HandleNodeguard(timeval_t *tv)
+void NodeDrv::HandleNodeguard(const timeval_t &tv)
 {
     if (fGuard)
-        fGuard->Reset(tv);
+        fGuard->Reset(&tv);
 }
 
Index: /trunk/MagicSoft/Cosy/candrv/nodedrv.h
===================================================================
--- /trunk/MagicSoft/Cosy/candrv/nodedrv.h	(revision 8812)
+++ /trunk/MagicSoft/Cosy/candrv/nodedrv.h	(revision 8813)
@@ -69,14 +69,14 @@
     void SetZombie(bool stopguard=true);
 
-    virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv);
-    virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, timeval_t *tv);
+    virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, const timeval_t &tv);
+    virtual void HandleSDOOK(WORD_t idx, BYTE_t subidx, LWORD_t data, const timeval_t &tv);
     virtual void HandleSDOError(LWORD_t data);
 
-    virtual void HandlePDO1(BYTE_t *data, timeval_t *tv) {}
-    virtual void HandlePDO2(BYTE_t *data, timeval_t *tv) {}
-    virtual void HandlePDO3(BYTE_t *data, timeval_t *tv) {}
-    virtual void HandlePDO4(BYTE_t *data, timeval_t *tv) {}
-    virtual void HandleNodeguard(timeval_t *tv);
-    virtual void HandleEmergency(timeval_t *tv) {}
+    virtual void HandlePDO1(const BYTE_t *data, const timeval_t &tv) {}
+    virtual void HandlePDO2(const BYTE_t *data, const timeval_t &tv) {}
+    virtual void HandlePDO3(const BYTE_t *data, const timeval_t &tv) {}
+    virtual void HandlePDO4(const BYTE_t *data, const timeval_t &tv) {}
+    virtual void HandleNodeguard(const timeval_t &tv);
+    virtual void HandleEmergency(const timeval_t &tv) {}
 
     bool SendPDO1(BYTE_t data[8]);
