协调.docx
- 文档编号:15849283
- 上传时间:2023-07-08
- 格式:DOCX
- 页数:27
- 大小:23.24KB
协调.docx
《协调.docx》由会员分享,可在线阅读,更多相关《协调.docx(27页珍藏版)》请在冰点文库上搜索。
协调
/**************************************************************************************************
Filename:
SampleApp.c
Revised:
$Date:
2009-03-1815:
56:
27-0700(Wed,18Mar2009)$
Revision:
$Revision:
19453$
Description:
SampleApplication(noProfile).
Copyright2007TexasInstrumentsIncorporated.Allrightsreserved.
IMPORTANT:
YouruseofthisSoftwareislimitedtothosespecificrights
grantedunderthetermsofasoftwarelicenseagreementbetweentheuser
whodownloadedthesoftware,his/heremployer(whichmustbeyouremployer)
andTexasInstrumentsIncorporated(the"License").Youmaynotusethis
SoftwareunlessyouagreetoabidebythetermsoftheLicense.TheLicense
limitsyouruse,andyouacknowledge,thattheSoftwaremaynotbemodified,
copiedordistributedunlessembeddedonaTexasInstrumentsmicrocontroller
orusedsolelyandexclusivelyinconjunctionwithaTexasInstrumentsradio
frequencytransceiver,whichisintegratedintoyourproduct.Otherthanfor
theforegoingpurpose,youmaynotuse,reproduce,copy,preparederivative
worksof,modify,distribute,perform,displayorsellthisSoftwareand/or
itsdocumentationforanypurpose.
YOUFURTHERACKNOWLEDGEANDAGREETHATTHESOFTWAREANDDOCUMENTATIONARE
PROVIDED揂SIS?
WITHOUTWARRANTYOFANYKIND,EITHEREXPRESSORIMPLIED,
INCLUDINGWITHOUTLIMITATION,ANYWARRANTYOFMERCHANTABILITY,TITLE,
NON-INFRINGEMENTANDFITNESSFORAPARTICULARPURPOSE.INNOEVENTSHALL
TEXASINSTRUMENTSORITSLICENSORSBELIABLEOROBLIGATEDUNDERCONTRACT,
NEGLIGENCE,STRICTLIABILITY,CONTRIBUTION,BREACHOFWARRANTY,OROTHER
LEGALEQUITABLETHEORYANYDIRECTORINDIRECTDAMAGESOREXPENSES
INCLUDINGBUTNOTLIMITEDTOANYINCIDENTAL,SPECIAL,INDIRECT,PUNITIVE
ORCONSEQUENTIALDAMAGES,LOSTPROFITSORLOSTDATA,COSTOFPROCUREMENT
OFSUBSTITUTEGOODS,TECHNOLOGY,SERVICES,ORANYCLAIMSBYTHIRDPARTIES
(INCLUDINGBUTNOTLIMITEDTOANYDEFENSETHEREOF),OROTHERSIMILARCOSTS.
ShouldyouhaveanyquestionsregardingyourrighttousethisSoftware,
contactTexasInstrumentsIncorporatedatwww.TI.com.
**************************************************************************************************/
/*********************************************************************
Thisapplicationisn'tintendedtodoanythinguseful,itis
intendedtobeasimpleexampleofanapplication'sstructure.
Thisapplicationsendsit'smessageseitherasbroadcastor
broadcastfilteredgroupmessages.Theother(morenormal)
messageaddressingisunicast.Mostoftheothersample
applicationsarewrittentosupporttheunicastmessagemodel.
Keycontrol:
SW1:
SendsaflashcommandtoalldevicesinGroup1.
SW2:
Adds/Removes(toggles)thisdeviceinandout
ofGroup1.Thiswillenableanddisablethe
receptionoftheflashcommand.
*********************************************************************/
/*********************************************************************
*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"
/*HAL*/
#include"hal_timer.h"
#include"hal_lcd.h"
#include"hal_led.h"
#include"hal_key.h"
#include"MT_UART.h"
#include"MT_APP.h"
#include"MT.h"
#include
#defineHAL_IO_SET(port,pin,val)HAL_IO_SET_PREP(port,pin,val)//输出
#defineHAL_IO_SET_PREP(port,pin,val)st(P##port##_##pin##=val;)
#defineHAL_IO_GET(port,pin)HAL_IO_GET_PREP(port,pin)//输入
#defineHAL_IO_GET_PREP(port,pin)(P##port##_##pin)
#defineSGP1_4//声感为p14口控制
#defineuintunsignedint
#defineucharunsignedchar
intDataDeal(void);//协调器串口接收上位机数据处理
voidReceOrderDeal(void);//处理无线数据
voidRFSend(uint8Data[7],uint8Long);//无线发射数据
voidEndInfoSend(void);//串口发送中断数据
voidSGRead(void);
voidInitT1();
ucharSgScan(void);
voidDelayms(uintxms);
uint8SendOut=0;//发送给终端标志
/**********发送命令数据帧********/
uint8OutOrder[7]={0x00,//帧头00XAA
0x00,//设备ID1字节1
0x00,//设备命令2
0x00,0x00,//设备数据34
0x00,//校验和5
0x00};//帧尾60XDD
/**********接收命令数据帧********/
uint8ReceOrder[7]={0x00,//帧头00XAA
0x00,//设备ID1字节1
0x00,//设备命令2
0x00,0x00,//设备数据34
0x00,//校验和5
0x00};//帧尾60XDD
/*********************************************************************
*GLOBALVARIABLES
*/
//ThislistshouldbefilledwithApplicationspecificClusterIDs.
constcId_tSampleApp_ClusterList[SAMPLEAPP_MAX_CLUSTERS]=
{
SAMPLEAPP_PERIODIC_CLUSTERID,
SAMPLEAPP_FLASH_CLUSTERID
};
constSimpleDescriptionFormat_tSampleApp_SimpleDesc=
{
SAMPLEAPP_ENDPOINT,//intEndpoint;
SAMPLEAPP_PROFID,//uint16AppProfId[2];
SAMPLEAPP_DEVICEID,//uint16AppDeviceId[2];
SAMPLEAPP_DEVICE_VERSION,//intAppDevVer:
4;
SAMPLEAPP_FLAGS,//intAppFlags:
4;
SAMPLEAPP_MAX_CLUSTERS,//uint8AppNumInClusters;
(cId_t*)SampleApp_ClusterList,//uint8*pAppInClusterList;
SAMPLEAPP_MAX_CLUSTERS,//uint8AppNumInClusters;
(cId_t*)SampleApp_ClusterList//uint8*pAppInClusterList;
};
//ThisistheEndpoint/Interfacedescription.Itisdefinedhere,but
//filled-ininSampleApp_Init().Anotherwaytogowouldbetofill
//inthestructurehereandmakeita"const"(incodespace).The
//wayit'sdefinedinthissampleappitisdefineinRAM.
endPointDesc_tSampleApp_epDesc;
/*********************************************************************
*EXTERNALVARIABLES
*/
/*********************************************************************
*EXTERNALFUNCTIONS
*/
/*********************************************************************
*LOCALVARIABLES
*/
uint8SampleApp_TaskID;//TaskIDforinternaltask/eventprocessing
//Thisvariablewillbereceivedwhen
//SampleApp_Init()iscalled.
devStates_tSampleApp_NwkState;
uint8SampleApp_TransID;//ThisistheuniquemessageID(counter)
afAddrType_tSampleApp_Periodic_DstAddr;
afAddrType_tSampleApp_Flash_DstAddr;
aps_Group_tSampleApp_Group;
uint8SampleAppPeriodicCounter=0;
uint8SampleAppFlashCounter=0;
/*********************************************************************
*LOCALFUNCTIONS
*/
voidSampleApp_HandleKeys(uint8shift,uint8keys);
voidSampleApp_MessageMSGCB(afIncomingMSGPacket_t*pckt);
voidSampleApp_SendPeriodicMessage(void);
voidSampleApp_SendFlashMessage(uint16flashTime);
voidSampleApp_SerialCMD(mtOSALSerialData_t*cmdMsg);
/*********************************************************************
*NETWORKLAYERCALLBACKS
*/
/*********************************************************************
*PUBLICFUNCTIONS
*/
/*********************************************************************
*@fnSampleApp_Init
*
*@briefInitializationfunctionfortheGenericAppTask.
*Thisiscalledduringinitializationandshouldcontain
*anyapplicationspecificinitialization(ie.hardware
*initialization/setup,tableinitialization,powerup
*notificaiton...).
*
*@paramtask_id-theIDassignedbyOSAL.ThisIDshouldbe
*usedtosendmessagesandsettimers.
*
*@returnnone
*/
voidSampleApp_Init(uint8task_id)
{
SampleApp_TaskID=task_id;
SampleApp_NwkState=DEV_INIT;
SampleApp_TransID=0;
/*初始化*******************************************************************/
/*初始化*******************************************************************/
/*初始化*******************************************************************/
//SetTime3();
MT_UartInit();//初始化
MT_UartRegisterTaskID(task_id);//登记任务号
HalUARTWrite(0,"HelloWorld\n",12);
//DS1302_init();//ds1302初始化
//调用初始化函数
//Devicehardwareinitializationcanbeaddedhereorinmain()(Zmain.c).
//Ifthehardwareisapplicationspecific-addithere.
//Ifthehardwareisotherpartsofthedeviceadditinmain().
#ifdefined(BUILD_ALL_DEVICES)
//The"Demo"targetissetuptohaveBUILD_ALL_DEVICESandHOLD_AUTO_START
//Wearelookingatajumper(definedinSampleAppHw.c)tobejumpered
//together-iftheyare-wewillstartupacoordinator.Otherwise,
//thedevicewillstartasarouter.
if(readCoordinatorJumper())
zgDeviceLogicalType=ZG_DEVICETYPE_COORDINATOR;
else
zgDeviceLogicalType=ZG_DEVICETYPE_ROUTER;
#endif//BUILD_ALL_DEVICES
#ifdefined(HOLD_AUTO_START)
//HOLD_AUTO_STARTisacompileoptionthatwillsurpressZDApp
//fromstartingthedeviceandwaitfortheapplicationto
//startthedevice.
ZDOInitDevice(0);
#endif
//Setupfortheperiodicmessage'sdestinationaddress
//Broadcasttoeveryone
SampleApp_Periodic_DstAddr.addrMode=(afAddrMode_t)AddrBroadcast;//广播
SampleApp_Periodic_DstAddr.endPoint=SAMPLEAPP_ENDPOINT;
SampleApp_Periodic_DstAddr.addr.shortAddr=0xFFFF;
//Setupfortheflashcommand'sdestinationaddress-Group1
SampleApp_Flash_DstAddr.addrMode=(afAddrMode_t)afAddrGroup;
SampleApp_Flash_DstAddr.endPoint=SAMPLEAPP_ENDPOINT;
SampleApp_Flash_DstAddr.addr.shortAddr=SAMPLEAPP_FLASH_GROUP;
//Fillouttheendpointdescription.
SampleApp_epDesc.endPoint=SAMPLEAPP_ENDPOINT;
SampleApp_epDesc.task_id=&SampleApp_TaskID;
SampleApp_epDesc.simpleDesc
=(SimpleDescriptionFormat_t*)&SampleApp_SimpleDesc;
SampleApp_epDesc.latencyReq=noLatencyReqs;
//RegistertheendpointdescriptionwiththeAF
afRegister(&SampleApp_epDesc);
//Registerforallkeyevents-Thisappwillhandleallkeyevents
RegisterForKeys(SampleApp_TaskID);
//Bydefault,alldevicesstartoutinGroup1
SampleApp_Group.ID=0x0001;
osal_memcpy(SampleApp_Group.name,"Group1",7);
aps_AddGroup(SAMPLEAPP_ENDPOINT,&SampleApp_Group);
#ifdefined(LCD_SUPPORTED)
HalLcdWriteString("SampleApp",HAL_LCD_LINE_
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 协调