src/lifegrd.c
changeset 177 d485a3fc5739
parent 149 fe50ada8020b
child 185 d529e20c323c
equal deleted inserted replaced
176:5d57fe1e3a5b 177:d485a3fc5739
    25 #include "canfestival.h"
    25 #include "canfestival.h"
    26 
    26 
    27 /* Prototypes for internals functions */
    27 /* Prototypes for internals functions */
    28 void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id);
    28 void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id);
    29 void ProducerHearbeatAlarm(CO_Data* d, UNS32 id);
    29 void ProducerHearbeatAlarm(CO_Data* d, UNS32 id);
       
    30 UNS32 OnHearbeatUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex);
    30 
    31 
    31 
    32 
    32 /*****************************************************************************/
    33 /*****************************************************************************/
    33 e_nodeState getNodeState (CO_Data* d, UNS8 nodeId)
    34 e_nodeState getNodeState (CO_Data* d, UNS8 nodeId)
    34 {
    35 {
   118 		/* Time expired, the heartbeat must be sent immediately
   119 		/* Time expired, the heartbeat must be sent immediately
   119 		 * generate the correct node-id: this is done by the offset 1792
   120 		 * generate the correct node-id: this is done by the offset 1792
   120 		 * (decimal) and additionaly
   121 		 * (decimal) and additionaly
   121 		 * the node-id of this device.
   122 		 * the node-id of this device.
   122 		 */
   123 		 */
       
   124 		
   123 		msg.cob_id.w = *d->bDeviceNodeId + 0x700;
   125 		msg.cob_id.w = *d->bDeviceNodeId + 0x700;
   124 		msg.len = (UNS8)0x01;
   126 		msg.len = (UNS8)0x01;
   125 		msg.rtr = 0;
   127 		msg.rtr = 0;
   126 		msg.data[0] = d->nodeState; /* No toggle for heartbeat !*/
   128 		msg.data[0] = d->nodeState; /* No toggle for heartbeat !*/
   127 		/* send the heartbeat */
   129 		/* send the heartbeat */
   128       		MSG_WAR(0x3130, "Producing heartbeat: ", d->nodeState);
   130       		MSG_WAR(0x3130, "Producing heartbeat: ", d->nodeState);
   129       		canSend(d->canHandle,&msg );
   131       		canSend(d->canHandle,&msg );
       
   132 	
   130 	}else{
   133 	}else{
   131 		d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer);
   134 		d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer);
   132 	}
   135 	}
   133 }
   136 }
   134 
   137 
   135 /*****************************************************************************/
   138 /*****************************************************************************/
       
   139 /* This is called when Index 0x1017 is updated.*/
       
   140 UNS32 OnHeartbeatProducerUpdate(CO_Data* d)
       
   141 {
       
   142 	heartbeatStop(d);
       
   143 	heartbeatInit(d);
       
   144 	return 0;
       
   145 }
       
   146 /*****************************************************************************/
       
   147 
   136 void heartbeatInit(CO_Data* d)
   148 void heartbeatInit(CO_Data* d)
   137 {
   149 {
       
   150 		
   138     UNS8 index; /* Index to scan the table of heartbeat consumers */
   151     UNS8 index; /* Index to scan the table of heartbeat consumers */
   139 
   152 	RegisterSetODentryCallBack(d, 0x1017,0x00, &OnHeartbeatProducerUpdate);
       
   153     
   140     d->toggle = 0;
   154     d->toggle = 0;
   141 
   155 	
   142     for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ )
   156     for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ )
   143     {
   157     {
   144         TIMEVAL time = (UNS16) ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ;
   158         TIMEVAL time = (UNS16) ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ;
   145         /* MSG_WAR(0x3121, "should_time : ", should_time ) ; */
   159         /* MSG_WAR(0x3121, "should_time : ", should_time ) ; */
   146         if ( time )
   160         if ( time )