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
|
-- check if the reactor is formed
|
||||||
local function _is_formed()
|
local function _is_formed()
|
||||||
local is_formed = self.reactor.isFormed()
|
local formed = self.reactor.isFormed()
|
||||||
if is_formed == ppm.ACCESS_FAULT then
|
if formed == ppm.ACCESS_FAULT then
|
||||||
-- lost the peripheral or terminated, handled later
|
-- lost the peripheral or terminated, handled later
|
||||||
_set_fault()
|
_set_fault()
|
||||||
elseif not self.state[state_keys.sys_fail] then
|
else
|
||||||
self.formed = is_formed
|
self.formed = formed
|
||||||
self.state[state_keys.sys_fail] = not is_formed
|
|
||||||
|
if not self.state[state_keys.sys_fail] then
|
||||||
|
self.state[state_keys.sys_fail] = not formed
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ local config = require("reactor-plc.config")
|
|||||||
local plc = require("reactor-plc.plc")
|
local plc = require("reactor-plc.plc")
|
||||||
local threads = require("reactor-plc.threads")
|
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 print = util.print
|
||||||
local println = util.println
|
local println = util.println
|
||||||
@ -134,6 +134,8 @@ if __shared_memory.networked and smem_dev.modem == nil then
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- PLC init
|
-- PLC init
|
||||||
|
---
|
||||||
|
--- EVENT_CONSUMER: this function consumes events
|
||||||
local function init()
|
local function init()
|
||||||
if plc_state.init_ok then
|
if plc_state.init_ok then
|
||||||
-- just booting up, no fission allowed (neutrons stay put thanks)
|
-- just booting up, no fission allowed (neutrons stay put thanks)
|
||||||
|
@ -80,7 +80,7 @@ function threads.thread__main(smem, init)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- are we now formed after waiting to be formed?
|
-- 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
|
-- push a connect event and unmount it from the PPM
|
||||||
local iface = ppm.get_iface(plc_dev.reactor)
|
local iface = ppm.get_iface(plc_dev.reactor)
|
||||||
if iface then
|
if iface then
|
||||||
@ -89,21 +89,19 @@ function threads.thread__main(smem, init)
|
|||||||
|
|
||||||
local type, device = ppm.mount(iface)
|
local type, device = ppm.mount(iface)
|
||||||
|
|
||||||
if type ~= "fissionReactorLogicAdapter" and device ~= nil then
|
if type == "fissionReactorLogicAdapter" and device ~= nil then
|
||||||
-- reconnect reactor
|
-- reconnect reactor
|
||||||
plc_dev.reactor = device
|
plc_dev.reactor = device
|
||||||
plc_state.reactor_formed = device.isFormed()
|
|
||||||
|
|
||||||
if plc_state.reactor_formed then
|
-- we need to assume formed here as we cannot check in this main loop
|
||||||
println_ts("reactor reconnected as formed.")
|
-- RPS will identify if it isn't and this will get set false later
|
||||||
log.info("reactor reconnected as formed")
|
plc_state.reactor_formed = true
|
||||||
|
|
||||||
-- SCRAM newly connected reactor
|
println_ts("reactor reconnected.")
|
||||||
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
log.info("reactor reconnected")
|
||||||
else
|
|
||||||
println_ts("reactor reconnected but still not formed.")
|
-- SCRAM newly connected reactor
|
||||||
log.info("reactor reconnected but still not formed")
|
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
||||||
end
|
|
||||||
|
|
||||||
-- determine if we are still in a degraded state
|
-- determine if we are still in a degraded state
|
||||||
if not networked or not plc_state.no_modem then
|
if not networked or not plc_state.no_modem then
|
||||||
@ -114,6 +112,10 @@ function threads.thread__main(smem, init)
|
|||||||
if networked then
|
if networked then
|
||||||
plc_comms.reconnect_reactor(plc_dev.reactor)
|
plc_comms.reconnect_reactor(plc_dev.reactor)
|
||||||
end
|
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
|
else
|
||||||
-- fully lost the reactor now :(
|
-- fully lost the reactor now :(
|
||||||
println_ts("reactor lost (failed reconnect)!")
|
println_ts("reactor lost (failed reconnect)!")
|
||||||
@ -183,7 +185,10 @@ function threads.thread__main(smem, init)
|
|||||||
log.info("reactor reconnected")
|
log.info("reactor reconnected")
|
||||||
|
|
||||||
plc_state.no_reactor = false
|
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
|
-- determine if we are still in a degraded state
|
||||||
if (not networked or not plc_state.no_modem) and plc_state.reactor_formed then
|
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
|
end
|
||||||
|
|
||||||
if plc_state.init_ok then
|
if plc_state.init_ok then
|
||||||
if plc_state.reactor_formed then
|
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
||||||
smem.q.mq_rps.push_command(MQ__RPS_CMD.SCRAM)
|
|
||||||
end
|
|
||||||
|
|
||||||
rps.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
|
||||||
|
|
||||||
|
-- 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
|
end
|
||||||
elseif networked and type == "modem" then
|
elseif networked and type == "modem" then
|
||||||
if device.isWireless() then
|
if device.isWireless() then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user