mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#12 specifically get wireless modems
This commit is contained in:
parent
03f9284f30
commit
b085baf91b
@ -25,8 +25,8 @@ println(">> Reactor PLC " .. R_PLC_VERSION .. " <<")
|
||||
-- mount connected devices
|
||||
ppm.mount_all()
|
||||
|
||||
local reactor = ppm.get_device("fissionReactor")
|
||||
local modem = ppm.get_device("modem")
|
||||
local reactor = ppm.get_fission_reactor()
|
||||
local modem = ppm.get_wireless_modem()
|
||||
|
||||
local networked = config.NETWORKED
|
||||
|
||||
@ -48,8 +48,8 @@ if reactor == nil then
|
||||
plc_state.no_reactor = true
|
||||
end
|
||||
if networked and modem == nil then
|
||||
println("boot> modem not found")
|
||||
log._warning("no modem on startup")
|
||||
println("boot> wireless modem not found")
|
||||
log._warning("no wireless modem on startup")
|
||||
|
||||
if reactor ~= nil then
|
||||
reactor.scram()
|
||||
@ -133,21 +133,28 @@ while true do
|
||||
plc_state.degraded = true
|
||||
-- send an alarm: plc_comms.send_alarm(ALARMS.PLC_PERI_DC) ?
|
||||
elseif networked and device.type == "modem" then
|
||||
println_ts("modem disconnected!")
|
||||
log._error("modem disconnected!")
|
||||
plc_state.no_modem = true
|
||||
-- we only care if this is our wireless modem
|
||||
if device.dev == modem then
|
||||
println_ts("wireless modem disconnected!")
|
||||
log._error("comms modem disconnected!")
|
||||
plc_state.no_modem = true
|
||||
|
||||
if plc_state.init_ok then
|
||||
-- try to scram reactor if it is still connected
|
||||
plc_state.scram = true
|
||||
if reactor.scram() then
|
||||
println_ts("successful reactor SCRAM")
|
||||
else
|
||||
println_ts("failed reactor SCRAM")
|
||||
if plc_state.init_ok then
|
||||
-- try to scram reactor if it is still connected
|
||||
plc_state.scram = true
|
||||
if reactor.scram() then
|
||||
println_ts("successful reactor SCRAM")
|
||||
log._error("successful reactor SCRAM")
|
||||
else
|
||||
println_ts("failed reactor SCRAM")
|
||||
log._error("failed reactor SCRAM")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
plc_state.degraded = true
|
||||
plc_state.degraded = true
|
||||
else
|
||||
log._warning("non-comms modem disconnected")
|
||||
end
|
||||
end
|
||||
elseif event == "peripheral" then
|
||||
local type, device = ppm.mount(param1)
|
||||
@ -175,20 +182,24 @@ while true do
|
||||
plc_state.degraded = false
|
||||
end
|
||||
elseif networked and type == "modem" then
|
||||
-- reconnected modem
|
||||
modem = device
|
||||
if device.isWireless() then
|
||||
-- reconnected modem
|
||||
modem = device
|
||||
|
||||
if plc_state.init_ok then
|
||||
plc_comms.reconnect_modem(modem)
|
||||
end
|
||||
if plc_state.init_ok then
|
||||
plc_comms.reconnect_modem(modem)
|
||||
end
|
||||
|
||||
println_ts("modem reconnected.")
|
||||
log._info("modem reconnected.")
|
||||
plc_state.no_modem = false
|
||||
println_ts("wireless modem reconnected.")
|
||||
log._info("comms modem reconnected.")
|
||||
plc_state.no_modem = false
|
||||
|
||||
-- determine if we are still in a degraded state
|
||||
if ppm.get_device("fissionReactor") ~= nil then
|
||||
plc_state.degraded = false
|
||||
-- determine if we are still in a degraded state
|
||||
if ppm.get_device("fissionReactor") ~= nil then
|
||||
plc_state.degraded = false
|
||||
end
|
||||
else
|
||||
log._info("wired modem reconnected.")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -30,9 +30,10 @@ local linked = false
|
||||
ppm.mount_all()
|
||||
|
||||
-- get modem
|
||||
local modem = ppm.get_device("modem")
|
||||
local modem = ppm.get_wireless_modem()
|
||||
if modem == nil then
|
||||
print("No modem found, exiting...")
|
||||
println("boot> wireless modem not found")
|
||||
log._warning("no wireless modem on startup")
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -4,6 +4,10 @@
|
||||
-- Protected Peripheral Manager
|
||||
--
|
||||
|
||||
----------------------------
|
||||
-- PRIVATE DATA/FUNCTIONS --
|
||||
----------------------------
|
||||
|
||||
local self = {
|
||||
mounts = {},
|
||||
mute = false
|
||||
@ -34,6 +38,12 @@ local peri_init = function (device)
|
||||
end
|
||||
end
|
||||
|
||||
----------------------
|
||||
-- PUBLIC FUNCTIONS --
|
||||
----------------------
|
||||
|
||||
-- REPORTING --
|
||||
|
||||
-- silence error prints
|
||||
function disable_reporting()
|
||||
self.mute = true
|
||||
@ -44,6 +54,8 @@ function enable_reporting()
|
||||
self.mute = false
|
||||
end
|
||||
|
||||
-- MOUNTING --
|
||||
|
||||
-- mount all available peripherals (clears mounts first)
|
||||
function mount_all()
|
||||
local ifaces = peripheral.getNames()
|
||||
@ -103,6 +115,8 @@ function handle_unmount(iface)
|
||||
return lost_dev
|
||||
end
|
||||
|
||||
-- GENERAL ACCESSORS --
|
||||
|
||||
-- list all available peripherals
|
||||
function list_avail()
|
||||
return peripheral.getNames()
|
||||
@ -123,7 +137,20 @@ function get_type(iface)
|
||||
return self.mounts[iface].type
|
||||
end
|
||||
|
||||
-- get a mounted peripheral by type
|
||||
-- get all mounted peripherals by type
|
||||
function get_all_devices(name)
|
||||
local devices = {}
|
||||
|
||||
for side, data in pairs(self.mounts) do
|
||||
if data.type == name then
|
||||
table.insert(devices, data.dev)
|
||||
end
|
||||
end
|
||||
|
||||
return devices
|
||||
end
|
||||
|
||||
-- get a mounted peripheral by type (if multiple, returns the first)
|
||||
function get_device(name)
|
||||
local device = nil
|
||||
|
||||
@ -137,15 +164,28 @@ function get_device(name)
|
||||
return device
|
||||
end
|
||||
|
||||
-- list all connected monitors
|
||||
function list_monitors()
|
||||
local monitors = {}
|
||||
-- SPECIFIC DEVICE ACCESSORS --
|
||||
|
||||
for side, data in pairs(self.mounts) do
|
||||
if data.type == "monitor" then
|
||||
table.insert(monitors, data.dev)
|
||||
-- get the fission reactor (if multiple, returns the first)
|
||||
function get_fission_reactor()
|
||||
return get_device("fissionReactor")
|
||||
end
|
||||
|
||||
-- get the wireless modem (if multiple, returns the first)
|
||||
function get_wireless_modem()
|
||||
local w_modem = nil
|
||||
|
||||
for side, device in pairs(self.mounts) do
|
||||
if device.type == "modem" and device.dev.isWireless() then
|
||||
w_modem = device.dev
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return monitors
|
||||
return w_modem
|
||||
end
|
||||
|
||||
-- list all connected monitors
|
||||
function list_monitors()
|
||||
return get_all_devices("monitor")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user