📄 light.c
字号:
/****************************************************************************
*
* MODULE: ZigBee Light Switch code
*
* COMPONENT: Light.c,v
*
* VERSION:
*
* REVISION: 1.12
*
* DATED: 2007/01/09 12:09:39
*
* STATUS: Exp
*
* AUTHOR: GPfef
*
* DESCRIPTION:
*
*
* LAST MODIFIED BY: gpfef
* $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 <AppHardwareApi.h>
#include <string.h>
#include "Button.h"
#include "LedControl.h"
#include "gdb.h"
#include "JZ_Api.h"
#include "af.h"
#include "aps.h"
#include "zdp.h"
#include "nwk.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
/* define LED positions */
#define LED1 0
#define LED2 1
/* define elements from Home Control Lighting profile */
#define PROFILEID_HC 0x0100
#define DEVICEID_HCL_SRC 0xfffe
#define DEVICEVERSION 0x0
#define CLUSTERID_ON_OFF_SRC 0x13
#define ATTRIBUTE_ON_OFF 0x0000
#define VALUE_ON 0xFF
#define VALUE_OFF 0x00
#define VALUE_TOGGLE 0xF0
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
/* Button values */
typedef enum
{
E_KEY_0 = BUTTON_0_MASK,
E_KEY_1 = BUTTON_1_MASK,
} teKeyValues;
/* binding state machine */
typedef enum
{
E_BIND_NONE,
E_BIND_BINDING,
E_BIND_BOUND
} teBindType;
/* All application data with scope within the entire file is kept here, */
typedef struct
{
teBindType eBound;
uint8 u8Endpoint;
bool_t bStackReady;
} tsLight;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
PRIVATE void vInit(void);
PRIVATE void vPerformEndBindRequest(uint8 u8Endpoint);
PRIVATE void vAddDesc(void);
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
/* File scope data */
PRIVATE tsLight sLight;
/****************************************************************************/
/*** Exported Functions ***/
/****************************************************************************/
/****************************************************************************
*
* NAME: AppColdStart
*
* DESCRIPTION:
* Entry point for application from boot loader. Initialises system.
*
* RETURNS:
* Never returns.
*
****************************************************************************/
PUBLIC void AppColdStart(void)
{
/* Debug hooks: include these regardless of whether debugging or not */
HAL_GDB_INIT();
HAL_BREAKPOINT();
/* Set essential ZigBee parameters */
JZS_sConfig.u32Channel = 0x14;
JZS_sConfig.u16PanId = 0x1aab;
JZS_sConfig.u16AppDataLength = 0;
/* Enable UART 0: 19200-8-N-1 */
vAHI_UartEnable(E_AHI_UART_0);
vAHI_UartReset(E_AHI_UART_0, TRUE, TRUE);
vAHI_UartReset(E_AHI_UART_0, FALSE, FALSE);
vAHI_UartSetClockDivisor(E_AHI_UART_0, E_AHI_UART_RATE_19200);
/* Initialise ZigBee stack */
(void)JZS_u32InitSystem(TRUE);
/* General initialisation */
vInit();
/* Start BOS */
(void)bBosRun(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)
{
AppColdStart();
}
/****************************************************************************
*
* NAME: JZA_boAppStart
*
* DESCRIPTION:
* Adds a simple descriptor for the Light endpoint
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC bool_t JZA_boAppStart(void)
{
/* start as a coordinator/router/end device according to the make file*/
JZS_vStartStack();
return TRUE;
}
/****************************************************************************
*
* NAME: JZA_vAppEventHandler
*
* DESCRIPTION:
* Main user routine. This is called by the Basic Operating System (BOS)
* at regular intervals.
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void JZA_vAppEventHandler(void)
{
if (sLight.bStackReady != TRUE)
{
return;
}
/* indicate that the device has started/joined a network and that the application
is now running */
vLedControl(LED1, FALSE);
/* ensure that LED 2 is on while waiting to bind */
if (sLight.eBound != E_BIND_BOUND)
{
vLedControl(LED2, TRUE);
}
/* check if user is trying initiate a Simple Bind */
if ((u8ButtonReadRfd() == E_KEY_0) && (sLight.eBound == E_BIND_NONE))
{
vPerformEndBindRequest(sLight.u8Endpoint);
}
}
/****************************************************************************
*
* NAME: JZA_vPeripheralEvent
*
* DESCRIPTION:
* Adds events to the hardware event queue.
*
* PARAMETERS: Name RW Usage
* u32Device R Peripheral responsible for interrupt e.g DIO
* u32ItemBitmap R Source of interrupt e.g. DIO bit map
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void JZA_vPeripheralEvent(uint32 u32Device, uint32 u32ItemBitmap)
{
}
/****************************************************************************
*
* NAME: JZA_vAppDefineTasks
*
* DESCRIPTION:
* Can be used to add additional tasks.
*
* 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -