canopen 心跳报文
心跳报文
1. 如何启用????报文功能?
对象字典中的1017h对应的就是生产者的Heartbeat time,生产者会根据设定的Heartbeat time进行周期性的心跳报文发送。1017h>0????报文将被启用,等于0则不启用。
CIA V4.2.0:
t
If the heartbeat producer time is configured on a CANopen device the heartbeat protocol begins
immediately. If a CANopen device starts with a value for the heartbeat producer time unequal to 0 the
heartbeat protocol starts on the transition from the NMT state Initialisation to the NMT state Preoperational. In this case the boot-up message is regarded as first heartbeat message. It is not allowed
to use both error control mechanisms guarding protocol and heartbeat protocol on one NMT slave at
the same time. If the heartbeat producer time is unequal 0 the heartbeat protocol is used.
代码举例:
注意:1017h这里的设置值单位是ms
/* index 0x1017 : Producer Heartbeat Time. */
UNS16 Master_obj1017 = 0x3E8; /* 1000 */
subindex Master_Index1017[] =
{
{ RW, uint16, sizeof (UNS16), (void*)&Master_obj1017, NULL }
};
2. 如何启用心跳报文的掉站报警功能?
协议框图
1. Heartbeat consumer 的字典1016h设置
例如:我对1016h添加了一个测试数据
/* index 0x1016 : Consumer Heartbeat Time. */
UNS8 Master_highestSubIndex_obj1016 = 1; /* number of subindex - 1*/
UNS32 Master_obj1016[] =
{
0x020FA0 /* */
};
subindex Master_Index1016[] =
{
{ RO, uint8, sizeof (UNS8), (void*)&Master_highestSubIndex_obj1016, NULL },
{ RW, uint32, sizeof (UNS32), (void*)&Master_obj1016[0], NULL }
};
说明:
上述代码中Master_obj1016[0]数组中 0x020FA0 的元素含义:
所以:0x020FA0 表示的含义就是Heartbeat consumer(主站)会对Node-ID为0x02的Heartbeat producer(从站)心跳站点掉线监测。如果超过0x0FA0毫秒(Heartbeat time)则Heartbeat consumer会产生一个Heartbeat Event。
在canfestival中Heartbeat consumer(主站)会调用lifegrd.c中的_heartbeatError()方法
上一篇: AutoSar网络管理