mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#6 PLC retry SCRAM until reactor confirms unpowered
This commit is contained in:
parent
7c2d89e70f
commit
ed997d53e1
@ -206,6 +206,7 @@ function rplc_comms(id, modem, local_port, server_port, reactor)
|
|||||||
l_port = local_port,
|
l_port = local_port,
|
||||||
reactor = reactor,
|
reactor = reactor,
|
||||||
status_cache = nil,
|
status_cache = nil,
|
||||||
|
scrammed = false,
|
||||||
linked = false
|
linked = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +315,11 @@ function rplc_comms(id, modem, local_port, server_port, reactor)
|
|||||||
elseif packet.type == RPLC_TYPES.RS_IO_GET then
|
elseif packet.type == RPLC_TYPES.RS_IO_GET then
|
||||||
elseif packet.type == RPLC_TYPES.RS_IO_SET then
|
elseif packet.type == RPLC_TYPES.RS_IO_SET then
|
||||||
elseif packet.type == RPLC_TYPES.MEK_SCRAM then
|
elseif packet.type == RPLC_TYPES.MEK_SCRAM then
|
||||||
|
self.scrammed = true
|
||||||
|
self.reactor.scram()
|
||||||
elseif packet.type == RPLC_TYPES.MEK_ENABLE then
|
elseif packet.type == RPLC_TYPES.MEK_ENABLE then
|
||||||
|
self.scrammed = false
|
||||||
|
self.reactor.activate()
|
||||||
elseif packet.type == RPLC_TYPES.MEK_BURN_RATE then
|
elseif packet.type == RPLC_TYPES.MEK_BURN_RATE then
|
||||||
elseif packet.type == RPLC_TYPES.ISS_GET then
|
elseif packet.type == RPLC_TYPES.ISS_GET then
|
||||||
elseif packet.type == RPLC_TYPES.ISS_CLEAR then
|
elseif packet.type == RPLC_TYPES.ISS_CLEAR then
|
||||||
@ -408,7 +413,8 @@ function rplc_comms(id, modem, local_port, server_port, reactor)
|
|||||||
_send(sys_status)
|
_send(sys_status)
|
||||||
end
|
end
|
||||||
|
|
||||||
local linked = function () return self.linked end
|
local is_scrammed = function () return self.scrammed end
|
||||||
|
local is_linked = function () return self.linked end
|
||||||
local unlink = function () self.linked = false end
|
local unlink = function () self.linked = false end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -418,7 +424,8 @@ function rplc_comms(id, modem, local_port, server_port, reactor)
|
|||||||
send_link_req = send_link_req,
|
send_link_req = send_link_req,
|
||||||
send_struct = send_struct,
|
send_struct = send_struct,
|
||||||
send_status = send_status,
|
send_status = send_status,
|
||||||
linked = linked,
|
is_scrammed = is_scrammed,
|
||||||
|
is_linked = is_linked,
|
||||||
unlink = unlink
|
unlink = unlink
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -61,15 +61,26 @@ local ticks_to_update = LINK_TICKS
|
|||||||
|
|
||||||
-- runtime variables
|
-- runtime variables
|
||||||
local control_state = false
|
local control_state = false
|
||||||
|
local reactor_scram = true -- treated as latching e-stop
|
||||||
|
|
||||||
-- event loop
|
-- event loop
|
||||||
while true do
|
while true do
|
||||||
local event, param1, param2, param3, param4, param5 = os.pullEventRaw()
|
local event, param1, param2, param3, param4, param5 = os.pullEventRaw()
|
||||||
|
|
||||||
|
-- if we tried to SCRAM but failed, keep trying
|
||||||
|
-- if it disconnected, isPowered will return nil (and error logs will get spammed at 10Hz, so disable reporting)
|
||||||
|
-- in that case, SCRAM won't be called until it reconnects (this is the expected use of this check)
|
||||||
|
ppm.disable_reporting()
|
||||||
|
if reactor_scram and reactor.isPowered() then
|
||||||
|
reactor.scram()
|
||||||
|
end
|
||||||
|
ppm.enable_reporting()
|
||||||
|
|
||||||
if event == "peripheral_detach" then
|
if event == "peripheral_detach" then
|
||||||
ppm.handle_unmount(param1)
|
ppm.handle_unmount(param1)
|
||||||
|
|
||||||
-- try to scram reactor if it is still connected
|
-- try to scram reactor if it is still connected
|
||||||
|
reactor_scram = true
|
||||||
if reactor.scram() then
|
if reactor.scram() then
|
||||||
print_ts("[fatal] PLC lost a peripheral: successful SCRAM\n")
|
print_ts("[fatal] PLC lost a peripheral: successful SCRAM\n")
|
||||||
else
|
else
|
||||||
@ -81,6 +92,7 @@ while true do
|
|||||||
|
|
||||||
-- check safety (SCRAM occurs if tripped)
|
-- check safety (SCRAM occurs if tripped)
|
||||||
local iss_status, iss_tripped, iss_first = iss.check()
|
local iss_status, iss_tripped, iss_first = iss.check()
|
||||||
|
reactor_scram = reactor_scram or iss_tripped
|
||||||
if iss_first then
|
if iss_first then
|
||||||
plc_comms.send_iss_alarm(iss_status)
|
plc_comms.send_iss_alarm(iss_status)
|
||||||
end
|
end
|
||||||
@ -91,7 +103,7 @@ while true do
|
|||||||
-- iss was already checked (main reason for this tick rate)
|
-- iss was already checked (main reason for this tick rate)
|
||||||
ticks_to_update = ticks_to_update - 1
|
ticks_to_update = ticks_to_update - 1
|
||||||
|
|
||||||
if plc_comms.linked() then
|
if plc_comms.is_linked() then
|
||||||
if ticks_to_update <= 0 then
|
if ticks_to_update <= 0 then
|
||||||
plc_comms.send_status(control_state, iss_tripped)
|
plc_comms.send_status(control_state, iss_tripped)
|
||||||
ticks_to_update = UPDATE_TICKS
|
ticks_to_update = UPDATE_TICKS
|
||||||
@ -109,13 +121,16 @@ while true do
|
|||||||
|
|
||||||
local packet = plc_comms.parse_packet(p1, p2, p3, p4, p5)
|
local packet = plc_comms.parse_packet(p1, p2, p3, p4, p5)
|
||||||
plc_comms.handle_packet(packet)
|
plc_comms.handle_packet(packet)
|
||||||
|
reactor_scram = reactor_scram or plc_comms.is_scrammed()
|
||||||
elseif event == "timer" and param1 == conn_watchdog.get_timer() then
|
elseif event == "timer" and param1 == conn_watchdog.get_timer() then
|
||||||
-- haven't heard from server recently? shutdown reactor
|
-- haven't heard from server recently? shutdown reactor
|
||||||
|
reactor_scram = true
|
||||||
plc_comms.unlink()
|
plc_comms.unlink()
|
||||||
iss.trip_timeout()
|
iss.trip_timeout()
|
||||||
print_ts("[alert] server timeout, reactor disabled\n")
|
print_ts("[alert] server timeout, reactor disabled\n")
|
||||||
elseif event == "terminate" then
|
elseif event == "terminate" then
|
||||||
-- safe exit
|
-- safe exit
|
||||||
|
reactor_scram = true
|
||||||
if reactor.scram() then
|
if reactor.scram() then
|
||||||
print_ts("[alert] exiting, reactor disabled\n")
|
print_ts("[alert] exiting, reactor disabled\n")
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user