⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zc_beeapp.c

📁 Zigbee Wireless Networking书中的示例代码
💻 C
字号:
/*****************************************************************************
* BeeApp.c
*
* This application (HaRangeExtenter) demonstrates a generic HA application.
* If programmed into in a router, can be used to extend the range of a ZigBee
* Home Automation network.
*
* Copyright (c) 2006, Freescale, Inc. All rights reserved.
*
*
* No part of this document must be reproduced in any form - including copied,
* transcribed, printed or by any electronic means - without specific written
* permission from Freescale Semiconductor.
*
* USER INTERFACE
* --------------
*
* Like most BeeStack sample applications, this application uses the the common
* ASL user interface. The ASL interface has two "modes" to allow the keys, LEDs
* and (optional on NCB) the LCD display to be used for multiple purposes.
* Configuration mode includes commands such as starting and leaving the network,
* whereas application mode includes application specific functions and display.
*
* Each key (aka switch) can be pressed for a short duration (short press) or
* long duration of about 2+ seconds (long press). Examples include SW1 or LSW3.
*
* Application specific code can be found here. Code common among applications
* can be found in ASL_UserInterface.c
*
* Config Mode:
* SW1  - Form/join network (form if ZC, join if ZR or ZED) with previous configuration
* SW2  - Toggle Permit Join (ZC/ZR only)
* SW3  - Use end-device-bind to bind to another node (e.g. switch to light)
* SW4  - Choose channel (default is 25). Only functional when NOT on network.
* LSW1 - Toggle display/keyboard mode (Config and Application)
* LSW2 - Leave network
* LSW3 - Remove all binding
* LSW4 - Form/join network (form if ZC, join if ZR or ZED) with new configuration
*
* OnOffSwitch Application Mode:
* SW1  -
* SW2  -
* SW3  - Toggle Identify mode on/off (will stay on for 20 seconds)
* SW4  - Recall scene(must store scene  first with LSW4)
* LSW1 - Toggle display/keyboard mode (Config and Application)
* LSW2 -
* LSW3 - Add any OnOffLights in identify mode to a group
* LSW4 - Add any OnOffLights in identify mode to scene
*
*****************************************************************************/
#include "BeeStack_Globals.h"
#include "BeeStackConfiguration.h"
#include "BeeStackParameters.h"
#include "AppZdoInterface.h"
#include "TS_Interface.h"
#include "TMR_Interface.h"
#include "AppAfInterface.h"
#include "FunctionLib.h"
#include "PublicConst.h"
#include "keyboard.h"
#include "Display.h"
#include "EndPointConfig.h"
#include "BeeApp.h"
#include "ZDOStateMachineHandler.h"
#include "BeeAppInit.h"
#include "NVM_Interface.h"
#include "ZtcInterface.h"
#include "HaProfile.h"
#include "HaOptions.h"
#include "ZdpManager.h"
#include "ASL_ZdpInterface.h"
#include "ASL_UserInterface.h"
#include "ASL_ZCLInterface.h"
#include "Led.h"

/******************************************************************************
*******************************************************************************
* Private type definitions
*******************************************************************************
******************************************************************************/
bool_t LightFlag = FALSE;
#define ticksof10Sec 10000

#define ticksof10Sec 10000
#define PermitJoinOn 0xFF
#define PermitJoinOff 0x00

#define dLed1 0x01
#define dLed2 0x02
#define dLed3 0x04
#define dLed4 0x08
/******************************************************************************
*******************************************************************************
* Private Prototypes
*******************************************************************************
******************************************************************************/

void BeeAppTask(event_t events);
void BeeAppDataIndication(void);
void BeeAppDataConfirm(void);

/******************************************************************************
*******************************************************************************
* Private Memory Declarations
*******************************************************************************
******************************************************************************/


/******************************************************************************
*******************************************************************************
* Public memory declarations
*******************************************************************************
******************************************************************************/

zbEndPoint_t appEndPoint;

/* This data set contains app layer variables to be preserved across resets */
NvDataItemDescription_t const gaNvAppDataSet[] = {
  {&gBeeStackParameters,    sizeof(beeStackParameters_t)},  /* BeeStackSpecific */
  {&gZclCommonAttr,         sizeof(zclCommonAttr_t)},       /* scenes, location, etc... */
  {&gAslData,               sizeof(ASL_Data_t)},            /* state of ASL */
  /* insert any user data for NVM here.... */
  {NULL, 0}       /* Required end-of-table marker. */
};


/******************************************************************************
*******************************************************************************
* Private Functions
*******************************************************************************
******************************************************************************/

/*****************************************************************************
* BeeAppInit
*
* Initialize the application.
****************************************************************************/
void BeeAppInit
  (
  void
  )
{
  uint8_t i;
  /* Southern Cross - ZC can hear ZR1, ZR2 and ZED Light */
  static zbNwkAddr_t maICanHearYouTable[] =
  { { 0x01, 0x00 }, /* 0x0001 ZR1 */
    { 0x3e, 0x14 }, /* 0x143e ZR2 */
    { 0x6f, 0x79 }  /* 0x796f ZED Light */
  };

  /* set up I-Can-Hear-You table */
  SetICanHearYouTable(3, maICanHearYouTable); 

  /* register the application endpoint(s), so we receive callbacks */
  for(i=0; i<gNum_EndPoints_c; ++i) {
    (void)AF_RegisterEndPoint(endPointList[i].pEndpointDesc);
  }

  /* where to send switch commands from */
  appEndPoint = endPointList[0].pEndpointDesc->pSimpleDesc->endPoint;

  /* start with all LEDs off */
  ASL_InitUserInterface("HaRangeExtender");
}

/*****************************************************************************
* BeeAppAppTask
*
* The application task.
*****************************************************************************/
void BeeAppTask
  (
  event_t events    /*IN: events for the application task */
  )
{
  /* received one or more data confirms */
  if(events & gAppEvtDataConfirm_c)
    BeeAppDataConfirm();

  /* received one or more data indications */
  if(events & gAppEvtDataIndication_c)
    BeeAppDataIndication();

  /* ZCL specific */
  if(events & gAppEvtAddGroup_c)
    ASL_ZclAddGroupHandler();

  if(events & gAppEvtStoreScene_c)
    ASL_ZclStoreSceneHandler();

    if(events & gAppEvtSyncReq_c)
      ASL_Nlme_Sync_req(FALSE);
}

/*****************************************************************************
* BeeAppHandleKeys
*
* Handles all key events for this device.
*****************************************************************************/
void BeeAppHandleKeys
  (
  key_event_t events  /*IN: Events from keyboard modul */
  )
{
(void) events;
  /* Clear LCD Display */
  LCD_ClearDisplay();

  /* no application specific keys, let ASL handle all of them */
  ASL_HandleKeys(events);
}

/*****************************************************************************
* BeeAppUpdateDevice
*
* Contains application specific
*
*
* The default keyboard handling uses a model system: a network configuration-mode
* and an application run-mode. Combined with the concepts of short and
* long-press, this gives the application a total of 16 keys on a 4 button system
* (4 buttons * 2 modes * short and long).
*
* Config-mode covers joining and leaving a network, binding and other
* non-application specific keys, and are common across all Freescale applications.
*
* Run-mode covers application specific keys.
*
*****************************************************************************/
void BeeAppUpdateDevice
  (
  zbEndPoint_t endPoint,    /* IN: endpoint update happend on */
  zclUIEvent_t event        /* IN: state to update */
  )
{
  /* no application specific events, let ASL handle all of them */
  ASL_UpdateDevice(endPoint,event);
}

/*****************************************************************************
  BeeAppDataIndication

  Process incoming ZigBee over-the-air messages.
*****************************************************************************/
void BeeAppDataIndication
  (
  void
  )
{
  apsdeToAfMessage_t *pMsg;
  zbApsdeDataIndication_t *pIndication;
  zbStatus_t status = gZclMfgSpecific_c;

  while(MSG_Pending(&gAppDataIndicationQueue))
  {
    /* Get a message from a queue */
    pMsg = MSG_DeQueue( &gAppDataIndicationQueue );

    /* ask ZCL to handle the frame */
    pIndication = &(pMsg->msgData.dataIndication);
    status = ZCL_InterpretFrame(pIndication);

    /* not handled by ZCL interface, handle cluster here... */
    if(status == gZclMfgSpecific_c)
    {
      /* insert manufacturer specific code here... */
    }

    /* Free memory allocated by data indication */
    MSG_Free(pMsg);
  }
}

/*****************************************************************************
  BeeAppDataConfirm

  Process incoming ZigBee over-the-air data confirms.
*****************************************************************************/
void BeeAppDataConfirm
  (
  void
  )
{
  apsdeToAfMessage_t *pMsg;
  zbApsdeDataConfirm_t *pConfirm;

  while(MSG_Pending(&gAppDataConfirmQueue))
  {
    /* Get a message from a queue */
    pMsg = MSG_DeQueue( &gAppDataConfirmQueue );
    pConfirm = &(pMsg->msgData.dataConfirm);

    /* Action taken when confirmation is received. */
    if( pConfirm->status != gSuccess_c )
    {
      /* The data wasn't delivered -- Handle error code here */
    }

    /* Free memory allocated in Call Back function */
    MSG_Free(pMsg);
  }
}


/******************************************************************************
*******************************************************************************
* Public Functions
*******************************************************************************
******************************************************************************/

/* place functions here that will be shared by other modules */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -