mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
parent
1828920873
commit
aaab34f1a8
@ -82,13 +82,16 @@ function plc.rps_init(reactor, is_formed)
|
||||
|
||||
-- check if the reactor is formed
|
||||
local function _is_formed()
|
||||
local is_formed = self.reactor.isFormed()
|
||||
if is_formed == ppm.ACCESS_FAULT then
|
||||
local formed = self.reactor.isFormed()
|
||||
if formed == ppm.ACCESS_FAULT then
|
||||
-- lost the peripheral or terminated, handled later
|
||||
_set_fault()
|
||||
elseif not self.state[state_keys.sys_fail] then
|
||||
self.formed = is_formed
|
||||
self.state[state_keys.sys_fail] = not is_formed
|
||||
else
|
||||
self.formed = formed
|
||||
|
||||
if not self.state[state_keys.sys_fail] then
|
||||
self.state[state_keys.sys_fail] = not formed
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -13,7 +13,7 @@ local config = require("reactor-plc.config")
|
||||
local plc = require("reactor-plc.plc")
|
||||
local threads = require("reactor-plc.threads")
|
||||
|
||||
local R_PLC_VERSION = "beta-v0.9.1"
|
||||
local R_PLC_VERSION = "beta-v0.9.2"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
@ -134,6 +134,8 @@ if __shared_memory.networked and smem_dev.modem == nil then
|
||||
end
|
||||
|
||||
-- PLC init
|
||||
---
|
||||
--- EVENT_CONSUMER: this function consumes events
|
||||
local function init()
|
||||
if plc_state.init_ok then
|
||||
-- just booting up, no fission allowed (neutrons stay put thanks)
|
||||
|
@ -80,7 +80,7 @@ function threads.thread__main(smem, init)
|
||||
end
|
||||
|
||||
-- are we now formed after waiting to be formed?
|
||||
if not plc_state.reactor_formed and rps.is_formed() then
|
||||
if (not plc_state.reactor_formed) and rps.is_formed() then
|
||||
-- push a connect event and unmount it from the PPM
|
||||
local iface = ppm.get_iface(plc_dev.reactor)
|
||||
if iface then
|
||||
@ -89,21 +89,19 @@ function threads.thread__main(smem, init)
|
||||
|
||||
local type, device = ppm.mount(iface)
|
||||
|
||||
if type ~= "fissionReactorLogicAdapter" and device ~= nil then
|
||||
if type == "fissionReactorLogicAdapter" and device ~= nil then
|
||||
-- reconnect reactor
|
||||
plc_dev.reactor = device
|
||||
plc_state.reactor_formed = device.isFormed()
|
||||
|
||||
if plc_state.reactor_formed then
|
||||
println_ts("reactor reconnected as formed.")
|
||||
log.info("reactor reconnected as formed")
|
||||
-- we need to assume formed here as we cannot check in this main loop
|
||||
-- RPS will identify if it isn't and this will get set false later
|
||||
plc_state.reactor_formed = true
|
||||
|
||||
-- SCRAM newly connected reactor
|
||||
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
||||
else
|
||||
println_ts("reactor reconnected but still not formed.")
|
||||
log.info("reactor reconnected but still not formed")
|
||||
end
|
||||
println_ts("reactor reconnected.")
|
||||
log.info("reactor reconnected")
|
||||
|
||||
-- SCRAM newly connected reactor
|
||||
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
||||
|
||||
-- determine if we are still in a degraded state
|
||||
if not networked or not plc_state.no_modem then
|
||||
@ -114,6 +112,10 @@ function threads.thread__main(smem, init)
|
||||
if networked then
|
||||
plc_comms.reconnect_reactor(plc_dev.reactor)
|
||||
end
|
||||
|
||||
-- reset RPS for newly connected reactor
|
||||
-- without this, is_formed will be out of date and cause it to think its no longer formed again
|
||||
rps.reset()
|
||||
else
|
||||
-- fully lost the reactor now :(
|
||||
println_ts("reactor lost (failed reconnect)!")
|
||||
@ -183,7 +185,10 @@ function threads.thread__main(smem, init)
|
||||
log.info("reactor reconnected")
|
||||
|
||||
plc_state.no_reactor = false
|
||||
plc_state.reactor_formed = device.isFormed()
|
||||
|
||||
-- we need to assume formed here as we cannot check in this main loop
|
||||
-- RPS will identify if it isn't and this will get set false later
|
||||
plc_state.reactor_formed = true
|
||||
|
||||
-- determine if we are still in a degraded state
|
||||
if (not networked or not plc_state.no_modem) and plc_state.reactor_formed then
|
||||
@ -191,14 +196,16 @@ function threads.thread__main(smem, init)
|
||||
end
|
||||
|
||||
if plc_state.init_ok then
|
||||
if plc_state.reactor_formed then
|
||||
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
||||
end
|
||||
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
||||
|
||||
rps.reconnect_reactor(plc_dev.reactor)
|
||||
if networked then
|
||||
plc_comms.reconnect_reactor(plc_dev.reactor)
|
||||
end
|
||||
|
||||
-- reset RPS for newly connected reactor
|
||||
-- without this, is_formed will be out of date and cause it to think its no longer formed again
|
||||
rps.reset()
|
||||
end
|
||||
elseif networked and type == "modem" then
|
||||
if device.isWireless() then
|
||||
|
Loading…
Reference in New Issue
Block a user