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

📄 apus_sensor.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:开始检测自己的温度
            SW2:  initiates end device binding
            SW3:停止检测自己温度
            SW4:  initiates a match description request
          shift+SW1 显示"ZIGBEE ZIGBEE12345"
          shift+SW2发送HELLO WORLD
          shift+SW3停止发送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板,然后在EB没有SW1(也就是没有自己检测温度前),DB板可以把
自己的数据送给EB板显示。(包括HELLO WORLD和温度)
EB板和DB板按SW3是可以停止检测温度的
EB板和DB板一旦绑定,DB板就一直发送HELLO WORLD(如果注释掉case ZDO_STATE_CHANGE:
就不会绑定就发了)
问题在于,如果绑定之后先发温度,就不能再发HELLO WORLD了。反之则可以。
*********************************************************************/

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

#include "APUS_Sensor.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;
  0,                          //  byte  AppNumInClusters;
  (cId_t *)NULL,              //  byte *pAppInClusterList;
  APUS_MAX_CLUSTERS,          //  byte  AppNumOutClusters;
  (cId_t *)Apus_ClusterList   //  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.
endPointDesc_t Apus_epDesc;

/*********************************************************************
 * EXTERNAL VARIABLES
 */

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

/*********************************************************************
 * LOCAL VARIABLES
 */
byte Apus_TaskID;   // Task ID for internal task/event processing
                          // This variable will be received when
                          // Apus_Init() is called.
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);
/*********************************************************************
 * 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 APUS_Sensor_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( &Apus_epDesc );

  // 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 APUS_Sensor_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;

          dstEP = ZDO_NewDstAddr->dstAddrDstEP;
          dstAddr = &ZDO_NewDstAddr->dstAddr;
          Apus_DstAddr.addrMode = (afAddrMode_t)dstAddr->addrMode;
          Apus_DstAddr.endPoint = dstEP;

          Apus_DstAddr.addr.shortAddr = dstAddr->addr.shortAddr;

          // Start sending "the" message in a regular interval.
             osal_start_timer( APUS_SEND_MSG_EVT,
                              APUS_SEND_MSG_TIMEOUT );
          break;

        case ZDO_STATE_CHANGE:
          Apus_NwkState = (devStates_t)(MSGpkt->hdr.status);
 /*
          if ( (Apus_NwkState == DEV_ZB_COORD)
              || (Apus_NwkState == DEV_ROUTER)
              || (Apus_NwkState == DEV_END_DEVICE) )
         */

          if (   (Apus_NwkState == DEV_END_DEVICE)

⌨️ 快捷键说明

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