From 7f0f4234504fb94f2b6cbccf45b41ee7afc05d2c Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Wed, 27 Apr 2022 18:49:54 -0400 Subject: [PATCH] PLC bugfixes/optimizations, removed some debug prints --- reactor-plc/plc.lua | 38 +++++++++++++++++++++++++++----------- reactor-plc/startup.lua | 2 +- reactor-plc/threads.lua | 6 ------ rtu/threads.lua | 1 - 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/reactor-plc/plc.lua b/reactor-plc/plc.lua index da71998..361c174 100644 --- a/reactor-plc/plc.lua +++ b/reactor-plc/plc.lua @@ -230,6 +230,24 @@ function comms_init(id, modem, local_port, server_port, reactor, iss) -- variable reactor status information, excluding heating rate local _reactor_status = function () + local coolant = self.reactor.getCoolant() + local coolant_name = "" + local coolant_amnt = 0 + + local hcoolant = self.reactor.getHeatedCoolant() + local hcoolant_name = "" + local hcoolant_amnt = 0 + + if coolant ~= nil then + coolant_name = coolant.name + coolant_amnt = coolant.amount + end + + if hcoolant ~= nil then + hcoolant_name = hcoolant.name + hcoolant_amnt = hcoolant.amount + end + return { self.reactor.getStatus(), self.reactor.getBurnRate(), @@ -240,18 +258,14 @@ function comms_init(id, modem, local_port, server_port, reactor, iss) self.reactor.getEnvironmentalLoss(), self.reactor.getFuel(), - self.reactor.getFuelNeeded(), self.reactor.getFuelFilledPercentage(), self.reactor.getWaste(), - self.reactor.getWasteNeeded(), self.reactor.getWasteFilledPercentage(), - self.reactor.getCoolant()['name'], - self.reactor.getCoolant()['amount'], - self.reactor.getCoolantNeeded(), + coolant_name, + coolant_amnt, self.reactor.getCoolantFilledPercentage(), - self.reactor.getHeatedCoolant()['name'], - self.reactor.getHeatedCoolant()['amount'], - self.reactor.getHeatedCoolantNeeded(), + hcoolant_name, + hcoolant_amnt, self.reactor.getHeatedCoolantFilledPercentage() }, self.reactor.__p_is_faulted() end @@ -273,7 +287,7 @@ function comms_init(id, modem, local_port, server_port, reactor, iss) changed = true end - if changed then + if changed and not faulted then self.status_cache = status end @@ -419,10 +433,12 @@ function comms_init(id, modem, local_port, server_port, reactor, iss) if trip_time < 0 then log._warning("PLC KEEP_ALIVE trip time less than 0 (" .. trip_time .. ")") - elseif trip_time > 1000 then - log._warning("PLC KEEP_ALIVE trip time > 1s (" .. trip_time .. ")") + elseif trip_time > 1200 then + log._warning("PLC KEEP_ALIVE trip time > 1.2s (" .. trip_time .. ")") end + -- log._debug("RPLC RTT = ".. trip_time .. "ms") + _send_keep_alive_ack(timestamp) elseif packet.type == RPLC_TYPES.LINK_REQ then -- link request confirmation diff --git a/reactor-plc/startup.lua b/reactor-plc/startup.lua index 2ceb289..4709a9c 100644 --- a/reactor-plc/startup.lua +++ b/reactor-plc/startup.lua @@ -12,7 +12,7 @@ os.loadAPI("config.lua") os.loadAPI("plc.lua") os.loadAPI("threads.lua") -local R_PLC_VERSION = "alpha-v0.4.5" +local R_PLC_VERSION = "alpha-v0.4.6" local print = util.print local println = util.println diff --git a/reactor-plc/threads.lua b/reactor-plc/threads.lua index ed1d93b..5cc80bc 100644 --- a/reactor-plc/threads.lua +++ b/reactor-plc/threads.lua @@ -287,11 +287,6 @@ function thread__iss(smem) break end - -- debug - -- print(util.time() - last_update) - -- println("ms") - -- last_update = util.time() - -- delay before next check, only if >50ms since we did already yield local sleep_for = ISS_SLEEP - (util.time() - last_update) last_update = util.time() @@ -353,7 +348,6 @@ function thread__comms(smem) local sleep_for = COMMS_SLEEP - (util.time() - last_update) last_update = util.time() if sleep_for >= 50 then - println("sleep for " .. (sleep_for / 1000.0)) psleep(sleep_for / 1000.0) end end diff --git a/rtu/threads.lua b/rtu/threads.lua index c2c1cfe..d736ee1 100644 --- a/rtu/threads.lua +++ b/rtu/threads.lua @@ -148,7 +148,6 @@ function thread__comms(smem) local sleep_for = COMMS_SLEEP - (util.time() - last_update) last_update = util.time() if sleep_for >= 50 then - println("sleep for " .. (sleep_for / 1000.0)) psleep(sleep_for / 1000.0) end end