threaded RTU/PLC bugfixes

This commit is contained in:
Mikayla Fischler
2022-04-27 15:52:34 -04:00
parent 14377e7348
commit 67a93016c0
4 changed files with 39 additions and 14 deletions

View File

@@ -19,7 +19,7 @@ os.loadAPI("dev/boiler_rtu.lua")
os.loadAPI("dev/imatrix_rtu.lua")
os.loadAPI("dev/turbine_rtu.lua")
local RTU_VERSION = "alpha-v0.4.0"
local RTU_VERSION = "alpha-v0.4.1"
local print = util.print
local println = util.println
@@ -58,11 +58,12 @@ local __shared_memory = {
-- message queues
q = {
mq_comms = mqeueu.new()
mq_comms = mqueue.new()
}
}
local smem_dev = __shared_memory.rtu_dev
local smem_sys = __shared_memory.rtu_sys
-- get modem
if smem_dev.modem == nil then
@@ -71,7 +72,7 @@ if smem_dev.modem == nil then
return
end
local rtu_comms = rtu.rtu_comms(modem, config.LISTEN_PORT, config.SERVER_PORT)
smem_sys.rtu_comms = rtu.rtu_comms(smem_dev.modem, config.LISTEN_PORT, config.SERVER_PORT)
----------------------------------------
-- interpret config and init units

View File

@@ -15,6 +15,8 @@ local COMMS_CLOCK = 0.25 -- (4Hz, 5 ticks)
function thread__main(smem)
-- execute thread
local exec = function ()
log._debug("main thread start")
-- advertisement/heartbeat clock
local loop_clock = os.startTimer(MAIN_CLOCK)
@@ -22,6 +24,7 @@ function thread__main(smem)
local rtu_state = smem.rtu_state
local rtu_dev = smem.rtu_dev
local rtu_comms = smem.rtu_sys.rtu_comms
local units = smem.rtu_sys.units
-- event loop
while true do
@@ -102,6 +105,8 @@ end
function thread__comms(smem)
-- execute thread
local exec = function ()
log._debug("comms thread start")
-- load in from shared memory
local rtu_state = smem.rtu_state
local rtu_comms = smem.rtu_sys.rtu_comms
@@ -127,7 +132,7 @@ function thread__comms(smem)
rtu_comms.handle_packet(msg.message, units, rtu_state)
end
-- quick yield
-- quick yield if we are looping right back
if comms_queue.ready() then util.nop() end
end
@@ -139,9 +144,14 @@ function thread__comms(smem)
-- delay before next check
local sleep_for = COMMS_CLOCK - (util.time() - last_update)
if sleep_for > 0.05 then
last_update = util.time()
if sleep_for > 0 then
sleep(sleep_for)
else
sleep(0.05)
end
end
end
return { exec = exec }
end