mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
ISS cleanup
This commit is contained in:
parent
074f6448e1
commit
1744527a41
@ -11,18 +11,16 @@ local RPLC_LINKING = comms.RPLC_LINKING
|
|||||||
function iss_init(reactor)
|
function iss_init(reactor)
|
||||||
local self = {
|
local self = {
|
||||||
reactor = reactor,
|
reactor = reactor,
|
||||||
|
cache = { false, false, false, false, false, false, false },
|
||||||
timed_out = false,
|
timed_out = false,
|
||||||
tripped = false,
|
tripped = false,
|
||||||
trip_cause = ""
|
trip_cause = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
-- re-link a reactor after a peripheral re-connect
|
-- PRIVATE FUNCTIONS --
|
||||||
local reconnect_reactor = function (reactor)
|
|
||||||
self.reactor = reactor
|
|
||||||
end
|
|
||||||
|
|
||||||
-- check for critical damage
|
-- check for critical damage
|
||||||
local damage_critical = function ()
|
local _damage_critical = function ()
|
||||||
local damage_percent = self.reactor.getDamagePercent()
|
local damage_percent = self.reactor.getDamagePercent()
|
||||||
if damage_percent == ppm.ACCESS_FAULT then
|
if damage_percent == ppm.ACCESS_FAULT then
|
||||||
-- lost the peripheral or terminated, handled later
|
-- lost the peripheral or terminated, handled later
|
||||||
@ -34,7 +32,7 @@ function iss_init(reactor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- check for heated coolant backup
|
-- check for heated coolant backup
|
||||||
local excess_heated_coolant = function ()
|
local _excess_heated_coolant = function ()
|
||||||
local hc_needed = self.reactor.getHeatedCoolantNeeded()
|
local hc_needed = self.reactor.getHeatedCoolantNeeded()
|
||||||
if hc_needed == ppm.ACCESS_FAULT then
|
if hc_needed == ppm.ACCESS_FAULT then
|
||||||
-- lost the peripheral or terminated, handled later
|
-- lost the peripheral or terminated, handled later
|
||||||
@ -46,7 +44,7 @@ function iss_init(reactor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- check for excess waste
|
-- check for excess waste
|
||||||
local excess_waste = function ()
|
local _excess_waste = function ()
|
||||||
local w_needed = self.reactor.getWasteNeeded()
|
local w_needed = self.reactor.getWasteNeeded()
|
||||||
if w_needed == ppm.ACCESS_FAULT then
|
if w_needed == ppm.ACCESS_FAULT then
|
||||||
-- lost the peripheral or terminated, handled later
|
-- lost the peripheral or terminated, handled later
|
||||||
@ -58,7 +56,7 @@ function iss_init(reactor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- check if the reactor is at a critically high temperature
|
-- check if the reactor is at a critically high temperature
|
||||||
local high_temp = function ()
|
local _high_temp = function ()
|
||||||
-- mekanism: MAX_DAMAGE_TEMPERATURE = 1_200
|
-- mekanism: MAX_DAMAGE_TEMPERATURE = 1_200
|
||||||
local temp = self.reactor.getTemperature()
|
local temp = self.reactor.getTemperature()
|
||||||
if temp == ppm.ACCESS_FAULT then
|
if temp == ppm.ACCESS_FAULT then
|
||||||
@ -71,7 +69,7 @@ function iss_init(reactor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- check if there is no fuel
|
-- check if there is no fuel
|
||||||
local insufficient_fuel = function ()
|
local _insufficient_fuel = function ()
|
||||||
local fuel = self.reactor.getFuel()
|
local fuel = self.reactor.getFuel()
|
||||||
if fuel == ppm.ACCESS_FAULT then
|
if fuel == ppm.ACCESS_FAULT then
|
||||||
-- lost the peripheral or terminated, handled later
|
-- lost the peripheral or terminated, handled later
|
||||||
@ -83,7 +81,7 @@ function iss_init(reactor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- check if there is no coolant
|
-- check if there is no coolant
|
||||||
local no_coolant = function ()
|
local _no_coolant = function ()
|
||||||
local coolant_filled = self.reactor.getCoolantFilledPercentage()
|
local coolant_filled = self.reactor.getCoolantFilledPercentage()
|
||||||
if coolant_filled == ppm.ACCESS_FAULT then
|
if coolant_filled == ppm.ACCESS_FAULT then
|
||||||
-- lost the peripheral or terminated, handled later
|
-- lost the peripheral or terminated, handled later
|
||||||
@ -94,9 +92,16 @@ function iss_init(reactor)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if PLC timed out
|
-- PUBLIC FUNCTIONS --
|
||||||
local timed_out = function ()
|
|
||||||
return self.timed_out
|
-- re-link a reactor after a peripheral re-connect
|
||||||
|
local reconnect_reactor = function (reactor)
|
||||||
|
self.reactor = reactor
|
||||||
|
end
|
||||||
|
|
||||||
|
-- report a PLC comms timeout
|
||||||
|
local trip_timeout = function ()
|
||||||
|
self.timed_out = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check all safety conditions
|
-- check all safety conditions
|
||||||
@ -104,29 +109,46 @@ function iss_init(reactor)
|
|||||||
local status = "ok"
|
local status = "ok"
|
||||||
local was_tripped = self.tripped
|
local was_tripped = self.tripped
|
||||||
|
|
||||||
|
-- update cache
|
||||||
|
self.cache = {
|
||||||
|
_damage_critical(),
|
||||||
|
_excess_heated_coolant(),
|
||||||
|
_excess_waste(),
|
||||||
|
_high_temp(),
|
||||||
|
_insufficient_fuel(),
|
||||||
|
_no_coolant(),
|
||||||
|
self.timed_out
|
||||||
|
}
|
||||||
|
|
||||||
-- check system states in order of severity
|
-- check system states in order of severity
|
||||||
if damage_critical() then
|
if self.cache[1] then
|
||||||
log._warning("ISS: damage critical!")
|
log._warning("ISS: damage critical!")
|
||||||
status = "dmg_crit"
|
status = "dmg_crit"
|
||||||
elseif high_temp() then
|
elseif self.cache[4] then
|
||||||
log._warning("ISS: high temperature!")
|
log._warning("ISS: high temperature!")
|
||||||
status = "high_temp"
|
status = "high_temp"
|
||||||
elseif excess_heated_coolant() then
|
elseif self.cache[2] then
|
||||||
log._warning("ISS: heated coolant backup!")
|
log._warning("ISS: heated coolant backup!")
|
||||||
status = "heated_coolant_backup"
|
status = "heated_coolant_backup"
|
||||||
elseif excess_waste() then
|
elseif self.cache[6] then
|
||||||
|
log._warning("ISS: no coolant!")
|
||||||
|
status = "no_coolant"
|
||||||
|
elseif self.cache[3] then
|
||||||
log._warning("ISS: full waste!")
|
log._warning("ISS: full waste!")
|
||||||
status = "full_waste"
|
status = "full_waste"
|
||||||
elseif insufficient_fuel() then
|
elseif self.cache[5] then
|
||||||
log._warning("ISS: no fuel!")
|
log._warning("ISS: no fuel!")
|
||||||
status = "no_fuel"
|
status = "no_fuel"
|
||||||
|
elseif self.timed_out then
|
||||||
|
log._warning("ISS: supervisor connection timeout!")
|
||||||
|
status = "timeout"
|
||||||
elseif self.tripped then
|
elseif self.tripped then
|
||||||
status = self.trip_cause
|
status = self.trip_cause
|
||||||
else
|
else
|
||||||
self.tripped = false
|
self.tripped = false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if a new trip occured...
|
-- if a trip occured...
|
||||||
if status ~= "ok" then
|
if status ~= "ok" then
|
||||||
log._warning("ISS: reactor SCRAM")
|
log._warning("ISS: reactor SCRAM")
|
||||||
self.tripped = true
|
self.tripped = true
|
||||||
@ -137,19 +159,12 @@ function iss_init(reactor)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- evaluate if this is a new trip
|
||||||
local first_trip = not was_tripped and self.tripped
|
local first_trip = not was_tripped and self.tripped
|
||||||
|
|
||||||
return self.tripped, status, first_trip
|
return self.tripped, status, first_trip
|
||||||
end
|
end
|
||||||
|
|
||||||
-- report a PLC comms timeout
|
|
||||||
local trip_timeout = function ()
|
|
||||||
self.tripped = false
|
|
||||||
self.trip_cause = "timeout"
|
|
||||||
self.timed_out = true
|
|
||||||
self.reactor.scram()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- reset the ISS
|
-- reset the ISS
|
||||||
local reset = function ()
|
local reset = function ()
|
||||||
self.timed_out = false
|
self.timed_out = false
|
||||||
@ -158,43 +173,16 @@ function iss_init(reactor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- get the ISS status
|
-- get the ISS status
|
||||||
local status = function (named)
|
local status = function ()
|
||||||
if named then
|
return self.cache
|
||||||
return {
|
|
||||||
damage_critical = damage_critical(),
|
|
||||||
excess_heated_coolant = excess_heated_coolant(),
|
|
||||||
excess_waste = excess_waste(),
|
|
||||||
high_temp = high_temp(),
|
|
||||||
insufficient_fuel = insufficient_fuel(),
|
|
||||||
no_coolant = no_coolant(),
|
|
||||||
timed_out = timed_out()
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return {
|
|
||||||
damage_critical(),
|
|
||||||
excess_heated_coolant(),
|
|
||||||
excess_waste(),
|
|
||||||
high_temp(),
|
|
||||||
insufficient_fuel(),
|
|
||||||
no_coolant(),
|
|
||||||
timed_out()
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
reconnect_reactor = reconnect_reactor,
|
reconnect_reactor = reconnect_reactor,
|
||||||
check = check,
|
|
||||||
trip_timeout = trip_timeout,
|
trip_timeout = trip_timeout,
|
||||||
|
check = check,
|
||||||
reset = reset,
|
reset = reset,
|
||||||
status = status,
|
status = status
|
||||||
damage_critical = damage_critical,
|
|
||||||
excess_heated_coolant = excess_heated_coolant,
|
|
||||||
excess_waste = excess_waste,
|
|
||||||
high_temp = high_temp,
|
|
||||||
insufficient_fuel = insufficient_fuel,
|
|
||||||
no_coolant = no_coolant,
|
|
||||||
timed_out = timed_out
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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.2.7"
|
local R_PLC_VERSION = "alpha-v0.2.8"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
@ -230,7 +230,8 @@ while true do
|
|||||||
plc_comms.send_iss_alarm(iss_status_string)
|
plc_comms.send_iss_alarm(iss_status_string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
elseif not plc_state.no_reactor then
|
||||||
|
-- degraded but we have a reactor
|
||||||
reactor.scram()
|
reactor.scram()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user