mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#85 handle loss of supervisor conn or comms modem
This commit is contained in:
@ -403,12 +403,12 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
|
|||||||
-- acknowledge receipt of builds
|
-- acknowledge receipt of builds
|
||||||
_send_sv(PROTOCOLS.SCADA_CRDN, SCADA_CRDN_TYPES.STRUCT_BUILDS, {})
|
_send_sv(PROTOCOLS.SCADA_CRDN, SCADA_CRDN_TYPES.STRUCT_BUILDS, {})
|
||||||
else
|
else
|
||||||
log.error("supervisor build packet invalid")
|
log.error("received invalid build packet")
|
||||||
end
|
end
|
||||||
elseif packet.type == SCADA_CRDN_TYPES.UNIT_STATUSES then
|
elseif packet.type == SCADA_CRDN_TYPES.UNIT_STATUSES then
|
||||||
-- update statuses
|
-- update statuses
|
||||||
if not database.update_statuses(packet.data) then
|
if not database.update_statuses(packet.data) then
|
||||||
log.error("supervisor unit status packet invalid")
|
log.error("received invalid unit statuses packet")
|
||||||
end
|
end
|
||||||
elseif packet.type == SCADA_CRDN_TYPES.COMMAND_UNIT then
|
elseif packet.type == SCADA_CRDN_TYPES.COMMAND_UNIT then
|
||||||
elseif packet.type == SCADA_CRDN_TYPES.ALARM then
|
elseif packet.type == SCADA_CRDN_TYPES.ALARM then
|
||||||
@ -435,6 +435,7 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
|
|||||||
elseif packet.type == SCADA_MGMT_TYPES.CLOSE then
|
elseif packet.type == SCADA_MGMT_TYPES.CLOSE then
|
||||||
-- handle session close
|
-- handle session close
|
||||||
sv_watchdog.cancel()
|
sv_watchdog.cancel()
|
||||||
|
self.sv_linked = false
|
||||||
println_ts("server connection closed by remote host")
|
println_ts("server connection closed by remote host")
|
||||||
log.warning("server connection closed by remote host")
|
log.warning("server connection closed by remote host")
|
||||||
else
|
else
|
||||||
@ -448,6 +449,9 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check if the coordinator is still linked to the supervisor
|
||||||
|
function public.is_linked() return self.sv_linked end
|
||||||
|
|
||||||
return public
|
return public
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,10 +8,6 @@ database.WASTE = { Pu = 0, Po = 1, AntiMatter = 2 }
|
|||||||
---@class coord_db
|
---@class coord_db
|
||||||
local db = {}
|
local db = {}
|
||||||
|
|
||||||
-- @todo
|
|
||||||
function database.purge_subscribers()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- initialize the coordinator database
|
-- initialize the coordinator database
|
||||||
---@param conf facility_conf configuration
|
---@param conf facility_conf configuration
|
||||||
function database.init(conf)
|
function database.init(conf)
|
||||||
|
@ -93,9 +93,6 @@ end
|
|||||||
-- close out the UI
|
-- close out the UI
|
||||||
---@param recolor? boolean true to restore to color palette from style
|
---@param recolor? boolean true to restore to color palette from style
|
||||||
function renderer.close_ui(recolor)
|
function renderer.close_ui(recolor)
|
||||||
-- delete all subscribers
|
|
||||||
database.purge_subscribers()
|
|
||||||
|
|
||||||
-- report ui as not ready
|
-- report ui as not ready
|
||||||
engine.ui_ready = false
|
engine.ui_ready = false
|
||||||
|
|
||||||
|
@ -108,39 +108,52 @@ log_comms("comms initialized")
|
|||||||
local MAIN_CLOCK = 0.5
|
local MAIN_CLOCK = 0.5
|
||||||
local loop_clock = util.new_clock(MAIN_CLOCK)
|
local loop_clock = util.new_clock(MAIN_CLOCK)
|
||||||
|
|
||||||
local tick_waiting, task_done = log_comms_connecting("attempting to connect to configured supervisor on channel " .. config.SCADA_SV_PORT)
|
-- attempt to connect to the supervisor or exit
|
||||||
|
local function init_connect_sv()
|
||||||
|
local tick_waiting, task_done = log_comms_connecting("attempting to connect to configured supervisor on channel " .. config.SCADA_SV_PORT)
|
||||||
|
|
||||||
-- attempt to establish a connection with the supervisory computer
|
-- attempt to establish a connection with the supervisory computer
|
||||||
if not coord_comms.sv_connect(60, tick_waiting, task_done) then
|
if not coord_comms.sv_connect(60, tick_waiting, task_done) then
|
||||||
log_comms("supervisor connection failed")
|
log_comms("supervisor connection failed")
|
||||||
println("boot> failed to connect to supervisor")
|
println("boot> failed to connect to supervisor")
|
||||||
log.fatal("failed to connect to supervisor")
|
log.fatal("failed to connect to supervisor")
|
||||||
log_sys("system shutdown")
|
log_sys("system shutdown")
|
||||||
return
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
init_connect_sv()
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
-- start the UI
|
-- start the UI
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
|
|
||||||
log_graphics("starting UI...")
|
-- start up the UI
|
||||||
-- util.psleep(3)
|
---@return boolean ui_ok started ok
|
||||||
|
local function init_start_ui()
|
||||||
|
log_graphics("starting UI...")
|
||||||
|
-- util.psleep(3)
|
||||||
|
|
||||||
local draw_start = util.time_ms()
|
local draw_start = util.time_ms()
|
||||||
|
|
||||||
local ui_ok, message = pcall(renderer.start_ui)
|
local ui_ok, message = pcall(renderer.start_ui)
|
||||||
if not ui_ok then
|
if not ui_ok then
|
||||||
renderer.close_ui(config.RECOLOR)
|
renderer.close_ui(config.RECOLOR)
|
||||||
log_graphics(util.c("UI crashed: ", message))
|
log_graphics(util.c("UI crashed: ", message))
|
||||||
println_ts("UI crashed")
|
println_ts("UI crashed")
|
||||||
log.fatal(util.c("ui crashed with error ", message))
|
log.fatal(util.c("ui crashed with error ", message))
|
||||||
else
|
else
|
||||||
log_graphics("first UI draw took " .. (util.time_ms() - draw_start) .. "ms")
|
log_graphics("first UI draw took " .. (util.time_ms() - draw_start) .. "ms")
|
||||||
|
|
||||||
-- start clock
|
-- start clock
|
||||||
loop_clock.start()
|
loop_clock.start()
|
||||||
|
end
|
||||||
|
|
||||||
|
return ui_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local ui_ok = init_start_ui()
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
-- main event loop
|
-- main event loop
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
@ -165,6 +178,9 @@ while ui_ok do
|
|||||||
log_sys("comms modem disconnected")
|
log_sys("comms modem disconnected")
|
||||||
println_ts("wireless modem disconnected!")
|
println_ts("wireless modem disconnected!")
|
||||||
log.error("comms modem disconnected!")
|
log.error("comms modem disconnected!")
|
||||||
|
|
||||||
|
-- close out UI
|
||||||
|
renderer.close_ui()
|
||||||
else
|
else
|
||||||
log_sys("non-comms modem disconnected")
|
log_sys("non-comms modem disconnected")
|
||||||
log.warning("non-comms modem disconnected")
|
log.warning("non-comms modem disconnected")
|
||||||
@ -185,6 +201,10 @@ while ui_ok do
|
|||||||
|
|
||||||
log_sys("comms modem reconnected")
|
log_sys("comms modem reconnected")
|
||||||
println_ts("wireless modem reconnected.")
|
println_ts("wireless modem reconnected.")
|
||||||
|
|
||||||
|
-- re-init system
|
||||||
|
init_connect_sv()
|
||||||
|
ui_ok = init_start_ui()
|
||||||
else
|
else
|
||||||
log_sys("wired modem reconnected")
|
log_sys("wired modem reconnected")
|
||||||
end
|
end
|
||||||
@ -206,6 +226,14 @@ while ui_ok do
|
|||||||
log_comms(msg)
|
log_comms(msg)
|
||||||
println_ts(msg)
|
println_ts(msg)
|
||||||
log.warning(msg)
|
log.warning(msg)
|
||||||
|
|
||||||
|
-- close connection and UI
|
||||||
|
coord_comms.close()
|
||||||
|
renderer.close_ui()
|
||||||
|
|
||||||
|
-- try to re-connect to the supervisor
|
||||||
|
init_connect_sv()
|
||||||
|
ui_ok = init_start_ui()
|
||||||
else
|
else
|
||||||
-- a non-clock/main watchdog timer event
|
-- a non-clock/main watchdog timer event
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user