From 5dfbe650c6deb2714a01a69fbda065dc827098eb Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Fri, 7 Oct 2022 11:28:56 -0400 Subject: [PATCH] #93 don't send out-of-range burn rates (won't get a good ack), fixed unit command packet ordering --- supervisor/session/coordinator.lua | 4 ++-- supervisor/session/plc.lua | 26 ++++++++++++++++---------- supervisor/startup.lua | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/supervisor/session/coordinator.lua b/supervisor/session/coordinator.lua index a4b2e2d..e3c80f7 100644 --- a/supervisor/session/coordinator.lua +++ b/supervisor/session/coordinator.lua @@ -182,8 +182,8 @@ function coordinator.new_session(id, in_queue, out_queue, facility_units) elseif pkt.type == SCADA_CRDN_TYPES.COMMAND_UNIT then if pkt.length >= 2 then -- get command and unit id - local cmd = pkt.data[1] - local uid = pkt.data[2] + local uid = pkt.data[1] + local cmd = pkt.data[2] -- continue if valid unit id if util.is_int(uid) and uid > 0 and uid <= #self.units then diff --git a/supervisor/session/plc.lua b/supervisor/session/plc.lua index 68898f3..4e7cdb5 100644 --- a/supervisor/session/plc.lua +++ b/supervisor/session/plc.lua @@ -519,18 +519,24 @@ function plc.new_session(id, for_reactor, in_queue, out_queue) local cmd = message.message ---@type queue_data if cmd.key == PLC_S_DATA.BURN_RATE then -- update burn rate - self.commanded_burn_rate = cmd.val - self.ramping_rate = false - self.acks.burn_rate = false - self.retry_times.burn_rate_req = util.time() + INITIAL_WAIT - _send(RPLC_TYPES.MEK_BURN_RATE, { self.commanded_burn_rate, self.ramping_rate }) + cmd.val = math.floor(cmd.val * 10) / 10 -- round to 10ths place + if cmd.val > 0 and cmd.val <= self.sDB.mek_struct.max_burn then + self.commanded_burn_rate = cmd.val + self.ramping_rate = false + self.acks.burn_rate = false + self.retry_times.burn_rate_req = util.time() + INITIAL_WAIT + _send(RPLC_TYPES.MEK_BURN_RATE, { self.commanded_burn_rate, self.ramping_rate }) + end elseif cmd.key == PLC_S_DATA.RAMP_BURN_RATE then -- ramp to burn rate - self.commanded_burn_rate = cmd.val - self.ramping_rate = true - self.acks.burn_rate = false - self.retry_times.burn_rate_req = util.time() + INITIAL_WAIT - _send(RPLC_TYPES.MEK_BURN_RATE, { self.commanded_burn_rate, self.ramping_rate }) + cmd.val = math.floor(cmd.val * 10) / 10 -- round to 10ths place + if cmd.val > 0 and cmd.val <= self.sDB.mek_struct.max_burn then + self.commanded_burn_rate = cmd.val + self.ramping_rate = true + self.acks.burn_rate = false + self.retry_times.burn_rate_req = util.time() + INITIAL_WAIT + _send(RPLC_TYPES.MEK_BURN_RATE, { self.commanded_burn_rate, self.ramping_rate }) + end end end end diff --git a/supervisor/startup.lua b/supervisor/startup.lua index d2ad774..69cb1fe 100644 --- a/supervisor/startup.lua +++ b/supervisor/startup.lua @@ -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.6.1" +local SUPERVISOR_VERSION = "beta-v0.6.2" local print = util.print local println = util.println