📄 homedemorouter.c
字号:
/****************************************************************************
*
* MODULE: Home Demo Router code
*
* COMPONENT: $RCSfile: HomeDemoRouter.c,v $
*
* VERSION: $Name: $
*
* REVISION: $Revision: 1.6 $
*
* DATED: $Date: 2007/06/21 08:14:41 $
*
* STATUS: $State: Exp $
*
* AUTHOR: CJG
*
* DESCRIPTION:
* Endpoint 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 32000
#define HW_INT_Q_SIZE 32
#define HW_INT_Q_PTR_MASK 0x1f
/****************************************************************************/
/*** 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 u8LightAlarmLevel;
} 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;
uint16 u16ShortAddr;
uint8 u8ThisNode;
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;
} tsDemoData;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
PRIVATE void vInitDemoSystem(void);
PRIVATE void vInitEndpoint(void);
PRIVATE void vStartReadSensors(void *pvMessage, uint8 u8Len);
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 vAddDesc(void);
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
tsDemoData sDemoData;
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
#if 0
PUBLIC void vUartChar(char cChar)
{
/* Wait for TX FIFO empty */
while ((u8AHI_UartReadLineStatus(E_AHI_UART_0) & E_AHI_UART_LS_THRE) == 0);
/* Send the character */
vAHI_UartWriteData(E_AHI_UART_0, cChar);
}
#endif
/****************************************************************************
*
* 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();
/* 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)
{
AppColdStart();
}
/****************************************************************************
*
* 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)
{
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 */
vLedControl(0, puTransactionInd->uFrame.sKvp.uAttributeData.UnsignedInt8);
puTransactionRsp->uFrame.sKvp.eErrorCode = KVP_SUCCESS;
return bReturnVal;
}
/****************************************************************************
*
* NAME: JZA_vAfKvpResponse
*
* DESCRIPTION:
* Used to send response to incoming KVP frame
*
* 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
* *puTransactionInd R Pointer to incoming frame
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void JZA_vAfKvpResponse(APS_Addrmode_e eAddrMode,
uint16 u16AddrSrc,
uint8 u8SrcEP,
uint8 u8LQI,
uint8 u8DstEP,
uint8 u8ClusterID,
AF_Transaction_s *puTransactionInd)
{
}
/****************************************************************************
*
* NAME: JZA_pu8AfMsgObject
*
* DESCRIPTION:
* Receives incoming MSG 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:
* FALSE
*
****************************************************************************/
PUBLIC bool_t JZA_bAfMsgObject(APS_Addrmode_e eAddrMode,
uint16 u16AddrSrc,
uint8 u8SrcEP,
uint8 u8LQI,
uint8 u8DstEP,
uint8 u8ClusterID,
uint8 *pu8ClusterIDRsp,
AF_Transaction_s *puTransactionInd,
AF_Transaction_s *puTransactionRsp)
{
return FALSE;
}
/****************************************************************************
*
* NAME: JZA_vZdpResponse
*
* DESCRIPTION:
* Called when a ZDP response frame has been received. In this case no action
* is taken as no ZDP responses are anticipated.
*
* PARAMETERS: Name RW Usage
* u8Type R ZDP response type
* pu8Payload R Payload buffer
* u8PayloadLen R Length of payload
*
****************************************************************************/
PUBLIC void JZA_vZdpResponse(uint8 u8Type, uint8 u8LQI,uint8 *pu8Payload,
uint8 u8PayloadLen)
{
}
/****************************************************************************
*
* NAME: JZA_vAppEventHandler
*
* DESCRIPTION:
* Called regularly by the task scheduler. This function reads the hardware
* event queue and processes the events therein. It is important that this
* function exits after a relatively short time so that the other tasks are
* not adversely affected.
*
****************************************************************************/
PUBLIC void JZA_vAppEventHandler(void)
{
tsHwIntData *psHwIntData;
static bool_t bEBStatus = 0;
if(!bEBStatus)
{
if (sDemoData.bJoined == TRUE)
{
/* Things to do when first called */
vStartReadSensors(NULL, 0);
vLedControl(0, FALSE);
vLedControl(1, FALSE);
bEBStatus = TRUE;
}
}
/* Check queue for hardware interrupts, and process */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -