mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
supervisor code moved around
This commit is contained in:
parent
5eaeb50000
commit
013656bc4d
@ -1,55 +0,0 @@
|
||||
--
|
||||
-- Nuclear Generation Facility SCADA Supervisor
|
||||
--
|
||||
|
||||
os.loadAPI("scada-common/util.lua")
|
||||
os.loadAPI("scada-common/comms.lua")
|
||||
os.loadAPI("supervisor/config.lua")
|
||||
|
||||
local SUPERVISOR_VERSION = "alpha-v0.1"
|
||||
|
||||
local print_ts = util.print_ts
|
||||
|
||||
local modem = peripheral.find("modem")
|
||||
|
||||
print("| SCADA Supervisor - " .. SUPERVISOR_VERSION .. " |")
|
||||
|
||||
-- we need a modem
|
||||
if modem == nil then
|
||||
print("No modem found, exiting...")
|
||||
return
|
||||
end
|
||||
|
||||
-- determine active/backup mode
|
||||
local mode = comms.SCADA_SV_MODES.BACKUP
|
||||
if config.SYSTEM_TYPE == "active" then
|
||||
mode = comms.SCADA_SV_MODES.ACTIVE
|
||||
end
|
||||
|
||||
-- start comms, open all channels
|
||||
if not modem.isOpen(config.SCADA_DEV_LISTEN) then
|
||||
modem.open(config.SCADA_DEV_LISTEN)
|
||||
end
|
||||
if not modem.isOpen(config.SCADA_FO_CHANNEL) then
|
||||
modem.open(config.SCADA_FO_CHANNEL)
|
||||
end
|
||||
if not modem.isOpen(config.SCADA_SV_CHANNEL) then
|
||||
modem.open(config.SCADA_SV_CHANNEL)
|
||||
end
|
||||
|
||||
local comms = comms.superv_comms(config.NUM_REACTORS, modem, config.SCADA_DEV_LISTEN, config.SCADA_FO_CHANNEL, config.SCADA_SV_CHANNEL)
|
||||
|
||||
-- base loop clock (4Hz, 5 ticks)
|
||||
local loop_tick = os.startTimer(0.25)
|
||||
|
||||
-- event loop
|
||||
while true do
|
||||
local event, param1, param2, param3, param4, param5 = os.pullEvent()
|
||||
|
||||
-- handle event
|
||||
if event == "timer" and param1 == loop_tick then
|
||||
-- basic event tick, send keep-alives
|
||||
elseif event == "modem_message" then
|
||||
-- got a packet
|
||||
end
|
||||
end
|
@ -1,3 +1,66 @@
|
||||
--
|
||||
-- Multi-Reactor Controller Server & GUI
|
||||
--
|
||||
-- Nuclear Generation Facility SCADA Supervisor
|
||||
--
|
||||
|
||||
os.loadAPI("scada-common/log.lua")
|
||||
os.loadAPI("scada-common/util.lua")
|
||||
os.loadAPI("scada-common/ppm.lua")
|
||||
os.loadAPI("scada-common/comms.lua")
|
||||
|
||||
os.loadAPI("supervisor/config.lua")
|
||||
os.loadAPI("supervisor/supervisor.lua")
|
||||
|
||||
local SUPERVISOR_VERSION = "alpha-v0.1.0"
|
||||
|
||||
local print_ts = util.print_ts
|
||||
|
||||
ppm.mount_all()
|
||||
|
||||
local modem = ppm.get_device("modem")
|
||||
|
||||
print("| SCADA Supervisor - " .. SUPERVISOR_VERSION .. " |")
|
||||
|
||||
-- we need a modem
|
||||
if modem == nil then
|
||||
print("Please connect a modem.")
|
||||
return
|
||||
end
|
||||
|
||||
-- determine active/backup mode
|
||||
local mode = comms.SCADA_SV_MODES.BACKUP
|
||||
if config.SYSTEM_TYPE == "active" then
|
||||
mode = comms.SCADA_SV_MODES.ACTIVE
|
||||
end
|
||||
|
||||
-- start comms, open all channels
|
||||
if not modem.isOpen(config.SCADA_DEV_LISTEN) then
|
||||
modem.open(config.SCADA_DEV_LISTEN)
|
||||
end
|
||||
if not modem.isOpen(config.SCADA_FO_CHANNEL) then
|
||||
modem.open(config.SCADA_FO_CHANNEL)
|
||||
end
|
||||
if not modem.isOpen(config.SCADA_SV_CHANNEL) then
|
||||
modem.open(config.SCADA_SV_CHANNEL)
|
||||
end
|
||||
|
||||
local comms = supervisor.superv_comms(config.NUM_REACTORS, modem, config.SCADA_DEV_LISTEN, config.SCADA_FO_CHANNEL, config.SCADA_SV_CHANNEL)
|
||||
|
||||
-- base loop clock (4Hz, 5 ticks)
|
||||
local loop_tick = os.startTimer(0.25)
|
||||
|
||||
-- event loop
|
||||
while true do
|
||||
local event, param1, param2, param3, param4, param5 = os.pullEventRaw()
|
||||
|
||||
-- handle event
|
||||
if event == "timer" and param1 == loop_tick then
|
||||
-- basic event tick, send keep-alives
|
||||
elseif event == "modem_message" then
|
||||
-- got a packet
|
||||
elseif event == "terminate" then
|
||||
-- safe exit
|
||||
print_ts("[alert] terminated\n")
|
||||
-- todo: attempt failover, alert hot backup
|
||||
return
|
||||
end
|
||||
end
|
||||
|
15
supervisor/supervisor.lua
Normal file
15
supervisor/supervisor.lua
Normal file
@ -0,0 +1,15 @@
|
||||
-- #REQUIRES comms.lua
|
||||
|
||||
-- supervisory controller communications
|
||||
function superv_comms(mode, num_reactors, modem, dev_listen, fo_channel, sv_channel)
|
||||
local self = {
|
||||
mode = mode,
|
||||
seq_num = 0,
|
||||
num_reactors = num_reactors,
|
||||
modem = modem,
|
||||
dev_listen = dev_listen,
|
||||
fo_channel = fo_channel,
|
||||
sv_channel = sv_channel,
|
||||
reactor_struct_cache = nil
|
||||
}
|
||||
end
|
Loading…
Reference in New Issue
Block a user