mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-26 14:31:59 +01:00
Added wireless connection controller
Base framework for wireless connection controller to replace radio controller for device communication
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/datum/wifi
|
||||
var/list/connected_devices
|
||||
|
||||
/datum/wifi/New()
|
||||
connected_devices = new()
|
||||
|
||||
/datum/wifi/Destroy(var/wifi/device)
|
||||
..()
|
||||
for(var/datum/wifi/D in connected_devices)
|
||||
D.disconnect_device(src)
|
||||
|
||||
/datum/wifi/proc/connect_device(var/datum/wifi/device)
|
||||
connected_devices |= device
|
||||
|
||||
/datum/wifi/proc/disconnect_device(var/datum/wifi/device)
|
||||
connected_devices -= device
|
||||
|
||||
|
||||
|
||||
/datum/wifi/receiver
|
||||
var/id
|
||||
|
||||
/datum/wifi/receiver/New(var/new_id)
|
||||
..()
|
||||
id = new_id
|
||||
wifi_manager.add_device(src)
|
||||
|
||||
/datum/wifi/receiver/Destroy()
|
||||
..()
|
||||
wifi_manager.remove_device(src)
|
||||
|
||||
|
||||
|
||||
/datum/wifi/sender
|
||||
var/target
|
||||
|
||||
/datum/wifi/sender/New(var/new_target)
|
||||
..()
|
||||
target = new_target
|
||||
|
||||
/datum/wifi/sender/proc/set_target(var/new_target)
|
||||
target = new_target
|
||||
|
||||
/datum/wifi/sender/proc/send_connection_request()
|
||||
var/datum/connection_request/C = new(src, target)
|
||||
wifi_manager.add_request(C)
|
||||
|
||||
|
||||
|
||||
/datum/connection_request
|
||||
var/datum/wifi/sender/source //wifi_sender object creating the request
|
||||
var/target //id tag of the target device to try to connect to
|
||||
|
||||
/datum/connection_request/New(var/datum/wifi/sender/sender, var/receiver)
|
||||
source = sender
|
||||
target = receiver
|
||||
@@ -0,0 +1,47 @@
|
||||
/datum/wifi_manager
|
||||
var/list/pending_connections
|
||||
var/list/receiver_list
|
||||
var/list/failed_connections
|
||||
|
||||
/datum/wifi_manager/New()
|
||||
pending_connections = new()
|
||||
receiver_list = new()
|
||||
failed_connections = new()
|
||||
|
||||
/datum/wifi_manager/proc/add_device(var/datum/wifi/receiver/R)
|
||||
receiver_list |= R
|
||||
|
||||
/datum/wifi_manager/proc/remove_device(var/datum/wifi/receiver/R)
|
||||
receiver_list -= R
|
||||
|
||||
/datum/wifi_manager/proc/add_request(var/datum/connection_request/C)
|
||||
pending_connections += C
|
||||
|
||||
/datum/wifi_manager/proc/process()
|
||||
//check any failed connections from the previous pass
|
||||
if(failed_connections.len > 0)
|
||||
for(var/datum/connection_request/C in failed_connections)
|
||||
var/target_found = 0
|
||||
for(var/datum/wifi/receiver/R in receiver_list)
|
||||
if(R.id == C.target)
|
||||
var/datum/wifi/sender/S = C.source
|
||||
S.connect_device(R)
|
||||
R.connect_device(S)
|
||||
target_found = 1
|
||||
failed_connections -= C
|
||||
if(!target_found)
|
||||
log_debug("[C.source] could not connect to \"[C.target]\"")
|
||||
|
||||
//check and try assigning any pending connections
|
||||
if(pending_connections.len > 0)
|
||||
for(var/datum/connection_request/C in pending_connections)
|
||||
var/target_found = 0
|
||||
for(var/datum/wifi/receiver/R in receiver_list)
|
||||
if(R.id == C.target)
|
||||
var/datum/wifi/sender/S = C.source
|
||||
S.connect_device(R)
|
||||
R.connect_device(S)
|
||||
target_found = 1
|
||||
pending_connections -= C
|
||||
if(!target_found)
|
||||
failed_connections += C
|
||||
Reference in New Issue
Block a user