#150 save and automatically set priority groups, added checks to set waste and set group commands, restore waste mode control if operation failed

This commit is contained in:
Mikayla Fischler 2023-02-03 16:40:58 -05:00
parent 72791d042b
commit a117d5ee97
6 changed files with 36 additions and 7 deletions

View File

@ -292,6 +292,7 @@ function iocontrol.update_facility_status(status)
if (type(group_map) == "table") and (#group_map == fac.num_units) then
local names = { "Manual", "Primary", "Secondary", "Tertiary", "Backup" }
for i = 1, #group_map do
io.units[i].unit_ps.publish("auto_group_id", group_map[i] + 1)
io.units[i].unit_ps.publish("auto_group", names[group_map[i] + 1])
end
end

View File

@ -70,12 +70,22 @@ function process.init(iocontrol, comms)
local waste_mode = settings.get("WASTE_MODES") ---@type table|nil
if type(waste_mode) == "table" then
for id = 1, math.min(#waste_mode, self.io.facility.num_units) do
self.comms.send_unit_command(UNIT_COMMANDS.SET_WASTE, id, waste_mode[id])
for id, mode in pairs(waste_mode) do
self.comms.send_unit_command(UNIT_COMMANDS.SET_WASTE, id, mode)
end
log.info("PROCESS: loaded waste mode settings from coord.settings")
end
local prio_groups = settings.get("PRIORITY_GROUPS") ---@type table|nil
if type(prio_groups) == "table" then
for id, group in pairs(prio_groups) do
self.comms.send_unit_command(UNIT_COMMANDS.SET_GROUP, id, group)
end
log.info("PROCESS: loaded priority groups settings from coord.settings")
end
end
-- start reactor
@ -113,6 +123,9 @@ end
---@param id integer unit ID
---@param mode integer waste mode
function process.set_waste(id, mode)
-- publish so that if it fails then it gets reset
self.io.units[id].unit_ps.publish("U_WasteMode", mode)
self.comms.send_unit_command(UNIT_COMMANDS.SET_WASTE, id, mode)
log.debug(util.c("UNIT[", id, "]: SET WASTE = ", mode))
@ -160,6 +173,20 @@ end
function process.set_group(unit_id, group_id)
self.comms.send_unit_command(UNIT_COMMANDS.SET_GROUP, unit_id, group_id)
log.debug(util.c("UNIT[", unit_id, "]: SET GROUP ", group_id))
local prio_groups = settings.get("PRIORITY_GROUPS") ---@type table|nil
if type(prio_groups) ~= "table" then
prio_groups = {}
end
prio_groups[unit_id] = group_id
settings.set("PRIORITY_GROUPS", prio_groups)
if not settings.save("/coord.settings") then
log.error("process.set_group(): failed to save coordinator settings file")
end
end
--------------------------

View File

@ -19,7 +19,7 @@ local iocontrol = require("coordinator.iocontrol")
local renderer = require("coordinator.renderer")
local sounder = require("coordinator.sounder")
local COORDINATOR_VERSION = "beta-v0.8.14"
local COORDINATOR_VERSION = "beta-v0.8.15"
local print = util.print
local println = util.println

View File

@ -459,10 +459,11 @@ local function init(parent, id)
local group = RadioButton{parent=auto_div,options=ctl_opts,callback=function()end,radio_colors=cpair(colors.blue,colors.white),radio_bg=colors.gray}
u_ps.subscribe("auto_group_id", group.set_value)
auto_div.line_break()
local function set_group() unit.set_group(group.get_value() - 1) end
local set_grp_btn = PushButton{parent=auto_div,text="SET",x=4,min_width=5,fg_bg=cpair(colors.black,colors.yellow),active_fg_bg=cpair(colors.white,colors.gray),dis_fg_bg=cpair(colors.gray,colors.white),callback=set_group}
auto_div.line_break()

View File

@ -268,7 +268,7 @@ function coordinator.new_session(id, in_queue, out_queue, facility)
log.debug(log_header .. "CRDN unit command burn rate missing option")
end
elseif cmd == UNIT_COMMANDS.SET_WASTE then
if pkt.length == 3 then
if (pkt.length == 3) and (type(pkt.data[3]) == "number") and (pkt.data[3] > 0) and (pkt.data[3] <= 4) then
unit.set_waste(pkt.data[3])
else
log.debug(log_header .. "CRDN unit command set waste missing option")
@ -289,7 +289,7 @@ function coordinator.new_session(id, in_queue, out_queue, facility)
log.debug(log_header .. "CRDN unit command reset alarm missing alarm id")
end
elseif cmd == UNIT_COMMANDS.SET_GROUP then
if pkt.length == 3 then
if (pkt.length == 3) and (type(pkt.data[3]) == "number") and (pkt.data[3] >= 0) and (pkt.data[3] <= 4) then
facility.set_group(unit.get_id(), pkt.data[3])
_send(SCADA_CRDN_TYPES.UNIT_CMD, { cmd, uid, pkt.data[3] })
else

View File

@ -14,7 +14,7 @@ local svsessions = require("supervisor.session.svsessions")
local config = require("supervisor.config")
local supervisor = require("supervisor.supervisor")
local SUPERVISOR_VERSION = "beta-v0.9.9"
local SUPERVISOR_VERSION = "beta-v0.9.10"
local print = util.print
local println = util.println