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