个人分析如下:
1、ZDO_JoinIndicationCB函数的处理
(1)每次产生回调,会新增到单链表ZDApp_NewDeviceList中,然后开启定时器事件ZDO_NEW_DEVICE
(2)在ZDO_NEW_DEVICE事件中处理
(3)根据链表节点,重复开启ZDO_NEW_DEVICE
疑问:这里的每个节点的timeDelta参数的计算?
举例:第一个节点加入时间T1(开启timer),第二个节点加入时间T2 = T1 + 100MS,那么第二个节点的timeDelta = ZDAPP_NEW_DEVICE_TIME - 100 = 500
当第一个节点ZDAPP_NEW_DEVICE_TIME时间到达后,处理;第二个节点,此时加入设备链表不是已经经过了500ms,怎么还是开启timer = 500的定时器?
ZStatus_t ZDO_JoinIndicationCB(uint16 ShortAddress, uint8 *ExtendedAddress,
uint8 CapabilityFlags, uint8 type)
{
// get the remaining time of the timer
timeToFire = osal_get_timeoutEx( ZDAppTaskID, ZDO_NEW_DEVICE );
pNewDevice->next = NULL;
pNewDevice->shortAddr = ShortAddress;
//////////////////////////////////////////////////////////////////////////////
//这里时间处理不明白?
pNewDevice->timeDelta = ZDAPP_NEW_DEVICE_TIME - timeToFire;
//////////////////////////////////////////////////////////////////////////////
// Start the timer only if there is no pending timer
if ( pNewDevice->timeDelta == ZDAPP_NEW_DEVICE_TIME )
{
osal_start_timerEx( ZDAppTaskID, ZDO_NEW_DEVICE, ZDAPP_NEW_DEVICE_TIME );
}
return ZSuccess;
}
// process the new device event
if ( ZDApp_NewDeviceList )
{
ZDAppNewDevice_t *pNewDevice;
uint16 timeDelta;
(void) ZDSecMgrNewDeviceEvent( ZDApp_NewDeviceList->shortAddr );
pNewDevice = (ZDAppNewDevice_t *) ZDApp_NewDeviceList->next;
osal_mem_free( ZDApp_NewDeviceList );
ZDApp_NewDeviceList = pNewDevice;
if ( pNewDevice )
{
timeDelta = pNewDevice->timeDelta;
pNewDevice = pNewDevice->next;
while ( pNewDevice )
{
//////////////////////////////////////////////////////////////////
//这里时间处理不明白?
pNewDevice->timeDelta -= timeDelta;
//////////////////////////////////////////////////////////////////
pNewDevice = pNewDevice->next;
}
osal_start_timerEx( ZDAppTaskID, ZDO_NEW_DEVICE, timeDelta );
}
}