#11 standalone de-asserts SCRAM and resets ISS before check, added prints to ISS, fixed non-networked mode related bugs, cleaned up ISS check call in startup

This commit is contained in:
Mikayla Fischler 2022-04-05 17:58:23 -04:00
parent ba1dd1b50e
commit 7e7e98ff6b
2 changed files with 54 additions and 27 deletions

View File

@ -50,14 +50,19 @@ function iss_init(reactor)
-- check system states in order of severity -- check system states in order of severity
if damage_critical() then if damage_critical() then
log._warning("ISS: damage critical!")
status = "dmg_crit" status = "dmg_crit"
elseif high_temp() then elseif high_temp() then
log._warning("ISS: high temperature!")
status = "high_temp" status = "high_temp"
elseif excess_heated_coolant() then elseif excess_heated_coolant() then
log._warning("ISS: heated coolant backup!")
status = "heated_coolant_backup" status = "heated_coolant_backup"
elseif excess_waste() then elseif excess_waste() then
log._warning("ISS: full waste!")
status = "full_waste" status = "full_waste"
elseif insufficient_fuel() then elseif insufficient_fuel() then
log._warning("ISS: no fuel!")
status = "no_fuel" status = "no_fuel"
elseif self.tripped then elseif self.tripped then
status = self.trip_cause status = self.trip_cause
@ -66,6 +71,7 @@ function iss_init(reactor)
end end
if status ~= "ok" then if status ~= "ok" then
log._warning("ISS: reactor SCRAM")
self.tripped = true self.tripped = true
self.trip_cause = status self.trip_cause = status
self.reactor.scram() self.reactor.scram()
@ -378,7 +384,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
end end
-- handle an RPLC packet -- handle an RPLC packet
local handle_packet = function (packet) local handle_packet = function (packet, plc_state)
if packet ~= nil then if packet ~= nil then
if packet.scada_frame.protocol() == PROTOCOLS.RPLC then if packet.scada_frame.protocol() == PROTOCOLS.RPLC then
if self.linked then if self.linked then
@ -424,10 +430,12 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
elseif packet.type == RPLC_TYPES.MEK_SCRAM then elseif packet.type == RPLC_TYPES.MEK_SCRAM then
-- disable the reactor -- disable the reactor
self.scrammed = true self.scrammed = true
plc_state.scram = true
_send_ack(packet.type, self.reactor.scram()) _send_ack(packet.type, self.reactor.scram())
elseif packet.type == RPLC_TYPES.MEK_ENABLE then elseif packet.type == RPLC_TYPES.MEK_ENABLE then
-- enable the reactor -- enable the reactor
self.scrammed = false self.scrammed = false
plc_state.scram = false
_send_ack(packet.type, self.reactor.activate()) _send_ack(packet.type, self.reactor.activate())
elseif packet.type == RPLC_TYPES.MEK_BURN_RATE then elseif packet.type == RPLC_TYPES.MEK_BURN_RATE then
-- set the burn rate -- set the burn rate

View File

@ -10,7 +10,7 @@ os.loadAPI("scada-common/comms.lua")
os.loadAPI("config.lua") os.loadAPI("config.lua")
os.loadAPI("plc.lua") os.loadAPI("plc.lua")
local R_PLC_VERSION = "alpha-v0.1.2" local R_PLC_VERSION = "alpha-v0.1.3"
local print = util.print local print = util.print
local println = util.println local println = util.println
@ -32,7 +32,7 @@ local networked = config.NETWORKED
local plc_state = { local plc_state = {
init_ok = true, init_ok = true,
scram = true, -- treated as latching e-stop, all conditions must be OK to set false scram = true,
degraded = false, degraded = false,
no_reactor = false, no_reactor = false,
no_modem = false no_modem = false
@ -69,7 +69,7 @@ local conn_watchdog = nil
local UPDATE_TICKS = 3 local UPDATE_TICKS = 3
local LINK_TICKS = 20 local LINK_TICKS = 20
local loop_tick = nil local loop_clock = nil
local ticks_to_update = LINK_TICKS -- start by linking local ticks_to_update = LINK_TICKS -- start by linking
function init() function init()
@ -94,7 +94,7 @@ function init()
end end
-- loop clock (10Hz, 2 ticks) -- loop clock (10Hz, 2 ticks)
loop_tick = os.startTimer(0.05) loop_clock = os.startTimer(0.05)
log._debug("loop clock started") log._debug("loop clock started")
println("boot> completed"); println("boot> completed");
@ -198,21 +198,36 @@ while true do
end end
end end
-- ISS
if plc_state.init_ok then
-- if we are in standalone mode, continuously reset ISS
-- ISS will trip again if there are faults, but if it isn't cleared, the user can't re-enable
if not networked then
plc_state.scram = false
iss.reset()
end
-- check safety (SCRAM occurs if tripped) -- check safety (SCRAM occurs if tripped)
if not plc_state.degraded then if not plc_state.degraded then
local iss_tripped, iss_status, iss_first = iss.check() local iss_tripped, iss_status, iss_first = iss.check()
plc_state.scram = plc_state.scram or iss_tripped plc_state.scram = plc_state.scram or iss_tripped
if networked and iss_first then
if iss_first then
println_ts("[ISS] reactor shutdown, safety tripped: " .. iss_status)
if networked then
plc_comms.send_iss_alarm(iss_status) plc_comms.send_iss_alarm(iss_status)
end end
elseif plc_state.init_ok then end
else
reactor.scram() reactor.scram()
end end
end
-- handle event -- handle event
if event == "timer" and param1 == loop_tick and networked and not plc_state.no_modem then if event == "timer" and param1 == loop_clock then
-- basic event tick, send updated data if it is time (~3.33Hz) -- basic event tick, send updated data if it is time (~3.33Hz)
-- iss was already checked (that's the main reason for this tick rate) -- iss was already checked (that's the main reason for this tick rate)
if networked and not plc_state.no_modem then
ticks_to_update = ticks_to_update - 1 ticks_to_update = ticks_to_update - 1
if plc_comms.is_linked() then if plc_comms.is_linked() then
@ -226,15 +241,19 @@ while true do
ticks_to_update = LINK_TICKS ticks_to_update = LINK_TICKS
end end
end end
end
-- start next clock timer
loop_clock = os.startTimer(0.05)
elseif event == "modem_message" and networked and not plc_state.no_modem then elseif event == "modem_message" and networked and not plc_state.no_modem then
-- got a packet -- got a packet
-- feed the watchdog first so it doesn't uhh...eat our packets -- feed the watchdog first so it doesn't uhh...eat our packets
conn_watchdog.feed() conn_watchdog.feed()
-- handle the packet (plc_state passed to allow clearing SCRAM flag)
local packet = plc_comms.parse_packet(p1, p2, p3, p4, p5) local packet = plc_comms.parse_packet(p1, p2, p3, p4, p5)
plc_comms.handle_packet(packet) plc_comms.handle_packet(packet, plc_state)
plc_state.scram = plc_state.scram or plc_comms.is_scrammed() elseif event == "timer" and networked and param1 == conn_watchdog.get_timer() then
elseif event == "timer" and param1 == conn_watchdog.get_timer() and networked then
-- haven't heard from server recently? shutdown reactor -- haven't heard from server recently? shutdown reactor
plc_state.scram = true plc_state.scram = true
plc_comms.unlink() plc_comms.unlink()