/*********************************************************************
Filename: SampleApp.c
Revised: $Date: 2007-05-31 15:56:04 -0700 (Thu, 31 May 2007) $
Revision: $Revision: 14490 $
Description:
- Sample 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 it's messages either as broadcast or
broadcast filtered group messages. The other (more normal)
message addressing is unicast. Most of the other
sample applications are written to support the unicast
message model.
Key control:
SW1: Sends a flash command to all devices in Group 1.
SW2: Adds/Removes (toggles) this device in and out
of Group 1. This will enable and disable the
reception of the flash command.
Notes:
Copyright (c) 2007 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.
*********************************************************************/
/*********************************************************************
* INCLUDES
*/
#include "OSAL.h"
#include "ZGlobals.h"
#include "AF.h"
#include "aps_groups.h"
#include "ZDApp.h"
#include "SampleApp.h"
#include "SampleAppHw.h"
#include "OnBoard.h"
#include "stdio.h"
#include "NLMEDE.h"
#include "string.h"
/* HAL */
#include "lcd128_64.h"
#include "hal_led.h"
#include "hal_key.h"
#include "Menu.h"
//#include "hal.h"
#include "wxl_uart.h"
#include "hal_lcd.h"
INT8U LanguageSel = 1;
#define RCVTEST
/*********************************************************************
* MACROS
*/
extern void ClearScreenLcd(void);
/*********************************************************************
* CONSTANTS
*/
/*********************************************************************
* TYPEDEFS
*/
/*********************************************************************
* GLOBAL VARIABLES
*/
//-----------------------------------------------------------------------------------------
//变量定义
//-----------------------------------------------------------------------------------------
union h{
uint8 RxBuf[29];
struct RFRXBUF
{
uint8 HeadCom[3]; //命令头
uint8 Laddr[8];
uint8 Saddr[2];
uint8 DataBuf[16]; //数据缓冲区
}RXDATA;
}RfRx;//无线接收缓冲区
union j{
uint8 TxBuf[29];
struct RFTXBUF
{
uint8 HeadCom[3]; //命令头
uint8 Laddr[8];
uint16 Saddr;
uint8 DataBuf[16]; //数据缓冲区
}TXDATA;
}RfTx;//无线发送缓冲区
// 这个列表列出了应用程序特殊的 Cluster IDs.
const cId_t SampleApp_ClusterList[SAMPLEAPP_MAX_CLUSTERS] =
{
SAMPLEAPP_PERIODIC_CLUSTERID,
SAMPLEAPP_FLASH_CLUSTERID
};
const SimpleDescriptionFormat_t SampleApp_SimpleDesc =
{
SAMPLEAPP_ENDPOINT, // int Endpoint;
SAMPLEAPP_PROFID, // uint16 AppProfId[2];
SAMPLEAPP_DEVICEID, // uint16 AppDeviceId[2];
SAMPLEAPP_DEVICE_VERSION, // int AppDevVer:4;
SAMPLEAPP_FLAGS, // int AppFlags:4;
SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters;
(cId_t *)SampleApp_ClusterList, // uint8 *pAppInClusterList;
SAMPLEAPP_MAX_CLUSTERS, // uint8 AppNumInClusters;
(cId_t *)SampleApp_ClusterList // uint8 *pAppInClusterList;
};
struct join
{
uint8 RfdCount; //RFD计数器
uint8 RouterCount; //路由器计数器
uint8 RfdAddr[3][10]; //存储RFD节点地址用,高两位为网络地址,低8位为物理地址
uint8 RouterAddr[3][10];//存储RFD节点地址用,高两位为网络地址,低8位为物理地址
}JoinNode;
// This is the Endpoint/Interface description. It is defined here, but
// filled-in in SampleApp_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 SampleApp_epDesc;
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*********************************************************************
* EXTERNAL FUNCTIONS
*/
/*********************************************************************
* LOCAL VARIABLES
*/
uint8 SampleApp_TaskID; // Task ID for internal task/event processing
// This variable will be received when
// SampleApp_Init() is called.
uint8 Menu_Key;
devStates_t SampleApp_NwkState;
uint8 SampleApp_TransID; // 这是个唯一的消息ID(counter)
afAddrType_t SampleApp_Periodic_DstAddr;
afAddrType_t SampleApp_Flash_DstAddr;
aps_Group_t SampleApp_Group;
NLME_LeaveCnf_t* Remove;
uint8 SampleAppPeriodicCounter = 0;
uint8 SampleAppFlashCounter = 0;
uint8 state2 = 0;
uint8 arr[20];
/*********************************************************************
* LOCAL FUNCTIONS
*/
void SampleApp_HandleKeys( uint8 shift, uint8 keys );
void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
void SampleApp_SendPeriodicMessage( void );
void SampleApp_SendFlashMessage( uint16 flashTime );
uint8 SendData(uint8 *buf, uint16 addr, uint8 Leng);
uint16 get_short_addr(void);
/*********************************************************************
* NETWORK LAYER CALLBACKS
*/
/*********************************************************************
* PUBLIC FUNCTIONS
*/
/*********************************************************************
* @fn SampleApp_Init
*
* @brief 应用初始化函数包括了硬件初始化、平台初始化、功耗初始化等
*
* @param task_id - 操作系统分配的任务ID,这个ID用来发送信息和设置时间
*
* @return none
*/
void SampleApp_Init( uint8 task_id )
{
SampleApp_TaskID = task_id;
SampleApp_NwkState = DEV_INIT;
SampleApp_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().
#if defined ( SOFT_START )
// The "Demo" target is setup to have SOFT_START and HOLD_AUTO_START
// SOFT_START is a compile option that allows the device to start
// as a coordinator if one isn't found.
// We are looking at a jumper (defined in SampleAppHw.c) to be jumpered
// together - if they are - we will start up a coordinator. Otherwise,
// the device will start as a router.
//选择Zigbee设备协调者
#ifdef ZG_Coord
zgDeviceLogicalType = ZG_DEVICETYPE_COORDINATOR;
#endif
//选择Zigbee设备为路由器
#ifdef ZG_Router
zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER;
#endif
//选择Zigbee设备为终端节点
#ifdef ZG_ENDDEVICE
zgDeviceLogicalType = ZG_DEVICETYPE_ENDDEVICE;
#endif
#endif //SOFT_START
#if defined ( HOLD_AUTO_START )
// HOLD_AUTO_START is a compile option that will surpress ZDApp
// from starting the device and wait for the application to
// start the device.
ZDOInitDevice(0);
#endif
// 设置通讯的目的地址
// 广播所有节点
SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;
SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; //目标地址设置为网络中的所有设备
// Setup for the flash command's destination address - Group 1
SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;
SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP; //当要发送数据给某个组时,这�