#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

@ -86,41 +86,52 @@ function iocontrol.record_builds(builds)
log.error("number of provided unit builds does not match expected number of units") log.error("number of provided unit builds does not match expected number of units")
return false return false
else else
-- note: if not all units and RTUs are connected, some will be nil
for i = 1, #builds do for i = 1, #builds do
local unit = io.units[i] ---@type ioctl_entry local unit = io.units[i] ---@type ioctl_entry
local build = builds[i] local build = builds[i]
-- reactor build -- reactor build
unit.reactor_data.mek_struct = build.reactor if type(build.reactor) == "table" then
for key, val in pairs(unit.reactor_data.mek_struct) do unit.reactor_data.mek_struct = build.reactor
unit.reactor_ps.publish(key, val) for key, val in pairs(unit.reactor_data.mek_struct) do
unit.reactor_ps.publish(key, val)
end
if unit.reactor_data.mek_struct.length ~= 0 and unit.reactor_data.mek_struct.width ~= 0 then
unit.reactor_ps.publish("size", { unit.reactor_data.mek_struct.length, unit.reactor_data.mek_struct.width })
end
end end
-- boiler builds -- boiler builds
for id, boiler in pairs(build.boilers) do if type(build.boilers) == "table" then
unit.boiler_data_tbl[id] = { for id, boiler in pairs(build.boilers) do
formed = boiler[2], ---@type boolean|nil unit.boiler_data_tbl[id] = {
build = boiler[1] ---@type table formed = boiler[2], ---@type boolean|nil
} build = boiler[1] ---@type table
}
unit.boiler_ps_tbl[id].publish("formed", boiler[2]) unit.boiler_ps_tbl[id].publish("formed", boiler[2])
for key, val in pairs(unit.boiler_data_tbl[id].build) do for key, val in pairs(unit.boiler_data_tbl[id].build) do
unit.boiler_ps_tbl[id].publish(key, val) unit.boiler_ps_tbl[id].publish(key, val)
end
end end
end end
-- turbine builds -- turbine builds
for id, turbine in pairs(build.turbines) do if type(build.turbines) == "table" then
unit.turbine_data_tbl[id] = { for id, turbine in pairs(build.turbines) do
formed = turbine[2], ---@type boolean|nil unit.turbine_data_tbl[id] = {
build = turbine[1] ---@type table formed = turbine[2], ---@type boolean|nil
} build = turbine[1] ---@type table
}
unit.turbine_ps_tbl[id].publish("formed", turbine[2]) unit.turbine_ps_tbl[id].publish("formed", turbine[2])
for key, val in pairs(unit.turbine_data_tbl[id].build) do for key, val in pairs(unit.turbine_data_tbl[id].build) do
unit.turbine_ps_tbl[id].publish(key, val) unit.turbine_ps_tbl[id].publish(key, val)
end
end end
end end
end end

View File

@ -16,7 +16,7 @@ local config = require("coordinator.config")
local coordinator = require("coordinator.coordinator") local coordinator = require("coordinator.coordinator")
local renderer = require("coordinator.renderer") local renderer = require("coordinator.renderer")
local COORDINATOR_VERSION = "alpha-v0.4.15" local COORDINATOR_VERSION = "alpha-v0.5.0"
local print = util.print local print = util.print
local println = util.println local println = util.println

View File

@ -47,9 +47,9 @@ local function init(parent, id)
-- main stats and core map -- -- main stats and core map --
---@todo need to be checking actual reactor dimensions somehow
local core_map = CoreMap{parent=main,x=2,y=3,reactor_l=18,reactor_w=18} local core_map = CoreMap{parent=main,x=2,y=3,reactor_l=18,reactor_w=18}
r_ps.subscribe("temp", core_map.update) r_ps.subscribe("temp", core_map.update)
r_ps.subscribe("size", function (s) core_map.resize(s[1], s[2]) end)
local stat_fg_bg = cpair(colors.black,colors.white) local stat_fg_bg = cpair(colors.black,colors.white)

View File

@ -5,6 +5,8 @@ local tcd = require("scada-common.tcallbackdsp")
local core = require("graphics.core") local core = require("graphics.core")
local element = require("graphics.element") local element = require("graphics.element")
local accent = colors.yellow
---@class scram_button_args ---@class scram_button_args
---@field callback function function to call on touch ---@field callback function function to call on touch
---@field parent graphics_element ---@field parent graphics_element
@ -33,7 +35,7 @@ local function scram_button(args)
-- draw border -- draw border
-- top -- top
e.window.setTextColor(colors.yellow) e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg) e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 1) e.window.setCursorPos(1, 1)
e.window.write("\x99\x89\x89\x89\x89\x89\x89\x89\x99") e.window.write("\x99\x89\x89\x89\x89\x89\x89\x89\x99")
@ -41,17 +43,17 @@ local function scram_button(args)
-- center left -- center left
e.window.setCursorPos(1, 2) e.window.setCursorPos(1, 2)
e.window.setTextColor(args.fg_bg.bkg) e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(colors.yellow) e.window.setBackgroundColor(accent)
e.window.write("\x99") e.window.write("\x99")
-- center right -- center right
e.window.setTextColor(args.fg_bg.bkg) e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(colors.yellow) e.window.setBackgroundColor(accent)
e.window.setCursorPos(9, 2) e.window.setCursorPos(9, 2)
e.window.write("\x99") e.window.write("\x99")
-- bottom -- bottom
e.window.setTextColor(colors.yellow) e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg) e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 3) e.window.setCursorPos(1, 3)
e.window.write("\x99\x98\x98\x98\x98\x98\x98\x98\x99") e.window.write("\x99\x98\x98\x98\x98\x98\x98\x98\x99")

View File

@ -5,6 +5,8 @@ local tcd = require("scada-common.tcallbackdsp")
local core = require("graphics.core") local core = require("graphics.core")
local element = require("graphics.element") local element = require("graphics.element")
local accent = colors.lightBlue
---@class start_button_args ---@class start_button_args
---@field callback function function to call on touch ---@field callback function function to call on touch
---@field parent graphics_element ---@field parent graphics_element
@ -33,7 +35,7 @@ local function start_button(args)
-- draw border -- draw border
-- top -- top
e.window.setTextColor(colors.orange) e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg) e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 1) e.window.setCursorPos(1, 1)
e.window.write("\x99\x89\x89\x89\x89\x89\x89\x89\x99") e.window.write("\x99\x89\x89\x89\x89\x89\x89\x89\x99")
@ -41,17 +43,17 @@ local function start_button(args)
-- center left -- center left
e.window.setCursorPos(1, 2) e.window.setCursorPos(1, 2)
e.window.setTextColor(args.fg_bg.bkg) e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(colors.orange) e.window.setBackgroundColor(accent)
e.window.write("\x99") e.window.write("\x99")
-- center right -- center right
e.window.setTextColor(args.fg_bg.bkg) e.window.setTextColor(args.fg_bg.bkg)
e.window.setBackgroundColor(colors.orange) e.window.setBackgroundColor(accent)
e.window.setCursorPos(9, 2) e.window.setCursorPos(9, 2)
e.window.write("\x99") e.window.write("\x99")
-- bottom -- bottom
e.window.setTextColor(colors.orange) e.window.setTextColor(accent)
e.window.setBackgroundColor(args.fg_bg.bkg) e.window.setBackgroundColor(args.fg_bg.bkg)
e.window.setCursorPos(1, 3) e.window.setCursorPos(1, 3)
e.window.write("\x99\x98\x98\x98\x98\x98\x98\x98\x99") e.window.write("\x99\x98\x98\x98\x98\x98\x98\x98\x99")

View File

@ -115,6 +115,9 @@ local function core_map(args)
if inner_width % 2 == 0 then alternator = not alternator end if inner_width % 2 == 0 then alternator = not alternator end
end end
-- reset alternator
alternator = true
end end
-- on state change -- on state change

View File

@ -27,26 +27,26 @@ config.RTU_DEVICES = {
} }
-- RTU redstone interface definitions -- RTU redstone interface definitions
config.RTU_REDSTONE = { config.RTU_REDSTONE = {
{ -- {
for_reactor = 1, -- for_reactor = 1,
io = { -- io = {
{ -- {
channel = rsio.IO.WASTE_PO, -- channel = rsio.IO.WASTE_PO,
side = "top", -- side = "top",
bundled_color = colors.blue -- bundled_color = colors.blue
}, -- },
{ -- {
channel = rsio.IO.WASTE_PU, -- channel = rsio.IO.WASTE_PU,
side = "top", -- side = "top",
bundled_color = colors.cyan -- bundled_color = colors.cyan
}, -- },
{ -- {
channel = rsio.IO.WASTE_AM, -- channel = rsio.IO.WASTE_AM,
side = "top", -- side = "top",
bundled_color = colors.purple -- bundled_color = colors.purple
} -- }
} -- }
} -- }
} }
return config return config

View File

@ -19,6 +19,16 @@ local println_ts = util.println_ts
local INITIAL_WAIT = 1500 local INITIAL_WAIT = 1500
local RETRY_PERIOD = 1000 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 = { local PERIODICS = {
KEEP_ALIVE = 2000, KEEP_ALIVE = 2000,
STATUS = 500 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 -- when to next retry one of these messages
retry_times = { retry_times = {
builds_packet = (util.time() + 500) builds_packet = 0
}, },
-- message acknowledgements -- message acknowledgements
acks = { acks = {
builds = true builds = false
} }
} }
@ -227,6 +237,13 @@ function coordinator.new_session(id, in_queue, out_queue, facility_units)
_handle_packet(message.message) _handle_packet(message.message)
elseif message.qtype == mqueue.TYPE.COMMAND then elseif message.qtype == mqueue.TYPE.COMMAND then
-- handle instruction -- 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 elseif message.qtype == mqueue.TYPE.DATA then
-- instruction with body -- instruction with body
end end

View File

@ -1,7 +1,9 @@
local comms = require("scada-common.comms") local comms = require("scada-common.comms")
local log = require("scada-common.log") local log = require("scada-common.log")
local mqueue = require("scada-common.mqueue") local mqueue = require("scada-common.mqueue")
local util = require("scada-common.util") local util = require("scada-common.util")
local svqtypes = require("supervisor.session.svqtypes")
local plc = {} local plc = {}
@ -19,9 +21,9 @@ local INITIAL_WAIT = 1500
local RETRY_PERIOD = 1000 local RETRY_PERIOD = 1000
local PLC_S_CMDS = { local PLC_S_CMDS = {
SCRAM = 0, SCRAM = 1,
ENABLE = 1, ENABLE = 2,
RPS_RESET = 2 RPS_RESET = 3
} }
local PLC_S_DATA = { local PLC_S_DATA = {
@ -193,7 +195,7 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
if self.received_struct then 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.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.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 self.sDB.mek_status.hcool_need = self.sDB.mek_struct.hcool_cap - self.sDB.mek_status.hcool_fill
end end
end end
@ -318,6 +320,7 @@ function plc.new_session(id, for_reactor, in_queue, out_queue)
if status then if status then
-- copied in structure data OK -- copied in structure data OK
self.received_struct = true self.received_struct = true
self.out_q.push_command(svqtypes.SV_Q_CMDS.BUILD_CHANGED)
else else
-- error copying structure data -- error copying structure data
log.error(log_header .. "failed to parse struct packet data") log.error(log_header .. "failed to parse struct packet data")

View File

@ -4,6 +4,8 @@ local mqueue = require("scada-common.mqueue")
local rsio = require("scada-common.rsio") local rsio = require("scada-common.rsio")
local util = require("scada-common.util") local util = require("scada-common.util")
local svqtypes = require("supervisor.session.svqtypes")
-- supervisor rtu sessions (svrs) -- supervisor rtu sessions (svrs)
local svrs_boilerv = require("supervisor.session.rtu.boilerv") local svrs_boilerv = require("supervisor.session.rtu.boilerv")
local svrs_envd = require("supervisor.session.rtu.envd") 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 break
end end
end end
-- report build changed
self.out_q.push_command(svqtypes.SV_Q_CMDS.BUILD_CHANGED)
end end
-- mark this RTU session as closed, stop watchdog -- mark this RTU session as closed, stop watchdog

View File

@ -60,8 +60,8 @@ function imatrix.new(session_id, unit_id, advert, out_queue)
length = 0, length = 0,
width = 0, width = 0,
height = 0, height = 0,
min_pos = 0, min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
max_pos = 0, max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
max_energy = 0, max_energy = 0,
transfer_cap = 0, transfer_cap = 0,
cells = 0, cells = 0,

View File

@ -60,8 +60,8 @@ function sps.new(session_id, unit_id, advert, out_queue)
length = 0, length = 0,
width = 0, width = 0,
height = 0, height = 0,
min_pos = 0, min_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
max_pos = 0, max_pos = { x = 0, y = 0, z = 0 }, ---@type coordinate
coils = 0, coils = 0,
input_cap = 0, input_cap = 0,
output_cap = 0, output_cap = 0,

View 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

View File

@ -2,6 +2,7 @@ local log = require("scada-common.log")
local mqueue = require("scada-common.mqueue") local mqueue = require("scada-common.mqueue")
local util = require("scada-common.util") local util = require("scada-common.util")
local svqtypes = require("supervisor.session.svqtypes")
local unit = require("supervisor.session.unit") local unit = require("supervisor.session.unit")
local coordinator = require("supervisor.session.coordinator") local coordinator = require("supervisor.session.coordinator")
@ -10,6 +11,9 @@ local rtu = require("supervisor.session.rtu")
-- Supervisor Sessions Handler -- Supervisor Sessions Handler
local SV_Q_CMDS = svqtypes.SV_Q_CMDS
local CRD_S_CMDS = coordinator.CRD_S_CMDS
local svsessions = {} local svsessions = {}
local SESSION_TYPE = { local SESSION_TYPE = {
@ -38,20 +42,30 @@ local self = {
---@param sessions table ---@param sessions table
local function _iterate(sessions) local function _iterate(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 and session.instance.iterate() then
local ok = session.instance.iterate() -- process output queues
if ok then while session.out_queue.ready() do
-- send packets in out queue local msg = session.out_queue.pop()
while session.out_queue.ready() do if msg ~= nil then
local msg = session.out_queue.pop() if msg.qtype == mqueue.TYPE.PACKET then
if msg ~= nil and msg.qtype == mqueue.TYPE.PACKET then -- packet to be sent
self.modem.transmit(session.r_port, session.l_port, msg.message.raw_sendable()) 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
end end
else
session.open = false
end end
else
session.open = false
end end
end end
end end
@ -104,7 +118,10 @@ end
---@param sessions table ---@param sessions table
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
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) util.filter_table(sessions, f, on_delete)
end end

View File

@ -13,7 +13,7 @@ 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 = "beta-v0.5.15" local SUPERVISOR_VERSION = "beta-v0.6.0"
local print = util.print local print = util.print
local println = util.println local println = util.println