ADDED: - new callback post_SlaveStateChange so that a master can monitor the state of its slave nodes using a heartbeat.
authorChristian Taedcke
Thu, 09 Sep 2010 15:38:20 +0200
changeset 635 30a0e926bb2e
parent 634 15e8d1ec0e61
child 636 033fe6f1ec3c
ADDED: - new callback post_SlaveStateChange so that a master can monitor the state of its slave nodes using a heartbeat.
* * *
CHANGED: - added missing export for _post_SlaveStateChange (for revision #679)
include/data.h
include/lifegrd.h
src/lifegrd.c
src/win32/CanFestival-3.def
--- a/include/data.h	Sun Nov 28 00:05:16 2010 +0100
+++ b/include/data.h	Thu Sep 09 15:38:20 2010 +0200
@@ -95,6 +95,7 @@
 	post_sync_t post_sync;
 	post_TPDO_t post_TPDO;
 	post_SlaveBootup_t post_SlaveBootup;
+  post_SlaveStateChange_t post_SlaveStateChange;
 	
 	/* General */
 	UNS8 toggle;
@@ -247,6 +248,7 @@
 	_post_sync,                 /* post_sync */\
 	_post_TPDO,                 /* post_TPDO */\
 	_post_SlaveBootup,			/* post_SlaveBootup */\
+  _post_SlaveStateChange,			/* post_SlaveStateChange */\
 	\
 	/* General */\
 	0,                                         /* toggle */\
--- a/include/lifegrd.h	Sun Nov 28 00:05:16 2010 +0100
+++ b/include/lifegrd.h	Thu Sep 09 15:38:20 2010 +0200
@@ -40,6 +40,9 @@
 typedef void (*post_SlaveBootup_t)(CO_Data*, UNS8);
 void _post_SlaveBootup(CO_Data* d, UNS8 SlaveID);
 
+typedef void (*post_SlaveStateChange_t)(CO_Data*, UNS8, e_nodeState);
+void _post_SlaveStateChange(CO_Data* d, UNS8 nodeId, e_nodeState newNodeState);
+
 #include "data.h"
 
 /*************************************************************************
--- a/src/lifegrd.c	Sun Nov 28 00:05:16 2010 +0100
+++ b/src/lifegrd.c	Thu Sep 09 15:38:20 2010 +0200
@@ -68,13 +68,17 @@
 **/
 void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id)
 {
+  UNS8 nodeId = (UNS8)(((d->ConsumerHeartbeatEntries[id]) & (UNS32)0x00FF0000) >> (UNS8)16);
   /*MSG_WAR(0x00, "ConsumerHearbeatAlarm", 0x00);*/
 
   /* timer have been notified and is now free (non periodic)*/
   /* -> avoid deleting re-assigned timer if message is received too late*/
   d->ConsumerHeartBeatTimers[id]=TIMER_NONE;
+  
+  /* set node state */
+  d->NMTable[nodeId] = Disconnected;
   /*! call heartbeat error with NodeId */
-  (*d->heartbeatError)(d, (UNS8)( ((d->ConsumerHeartbeatEntries[id]) & (UNS32)0x00FF0000) >> (UNS8)16 ));
+  (*d->heartbeatError)(d, nodeId);
 }
 
 /*!
@@ -120,11 +124,17 @@
         }
 
     }else{ /* Not a request CAN */
+      /* The state is stored on 7 bit */
+      e_nodeState newNodeState = (e_nodeState) ((*m).data[0] & 0x7F);
 
       MSG_WAR(0x3110, "Received NMT nodeId : ", nodeId);
-      /* the slave's state receievd is stored in the NMTable */
-      /* The state is stored on 7 bit */
-      d->NMTable[nodeId] = (e_nodeState) ((*m).data[0] & 0x7F) ;
+      
+      if (d->NMTable[nodeId] != newNodeState)
+      {
+        (*d->post_SlaveStateChange)(d, nodeId, newNodeState);
+        /* the slave's state receievd is stored in the NMTable */
+        d->NMTable[nodeId] = newNodeState;
+      }
 
       /* Boot-Up frame reception */
       if ( d->NMTable[nodeId] == Initialisation)
@@ -262,3 +272,5 @@
 **/
 void _heartbeatError(CO_Data* d, UNS8 heartbeatID){}
 void _post_SlaveBootup(CO_Data* d, UNS8 SlaveID){}
+void _post_SlaveStateChange(CO_Data* d, UNS8 nodeId, e_nodeState newNodeState){}
+
--- a/src/win32/CanFestival-3.def	Sun Nov 28 00:05:16 2010 +0100
+++ b/src/win32/CanFestival-3.def	Thu Sep 09 15:38:20 2010 +0200
@@ -31,6 +31,7 @@
         ; lifegrd.h
         _heartbeatError
         _post_SlaveBootup
+        _post_SlaveStateChange
         getNodeState
         heartbeatInit
         heartbeatStop