00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <data.h>
00024 #include "lifegrd.h"
00025 #include "canfestival.h"
00026
00027
00028 void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id);
00029 void ProducerHearbeatAlarm(CO_Data* d, UNS32 id);
00030 UNS32 OnHearbeatProducerUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex);
00031
00032
00033 e_nodeState getNodeState (CO_Data* d, UNS8 nodeId)
00034 {
00035 e_nodeState networkNodeState = d->NMTable[nodeId];
00036 return networkNodeState;
00037 }
00038
00039
00040
00041 void ConsumerHearbeatAlarm(CO_Data* d, UNS32 id)
00042 {
00043
00044
00045
00046 (*d->heartbeatError)((UNS8)( ((d->ConsumerHeartbeatEntries[id]) & (UNS32)0x00FF0000) >> (UNS8)16 ));
00047 }
00048
00049
00050 void proceedNODE_GUARD(CO_Data* d, Message* m )
00051 {
00052 UNS8 nodeId = (UNS8) GET_NODE_ID((*m));
00053
00054 if((m->rtr == 1) )
00055 {
00056
00057 if (nodeId == *d->bDeviceNodeId )
00058 {
00059 Message msg;
00060 msg.cob_id.w = *d->bDeviceNodeId + 0x700;
00061 msg.len = (UNS8)0x01;
00062 msg.rtr = 0;
00063 msg.data[0] = d->nodeState;
00064 if (d->toggle)
00065 {
00066 msg.data[0] |= 0x80 ;
00067 d->toggle = 0 ;
00068 }
00069 else
00070 d->toggle = 1 ;
00071
00072 MSG_WAR(0x3130, "Sending NMT Nodeguard to master, state: ", d->nodeState);
00073 canSend(d->canHandle,&msg );
00074 }
00075
00076 }else{
00077
00078 MSG_WAR(0x3110, "Received NMT nodeId : ", nodeId);
00079
00080
00081 d->NMTable[nodeId] = (e_nodeState) ((*m).data[0] & 0x7F) ;
00082
00083
00084 if ( d->NMTable[nodeId] == Initialisation)
00085 {
00086
00087
00088
00089
00090
00091 MSG_WAR(0x3100, "The NMT is a bootup from node : ", nodeId);
00092 }
00093
00094 if( d->NMTable[nodeId] != Unknown_state ) {
00095 UNS8 index, ConsummerHeartBeat_nodeId ;
00096 for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ )
00097 {
00098 ConsummerHeartBeat_nodeId = (UNS8)( ((d->ConsumerHeartbeatEntries[index]) & (UNS32)0x00FF0000) >> (UNS8)16 );
00099 if ( nodeId == ConsummerHeartBeat_nodeId )
00100 {
00101 TIMEVAL time = ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ;
00102
00103 DelAlarm(d->ConsumerHeartBeatTimers[index]);
00104 d->ConsumerHeartBeatTimers[index] = SetAlarm(d, index, &ConsumerHearbeatAlarm, MS_TO_TIMEVAL(time), 0);
00105 }
00106 }
00107 }
00108 }
00109 }
00110
00111
00112
00113 void ProducerHearbeatAlarm(CO_Data* d, UNS32 id)
00114 {
00115 if(*d->ProducerHeartBeatTime)
00116 {
00117 Message msg;
00118
00119
00120
00121
00122
00123
00124 msg.cob_id.w = *d->bDeviceNodeId + 0x700;
00125 msg.len = (UNS8)0x01;
00126 msg.rtr = 0;
00127 msg.data[0] = d->nodeState;
00128
00129 MSG_WAR(0x3130, "Producing heartbeat: ", d->nodeState);
00130 canSend(d->canHandle,&msg );
00131
00132 }else{
00133 d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer);
00134 }
00135 }
00136
00137
00138
00139 UNS32 OnHeartbeatProducerUpdate(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
00140 {
00141 heartbeatStop(d);
00142 heartbeatInit(d);
00143 return 0;
00144 }
00145
00146
00147 void heartbeatInit(CO_Data* d)
00148 {
00149
00150 UNS8 index;
00151 RegisterSetODentryCallBack(d, 0x1017, 0x00, &OnHeartbeatProducerUpdate);
00152
00153 d->toggle = 0;
00154
00155 for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ )
00156 {
00157 TIMEVAL time = (UNS16) ( (d->ConsumerHeartbeatEntries[index]) & (UNS32)0x0000FFFF ) ;
00158
00159 if ( time )
00160 {
00161 d->ConsumerHeartBeatTimers[index] = SetAlarm(d, index, &ConsumerHearbeatAlarm, MS_TO_TIMEVAL(time), 0);
00162 }
00163 }
00164
00165 if ( *d->ProducerHeartBeatTime )
00166 {
00167 TIMEVAL time = *d->ProducerHeartBeatTime;
00168 d->ProducerHeartBeatTimer = SetAlarm(d, 0, &ProducerHearbeatAlarm, MS_TO_TIMEVAL(time), MS_TO_TIMEVAL(time));
00169 }
00170 }
00171
00172
00173 void heartbeatStop(CO_Data* d)
00174 {
00175 UNS8 index;
00176 for( index = (UNS8)0x00; index < *d->ConsumerHeartbeatCount; index++ )
00177 {
00178 d->ConsumerHeartBeatTimers[index + 1] = DelAlarm(d->ConsumerHeartBeatTimers[index + 1]);;
00179 }
00180
00181 d->ProducerHeartBeatTimer = DelAlarm(d->ProducerHeartBeatTimer);;
00182 }
00183
00184 void _heartbeatError(UNS8 heartbeatID){}