Skip to content

Commit ad27d23

Browse files
committed
[fix][CANOPEN]CAN断路恢复时,检测主站进入STOP后重新配置失败
1 parent 461e98d commit ad27d23

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

packages/CanFestival-latest/master402/canopen_callback.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,31 @@ void master402_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg, co
236236
}
237237
}
238238
/*******************************ERROR FIX CODE*****************************************************************/
239+
/**
240+
* @brief 主站恢复操作状态.
241+
* @param None.
242+
* @retval None.
243+
* @note 重新开始生产者心跳
244+
*/
245+
void master_resume_start(CO_Data *d,UNS8 nodeId)
246+
{
247+
if(getState(d) == Stopped)//can通信异常,发送失败多次,进入停止状态
248+
{
249+
//Stop状态时会删除生产者心跳定时器
250+
if (*d->ProducerHeartBeatTime)//恢复到OP状态时检查是否有生产者心跳时间
251+
{
252+
TIMEVAL time = *d->ProducerHeartBeatTime;
253+
extern void ProducerHeartbeatAlarm(CO_Data* d, UNS32 id);
254+
//设置生产者时间定时器,并设置定时回调
255+
LOG_W("Restart the producer heartbeat");
256+
d->ProducerHeartBeatTimer = SetAlarm(d, 0, &ProducerHeartbeatAlarm, MS_TO_TIMEVAL(time), MS_TO_TIMEVAL(time));
257+
}
258+
LOG_W("The master station enters the operation state from the stop state");
259+
setState(d, Operational);//转入Operational状态
260+
}
261+
masterSendNMTstateChange(d,nodeId,NMT_Start_Node);
262+
}
263+
239264
/**
240265
* @brief 修复节点NMT异常
241266
* @param None.
@@ -265,21 +290,7 @@ static void master402_fix_node_Disconnected(void* parameter)
265290
}
266291
else if(now == Pre_operational)
267292
{
268-
if(getState(OD_Data) == Stopped)//can通信异常,发送失败多次,进入停止状态
269-
{
270-
//Stop状态时会删除生产者心跳定时器
271-
if (*OD_Data->ProducerHeartBeatTime)//恢复到OP状态时检查是否有生产者心跳时间
272-
{
273-
TIMEVAL time = *OD_Data->ProducerHeartBeatTime;
274-
extern void ProducerHeartbeatAlarm(CO_Data* d, UNS32 id);
275-
//设置生产者时间定时器,并设置定时回调
276-
LOG_W("Restart the producer heartbeat");
277-
OD_Data->ProducerHeartBeatTimer = SetAlarm(OD_Data, 0, &ProducerHeartbeatAlarm, MS_TO_TIMEVAL(time), MS_TO_TIMEVAL(time));
278-
}
279-
LOG_W("The master station enters the operation state from the stop state");
280-
setState(OD_Data, Operational);//转入Operational状态
281-
}
282-
masterSendNMTstateChange(OD_Data,heartbeatID,NMT_Start_Node);
293+
master_resume_start(OD_Data,heartbeatID);
283294
LOG_I("nodeID:%d,Determines that the line is restored and switches the slave machine to operation mode, deleting the current thread",heartbeatID);
284295
node[heartbeatID - 2].lock = 0;
285296
return;//退出线程

packages/CanFestival-latest/master402/canopen_callback.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern void master402_post_TPDO(CO_Data* d);
3838
extern void master402_storeODSubIndex(CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
3939
extern void master402_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg, const UNS8 errSpec[5]);
4040

41+
extern void master_resume_start(CO_Data *d,UNS8 nodeId);
4142
extern void master402_fix_config_err(CO_Data *d,UNS8 nodeId);
4243

4344
#ifdef __cplusplus

packages/CanFestival-latest/master402/master402_canopen.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ static void config_single_node(void *parameter)
456456
*/
457457
static void slaveBootupHdl(CO_Data* d, UNS8 nodeId)
458458
{
459+
master_resume_start(d,nodeId);//是否需要恢复操作模式
459460
rt_thread_t tid;
460461
LOG_I("Node %d has gone online",nodeId);
461462
//判断信号量是否初始化

0 commit comments

Comments
 (0)