fix: replace sleep(0) with os.pullEvent() + add diagnostic logging
sleep(0) wakes the processor only on timer ticks, causing a 1-tick delay. os.pullEvent() with no filter wakes the processor on ANY event — including the modem_message that triggered the capture — so items are processed in the same event cycle. Added logging to capture and processor tasks: - NET-CAP: logs each queued message with type and queue depth - NET-PROC: logs each message being processed - Both log on startup to confirm they're running
This commit is contained in:
@@ -640,12 +640,15 @@ local function main()
|
|||||||
-- miss events while other tasks yield for "task_complete" etc.
|
-- miss events while other tasks yield for "task_complete" etc.
|
||||||
resilient("Network-capture", function()
|
resilient("Network-capture", function()
|
||||||
if not ctx.networkModem then
|
if not ctx.networkModem then
|
||||||
|
log.warn("NET-CAP", "No modem — capture task idle")
|
||||||
while true do sleep(3600) end
|
while true do sleep(3600) end
|
||||||
end
|
end
|
||||||
|
log.info("NET-CAP", "Capture task started, listening on ch %d", cfg.ORDER_CHANNEL)
|
||||||
while true do
|
while true do
|
||||||
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||||
if channel == cfg.ORDER_CHANNEL and type(message) == "table" then
|
if channel == cfg.ORDER_CHANNEL and type(message) == "table" then
|
||||||
table.insert(networkQueue, { replyChannel = replyChannel, message = message })
|
table.insert(networkQueue, { replyChannel = replyChannel, message = message })
|
||||||
|
log.info("NET-CAP", "Queued: type=%s queue=%d", tostring(message.type), #networkQueue)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end),
|
end),
|
||||||
@@ -653,16 +656,20 @@ local function main()
|
|||||||
-- Task 13b: Network message processor (drains queue — safe to yield)
|
-- Task 13b: Network message processor (drains queue — safe to yield)
|
||||||
resilient("Network-processor", function()
|
resilient("Network-processor", function()
|
||||||
if not ctx.networkModem then
|
if not ctx.networkModem then
|
||||||
|
log.warn("NET-PROC", "No modem — processor task idle")
|
||||||
while true do sleep(3600) end
|
while true do sleep(3600) end
|
||||||
end
|
end
|
||||||
|
log.info("NET-PROC", "Processor task started")
|
||||||
while true do
|
while true do
|
||||||
if #networkQueue == 0 then
|
if #networkQueue == 0 then
|
||||||
sleep(0)
|
os.pullEvent()
|
||||||
end
|
end
|
||||||
while #networkQueue > 0 do
|
while #networkQueue > 0 do
|
||||||
local entry = table.remove(networkQueue, 1)
|
local entry = table.remove(networkQueue, 1)
|
||||||
local message = entry.message
|
local message = entry.message
|
||||||
local replyChannel = entry.replyChannel
|
local replyChannel = entry.replyChannel
|
||||||
|
log.info("NET-PROC", "Processing: type=%s id=%s queue=%d",
|
||||||
|
tostring(message.type), tostring(message.commandId), #networkQueue)
|
||||||
|
|
||||||
if isCommandDuplicate(message.commandId) then
|
if isCommandDuplicate(message.commandId) then
|
||||||
log.debug("NET", "Duplicate command skipped: %s", tostring(message.commandId))
|
log.debug("NET", "Duplicate command skipped: %s", tostring(message.commandId))
|
||||||
|
|||||||
Reference in New Issue
Block a user