Index: trunk/MagicSoft/Cosy/candrv/nodedrv.cc
===================================================================
--- trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 1702)
+++ trunk/MagicSoft/Cosy/candrv/nodedrv.cc	(revision 1703)
@@ -30,5 +30,5 @@
 //
 // to be overloaded:
-//  virtual void InitDevice(Network *net)
+//  virtual void Init()
 //  virtual void StopDevice()
 //  virtual void HandleSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, timeval_t *tv)
@@ -39,4 +39,6 @@
 //  virtual void HandlePDO3(BYTE_t *data, timeval_t *tv)
 //  virtual void HandlePDO4(BYTE_t *data, timeval_t *tv)
+//  virtual bool Reboot();
+//  virtual void CheckConnection();
 //
 ///////////////////////////////////////////////////////////////////////
@@ -56,5 +58,5 @@
 // and the node name. The name is a name for debug output.
 //
-NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0), fIsZombie(kFALSE)
+NodeDrv::NodeDrv(BYTE_t nodeid, const char *name, MLog &out) : Log(out), fNetwork(NULL), fId(32), fError(0), fIsZombie(kTRUE)
 {
     if (nodeid>0x1f)
@@ -93,5 +95,8 @@
 {
     fIsZombie = false;
-    return true;
+
+    Init();
+
+    return !fIsZombie;
 }
 
@@ -107,5 +112,5 @@
 //   SDO tx
 //
-void NodeDrv::InitDevice(Network *net)
+bool NodeDrv::InitDevice(Network *net)
 {
     fNetwork = net;
@@ -117,4 +122,10 @@
     EnableCanMsg(kSDO_RX);
     EnableCanMsg(kSDO_TX);
+
+    fIsZombie = kFALSE;
+
+    Init();
+
+    return !fIsZombie;
 }
 
@@ -165,7 +176,12 @@
 // A PDO is carrying up to eight bytes of information.
 //
-void NodeDrv::SendPDO1(BYTE_t data[8])
-{
-    fNetwork->SendPDO1(fId, data);
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendPDO1(BYTE_t data[8])
+{
+    if (!fIsZombie)
+        fNetwork->SendPDO1(fId, data);
+    return !fIsZombie;
 }
 
@@ -175,7 +191,12 @@
 // A PDO is carrying up to eight bytes of information.
 //
-void NodeDrv::SendPDO2(BYTE_t data[8])
-{
-    fNetwork->SendPDO2(fId, data);
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendPDO2(BYTE_t data[8])
+{
+    if (!fIsZombie)
+        fNetwork->SendPDO2(fId, data);
+    return !fIsZombie;
 }
 
@@ -185,8 +206,13 @@
 // A PDO is carrying up to eight bytes of information.
 //
-void NodeDrv::SendPDO1(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendPDO1(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)
 {
-    fNetwork->SendPDO1(fId, m0, m1, m2, m3, m4, m5, m6, m7);
+    if (!fIsZombie)
+        fNetwork->SendPDO1(fId, m0, m1, m2, m3, m4, m5, m6, m7);
+    return !fIsZombie;
 }
 
@@ -196,92 +222,127 @@
 // A PDO is carrying up to eight bytes of information.
 //
-void NodeDrv::SendPDO2(BYTE_t m0=0, BYTE_t m1=0, BYTE_t m2=0, BYTE_t m3=0,
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendPDO2(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)
 {
-    fNetwork->SendPDO2(fId, m0, m1, m2, m3, m4, m5, m6, m7);
-}
-
-// --------------------------------------------------------------------------
-//
-// Sends the given SDO through the network to this device
-// An SDO message contains
-//  an address (this device)
-//  an index of the dictionary entry to address
-//  a subindex of this dictionary entry to access
-//  and a value to set for this dictionary entry
-//
-void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store)
-{
-    fNetwork->SendSDO(fId, idx, subidx, val, store);
-}
-
-// --------------------------------------------------------------------------
-//
-// Sends the given SDO through the network to this device
-// An SDO message contains
-//  an address (this device)
-//  an index of the dictionary entry to address
-//  a subindex of this dictionary entry to access
-//  and a value to set for this dictionary entry
-//
-void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store)
-{
-    fNetwork->SendSDO(fId, idx, subidx, val, store);
-}
-
-// --------------------------------------------------------------------------
-//
-// Sends the given SDO through the network to this device
-// An SDO message contains
-//  an address (this device)
-//  an index of the dictionary entry to address
-//  a subindex of this dictionary entry to access
-//  and a value to set for this dictionary entry
-//
-void NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store)
-{
-    fNetwork->SendSDO(fId, idx, subidx, val, store);
-}
-
-// --------------------------------------------------------------------------
-//
-// Sends the given SDO through the network to this device
-// An SDO message contains
-//  an address (this device)
-//  an index of the dictionary entry to address
-//  a subindex of this dictionary entry to access
-//  and a value to set for this dictionary entry
-//
-void NodeDrv::SendSDO(WORD_t idx, BYTE_t val)
-{
-    fNetwork->SendSDO(fId, idx, val, true);
-}
-
-// --------------------------------------------------------------------------
-//
-// Sends the given SDO through the network to this device
-// An SDO message contains
-//  an address (this device)
-//  an index of the dictionary entry to address
-//  a subindex of this dictionary entry to access
-//  and a value to set for this dictionary entry
-//
-void NodeDrv::SendSDO(WORD_t idx, WORD_t val)
-{
-    fNetwork->SendSDO(fId, idx, val, true);
-}
-
-// --------------------------------------------------------------------------
-//
-// Sends the given SDO through the network to this device
-// An SDO message contains
-//  an address (this device)
-//  an index of the dictionary entry to address
-//  a subindex of this dictionary entry to access
-//  and a value to set for this dictionary entry
-//
-void NodeDrv::SendSDO(WORD_t idx, LWORD_t val)
-{
-    fNetwork->SendSDO(fId, idx, val, true);
+    if (!fIsZombie)
+        fNetwork->SendPDO2(fId, m0, m1, m2, m3, m4, m5, m6, m7);
+    return !fIsZombie;
+}
+
+// --------------------------------------------------------------------------
+//
+// Sends the given SDO through the network to this device
+// An SDO message contains
+//  an address (this device)
+//  an index of the dictionary entry to address
+//  a subindex of this dictionary entry to access
+//  and a value to set for this dictionary entry
+//
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, BYTE_t val, bool store)
+{
+    if (!fIsZombie)
+        fNetwork->SendSDO(fId, idx, subidx, val, store);
+    return !fIsZombie;
+}
+
+// --------------------------------------------------------------------------
+//
+// Sends the given SDO through the network to this device
+// An SDO message contains
+//  an address (this device)
+//  an index of the dictionary entry to address
+//  a subindex of this dictionary entry to access
+//  and a value to set for this dictionary entry
+//
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, WORD_t val, bool store)
+{
+    if (!fIsZombie)
+        fNetwork->SendSDO(fId, idx, subidx, val, store);
+    return !fIsZombie;
+}
+
+// --------------------------------------------------------------------------
+//
+// Sends the given SDO through the network to this device
+// An SDO message contains
+//  an address (this device)
+//  an index of the dictionary entry to address
+//  a subindex of this dictionary entry to access
+//  and a value to set for this dictionary entry
+//
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendSDO(WORD_t idx, BYTE_t subidx, LWORD_t val, bool store)
+{
+    if (!fIsZombie)
+        fNetwork->SendSDO(fId, idx, subidx, val, store);
+    return !fIsZombie;
+}
+
+// --------------------------------------------------------------------------
+//
+// Sends the given SDO through the network to this device
+// An SDO message contains
+//  an address (this device)
+//  an index of the dictionary entry to address
+//  a subindex of this dictionary entry to access
+//  and a value to set for this dictionary entry
+//
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendSDO(WORD_t idx, BYTE_t val)
+{
+    if (!fIsZombie)
+        fNetwork->SendSDO(fId, idx, val, true);
+    return !fIsZombie;
+}
+
+// --------------------------------------------------------------------------
+//
+// Sends the given SDO through the network to this device
+// An SDO message contains
+//  an address (this device)
+//  an index of the dictionary entry to address
+//  a subindex of this dictionary entry to access
+//  and a value to set for this dictionary entry
+//
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendSDO(WORD_t idx, WORD_t val)
+{
+    if (!fIsZombie)
+        fNetwork->SendSDO(fId, idx, val, true);
+    return !fIsZombie;
+}
+
+// --------------------------------------------------------------------------
+//
+// Sends the given SDO through the network to this device
+// An SDO message contains
+//  an address (this device)
+//  an index of the dictionary entry to address
+//  a subindex of this dictionary entry to access
+//  and a value to set for this dictionary entry
+//
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendSDO(WORD_t idx, LWORD_t val)
+{
+    if (!fIsZombie)
+        fNetwork->SendSDO(fId, idx, val, true);
+    return !fIsZombie;
 }
 
@@ -294,7 +355,12 @@
 //  a subindex of this dictionary entry to access
 //
-void NodeDrv::RequestSDO(WORD_t idx, BYTE_t subidx)
-{
-    fNetwork->RequestSDO(fId, idx, subidx);
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::RequestSDO(WORD_t idx, BYTE_t subidx)
+{
+    if (!fIsZombie)
+        fNetwork->RequestSDO(fId, idx, subidx);
+    return !fIsZombie;
 }
 
@@ -303,7 +369,12 @@
 // Send an NMT message (command) to this device
 //
-void NodeDrv::SendNMT(BYTE_t cmd)
-{
-    fNetwork->SendNMT(fId, cmd);
+// The message is not send if the node has the status Zombie.
+// In this case false is returned, otherwise true
+//
+bool NodeDrv::SendNMT(BYTE_t cmd)
+{
+    if (!fIsZombie)
+        fNetwork->SendNMT(fId, cmd);
+    return !fIsZombie;
 }
 
@@ -323,13 +394,17 @@
 // You can stop waiting by StopWaitingForSDO.
 // Return false if waiting timed out.
+// If waiting timed out the node is set to status Zombie.
+//
+// If the node is already a zombie node, the message is deleted from the
+// queue and no waiting is done, false is returned..
 //
 bool NodeDrv::WaitForSdo(WORD_t idx, BYTE_t subidx, WORDS_t timeout)
 {
-    bool rc = fNetwork->WaitForSdo(fId, idx, subidx, timeout);
+    bool rc = fNetwork->WaitForSdo(fId, idx, subidx, fIsZombie?-1:timeout);
 
     if (!rc)
         fIsZombie = kTRUE;
 
-    return rc;
+    return fIsZombie ? false : rc;
 }
 
