cc-mek-scada/supervisor/unit.lua

83 lines
2.1 KiB
Lua
Raw Normal View History

local unit = {}
unit.new = function (for_reactor)
local public = {}
local self = {
r_id = for_reactor,
plc_s = nil,
turbines = {},
boilers = {},
energy_storage = {},
redstone = {},
db = {
annunciator = {
-- RPS
-- reactor
PLCOnline = false,
ReactorTrip = false,
ManualReactorTrip = false,
RCPTrip = false,
RCSFlowLow = false,
ReactorTempHigh = false,
ReactorHighDeltaT = false,
ReactorOverPower = false,
HighStartupRate = false,
-- boiler
BoilerOnline = false,
HeatingRateLow = false,
CoolantFeedMismatch = false,
-- turbine
TurbineOnline = false,
SteamFeedMismatch = false,
SteamDumpOpen = false,
TurbineTrip = false,
TurbineOverUnderSpeed = false
}
}
}
public.link_plc_session = function (plc_session)
self.plc_s = plc_session
end
public.add_turbine = function (turbine)
table.insert(self.turbines, turbine)
end
2022-05-10 16:01:56 +00:00
public.add_boiler = function (boiler)
table.insert(self.boilers, boiler)
end
public.add_redstone = function (field, accessor)
-- ensure field exists
2022-05-10 16:01:56 +00:00
if self.redstone[field] == nil then
self.redstone[field] = {}
end
-- insert into list
2022-05-10 16:01:56 +00:00
table.insert(self.redstone[field], accessor)
end
local _update_annunciator = function ()
self.db.annunciator.PLCOnline = (self.plc_s ~= nil) and (self.plc_s.open)
self.db.annunciator.ReactorTrip = false
end
public.update = function ()
-- unlink PLC if session was closed
if not self.plc_s.open then
self.plc_s = nil
end
-- update annunciator logic
_update_annunciator()
end
public.get_annunciator = function () return self.db.annunciator end
return public
end
return unit