Part Number: CC2530
Other Parts Discussed in Thread: Z-STACK
Hello everyone.
I am working smart system by using CC2530 and zstack3.0.1.
I have two coordinators and two end devices.
I only had to connect a specific end device to every coordinator.
But what if you want to disconnect a end device connected to one of the cooperators and connect them to another coordinator?
To do this, I first deleted the iEEE address from the white list of connected coordinator and registered it with the white list of next coordinator.
My code are as following.
ZStatus_t ZDO_JoinIndicationCB(uint16 ShortAddress, uint8 *ExtendedAddress,
uint8 CapabilityFlags, uint8 type)
{
(void)ExtendedAddress;
//check if the device is leaving before responding to rejoin request
if( osal_get_timeoutEx( ZDAppTaskID , ZDO_DEVICE_RESET) )
{
return ZFailure; // device leaving , hence do not allow rejoin
}
#if 1
uint8 iEndDev;
uint8 passAddr123[Z_EXTADDR_LEN];
uint8 passAddr[Z_EXTADDR_LEN];
uint8 fSuccess = 0;
osal_memcpy(passAddr123,ExtendedAddress,Z_EXTADDR_LEN);
printf("End device ADDR : %x %x %x %x %x %x %x %x\n",passAddr123[0],passAddr123[1],passAddr123[2],passAddr123[3],passAddr123[4],passAddr123[5],passAddr123[6],passAddr123[7]);
for(iEndDev = 0; iEndDev < MAX_END_DEV_NUM; iEndDev ++)
{
osal_nv_item_init(NV_APP_EASEN_LOOKUP + iEndDev, Z_EXTADDR_LEN, NULL);
osal_nv_read(NV_APP_EASEN_LOOKUP + iEndDev, 0, Z_EXTADDR_LEN,
passAddr);
if ( AddrMgrExtAddrEqual( passAddr, ExtendedAddress) == TRUE )
{
fSuccess = 1;
break;
}
}
if (fSuccess == 0)
{
zAddrType_t destAddr;
destAddr.addrMode = Addr64Bit;
osal_memcpy(destAddr.addr.extAddr,ExtendedAddress,Z_EXTADDR_LEN);
ZDP_MgmtLeaveReq(&destAddr,ExtendedAddress,1,1,0);
return ZFailure;
}
#endif
//////////////////////////
#if ZDO_NV_SAVE_RFDs
(void)CapabilityFlags;
#else // if !ZDO_NV_SAVE_RFDs
if (CapabilityFlags & CAPINFO_DEVICETYPE_FFD)
#endif
{
ZDApp_NVUpdate(); // Notify to save info into NV.
}
if (ZG_SECURE_ENABLED) // Send notification to TC of new device.
{
if ( type == NWK_ASSOC_JOIN ||
type == NWK_ASSOC_REJOIN_UNSECURE ||
type == NWK_ASSOC_REJOIN_SECURE )
{
uint16 timeToFire;
ZDAppNewDevice_t *pNewDevice, *pDeviceList;
pNewDevice = (ZDAppNewDevice_t *) osal_mem_alloc( sizeof(ZDAppNewDevice_t) );
if ( pNewDevice == NULL )
{
// Memory alloc failed
return ZMemError;
}
// Add the new device to the New Device List
if ( ZDApp_NewDeviceList == NULL )
{
// The list is empty, add the first element
ZDApp_NewDeviceList = pNewDevice;
}
else
{
pDeviceList = ZDApp_NewDeviceList;
// Walk the list to last element
while ( pDeviceList->next )
{
pDeviceList = (ZDAppNewDevice_t *) pDeviceList->next;
}
// Add new device at the end
pDeviceList->next = pNewDevice;
}
// 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;
}
Please help me.
Thanks in advance.
Piao