code cleanup and bugfixes

This commit is contained in:
Mikayla Fischler
2022-05-10 12:01:56 -04:00
parent d7e38d6393
commit 168341db39
12 changed files with 48 additions and 27 deletions

View File

@@ -558,8 +558,10 @@ plc.comms = function (id, modem, local_port, server_port, reactor, rps, conn_wat
-- feed the watchdog first so it doesn't uhh...eat our packets :)
self.conn_watchdog.feed()
local protocol = packet.scada_frame.protocol()
-- handle packet
if packet.scada_frame.protocol() == PROTOCOLS.RPLC then
if protocol == PROTOCOLS.RPLC then
if self.linked then
if packet.type == RPLC_TYPES.LINK_REQ then
-- link request confirmation
@@ -678,7 +680,7 @@ plc.comms = function (id, modem, local_port, server_port, reactor, rps, conn_wat
else
log.debug("discarding non-link packet before linked")
end
elseif packet.scada_frame.protocol() == PROTOCOLS.SCADA_MGMT then
elseif protocol == PROTOCOLS.SCADA_MGMT then
if packet.type == SCADA_MGMT_TYPES.KEEP_ALIVE then
-- keep alive request received, echo back
if packet.length == 1 then

View File

@@ -11,7 +11,7 @@ local config = require("config")
local plc = require("plc")
local threads = require("threads")
local R_PLC_VERSION = "alpha-v0.6.5"
local R_PLC_VERSION = "alpha-v0.6.6"
local print = util.print
local println = util.println
@@ -46,7 +46,7 @@ local __shared_memory = {
burn_rate_en = false,
burn_rate = 0.0
},
-- core PLC devices
plc_dev = {
reactor = ppm.get_fission_reactor(),
@@ -82,7 +82,7 @@ if smem_dev.reactor == nil then
plc_state.degraded = true
plc_state.no_reactor = true
end
if networked and smem_dev.modem == nil then
if __shared_memory.networked and smem_dev.modem == nil then
println("boot> wireless modem not found")
log.warning("no wireless modem on startup")
@@ -95,7 +95,8 @@ if networked and smem_dev.modem == nil then
plc_state.no_modem = true
end
function init()
-- PLC init
local init = function ()
if plc_state.init_ok then
-- just booting up, no fission allowed (neutrons stay put thanks)
smem_dev.reactor.scram()
@@ -117,6 +118,7 @@ function init()
log.debug("init> running without networking")
end
---@diagnostic disable-next-line: undefined-field
os.queueEvent("clock_start")
println("boot> completed");
@@ -155,7 +157,7 @@ if __shared_memory.networked then
smem_sys.plc_comms.send_rps_status()
-- close connection
smem_sys.plc_comms.close(smem_sys.conn_watchdog)
smem_sys.plc_comms.close()
end
else
-- run threads, excluding comms

View File

@@ -51,6 +51,7 @@ threads.thread__main = function (smem, init)
-- event loop
while true do
---@diagnostic disable-next-line: undefined-field
local event, param1, param2, param3, param4, param5 = os.pullEventRaw()
-- handle event
@@ -443,7 +444,7 @@ threads.thread__setpoint_control = function (smem)
if running then
-- do not use the actual elapsed time, it could spike
-- we do not want to have big jumps as that is what we are trying to avoid in the first place
local min_elapsed_s = SETPOINT_CTRL_SLEEP / 1000.0
local min_elapsed_s = SP_CTRL_SLEEP / 1000.0
-- clear so we can later evaluate if we should keep running
running = false