Elevator v1.0.0 NetworkHandler

Module for handling and setting up the Node Network, and communication between nodes

State:

  • A map with the connected nodes as keys and a backup of the node's elevator state as the respective value, as well as a boolean value indicating their ability to accept new orders. The entire state for three connected nodes will look like this: %{ "elev@10.100.23.197": [ %State{active_orders: [], direction: :stop, floor: 0}, true ], "elev@10.100.23.233": [ %State{active_orders: [], direction: :stop, floor: 1}, true ], "elev@10.100.23.253": [ %State{active_orders: [], direction: :stop, floor: 1}, true ] }

Tasks:

  • Initializes all modules for one computer, broadcasts own IP and listnes, making a Peer-to-peer network of NetworkModules
  • Decides the recipient of Hall orders based on a cost function, considering number of orders and distance to order.
  • Is responsible for restarting nodes and redistributing orders that are not executed by assigned elevator

Communication:

  • Receives from: OrderHandler, WatchDog, StateMachine, (other nodes') NetworkModule(s)
  • Sends to: OrderHandler, (other nodes') NetworkModule(s)

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor

Send assigned order to other node

Handle a request to update own map with another node

Handle a request to synchronize the lights on an external node

Handle event of node going down

Boot Node with name "elev@ip" and spawn listen and receive processes based on UDP broadcasting

Set up two-way monitoring

Get info about a node in another node's state map

Send own updated backup to all other nodes

Iterate through an order list and send all orders to own state machine

Process to be spawned for delaying cab order resend to after initialization. Example iex> pid = Process.spawn(NetworkHandler, :resend_cab_orders, [node_name, net_state], []) iex> Process.send_after(pid, :resend_cab_orders, 3000)

Synchronize order light externally

Synchronize local order list with an external order list

Synchronize internal order list with the other elevators

Link to this section Functions

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

export_order(arg)

Send assigned order to other node

Link to this function

handle_call(msg, from, state)

Handle a request to update own map with another node

Link to this function

handle_cast(msg, state)

Handle a request to synchronize the lights on an external node

Link to this function

handle_info(msg, state)

Handle event of node going down.

Boot Node with name "elev@ip" and spawn listen and receive processes based on UDP broadcasting

Link to this function

monitor_me_back(node_name)

Set up two-way monitoring

Link to this function

multi_call_request_backup(from_node_name, about_node)

Get info about a node in another node's state map

Link to this function

multi_call_update_backup(backup)

Send own updated backup to all other nodes

Link to this function

redistribute_orders(order_list)

Iterate through an order list and send all orders to own state machine

Link to this function

return_cab_orders(node_name, net_state)

Process to be spawned for delaying cab order resend to after initialization. Example iex> pid = Process.spawn(NetworkHandler, :resend_cab_orders, [node_name, net_state], []) iex> Process.send_after(pid, :resend_cab_orders, 3000)

Link to this function

start_link(list \\ [20087, 20086])

Link to this function

sync_ext_elev_lights(order, light_state)

Synchronize order light externally

Link to this function

sync_ext_order_list(ext_order_list)

Synchronize local order list with an external order list

Link to this function

sync_int_order_list(order_list)

Synchronize internal order list with the other elevators