Research Article
AH-MAC: Adaptive Hierarchical MAC Protocol for Low-Rate Wireless Sensor Network Applications
Algorithm 1
Cluster head join algorithm.
() procedure start_scan() | () best_parent_addr = 0XFFFF; min_dfs = 255; scan_timer = ON | () wake_after(0) ⊳ wakeup now | () start_scan_timer(0, SCAN_LENGTH) ⊳ scan_timer starts now and will fire after SCAN_LENGTH | () end procedure | () procedure recv_beacon(src, dfs, accept) | () if scan_timer then | () if (dfs < min_dfs & accept) then ⊳ replace current parent | () min_dfs = dfs | () best_parent_addr = src | () end if | () if (my_parent_addr == best_parent_addr) then ⊳ restore synchronization with last parent | () stop_scan_timer() | () scan_timer = OFF | () end if | () end if | () if scan_timer then | () return | () end if | () if (not associated) then | () sleep_after(slot_time) | () wake_after() | () send_associate_request_packet() | () else if (data available) then | () sleep_after(slot_time) | () wake_after(my_slot slot_time) ⊳ wake up in my slot to start my frame | () try_send_data() | (28) else | () sleep_after(0) | () wake_after(my_slot slot_time) | () end if | () end procedure | () procedure scan_handler() ⊳ called when scan timer is fired | () if (best_parent_addr < 0XFFFF) then | () my_parent_addr = best_parent_addr | () my_dfs = min_dfs + 1 | () scan_timer = OFF | () else | () sleep_after(0) | () start_scan_timer(random delay, SCAN_LENGTH) | () end if | () return | () end procedure |
|