code cleanup, type hints, bugfixes, and #98 removal of support for mek 10.0 RTU peripherals
This commit is contained in:
@@ -21,6 +21,7 @@ local SCADA_CRDN_TYPES = comms.SCADA_CRDN_TYPES
|
||||
|
||||
-- request the user to select a monitor
|
||||
---@param names table available monitors
|
||||
---@return boolean|string|nil
|
||||
local function ask_monitor(names)
|
||||
println("available monitors:")
|
||||
for i = 1, #names do
|
||||
@@ -71,7 +72,7 @@ function coordinator.configure_monitors(num_units)
|
||||
-- PRIMARY DISPLAY --
|
||||
---------------------
|
||||
|
||||
local iface_primary_display = settings.get("PRIMARY_DISPLAY")
|
||||
local iface_primary_display = settings.get("PRIMARY_DISPLAY") ---@type boolean|string|nil
|
||||
|
||||
if not util.table_contains(names, iface_primary_display) then
|
||||
println("primary display is not connected")
|
||||
@@ -85,7 +86,7 @@ function coordinator.configure_monitors(num_units)
|
||||
iface_primary_display = ask_monitor(names)
|
||||
end
|
||||
|
||||
if iface_primary_display == false then return false end
|
||||
if type(iface_primary_display) ~= "string" then return false end
|
||||
|
||||
settings.set("PRIMARY_DISPLAY", iface_primary_display)
|
||||
util.filter_table(names, function (x) return x ~= iface_primary_display end)
|
||||
@@ -175,7 +176,10 @@ function coordinator.log_comms(message) log_dmesg(message, "COMMS") end
|
||||
|
||||
---@param message string
|
||||
---@return function update, function done
|
||||
function coordinator.log_comms_connecting(message) return log_dmesg(message, "COMMS", true) end
|
||||
function coordinator.log_comms_connecting(message)
|
||||
---@diagnostic disable-next-line: return-type-mismatch
|
||||
return log_dmesg(message, "COMMS", true)
|
||||
end
|
||||
|
||||
-- coordinator communications
|
||||
---@param version string
|
||||
@@ -306,6 +310,14 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
|
||||
return self.sv_linked
|
||||
end
|
||||
|
||||
-- send a unit command
|
||||
---@param unit integer unit ID
|
||||
---@param cmd CRDN_COMMANDS command
|
||||
---@param option any? optional options (like burn rate)
|
||||
function public.send_command(unit, cmd, option)
|
||||
_send_sv(PROTOCOLS.SCADA_CRDN, SCADA_CRDN_TYPES.COMMAND_UNIT, { unit, cmd, option })
|
||||
end
|
||||
|
||||
-- parse a packet
|
||||
---@param side string
|
||||
---@param sender integer
|
||||
@@ -348,12 +360,13 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
|
||||
end
|
||||
|
||||
-- handle a packet
|
||||
---@param packet mgmt_frame|crdn_frame|capi_frame
|
||||
---@param packet mgmt_frame|crdn_frame|capi_frame|nil
|
||||
function public.handle_packet(packet)
|
||||
if packet ~= nil then
|
||||
local protocol = packet.scada_frame.protocol()
|
||||
|
||||
if protocol == PROTOCOLS.COORD_API then
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
apisessions.handle_packet(packet)
|
||||
else
|
||||
-- check sequence number
|
||||
@@ -389,7 +402,7 @@ function coordinator.comms(version, modem, sv_port, sv_listen, api_listen, sv_wa
|
||||
end
|
||||
|
||||
-- init io controller
|
||||
iocontrol.init(conf)
|
||||
iocontrol.init(conf, public)
|
||||
|
||||
self.sv_linked = true
|
||||
else
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
local psil = require("scada-common.psil")
|
||||
local log = require("scada-common.log")
|
||||
local comms = require("scada-common.comms")
|
||||
local log = require("scada-common.log")
|
||||
local psil = require("scada-common.psil")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local CRDN_COMMANDS = comms.CRDN_COMMANDS
|
||||
|
||||
local iocontrol = {}
|
||||
|
||||
@@ -8,7 +12,8 @@ local io = {}
|
||||
|
||||
-- initialize the coordinator IO controller
|
||||
---@param conf facility_conf configuration
|
||||
function iocontrol.init(conf)
|
||||
---@param comms coord_comms comms reference
|
||||
function iocontrol.init(conf, comms)
|
||||
io.facility = {
|
||||
scram = false,
|
||||
num_units = conf.num_units,
|
||||
@@ -29,10 +34,20 @@ function iocontrol.init(conf)
|
||||
burn_rate_cmd = 0.0,
|
||||
waste_control = 0,
|
||||
|
||||
---@fixme debug stubs to be linked into comms later?
|
||||
start = function () print("UNIT " .. i .. ": start") end,
|
||||
scram = function () print("UNIT " .. i .. ": SCRAM") end,
|
||||
set_burn = function (rate) print("UNIT " .. i .. ": set burn rate to " .. rate) end,
|
||||
start = function ()
|
||||
comms.send_command(i, CRDN_COMMANDS.START)
|
||||
log.debug(util.c("sent unit ", i, ": START"))
|
||||
end,
|
||||
|
||||
scram = function ()
|
||||
comms.send_command(i, CRDN_COMMANDS.SCRAM)
|
||||
log.debug(util.c("sent unit ", i, ": SCRAM"))
|
||||
end,
|
||||
|
||||
set_burn = function (rate)
|
||||
comms.send_command(i, CRDN_COMMANDS.SET_BURN, rate)
|
||||
log.debug(util.c("sent unit ", i, ": SET_BURN = ", rate))
|
||||
end,
|
||||
|
||||
reactor_ps = psil.create(),
|
||||
reactor_data = {}, ---@type reactor_db
|
||||
@@ -45,13 +60,13 @@ function iocontrol.init(conf)
|
||||
}
|
||||
|
||||
for _ = 1, conf.defs[(i * 2) - 1] do
|
||||
local data = {} ---@type boiler_session_db|boilerv_session_db
|
||||
local data = {} ---@type boilerv_session_db
|
||||
table.insert(entry.boiler_ps_tbl, psil.create())
|
||||
table.insert(entry.boiler_data_tbl, data)
|
||||
end
|
||||
|
||||
for _ = 1, conf.defs[i * 2] do
|
||||
local data = {} ---@type turbine_session_db|turbinev_session_db
|
||||
local data = {} ---@type turbinev_session_db
|
||||
table.insert(entry.turbine_ps_tbl, psil.create())
|
||||
table.insert(entry.turbine_data_tbl, data)
|
||||
end
|
||||
@@ -225,7 +240,7 @@ function iocontrol.update_statuses(statuses)
|
||||
unit.boiler_data_tbl[id].state = boiler[1] ---@type table
|
||||
unit.boiler_data_tbl[id].tanks = boiler[2] ---@type table
|
||||
|
||||
local data = unit.boiler_data_tbl[id] ---@type boiler_session_db|boilerv_session_db
|
||||
local data = unit.boiler_data_tbl[id] ---@type boilerv_session_db
|
||||
|
||||
if data.state.boil_rate > 0 then
|
||||
unit.boiler_ps_tbl[id].publish("computed_status", 3) -- active
|
||||
@@ -255,7 +270,7 @@ function iocontrol.update_statuses(statuses)
|
||||
unit.turbine_data_tbl[id].state = turbine[1] ---@type table
|
||||
unit.turbine_data_tbl[id].tanks = turbine[2] ---@type table
|
||||
|
||||
local data = unit.turbine_data_tbl[id] ---@type turbine_session_db|turbinev_session_db
|
||||
local data = unit.turbine_data_tbl[id] ---@type turbinev_session_db
|
||||
|
||||
if data.tanks.steam_fill >= 0.99 then
|
||||
unit.turbine_ps_tbl[id].publish("computed_status", 4) -- trip
|
||||
|
||||
@@ -16,7 +16,7 @@ local config = require("coordinator.config")
|
||||
local coordinator = require("coordinator.coordinator")
|
||||
local renderer = require("coordinator.renderer")
|
||||
|
||||
local COORDINATOR_VERSION = "alpha-v0.4.12"
|
||||
local COORDINATOR_VERSION = "alpha-v0.4.13"
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
@@ -66,7 +66,7 @@ ppm.mount_all()
|
||||
|
||||
-- setup monitors
|
||||
local configured, monitors = coordinator.configure_monitors(config.NUM_UNITS)
|
||||
if not configured then
|
||||
if not configured or monitors == nil then
|
||||
println("boot> monitor setup failed")
|
||||
log.fatal("monitor configuration failed")
|
||||
return
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local completion = require("cc.completion")
|
||||
|
||||
local util = require("scada-common.util")
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local print = util.print
|
||||
local println = util.println
|
||||
@@ -9,6 +9,10 @@ local println_ts = util.println_ts
|
||||
|
||||
local dialog = {}
|
||||
|
||||
-- ask the user yes or no
|
||||
---@param question string
|
||||
---@param default boolean
|
||||
---@return boolean|nil
|
||||
function dialog.ask_y_n(question, default)
|
||||
print(question)
|
||||
|
||||
@@ -31,6 +35,10 @@ function dialog.ask_y_n(question, default)
|
||||
end
|
||||
end
|
||||
|
||||
-- ask the user for an input within a set of options
|
||||
---@param options table
|
||||
---@param cancel string
|
||||
---@return boolean|string|nil
|
||||
function dialog.ask_options(options, cancel)
|
||||
print("> ")
|
||||
local response = read(nil, nil, function(text) return completion.choice(text, options) end)
|
||||
|
||||
Reference in New Issue
Block a user