From b1998b61bcf8a4f090a8be5263966cad800ee9e1 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Mon, 25 Apr 2022 11:44:34 -0400 Subject: [PATCH] #32 parallel RTU execution of packet handler --- rtu/startup.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rtu/startup.lua b/rtu/startup.lua index 4534f18..ecb3f3d 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -17,13 +17,15 @@ os.loadAPI("dev/boiler_rtu.lua") os.loadAPI("dev/imatrix_rtu.lua") os.loadAPI("dev/turbine_rtu.lua") -local RTU_VERSION = "alpha-v0.2.4" +local RTU_VERSION = "alpha-v0.3.0" local print = util.print local println = util.println local print_ts = util.print_ts local println_ts = util.println_ts +local async_wait = util.async_wait + log._info("========================================") log._info("BOOTING rtu.startup " .. RTU_VERSION) log._info("========================================") @@ -218,6 +220,9 @@ while true do end end elseif event == "timer" and param1 == loop_clock then + -- start next clock timer + loop_clock = os.startTimer(2) + -- period tick, if we are linked send heartbeat, if not send advertisement if linked then rtu_comms.send_heartbeat() @@ -225,15 +230,12 @@ while true do -- advertise units rtu_comms.send_advertisement(units) end - - -- start next clock timer - loop_clock = os.startTimer(2) elseif event == "modem_message" then -- got a packet local link_ref = { linked = linked } local packet = rtu_comms.parse_packet(p1, p2, p3, p4, p5) - rtu_comms.handle_packet(packet, units, link_ref) + async_wait(function () rtu_comms.handle_packet(packet, units, link_ref) end) -- if linked, stop sending advertisements linked = link_ref.linked