第一种方法,利用NLME.h里面定义的专门API
获取设备自身IEEE地址
/*
* This function will return a pointer to the device's IEEE 64 bit address
*
* This function resides in nwk_util.c.
*/
extern byte *NLME_GetExtAddr( void );
获取设备自身网络地址
/*
* This function will return this device's 16 bit short address
*
* This function resides in nwk_util.c.
*/
extern uint16 NLME_GetShortAddr( void );
获取父设备网络地址
/*
* This function will return the MAC's Coordinator's short (16bit) address
* which is this device's parent, not necessarily the Zigbee coordinator.
*
* This function resides in nwk_util.c.
*/
extern uint16 NLME_GetCoordShortAddr( void );
获取父设备IEEE地址
/*
* This function will return the MAC's Coordinator's Extented (64bit) address
* which is this device's parent, not necessarily the Zigbee coordinator.
*
* This function resides in nwk_util.c.
*/
extern void NLME_GetCoordExtAddr( byte * );
第二种方法:
利用zb_GetDeviceInfo()函数
查看该函数定义即可知用法:
void zb_GetDeviceInfo ( uint8 param, void *pValue )
{
switch(param)
{
case ZB_INFO_DEV_STATE:
osal_memcpy(pValue, &devState, sizeof(uint8));
break;
case ZB_INFO_IEEE_ADDR:
osal_memcpy(pValue, &aExtendedAddress, Z_EXTADDR_LEN);
break;
case ZB_INFO_SHORT_ADDR:
osal_memcpy(pValue, &_NIB.nwkDevAddress, sizeof(uint16));
break;
case ZB_INFO_PARENT_SHORT_ADDR:
osal_memcpy(pValue, &_NIB.nwkCoordAddress, sizeof(uint16));
break;
case ZB_INFO_PARENT_IEEE_ADDR:
osal_memcpy(pValue, &_NIB.nwkCoordExtAddress, Z_EXTADDR_LEN);
break;
case ZB_INFO_CHANNEL:
osal_memcpy(pValue, &_NIB.nwkLogicalChannel, sizeof(uint8));
break;
case ZB_INFO_PAN_ID:
osal_memcpy(pValue, &_NIB.nwkPanId, sizeof(uint16));
break;
case ZB_INFO_EXT_PAN_ID:
osal_memcpy(pValue, &_NIB.extendedPANID, Z_EXTADDR_LEN);
break;
}
}
例如要获取设备短地址,可以这样:
uint16 my_short_addr;
zb_GetDeviceInfo(ZB_INFO_SHORT_ADDR,my_short_addr);
第三种方法:利用上述zb_GetDeviceInfo()函数的定义,同样可知,通过读取_NIB的值也可以获取地址信息,如下调用即可
uint16 my_short_addr = _NIB.nwkDevAddress;
第四种方法:直接读NV,方法如下:
uint8 pValue[8];
osal_nv_read(ZCD_NV_EXTADDR , Z_EXTADDR_LEN, size, pValue);
pValue里保存的即是设备扩展地址
第五种方法,利用OnBoard.c里定义的全局变量aExtendedAddress获取IEEE地址,如下:
uint8 * pValue[Z_EXTADDR_LEN];
osal_memcpy(pValue, &aExtendedAddress, Z_EXTADDR_LEN);
第六种方法,利用ZMacGetReq()函数,如下:
uint8 * pValue[Z_EXTADDR_LEN];
ZMacGetReq(ZMacExtAddr,pValue);
转载于:https://www.cnblogs.com/liutogo/p/3888713.html