From 8ffbbb5ac9809927c53457bbe4837a84731bf726 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Fri, 6 Sep 2024 21:11:56 -0400 Subject: [PATCH] #498 supervisor block disallowed commands based on state, removed unused acks --- coordinator/coordinator.lua | 8 +------- supervisor/facility.lua | 12 ++++++++++-- supervisor/session/coordinator.lua | 24 ++++++++++++++++++------ supervisor/session/plc.lua | 7 ------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index 6e06fed..baca753 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -632,16 +632,10 @@ function coordinator.comms(version, nic, sv_watchdog) process.unit_ack(unit_id, cmd, ack) elseif cmd == UNIT_COMMAND.RESET_RPS then process.unit_ack(unit_id, cmd, ack) - elseif cmd == UNIT_COMMAND.SET_BURN then - -- this also doesn't exist - elseif cmd == UNIT_COMMAND.SET_WASTE then - -- updated by unit updates elseif cmd == UNIT_COMMAND.ACK_ALL_ALARMS then process.unit_ack(unit_id, cmd, ack) - elseif cmd == UNIT_COMMAND.SET_GROUP then - -- updated by unit updates else - log.debug(util.c("received unit command ack with unknown command ", cmd)) + log.debug(util.c("received unsupported unit command ack for command ", cmd)) end else log.debug(util.c("received unit command ack with unknown unit ", unit_id)) diff --git a/supervisor/facility.lua b/supervisor/facility.lua index 88486bc..9948023 100644 --- a/supervisor/facility.lua +++ b/supervisor/facility.lua @@ -73,8 +73,8 @@ function facility.new(config) burn_target = 0.1, -- burn rate target for aggregate burn mode charge_setpoint = 0, -- FE charge target setpoint gen_rate_setpoint = 0, -- FE/t charge rate target setpoint - group_map = {}, -- units -> group IDs - prio_defs = { {}, {}, {}, {} }, -- priority definitions (each level is a table of units) + group_map = {}, ---@type integer[] units -> group IDs + prio_defs = { {}, {}, {}, {} }, ---@type reactor_unit[][] priority definitions (each level is a table of units) at_max_burn = false, ascram = false, ascram_reason = AUTO_SCRAM.NONE, @@ -375,6 +375,9 @@ function facility.new(config) end end + -- check automatic control mode + function public.auto_is_active() return self.mode ~= PROCESS.INACTIVE end + -- stop auto control function public.auto_stop() self.mode = PROCESS.INACTIVE end @@ -469,6 +472,11 @@ function facility.new(config) end end + -- get the automatic control group of a unit + ---@param unit_id integer unit ID + ---@nodiscard + function public.get_group(unit_id) return self.group_map[unit_id] end + -- set waste production ---@param product WASTE_PRODUCT target product ---@return WASTE_PRODUCT product newly set value, if valid diff --git a/supervisor/session/coordinator.lua b/supervisor/session/coordinator.lua index 4d0dcd6..bd93c1c 100644 --- a/supervisor/session/coordinator.lua +++ b/supervisor/session/coordinator.lua @@ -241,8 +241,13 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim facility.scram_all() _send(CRDN_TYPE.FAC_CMD, { cmd, true }) elseif cmd == FAC_COMMAND.STOP then - facility.auto_stop() - _send(CRDN_TYPE.FAC_CMD, { cmd, true }) + local was_active = facility.auto_is_active() + + if was_active then + facility.auto_stop() + end + + _send(CRDN_TYPE.FAC_CMD, { cmd, was_active }) elseif cmd == FAC_COMMAND.START then if pkt.length == 6 then ---@type sys_auto_config @@ -299,17 +304,25 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim -- continue if valid unit id if util.is_int(uid) and uid > 0 and uid <= #self.units then - local unit = self.units[uid] ---@type reactor_unit + local unit = self.units[uid] ---@type reactor_unit + local manual = facility.get_group(uid) == 0 if cmd == UNIT_COMMAND.START then - out_queue.push_data(SV_Q_DATA.START, data) + if manual then + out_queue.push_data(SV_Q_DATA.START, data) + else + -- denied + _send(CRDN_TYPE.UNIT_CMD, { cmd, uid, false }) + end elseif cmd == UNIT_COMMAND.SCRAM then out_queue.push_data(SV_Q_DATA.SCRAM, data) elseif cmd == UNIT_COMMAND.RESET_RPS then out_queue.push_data(SV_Q_DATA.RESET_RPS, data) elseif cmd == UNIT_COMMAND.SET_BURN then if pkt.length == 3 then - out_queue.push_data(SV_Q_DATA.SET_BURN, data) + if manual then + out_queue.push_data(SV_Q_DATA.SET_BURN, data) + end else log.debug(log_tag .. "CRDN unit command burn rate missing option") end @@ -337,7 +350,6 @@ function coordinator.new_session(id, s_addr, i_seq_num, in_queue, out_queue, tim elseif cmd == UNIT_COMMAND.SET_GROUP 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(CRDN_TYPE.UNIT_CMD, { cmd, uid, pkt.data[3] }) else log.debug(log_tag .. "CRDN unit command set group missing group id") end diff --git a/supervisor/session/plc.lua b/supervisor/session/plc.lua index f0394e0..8850a16 100644 --- a/supervisor/session/plc.lua +++ b/supervisor/session/plc.lua @@ -395,13 +395,6 @@ function plc.new_session(id, s_addr, i_seq_num, reactor_id, in_queue, out_queue, elseif ack == false then log.debug(log_tag .. "burn rate update failed!") end - - -- send acknowledgement to coordinator - out_queue.push_data(svqtypes.SV_Q_DATA.CRDN_ACK, { - unit = reactor_id, - cmd = UNIT_COMMAND.SET_BURN, - ack = ack - }) elseif pkt.type == RPLC_TYPE.RPS_ENABLE then -- enable acknowledgement local ack = _get_ack(pkt)