📄 homedemoenddevice.c
字号:
/****************************************************************************
*
* MODULE: Home Demo End Device code
*
* COMPONENT: $RCSfile: HomeDemoEndDevice.c,v $
*
* VERSION: $Name: $
*
* REVISION: $Revision: 1.7 $
*
* DATED: $Date: 2007/06/21 08:14:40 $
*
* STATUS: $State: Exp $
*
* AUTHOR: CJG
*
* DESCRIPTION:
* End device for demonstrator. Synchronises to coordinator and sends
* back data, sets up sensor reads.
*
* LAST MODIFIED BY: $Author: jahme $
* $Modtime: $
*
****************************************************************************
*
* This software is owned by Jennic and/or its supplier and is protected
* under applicable copyright laws. All rights are reserved. We grant You,
* and any third parties, a license to use this software solely and
* exclusively on Jennic products. You, and any third parties must reproduce
* the copyright and warranty notice and any other legend of ownership on each
* copy or partial copy of the software.
*
* THIS SOFTWARE IS PROVIDED "AS IS". JENNIC MAKES NO WARRANTIES, WHETHER
* EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
* ACCURACY OR LACK OF NEGLIGENCE. JENNIC SHALL NOT, IN ANY CIRCUMSTANCES,
* BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, SPECIAL,
* INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER.
*
* Copyright Jennic Ltd 2005, 2006, 2007. All rights reserved
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include "jendefs.h"
#include "ALSdriver.h"
#include "HTSdriver.h"
#include "AppHardwareApi.h"
#include "LedControl.h"
#include "Button.h"
#include "gdb.h"
#include "JZ_Api.h"
#include "AppApi.h"
#include "HomeDemoProfile.h"
#include "nwk.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
/* Timing values */
#define ONE_SEC_IN_32K_PERIODS 32000UL
#define HW_INT_Q_SIZE 32
#define HW_INT_Q_PTR_MASK 0x1f
#define TX_WAIT_MS 20
//#define SLEEP_PERIOD_ms 250UL
//#define SLEEP_PERIOD (SLEEP_PERIOD_ms * 32UL)
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
/* State machine states */
typedef enum
{
E_STATE_READY_TO_READ_SENSORS,
E_STATE_READING_S1,
E_STATE_READING_S2
} teState;
typedef struct
{
uint32 u32Device;
uint32 u32ItemBitmap;
} tsHwIntData;
/* All variables with scope throughout module are in one structure */
typedef struct
{
/* Transceiver (basically anything TX/RX not covered elsewhere) */
struct
{
uint8 u8CurrentTxHandle;
uint8 u8PrevRxBsn;
} sTransceiver;
/* Controls (switch, light level alarm) */
struct
{
uint8 u8Switch;
uint8 u8LedState;
} sControls;
/* Sensor data, stored between read and going out in frame */
struct
{
uint8 u8TempResult;
uint8 u8HtsResult;
uint8 u8AlsResult;
} sSensors;
/* System (state, assigned address, channel) */
struct
{
teState eState;
uint8 u8Channel;
uint32 u32CalibratedTimeout;
} sSystem;
/* Queue for hardware interrupts */
struct
{
tsHwIntData asHwIntData[HW_INT_Q_SIZE];
volatile uint8 u8ReadPtr;
volatile uint8 u8WritePtr;
} sQueue;
bool_t bJoined;
bool_t bRejoining;
} tsDemoData;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
PRIVATE void vInitDemoSystem(bool_t bColdStart);
PRIVATE void vInitEndpoint(void);
PRIVATE void vStartReadSensors(void);
PRIVATE void vReadSensor2(void);
PRIVATE void vReadSensor3(void);
PRIVATE void vSendData(uint8 u8LightValue, uint8 u8TempValue,
uint8 u8HumidityValue, uint8 u8Switch);
PRIVATE uint8 u8FindMin(uint8 u8Val1, uint8 u8Val2);
PRIVATE void vSleep(void);
PRIVATE void vAddDesc(void);
#ifdef TEST_BOS_TIMER
PRIVATE void vTimerFired0(void *pvMessage, uint8 u8Len);
PRIVATE void vTimerFired1(void *pvMessage, uint8 u8Len);
#endif
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
tsDemoData sDemoData;
#ifdef TEST_BOS_TIMER
uint8 u8LedFlash0 = 0;
uint8 u8LedFlash1 = 0;
#endif
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
/****************************************************************************
*
* NAME: AppColdStart
*
* DESCRIPTION:
* Entry point for application. Initialises system, starts scan then
* processes interrupts.
*
* RETURNS:
* void, never returns
*
****************************************************************************/
PUBLIC void AppColdStart(void)
{
/* Debug hooks: include these regardless of whether debugging or not */
HAL_GDB_INIT();
HAL_BREAKPOINT();
/* General initialisation: reset hardware */
JZS_sConfig.u32Channel = 0;
JZS_sConfig.u16PanId = DEMO_PAN_ID;
JZS_sConfig.u16AppDataLength = 0;
vInitDemoSystem(TRUE);
/* No return from the above function call */
}
/****************************************************************************
*
* NAME: AppWarmStart
*
* DESCRIPTION:
* Entry point for application from boot loader. Simply jumps to AppColdStart
* as, in this instance, application will never warm start.
*
* RETURNS:
* Never returns.
*
****************************************************************************/
PUBLIC void AppWarmStart(void)
{
vInitDemoSystem(FALSE);
}
/****************************************************************************
*
* NAME: JZA_boAppStart
*
* DESCRIPTION:
* Called by Zigbee stack during initialisation. Sets up the profile
* information and starts the networking activity
*
* RETURNS:
* TRUE
*
****************************************************************************/
PUBLIC bool_t JZA_boAppStart(void)
{
#ifdef TEST_BOS_TIMER
bBosCreateTimer(vTimerFired0, NULL, 0, 10, NULL);
bBosCreateTimer(vTimerFired1, NULL, 0, 15, NULL);
#endif
JZS_vStartStack();
return TRUE;
}
/****************************************************************************
*
* NAME: JZA_vAppDefineTasks
*
* DESCRIPTION:
* Called by Zigbee stack during initialisation to allow the application to
* initialise any tasks that it requires. This application requires none.
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void JZA_vAppDefineTasks(void)
{
}
/****************************************************************************
*
* NAME: JZA_eAfKvpObject
*
* DESCRIPTION:
* Receives incoming KVP data frames
*
* PARAMETERS: Name RW Usage
* eAddrMode R Address mode of incoming frame
* u16AddrSrc R Network address of source node
* u8SrcEP R Endpoint address of source node
* u8LQI R Link Quality Indication
* u8DstEP R Destination endpoint address
* u8ClusterId R Cluster ID of incoming frame
* *pu8ClusterIDRsp R Pointer to cluster ID of response frame
* *puTransactionInd R Pointer to incoming frame
* *puTransactionRsp R Pointer to response frame
*
* RETURNS:
* TRUE for stack to automatically generate KVP response frames when appropriate
* FALSE otherwise
*
****************************************************************************/
PUBLIC bool_t JZA_bAfKvpObject( APS_Addrmode_e eAddrMode,
uint16 u16AddrSrc,
uint8 u8SrcEP,
uint8 u8LQI,
uint8 u8DstEP,
uint8 u8ClusterId,
uint8 *pu8ClusterIDRsp,
AF_Transaction_s *puTransactionInd,
AF_Transaction_s *puTransactionRsp)
{
bool_t bReturnVal = FALSE;
if (puTransactionInd->uFrame.sKvp.eCommandTypeID == SET_ACKNOWLEDGMENT)
{
bReturnVal = TRUE;
}
if ((eAddrMode != APS_ADDRMODE_SHORT) || (u8DstEP != 0x40))
{
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_ENDPOINT;
return bReturnVal;
}
if ( (puTransactionInd->uFrame.sKvp.eCommandTypeID != SET)
&& (puTransactionInd->uFrame.sKvp.eCommandTypeID != SET_ACKNOWLEDGMENT))
{
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_INVALID_COMMAND_TYPE;
return bReturnVal;
}
/* Assume data is switch info, and set LED */
sDemoData.sControls.u8LedState = puTransactionInd->uFrame.sKvp.uAttributeData.UnsignedInt8;
vLedControl(0, sDemoData.sControls.u8LedState);
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_SUCCESS;
return bReturnVal;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -