mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
send ISS status automatically along with PLC status
This commit is contained in:
parent
0c132f6e43
commit
b10a8d9479
@ -1,4 +1,4 @@
|
||||
-- set to false to run in standalone mode (safety regulation only)
|
||||
-- set to false to run in offline mode (safety regulation only)
|
||||
NETWORKED = true
|
||||
-- unique reactor ID
|
||||
REACTOR_ID = 1
|
||||
|
@ -207,9 +207,10 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
l_port = local_port,
|
||||
reactor = reactor,
|
||||
iss = iss,
|
||||
status_cache = nil,
|
||||
scrammed = false,
|
||||
linked = false
|
||||
linked = false,
|
||||
status_cache = nil,
|
||||
max_burn_rate = nil
|
||||
}
|
||||
|
||||
-- open modem
|
||||
@ -328,7 +329,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
local _send_iss_status = function ()
|
||||
local iss_status = {
|
||||
id = self.id,
|
||||
type = RPLC_TYPES.ISS_GET,
|
||||
type = RPLC_TYPES.ISS_STATUS,
|
||||
status = iss.status()
|
||||
}
|
||||
|
||||
@ -438,10 +439,17 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
_send_ack(packet.type, self.reactor.activate() == ppm.ACCESS_OK)
|
||||
elseif packet.type == RPLC_TYPES.MEK_BURN_RATE then
|
||||
-- set the burn rate
|
||||
local burn_rate = packet.data[1]
|
||||
local max_burn_rate = self.reactor.getMaxBurnRate()
|
||||
local success = false
|
||||
local burn_rate = packet.data[1]
|
||||
local max_burn_rate = self.max_burn_rate
|
||||
|
||||
-- if no known max burn rate, check again
|
||||
if max_burn_rate == nil then
|
||||
max_burn_rate = self.reactor.getMaxBurnRate()
|
||||
self.max_burn_rate = max_burn_rate
|
||||
end
|
||||
|
||||
-- if we know our max burn rate, update current burn rate if in range
|
||||
if max_burn_rate ~= ppm.ACCESS_FAULT then
|
||||
if burn_rate > 0 and burn_rate <= max_burn_rate then
|
||||
success = self.reactor.setBurnRate(burn_rate)
|
||||
@ -449,9 +457,6 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
end
|
||||
|
||||
_send_ack(packet.type, success == ppm.ACCESS_OK)
|
||||
elseif packet.type == RPLC_TYPES.ISS_GET then
|
||||
-- get the ISS status
|
||||
_send_iss_status(iss.status())
|
||||
elseif packet.type == RPLC_TYPES.ISS_CLEAR then
|
||||
-- clear the ISS status
|
||||
iss.reset()
|
||||
@ -526,6 +531,16 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
_send(sys_status)
|
||||
end
|
||||
|
||||
local send_iss_status = function ()
|
||||
local iss_status = {
|
||||
id = self.id,
|
||||
type = RPLC_TYPES.ISS_STATUS,
|
||||
status = iss.status()
|
||||
}
|
||||
|
||||
_send(iss_status)
|
||||
end
|
||||
|
||||
local send_iss_alarm = function (cause)
|
||||
local iss_alarm = {
|
||||
id = self.id,
|
||||
@ -548,6 +563,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss)
|
||||
handle_packet = handle_packet,
|
||||
send_link_req = send_link_req,
|
||||
send_status = send_status,
|
||||
send_iss_status = send_iss_status,
|
||||
send_iss_alarm = send_iss_alarm,
|
||||
is_scrammed = is_scrammed,
|
||||
is_linked = is_linked,
|
||||
|
@ -10,7 +10,7 @@ os.loadAPI("scada-common/comms.lua")
|
||||
os.loadAPI("config.lua")
|
||||
os.loadAPI("plc.lua")
|
||||
|
||||
local R_PLC_VERSION = "alpha-v0.2.1"
|
||||
local R_PLC_VERSION = "alpha-v0.2.2"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
@ -90,6 +90,7 @@ function init()
|
||||
conn_watchdog = util.new_watchdog(3)
|
||||
log._debug("conn watchdog started")
|
||||
else
|
||||
println("boot> starting in offline mode");
|
||||
log._debug("running without networking")
|
||||
end
|
||||
|
||||
@ -220,13 +221,13 @@ while true do
|
||||
|
||||
-- check safety (SCRAM occurs if tripped)
|
||||
if not plc_state.degraded then
|
||||
local iss_tripped, iss_status, iss_first = iss.check()
|
||||
local iss_tripped, iss_status_string, iss_first = iss.check()
|
||||
plc_state.scram = plc_state.scram or iss_tripped
|
||||
|
||||
if iss_first then
|
||||
println_ts("[ISS] reactor shutdown, safety tripped: " .. iss_status)
|
||||
println_ts("[ISS] reactor shutdown, safety tripped: " .. iss_status_string)
|
||||
if networked then
|
||||
plc_comms.send_iss_alarm(iss_status)
|
||||
plc_comms.send_iss_alarm(iss_status_string)
|
||||
end
|
||||
end
|
||||
else
|
||||
@ -244,6 +245,7 @@ while true do
|
||||
if plc_comms.is_linked() then
|
||||
if ticks_to_update <= 0 then
|
||||
plc_comms.send_status(iss_tripped, plc_state.degraded)
|
||||
plc_comms.send_iss_status()
|
||||
ticks_to_update = UPDATE_TICKS
|
||||
end
|
||||
else
|
||||
@ -275,9 +277,8 @@ while true do
|
||||
|
||||
-- check for termination request
|
||||
if event == "terminate" or ppm.should_terminate() then
|
||||
log._warning("terminate requested, exiting...")
|
||||
|
||||
-- safe exit
|
||||
log._warning("terminate requested, exiting...")
|
||||
if plc_state.init_ok then
|
||||
plc_state.scram = true
|
||||
if reactor.scram() ~= ppm.ACCESS_FAULT then
|
||||
@ -287,7 +288,6 @@ while true do
|
||||
println_ts("exiting, reactor failed to disable")
|
||||
end
|
||||
end
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
@ -18,8 +18,8 @@ RPLC_TYPES = {
|
||||
MEK_SCRAM = 4, -- SCRAM reactor
|
||||
MEK_ENABLE = 5, -- enable reactor
|
||||
MEK_BURN_RATE = 6, -- set burn rate
|
||||
ISS_ALARM = 7, -- ISS alarm broadcast
|
||||
ISS_GET = 8, -- get ISS status
|
||||
ISS_STATUS = 7, -- ISS status
|
||||
ISS_ALARM = 8, -- ISS alarm broadcast
|
||||
ISS_CLEAR = 9 -- clear ISS trip (if in bad state, will trip immediately)
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ function rplc_packet()
|
||||
self.type == RPLC_TYPES.MEK_ENABLE or
|
||||
self.type == RPLC_TYPES.MEK_BURN_RATE or
|
||||
self.type == RPLC_TYPES.ISS_ALARM or
|
||||
self.type == RPLC_TYPES.ISS_GET or
|
||||
self.type == RPLC_TYPES.ISS_STATUS or
|
||||
self.type == RPLC_TYPES.ISS_CLEAR
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user