#99 updating/sending builds
This commit is contained in:
@@ -19,6 +19,16 @@ local println_ts = util.println_ts
|
||||
local INITIAL_WAIT = 1500
|
||||
local RETRY_PERIOD = 1000
|
||||
|
||||
local CRD_S_CMDS = {
|
||||
RESEND_BUILDS = 1
|
||||
}
|
||||
|
||||
local CRD_S_DATA = {
|
||||
}
|
||||
|
||||
coordinator.CRD_S_CMDS = CRD_S_CMDS
|
||||
coordinator.CRD_S_DATA = CRD_S_DATA
|
||||
|
||||
local PERIODICS = {
|
||||
KEEP_ALIVE = 2000,
|
||||
STATUS = 500
|
||||
@@ -51,11 +61,11 @@ function coordinator.new_session(id, in_queue, out_queue, facility_units)
|
||||
},
|
||||
-- when to next retry one of these messages
|
||||
retry_times = {
|
||||
builds_packet = (util.time() + 500)
|
||||
builds_packet = 0
|
||||
},
|
||||
-- message acknowledgements
|
||||
acks = {
|
||||
builds = true
|
||||
builds = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,6 +237,13 @@ function coordinator.new_session(id, in_queue, out_queue, facility_units)
|
||||
_handle_packet(message.message)
|
||||
elseif message.qtype == mqueue.TYPE.COMMAND then
|
||||
-- handle instruction
|
||||
local cmd = message.message
|
||||
if cmd == CRD_S_CMDS.RESEND_BUILDS then
|
||||
-- re-send builds
|
||||
self.acks.builds = false
|
||||
self.retry_times.builds_packet = util.time() + RETRY_PERIOD
|
||||
_send_builds()
|
||||
end
|
||||
elseif message.qtype == mqueue.TYPE.DATA then
|
||||
-- instruction with body
|
||||
end
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
local comms = require("scada-common.comms")
|
||||
local log = require("scada-common.log")
|
||||
local mqueue = require("scada-common.mqueue")
|
||||
local util = require("scada-common.util")
|
||||
local comms = require("scada-common.comms")
|
||||
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 plc = {}
|
||||
|
||||
@@ -19,9 +21,9 @@ local INITIAL_WAIT = 1500
|
||||
local RETRY_PERIOD = 1000
|
||||
|
||||
local PLC_S_CMDS = {
|
||||
SCRAM = 0,
|
||||
ENABLE = 1,
|
||||
RPS_RESET = 2
|
||||
SCRAM = 1,
|
||||
ENABLE = 2,
|
||||
RPS_RESET = 3
|
||||
}
|
||||
|
||||
local PLC_S_DATA = {
|
||||
@@ -193,7 +195,7 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
|
||||
if self.received_struct then
|
||||
self.sDB.mek_status.fuel_need = self.sDB.mek_struct.fuel_cap - self.sDB.mek_status.fuel_fill
|
||||
self.sDB.mek_status.waste_need = self.sDB.mek_struct.waste_cap - self.sDB.mek_status.waste_fill
|
||||
self.sDB.mek_status.cool_need = self.sDB.mek_struct.ccool_cap - self.sDB.mek_status.ccool_fill
|
||||
self.sDB.mek_status.cool_need = self.sDB.mek_struct.ccool_cap - self.sDB.mek_status.ccool_fill
|
||||
self.sDB.mek_status.hcool_need = self.sDB.mek_struct.hcool_cap - self.sDB.mek_status.hcool_fill
|
||||
end
|
||||
end
|
||||
@@ -318,6 +320,7 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
|
||||
if status then
|
||||
-- copied in structure data OK
|
||||
self.received_struct = true
|
||||
self.out_q.push_command(svqtypes.SV_Q_CMDS.BUILD_CHANGED)
|
||||
else
|
||||
-- error copying structure data
|
||||
log.error(log_header .. "failed to parse struct packet data")
|
||||
|
||||
@@ -4,6 +4,8 @@ local mqueue = require("scada-common.mqueue")
|
||||
local rsio = require("scada-common.rsio")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local svqtypes = require("supervisor.session.svqtypes")
|
||||
|
||||
-- supervisor rtu sessions (svrs)
|
||||
local svrs_boilerv = require("supervisor.session.rtu.boilerv")
|
||||
local svrs_envd = require("supervisor.session.rtu.envd")
|
||||
@@ -192,6 +194,9 @@ function rtu.new_session(id, in_queue, out_queue, advertisement, facility_units)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- report build changed
|
||||
self.out_q.push_command(svqtypes.SV_Q_CMDS.BUILD_CHANGED)
|
||||
end
|
||||
|
||||
-- mark this RTU session as closed, stop watchdog
|
||||
|
||||
@@ -60,8 +60,8 @@ function imatrix.new(session_id, unit_id, advert, out_queue)
|
||||
length = 0,
|
||||
width = 0,
|
||||
height = 0,
|
||||
min_pos = 0,
|
||||
max_pos = 0,
|
||||
min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
|
||||
max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
|
||||
max_energy = 0,
|
||||
transfer_cap = 0,
|
||||
cells = 0,
|
||||
|
||||
@@ -60,8 +60,8 @@ function sps.new(session_id, unit_id, advert, out_queue)
|
||||
length = 0,
|
||||
width = 0,
|
||||
height = 0,
|
||||
min_pos = 0,
|
||||
max_pos = 0,
|
||||
min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
|
||||
max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
|
||||
coils = 0,
|
||||
input_cap = 0,
|
||||
output_cap = 0,
|
||||
|
||||
13
supervisor/session/svqtypes.lua
Normal file
13
supervisor/session/svqtypes.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
local svqtypes = {}
|
||||
|
||||
local SV_Q_CMDS = {
|
||||
BUILD_CHANGED = 0
|
||||
}
|
||||
|
||||
local SV_Q_DATA = {
|
||||
}
|
||||
|
||||
svqtypes.SV_Q_CMDS = SV_Q_CMDS
|
||||
svqtypes.SV_Q_DATA = SV_Q_DATA
|
||||
|
||||
return svqtypes
|
||||
@@ -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
|
||||
|
||||
@@ -13,7 +13,7 @@ local svsessions = require("supervisor.session.svsessions")
|
||||
local config = require("supervisor.config")
|
||||
local supervisor = require("supervisor.supervisor")
|
||||
|
||||
local SUPERVISOR_VERSION = "beta-v0.5.15"
|
||||
local SUPERVISOR_VERSION = "beta-v0.6.0"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
|
||||
Reference in New Issue
Block a user