mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#43 rename ISS to RPS
This commit is contained in:
parent
b575899d46
commit
c4df8eabf9
@ -6,7 +6,7 @@ local util = require("scada-common.util")
|
|||||||
|
|
||||||
local plc = {}
|
local plc = {}
|
||||||
|
|
||||||
local iss_status_t = types.iss_status_t
|
local rps_status_t = types.rps_status_t
|
||||||
|
|
||||||
local PROTOCOLS = comms.PROTOCOLS
|
local PROTOCOLS = comms.PROTOCOLS
|
||||||
local RPLC_TYPES = comms.RPLC_TYPES
|
local RPLC_TYPES = comms.RPLC_TYPES
|
||||||
@ -18,10 +18,10 @@ local println = util.println
|
|||||||
local print_ts = util.print_ts
|
local print_ts = util.print_ts
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
|
|
||||||
-- Internal Safety System
|
-- Reactor Protection System
|
||||||
-- identifies dangerous states and SCRAMs reactor if warranted
|
-- identifies dangerous states and SCRAMs reactor if warranted
|
||||||
-- autonomous from main SCADA supervisor/coordinator control
|
-- autonomous from main SCADA supervisor/coordinator control
|
||||||
plc.iss_init = function (reactor)
|
plc.rps_init = function (reactor)
|
||||||
local self = {
|
local self = {
|
||||||
reactor = reactor,
|
reactor = reactor,
|
||||||
cache = { false, false, false, false, false, false, false },
|
cache = { false, false, false, false, false, false, false },
|
||||||
@ -37,7 +37,7 @@ plc.iss_init = function (reactor)
|
|||||||
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
|
||||||
log.error("ISS: failed to check reactor damage")
|
log.error("RPS: failed to check reactor damage")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return damage_percent >= 100
|
return damage_percent >= 100
|
||||||
@ -49,7 +49,7 @@ plc.iss_init = function (reactor)
|
|||||||
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
|
||||||
log.error("ISS: failed to check reactor heated coolant level")
|
log.error("RPS: failed to check reactor heated coolant level")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return hc_needed == 0
|
return hc_needed == 0
|
||||||
@ -61,7 +61,7 @@ plc.iss_init = function (reactor)
|
|||||||
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
|
||||||
log.error("ISS: failed to check reactor waste level")
|
log.error("RPS: failed to check reactor waste level")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return w_needed == 0
|
return w_needed == 0
|
||||||
@ -74,7 +74,7 @@ plc.iss_init = function (reactor)
|
|||||||
local temp = self.reactor.getTemperature()
|
local temp = self.reactor.getTemperature()
|
||||||
if temp == ppm.ACCESS_FAULT then
|
if temp == ppm.ACCESS_FAULT then
|
||||||
-- lost the peripheral or terminated, handled later
|
-- lost the peripheral or terminated, handled later
|
||||||
log.error("ISS: failed to check reactor temperature")
|
log.error("RPS: failed to check reactor temperature")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return temp >= 1200
|
return temp >= 1200
|
||||||
@ -86,7 +86,7 @@ plc.iss_init = function (reactor)
|
|||||||
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
|
||||||
log.error("ISS: failed to check reactor fuel level")
|
log.error("RPS: failed to check reactor fuel level")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return fuel == 0
|
return fuel == 0
|
||||||
@ -98,7 +98,7 @@ plc.iss_init = function (reactor)
|
|||||||
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
|
||||||
log.error("ISS: failed to check reactor coolant level")
|
log.error("RPS: failed to check reactor coolant level")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return coolant_filled < 0.02
|
return coolant_filled < 0.02
|
||||||
@ -119,7 +119,7 @@ plc.iss_init = function (reactor)
|
|||||||
|
|
||||||
-- check all safety conditions
|
-- check all safety conditions
|
||||||
local check = function ()
|
local check = function ()
|
||||||
local status = iss_status_t.ok
|
local status = rps_status_t.ok
|
||||||
local was_tripped = self.tripped
|
local was_tripped = self.tripped
|
||||||
|
|
||||||
-- update cache
|
-- update cache
|
||||||
@ -137,34 +137,34 @@ plc.iss_init = function (reactor)
|
|||||||
if self.tripped then
|
if self.tripped then
|
||||||
status = self.trip_cause
|
status = self.trip_cause
|
||||||
elseif self.cache[1] then
|
elseif self.cache[1] then
|
||||||
log.warning("ISS: damage critical!")
|
log.warning("RPS: damage critical!")
|
||||||
status = iss_status_t.dmg_crit
|
status = rps_status_t.dmg_crit
|
||||||
elseif self.cache[4] then
|
elseif self.cache[4] then
|
||||||
log.warning("ISS: high temperature!")
|
log.warning("RPS: high temperature!")
|
||||||
status = iss_status_t.high_temp
|
status = rps_status_t.high_temp
|
||||||
elseif self.cache[2] then
|
elseif self.cache[2] then
|
||||||
log.warning("ISS: heated coolant backup!")
|
log.warning("RPS: heated coolant backup!")
|
||||||
status = iss_status_t.ex_hcoolant
|
status = rps_status_t.ex_hcoolant
|
||||||
elseif self.cache[6] then
|
elseif self.cache[6] then
|
||||||
log.warning("ISS: no coolant!")
|
log.warning("RPS: no coolant!")
|
||||||
status = iss_status_t.no_coolant
|
status = rps_status_t.no_coolant
|
||||||
elseif self.cache[3] then
|
elseif self.cache[3] then
|
||||||
log.warning("ISS: full waste!")
|
log.warning("RPS: full waste!")
|
||||||
status = iss_status_t.ex_waste
|
status = rps_status_t.ex_waste
|
||||||
elseif self.cache[5] then
|
elseif self.cache[5] then
|
||||||
log.warning("ISS: no fuel!")
|
log.warning("RPS: no fuel!")
|
||||||
status = iss_status_t.no_fuel
|
status = rps_status_t.no_fuel
|
||||||
elseif self.cache[7] then
|
elseif self.cache[7] then
|
||||||
log.warning("ISS: supervisor connection timeout!")
|
log.warning("RPS: supervisor connection timeout!")
|
||||||
status = iss_status_t.timeout
|
status = rps_status_t.timeout
|
||||||
else
|
else
|
||||||
self.tripped = false
|
self.tripped = false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if a new trip occured...
|
-- if a new trip occured...
|
||||||
local first_trip = false
|
local first_trip = false
|
||||||
if not was_tripped and status ~= iss_status_t.ok then
|
if not was_tripped and status ~= rps_status_t.ok then
|
||||||
log.warning("ISS: reactor SCRAM")
|
log.warning("RPS: reactor SCRAM")
|
||||||
|
|
||||||
first_trip = true
|
first_trip = true
|
||||||
self.tripped = true
|
self.tripped = true
|
||||||
@ -172,22 +172,22 @@ plc.iss_init = function (reactor)
|
|||||||
|
|
||||||
self.reactor.scram()
|
self.reactor.scram()
|
||||||
if self.reactor.__p_is_faulted() then
|
if self.reactor.__p_is_faulted() then
|
||||||
log.error("ISS: failed reactor SCRAM")
|
log.error("RPS: failed reactor SCRAM")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return self.tripped, status, first_trip
|
return self.tripped, status, first_trip
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get the ISS status
|
-- get the RPS status
|
||||||
local status = function () return self.cache end
|
local status = function () return self.cache end
|
||||||
local is_tripped = function () return self.tripped end
|
local is_tripped = function () return self.tripped end
|
||||||
|
|
||||||
-- reset the ISS
|
-- reset the RPS
|
||||||
local reset = function ()
|
local reset = function ()
|
||||||
self.timed_out = false
|
self.timed_out = false
|
||||||
self.tripped = false
|
self.tripped = false
|
||||||
self.trip_cause = iss_status_t.ok
|
self.trip_cause = rps_status_t.ok
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -201,7 +201,7 @@ plc.iss_init = function (reactor)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- reactor PLC communications
|
-- reactor PLC communications
|
||||||
plc.comms = function (id, modem, local_port, server_port, reactor, iss)
|
plc.comms = function (id, modem, local_port, server_port, reactor, rps)
|
||||||
local self = {
|
local self = {
|
||||||
id = id,
|
id = id,
|
||||||
seq_num = 0,
|
seq_num = 0,
|
||||||
@ -210,7 +210,7 @@ plc.comms = function (id, modem, local_port, server_port, reactor, iss)
|
|||||||
s_port = server_port,
|
s_port = server_port,
|
||||||
l_port = local_port,
|
l_port = local_port,
|
||||||
reactor = reactor,
|
reactor = reactor,
|
||||||
iss = iss,
|
rps = rps,
|
||||||
scrammed = false,
|
scrammed = false,
|
||||||
linked = false,
|
linked = false,
|
||||||
status_cache = nil,
|
status_cache = nil,
|
||||||
@ -411,7 +411,7 @@ plc.comms = function (id, modem, local_port, server_port, reactor, iss)
|
|||||||
local sys_status = {
|
local sys_status = {
|
||||||
util.time(), -- timestamp
|
util.time(), -- timestamp
|
||||||
(not self.scrammed), -- enabled
|
(not self.scrammed), -- enabled
|
||||||
iss.is_tripped(), -- overridden
|
rps.is_tripped(), -- overridden
|
||||||
degraded, -- degraded
|
degraded, -- degraded
|
||||||
self.reactor.getHeatingRate(), -- heating rate
|
self.reactor.getHeatingRate(), -- heating rate
|
||||||
mek_data -- mekanism status data
|
mek_data -- mekanism status data
|
||||||
@ -425,22 +425,22 @@ plc.comms = function (id, modem, local_port, server_port, reactor, iss)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- send safety system status
|
-- send reactor protection system status
|
||||||
local send_iss_status = function ()
|
local send_rps_status = function ()
|
||||||
if self.linked then
|
if self.linked then
|
||||||
_send(RPLC_TYPES.ISS_STATUS, iss.status())
|
_send(RPLC_TYPES.RPS_STATUS, rps.status())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- send safety system alarm
|
-- send reactor protection system alarm
|
||||||
local send_iss_alarm = function (cause)
|
local send_rps_alarm = function (cause)
|
||||||
if self.linked then
|
if self.linked then
|
||||||
local iss_alarm = {
|
local rps_alarm = {
|
||||||
cause,
|
cause,
|
||||||
table.unpack(iss.status())
|
table.unpack(rps.status())
|
||||||
}
|
}
|
||||||
|
|
||||||
_send(RPLC_TYPES.ISS_ALARM, iss_alarm)
|
_send(RPLC_TYPES.RPS_ALARM, rps_alarm)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -581,9 +581,9 @@ plc.comms = function (id, modem, local_port, server_port, reactor, iss)
|
|||||||
else
|
else
|
||||||
log.debug("RPLC set burn rate packet length mismatch")
|
log.debug("RPLC set burn rate packet length mismatch")
|
||||||
end
|
end
|
||||||
elseif packet.type == RPLC_TYPES.ISS_CLEAR then
|
elseif packet.type == RPLC_TYPES.RPS_RESET then
|
||||||
-- clear the ISS status
|
-- reset the RPS status
|
||||||
iss.reset()
|
rps.reset()
|
||||||
_send_ack(packet.type, true)
|
_send_ack(packet.type, true)
|
||||||
else
|
else
|
||||||
log.warning("received unknown RPLC packet type " .. packet.type)
|
log.warning("received unknown RPLC packet type " .. packet.type)
|
||||||
@ -647,8 +647,8 @@ plc.comms = function (id, modem, local_port, server_port, reactor, iss)
|
|||||||
close = close,
|
close = close,
|
||||||
send_link_req = send_link_req,
|
send_link_req = send_link_req,
|
||||||
send_status = send_status,
|
send_status = send_status,
|
||||||
send_iss_status = send_iss_status,
|
send_rps_status = send_rps_status,
|
||||||
send_iss_alarm = send_iss_alarm,
|
send_rps_alarm = send_rps_alarm,
|
||||||
parse_packet = parse_packet,
|
parse_packet = parse_packet,
|
||||||
handle_packet = handle_packet,
|
handle_packet = handle_packet,
|
||||||
is_scrammed = is_scrammed,
|
is_scrammed = is_scrammed,
|
||||||
|
@ -11,7 +11,7 @@ local config = require("config")
|
|||||||
local plc = require("plc")
|
local plc = require("plc")
|
||||||
local threads = require("threads")
|
local threads = require("threads")
|
||||||
|
|
||||||
local R_PLC_VERSION = "alpha-v0.6.0"
|
local R_PLC_VERSION = "alpha-v0.6.1"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
@ -55,14 +55,14 @@ local __shared_memory = {
|
|||||||
|
|
||||||
-- system objects
|
-- system objects
|
||||||
plc_sys = {
|
plc_sys = {
|
||||||
iss = nil,
|
rps = nil,
|
||||||
plc_comms = nil,
|
plc_comms = nil,
|
||||||
conn_watchdog = nil
|
conn_watchdog = nil
|
||||||
},
|
},
|
||||||
|
|
||||||
-- message queues
|
-- message queues
|
||||||
q = {
|
q = {
|
||||||
mq_iss = mqueue.new(),
|
mq_rps = mqueue.new(),
|
||||||
mq_comms_tx = mqueue.new(),
|
mq_comms_tx = mqueue.new(),
|
||||||
mq_comms_rx = mqueue.new()
|
mq_comms_rx = mqueue.new()
|
||||||
}
|
}
|
||||||
@ -100,13 +100,13 @@ function init()
|
|||||||
-- just booting up, no fission allowed (neutrons stay put thanks)
|
-- just booting up, no fission allowed (neutrons stay put thanks)
|
||||||
smem_dev.reactor.scram()
|
smem_dev.reactor.scram()
|
||||||
|
|
||||||
-- init internal safety system
|
-- init reactor protection system
|
||||||
smem_sys.iss = plc.iss_init(smem_dev.reactor)
|
smem_sys.rps = plc.rps_init(smem_dev.reactor)
|
||||||
log.debug("iss init")
|
log.debug("rps init")
|
||||||
|
|
||||||
if __shared_memory.networked then
|
if __shared_memory.networked then
|
||||||
-- start comms
|
-- start comms
|
||||||
smem_sys.plc_comms = plc.comms(config.REACTOR_ID, smem_dev.modem, config.LISTEN_PORT, config.SERVER_PORT, smem_dev.reactor, smem_sys.iss)
|
smem_sys.plc_comms = plc.comms(config.REACTOR_ID, smem_dev.modem, config.LISTEN_PORT, config.SERVER_PORT, smem_dev.reactor, smem_sys.rps)
|
||||||
log.debug("comms init")
|
log.debug("comms init")
|
||||||
|
|
||||||
-- comms watchdog, 3 second timeout
|
-- comms watchdog, 3 second timeout
|
||||||
@ -131,7 +131,7 @@ init()
|
|||||||
|
|
||||||
-- init threads
|
-- init threads
|
||||||
local main_thread = threads.thread__main(__shared_memory, init)
|
local main_thread = threads.thread__main(__shared_memory, init)
|
||||||
local iss_thread = threads.thread__iss(__shared_memory)
|
local rps_thread = threads.thread__rps(__shared_memory)
|
||||||
|
|
||||||
if __shared_memory.networked then
|
if __shared_memory.networked then
|
||||||
-- init comms threads
|
-- init comms threads
|
||||||
@ -142,19 +142,19 @@ if __shared_memory.networked then
|
|||||||
local sp_ctrl_thread = threads.thread__setpoint_control(__shared_memory)
|
local sp_ctrl_thread = threads.thread__setpoint_control(__shared_memory)
|
||||||
|
|
||||||
-- run threads
|
-- run threads
|
||||||
parallel.waitForAll(main_thread.exec, iss_thread.exec, comms_thread_tx.exec, comms_thread_rx.exec, sp_ctrl_thread.exec)
|
parallel.waitForAll(main_thread.exec, rps_thread.exec, comms_thread_tx.exec, comms_thread_rx.exec, sp_ctrl_thread.exec)
|
||||||
|
|
||||||
if plc_state.init_ok then
|
if plc_state.init_ok then
|
||||||
-- send status one last time after ISS shutdown
|
-- send status one last time after RPS shutdown
|
||||||
smem_sys.plc_comms.send_status(plc_state.degraded)
|
smem_sys.plc_comms.send_status(plc_state.degraded)
|
||||||
smem_sys.plc_comms.send_iss_status()
|
smem_sys.plc_comms.send_rps_status()
|
||||||
|
|
||||||
-- close connection
|
-- close connection
|
||||||
smem_sys.plc_comms.close(smem_sys.conn_watchdog)
|
smem_sys.plc_comms.close(smem_sys.conn_watchdog)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- run threads, excluding comms
|
-- run threads, excluding comms
|
||||||
parallel.waitForAll(main_thread.exec, iss_thread.exec)
|
parallel.waitForAll(main_thread.exec, rps_thread.exec)
|
||||||
end
|
end
|
||||||
|
|
||||||
println_ts("exited")
|
println_ts("exited")
|
||||||
|
@ -13,13 +13,13 @@ local println_ts = util.println_ts
|
|||||||
local psleep = util.psleep
|
local psleep = util.psleep
|
||||||
|
|
||||||
local MAIN_CLOCK = 1 -- (1Hz, 20 ticks)
|
local MAIN_CLOCK = 1 -- (1Hz, 20 ticks)
|
||||||
local ISS_SLEEP = 500 -- (500ms, 10 ticks)
|
local RPS_SLEEP = 500 -- (500ms, 10 ticks)
|
||||||
local COMMS_SLEEP = 150 -- (150ms, 3 ticks)
|
local COMMS_SLEEP = 150 -- (150ms, 3 ticks)
|
||||||
local SP_CTRL_SLEEP = 250 -- (250ms, 5 ticks)
|
local SP_CTRL_SLEEP = 250 -- (250ms, 5 ticks)
|
||||||
|
|
||||||
local BURN_RATE_RAMP_mB_s = 5.0
|
local BURN_RATE_RAMP_mB_s = 5.0
|
||||||
|
|
||||||
local MQ__ISS_CMD = {
|
local MQ__RPS_CMD = {
|
||||||
SCRAM = 1,
|
SCRAM = 1,
|
||||||
DEGRADED_SCRAM = 2,
|
DEGRADED_SCRAM = 2,
|
||||||
TRIP_TIMEOUT = 3
|
TRIP_TIMEOUT = 3
|
||||||
@ -45,7 +45,7 @@ threads.thread__main = function (smem, init)
|
|||||||
local networked = smem.networked
|
local networked = smem.networked
|
||||||
local plc_state = smem.plc_state
|
local plc_state = smem.plc_state
|
||||||
local plc_dev = smem.plc_dev
|
local plc_dev = smem.plc_dev
|
||||||
local iss = smem.plc_sys.iss
|
local rps = smem.plc_sys.rps
|
||||||
local plc_comms = smem.plc_sys.plc_comms
|
local plc_comms = smem.plc_sys.plc_comms
|
||||||
local conn_watchdog = smem.plc_sys.conn_watchdog
|
local conn_watchdog = smem.plc_sys.conn_watchdog
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ threads.thread__main = function (smem, init)
|
|||||||
elseif event == "timer" and networked and param1 == conn_watchdog.get_timer() then
|
elseif event == "timer" and networked and param1 == conn_watchdog.get_timer() then
|
||||||
-- haven't heard from server recently? shutdown reactor
|
-- haven't heard from server recently? shutdown reactor
|
||||||
plc_comms.unlink()
|
plc_comms.unlink()
|
||||||
smem.q.mq_iss.push_command(MQ__ISS_CMD.TRIP_TIMEOUT)
|
smem.q.mq_rps.push_command(MQ__RPS_CMD.TRIP_TIMEOUT)
|
||||||
elseif event == "peripheral_detach" then
|
elseif event == "peripheral_detach" then
|
||||||
-- peripheral disconnect
|
-- peripheral disconnect
|
||||||
local device = ppm.handle_unmount(param1)
|
local device = ppm.handle_unmount(param1)
|
||||||
@ -103,7 +103,7 @@ threads.thread__main = function (smem, init)
|
|||||||
|
|
||||||
if plc_state.init_ok then
|
if plc_state.init_ok then
|
||||||
-- try to scram reactor if it is still connected
|
-- try to scram reactor if it is still connected
|
||||||
smem.q.mq_iss.push_command(MQ__ISS_CMD.DEGRADED_SCRAM)
|
smem.q.mq_rps.push_command(MQ__RPS_CMD.DEGRADED_SCRAM)
|
||||||
end
|
end
|
||||||
|
|
||||||
plc_state.degraded = true
|
plc_state.degraded = true
|
||||||
@ -119,14 +119,14 @@ threads.thread__main = function (smem, init)
|
|||||||
-- reconnected reactor
|
-- reconnected reactor
|
||||||
plc_dev.reactor = device
|
plc_dev.reactor = device
|
||||||
|
|
||||||
smem.q.mq_iss.push_command(MQ__ISS_CMD.SCRAM)
|
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
||||||
|
|
||||||
println_ts("reactor reconnected.")
|
println_ts("reactor reconnected.")
|
||||||
log.info("reactor reconnected.")
|
log.info("reactor reconnected.")
|
||||||
plc_state.no_reactor = false
|
plc_state.no_reactor = false
|
||||||
|
|
||||||
if plc_state.init_ok then
|
if plc_state.init_ok then
|
||||||
iss.reconnect_reactor(plc_dev.reactor)
|
rps.reconnect_reactor(plc_dev.reactor)
|
||||||
if networked then
|
if networked then
|
||||||
plc_comms.reconnect_reactor(plc_dev.reactor)
|
plc_comms.reconnect_reactor(plc_dev.reactor)
|
||||||
end
|
end
|
||||||
@ -171,7 +171,7 @@ threads.thread__main = function (smem, init)
|
|||||||
-- check for termination request
|
-- check for termination request
|
||||||
if event == "terminate" or ppm.should_terminate() then
|
if event == "terminate" or ppm.should_terminate() then
|
||||||
log.info("terminate requested, main thread exiting")
|
log.info("terminate requested, main thread exiting")
|
||||||
-- iss handles reactor shutdown
|
-- rps handles reactor shutdown
|
||||||
plc_state.shutdown = true
|
plc_state.shutdown = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -181,20 +181,20 @@ threads.thread__main = function (smem, init)
|
|||||||
return { exec = exec }
|
return { exec = exec }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ISS monitor thread
|
-- RPS operation thread
|
||||||
threads.thread__iss = function (smem)
|
threads.thread__rps = function (smem)
|
||||||
-- execute thread
|
-- execute thread
|
||||||
local exec = function ()
|
local exec = function ()
|
||||||
log.debug("iss thread start")
|
log.debug("rps thread start")
|
||||||
|
|
||||||
-- load in from shared memory
|
-- load in from shared memory
|
||||||
local networked = smem.networked
|
local networked = smem.networked
|
||||||
local plc_state = smem.plc_state
|
local plc_state = smem.plc_state
|
||||||
local plc_dev = smem.plc_dev
|
local plc_dev = smem.plc_dev
|
||||||
local iss = smem.plc_sys.iss
|
local rps = smem.plc_sys.rps
|
||||||
local plc_comms = smem.plc_sys.plc_comms
|
local plc_comms = smem.plc_sys.plc_comms
|
||||||
|
|
||||||
local iss_queue = smem.q.mq_iss
|
local rps_queue = smem.q.mq_rps
|
||||||
|
|
||||||
local was_linked = false
|
local was_linked = false
|
||||||
local last_update = util.time()
|
local last_update = util.time()
|
||||||
@ -203,14 +203,14 @@ threads.thread__iss = function (smem)
|
|||||||
while true do
|
while true do
|
||||||
local reactor = plc_dev.reactor
|
local reactor = plc_dev.reactor
|
||||||
|
|
||||||
-- ISS checks
|
-- RPS checks
|
||||||
if plc_state.init_ok then
|
if plc_state.init_ok then
|
||||||
-- SCRAM if no open connection
|
-- SCRAM if no open connection
|
||||||
if networked and not plc_comms.is_linked() then
|
if networked and not plc_comms.is_linked() then
|
||||||
plc_state.scram = true
|
plc_state.scram = true
|
||||||
if was_linked then
|
if was_linked then
|
||||||
was_linked = false
|
was_linked = false
|
||||||
iss.trip_timeout()
|
rps.trip_timeout()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- would do elseif not networked but there is no reason to do that extra operation
|
-- would do elseif not networked but there is no reason to do that extra operation
|
||||||
@ -223,38 +223,38 @@ threads.thread__iss = function (smem)
|
|||||||
reactor.scram()
|
reactor.scram()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if we are in standalone mode, continuously reset ISS
|
-- if we are in standalone mode, continuously reset RPS
|
||||||
-- ISS will trip again if there are faults, but if it isn't cleared, the user can't re-enable
|
-- RPS will trip again if there are faults, but if it isn't cleared, the user can't re-enable
|
||||||
if not networked then
|
if not networked then
|
||||||
plc_state.scram = false
|
plc_state.scram = false
|
||||||
iss.reset()
|
rps.reset()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check safety (SCRAM occurs if tripped)
|
-- check safety (SCRAM occurs if tripped)
|
||||||
if not plc_state.no_reactor then
|
if not plc_state.no_reactor then
|
||||||
local iss_tripped, iss_status_string, iss_first = iss.check()
|
local rps_tripped, rps_status_string, rps_first = rps.check()
|
||||||
plc_state.scram = plc_state.scram or iss_tripped
|
plc_state.scram = plc_state.scram or rps_tripped
|
||||||
|
|
||||||
if iss_first then
|
if rps_first then
|
||||||
println_ts("[ISS] SCRAM! safety trip: " .. iss_status_string)
|
println_ts("[RPS] SCRAM! safety trip: " .. rps_status_string)
|
||||||
if networked and not plc_state.no_modem then
|
if networked and not plc_state.no_modem then
|
||||||
plc_comms.send_iss_alarm(iss_status_string)
|
plc_comms.send_rps_alarm(rps_status_string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check for messages in the message queue
|
-- check for messages in the message queue
|
||||||
while iss_queue.ready() and not plc_state.shutdown do
|
while rps_queue.ready() and not plc_state.shutdown do
|
||||||
local msg = iss_queue.pop()
|
local msg = rps_queue.pop()
|
||||||
|
|
||||||
if msg.qtype == mqueue.TYPE.COMMAND then
|
if msg.qtype == mqueue.TYPE.COMMAND then
|
||||||
-- received a command
|
-- received a command
|
||||||
if msg.message == MQ__ISS_CMD.SCRAM then
|
if msg.message == MQ__RPS_CMD.SCRAM then
|
||||||
-- basic SCRAM
|
-- basic SCRAM
|
||||||
plc_state.scram = true
|
plc_state.scram = true
|
||||||
reactor.scram()
|
reactor.scram()
|
||||||
elseif msg.message == MQ__ISS_CMD.DEGRADED_SCRAM then
|
elseif msg.message == MQ__RPS_CMD.DEGRADED_SCRAM then
|
||||||
-- SCRAM with print
|
-- SCRAM with print
|
||||||
plc_state.scram = true
|
plc_state.scram = true
|
||||||
if reactor.scram() then
|
if reactor.scram() then
|
||||||
@ -264,10 +264,10 @@ threads.thread__iss = function (smem)
|
|||||||
println_ts("failed reactor SCRAM")
|
println_ts("failed reactor SCRAM")
|
||||||
log.error("failed reactor SCRAM")
|
log.error("failed reactor SCRAM")
|
||||||
end
|
end
|
||||||
elseif msg.message == MQ__ISS_CMD.TRIP_TIMEOUT then
|
elseif msg.message == MQ__RPS_CMD.TRIP_TIMEOUT then
|
||||||
-- watchdog tripped
|
-- watchdog tripped
|
||||||
plc_state.scram = true
|
plc_state.scram = true
|
||||||
iss.trip_timeout()
|
rps.trip_timeout()
|
||||||
println_ts("server timeout")
|
println_ts("server timeout")
|
||||||
log.warning("server timeout")
|
log.warning("server timeout")
|
||||||
end
|
end
|
||||||
@ -284,24 +284,24 @@ threads.thread__iss = function (smem)
|
|||||||
-- check for termination request
|
-- check for termination request
|
||||||
if plc_state.shutdown then
|
if plc_state.shutdown then
|
||||||
-- safe exit
|
-- safe exit
|
||||||
log.info("iss thread shutdown initiated")
|
log.info("rps thread shutdown initiated")
|
||||||
if plc_state.init_ok then
|
if plc_state.init_ok then
|
||||||
plc_state.scram = true
|
plc_state.scram = true
|
||||||
reactor.scram()
|
reactor.scram()
|
||||||
if reactor.__p_is_ok() then
|
if reactor.__p_is_ok() then
|
||||||
println_ts("reactor disabled")
|
println_ts("reactor disabled")
|
||||||
log.info("iss thread reactor SCRAM OK")
|
log.info("rps thread reactor SCRAM OK")
|
||||||
else
|
else
|
||||||
println_ts("exiting, reactor failed to disable")
|
println_ts("exiting, reactor failed to disable")
|
||||||
log.error("iss thread failed to SCRAM reactor on exit")
|
log.error("rps thread failed to SCRAM reactor on exit")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
log.info("iss thread exiting")
|
log.info("rps thread exiting")
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
-- delay before next check
|
-- delay before next check
|
||||||
last_update = util.adaptive_delay(ISS_SLEEP, last_update)
|
last_update = util.adaptive_delay(RPS_SLEEP, last_update)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -331,9 +331,9 @@ threads.thread__comms_tx = function (smem)
|
|||||||
if msg.qtype == mqueue.TYPE.COMMAND then
|
if msg.qtype == mqueue.TYPE.COMMAND then
|
||||||
-- received a command
|
-- received a command
|
||||||
if msg.message == MQ__COMM_CMD.SEND_STATUS then
|
if msg.message == MQ__COMM_CMD.SEND_STATUS then
|
||||||
-- send PLC/ISS status
|
-- send PLC/RPS status
|
||||||
plc_comms.send_status(plc_state.degraded)
|
plc_comms.send_status(plc_state.degraded)
|
||||||
plc_comms.send_iss_status()
|
plc_comms.send_rps_status()
|
||||||
end
|
end
|
||||||
elseif msg.qtype == mqueue.TYPE.DATA then
|
elseif msg.qtype == mqueue.TYPE.DATA then
|
||||||
-- received data
|
-- received data
|
||||||
|
@ -20,9 +20,9 @@ local RPLC_TYPES = {
|
|||||||
MEK_SCRAM = 4, -- SCRAM reactor
|
MEK_SCRAM = 4, -- SCRAM reactor
|
||||||
MEK_ENABLE = 5, -- enable reactor
|
MEK_ENABLE = 5, -- enable reactor
|
||||||
MEK_BURN_RATE = 6, -- set burn rate
|
MEK_BURN_RATE = 6, -- set burn rate
|
||||||
ISS_STATUS = 7, -- ISS status
|
RPS_STATUS = 7, -- RPS status
|
||||||
ISS_ALARM = 8, -- ISS alarm broadcast
|
RPS_ALARM = 8, -- RPS alarm broadcast
|
||||||
ISS_CLEAR = 9 -- clear ISS trip (if in bad state, will trip immediately)
|
RPS_RESET = 9 -- clear RPS trip (if in bad state, will trip immediately)
|
||||||
}
|
}
|
||||||
|
|
||||||
local RPLC_LINKING = {
|
local RPLC_LINKING = {
|
||||||
@ -232,9 +232,9 @@ comms.rplc_packet = function ()
|
|||||||
self.type == RPLC_TYPES.MEK_SCRAM or
|
self.type == RPLC_TYPES.MEK_SCRAM or
|
||||||
self.type == RPLC_TYPES.MEK_ENABLE or
|
self.type == RPLC_TYPES.MEK_ENABLE or
|
||||||
self.type == RPLC_TYPES.MEK_BURN_RATE or
|
self.type == RPLC_TYPES.MEK_BURN_RATE or
|
||||||
self.type == RPLC_TYPES.ISS_ALARM or
|
self.type == RPLC_TYPES.RPS_ALARM or
|
||||||
self.type == RPLC_TYPES.ISS_STATUS or
|
self.type == RPLC_TYPES.RPS_STATUS or
|
||||||
self.type == RPLC_TYPES.ISS_CLEAR
|
self.type == RPLC_TYPES.RPS_RESET
|
||||||
end
|
end
|
||||||
|
|
||||||
-- make an RPLC packet
|
-- make an RPLC packet
|
||||||
|
@ -14,7 +14,7 @@ types.rtu_t = {
|
|||||||
induction_matrix = "induction_matrix"
|
induction_matrix = "induction_matrix"
|
||||||
}
|
}
|
||||||
|
|
||||||
types.iss_status_t = {
|
types.rps_status_t = {
|
||||||
ok = "ok",
|
ok = "ok",
|
||||||
dmg_crit = "dmg_crit",
|
dmg_crit = "dmg_crit",
|
||||||
ex_hcoolant = "heated_coolant_backup",
|
ex_hcoolant = "heated_coolant_backup",
|
||||||
|
@ -22,7 +22,7 @@ local PLC_S_CMDS = {
|
|||||||
SCRAM = 0,
|
SCRAM = 0,
|
||||||
ENABLE = 1,
|
ENABLE = 1,
|
||||||
BURN_RATE = 2,
|
BURN_RATE = 2,
|
||||||
ISS_CLEAR = 3
|
RPS_RESET = 3
|
||||||
}
|
}
|
||||||
|
|
||||||
plc.PLC_S_CMDS = PLC_S_CMDS
|
plc.PLC_S_CMDS = PLC_S_CMDS
|
||||||
@ -62,14 +62,14 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
|||||||
scram_req = 0,
|
scram_req = 0,
|
||||||
enable_req = 0,
|
enable_req = 0,
|
||||||
burn_rate_req = 0,
|
burn_rate_req = 0,
|
||||||
iss_clear_req = 0
|
rps_reset_req = 0
|
||||||
},
|
},
|
||||||
-- command acknowledgements
|
-- command acknowledgements
|
||||||
acks = {
|
acks = {
|
||||||
scram = true,
|
scram = true,
|
||||||
enable = true,
|
enable = true,
|
||||||
burn_rate = true,
|
burn_rate = true,
|
||||||
iss_clear = true
|
rps_reset = true
|
||||||
},
|
},
|
||||||
-- session database
|
-- session database
|
||||||
sDB = {
|
sDB = {
|
||||||
@ -77,9 +77,9 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
|||||||
control_state = false,
|
control_state = false,
|
||||||
overridden = false,
|
overridden = false,
|
||||||
degraded = false,
|
degraded = false,
|
||||||
iss_tripped = false,
|
rps_tripped = false,
|
||||||
iss_trip_cause = "ok",
|
rps_trip_cause = "ok",
|
||||||
iss_status = {
|
rps_status = {
|
||||||
dmg_crit = false,
|
dmg_crit = false,
|
||||||
ex_hcool = false,
|
ex_hcool = false,
|
||||||
ex_waste = false,
|
ex_waste = false,
|
||||||
@ -127,14 +127,14 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local _copy_iss_status = function (iss_status)
|
local _copy_rps_status = function (rps_status)
|
||||||
self.sDB.iss_status.dmg_crit = iss_status[1]
|
self.sDB.rps_status.dmg_crit = rps_status[1]
|
||||||
self.sDB.iss_status.ex_hcool = iss_status[2]
|
self.sDB.rps_status.ex_hcool = rps_status[2]
|
||||||
self.sDB.iss_status.ex_waste = iss_status[3]
|
self.sDB.rps_status.ex_waste = rps_status[3]
|
||||||
self.sDB.iss_status.high_temp = iss_status[4]
|
self.sDB.rps_status.high_temp = rps_status[4]
|
||||||
self.sDB.iss_status.no_fuel = iss_status[5]
|
self.sDB.rps_status.no_fuel = rps_status[5]
|
||||||
self.sDB.iss_status.no_cool = iss_status[6]
|
self.sDB.rps_status.no_cool = rps_status[6]
|
||||||
self.sDB.iss_status.timed_out = iss_status[7]
|
self.sDB.rps_status.timed_out = rps_status[7]
|
||||||
end
|
end
|
||||||
|
|
||||||
local _copy_status = function (mek_data)
|
local _copy_status = function (mek_data)
|
||||||
@ -317,44 +317,44 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
|||||||
elseif ack == false then
|
elseif ack == false then
|
||||||
log.debug(log_header .. "burn rate update failed!")
|
log.debug(log_header .. "burn rate update failed!")
|
||||||
end
|
end
|
||||||
elseif pkt.type == RPLC_TYPES.ISS_STATUS then
|
elseif pkt.type == RPLC_TYPES.RPS_STATUS then
|
||||||
-- ISS status packet received, copy data
|
-- RPS status packet received, copy data
|
||||||
if pkt.length == 7 then
|
if pkt.length == 7 then
|
||||||
local status = pcall(_copy_iss_status, pkt.data)
|
local status = pcall(_copy_rps_status, pkt.data)
|
||||||
if status then
|
if status then
|
||||||
-- copied in ISS status data OK
|
-- copied in RPS status data OK
|
||||||
else
|
else
|
||||||
-- error copying ISS status data
|
-- error copying RPS status data
|
||||||
log.error(log_header .. "failed to parse ISS status packet data")
|
log.error(log_header .. "failed to parse RPS status packet data")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log.debug(log_header .. "RPLC ISS status packet length mismatch")
|
log.debug(log_header .. "RPLC RPS status packet length mismatch")
|
||||||
end
|
end
|
||||||
elseif pkt.type == RPLC_TYPES.ISS_ALARM then
|
elseif pkt.type == RPLC_TYPES.RPS_ALARM then
|
||||||
-- ISS alarm
|
-- RPS alarm
|
||||||
self.sDB.overridden = true
|
self.sDB.overridden = true
|
||||||
if pkt.length == 8 then
|
if pkt.length == 8 then
|
||||||
self.sDB.iss_tripped = true
|
self.sDB.rps_tripped = true
|
||||||
self.sDB.iss_trip_cause = pkt.data[1]
|
self.sDB.rps_trip_cause = pkt.data[1]
|
||||||
local status = pcall(_copy_iss_status, { table.unpack(pkt.data, 2, #pkt.length) })
|
local status = pcall(_copy_rps_status, { table.unpack(pkt.data, 2, #pkt.length) })
|
||||||
if status then
|
if status then
|
||||||
-- copied in ISS status data OK
|
-- copied in RPS status data OK
|
||||||
else
|
else
|
||||||
-- error copying ISS status data
|
-- error copying RPS status data
|
||||||
log.error(log_header .. "failed to parse ISS alarm status data")
|
log.error(log_header .. "failed to parse RPS alarm status data")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log.debug(log_header .. "RPLC ISS alarm packet length mismatch")
|
log.debug(log_header .. "RPLC RPS alarm packet length mismatch")
|
||||||
end
|
end
|
||||||
elseif pkt.type == RPLC_TYPES.ISS_CLEAR then
|
elseif pkt.type == RPLC_TYPES.RPS_RESET then
|
||||||
-- ISS clear acknowledgement
|
-- RPS reset acknowledgement
|
||||||
local ack = _get_ack(pkt)
|
local ack = _get_ack(pkt)
|
||||||
if ack then
|
if ack then
|
||||||
self.acks.iss_tripped = true
|
self.acks.rps_tripped = true
|
||||||
self.sDB.iss_tripped = false
|
self.sDB.rps_tripped = false
|
||||||
self.sDB.iss_trip_cause = "ok"
|
self.sDB.rps_trip_cause = "ok"
|
||||||
elseif ack == false then
|
elseif ack == false then
|
||||||
log.debug(log_header .. "ISS clear failed")
|
log.debug(log_header .. "RPS reset failed")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log.debug(log_header .. "handler received unsupported RPLC packet type " .. pkt.type)
|
log.debug(log_header .. "handler received unsupported RPLC packet type " .. pkt.type)
|
||||||
@ -438,11 +438,11 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
|||||||
self.acks.enable = false
|
self.acks.enable = false
|
||||||
self.retry_times.enable_req = util.time() + INITIAL_WAIT
|
self.retry_times.enable_req = util.time() + INITIAL_WAIT
|
||||||
_send(RPLC_TYPES.MEK_ENABLE, {})
|
_send(RPLC_TYPES.MEK_ENABLE, {})
|
||||||
elseif cmd == PLC_S_CMDS.ISS_CLEAR then
|
elseif cmd == PLC_S_CMDS.RPS_RESET then
|
||||||
-- clear ISS
|
-- reset RPS
|
||||||
self.acks.iss_clear = false
|
self.acks.rps_reset = false
|
||||||
self.retry_times.iss_clear_req = util.time() + INITIAL_WAIT
|
self.retry_times.rps_reset_req = util.time() + INITIAL_WAIT
|
||||||
_send(RPLC_TYPES.ISS_CLEAR, {})
|
_send(RPLC_TYPES.RPS_RESET, {})
|
||||||
end
|
end
|
||||||
elseif message.qtype == mqueue.TYPE.DATA then
|
elseif message.qtype == mqueue.TYPE.DATA then
|
||||||
-- instruction with body
|
-- instruction with body
|
||||||
@ -540,12 +540,12 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ISS clear request retry
|
-- RPS reset request retry
|
||||||
|
|
||||||
if not self.acks.iss_clear then
|
if not self.acks.rps_reset then
|
||||||
if rtimes.iss_clear_req - util.time() <= 0 then
|
if rtimes.rps_reset_req - util.time() <= 0 then
|
||||||
_send(RPLC_TYPES.ISS_CLEAR, {})
|
_send(RPLC_TYPES.RPS_RESET, {})
|
||||||
rtimes.iss_clear_req = util.time() + RETRY_PERIOD
|
rtimes.rps_reset_req = util.time() + RETRY_PERIOD
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ local svsessions = require("session.svsessions")
|
|||||||
local config = require("config")
|
local config = require("config")
|
||||||
local supervisor = require("supervisor")
|
local supervisor = require("supervisor")
|
||||||
|
|
||||||
local SUPERVISOR_VERSION = "alpha-v0.3.0"
|
local SUPERVISOR_VERSION = "alpha-v0.3.1"
|
||||||
|
|
||||||
local print = util.print
|
local print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
|
Loading…
Reference in New Issue
Block a user