1. case ZDO_STATE_CHANGE: //当网络状态改变,所有节点都会发生 2. SampleApp_NwkSta te = (devStates_t)(MS Gpkt->hdr.status); 3. if ( (SampleApp_ NwkState == DEV_ZB_COORD ) //协议器不用发送所以屏蔽 4. || (SampleApp_Nw kState == DEV_ROUTER) //路由器 5. || (SampleApp_Nw kState == DEV_END_DEVI CE) ) //终端设备 6. { 7. // Start sending the periodic message in a regular interval . 8. //osal_start_tim erEx( SampleApp_TaskID , //SAMPLEAPP_SEND _PERIODIC_MSG_EVT, //SAMPLEAPP_SEND _PERIODIC_MSG_TIMEOUT ); 9. } |
void SampleApp_HandleKeys( uint8 shift, uint8 keys ) { (void )shift; // Intentionaly unreferenced parameter //判断 S1 按键是否被按下,由于 TI 用的 5 向按键,和我们的开发板 IO 有所不同 if ( keys & HAL_KEY_SW_6 ) { #if defined(ZDO_COORDINATOR ) //协调器只接收数据 #else //路由器和终端才发送数据 SampleApp_SendFlashMessage(0); //以组播组网方式发数据 #endif } if ( keys & HAL_KEY_SW_1 ) //判断 S2 按键是否被按下 { /* The Flashr Command is s ent to Group 1. * This key toggles this device in and out of group 1. * If this device doesn't belong to group 1, t his application * will not receive the F lash command sent to group 1. */ aps_Group_t *grp; //查找 SAMPLEAPP_ENDPOINT 端点是否加入了以 SAMPLEAPP_FLASH_GROUP 为组 ID 的组 grp = aps_FindGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP ); if ( grp ) {// Remove from the group aps_RemoveGroup( SAMPLEAP P_ENDPOINT, SAMPLEAPP _FLASH_GROUP );//退出组 } else {// Add to the flash group aps_AddGroup( SAMPLEAPP_ ENDPOINT, &SampleApp_Group ); //加入组 } } } |
void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) //接收数据 { uint8 data; switch ( pkt->clusterId ) { case SAMPLEAPP_PERIODIC_CLUSTERID: break; case SAMPLEAPP_FLASH_CLUSTERID: data = (uint8)pkt->cmd.Data[0]; //根据接收到的数据改变 Led2 的亮灭 if(data == 0) HalLedSet(HAL_LED_2, HAL_LED_MODE_OFF); else HalLedSet(HAL_LED_2, HAL_LED_MODE_ON); break; } } |
void SampleApp_SendFlashMessage( uint16 flashTime ) { BuzzerState = ~ BuzzerState; //状态取反 if ( AF_DataRequest( &SampleApp_Flash_DstAddr, &SampleApp_epDesc, SAMPLEAPP_FLASH_CLUSTERID, 1, &LedState, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { if(LedState == 0) //切换自身状态提示用户操作成功 HalLedSet(HAL_LED_2, HAL_LED_MODE_ON); else HalLedSet(HAL_LED_2, HAL_LED_MODE_OFF); } else { // Error occurred in request to send. } } |