diff --git a/rtu/rtu.lua b/rtu/rtu.lua index de96c66..d02bc6c 100644 --- a/rtu/rtu.lua +++ b/rtu/rtu.lua @@ -336,30 +336,36 @@ rtu.comms = function (modem, local_port, server_port, conn_watchdog) -- handle MODBUS instruction if packet.unit_id <= #units then local unit = units[packet.unit_id] ---@type rtu_unit_registry_entry + local unit_dbg_tag = " (unit " .. packet.unit_id .. ")" + if unit.name == "redstone_io" then -- immediately execute redstone RTU requests return_code, reply = unit.modbus_io.handle_packet(packet) if not return_code then - log.warning("requested MODBUS operation failed") + log.warning("requested MODBUS operation failed" .. unit_dbg_tag) end else -- check validity then pass off to unit comms thread return_code, reply = unit.modbus_io.check_request(packet) if return_code then - -- check if an operation is already in progress for this unit - if unit.modbus_busy then + -- check if there are more than 3 active transactions + -- still queue the packet, but this may indicate a problem + if unit.pkt_queue.length() > 3 then reply = unit.modbus_io.reply__srv_device_busy(packet) - else - unit.pkt_queue.push_packet(packet) + log.debug("queueing new request with " .. unit.pkt_queue.length() .. + " transactions already in the queue" .. unit_dbg_tag) end + + -- always queue the command even if busy + unit.pkt_queue.push_packet(packet) else - log.warning("cannot perform requested MODBUS operation") + log.warning("cannot perform requested MODBUS operation" .. unit_dbg_tag) end end else -- unit ID out of range? reply = modbus.reply__gw_unavailable(packet) - log.error("MODBUS packet requesting non-existent unit") + log.error("received MODBUS packet for non-existent unit") end public.send_modbus(reply) diff --git a/rtu/startup.lua b/rtu/startup.lua index 654f7a4..8293d39 100644 --- a/rtu/startup.lua +++ b/rtu/startup.lua @@ -24,7 +24,7 @@ local imatrix_rtu = require("rtu.dev.imatrix_rtu") local turbine_rtu = require("rtu.dev.turbine_rtu") local turbinev_rtu = require("rtu.dev.turbinev_rtu") -local RTU_VERSION = "alpha-v0.6.5" +local RTU_VERSION = "alpha-v0.6.6" local rtu_t = types.rtu_t @@ -154,7 +154,6 @@ for entry_idx = 1, #rtu_redstone do device = capabilities, -- use device field for redstone channels rtu = rs_rtu, modbus_io = modbus.new(rs_rtu, false), - modbus_busy = false, pkt_queue = nil, thread = nil } @@ -218,7 +217,6 @@ for i = 1, #rtu_devices do device = device, rtu = rtu_iface, modbus_io = modbus.new(rtu_iface, true), - modbus_busy = false, pkt_queue = mqueue.new(), thread = nil } diff --git a/rtu/threads.lua b/rtu/threads.lua index 617f3d2..a3d19d7 100644 --- a/rtu/threads.lua +++ b/rtu/threads.lua @@ -236,10 +236,8 @@ threads.thread__unit_comms = function (smem, unit) -- received data elseif msg.qtype == mqueue.TYPE.PACKET then -- received a packet - unit.modbus_busy = true local _, reply = unit.modbus_io.handle_packet(msg.message) rtu_comms.send_modbus(reply) - unit.modbus_busy = false end end