协调器程序.docx

上传人:大张伟 文档编号:10734156 上传时间:2021-06-01 格式:DOCX 页数:15 大小:21.74KB
返回 下载 相关 举报
协调器程序.docx_第1页
第1页 / 共15页
协调器程序.docx_第2页
第2页 / 共15页
协调器程序.docx_第3页
第3页 / 共15页
协调器程序.docx_第4页
第4页 / 共15页
协调器程序.docx_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《协调器程序.docx》由会员分享,可在线阅读,更多相关《协调器程序.docx(15页珍藏版)》请在三一文库上搜索。

1、Filename:GenericApp.cRevised:SDate: 2012-03-07 01:04:58 -0800(Wed. 07 Mar 2012) $Revision:SRevision: 29656 $Description:Generic Application (no Profile).Copyright 2004-2012 Texas Instruments Incorporated. All rights reserved.IMPORTANT: Your use of this Software is limited to those specific rights gr

2、anted under the terms of a software license agreement between the user who downloaded the software, his/lier employer (which must be your employer) and Texas Instruments Incorporated (the License”), You may not use this Software unless you agree to abide by the terms of the License. The License limi

3、ts your use. and you acknowledge, that the Software may not be modified, copied or distributed unless embedded on a Texas Instruments microcontroller or used solely and exclusively in conjunction with a Texas Instniments radio frequency transceiver, which is integrated into your product. Other than

4、for the foregoing purpose, you may not use, reproduce, copy, prepare derivative works of, modify, distribute, perform, display or sell this Software and/or its documentation for any purpose.YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION AREPROVIDED 摘 S IS7WITHOUT WARRANTY OF A

5、NY KIND, EITHER EXPRESS OR IMPLIED,INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY TITLE.NON-INFRINGEMENT AND HTNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALLTEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,NEGLIGENCE, STRICT LIABILITY. CONTRIBUTION, BREACH OF

6、 WARRANTY. OR OTHERLEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL. SPECIAL. INDIRECT.PUNITIVEOR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA. COST OF PROCUREMENTOF SUBSTITUTE GOODS, TECHNOLOGY SERVICES, OR ANY CLAIMS BY THIRD PARTIES

7、(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.Should you have any questions regarding your right to use this Software, contact Texas Instruments Incoiporated at www.TI.com.*/*This application isnt intended to do anything useful, it is intended to be a simple example of a

8、n applications structure.This application sends Hello World11 to another nGenericH application every 5 seconds. The application will also receives uHello World” packets.The “Hello World0 messages are sent/received as MSG type message.This applications doesnt have a profile, so it handles everything

9、directly - itself.Key control:SW1:SW2: initiates end device bindingSW3:SW4: initiates a match description request*/* INCLUDES*/include uOSAL.hMinclude ”AF.h”#includc ZDApp.h”include MZDObject.hH#includc ZDProfile.h include HGenericApp.hH#includc HDebugTrace.hH#if !defined( WIN32)include NOnBoard.hN#

10、endif/* HAL */#include ,halJcd.hH#includc vhal led.hM#includc Hhal_key.hH#include hal_uarth”/* rtoS */#if defined( IAR_ARMCM3.LM )#include RTOS_App.h#endif/* MACROS*/* CONSTANTS*/* TYPEDEFS*/* GLOBAL VARIABLES*/ Tliis list should be filled with Application specific Cluster IDs.const cld_t GenericApp

11、_ClusterListGENERICAPP_MAX_CLUSTERS=GENERICAPP.CLUSTERID); const SimpleDescriptionFormatJ GenericApp_SimpleDesc =/GENERICAPP_ENDPOINT.GENERICAPP_PROFID, GENERICAPP_DEVICEID.GENERICAPP.DEVICE.VERSION, GENERICAPP_FLAGS, GENERICAPP_MAX_CLUSTERS, (cld_t *)GenericApp_ClusterList, / GENERICAPP_MAX_CLUSTER

12、S. (cld_t *)GenericApp_ClusterList / );int Endpoint:uint 16 AppProfld2;uint16 AppDeviceId2;/ int AppDevVer:4;/ int AppFlags:4:/ byte AppNumlnClusters;byte *pAppInClusterList;/ byte AppNumlnClusters; byte *pAppInClusterList;/ Tliis is the Endpoint/Interface description. It is defined here, but/ fille

13、d-in in GenericApp_Init(). Another way to go would be to fill/ in the stnicture here and make it a const”(in code space). The / way its defined in this sample app it is define in RAM. endPointDescJ GenericApp_epDesc;/* EXTERNAL VARIABLES*/* EXTERNAL FUNCTIONS*/* LOCAL VARIABLES*/byte GenericApp_Task

14、ID: /Task ID for internal task/event processing / This variable will be received when / GenericApp_Init() is called.devStatesj GenericApp_NwkState;byte GenericApp_TransID: / This is the unique message ID (counter)afAddrTypeJ GenericApp_DstAddr:static void delayms(unsigned int x);void delayms(unsigne

15、d int x)(unsigned char i;while(x-)for(i=0;ihdr.event)case ZDO_CB_MSG:GenericApp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt); break;case KEY.CHANGE:GenericApp_HandleKeys( (keyChangeJ *)MSGpkt)-state, (keyChangeJ *)MSGpkt)-keys);break;case AF_DATA_CONFIRM_CMD:/ This message is received as a confirmati

16、on of a data packet sent.The status is of ZStatusJ type defined in ZComDef.h/The message fields are defined in AEhafDataConfinn = (afDataConfirmj *)MSGpkt;sentEP = afDataConfirm-endpoint;sentStatus = afDataConfirm-hdr.status;sentTransID = alDataConfirm-XransID:(void)sentEP;(void)sentTransID;/Action

17、taken when confirmation is received.if ( sentStatus != ZSuccess )(/ The data wasnt delivered - Do something)break:case AFJNCOMING_MSG_CMD: GenericApp_MessageMSGCB( MSGpkt); break:case ZDO_STATE_CHANGE:GenericApp_NwkState = (devStatesJ)(MSGpkt-hdr.status);if (GenericApp.NwkState = DEV_ZB_COORD)II (Ge

18、nericApp.NwkState = DEV_ROUTER)II (GenericApp_NwkState = DEV_END_DEVICE) (/ Start sending the11 message in a regular interval. osaLstart_timerEx( GenericApp_TaskID,GENERICAPP_SEND_MSG_EVT, GENERICAPP_SEND_MSG_TIMEOUT);)break:default:break;)/ Release the memory osal_msg_deallocate( (uint8 *)MSGpkt);/

19、 NextMSGpkt = (aflncomingMSGPacketJ *)osal_msg_receive( GencricApp_TaskID ); )/ return unprocessed eventsreturn (events A SYS_EVENT_MSG);/ Send a message out - This event is generated by a timer/ (setup in GenericAppnit().if( events & GENERICAPP_SEND_MSG_EVT )/ Send Mtheu messageGeneric App_SendTheM

20、essage();/ Setup to send message againosal_start_timerEx( GenericApp_TaskID.GENERICAPP_SEND_MSG_EVT.GENERICAPP_SEND_MSG_TIMEOUT);/ return unprocessed eventsreturn (events A GENERICAPP_SEND_MSG_EVT);#if defined( IAR_ARMCM3.LM )/ Receive a message from the RTOS queueif( events & GENERICAPP_RTOS_MSG_EV

21、T )/ Process message from RTOS queue GenericApp_ProcessRtosMessage();/ return unprocessed eventsreturn (events A GENERICAPP_RTOS_MSG_EVT);#cndif/ Discard unknown events return 0;)/* Event Generation Functions*/* fn GenericApp_ProcessZDOMsgs() * brief Process response messages * param none* return no

22、ne*/static void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )(switch (inMsg-c!usterID )(case End_Device_B i nd_rsp:if (ZDO_ParseBindRsp( inMsg ) = ZSuccess )(/ Light LEDHalLedSet( HAL_LED_4. HAL_LED_MODE_ON );)#if defincd( BLINK_LEDS )else(/ Flash LED to show failureHalLedSet ( HAL_LED_4, HAL

23、_LED_MODE_FLASH );)#endifbreak;case Match_Dcsc_rsp:(ZDO_ActiveEndpointRspJ *pRsp = ZDO_ParseEPListRsp( inMsg );if (pRsp) (if ( pRsp-status = ZSuccess & pRsp-cnt)(GencricApp_DstAddr.addrMode = (afAddrMode_t)AddrI6Bit;GencricApp_DstAddr.addr.shortAddr = pRsp-nwkAddr;/ Take the first endpoint, Can be c

24、hanged to search through endpoints GencricApp_DstAddr.endPoint = pRsp-epListO;/ Light LEDHalLedSet( HAL_LED_4, HAL_LED_MODE_ON);)osal_mem_free( pRsp);) break;)static void rxCB(uint8 port.uint8 event)uint8 uartbuf5;HalUARTRead(0,uartbuf,5);从串口读取五个字节的数据到uartbuf中AF_DataRcquest( &GcnericApp_DstAddr. & G

25、eneric App_epDesc, GENERICAPP.CLUSTERID.5发送五个字节的数据uartbuf”发送的数据内容,其实就是从串口收到的2个字节的数 据&GcncricApp_TransID.AF_DISCV_ROUTE. AF_DEFAULT_RADIUS );/ for(i = 0;icmd.Data, pkt-cmd.DataLength); 输出接收到的数据HalUARTWrite(O,1);HalUARTWrite(O,1);/ 回车换行) break;/ *theH message/#if defined( LCD.SUPPORTED)/ HalLcdWriteScreen( (char*)pkt-cmd.Data, HrcvdH);/#elif defined( WIN32 )/WPRINTSTR( pkt-cmd.Data);/#endif/break:)/*

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1