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
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
export_order(arg)
Send assigned order to other node
handle_call(msg, from, state)
Handle a request to update own map with another node
handle_cast(msg, state)
Handle a request to synchronize the lights on an external node
handle_info(msg, state)
Handle event of node going down.
init(list)
Boot Node with name "elev@ip" and spawn listen and receive processes based on UDP broadcasting
monitor_me_back(node_name)
Set up two-way monitoring
multi_call_request_backup(from_node_name, about_node)
Get info about a node in another node's state map
multi_call_update_backup(backup)
Send own updated backup to all other nodes
redistribute_orders(order_list)
Iterate through an order list and send all orders to own state machine
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)
start_link(list \\ [20087, 20086])
sync_ext_elev_lights(order, light_state)
Synchronize order light externally
sync_ext_order_list(ext_order_list)
Synchronize local order list with an external order list
sync_int_order_list(order_list)
Synchronize internal order list with the other elevators