资源描述:
《zstack网络的建立》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.voidZDApp_Init(bytetask_id){uint8capabilities;//SavethetaskIDZDAppTaskID=task_id;//设置任务id//InitializetheZDOglobaldeviceshortaddressstorageZDAppNwkAddr.addrMode=Addr16Bit;ZDAppNwkAddr.addr.shortAddr=INVALID_NODE_ADDR;(void)NLME_GetExtAddr();//LoadthesaveExtAddrpoi
2、nter.//函数的作用是返回指向64bitIEEE地址的指针,但这里有点奇怪,它好像没有接收这个指针//Checkformanual"HoldAutoStart"ZDAppCheckForHoldKey();//该函数的作用是如果HAL_KEY_SW_1键被按下,则notstartedautomatically,如果不是自启动,则在自己的应用程序中要添加函数ZDOInitDevice(0)来启动建网过程,见Sample例子的应用程序//InitializeZDOitemsandsetupthedevice-typeofde
3、vicetocreate.ZDO_Init();//RegistertheendpointdescriptionwiththeAF//Thistaskdoesn'thaveaSimpledescription,butwestillneed//toregistertheendpoint.afRegister((endPointDesc_t*)&ZDApp_epDesc);//注册端点#ifdefined(ZDO_USERDESC_RESPONSE)ZDApp_InitUserDesc();#endif//ZDO_USERDES
4、C_RESPONSE//setbroadcastaddressmasktosupportbroadcastfilteringNLME_GetRequest(nwkCapabilityInfo,0,&capabilities);//ThisfunctionallowsthenexthigherlayertogetthevalueofaNIB(networkinformationbase)attributeNLME_SetBroadcastFilter(capabilities);//Thisfunctionsetsabitma
5、skbasedonthecapabilitiesofthedevice.Itwillbeusedtoprocessvalidbroadcastaddresses//Startthedevice?if(devState!=DEV_HOLD){ZDOInitDevice(0);}else{//BlinkLEDtoindicateHOLD_STARTHalLedBlink(HAL_LED_4,0,50,500);}ZDApp_RegisterCBs();}/*ZDO_Init()*/2.voidZDApp_RegisterCBs(
6、void){#ifdefined(ZDO_IEEEADDR_REQUEST)
7、
8、defined(REFLECTOR)ZDO_RegisterForZDOMsg(ZDAppTaskID,IEEE_addr_rsp);#endif#ifdefined(ZDO_NWKADDR_REQUEST)
9、
10、defined(REFLECTOR)ZDO_RegisterForZDOMsg(ZDAppTaskID,NWK_addr_rsp);#endif#ifdefined(ZDO_COORDINATOR)ZDO_RegisterForZDOMs
11、g(ZDAppTaskID,Bind_rsp);ZDO_RegisterForZDOMsg(ZDAppTaskID,Unbind_rsp);ZDO_RegisterForZDOMsg(ZDAppTaskID,End_Device_Bind_req);#endif#ifdefined(REFLECTOR)ZDO_RegisterForZDOMsg(ZDAppTaskID,Bind_req);ZDO_RegisterForZDOMsg(ZDAppTaskID,Unbind_req);#endif}3.ZStatus_tZDO_R
12、egisterForZDOMsg(uint8taskID,uint16clusterID){ZDO_MsgCB_t*pList;ZDO_MsgCB_t*pLast;ZDO_MsgCB_t*pNew;//LookforduplicatepList=zdoMsgCBs;while(pList)