Z-stack Networking Process

Source: Internet
Author: User
Tags event timer

Z-stack Network: Coordinators establish networks, routers, and terminals to join the network

Temporarily only record the first time to set up the network of the process, as to open Nv_restore, the restoration of the original network is temporarily not analyzed.

One, the coordinator set up the network:

1, the ZdO layer of the zdapp_init has the following functions:

  if (Devstate! = dev_hold)     //If you do not want to start automatically, you can set the Devstate to Dev_hold before this function is called, and then set to Dev_init when you need to start
{ 0 ); Start the device, it contains the network } else {// Blink LED to indicate Hold_start 0 ); }

2, Zdoinitdevice () if the Nv_restord is defined, you can choose whether to create a new network by pressing the key, or to read the network in NV to recover, we assume that Nv_restore is not defined, create a new network directly.

  if(Networkstatenv = =zdo_initdev_new_network_state)//judgment is to create a new network {zdappdeterminedevicetype (); Determine the current device type is the Nodetype_coordinator coordinator and the device startup mode is Mode_hard//Only delay if joining Network-not restoring network StateExtendeddelay = (uint16) ((Nwk_start_delay +startdelay)+ (Osal_rand () &extended_joining_random_mask)); }  //Initialize the security for type of deviceZdapp_secinit (networkstatenv); //Trigger the network startZdapp_networkinit (Extendeddelay); Start the network initialization, here we have the coordinator to start the network//Set broadcast address mask to support broadcast filteringNlme_setbroadcastfilter (Zdo_config_node_descriptor.capabilityflags);

3, Zdapp_networkinit () function, set an event timer, when the event is reached, triggering the Zdo_network_init event

void Zdapp_networkinit (uint16 delay) {  if  (delay)  {    //  Wait Awhile Before starting    the device Osal_start_timerex (Zdapptaskid, zdo_network_init, delay);  }   Else   {    osal_set_event (zdapptaskid, zdo_network_init);  }}

4, Zdapp_event_loop the task of detecting ZdO layer, when found Zdo_network_init event, will be executed as follows:

  if (Events & Zdo_network_init)  {    //  Initialize Apps and start the network    devstate = dev_init;     
//In the previously identified node type Nodetype_coordinator (Coordinator), boot mode mode_hard boot device Zdo_startdevice (uint8) Zdo_config_node_descriptor.logicaltype, Devstartmode, Default_beacon_order, DEFAULT_ Superframe_order); // Return unprocessed Events return (Events ^ zdo_network_init); }

5. The Zdo_startdevice () function calls the following function to begin forming the network:

 if  (zg_build_coordinator_type && logicaltype == Nodetype_coordinator) { if  (startMode == Mode_hard) {devstate  = dev_coord_starting; Change the device state to the coordinator start, and start to establish the network 
//Call network formation function to start the network, the information needed to set up the main include Panid, channel ret = Nlme_networkformationrequest (Zgconfigpanid, Zgapsuseextendedpanid, Zgdefaultchannellist, Zgdefaultstartingscanduration, Beaconorder, Superframeorder, false ); }

6, Nlme_networkformationrequest () function is through the network layer like space sent to establish a network request, which through the capture software discovery, he would like to send a beacon signal space, to obtain the network situation in the space, and then set up their own network, If your network and the network in the space Panid the same, it will be on this Panid +1,
7. The Nlme_networkformationrequest () function will get a confirm after the request is made, and the Confirm function is ZDO_NETWORKFORMATIONCONFIRMCB (), If the value of status is Zsuccess, then this network successfully established, network establishment success or failure, all need to inform ZdO layer, ZdO layer good according to the situation to make appropriate processing.

/********************************************************************* * @fn ZDO_NETWORKFORMATIONCONFIRMCB * * @brief This function reports the results of the request to * initialize a coordinator in a network. * * @param status-result of Nlme_networkformationrequest () * * @return None*/voidZDO_NETWORKFORMATIONCONFIRMCB (zstatus_t Status) {nwkstatus= (byte) Status; if(Status = =zsuccess) {    //LED on shows coordinator startedHalledset (Hal_led_3, hal_led_mode_on); //LED off forgets Hold_auto_startHalledset (Hal_led_4, hal_led_mode_off);#ifDefined (zbit)Sim_setcolor (0xd0ffd0);#endif    if(Devstate = =dev_hold) {      //began with Hold_auto_startDevstate =dev_coord_starting; }  }#ifDefined (blink_leds)Else{halledset (hal_led_3, Hal_led_mode_flash); //Flash LED to show failure  }#endifosal_set_event (Zdapptaskid, Zdo_network_start); Notifies the ZdO layer to set a Zdo_network_start event}

8, Zdapp_event_loop processing the above triggered Zdo_network_start event

    if (Events & Zdo_network_start)    {      zdapp_networkstartevt ();       // Return unprocessed Events      return (Events ^ zdo_network_start);    }

9, Zdo_network_start event called the Zdapp_networkstartevt () function, if the network has been established successfully set the ZDO_STATE_CHANGE_EVT event, otherwise increase the transmit power again set Zdo_ Network_init the event and start the network again with the following functions:

voidZDAPP_NETWORKSTARTEVT (void ){  if(Nwkstatus = =zsuccess) {    //successfully started a ZigBee network    if(Devstate = =dev_coord_starting) {Devstate=Dev_zb_coord;    } osal_pwrmgr_device (pwrmgr_always_on);  Osal_set_event (Zdapptaskid, zdo_state_change_evt); }  Else  {    //Try again with a higher energy threshold !    if((Nlme_getenergythreshold () + energy_scan_increment) <0xFF) {nlme_setenergythreshold (uint8) (Nlme_getenergythreshold ()+energy_scan_increment));    Osal_set_event (Zdapptaskid, zdo_network_init); }    Else    {      //Failed to start network. Enter a dormant state (until user intervenes)Devstate =Dev_init;    Osal_set_event (Zdapptaskid, zdo_state_change_evt); }  }}

10, Zdo_state_change_evt event Call Function Zdo_updatenwkstatue () function, this function will notify the network changes to all the application layer endpoint, so that the user according to this notification to do the corresponding processing, the specific function is as follows:

voidZdo_updatenwkstatus (devstates_t state) {eplist_t*pitem =eplist;  while(Pitem! =NULL) {    if(Pitem->epdesc->endpoint! =Zdo_ep) {      //send messages to all application-level tasks and endpointsZdosendstatechangemsg (State, * (pitem->epdesc->task_id)); } pitem= pitem->Nextdesc; }#ifDefined Mt_zdo_cb_funczdosendstatechangemsg (state, mt_taskid);#endifZDAppNwkAddr.addr.shortAddr=nlme_getshortaddr (); (void) nlme_getextaddr ();//Load the saveextaddr pointer.}

11. The Coordinator successfully establishes the network and informs the application layer. The process of joining routers and terminals to the network continues in the next section.

Z-stack Networking Process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.