mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
catch nil cases, supervisor use loop clock
This commit is contained in:
parent
3c688bfafa
commit
e3a4ed5363
@ -88,16 +88,17 @@ threads.thread__main = function (smem, init)
|
||||
smem.q.mq_rps.push_command(MQ__RPS_CMD.TRIP_TIMEOUT)
|
||||
elseif event == "peripheral_detach" then
|
||||
-- peripheral disconnect
|
||||
local device = ppm.handle_unmount(param1)
|
||||
local type, device = ppm.handle_unmount(param1)
|
||||
|
||||
if device.type == "fissionReactor" then
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "fissionReactor" then
|
||||
println_ts("reactor disconnected!")
|
||||
log.error("reactor disconnected!")
|
||||
plc_state.no_reactor = true
|
||||
plc_state.degraded = true
|
||||
elseif networked and device.type == "modem" then
|
||||
elseif networked and type == "modem" then
|
||||
-- we only care if this is our wireless modem
|
||||
if device.dev == plc_dev.modem then
|
||||
if device == plc_dev.modem then
|
||||
println_ts("wireless modem disconnected!")
|
||||
log.error("comms modem disconnected!")
|
||||
plc_state.no_modem = true
|
||||
@ -112,10 +113,12 @@ threads.thread__main = function (smem, init)
|
||||
log.warning("non-comms modem disconnected")
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event == "peripheral" then
|
||||
-- peripheral connect
|
||||
local type, device = ppm.mount(param1)
|
||||
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "fissionReactor" then
|
||||
-- reconnected reactor
|
||||
plc_dev.reactor = device
|
||||
@ -158,6 +161,7 @@ threads.thread__main = function (smem, init)
|
||||
log.info("wired modem reconnected.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not plc_state.init_ok and not plc_state.degraded then
|
||||
plc_state.init_ok = true
|
||||
|
@ -74,11 +74,12 @@ threads.thread__main = function (smem)
|
||||
rtu_comms.unlink(rtu_state)
|
||||
elseif event == "peripheral_detach" then
|
||||
-- handle loss of a device
|
||||
local device = ppm.handle_unmount(param1)
|
||||
local type, device = ppm.handle_unmount(param1)
|
||||
|
||||
if device.type == "modem" then
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "modem" then
|
||||
-- we only care if this is our wireless modem
|
||||
if device.dev == rtu_dev.modem then
|
||||
if device == rtu_dev.modem then
|
||||
println_ts("wireless modem disconnected!")
|
||||
log.warning("comms modem disconnected!")
|
||||
else
|
||||
@ -87,7 +88,7 @@ threads.thread__main = function (smem)
|
||||
else
|
||||
for i = 1, #units do
|
||||
-- find disconnected device
|
||||
if units[i].device == device.dev then
|
||||
if units[i].device == device then
|
||||
-- we are going to let the PPM prevent crashes
|
||||
-- return fault flags/codes to MODBUS queries
|
||||
local unit = units[i]
|
||||
@ -95,10 +96,12 @@ threads.thread__main = function (smem)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event == "peripheral" then
|
||||
-- peripheral connect
|
||||
local type, device = ppm.mount(param1)
|
||||
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "modem" then
|
||||
if device.isWireless() then
|
||||
-- reconnected modem
|
||||
@ -141,6 +144,7 @@ threads.thread__main = function (smem)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- check for termination request
|
||||
if event == "terminate" or ppm.should_terminate() then
|
||||
|
@ -43,28 +43,32 @@ local superv_comms = supervisor.comms(config.NUM_REACTORS, modem, config.SCADA_D
|
||||
|
||||
-- base loop clock (6.67Hz, 3 ticks)
|
||||
local MAIN_CLOCK = 0.15
|
||||
local loop_clock = os.startTimer(MAIN_CLOCK)
|
||||
local loop_clock = util.new_clock(MAIN_CLOCK)
|
||||
|
||||
-- event loop
|
||||
while true do
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
local event, param1, param2, param3, param4, param5 = os.pullEventRaw()
|
||||
|
||||
-- handle event
|
||||
if event == "peripheral_detach" then
|
||||
local device = ppm.handle_unmount(param1)
|
||||
local type, device = ppm.handle_unmount(param1)
|
||||
|
||||
if device.type == "modem" then
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "modem" then
|
||||
-- we only care if this is our wireless modem
|
||||
if device.dev == modem then
|
||||
if device == modem then
|
||||
println_ts("wireless modem disconnected!")
|
||||
log.error("comms modem disconnected!")
|
||||
else
|
||||
log.warning("non-comms modem disconnected")
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif event == "peripheral" then
|
||||
local type, device = ppm.mount(param1)
|
||||
|
||||
if type ~= nil and device ~= nil then
|
||||
if type == "modem" then
|
||||
if device.isWireless() then
|
||||
-- reconnected modem
|
||||
@ -77,7 +81,8 @@ while true do
|
||||
log.info("wired modem reconnected.")
|
||||
end
|
||||
end
|
||||
elseif event == "timer" and param1 == loop_clock then
|
||||
end
|
||||
elseif event == "timer" and loop_clock.is_clock(param1) then
|
||||
-- main loop tick
|
||||
|
||||
-- iterate sessions
|
||||
@ -86,9 +91,9 @@ while true do
|
||||
-- free any closed sessions
|
||||
svsessions.free_all_closed()
|
||||
|
||||
loop_clock = os.startTimer(MAIN_CLOCK)
|
||||
loop_clock.start()
|
||||
elseif event == "timer" then
|
||||
-- another timer event, check watchdogs
|
||||
-- a non-clock timer event, check watchdogs
|
||||
svsessions.check_all_watchdogs(param1)
|
||||
elseif event == "modem_message" then
|
||||
-- got a packet
|
||||
|
Loading…
Reference in New Issue
Block a user