void zclHomelink_zigbeeReset(void)
{
  uint16 clusters[2];
  zAddrType_t tempAddr = {{0}, (afAddrMode_t)AddrGroup};
  aps_Group_t tempGroup = {0, "SwitchX"};
  int i;
  
  for (i = HAL_NV_PAGE_BEG; i <= (HAL_NV_PAGE_BEG + HAL_NV_PAGE_CNT); i++)
  {
    HalFlashErase(i);
  }
  
  clusters[0] = ZCL_CLUSTER_ID_GEN_ON_OFF;
  clusters[1] = ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL;
  
  BindSetDefaultNV();
  aps_GroupsSetDefaultNV();
  
  // Initialize default groups.  Each button has a group ID built from the MAC.
  // The top 2 bits are for the endpoints.
  for(i = 0; i < NUM_BUTTONS; i ++) {
    tempGroup.ID =  i << 14 | (aExtendedAddress[1] & 0x3F) << 8 | aExtendedAddress[0];
    tempGroup.name[6] = '1' + i;
    tempAddr.addr.shortAddr = tempGroup.ID;
    bindAddEntry(ENDPOINT+i, &tempAddr, 0, 2, clusters);
    aps_AddGroup(ENDPOINT+i, &tempGroup);
  }
  BindWriteNV();
  aps_GroupsWriteNV();

  Onboard_soft_reset();
}
Example #2
0
/*********************************************************************
 * @fn      SampleApp_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_2
 *                 HAL_KEY_SW_1
 *
 * @return  none
 */
void SampleApp_HandleKeys( uint8 shift, uint8 keys )
{
  (void)shift;  // Intentionally unreferenced parameter
  
  if ( keys & HAL_KEY_SW_1 )
  {
    /* This key sends the Flash Command is sent to Group 1.
     * This device will not receive the Flash Command from this
     * device (even if it belongs to group 1).
     */
    SampleApp_SendFlashMessage( SAMPLEAPP_FLASH_DURATION );
  }

  if ( keys & HAL_KEY_SW_2 )
  {
    /* The Flashr Command is sent to Group 1.
     * This key toggles this device in and out of group 1.
     * If this device doesn't belong to group 1, this application
     * will not receive the Flash command sent to group 1.
     */
    aps_Group_t *grp;
    grp = aps_FindGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP );
    if ( grp )
    {
      // Remove from the group
      aps_RemoveGroup( SAMPLEAPP_ENDPOINT, SAMPLEAPP_FLASH_GROUP );
    }
    else
    {
      // Add to the flash group
      aps_AddGroup( SAMPLEAPP_ENDPOINT, &SampleApp_Group );
    }
  }
}
Example #3
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
}
Example #4
0
/*********************************************************************
 * @fn      TransmitApp_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:
 *                 EVAL_SW4
 *                 EVAL_SW3
 *                 EVAL_SW2
 *                 EVAL_SW1
 *
 * @return  none
 */
void TransmitApp_HandleKeys( byte shift, byte keys )
{
  aps_Group_t group;
  // Shift is used to make each button/switch dual purpose.
  if ( shift )
  {
    if ( keys & HAL_KEY_SW_1 )
    {
      // Assign yourself to group 1
      group.ID = 0x0001;
      group.name[0] = 0;
      aps_AddGroup( TRANSMITAPP_ENDPOINT, &group );
    }
    if ( keys & HAL_KEY_SW_2 )
    {
      // Change destination address to group 1
      TransmitApp_DstAddr.addrMode = afAddrGroup;
      TransmitApp_DstAddr.endPoint = 0;
      TransmitApp_DstAddr.addr.shortAddr = 0x001; // group address
    }
    if ( keys & HAL_KEY_SW_3 )
    {
    }
    if ( keys & HAL_KEY_SW_4 )
    {
    }
  }
  else
  {
    if ( keys & HAL_KEY_SW_1 )
    {
      TransmitApp_ChangeState();
    }

    if ( keys & HAL_KEY_SW_2 )
    {
      // Initiate an End Device Bind Request for the mandatory endpoint
      ZDApp_SendEndDeviceBindReq( TransmitApp_epDesc.endPoint );
    }

    if ( keys & HAL_KEY_SW_3 )
    {
      rxTotal = txTotal = 0;
      rxAccum = txAccum = 0;
      TransmitApp_DisplayResults();
    }

    if ( keys & HAL_KEY_SW_4 )
    {
      // Initiate a Match Description Request (Service Discovery)
      //  for the mandatory endpoint
      ZDApp_AutoFindDestination( TransmitApp_epDesc.endPoint );
    }
  }
}
void AT_AF_Register(uint8 *task_id){
 // Fill out the endpoint description.
  AT_AF_epDesc.endPoint = AT_AF_ENDPOINT;
  AT_AF_epDesc.task_id = task_id;
  AT_AF_epDesc.simpleDesc
            = (SimpleDescriptionFormat_t *)&AT_AF_SimpleDesc;
  AT_AF_epDesc.latencyReq = noLatencyReqs;
  
  // Register the endpoint description with the AF
  afRegister( &AT_AF_epDesc );
  
  aps_AddGroup( AT_AF_ENDPOINT, &AT_AF_Group );
  
}
/*********************************************************************
 * @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
}
Example #7
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
}
/*********************************************************************
 * @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 );
}
Example #9
0
/*********************************************************************
 * @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 );
}
Example #10
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
  
}
Example #11
0
ZStatus_t processGroupsClusterServerCommands(zclIncoming_t *pInMsg) {
	aps_Group_t group;
	uint8 grpCnt;
	uint16 *grpList;
	uint8 grpRspCnt = 0;
	ZStatus_t response;
	uint8 *pData;
	aps_Group_t *pGroup;

	afAddrType_t *dstAddr;
	
	pData = pInMsg->pData;
	group.ID = BUILD_UINT16( pData[0], pData[1] );
	dstAddr =  &pInMsg->msg->srcAddr;
	srcEP = pInMsg->msg->endPoint;
	seqNum = pInMsg->hdr.transSeqNum;
	switch(pInMsg->hdr.commandID){
	case COMMAND_GROUP_ADD:
		response = aps_AddGroup( srcEP,& group );
		if (response != ZSuccess){
			if ( response == ZApsDuplicateEntry )
				response = ZCL_STATUS_DUPLICATE_EXISTS;
        	else
	          response=ZCL_STATUS_INSUFFICIENT_SPACE;
		}
		sendGroupResponse( dstAddr, COMMAND_GROUP_ADD_RSP, response, group.ID, TRUE);
		response = ZCL_STATUS_CMD_HAS_RSP;
		break;
	case COMMAND_GROUP_VIEW:
		 pGroup = aps_FindGroup( srcEP, group.ID );
      	if ( pGroup ) {
	        response = ZCL_STATUS_SUCCESS;
      	} else {
        	// Group not found
        	response = ZCL_STATUS_NOT_FOUND;
        	pGroup = &group;
      	}
      	sendGroupViewResponse( dstAddr, response, pGroup, true );
      	response = ZCL_STATUS_CMD_HAS_RSP;
		break;
	case COMMAND_GROUP_GET_MEMBERSHIP:
		grpCnt = *pData++;
        
      	// Allocate space for the group list
      	grpList = osal_mem_alloc( sizeof( uint16 ) * APS_MAX_GROUPS );
      	if ( grpList != NULL ) {
	        if ( grpCnt == 0 ) {
	          	// Find out all the groups of which the endpoint is a member.
          		grpRspCnt = aps_FindAllGroupsForEndpoint( srcEP, grpList );
        	} else {
          		// Find out the groups (in the list) of which the endpoint is a member.
          		for ( int i = 0; i < grpCnt; i++ ){
		            group.ID = BUILD_UINT16( pData[0], pData[1] );
            		pData += 2;

            		if ( aps_FindGroup( srcEP, group.ID ) )
              			grpList[grpRspCnt++] = group.ID;
          		}
        	}
      
        	if ( grpCnt == 0 ||  grpRspCnt != 0 )  {
				sendGroupGetMembershipRequest(
					dstAddr, COMMAND_GROUP_GET_MEMBERSHIP_RSP,
					TRUE, ZCL_FRAME_SERVER_CLIENT_DIR, aps_GroupsRemaingCapacity(),
					grpRspCnt, grpList, true );
			}

			osal_mem_free( grpList );
      	} else {
	        // Couldn't allocate space for the group list -- send a Default Response command back.
    	    zclDefaultRspCmd_t defaultRspCmd;
        
        	defaultRspCmd.commandID = pInMsg->hdr.commandID;
	        defaultRspCmd.statusCode = ZCL_STATUS_INSUFFICIENT_SPACE;
    	    zcl_SendDefaultRspCmd( srcEP, dstAddr, pInMsg->msg->clusterId, &defaultRspCmd, ZCL_FRAME_SERVER_CLIENT_DIR, true, 0, seqNum );
		}

      	response = ZCL_STATUS_CMD_HAS_RSP;
		break;
	case COMMAND_GROUP_REMOVE:
		if ( aps_RemoveGroup( pInMsg->msg->endPoint, group.ID ) )
        	response = ZCL_STATUS_SUCCESS;
      	else
        	response = ZCL_STATUS_NOT_FOUND;
		sendGroupResponse( dstAddr, COMMAND_GROUP_REMOVE_RSP, response,  group.ID, true );
      	response = ZCL_STATUS_CMD_HAS_RSP;
		break;
	case COMMAND_GROUP_REMOVE_ALL:
	case COMMAND_GROUP_ADD_IF_IDENTIFYING:
	default:
		response = ZFailure;
	}
	return response;
}