コード例 #1
0
ファイル: BindingTable.c プロジェクト: comword/SmartIR-8051
/*********************************************************************
 * @fn      bindAddrMgrLocalLoad
 *
 * @brief   Load local(self and parent) address information into
 *          Address Manager
 *
 * @param   none
 *
 * @return  none
 */
void bindAddrMgrLocalLoad( void )
{
  AddrMgrEntry_t entry;
  uint16         parent;

  // add "local"(self and parent) address informtion into the Address
  // Manager
  if ( bindAddrMgrLocalLoaded == FALSE )
  {
    // add the device's address information
    entry.user    = ADDRMGR_USER_BINDING;
    entry.nwkAddr = _NIB.nwkDevAddress;
    AddrMgrExtAddrSet( entry.extAddr, NLME_GetExtAddr() );
    AddrMgrEntryUpdate( &entry );

    // make sure parent address is valid
    parent = NLME_GetCoordShortAddr();
    if ( ( parent != entry.nwkAddr     ) &&
         ( parent != INVALID_NODE_ADDR )    )
    {
      // add the parent's address information
      entry.nwkAddr = parent;
      NLME_GetCoordExtAddr( entry.extAddr );
      AddrMgrEntryUpdate( &entry );
    }

    bindAddrMgrLocalLoaded = TRUE;
  }
}
コード例 #2
0
ファイル: ParkingAppE.c プロジェクト: kk30/kdc
/*********************************************************************
 * @fn      App_SendSample
 *
 * @brief   
 *
 * @param   buf - pointer for the  field
 *          len - length of the  field
 *
 * @return  none
 */
void App_SendSample(unsigned char *buf, unsigned char len, uint16 option) 
{
  uint8 packetLen=0;
  app_msg_t packet;
  
    packet.head = 0xFE;
//    packet.nodeid = theNodeID;
    SendSeqno++;
    if(SendSeqno == 0xFE)
    {
      SendSeqno = 1;
    }
    packet.seqno = SendSeqno; 
    memcpy(packet.IEEEAddr, NLME_GetExtAddr(), 8);//IEEE address 64 bit
    myAddr = NLME_GetShortAddr();  
    packet.myAddr = myAddr;
    packet.rssi = 0x00;
    packet.cmd = option;
    packet.len = len;
    memcpy(packet.data, buf, len);
    packetLen = sizeof(app_msg_t)-60 + len;
//    packet.end = 0xAA;
    
    // AF_SKIP_ROUTING -  will cause the device to skip
    // routing and try to send the message directly
    if ( AF_DataRequest( &ParkingApp_Periodic_DstAddr, &ParkingApp_epDesc,
                        PARKINGAPP_PERIODIC_CLUSTERID,
			packetLen,//sizeof(app_msg_t),//22,
			(byte*) &packet,//(byte *)tempbuf,
                        &ParkingApp_TransID,
#if (defined DATABROADCAST && DATABROADCAST == TRUE)
                        AF_SKIP_ROUTING, //  AF_DISCV_ROUTE
                        ENDDEVICE_BCAST_RADIUS ) == afStatus_SUCCESS ) //AF_DEFAULT_RADIUS
#else
                        AF_DISCV_ROUTE,  
                        AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
#endif
    {
//            P0_0 = 0;
    }
    else
    {
      // Error occurred in request to send.
    }

}
コード例 #3
0
ファイル: LCD.c プロジェクト: smileboywtu/ZigbeeLcdStack
/*********************************************************************
 *
 * @fn		LCD_SendTopoInfo
 *
 *
 *
 */
static void LCD_SendTopoInformation()
{ 
  // Define the Frame
  unsigned char* srcExtAddr;
  srcExtAddr = NLME_GetExtAddr();
  uint16 srcAddr = NLME_GetShortAddr();
  uint16 parAddr = NLME_GetCoordShortAddr();
  byte frame[19] = {0};
  
  // Build the Frame
  // Fill SOF	0xFE
  frame[0] = 0xFE;
  // Fill len
  frame[1] = 12;
  // Fill CMD
  frame[2] = LO_UINT16(TOPOLOGY_CMD);
  frame[3] = HI_UINT16(TOPOLOGY_CMD);
  // Fill Addr
  frame[4] = LO_UINT16(srcAddr);
  frame[5] = HI_UINT16(srcAddr);
  // fill type
  frame[6] = LO_UINT16(LCD);
  frame[7] = HI_UINT16(LCD);
  // Fill Parent
  frame[8] = LO_UINT16(parAddr);
  frame[9] = HI_UINT16(parAddr);
  // fill the ieee64 address
  copyExtAddr(srcExtAddr, (byte*)&frame[10]); 
  // Cal and fill FCS
  frame[18] = LCD_CalcFCS((byte*)&frame[1], 17);
  
  // Send the data to Coordinator
  AF_DataRequest( &LCD_DstAddr, 
				  &LCD_epDesc,
				  ZIGBEE_COMMON_CLUSTER,
				  19,
				  (byte *)frame,
				  &LCD_TransID,
				  AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
}
コード例 #4
0
ファイル: protocol.c プロジェクト: cuu/weiyi
void send_dev_info(uint8 type)// when get command 0xAD
{
  uint16 short_addr;
  uint8 *ieeeAddr;
  uint8 i;
  uint8 arr[12];
  
  ieeeAddr = NLME_GetExtAddr();
  
  short_addr = _NIB.nwkDevAddress;
  
  arr[0] = 0x0b;
  arr[1] = 0x05;
  for( i = 0; i < 8; i++)
  {
    arr[i+2] = ieeeAddr[i];
  }
  arr[11] = type;
  
  /// now Send to gateway
  
}
コード例 #5
0
/*********************************************************************
 * @fn          UART_callback
 * @brief       Uart callback function.
 * @param       port - Com Port 0 or com port 1. 
 * @param       event - UART Events.
 * @return      null.
 */
void UART_callback ( uint8 port, uint8 event )
{ 
  uint16 uart1_len=0;
  if(( event & ( HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT ) ) ) 
  {   
    if(port == HAL_UART_PORT_0)//不用来接收数据,仅仅用来上传数据
    {
      //(HAL_UART_PORT_0, i8_uart_buf, len);   //读取串口数据到buf指向的内存,处添加数据解析函数    
    }
    else//port == HAL_UART_PORT_1
    {
      uart1_len = Hal_UART_RxBufLen(HAL_UART_PORT_1); //取出本次接收到的字符长度 
      uint8 *uart1_buf = osal_mem_alloc(uart1_len);
      HalUARTRead(HAL_UART_PORT_1, uart1_buf, uart1_len);
    
      //数据逻辑操作
      afAddrType_t SampleApp_Send_DstAddr;//目标地址
      unsigned int len;
      //获取目标网络地址
      uint8 arr[2];
      uint16 nwkAddr;
      StrConvert2Hex(uart1_buf+3, arr,4);//转换网络地址
      nwkAddr = BUILD_UINT16(arr[0],arr[1]); 
      
      SampleApp_Send_DstAddr.addr.shortAddr = nwkAddr;
      SampleApp_Send_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
      SampleApp_Send_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
      len = strlen(uart1_buf);
      
      //HCCU发送控制命令,则将该指令转发给EP
      if(uart1_buf[1] == 'C' ||uart1_buf[1] == 'c'){
        
        //协调器 /c|IP|Cluster_id|Group_id|endPoint----|T,V|
       if( AF_DataRequest( &SampleApp_Send_DstAddr, 
                       &SampleApp_epDesc,
                       SAMPLEAPP_COM_CLUSTERID,
                       len,// 数据长度         
                       uart1_buf,//数据内容
                       &SampleApp_TransID,
                       AF_DISCV_ROUTE,
                       AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
       {
         HalUARTWrite(1,"success\n",9);       
       }else{
         HalUARTWrite(1,"failed\n",8);
       }
      }
      
      //发送自身的MAC地址,作为HCCU的唯一标识码;
      if(uart1_buf[1] == 'A' || uart1_buf[1] == 'a'){
         uint8 *TmpBuf = osal_mem_alloc(8);
         uint8 asc_16[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
         uint8 *IEEEAddr;
         //获取长地址
         IEEEAddr = NLME_GetExtAddr();
         osal_cpyExtAddr( TmpBuf,IEEEAddr);
         HalUARTWrite(1,"/H|",3);
         HalUARTWrite(1,&asc_16[TmpBuf[0]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[0]%16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[1]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[1]%16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[2]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[2]%16],1);  
         HalUARTWrite(1,&asc_16[TmpBuf[3]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[3]%16],1);   
         HalUARTWrite(1,&asc_16[TmpBuf[4]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[4]%16],1); 
         HalUARTWrite(1,&asc_16[TmpBuf[5]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[5]%16],1);      
         HalUARTWrite(1,&asc_16[TmpBuf[6]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[6]%16],1);  
         HalUARTWrite(1,&asc_16[TmpBuf[7]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[7]%16],1);
         HalUARTWrite(1,"|*\r\n",6);
         osal_mem_free(TmpBuf);
      }
      osal_mem_free(uart1_buf);
    }
  } 
}
コード例 #6
0
ファイル: GenericApp.c プロジェクト: cuu/weiyi
/*********************************************************************
 * @fn      GenericApp_MessageMSGCB
 *
 * @brief   Data message processor callback.  This function processes
 *          any incoming data - probably from other devices.  So, based
 *          on cluster ID, perform the intended action.
 *
 * @param   none
 *
 * @return  none
 */
static void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
  unsigned char buff[12];
  char*p;
  byte nr;
  uint8 i;
  uint8 ass_num;
  uint8* ieeeaddr;
  
  
  uint8 yy1;
  uint16 devlist[ NWK_MAX_DEVICES + 1];
  
  afAddrType_t myaddr; // use for p2p
  
  ass_num = 0;
  
  switch ( pkt->clusterId )
  {
    case GENERICAPP_CLUSTERID:
      //sprintf(buff,"%hu", pkt->cmd.DataLength);
     ///if( p[4] =='l' && p[5] =='e' && p[6] =='d' && p[7] =='1')
     // {
//       uprint( (uint8*)pkt->srcAddr );
//        uprint( (uint8*)pkt->endPoint);
       // UART_Send_String( &pkt->LinkQuality, 1);
        //uprint( pkt->cmd.Data);
     // }
     //UART_Send_String( (uint8*)&pkt->cmd.DataLength, 1);
     //UART_Send_String( &pkt->cmd.TransSeqNumber,1 );

    if( pkt->cmd.DataLength == 1)
    {      
        yy1 = 1;
#if !defined( ZDO_COORDINATOR ) 
        if(pkt->cmd.Data[0] == 0x6d)
        {
          /// return mac address : ac xx xx ieee addr
               myaddr.addrMode = (afAddrMode_t)Addr16Bit;
               myaddr.endPoint = GENERICAPP_ENDPOINT;          
               myaddr.addr.shortAddr = 0x0000;
               
            ieeeaddr = NLME_GetExtAddr();
            osal_cpyExtAddr(buff+3, ieeeaddr);
            buff[0] = 0xac;
            buff[1] = LO_UINT16(_NIB.nwkDevAddress);
            buff[2] = HI_UINT16(_NIB.nwkDevAddress);
            if ( AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID,  11,
                          &buff[0],
                          &GenericApp_TransID,
                          AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) != afStatus_SUCCESS )
            {
                 AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID,  11,
                          &buff[0],
                          &GenericApp_TransID,
                          AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
              // send twice only, if it is still not ok, f**k it
            }            
            
        }
        // only routers return devlist
        if( pkt->cmd.Data[0] == 0xCA )
        {
               myaddr.addrMode = (afAddrMode_t)Addr16Bit;
               myaddr.endPoint = GENERICAPP_ENDPOINT;          
               myaddr.addr.shortAddr = 0x0000;
          
        ass_num = AssocCount(1, 4);
      //  if( ass_num > 0)
        //{
          for(i=0;i< NWK_MAX_DEVICES; i++)
          {
             nr = AssociatedDevList[ i ].nodeRelation;
              if(nr > 0 && nr < 5) //CHILD_RFD CHILD_RFD_RX_IDLE CHILD_FFD CHILD_FFD_RX_IDLE
             //if( nr != 0XFF)
             {
             //  if( AssociatedDevList[ i ].shortAddr != 0x0000)
             //  {
                  //if( AssocIsChild( AssociatedDevList[ i ].shortAddr ) != 1 || AssociatedDevList[ i ].age > NWK_ROUTE_AGE_LIMIT)
                  //if( AssocIsChild( AssociatedDevList[ i ].shortAddr ) == 1 && AssociatedDevList[ i ].age > NWK_ROUTE_AGE_LIMIT )
                 // {
                    //  myaddr.addr.shortAddr = AssociatedDevList[ i ].shortAddr;
                      /*
                      if ( AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID,(byte)osal_strlen( theMessageData ) + 1,
                              (byte *)&theMessageData,
                              &GenericApp_TransID,
                              AF_ACK_REQUEST, AF_DEFAULT_RADIUS ) != afStatus_SUCCESS )
                        {
                          uprint("delete asso");
                        */
                   //       delete_asso( AssociatedDevList[ i ]. addrIdx);
                          
                  // }
                    //    else
                     //   {
                          devlist[yy1] = AssociatedDevList[ i ].shortAddr;
                          yy1++;
                     //   }
                  
                  // }
             }
              else { break; }
          }
       // }else
        //{
          //devlist[yy1] = 0;
        //}
          devlist[0] = BUILD_UINT16(0xce,  ass_num );
          if ( AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, yy1*2,
                          (byte *)&devlist,
                          &GenericApp_TransID,
                          AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) != afStatus_SUCCESS )
          {
              AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, yy1*2,
                          (byte *)&devlist,
                          &GenericApp_TransID,
                          AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
             // send twice only, if it is still not ok, f**k it
          }
        
          
          //cb_SendDataRequest( 0x0000, GENERICAPP_CLUSTERID, yy1*2+1, (uint8*)&devlist[0], 0, AF_DISCV_ROUTE, 0 );
          
          //UART_Send_String( (uint8*)&devlist[0], yy1*2);
          
            //p1 = AssocMakeList( &cnt );
            //UART_Send_String( (uint8*)p1,  AssocCount(1, 4)*2);
            //osal_mem_free(p1);
        }
#endif  
    } //if( pkt->cmd.DataLength == 1)
    
    if( pkt->cmd.DataLength == 3)
    { 
        //ed fa 01 ,turn on led 1
        //ed ff 01  turn off led 1
        if( pkt->cmd.Data[0] == 0xed  && pkt->cmd.Data[1] == 0xfa )
        {
            switch(pkt->cmd.Data[2])
            {
              case 0x01:
                led1 = 1;
                break;
              case 0x05:
                // led5 = 1;
                break;
              default:break;
            }
                   
        }
        if( pkt->cmd.Data[0] == 0xed  && pkt->cmd.Data[1] == 0xff )
        {
            switch(pkt->cmd.Data[2])
            {
              case 0x01:
                led1 = 0;
                break;
              case 0x05:
               //  led5 = 0;
                break;
              default:break;
            }          
        }
        
    } // if( pkt->cmd.DataLength == 3)
    
     // led1 = !led1;
     // led5 = !led5;
      break;
  }
  
#if defined( LCD_SUPPORTED )
      UART_Send_String( &pkt->cmd.Data[0], pkt->cmd.DataLength);
#endif

}
コード例 #7
0
ファイル: GenericApp.c プロジェクト: cuu/weiyi
void Serial_callBack(uint8 port, uint8 event)
{
  char theMessageData[] = "Hello";
  zAddrType_t dstAddr;
  zAddrType_t ZAddr;
  
  afAddrType_t myaddr; // use for p2p
  
  char pbuf[3];
  char pbuf1[3];
  uint16 cmd;
  
  uint8 buff[128];
  uint8 readBytes = 0;
  
  uint16 short_ddr;
  uint16 panid;
  uint8 *ieeeAddr;
  
  uint16 *p1;
  
  byte cnt = 0;
  uint8 yy1;
  uint8 yy2;
  
  uint8 i;
  byte nr;
  uint16 devlist[ NWK_MAX_DEVICES + 1];
  associated_devices_t *adp; // delete devices
  
  //short_ddr = GenericApp_DstAddr.addr.shortAddr;
  uint8 startOptions;    
  uint8 logicalType;
  
  logicalType = (uint8)ZDO_Config_Node_Descriptor.LogicalType;
  
            
  readBytes = HalUARTRead(SER_PORT, buff, 127);
  if (readBytes > 0)
  {
    //HalUARTWrite( SER_PORT, "DataRead: ",10);
    // HalUARTWrite( SER_PORT, buff, readBytes);
    if(readBytes == 4)
    {
      if(buff[0] == 'p' && buff[1] == 'i' && buff[2]=='n' && buff[3] == 'g')
      {
          UART_Send_String( "pong", 4 );
      }
    }
    
    if( readBytes == 1)
    {
        yy1 = 1;
        if(buff[0]== 's')
        {
          /// short address
          short_ddr = _NIB.nwkDevAddress;
          
          UART_Send_String( (uint8*)&short_ddr, 2);
          
        }
        if(buff[0] == 'p')
        {
          /// pan id
          panid = _NIB.nwkPanId;
          UART_Send_String( (uint8*)&panid, 2);          
        }
        if(buff[0] == 'c')/// channel
        {
            yy2 = _NIB.nwkLogicalChannel;
            UART_Send_String( (uint8*)&yy2, 1);
            
        }
        if(buff[0] =='m') // mac address
        {
            ieeeAddr = NLME_GetExtAddr();
            UART_Send_String( ieeeAddr, 8);
            
        }

        if( buff[0] ==0xc0) // coordinator 
        {

          set_coordi();       
          return;
        }

        if( buff[0] ==0xe0) // router
        {
          set_router();
          
          return;
        }
        
        if(buff[0] == 0xCA)
        {
          // 使命的招唤
          // read self AssociatedDevList
          for(i=0;i< NWK_MAX_DEVICES; i++)
          {
             nr = AssociatedDevList[ i ].nodeRelation;
             if(nr > 0 && nr < 5) //CHILD_RFD CHILD_RFD_RX_IDLE CHILD_FFD CHILD_FFD_RX_IDLE
             //if( nr != 0XFF)
             {
               //   myaddr.addrMode = (afAddrMode_t)Addr16Bit;
               //   myaddr.endPoint = GENERICAPP_ENDPOINT;
             //  if( AssociatedDevList[ i ].shortAddr != 0x0000)
             //  {
                  //if( AssocIsChild( AssociatedDevList[ i ].shortAddr ) != 1 || AssociatedDevList[ i ].age > NWK_ROUTE_AGE_LIMIT)
                  //if( AssocIsChild( AssociatedDevList[ i ].shortAddr ) == 1 && AssociatedDevList[ i ].age > NWK_ROUTE_AGE_LIMIT )
                 // {
                    //  myaddr.addr.shortAddr = AssociatedDevList[ i ].shortAddr;
                      /*
                      if ( AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID,(byte)osal_strlen( theMessageData ) + 1,
                              (byte *)&theMessageData,
                              &GenericApp_TransID,
                              AF_ACK_REQUEST, AF_DEFAULT_RADIUS ) != afStatus_SUCCESS )
                        {
                          uprint("delete asso");
                        */
                   //       delete_asso( AssociatedDevList[ i ]. addrIdx);
                          
                  // }
                    //    else
                     //   {
                          devlist[yy1] = AssociatedDevList[ i ].shortAddr;
                          yy1++;
                     //   }
                  
                  // }
             }//else {break;}
          }
          devlist[0] = BUILD_UINT16(0xce,  AssocCount(1, 4) );
          UART_Send_String( (uint8*)&devlist[0], yy1*2);
            //p1 = AssocMakeList( &cnt );
            //UART_Send_String( (uint8*)p1,  AssocCount(1, 4)*2);
            //osal_mem_free(p1);
          return;
        }
    }
    
#if defined( ZDO_COORDINATOR )
    // only coordinator can have this function
    if(readBytes == 3)
    {
      
      if( buff[0] == 0xCA || buff[0] == 0x6d)
      {
        // CA xx xx ,send CA to a node ,with it's short address
        ///uprint("it's CA ");
        short_ddr = BUILD_UINT16( buff[1], buff[2] );
        myaddr.addrMode = (afAddrMode_t)Addr16Bit;
        myaddr.endPoint = GENERICAPP_ENDPOINT;
        myaddr.addr.shortAddr = short_ddr;
        
        if ( AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, 1,
                          (byte *)&buff,
                          &GenericApp_TransID,
                          AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) != afStatus_SUCCESS )
        {
             AF_DataRequest( &myaddr, &GenericApp_epDesc, GENERICAPP_CLUSTERID, 1,
                          (byte *)&buff,
                          &GenericApp_TransID,
                          AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
             // send twice only, if it is still not ok, f**k it
          
        }
       return;
      }
    }
          
#endif 
          
    if( readBytes >= 2)
    {
     
      if( buff[0] == 'e' && buff[1] == '#')
      {
          uprint("EndDevice match");
          HalLedSet ( HAL_LED_1, HAL_LED_MODE_OFF );

          dstAddr.addrMode = Addr16Bit;
          dstAddr.addr.shortAddr = 0x0000; // Coordinator
          ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(), GenericApp_epDesc.endPoint,
                            GENERICAPP_PROFID,
                            GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                            GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                            FALSE );
      
      }
 
      if( buff[0] == 'r' && buff[1] == '#')
      {
          uprint("Router Device match");
          
        HalLedSet ( HAL_LED_1, HAL_LED_MODE_FLASH );

      dstAddr.addrMode = AddrBroadcast;
      dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
      ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR,
                        GENERICAPP_PROFID,
                        GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                        GENERICAPP_MAX_CLUSTERS, (cId_t *)GenericApp_ClusterList,
                        FALSE );
      
      }
      if(readBytes == 6)
      {
        if(buff[0] == 'p' && buff[1]==':') // pan id
        {
            strncpy(pbuf, &buff[2],2); pbuf[2] = '\0';
            strncpy(pbuf1, &buff[4],2); pbuf1[2] = '\0';
            
            set_panid( BUILD_UINT16( strtol(pbuf1,NULL,16),strtol(pbuf,NULL,16) ));
            if(_NIB.nwkPanId == 0xffff)
            {
              zgWriteStartupOptions (ZG_STARTUP_SET, ZCD_STARTOPT_DEFAULT_NETWORK_STATE);           
              SystemReset();
            }            
            //SystemResetSoft();
        }
        
        if(buff[0] == 's' && buff[1]==':') // short address
        {
            /*
            strncpy(pbuf, &buff[2],2); pbuf[2] = '\0';
            strncpy(pbuf1, &buff[4],2); pbuf1[2] = '\0';
            _NIB.nwkDevAddress = BUILD_UINT16( strtol(pbuf1,NULL,16),strtol(pbuf,NULL,16));
            */
            
        }
      }
      
      
      cmd = BUILD_UINT16(buff[ 1 + 1], buff[1]);
      if( ( buff[ 0 ] == CPT_SOP) && (cmd == SYS_PING_REQUEST) ) 
      {
        sysPingReqRcvd();
        return;
      }

      if( readBytes == 2)
      {        
        if( buff[0] == 0xcc )
        {
          if( buff[1] > 0x0a && buff[1] < 0x1b )
          {

            _NIB.nwkLogicalChannel = buff[1];
            NLME_UpdateNV(0x01);
            ZMacSetReq( ZMacChannel, &buff[1]);
            
            osal_nv_item_init( ZCD_NV_CHANLIST, sizeof(zgDefaultChannelList), &zgDefaultChannelList);
            
            if( buff[1] == 0x0b)
            {
              zgDefaultChannelList = 0x00000800;
              
            } 
            if (buff[1] == 0x0c )
            {
              zgDefaultChannelList = 0x00001000;
            }            
            if (buff[1] == 0x0d )
            {
              zgDefaultChannelList = 0x00002000;
            }
            if (buff[1] == 0x0e )
            {
              zgDefaultChannelList = 0x00004000;
            }
            if (buff[1] == 0x0f )
            {
              zgDefaultChannelList = 0x00008000;
            }
            if (buff[1] == 0x10 )
            {
              zgDefaultChannelList = 0x00010000;
            }
            if (buff[1] == 0x11 )
            {
              zgDefaultChannelList = 0x00020000;
            }
            if (buff[1] == 0x12 )
            {
              zgDefaultChannelList = 0x00040000;
            }            
            if (buff[1] == 0x13 )
            {
              zgDefaultChannelList = 0x00080000;
            }
            if (buff[1] == 0x14 )
            {
              zgDefaultChannelList = 0x00100000;
            }
            if (buff[1] == 0x15 )
            {
              zgDefaultChannelList = 0x00200000;
            }            
            if (buff[1] == 0x16 )
            {
              zgDefaultChannelList = 0x00400000;
            }
            if (buff[1] == 0x17 )
            {
              zgDefaultChannelList = 0x00800000;
            }
            if (buff[1] == 0x18 )
            {
              zgDefaultChannelList = 0x01000000;
            }

            if (buff[1] == 0x19 )
            {
              zgDefaultChannelList = 0x02000000;
            }
            if (buff[1] == 0x1a )
            {
              zgDefaultChannelList = 0x04000000;
            }
            
            osal_nv_write(  ZCD_NV_CHANLIST, 0 ,sizeof(zgDefaultChannelList), &zgDefaultChannelList);
            
            UART_Send_String( (uint8*)&zgDefaultChannelList, sizeof(zgDefaultChannelList) );

            /*
            _NIB.nwkLogicalChannel = buff[1];
            NLME_UpdateNV(0x01);
            if( osal_nv_write(ZCD_NV_CHANLIST, 0, osal_nv_item_len( ZCD_NV_CHANLIST ), &tmp32) !=  ZSUCCESS)
            {
              uprint("change channel to nv failed");
            }
            */
            /*
            _NIB.nwkLogicalChannel = buff[1];
            ZMacSetReq( ZMacChannel, &buff[1]);
            ZDApp_NwkStateUpdateCB();
            _NIB.nwkTotalTransmissions = 0;
            nwkTransmissionFailures( TRUE );
            */
          }
        }
        
      }// readBytes==2


      ser_process( buff,readBytes );// 中讯威易的协议最小也是2 字节
    }//if( readBytes >= 2)


    AF_DataRequest( &GenericApp_DstAddr, &GenericApp_epDesc,
                       GENERICAPP_CLUSTERID,
                       readBytes,
                       (byte *)&buff,
                       &GenericApp_TransID,
                       AF_DISCV_ROUTE, AF_DEFAULT_RADIUS );
    
      
  } //if (readBytes > 0) 
}