void zaccel_getdev(struct bmi_zb *zb) { struct zaccel_info *z_info; struct zaccel_device zdev; z_info = &zb->z_info; zb_GetDeviceInfo(zb,ZB_DEVICE_STATE, (unsigned char *)&zdev.state); zb_GetDeviceInfo(zb,ZB_DEVICE_IEEE_ADDR, (unsigned char *)&zdev.device_ieee); zb_GetDeviceInfo(zb,ZB_DEVICE_SHORT_ADDR, (unsigned char *)&zdev.device_short); zb_GetDeviceInfo(zb,ZB_PARENT_SHORT_ADDR, (unsigned char *)&zdev.parent_short); zb_GetDeviceInfo(zb,ZB_PARENT_IEEE_ADDR, (unsigned char *)&zdev.parent_ieee); zb_GetDeviceInfo(zb,ZB_DEVICE_CHANNEL, (unsigned char *)&zdev.channel); zb_GetDeviceInfo(zb,ZB_DEVICE_PANID, (unsigned char *)&zdev.panid); zb_GetDeviceInfo(zb,ZB_DEVICE_EXT_PANID, (unsigned char *)&zdev.ext_panid); z_info->device.state = zdev.state; memcpy(&z_info->device.device_ieee,&zdev.device_ieee,8); memcpy(&z_info->device.device_short,&zdev.device_short,2); memcpy(&z_info->device.parent_short,&zdev.parent_short,2); memcpy(&z_info->device.parent_ieee,&zdev.parent_ieee,8); z_info->device.channel = zdev.channel; memcpy(&z_info->device.panid,&zdev.panid,2); memcpy(&z_info->device.ext_panid,&zdev.ext_panid,8); }
/****************************************************************************** * @fn zb_StartConfirm * * @brief The zb_StartConfirm callback is called by the ZigBee stack * after a start request operation completes * * @param status - The status of the start operation. Status of * ZB_SUCCESS indicates the start operation completed * successfully. Else the status is an error code. * * @return none */ void zb_StartConfirm( uint8 status ) { // If the device sucessfully started, change state to running if ( status == ZB_SUCCESS ) { // Change application state appState = APP_START; // Set LED 1 to indicate that node is operational on the network HalLedSet( HAL_LED_1, HAL_LED_MODE_ON ); // Store parent short address zb_GetDeviceInfo(ZB_INFO_PARENT_SHORT_ADDR, &parentShortAddr); // Set event to bind to a collector osal_set_event( sapi_TaskID, MY_FIND_COLLECTOR_EVT ); } else { // Try again later with a delay osal_start_timerEx( sapi_TaskID, MY_START_EVT, myStartRetryDelay ); } }
/********************************************************************* * @fn ZDOInitDevice * * @brief Start the device in the network. This function will read * ZCD_NV_STARTUP_OPTION (NV item) to determine whether or not to * restore the network state of the device. * * @param startDelay - timeDelay to start device (in milliseconds). * There is a jitter added to this delay: * ((NWK_START_DELAY + startDelay) * + (osal_rand() & EXTENDED_JOINING_RANDOM_MASK)) * * NOTE: If the application would like to force a "new" join, the * application should set the ZCD_STARTOPT_DEFAULT_NETWORK_STATE * bit in the ZCD_NV_STARTUP_OPTION NV item before calling * this function. "new" join means to not restore the network * state of the device. Use zgWriteStartupOptions() to set these * options. * * @return * ZDO_INITDEV_RESTORED_NETWORK_STATE - The device's network state was * restored. * ZDO_INITDEV_NEW_NETWORK_STATE - The network state was initialized. * This could mean that ZCD_NV_STARTUP_OPTION said to not restore, or * it could mean that there was no network state to restore. * ZDO_INITDEV_LEAVE_NOT_STARTED - Before the reset, a network leave was issued * with the rejoin option set to TRUE. So, the device was not * started in the network (one time only). The next time this * function is called it will start. * 0xFF for failure. */ uint8 ZDOInitDevice(uint16 startDelay) { uint8 *pBuf; #if !ZAP_ZDO_STARTUP_AREQ uint8 rtrn; #endif (void)startDelay; // ZNP MT_ZDO_STARTUP_FROM_APP processing forces delay 0. zb_GetDeviceInfo(ZB_INFO_DEV_STATE, &devState); if ((DEV_HOLD != devState) && (DEV_INIT != devState) && (DEV_NWK_ORPHAN != devState)) { return FAILURE; } #if ZAP_ZDO_STARTUP_AREQ pBuf = zap_msg_allocate(0, (uint8)MT_RPC_SYS_ZDO | (uint8)MT_RPC_CMD_AREQ, (uint8)MT_ZDO_STARTUP_FROM_APP); #else pBuf = zap_msg_allocate(0, (uint8)MT_RPC_SYS_ZDO | (uint8)MT_RPC_CMD_SREQ, (uint8)MT_ZDO_STARTUP_FROM_APP); #endif if (NULL == pBuf) { return 0xFF; } zapPhySend(zapAppPort, pBuf); #if !ZAP_ZDO_STARTUP_AREQ if (ZSuccess == (rtrn = ZAP_SRSP_STATUS(pBuf))) #endif // Need to locally enter the discovery state to holdoff calls to ZDOInitDevice() until the ZAP // monitoring task requests the actual ZNP state. devState = DEV_NWK_DISC; zap_msg_deallocate(&pBuf); // Joining can take some time - especially with > 1 scan channel. if (ZSuccess != osal_start_timerEx(zapTaskId, ZAP_APP_TMR_EVT, ZAP_APP_JOIN_DLY)) { (void)osal_set_event(zapTaskId, ZAP_APP_TMR_EVT); } #if ZAP_ZDO_STARTUP_AREQ // Made into an AREQ after empirical results showed > 400 msec delay on SRSP. #if ZAP_NV_RESTORE return ZDO_INITDEV_RESTORED_NETWORK_STATE; #else return ZDO_INITDEV_NEW_NETWORK_STATE; #endif #else return rtrn; #endif }
/*************************************************************************************************** * @fn MT_SapiGetDevInfo * * @brief Process Get Device Info command * * @param pBuf - pointer to received buffer * * @return none ***************************************************************************************************/ void MT_SapiGetDevInfo(uint8 *pBuf) { uint8 *pRetBuf; uint8 cmdId; /* parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; pRetBuf = osal_mem_alloc(Z_EXTADDR_LEN+1); if (pRetBuf) { zb_GetDeviceInfo(pBuf[0], pRetBuf+1); pRetBuf[0] = pBuf[0]; /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SAPI), cmdId, Z_EXTADDR_LEN+1, pRetBuf ); osal_mem_free(pRetBuf); } }
/****************************************************************************** * @fn zb_StartConfirm * * @brief The zb_StartConfirm callback is called by the ZigBee stack * after a start request operation completes * * @param status - The status of the start operation. Status of * ZB_SUCCESS indicates the start operation completed * successfully. Else the status is an error code. * * @return none */ void zb_StartConfirm( uint8 status ) { // If the device sucessfully started, change state to running if ( status == ZB_SUCCESS ) { // Change application state appState = APP_START; // Set LED 1 to indicate that node is operational on the network HalLedSet( HAL_LED_1, HAL_LED_MODE_ON ); // Update the display #if defined ( LCD_SUPPORTED ) HalLcdWriteString( "SensorDemo", HAL_LCD_LINE_1 ); HalLcdWriteString( "Sensor", HAL_LCD_LINE_2 ); #endif // Store parent short address zb_GetDeviceInfo(ZB_INFO_PARENT_SHORT_ADDR, &parentShortAddr); // Set event to bind to a collector osal_set_event( sapi_TaskID, MY_FIND_COLLECTOR_EVT ); } }