The first approach, using the specialized APIs defined within the NLME.h
Get the device's own IEEE address
extern byte *nlme_getextaddr (void);
Get the device's own network address
extern uint16 nlme_getshortaddr (void);
Get the parent Device network address
extern uint16 nlme_getcoordshortaddr (void);
Get the parent device IEEE address
extern void Nlme_getcoordextaddr (BYTE *);
The second method:
Using the Zb_getdeviceinfo () function
To view the function definition, you can know how to use:
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
}
}
For example, to get the device's short address, you can:
UInt16 my_short_addr;
Zb_getdeviceinfo (ZB_INFO_SHORT_ADDR,MY_SHORT_ADDR);
The third method: using the definition of the above zb_getdeviceinfo () function, it is also known that by reading the value of the _nib, the address information can be obtained, such as a downward
UInt16 my_short_addr = _nib.nwkdevaddress;
The fourth method: directly read NV, the method is as follows:
Uint8 Pvalue[8];
Osal_nv_read (ZCD_NV_EXTADDR, Z_extaddr_len, size, pValue);
The device extension address is stored in the pvalue.
The fifth method, using the global variable aextendedaddress defined in ONBOARD.C, obtains the IEEE address, as follows:
Uint8 * Pvalue[z_extaddr_len];
osal_memcpy (PValue, &aextendedaddress, Z_extaddr_len);
The sixth method, using the Zmacgetreq () function, is as follows:
Uint8 * Pvalue[z_extaddr_len];
Zmacgetreq (Zmacextaddr,pvalue);