mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#8 cleaned up closing logic, added connected flags to RTU unit sessions
This commit is contained in:
parent
136b09d7f2
commit
0eff8a3e6a
@ -202,6 +202,12 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
||||
self.sDB.mek_struct.max_burn = mek_data[8]
|
||||
end
|
||||
|
||||
-- mark this PLC session as closed, stop watchdog
|
||||
local _close = function ()
|
||||
self.rtu_conn_watchdog.cancel()
|
||||
self.connected = false
|
||||
end
|
||||
|
||||
-- send an RPLC packet
|
||||
---@param msg_type RPLC_TYPES
|
||||
---@param msg table
|
||||
@ -392,7 +398,7 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
||||
end
|
||||
elseif pkt.type == SCADA_MGMT_TYPES.CLOSE then
|
||||
-- close the session
|
||||
self.connected = false
|
||||
_close()
|
||||
else
|
||||
log.debug(log_header .. "handler received unsupported SCADA_MGMT packet type " .. pkt.type)
|
||||
end
|
||||
@ -427,13 +433,12 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
||||
|
||||
-- check if a timer matches this session's watchdog
|
||||
public.check_wd = function (timer)
|
||||
return self.plc_conn_watchdog.is_timer(timer)
|
||||
return self.plc_conn_watchdog.is_timer(timer) and self.connected
|
||||
end
|
||||
|
||||
-- close the connection
|
||||
public.close = function ()
|
||||
self.plc_conn_watchdog.cancel()
|
||||
self.connected = false
|
||||
_close()
|
||||
_send_mgmt(SCADA_MGMT_TYPES.CLOSE, {})
|
||||
println("connection to reactor " .. self.for_reactor .. " PLC closed by server")
|
||||
log.info(log_header .. "session closed by server")
|
||||
@ -506,7 +511,6 @@ plc.new_session = function (id, for_reactor, in_queue, out_queue)
|
||||
|
||||
-- exit if connection was closed
|
||||
if not self.connected then
|
||||
self.plc_conn_watchdog.cancel()
|
||||
println("connection to reactor " .. self.for_reactor .. " PLC closed by remote host")
|
||||
log.info(log_header .. "session closed by remote host")
|
||||
return self.connected
|
||||
|
@ -129,6 +129,17 @@ rtu.new_session = function (id, in_queue, out_queue, advertisement)
|
||||
end
|
||||
end
|
||||
|
||||
-- mark this RTU session as closed, stop watchdog
|
||||
local _close = function ()
|
||||
self.rtu_conn_watchdog.cancel()
|
||||
self.connected = false
|
||||
|
||||
-- mark all RTU unit sessions as closed so the reactor unit knows
|
||||
for i = 1, #self.units do
|
||||
self.units[i].close()
|
||||
end
|
||||
end
|
||||
|
||||
-- send a SCADA management packet
|
||||
---@param msg_type SCADA_MGMT_TYPES
|
||||
---@param msg table
|
||||
@ -186,7 +197,7 @@ rtu.new_session = function (id, in_queue, out_queue, advertisement)
|
||||
end
|
||||
elseif pkt.type == SCADA_MGMT_TYPES.CLOSE then
|
||||
-- close the session
|
||||
self.connected = false
|
||||
_close()
|
||||
elseif pkt.type == SCADA_MGMT_TYPES.RTU_ADVERT then
|
||||
-- RTU unit advertisement
|
||||
-- handle advertisement; this will re-create all unit sub-sessions
|
||||
@ -206,13 +217,12 @@ rtu.new_session = function (id, in_queue, out_queue, advertisement)
|
||||
-- check if a timer matches this session's watchdog
|
||||
---@param timer number
|
||||
public.check_wd = function (timer)
|
||||
return self.rtu_conn_watchdog.is_timer(timer)
|
||||
return self.rtu_conn_watchdog.is_timer(timer) and self.connected
|
||||
end
|
||||
|
||||
-- close the connection
|
||||
public.close = function ()
|
||||
self.rtu_conn_watchdog.cancel()
|
||||
self.connected = false
|
||||
_close()
|
||||
_send_mgmt(SCADA_MGMT_TYPES.CLOSE, {})
|
||||
println(log_header .. "connection to RTU closed by server")
|
||||
log.info(log_header .. "session closed by server")
|
||||
@ -272,7 +282,6 @@ rtu.new_session = function (id, in_queue, out_queue, advertisement)
|
||||
|
||||
-- exit if connection was closed
|
||||
if not self.connected then
|
||||
self.rtu_conn_watchdog.cancel()
|
||||
println(log_header .. "connection to RTU closed by remote host")
|
||||
log.info(log_header .. "session closed by remote host")
|
||||
return self.connected
|
||||
|
@ -42,6 +42,7 @@ boiler.new = function (session_id, advert, out_queue)
|
||||
reactor = advert.reactor,
|
||||
out_q = out_queue,
|
||||
transaction_controller = txnctrl.new(),
|
||||
connected = true,
|
||||
has_build = false,
|
||||
periodics = {
|
||||
next_build_req = 0,
|
||||
@ -180,6 +181,9 @@ boiler.new = function (session_id, advert, out_queue)
|
||||
public.get_reactor = function () return self.reactor end
|
||||
public.get_db = function () return self.db end
|
||||
|
||||
public.close = function () self.connected = false end
|
||||
public.is_connected = function () return self.connected end
|
||||
|
||||
-- update this runner
|
||||
---@param time_now integer milliseconds
|
||||
public.update = function (time_now)
|
||||
|
@ -41,6 +41,7 @@ emachine.new = function (session_id, advert, out_queue)
|
||||
reactor = 0,
|
||||
out_q = out_queue,
|
||||
transaction_controller = txnctrl.new(),
|
||||
connected = true,
|
||||
has_build = false,
|
||||
periodics = {
|
||||
next_build_req = 0,
|
||||
@ -130,6 +131,9 @@ emachine.new = function (session_id, advert, out_queue)
|
||||
public.get_reactor = function () return self.reactor end
|
||||
public.get_db = function () return self.db end
|
||||
|
||||
public.close = function () self.connected = false end
|
||||
public.is_connected = function () return self.connected end
|
||||
|
||||
-- update this runner
|
||||
---@param time_now integer milliseconds
|
||||
public.update = function (time_now)
|
||||
|
@ -60,6 +60,7 @@ redstone.new = function (session_id, advert, out_queue)
|
||||
in_q = mqueue.new(),
|
||||
out_q = out_queue,
|
||||
transaction_controller = txnctrl.new(),
|
||||
connected = true,
|
||||
has_di = false,
|
||||
has_ai = false,
|
||||
periodics = {
|
||||
@ -192,6 +193,9 @@ redstone.new = function (session_id, advert, out_queue)
|
||||
public.get_reactor = function () return self.reactor end
|
||||
public.get_db = function () return self.db end
|
||||
|
||||
public.close = function () self.connected = false end
|
||||
public.is_connected = function () return self.connected end
|
||||
|
||||
-- update this runner
|
||||
---@param time_now integer milliseconds
|
||||
public.update = function (time_now)
|
||||
|
@ -43,6 +43,7 @@ turbine.new = function (session_id, advert, out_queue)
|
||||
reactor = advert.reactor,
|
||||
out_q = out_queue,
|
||||
transaction_controller = txnctrl.new(),
|
||||
connected = true,
|
||||
has_build = false,
|
||||
periodics = {
|
||||
next_build_req = 0,
|
||||
@ -171,6 +172,9 @@ turbine.new = function (session_id, advert, out_queue)
|
||||
public.get_reactor = function () return self.reactor end
|
||||
public.get_db = function () return self.db end
|
||||
|
||||
public.close = function () self.connected = false end
|
||||
public.is_connected = function () return self.connected end
|
||||
|
||||
-- update this runner
|
||||
---@param time_now integer milliseconds
|
||||
public.update = function (time_now)
|
||||
|
Loading…
Reference in New Issue
Block a user