mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
supervisor code cleanup
This commit is contained in:
@ -173,7 +173,7 @@ function coordinator.new_session(id, in_queue, out_queue, timeout, facility)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- handle a packet
|
-- handle a packet
|
||||||
---@param pkt crdn_frame
|
---@param pkt mgmt_frame|crdn_frame
|
||||||
local function _handle_packet(pkt)
|
local function _handle_packet(pkt)
|
||||||
-- check sequence number
|
-- check sequence number
|
||||||
if self.r_seq_num == nil then
|
if self.r_seq_num == nil then
|
||||||
@ -190,6 +190,7 @@ function coordinator.new_session(id, in_queue, out_queue, timeout, facility)
|
|||||||
|
|
||||||
-- process packet
|
-- process packet
|
||||||
if pkt.scada_frame.protocol() == PROTOCOL.SCADA_MGMT then
|
if pkt.scada_frame.protocol() == PROTOCOL.SCADA_MGMT then
|
||||||
|
---@cast pkt mgmt_frame
|
||||||
if pkt.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
if pkt.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
||||||
-- keep alive reply
|
-- keep alive reply
|
||||||
if pkt.length == 2 then
|
if pkt.length == 2 then
|
||||||
@ -214,6 +215,7 @@ function coordinator.new_session(id, in_queue, out_queue, timeout, facility)
|
|||||||
log.debug(log_header .. "handler received unsupported SCADA_MGMT packet type " .. pkt.type)
|
log.debug(log_header .. "handler received unsupported SCADA_MGMT packet type " .. pkt.type)
|
||||||
end
|
end
|
||||||
elseif pkt.scada_frame.protocol() == PROTOCOL.SCADA_CRDN then
|
elseif pkt.scada_frame.protocol() == PROTOCOL.SCADA_CRDN then
|
||||||
|
---@cast pkt crdn_frame
|
||||||
if pkt.type == SCADA_CRDN_TYPE.INITIAL_BUILDS then
|
if pkt.type == SCADA_CRDN_TYPE.INITIAL_BUILDS then
|
||||||
-- acknowledgement to coordinator receiving builds
|
-- acknowledgement to coordinator receiving builds
|
||||||
self.acks.builds = true
|
self.acks.builds = true
|
||||||
|
@ -279,7 +279,7 @@ function plc.new_session(id, reactor_id, in_queue, out_queue, timeout)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- handle a packet
|
-- handle a packet
|
||||||
---@param pkt rplc_frame
|
---@param pkt mgmt_frame|rplc_frame
|
||||||
local function _handle_packet(pkt)
|
local function _handle_packet(pkt)
|
||||||
-- check sequence number
|
-- check sequence number
|
||||||
if self.r_seq_num == nil then
|
if self.r_seq_num == nil then
|
||||||
@ -293,6 +293,7 @@ function plc.new_session(id, reactor_id, in_queue, out_queue, timeout)
|
|||||||
|
|
||||||
-- process packet
|
-- process packet
|
||||||
if pkt.scada_frame.protocol() == PROTOCOL.RPLC then
|
if pkt.scada_frame.protocol() == PROTOCOL.RPLC then
|
||||||
|
---@cast pkt rplc_frame
|
||||||
-- check reactor ID
|
-- check reactor ID
|
||||||
if pkt.id ~= reactor_id then
|
if pkt.id ~= reactor_id then
|
||||||
log.warning(log_header .. "RPLC packet with ID not matching reactor ID: reactor " .. reactor_id .. " != " .. pkt.id)
|
log.warning(log_header .. "RPLC packet with ID not matching reactor ID: reactor " .. reactor_id .. " != " .. pkt.id)
|
||||||
@ -469,6 +470,7 @@ function plc.new_session(id, reactor_id, in_queue, out_queue, timeout)
|
|||||||
log.debug(log_header .. "handler received unsupported RPLC packet type " .. pkt.type)
|
log.debug(log_header .. "handler received unsupported RPLC packet type " .. pkt.type)
|
||||||
end
|
end
|
||||||
elseif pkt.scada_frame.protocol() == PROTOCOL.SCADA_MGMT then
|
elseif pkt.scada_frame.protocol() == PROTOCOL.SCADA_MGMT then
|
||||||
|
---@cast pkt mgmt_frame
|
||||||
if pkt.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
if pkt.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
||||||
-- keep alive reply
|
-- keep alive reply
|
||||||
if pkt.length == 2 then
|
if pkt.length == 2 then
|
||||||
|
@ -226,12 +226,13 @@ function rtu.new_session(id, in_queue, out_queue, timeout, advertisement, facili
|
|||||||
|
|
||||||
-- process packet
|
-- process packet
|
||||||
if pkt.scada_frame.protocol() == PROTOCOL.MODBUS_TCP then
|
if pkt.scada_frame.protocol() == PROTOCOL.MODBUS_TCP then
|
||||||
|
---@cast pkt modbus_frame
|
||||||
if self.units[pkt.unit_id] ~= nil then
|
if self.units[pkt.unit_id] ~= nil then
|
||||||
local unit = self.units[pkt.unit_id] ---@type unit_session
|
local unit = self.units[pkt.unit_id] ---@type unit_session
|
||||||
---@diagnostic disable-next-line: param-type-mismatch
|
|
||||||
unit.handle_packet(pkt)
|
unit.handle_packet(pkt)
|
||||||
end
|
end
|
||||||
elseif pkt.scada_frame.protocol() == PROTOCOL.SCADA_MGMT then
|
elseif pkt.scada_frame.protocol() == PROTOCOL.SCADA_MGMT then
|
||||||
|
---@cast pkt mgmt_frame
|
||||||
-- handle management packet
|
-- handle management packet
|
||||||
if pkt.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
if pkt.type == SCADA_MGMT_TYPE.KEEP_ALIVE then
|
||||||
-- keep alive reply
|
-- keep alive reply
|
||||||
|
@ -123,7 +123,7 @@ local function _iterate(sessions)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- cleanly close a session
|
-- cleanly close a session
|
||||||
---@param session plc_session_struct|rtu_session_struct
|
---@param session plc_session_struct|rtu_session_struct|coord_session_struct
|
||||||
local function _shutdown(session)
|
local function _shutdown(session)
|
||||||
session.open = false
|
session.open = false
|
||||||
session.instance.close()
|
session.instance.close()
|
||||||
@ -143,10 +143,8 @@ end
|
|||||||
---@param sessions table
|
---@param sessions table
|
||||||
local function _close(sessions)
|
local function _close(sessions)
|
||||||
for i = 1, #sessions do
|
for i = 1, #sessions do
|
||||||
local session = sessions[i] ---@type plc_session_struct|rtu_session_struct
|
local session = sessions[i] ---@type plc_session_struct|rtu_session_struct|coord_session_struct
|
||||||
if session.open then
|
if session.open then _shutdown(session) end
|
||||||
_shutdown(session)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -155,7 +153,7 @@ end
|
|||||||
---@param timer_event number
|
---@param timer_event number
|
||||||
local function _check_watchdogs(sessions, timer_event)
|
local function _check_watchdogs(sessions, timer_event)
|
||||||
for i = 1, #sessions do
|
for i = 1, #sessions do
|
||||||
local session = sessions[i] ---@type plc_session_struct|rtu_session_struct
|
local session = sessions[i] ---@type plc_session_struct|rtu_session_struct|coord_session_struct
|
||||||
if session.open then
|
if session.open then
|
||||||
local triggered = session.instance.check_wd(timer_event)
|
local triggered = session.instance.check_wd(timer_event)
|
||||||
if triggered then
|
if triggered then
|
||||||
@ -172,6 +170,7 @@ end
|
|||||||
local function _free_closed(sessions)
|
local function _free_closed(sessions)
|
||||||
local f = function (session) return session.open end
|
local f = function (session) return session.open end
|
||||||
|
|
||||||
|
---@param session plc_session_struct|rtu_session_struct|coord_session_struct
|
||||||
local on_delete = function (session)
|
local on_delete = function (session)
|
||||||
log.debug(util.c("free'ing closed ", session.s_type, " session ", session.instance.get_id(),
|
log.debug(util.c("free'ing closed ", session.s_type, " session ", session.instance.get_id(),
|
||||||
" on remote port ", session.r_port))
|
" on remote port ", session.r_port))
|
||||||
|
@ -9,12 +9,12 @@ local log = require("scada-common.log")
|
|||||||
local ppm = require("scada-common.ppm")
|
local ppm = require("scada-common.ppm")
|
||||||
local util = require("scada-common.util")
|
local util = require("scada-common.util")
|
||||||
|
|
||||||
local svsessions = require("supervisor.session.svsessions")
|
|
||||||
|
|
||||||
local config = require("supervisor.config")
|
local config = require("supervisor.config")
|
||||||
local supervisor = require("supervisor.supervisor")
|
local supervisor = require("supervisor.supervisor")
|
||||||
|
|
||||||
local SUPERVISOR_VERSION = "v0.14.4"
|
local svsessions = require("supervisor.session.svsessions")
|
||||||
|
|
||||||
|
local SUPERVISOR_VERSION = "v0.14.5"
|
||||||
|
|
||||||
local println = util.println
|
local println = util.println
|
||||||
local println_ts = util.println_ts
|
local println_ts = util.println_ts
|
||||||
|
@ -22,6 +22,7 @@ local println = util.println
|
|||||||
---@param dev_listen integer listening port for PLC/RTU devices
|
---@param dev_listen integer listening port for PLC/RTU devices
|
||||||
---@param coord_listen integer listening port for coordinator
|
---@param coord_listen integer listening port for coordinator
|
||||||
---@param range integer trusted device connection range
|
---@param range integer trusted device connection range
|
||||||
|
---@diagnostic disable-next-line: unused-local
|
||||||
function supervisor.comms(version, num_reactors, cooling_conf, modem, dev_listen, coord_listen, range)
|
function supervisor.comms(version, num_reactors, cooling_conf, modem, dev_listen, coord_listen, range)
|
||||||
local self = {
|
local self = {
|
||||||
last_est_acks = {}
|
last_est_acks = {}
|
||||||
|
Reference in New Issue
Block a user