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

📄 switch.c

📁 jennic公司的zigbee在灯光上应用源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************** * * MODULE:             ZigBee Light Switch code * * COMPONENT:          Switch.c,v * * VERSION: * * REVISION:           1.9 * * DATED:              2007/01/03 15:40:19 * * 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 "nwk.h"#include "af.h"#include "zdp.h"/****************************************************************************//***        Macro Definitions                                             ***//****************************************************************************//* Timing values */#define APP_TICK_PERIOD_ms			100/* 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 		bAppTimerStarted;    bool_t		bSwitchState;    bool_t		bStackReady;} tsSwitch;/****************************************************************************//***        Local Function Prototypes                                     ***//****************************************************************************/PRIVATE void vInit(void);PRIVATE void vCheckButtons(void *Message, uint8 u8Length);PRIVATE void vTxData(uint8 u8SwitchValue);PRIVATE void vPerformEndBindRequest(uint8 u8Endpoint);PRIVATE void vAddDesc(void);/****************************************************************************//***        Exported Variables                                            ***//****************************************************************************//****************************************************************************//***        Local Variables                                               ***//****************************************************************************//* File scope data */PRIVATE tsSwitch sSwitch;/****************************************************************************//***        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; */    /* set this field for 5139-based platforms. */    /* JZS_sConfig.bFlashTypeIsSST = FALSE; */    /* 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 Switch 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){    uint8 u8TimerId;	if (sSwitch.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 (sSwitch.eBound != E_BIND_BOUND)	{		vLedControl(LED2, TRUE);	}    /* if this is the first time this function has been called, the BOS Timer    will not have been started yet: so start it */    if (!sSwitch.bAppTimerStarted)    {    	sSwitch.bAppTimerStarted = TRUE;    	/* register the function vCheckButtons with the BOS Timer so that    	after APP_TICK_PERIOD_ms milliseconds, vCheckButtons gets called */    	bBosCreateTimer(vCheckButtons, NULL, 0, (APP_TICK_PERIOD_ms / 10), &u8TimerId);    }}/**************************************************************************** * * 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){    return FALSE;}/**************************************************************************** * * 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){

⌨️ 快捷键说明

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