From 14cb7f96fccec529b0215b05f48eb618290c37f3 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 22 Jan 2022 14:47:54 -0500 Subject: [PATCH] supervisor comms init --- scada-common/comms.lua | 14 +++++++++++++- supervisor/config.lua | 8 +++----- supervisor/scada-supervisor.lua | 22 ++++++++++++++++------ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/scada-common/comms.lua b/scada-common/comms.lua index 23af375..5641cba 100644 --- a/scada-common/comms.lua +++ b/scada-common/comms.lua @@ -5,6 +5,11 @@ PROTOCOLS = { COORD_DATA = 3 -- data packets for coordinators to/from supervisory controller } +SCADA_SV_MODES = { + ACTIVE = 0, + BACKUP = 1 +} + RPLC_TYPES = { KEEP_ALIVE = 0, -- keep alive packets LINK_REQ = 1, -- linking requests @@ -131,8 +136,15 @@ function coord_comms() end -- supervisory controller communications -function superv_comms() +function superv_comms(mode, num_reactors, modem, dev_listen, fo_channel, sv_channel) local self = { + mode = mode, + seq_id = 0, + num_reactors = num_reactors, + modem = modem, + dev_listen = dev_listen, + fo_channel = fo_channel, + sv_channel = sv_channel, reactor_struct_cache = nil } end diff --git a/supervisor/config.lua b/supervisor/config.lua index 39adeef..bc02177 100644 --- a/supervisor/config.lua +++ b/supervisor/config.lua @@ -5,14 +5,12 @@ -- instant failover if active goes offline without re-sync SYSTEM_TYPE = 'active' --- scada network -SCADA_NET_PFX = 16000 +-- scada network listen for PLC's and RTU's +SCADA_DEV_LISTEN = 16000 -- failover synchronization SCADA_FO_CHANNEL = 16001 --- listen port for SCADA supervisor access +-- listen port for SCADA supervisor access by coordinators SCADA_SV_CHANNEL = 16002 --- listen port for PLC's -SCADA_PLC_LISTEN = 16003 -- expected number of reactors NUM_REACTORS = 4 diff --git a/supervisor/scada-supervisor.lua b/supervisor/scada-supervisor.lua index 772c572..28a7e40 100644 --- a/supervisor/scada-supervisor.lua +++ b/supervisor/scada-supervisor.lua @@ -20,14 +20,24 @@ if modem == nil then return end --- read config - --- start comms -if not modem.isOpen(config.LISTEN_PORT) then - modem.open(config.LISTEN_PORT) +-- determine active/backup mode +local mode = comms.SCADA_SV_MODES.BACKUP +if config.SYSTEM_TYPE == "active" then + mode = comms.SCADA_SV_MODES.ACTIVE end -local comms = comms.superv_comms(config.NUM_REACTORS, modem, config.SCADA_PLC_LISTEN, config.SCADA_SV_CHANNEL) +-- 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)