typedef enum //个枚举类型 { afAddrNotPresent = AddrNotPresent, afAddr16Bit = Addr16Bit, //点播方式 afAddr64Bit = Addr64Bit, afAddrGroup = AddrGroup, //组播方式 afAddrBroadcast = AddrBroadcast //广播方式 } afAddrMode_t; typedef struct { union { uint16 shortAddr; //短地址 ZLongAddr_t extAddr; //IEEE 地址 } addr; afAddrMode_t addrMode; //传送模式 byte endPoint; //端点号 uint16 panId; // used for the INTER_PAN feature } afAddrType_t; |
void SampleApp_Send_P2P_Message( void ) { uint8 data[11]="0123456789"; if ( AF_DataRequest( &SampleApp_P2P_DstAddr, &SampleApp_epDesc, SAMPLEAPP_P2P_CLUSTERID, 10, data, &SampleApp_TransID, AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS ) { } else { // Error occurred in request to send. } } |
#define SAMPLEAPP_PERIODIC_CLUSTERID 1 #define SAMPLEAPP_FLASH_CLUSTERID 2 #define SAMPLEAPP_COM_CLUSTERID 3 #define SAMPLEAPP_P2P_CLUSTERID 4 |
if ( events & SAMPLEAPP_SEND_PERIODIC_MSG_EVT ) { // Send the periodic message //SampleApp_SendPeriodicMessage(); //注释原来的发送函数 SampleApp_Send_P2P_Message(); //增加点播的发送函数 // Setup to send message again in normal perio d (+ a little jitter) osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, (SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT + (osal _rand() & 0x00FF)) ) ; // return unprocessed events return (events ^ SAMPLEAPP_SEND_PERIODIC_MSG_EVT); } |
void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt ) { uint16 flashTime; switch ( pkt->clusterId ) { case SAMPLEAPP_P2P_CLUSTERID: HalUARTWrite(0, "Rx:", 3); //提示接收到数据 HalUARTWrite(0, pkt->cmd.Data, pkt->cmd.DataLength); //串口输出接收到的数据 HalUARTWrite(0, "\n", 1); // 回车换行 break; case SAMPLEAPP_PERIODIC_CLUSTERID: break; case SAMPLEAPP_FLASH_CLUSTERID: flashTime = BUILD_UINT16(pkt->cmd.Data[1], pkt->cmd.Data[2] ); HalLedBlink( HAL_LED_4, 4, 50, (flashTime / 4) ); break; } } |
case ZDO_STATE_CHANGE: SampleApp_NwkState = (devStates_t)(MSGpkt->hdr.status); if ( //(SampleApp_NwkState == DEV_ZB_COORD) || (SampleApp_NwkState == DEV_ROUTER) || (SampleApp_NwkState == DEV_END_DEVICE) ) { // Start sending the periodic message in a regular interval. osal_start_timerEx( SampleApp_TaskID, SAMPLEAPP_SEND_PERIODIC_MSG_EVT, SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT ); } else { // Device is no longer in the network } break; |