/******************************************************************************
 * @fn          zb_StartRequest
 *
 * @brief       The zb_StartRequest function starts the ZigBee stack.  When the
 *              ZigBee stack starts, the device reads configuration parameters
 *              from Nonvolatile memory and the device joins its network.  The
 *              ZigBee stack calls the zb_StartConrifm callback function when
 *              the startup process completes.
 *
 * @param       none
 *
 * @return      none
 */
void zb_StartRequest()
{
  uint8 logicalType;

  zb_ReadConfiguration( ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType );

  // Check for bad combinations of compile flag definitions and device type setting.
  if ((logicalType > ZG_DEVICETYPE_ENDDEVICE)      ||
#if !ZG_BUILD_ENDDEVICE_TYPE   // Only RTR or Coord possible.
      (logicalType == ZG_DEVICETYPE_ENDDEVICE)     ||
#endif
#if !ZG_BUILD_RTR_TYPE         // Only End Device possible.
      (logicalType == ZG_DEVICETYPE_ROUTER)        ||
      (logicalType == ZG_DEVICETYPE_COORDINATOR)   ||
#elif ZG_BUILD_RTRONLY_TYPE    // Only RTR possible.
      (logicalType == ZG_DEVICETYPE_COORDINATOR)   ||
#elif !ZG_BUILD_JOINING_TYPE   // Only Coord possible.
      (logicalType == ZG_DEVICETYPE_ROUTER)        ||
#endif
      (0))
  {
    logicalType = ZB_INVALID_PARAMETER;
    SAPI_SendCback(SAPICB_START_CNF, logicalType, 0);
  }
  else
  {
    logicalType = ZB_SUCCESS;
    ZDOInitDevice(zgStartDelay);
  }

  
  return;
}
예제 #2
0
/*********************************************************************
 * @fn      SampleApp_Init
 *
 * @brief   Initialization function for the Generic App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void SampleApp_Init( uint8 task_id )
{
  SampleApp_TaskID = task_id;
  SampleApp_NwkState = DEV_INIT; // Device state : Initialized - not connected to anything
  SampleApp_TransID = 0; // The unique message ID (counter)

  // Device hardware initialization can be added here or in main() (Zmain.c). If the hardware is application 
  // specific(¯S©wÀ³¥Î) - add it here. If the hardware is other parts of the device(¨ä¥L¸Ë¸mªº³¡¤À) add it in main().

//#if defined ( BUILD_ALL_DEVICES )
//  // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START We are looking at a 
//  // jumper (defined in SampleAppHw.c) to be jumpered together - if they are - we will start up a 
//  // coordinator. Otherwise, the device will start as a router. -> ·íjumper¦³±µ¤W®É,¸Ë¸m¥HCoordinator±Ò°Ê,§_«h¥Hrouter±Ò°Ê.
//  if ( readCoordinatorJumper() )
//    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
//  else
//    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
//#endif // BUILD_ALL_DEVICES

#if defined ( HOLD_AUTO_START ) // HOLD_AUTO_START½sĶ¿ï¶µ·|¥õ¨îZDAppªº±Ò°Ê¸Ë¸m¤ÎÀ³¥Îµ{§Ç
  // HOLD_AUTO_START is a compile option that will surpress ZDApp from starting the device 
  // and wait for the application to start the device.
  ZDOInitDevice(0);
#endif
  
  /* SampleApp_Periodic Message's */
  // Setup for the periodic message's destination address Broadcast to everyone
  SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; // ¶Ç°e¼Ò¦¡-¼s¼½
  SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;          // end-point½s¸¹:20
  SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;                // ºô¸ô¦ì§}(0xFFFF -> ¼s¼½¨ìºô¸ô¤¤©Ò¦³¸Ë¸m(§t¥ð¯v))

  /* SampleApp_Flash Command's */
  // Setup for the flash command's destination address - Group 1
  SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;      // ¶Ç°e¼Ò¦¡-¸s²Õ¦ì§}
  SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;             // end-point½s¸¹:20
  SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;    // ¸s²Õ¦WºÙ¦ì§}
  
  /* SampleApp_epDesc description */
  // Fill out the endpoint description.
  SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;                    // SampleApp´y­zªºendpoint½s¸¹
  SampleApp_epDesc.task_id = &SampleApp_TaskID;                      // SampleApp´y­zªºTaskID
  SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;   // SampleApp´y­zªº²Å¸¹
  SampleApp_epDesc.latencyReq = noLatencyReqs;                       // ¦bAF¼hµù¥U§ï¥Îend-point

  // Register the endpoint description with the AF(¦V¤U¼hµù¥U¦¹À³¥Îµ{¦¡)
  afRegister( &SampleApp_epDesc );

  // Register for all key events - This app will handle all key events(¦V¤U¼hµù¥U«ö¶s¨Æ¥ó)
  RegisterForKeys( SampleApp_TaskID );

  // By default, all devices start out in Group 1 //µù¥U¸s²Õ
  SampleApp_Group.ID = 0x0001;
  osal_memcpy( SampleApp_Group.name, "Group 1", 7  );
  aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );  

#if defined ( LCD_SUPPORTED )
  HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 );
#endif
}
예제 #3
0
파일: protocol.c 프로젝트: cuu/weiyi
static void start_dev(void)
{
  
 #if defined ( HOLD_AUTO_START )
    ZDOInitDevice(0);
    osal_nv_item_init( 0x0201, sizeof(start_flag), &start_flag);
    start_flag = 1;
    osal_nv_write(0x0201,0,  sizeof(start_flag), &start_flag);
    
 #endif     

}
예제 #4
0
/*********************************************************************
 * @fn      OTA_ProcessSysApp_JoinReq
 *
 * @brief   Handles app messages from the console application.
 *
 * @param   pData - The data from the server.
 *
 * @return  none
 */
void OTA_ProcessSysApp_JoinReq(uint8 *pData)
{
    // Setup Z-Stack global configuration
    zgConfigPANID = BUILD_UINT16(pData[0], pData[1]);
    zgDefaultChannelList = 0x00000800;
    zgDefaultChannelList <<= (pData[2] - 11);
    zgDefaultStartingScanDuration = 0;

    // Make sure all NWK layer callbacks go to the stack
    _nwkCallbackSub = 0;

    // Start the stack.  This will join the PAN specified above
    ZDOInitDevice(0);
}
예제 #5
0
/*********************************************************************
 * @fn          zclRouterVersion1_Init
 *
 * @brief       Initialization function for the zclGeneral layer.
 *
 * @param       none
 *
 * @return      none
 */
void zclRouterVersion1_Init( byte task_id )
{
  zclRouterVersion1_TaskID = task_id;

  // Set destination address to indirect
  zclRouterVersion1_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
  zclRouterVersion1_DstAddr.endPoint = 2;
  zclRouterVersion1_DstAddr.addr.shortAddr = 0x0000;

  // This app is part of the Home Automation Profile
  zclHA_Init( &zclRouterVersion1_SimpleDesc );

  // Register the ZCL General Cluster Library callback functions
  zclGeneral_RegisterCmdCallbacks( ROUTERVERSION1_ENDPOINT, &zclRouterVersion1_CmdCallbacks );
  // Register the application's attribute list
  zcl_registerAttrList( ROUTERVERSION1_ENDPOINT, zclRouterVersion1_NumAttributes, zclRouterVersion1_Attrs );

  // Register the Application to receive the unprocessed Foundation command/response messages
  zcl_registerForMsg( zclRouterVersion1_TaskID );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( zclRouterVersion1_TaskID );

  // Register for a test endpoint
  afRegister( &sampleLight_TestEp );

  ZDO_RegisterForZDOMsg(task_id, Device_annce);

  osal_start_timerEx(zclRouterVersion1_TaskID, SET_PARAMETER, 1000);
  HAL_CONFIG_IO_OUTPUT(1,2,0);
  HAL_CONFIG_IO_OUTPUT(1,3,0);
  HAL_CONFIG_IO_OUTPUT(0,0,0);
  HAL_CONFIG_IO_OUTPUT(0,1,0);
  HAL_CONFIG_IO_OUTPUT(0,2,0);
  HAL_CONFIG_IO_OUTPUT(0,3,0);
  HAL_CONFIG_IO_OUTPUT(0,4,0);
  HAL_CONFIG_IO_OUTPUT(0,7,0);
  HalLedSet(HAL_LED_1,HAL_LED_MODE_OFF);
  HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF);
  //ZDOInitDevice(0);
   if (ZDApp_ReadNetworkRestoreState() == 0) {
      ZDOInitDevice(0);
    }
}
예제 #6
0
/**************************************************************************************************
 * @fn          znpBasicCfg
 *
 * @brief       Process the Conglomerate Basic Configuration command.
 *
 * input parameters
 *
 * @param       pBuf - Pointer to the MT buffer containing the conglomerated configuration.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 */
static void znpBasicCfg(uint8 *pBuf)
{
  uint32 t32 = osal_build_uint32( &pBuf[0], 4 );
  if (MT_PeriodicMsgRate != t32)
  {
    MT_PeriodicMsgRate = t32;
    (void)osal_start_reload_timer(MT_TaskID, MT_PERIODIC_MSG_EVENT, t32);
  }

  t32 = osal_build_uint32( &pBuf[4], 4 );
  if (osal_memcmp(&zgDefaultChannelList, &t32, 4) == FALSE)
  {
    (void)osal_nv_write(ZCD_NV_CHANLIST, 0, 4, &t32);
  }

  uint16 t16 = osal_build_uint16( &pBuf[8] );
  if (osal_memcmp(&zgConfigPANID, &t16, 2) == FALSE)
  {
    (void)osal_nv_write(ZCD_NV_PANID, 0, 2, &t16);
  }

  if (zgDeviceLogicalType != pBuf[10])
  {
    (void)osal_nv_write(ZCD_NV_LOGICAL_TYPE, 0, 1, pBuf+10);
  }

  if (pBuf[11] & MT_ZNP_CMD_DISC_RESET_NWK)
  {
    pBuf[0] = ZCD_STARTOPT_DEFAULT_NETWORK_STATE;
    (void)osal_nv_write(ZCD_NV_STARTUP_OPTION, 0, 1, pBuf);
#if defined CC2531ZNP
    SystemResetSoft();
#else
    SystemReset();
#endif
  }
  else if (pBuf[11] & MT_ZNP_CMD_DISC_ZDO_START)
  {
    if (devState == DEV_HOLD)
    {
      ZDOInitDevice(0);
    }
  }
}
예제 #7
0
/******************************************************************************
 * @fn          zb_StartRequest
 *
 * @brief       The zb_StartRequest function starts the ZigBee stack.  When the
 *              ZigBee stack starts, the device reads configuration parameters
 *              from Nonvolatile memory and the device joins its network.  The
 *              ZigBee stack calls the zb_StartConrifm callback function when
 *              the startup process completes.
 *
 * @param       none
 *
 * @return      none
 */
void zb_StartRequest()
{
  uint8 logicalType;

  // Start the device
  // start delay = min(NWK_START_DELAY, zgStartDelay) + rand() - only for fresh start, not restore
  if ( zgStartDelay < NWK_START_DELAY )
    zgStartDelay = 0;
  else
    zgStartDelay -= NWK_START_DELAY;

  // check that bad combinations of compile flag definitions and device type
  zb_ReadConfiguration( ZCD_NV_LOGICAL_TYPE, sizeof(uint8), &logicalType );
   if (  ( logicalType > ZG_DEVICETYPE_ENDDEVICE )        ||
#if defined( RTR_NWK )
  #if defined( ZDO_COORDINATOR )
          // Only RTR or Coord possible
         ( logicalType == ZG_DEVICETYPE_ENDDEVICE )   ||
  #else
          // Only RTR possible
          ( logicalType != ZG_DEVICETYPE_ROUTER )     ||
  #endif
#else
  #if defined( ZDO_COORDINATOR )
          // Error
          ( 1 )                                     ||
  #else
          // only ED possible
          ( logicalType != ZG_DEVICETYPE_ENDDEVICE )  ||
  #endif
#endif
          ( 0 ) )
   {
     // error configuration
     SAPI_SendCback( SAPICB_START_CNF, ZInvalidParameter, 0 );
   }
   else
   {
     ZDOInitDevice(zgStartDelay);
   }

  return;
}
예제 #8
0
/*********************************************************************
 * @fn      loadcontrol_HandleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   shift - true if in shift/alt.
 * @param   keys - bit field for key events. Valid entries:
 *                 HAL_KEY_SW_4
 *                 HAL_KEY_SW_3
 *                 HAL_KEY_SW_2
 *                 HAL_KEY_SW_1
 *
 * @return  none
 */
static void loadcontrol_HandleKeys( uint8 shift, uint8 keys )
{
  // Shift is used to make each button/switch dual purpose.
  if ( shift )
  {
    if ( keys & HAL_KEY_SW_1 )
    {
    }
    if ( keys & HAL_KEY_SW_2 )
    {
    }
    if ( keys & HAL_KEY_SW_3 )
    {
    }
    if ( keys & HAL_KEY_SW_4 )
    {
    }
  }
  else
  {
    if ( keys & HAL_KEY_SW_1 )
    {
      ZDOInitDevice(0); // join the network
    }

    if ( keys & HAL_KEY_SW_2 )
    {

    }

    if ( keys & HAL_KEY_SW_3 )
    {

    }

    if ( keys & HAL_KEY_SW_4 )
    {

    }
  }
}
예제 #9
0
/*********************************************************************
 * @fn      OTA_Dongle_HandleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   shift - true if in shift/alt.
 * @param   keys - bit field for key events. Valid entries:
 *                 HAL_KEY_SW_4
 *                 HAL_KEY_SW_3
 *                 HAL_KEY_SW_2
 *                 HAL_KEY_SW_1
 *
 * @return  none
 */
static void OTA_Dongle_HandleKeys( byte shift, byte keys )
{
    (void)shift;  // Intentionally unreferenced parameter

    if ( keys & HAL_KEY_SW_1 )
    {
        ZDOInitDevice(0);
    }

    if ( keys & HAL_KEY_SW_2 )
    {
    }

    if ( keys & HAL_KEY_SW_3 )
    {
    }

    if ( keys & HAL_KEY_SW_4 )
    {
    }
}
예제 #10
0
/*********************************************************************
 * @fn          zclSample_event_loop
 *
 * @brief       Event Loop Processor for zclGeneral.
 *
 * @param       none
 *
 * @return      none
 */
uint16 zclRouterVersion1_event_loop( uint8 task_id, uint16 events )
{
  afIncomingMSGPacket_t *MSGpkt;
  (void)task_id;  // Intentionally unreferenced parameter

  if ( events & SYS_EVENT_MSG )
  {
   while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( zclRouterVersion1_TaskID )) )
    {
      switch ( MSGpkt->hdr.event )
      {
        case ZCL_INCOMING_MSG:
          // Incoming ZCL Foundation command/response messages
          zclRouterVersion1_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
          break;      
        case KEY_CHANGE:
          //zclRouterVersion1_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
          break;

        case ZDO_STATE_CHANGE:
          zclRouterVersion1_NwkState = (devStates_t)(MSGpkt->hdr.status);

          // now on the network
          if ( (zclRouterVersion1_NwkState == DEV_ZB_COORD) ||
               (zclRouterVersion1_NwkState == DEV_ROUTER)   ||
               (zclRouterVersion1_NwkState == DEV_END_DEVICE) )
          {
            
            HalLedSet(HAL_LED_1,HAL_LED_MODE_ON);
          }
          break;

        default:
          {
            
          }
          break;
      }

      // Release the memory
      osal_msg_deallocate( (uint8 *)MSGpkt );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  
  if ( events & SET_PARAMETER ) {
    button1 = P0_2;
    button2 = P0_3;
    button3 = P0_4;
    return ( events = CHECK_INPUT_BUTTON);
  }
  
  if ( events & CHECK_INPUT_BUTTON ) {
    if (button1 ^ P0_2 ) {
      HalLedSet(HAL_LED_2,HAL_LED_MODE_TOGGLE);
      button1 = P0_2 ;
    }
    if (button2 ^ P0_3 ) {
      if(P1_2 == 0) {
        P1_2 = 1;
        //P0_1 = 1;
      } else {
        P1_2 = 0;
        //P0_1 = 0;
      }
      button2 = P0_3 ;
    }
    if (button3 ^ P0_4 ) {
      if(P1_3 == 0) {
        P1_3 = 1;
        //P0_1 = 1;
      } else {
        P1_3 = 0;
        //P0_1 = 0;
      }
      button3 = P0_4 ;
    }
    
    if (P0_1) {     
      ZDOInitDevice(0);
    }
      
    if ( P0_0) {
      zclRouterVersion1_BasicResetCB();
    }
    
    osal_start_timerEx(zclRouterVersion1_TaskID, CHECK_INPUT_BUTTON, 400);
    return ( events ^ CHECK_INPUT_BUTTON );
  }
  
  return 0;
}
예제 #11
0
파일: GenericApp.c 프로젝트: cuu/weiyi
void GenericApp_Init( uint8 task_id )
{
  uint16 size;
  
  GenericApp_TaskID = task_id;
  GenericApp_NwkState = DEV_INIT;
  GenericApp_TransID = 0;
  
  uint8 networkStateNV = ZDO_INITDEV_NEW_NETWORK_STATE;
  devStartModes_t devStartMode = MODE_RESUME; 
  

  //GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent; //(afAddrMode_t)Addr16Bit;
  GenericApp_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
  GenericApp_DstAddr.endPoint = GENERICAPP_ENDPOINT;
  GenericApp_DstAddr.addr.shortAddr = 0xFFFF;

  // Fill out the endpoint description.
  GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
  GenericApp_epDesc.task_id = &GenericApp_TaskID;
  GenericApp_epDesc.simpleDesc
            = (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
  GenericApp_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint description with the AF
  afRegister( &GenericApp_epDesc );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( GenericApp_TaskID );

  // Update the display
#if defined ( LCD_SUPPORTED )
  HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 );
#endif

  
#if !defined( ZDO_COORDINATOR )
  ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp );
  ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp );
  
#endif
  
#if defined ( BUILD_ALL_DEVICES )
  size = osal_nv_item_len( ZCD_NV_LOGICAL_TYPE );
  if( size  <= sizeof(zgDeviceLogicalType) && size != 0 )
  {
    cb_ReadConfiguration( ZCD_NV_LOGICAL_TYPE, sizeof(zgDeviceLogicalType), &zgDeviceLogicalType);
  }
  
#endif

#if defined ( HOLD_AUTO_START )
  if(start_flag == 1)
  {
      ZDOInitDevice(0);
  }
#endif
  serial_init();
  
  init_cc2530();
  
  HalLedSet( HAL_LED_2, HAL_LED_MODE_ON );
  
}
/*********************************************************************
 * @fn      SampleApp_Init
 *
 * @brief   Initialization function for the Generic App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void SampleApp_Init( uint8 task_id )
{
  SampleApp_TaskID = task_id; 
  SampleApp_NwkState = DEV_INIT;
  SampleApp_TransID = 0;
  MT_UartInit();//串口初始化
  MT_UartRegisterTaskID(task_id);//登记任务号
    
  
#ifdef MODE_ED //终端节点下才配置
/**************超声波***************/  
  
#define trig P0_1
#define echo P0_0

  P0DIR |= 0x02;		//P01输出trig
  P0DIR &= ~0x01;		//P00输入echo	
  trig=0;
  /*定时器配置*/ 


  HalTimerInit();
  HalTimerConfig(HAL_TIMER_0,
                 HAL_TIMER_MODE_CTC,
                 HAL_TIMER_CHANNEL_SINGLE,
                 HAL_TIMER_CH_MODE_OUTPUT_COMPARE,
                 TRUE,
                 timer_callback);
  /***********步进电机**************/
#define in1 P0_4
#define in2 P0_5
#define in3 P0_6
#define in4 P0_7  
  P0SEL &=~0xf0;
  P0DIR |= 0xf0;
  P0INP &=~0Xf0; //打开上拉

  in1=0;
  in2=0;
  in3=0;
  in4=0;
  /*测试*/
  int i=0;
  for(i=0;i<128;i++)
  {
    MotorCW();
  }

  for(i=0;i<128;i++)
  {
    MotorCCW();
  }        
  HalLedBlink( HAL_LED_2, 2,50, 500);

#endif
  // Device hardware initialization can be added here or in main() (Zmain.c).
  // If the hardware is application specific - add it here.
  // If the hardware is other parts of the device add it in main().

 #if defined ( BUILD_ALL_DEVICES )
  // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START
  // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered
  // together - if they are - we will start up a coordinator. Otherwise,
  // the device will start as a router.
  if ( readCoordinatorJumper() )
    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
  else
    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif // BUILD_ALL_DEVICES

#if defined ( HOLD_AUTO_START )
  // HOLD_AUTO_START is a compile option that will surpress ZDApp
  //  from starting the device and wait for the application to
  //  start the device.
  ZDOInitDevice(0);
#endif

  // Setup for the periodic message's destination address
  // Broadcast to everyone
  SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
  SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;

  // Setup for the flash command's destination address - Group 1
  SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;
  SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;
  
  // 网蜂点对点通讯定义
    Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;//点播
    Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
    Point_To_Point_DstAddr.addr.shortAddr = 0x0000; //发给协调器


  // Fill out the endpoint description.
  SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_epDesc.task_id = &SampleApp_TaskID;
  SampleApp_epDesc.simpleDesc
            = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;
  SampleApp_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint description with the AF
  afRegister( &SampleApp_epDesc );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( SampleApp_TaskID );

  // By default, all devices start out in Group 1
  SampleApp_Group.ID = 0x0001;
  osal_memcpy( SampleApp_Group.name, "Group 1", 7  );
  aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );

#if defined ( LCD_SUPPORTED )
  HalLcdWriteString( "SmartPark", HAL_LCD_LINE_1 );
#endif
}
예제 #13
0
/*********************************************************************
 * @fn      SampleApp_Init
 *
 * @brief   Initialization function for the Generic App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void SampleApp_Init( uint8 task_id )
{
  macRadioSetTxPower(20);
  SampleApp_TaskID = task_id;
  SampleApp_NwkState = DEV_INIT;
  SampleApp_TransID = 0;

   /***********串口初始化****************/
  MT_UartInit(); //串口配置初始化
  MT_UartRegisterTaskID(task_id);//登记串口任务号
  HalUARTWrite(0,"Hello World\r\n",13); // (串口 0,'字符',字符个数)
  // Device hardware initialization can be added here or in main() (Zmain.c).
  // If the hardware is application specific - add it here.
  // If the hardware is other parts of the device add it in main().

 #if defined ( BUILD_ALL_DEVICES )
  // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START
  // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered
  // together - if they are - we will start up a coordinator. Otherwise,
  // the device will start as a router.
  if ( readCoordinatorJumper() )
    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
  else
    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif // BUILD_ALL_DEVICES

#if defined ( HOLD_AUTO_START )
  // HOLD_AUTO_START is a compile option that will surpress ZDApp
  //  from starting the device and wait for the application to
  //  start the device.
  ZDOInitDevice(0);
#endif

  // Setup for the periodic message's destination address
  // Broadcast to everyone
  SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
  SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;
  
  // Setup for the flash command's destination address - Group 1
  SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;
  SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;

  // Fill out the endpoint description.
  SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_epDesc.task_id = &SampleApp_TaskID;
  SampleApp_epDesc.simpleDesc
            = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;
  SampleApp_epDesc.latencyReq = noLatencyReqs;
   
  // Register the endpoint description with the AF
  afRegister( &SampleApp_epDesc );
  
  // Register for all key events - This app will handle all key events
  RegisterForKeys( SampleApp_TaskID );

  /*分组信息初始化*/
  SampleApp_Group.ID = 0x0001;
  osal_memcpy( SampleApp_Group.name, "Group 1", 7  );
  aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );

#if defined ( LCD_SUPPORTED )
  HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 );
#endif
  
}
예제 #14
0
void SampleApp_Init( uint8 task_id )
{
  SampleApp_TaskID = task_id;
  SampleApp_NwkState = DEV_INIT;
  SampleApp_TransID = 0;
  //uart
  open(SampleApp_TaskID);

  // Device hardware initialization can be added here or in main() (Zmain.c).
  // If the hardware is application specific - add it here.
  // If the hardware is other parts of the device add it in main().
 
 #if defined ( SOFT_START )
  // The "Demo" target is setup to have SOFT_START and HOLD_AUTO_START
  // SOFT_START is a compile option that allows the device to start
  //  as a coordinator if one isn't found.
  // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered 
  // together - if they are - we will start up a coordinator. Otherwise,
  // the device will start as a router.
  if ( readCoordinatorJumper() )
    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
  else
    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif // SOFT_START
  
#if defined ( HOLD_AUTO_START )
  // HOLD_AUTO_START is a compile option that will surpress ZDApp
  //  from starting the device and wait for the application to 
  //  start the device.
  ZDOInitDevice(0);
#endif
  
  // Setup for the periodic message's destination address
  // Broadcast to everyone
  SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
  SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;

  // Setup for the flash command's destination address - Group 1
  SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
  SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Flash_DstAddr.addr.shortAddr = 0xFFFF;  //�s��
  //end device
  /*
  coordinator to end device must 0xffff
  end device to coordinator must 0x0000
  */
  //mpleApp_Flash_DstAddr.addr.shortAddr = 0x0000;
  //SampleApp_Flash_DstAddr.addr.shortAddr =SAMPLEAPP_FLASH_GROUP;
  //coordinator
   
   
  // Fill out the endpoint description.
  SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_epDesc.task_id = &SampleApp_TaskID;
  SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;
  SampleApp_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint description with the AF
  afRegister( &SampleApp_epDesc );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( SampleApp_TaskID );

  // By default, all devices start out in Group 1  
  SampleApp_Group.ID = SAMPLEAPP_FLASH_GROUP;
  osal_memcpy( SampleApp_Group.name, "Group 1", 7  );
  aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );

#if defined( HAL_UART )
  open(SampleApp_TaskID);
#endif  
#if defined ( LCD_SUPPORTED )
  HalLcdWriteString( "SampleApp", HAL_LCD_LINE_1 );
#endif
}
예제 #15
0
/*********************************************************************
 * @fn      HVACTest_Init
 *
 * @brief   Initialization function for the Generic App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void HVACTest_Init( uint8 task_id )
{
  HVACTest_TaskID = task_id;
  HVACTest_NwkState = DEV_INIT;
  HVACTest_TransID = 0;
  uint8 initVersion = 0;
  uint8 startupMsg[4] = {0xFF,0xFF,0,0};

  // use this code to trick compiler
  initVersion = firm_version + hardware_version + chip_version;
  (void)initVersion;  
  
  // Device hardware initialization can be added here or in main() (Zmain.c).
  // If the hardware is application specific - add it here.
  // If the hardware is other parts of the device add it in main().
  hvac_STM32ResetInit();
  // Register UART, init UART
  MT_UartInit ();
  MT_UartRegisterTaskID (HVACTest_TaskID);
  
  HVACTest_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
  HVACTest_DstAddr.endPoint = HVACQUEEN_ENDPOINT;
  HVACTest_DstAddr.addr.shortAddr = 0;

  // Fill out the endpoint description.
  HVACTest_epDesc.endPoint = HVACQUEEN_ENDPOINT;
  HVACTest_epDesc.task_id = &HVACTest_TaskID;
  HVACTest_epDesc.simpleDesc
            = (SimpleDescriptionFormat_t *)&HVACTest_SimpleDesc;
  HVACTest_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint description with the AF
  afRegister( &HVACTest_epDesc );
  
  // Register ZDO Message
  ZDO_RegisterForZDOMsg( HVACTest_TaskID, Device_annce );
  ZDO_RegisterForZDOMsg( HVACTest_TaskID, End_Device_Bind_rsp );
  ZDO_RegisterForZDOMsg( HVACTest_TaskID, Match_Desc_rsp );

  // Init critical resource
  ptl0_initPTL0Status();
  
  // check valid MAC address?
  //
  // If a mac address copy is valid in flash, send "FF FF FF" Msg to 
  // STM32 and start the zigbee network.
  //
  // If not, send "FF FF 00" Msg to STM32, and prepare to handle MAC 
  // address message.
  //
  // The forth byte is the firmware version
  
// Test program, no need init white list
// However, to disable any device to join, enable the empty white list function
  
  // Add firmware version
  startupMsg[3] = firm_version;
    
  // send valid flash startup mag
  while(HalUARTWrite(0, startupMsg, 4) != 4)
  {
#ifdef WDT_IN_PM1
    // clear WDT
    WDCTL |= WDCLP1; 
    WDCTL |= WDCLP2;
#endif
    HalUARTPoll();
  }
   
  // start network directly, form a network and check
  ZDOInitDevice(0);
 
  // Init timer
  osal_start_timerEx( HVACTest_TaskID,
               HVAC_PTL0_GUT_EVT,
               HVAC_PTL0_FAIL_TIMEOUT );
  
  // WDT
#ifdef WDT_IN_PM1
  // Start WDT reset timer
  osal_start_timerEx( HVACTest_TaskID,
                      HVAC_WDT_CLEAR_EVT,
                      HVAC_WDT_CLEAR_TIMEOUT ); 
#endif
  
#if defined( IAR_ARMCM3_LM )
  // Register this task with RTOS task initiator
  RTOS_RegisterApp( task_id, HVACQUEEN_RTOS_MSG_EVT );
#endif
}
예제 #16
0
/*********************************************************************
 * @fn      zcl_ProcessEZMode
 *
 * @brief   Called when EZ-Mode changes state. See EZMODE_STATE_xxxx in zcl_ezmode.h
 *
 * @param   none
 *
 * @return  status
 */
static void zcl_ProcessEZMode( void )
{
  zAddrType_t dstAddr;
  afAddrType_t afDstAddr;
  zclEZMode_CBData_t cbData;

  dstAddr.addr.shortAddr = 0xfffc;        // all routers (for PermitJoin) devices
  dstAddr.addrMode = AddrBroadcast;

  afDstAddr.addr.shortAddr = 0xffff;      // all devices (for IdentifyQuery)
  afDstAddr.addrMode = afAddrBroadcast;
  afDstAddr.endPoint = 0xff;

  switch(zclEZModeState)
  {
    // openers will broadcast permit joining
    case EZMODE_STATE_OPENER:
      zclEZModeOpener = 1;

      // enable joining both locally and over-the-air
      NLME_PermitJoiningRequest( (byte)(EZMODE_TIME / 1000)  );
      ZDP_MgmtPermitJoinReq( &dstAddr, (byte)(EZMODE_TIME / 1000), TRUE, FALSE);

      // then go to identifying state
      zcl_SetEZModeState(EZMODE_STATE_IDENTIFYING);
    break;

    // joiners will try to join the network, and if success will go to identifying state
    case EZMODE_STATE_JOINER:
      zclEZModeOpener = 0;
      ZDOInitDevice(0);   // see ZDO_STATE_CHANGE in zclSampleSw_event_loop()
    break;

    // go into identify state
    case EZMODE_STATE_IDENTIFYING:

      // tell app to go into identify mode
      if ( zclEZModeRegisterData.pfnNotifyCB )
      {
        (*zclEZModeRegisterData.pfnNotifyCB)( zclEZModeState, NULL );
      }

      // initiators start looking for other nodes in identify mode
      if ( zclEZModeInvokeData.initiator )
      {
        zcl_SetEZModeState ( EZMODE_STATE_WAITING_IDENTIFYQUERYRSP );
      }
    break;

    // timeout out with no query response, send another
    case EZMODE_STATE_WAITING_IDENTIFYQUERYRSP:
      // ZStatus_t zclGeneral_SendIdentifyQuery( uint8 srcEP, afAddrType_t *dstAddr, uint8 disableDefaultRsp, uint8 seqNum );
      // NOTE: Ensure that Identify Cluster is enabled to use this function for EZ-Mode
      zclGeneral_SendIdentifyQuery( zclEZModeInvokeData.endpoint, &afDstAddr, TRUE, (*zclEZModeRegisterData.pZclSeqNum)++ );

      // wait some time before sending out the next IdentifyQuery, will stop when we get a response
      osal_start_timerEx( *zclEZModeRegisterData.pTaskID, zclEZModeRegisterData.processEvt, EZMODE_IDQUERYTIME );
      break;

    // waiting for simple descriptor response
    case EZMODE_STATE_WAITING_MATCHDESCRSP:
    break;

    // if waiting on autoclose, then we're done. Go to success.
    case EZMODE_STATE_AUTOCLOSE:

      // special case: if 2 initators, we only fail if no match from either side
      if( zclEZModeInvokeData.initiator && !zclEZModeMatched )
      {
        zcl_SetEZModeError ( EZMODE_ERR_NOMATCH );
      }

      // if user specified callback, call on AutoClose
      if ( zclEZModeRegisterData.pfnNotifyCB )
      {
        cbData.sAutoClose.err = zclEZModeErr;
        (*zclEZModeRegisterData.pfnNotifyCB)( zclEZModeState, &cbData );
      }

      // no longer will timeout, since cannot fail
      osal_stop_timerEx( *zclEZModeRegisterData.pTaskID, zclEZModeRegisterData.timeoutEvt );

      // wait a little to turn off identify mode, to give time for the other side to discover
      // in case of complex devices (both target/initiator)
      osal_start_timerEx( *zclEZModeRegisterData.pTaskID, zclEZModeRegisterData.processEvt, EZMODE_AUTOCLOSETIME );

      // go to finish state after autoclose. Don't use zcl_SetEZModeState() because we don't want it to happen immediately
      zclEZModeState = EZMODE_STATE_FINISH;
    break;

    case EZMODE_STATE_FINISH:

      // no longer will timeout, since we're done
      osal_stop_timerEx( *zclEZModeRegisterData.pTaskID, zclEZModeRegisterData.timeoutEvt );

      // if we opened the network, close it now (turn off joining)
      if ( zclEZModeOpener )
      {
        ZDP_MgmtPermitJoinReq( &dstAddr, 0, TRUE, FALSE);
      }

      // if user callback, inform them of the finish, which will also turn off identify
      if ( zclEZModeRegisterData.pfnNotifyCB )
      {
        cbData.sFinish.err = zclEZModeErr;
        cbData.sFinish.ep = zclEZModeQueryRspEP;
        cbData.sFinish.nwkaddr = zclEZModeQueryRspNwkAddr;
        (*zclEZModeRegisterData.pfnNotifyCB)( zclEZModeState, &cbData );
      }

      // done, back to ready state
      zclEZModeState = EZMODE_STATE_READY;
    break;
  }

}
예제 #17
0
파일: ParkingAppE.c 프로젝트: kk30/kdc
/*********************************************************************
 * @fn      ParkingApp_Init
 *
 * @brief   Initialization function for the Generic App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 *
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 *
 * @return  none
 */
void ParkingApp_Init( uint8 task_id )
{
  //开始应用初始化,闪灯
  //HalLedSet(HAL_LED_1,HAL_LED_MODE_FLASH);
  HalLedBlink( HAL_LED_1, 10, 50, 1000 );

  ParkingApp_TaskID = task_id;
  ParkingApp_NwkState = DEV_INIT;
  ParkingApp_TransID = 0;

  // Device hardware initialization can be added here or in main() (Zmain.c).
  // If the hardware is application specific - add it here.
  // If the hardware is other parts of the device add it in main().

 #if defined ( BUILD_ALL_DEVICES )
  // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START
  // We are looking at a jumper (defined in ParkingAppHw.c) to be jumpered
  // together - if they are - we will start up a coordinator. Otherwise,
  // the device will start as a router.
  if ( readCoordinatorJumper() )
    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
  else
    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif // BUILD_ALL_DEVICES

#if defined ( HOLD_AUTO_START )
  // HOLD_AUTO_START is a compile option that will surpress ZDApp
  //  from starting the device and wait for the application to
  //  start the device.
  ZDOInitDevice(0);
#endif

  // Setup for the periodic message's destination address
  // Broadcast to everyone
#if (defined DATABROADCAST && DATABROADCAST == TRUE)
  ParkingApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast; //afAddr16Bit;
  ParkingApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; // 0x0000;
#else
  ParkingApp_Periodic_DstAddr.addrMode = (afAddrMode_t)afAddr16Bit;
  ParkingApp_Periodic_DstAddr.addr.shortAddr = 0x0000;
#endif
  ParkingApp_Periodic_DstAddr.endPoint = PARKINGAPP_ENDPOINT;
  
  // Fill out the endpoint description.
  ParkingApp_epDesc.endPoint = PARKINGAPP_ENDPOINT;
  ParkingApp_epDesc.task_id = &ParkingApp_TaskID;
  ParkingApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&ParkingApp_SimpleDesc;
  ParkingApp_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint description with the AF
  afRegister( &ParkingApp_epDesc );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( ParkingApp_TaskID );
  
  osal_pwrmgr_task_state( ParkingApp_TaskID, PWRMGR_CONSERVE );

  // Set TXPOWER
//  MAC_MlmeSetReq( ZMacPhyTransmitPower, &txPower );
  
  // By default, all devices start out in Group 1
  ParkingApp_Group.ID = 0x0005;
  osal_memcpy( ParkingApp_Group.name, "Group 1", 7  );
  aps_AddGroup( PARKINGAPP_ENDPOINT, &ParkingApp_Group );
}
예제 #18
0
/*********************************************************************
 * @fn      ipd_HandleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   shift - true if in shift/alt.
 * @param   keys - bit field for key events. Valid entries:
 *                 HAL_KEY_SW_4
 *                 HAL_KEY_SW_3
 *                 HAL_KEY_SW_2
 *                 HAL_KEY_SW_1
 *
 * @return  none
 */
static void ipd_HandleKeys( uint8 shift, uint8 keys )
{
    // Shift is used to make each button/switch dual purpose.
    if ( shift )
    {
        if ( keys & HAL_KEY_SW_1 )
        {
        }
        if ( keys & HAL_KEY_SW_2 )
        {
        }
        if ( keys & HAL_KEY_SW_3 )
        {
        }
        if ( keys & HAL_KEY_SW_4 )
        {
        }
    }
    else
    {
        if ( keys & HAL_KEY_SW_1 )
        {
            ZDOInitDevice(0); // join the network
        }

        if ( keys & HAL_KEY_SW_2 )
        {
#if defined( INTER_PAN )

            uint8 x = true;
            ZMacGetReq( ZMacRxOnIdle, &rxOnIdle );
            ZMacSetReq( ZMacRxOnIdle, &x );
            afAddrType_t dstAddr;
            uint8 option = 1;

            // Send a request for public pricing information using the INTERP-DATA SAP.
            // The request is sent as a broadcast to all PANs within the discovered
            // channel. Receiving devices that implement the INTRP-DATA SAP will process
            // it and, if any such device is able to respond, it will respond directly
            // to the requestor. After receiving at least one response the requestor may
            // store the PAN ID and device address of one or more responders so that it
            // may query them directly in future.
            dstAddr.addrMode = afAddrBroadcast;
            dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL;
            dstAddr.endPoint = STUBAPS_INTER_PAN_EP;
            dstAddr.panId = 0xFFFF;

            zclSE_Pricing_Send_GetCurrentPrice( IPD_ENDPOINT, &dstAddr, option, TRUE, 0 );
#endif
        }

        if ( keys & HAL_KEY_SW_3 )
        {

        }

        if ( keys & HAL_KEY_SW_4 )
        {

        }
    }
}
/*********************************************************************
 * @fn      SampleApp_Init
 * @brief   Initialization function for the Generic App Task.
 *          This is called during initialization and should contain
 *          any application specific initialization (ie. hardware
 *          initialization/setup, table initialization, power up
 *          notificaiton ... ).
 * @param   task_id - the ID assigned by OSAL.  This ID should be
 *                    used to send messages and set timers.
 * @return  none
 */
void SampleApp_Init( uint8 task_id )
{
  
  SampleApp_TaskID = task_id;
  SampleApp_NwkState = DEV_INIT;
  SampleApp_TransID = 0;
  
  //initial uart1 and uart0
  initUart1(UART_callback);
  MT_UartInit();//初始化
  
  // Device hardware initialization can be added here or in main() (Zmain.c).
  // If the hardware is application specific - add it here.
  // If the hardware is other parts of the device add it in main().

 #if defined ( BUILD_ALL_DEVICES )
  // The "Demo" target is setup to have BUILD_ALL_DEVICES and HOLD_AUTO_START
  // We are looking at a jumper (defined in SampleAppHw.c) to be jumpered
  // together - if they are - we will start up a coordinator. Otherwise,
  // the device will start as a router.
  if ( readCoordinatorJumper() )
    zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
  else
    zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif // BUILD_ALL_DEVICES

#if defined ( HOLD_AUTO_START )
  // HOLD_AUTO_START is a compile option that will surpress ZDApp
  //  from starting the device and wait for the application to
  //  start the device.
  ZDOInitDevice(0);
#endif

  // Setup for the periodic message's destination address
  // Broadcast to everyone
  SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
  SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF;

  // Setup for the flash command's destination address - Group 1
  SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;
  SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;
  
  //  点对点通讯定义
  Point_To_Point_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; //点播
  Point_To_Point_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
  Point_To_Point_DstAddr.addr.shortAddr = 0x0000;//发给协调器
  
  // Fill out the endpoint description.
  SampleApp_epDesc.endPoint = SAMPLEAPP_ENDPOINT;
  SampleApp_epDesc.task_id = &SampleApp_TaskID;
  SampleApp_epDesc.simpleDesc = (SimpleDescriptionFormat_t *)&SampleApp_SimpleDesc;
  SampleApp_epDesc.latencyReq = noLatencyReqs;

  // Register the endpoint description with the AF
  afRegister( &SampleApp_epDesc );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( SampleApp_TaskID );

  // By default, all devices start out in Group 1
  SampleApp_Group.ID = 0x0001;
  osal_memcpy( SampleApp_Group.name, "Group 1", 7  );
  aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );
}