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

📄 apus_router.c

📁 TI 公司的Z-STACK 应用层开发程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
  Filename:       Apus.c
  Revised:        $Date: 2006-08-01 09:24:16 -0700 (Tue, 01 Aug 2006) $
  Revision:       $Revision: 11547 $

  Description:
      - Generic Application (no Profile).

          This application isn't intended to do anything useful,
          it is intended to be a simple example of an application's
          structure.

          This application sends "Hello World" to another "Generic"
          application every 15 seconds.  The application will also
          receive "Hello World" packets.

          The "Hello World" messages are sent/received as MSG type
          message.

          This applications doesn't have a profile, so it handles
          everything directly - itself.

          Key control:
            SW1:?aê??ì2a×??oμ????è
            SW2:  initiates end device binding
            SW3:í£?1?ì2a×??o???è
            SW4:  initiates a match description request
          shift+SW1 ??ê?"ZIGBEE ZIGBEE12345"
          shift+SW2·¢?íHELLO WORLD
          shift+SW3í£?1·¢?íHELLO WORLD

  Notes:

  Copyright (c) 2006 by Texas Instruments, Inc.
  All Rights Reserved.  Permission to use, reproduce, copy, prepare
  derivative works, modify, distribute, perform, display or sell this
  software and/or its documentation for any purpose is prohibited
  without the express written consent of Texas Instruments, Inc.
?éò?DB°?°ó?¨EB°?£?è?oó?úEB??óDSW1£¨ò2?íê???óD×??o?ì2a???è?°£?£?DB°??éò?°?
×??oμ?êy?Y?í??EB°???ê??£(°üà¨HELLO WORLDoí???è)
EB°?oíDB°?°′SW3ê??éò?í£?1?ì2a???èμ?
EB°?oíDB°?ò?μ?°ó?¨,DB°??íò??±·¢?íHELLO WORLD(è?1?×¢êíμ?case ZDO_STATE_CHANGE:
?í2??á°ó?¨?í·¢á?)
?êìa?úóú£?è?1?°ó?¨??oó?è·¢???è£??í2??ü?ù·¢HELLO WORLDá??£·′???ò?éò??£
*********************************************************************/

/*********************************************************************
 * INCLUDES
 */
#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"

#include "APUS_Router.h"
#include "DebugTrace.h"

#if !defined( WIN32 )
  #include "OnBoard.h"
#endif

/* HAL */
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_uart.h"

/*********************************************************************
 * MACROS
 */

/*********************************************************************
 * CONSTANTS
 */

/*********************************************************************
 * TYPEDEFS
 */

/*********************************************************************
 * GLOBAL VARIABLES
 */



// This list should be filled with Application specific Cluster IDs.
const cId_t Apus_ClusterList[APUS_MAX_CLUSTERS] =
{
  APUS_CLUSTERID
};

const SimpleDescriptionFormat_t Apus_SimpleDesc =
{
  APUS_ENDPOINT,              //  int Endpoint;
  APUS_PROFID,                //  uint16 AppProfId[2];
  APUS_DEVICEID,              //  uint16 AppDeviceId[2];
  APUS_DEVICE_VERSION,        //  int   AppDevVer:4;
  APUS_FLAGS,                 //  int   AppFlags:4;
  APUS_MAX_CLUSTERS,          //  byte  AppNumInClusters;
  (cId_t *)Apus_ClusterList,  //  byte *pAppInClusterList;
  0,                          //  byte  AppNumOutClusters;
  (cId_t *)NULL               //  byte *pAppOutClusterList;
};

const cId_t Apus_ClusterListOut[APUS_MAX_CLUSTERS_ROUTER] =
{
  APUS_CLUSTERID_ROUT
};

const SimpleDescriptionFormat_t Apus_DataChoose =
{
  APUS_ENDPOINT_OUT,              //  int Endpoint;
  APUS_PROFID_OUT,                //  uint16 AppProfId[2];
  APUS_DEVICEID,              //  uint16 AppDeviceId[2];
  APUS_DEVICE_VERSION,        //  int   AppDevVer:4;
  APUS_FLAGS,                 //  int   AppFlags:4;
  0,          //  byte  AppNumInClusters;
  (cId_t *)NULL,  //  byte *pAppInClusterList;
  APUS_CLUSTERID_ROUT,                          //  byte  AppNumOutClusters;
  (cId_t *)Apus_ClusterListOut              //  byte *pAppOutClusterList;
};
// This is the Endpoint/Interface description.  It is defined here, but
// filled-in in Apus_Init().  Another way to go would be to fill
// in the structure here and make it a "const" (in code space).  The
// way it's defined in this sample app it is define in RAM.

byte Apus_TaskID;   // Task ID for internal task/event processing
                          // This variable will be received when
                          // Apus_Init() is called.
//endPointDesc_t Apus_epDesc;//*********************************************************************
//******************************************************************************************************
const endPointDesc_t Apus_epDesc =
{
  APUS_ENDPOINT,
  &Apus_TaskID,
  (SimpleDescriptionFormat_t *)&Apus_SimpleDesc,
  noLatencyReqs
};
 const endPointDesc_t Apus_epDescRouter =
{
  APUS_ENDPOINT_OUT,
  &Apus_TaskID,
  (SimpleDescriptionFormat_t *)&Apus_DataChoose,
  noLatencyReqs
};
/*********************************************************************
 * EXTERNAL VARIABLES
 */

/*********************************************************************
 * EXTERNAL FUNCTIONS
 */

/*********************************************************************
 * LOCAL VARIABLES
 */

devStates_t Apus_NwkState;


byte Apus_TransID;  // This is the unique message ID (counter)

afAddrType_t Apus_DstAddr;

/*********************************************************************
 * LOCAL FUNCTIONS
 */
void Apus_HandleKeys( byte shift, byte keys );
void Apus_MessageMSGCB( afIncomingMSGPacket_t *pckt );
void Apus_SendTheMessage( void );
//void Apus_SendTheMessage1( void );
//int16 temperature;

//int16 GetTemperature(void);
//void DispTemperature(void);
char buf[10];
uint16 temp2;
/*********************************************************************
 * NETWORK LAYER CALLBACKS
 */

/*********************************************************************
 * PUBLIC FUNCTIONS
 */

/*********************************************************************
 * @fn      Apus_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 ApusApp_Init( byte task_id )
{
  Apus_TaskID = task_id;
  Apus_NwkState = DEV_INIT;
  Apus_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().

  Apus_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
  Apus_DstAddr.endPoint = 0;
  Apus_DstAddr.addr.shortAddr = 0;

  // Fill out the endpoint description.
 /* Apus_epDesc.endPoint = APUS_ENDPOINT;
  Apus_epDesc.task_id = &Apus_TaskID;
  Apus_epDesc.simpleDesc
            = (SimpleDescriptionFormat_t *)&Apus_SimpleDesc;
  Apus_epDesc.latencyReq = noLatencyReqs;*/

  // Register the endpoint description with the AF
  afRegister( (endPointDesc_t *)&Apus_epDesc );
 // afRegister( &Apus_epDesc );
  afRegister( (endPointDesc_t *)&Apus_epDescRouter);
 // afRegister( &Apus_epDescRouter);
  // Register for all key events - This app will handle all key events
  RegisterForKeys( Apus_TaskID );

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

/*********************************************************************
 * @fn      Apus_ProcessEvent
 *
 * @brief   Generic Application Task event processor.  This function
 *          is called to process all events for the task.  Events
 *          include timers, messages and any other user defined events.
 *
 * @param   task_id  - The OSAL assigned task ID.
 * @param   events - events to process.  This is a bit map and can
 *                   contain more than one event.
 *
 * @return  none
 */
UINT16 ApusApp_ProcessEvent( byte task_id, UINT16 events )
{
   afIncomingMSGPacket_t *MSGpkt;
  afDataConfirm_t *afDataConfirm;
  ZDO_NewDstAddr_t *ZDO_NewDstAddr;
  byte dstEP;
  zAddrType_t *dstAddr;

  // Data Confirmation message fields
  byte sentEP;
  ZStatus_t sentStatus;
  byte sentTransID;       // This should match the value sent

  if ( events & SYS_EVENT_MSG )
  {
    MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( Apus_TaskID );
    while ( MSGpkt )
    {
      switch ( MSGpkt->hdr.event )
      {
        case KEY_CHANGE:
          Apus_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
          break;

        case AF_DATA_CONFIRM_CMD:
          // This message is received as a confirmation of a data packet sent.
          // The status is of ZStatus_t type [defined in ZComDef.h]
          // The message fields are defined in AF.h
          afDataConfirm = (afDataConfirm_t *)MSGpkt;
          sentEP = afDataConfirm->endpoint;
          sentStatus = afDataConfirm->hdr.status;
          sentTransID = afDataConfirm->transID;
          (void)sentEP;
          (void)sentTransID;

          // Action taken when confirmation is received.
          if ( sentStatus != ZSuccess )
          {
            // The data wasn't delivered -- Do something
          }
          break;

        case AF_INCOMING_MSG_CMD:
          Apus_MessageMSGCB( MSGpkt );
          break;

        case ZDO_NEW_DSTADDR:
          ZDO_NewDstAddr = (ZDO_NewDstAddr_t *)MSGpkt;

⌨️ 快捷键说明

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