#99 updating/sending builds

This commit is contained in:
Mikayla Fischler
2022-10-02 21:17:13 -04:00
parent 1b553ad495
commit c02479b52e
15 changed files with 148 additions and 75 deletions

View File

@@ -2,6 +2,7 @@ local log = require("scada-common.log")
local mqueue = require("scada-common.mqueue")
local util = require("scada-common.util")
local svqtypes = require("supervisor.session.svqtypes")
local unit = require("supervisor.session.unit")
local coordinator = require("supervisor.session.coordinator")
@@ -10,6 +11,9 @@ local rtu = require("supervisor.session.rtu")
-- Supervisor Sessions Handler
local SV_Q_CMDS = svqtypes.SV_Q_CMDS
local CRD_S_CMDS = coordinator.CRD_S_CMDS
local svsessions = {}
local SESSION_TYPE = {
@@ -38,20 +42,30 @@ local self = {
---@param sessions table
local function _iterate(sessions)
for i = 1, #sessions do
local session = sessions[i] ---@type plc_session_struct|rtu_session_struct
if session.open then
local ok = session.instance.iterate()
if ok then
-- send packets in out queue
while session.out_queue.ready() do
local msg = session.out_queue.pop()
if msg ~= nil and msg.qtype == mqueue.TYPE.PACKET then
local session = sessions[i] ---@type plc_session_struct|rtu_session_struct|coord_session_struct
if session.open and session.instance.iterate() then
-- process output queues
while session.out_queue.ready() do
local msg = session.out_queue.pop()
if msg ~= nil then
if msg.qtype == mqueue.TYPE.PACKET then
-- packet to be sent
self.modem.transmit(session.r_port, session.l_port, msg.message.raw_sendable())
elseif msg.qtype == mqueue.TYPE.COMMAND then
-- notification
local cmd = msg.message
if cmd == SV_Q_CMDS.BUILD_CHANGED then
-- notify coordinator(s) that a build has changed
for j = 1, #self.coord_sessions do
local s = self.coord_sessions[j] ---@type coord_session_struct
s.in_queue.push_command(CRD_S_CMDS.RESEND_BUILDS)
end
end
end
end
else
session.open = false
end
else
session.open = false
end
end
end
@@ -104,7 +118,10 @@ end
---@param sessions table
local function _free_closed(sessions)
local f = function (session) return session.open end
local on_delete = function (session) log.debug("free'ing closed session " .. session.instance.get_id() .. " on remote port " .. session.r_port) end
local on_delete = function (session)
log.debug("free'ing closed session " .. session.instance.get_id() .. " on remote port " .. session.r_port)
end
util.filter_table(sessions, f, on_delete)
end