diag: add verbose network listener logging to trace command delivery

Manager logs: listener start, every modem_message received, channel
match/mismatch, command acceptance count, handler result.
Client logs: every sendToMaster call with type and commandId.
This commit is contained in:
MayaTheShy
2026-03-29 16:39:29 -04:00
parent 033da0933c
commit 9835556e6f
2 changed files with 18 additions and 1 deletions

View File

@@ -105,10 +105,14 @@ end
------------------------------------------------- -------------------------------------------------
local function sendToMaster(message) local function sendToMaster(message)
if not networkModem then return end if not networkModem then
log.warn("NET", "sendToMaster: no modem, dropping %s", tostring(message.type))
return
end
if not message.commandId then if not message.commandId then
message.commandId = newCommandId() message.commandId = newCommandId()
end end
log.info("NET", "TX -> ch %d: type=%s cmdId=%s", ORDER_CHANNEL, tostring(message.type), tostring(message.commandId))
networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message) networkModem.transmit(ORDER_CHANNEL, CLIENT_CHANNEL, message)
end end

View File

@@ -541,14 +541,23 @@ local function main()
-- Task 13: Network order/command listener -- Task 13: Network order/command listener
function() function()
if not ctx.networkModem then if not ctx.networkModem then
log.warn("NET", "No modem — listener disabled")
while true do sleep(3600) end while true do sleep(3600) end
end end
log.info("NET", "Listener started on channel %d (modem: %s)", cfg.ORDER_CHANNEL, ctx.networkModemName or "?")
local cmdCount = 0
while true do while true do
log.info("NET", "Waiting for modem_message... (handled %d so far)", cmdCount)
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
log.info("NET", "Got modem_message: side=%s ch=%d reply=%d type=%s",
tostring(side), channel or -1, replyChannel or -1,
type(message) == "table" and tostring(message.type) or type(message))
if channel == cfg.ORDER_CHANNEL and type(message) == "table" then if channel == cfg.ORDER_CHANNEL and type(message) == "table" then
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))
else else
cmdCount = cmdCount + 1
log.info("NET", "Command #%d accepted: type=%s cmdId=%s", cmdCount, tostring(message.type), tostring(message.commandId))
recordCommandId(message.commandId) recordCommandId(message.commandId)
cleanupCommandIds() cleanupCommandIds()
local handlerOk, handlerErr = pcall(function() local handlerOk, handlerErr = pcall(function()
@@ -794,8 +803,12 @@ local function main()
end) -- pcall handler end) -- pcall handler
if not handlerOk then if not handlerOk then
log.error("NET", "Handler error: %s", tostring(handlerErr)) log.error("NET", "Handler error: %s", tostring(handlerErr))
else
log.info("NET", "Command #%d handled OK", cmdCount)
end end
end -- idempotency else end -- idempotency else
else
log.info("NET", "Ignored: ch=%d (want %d) or not table", channel or -1, cfg.ORDER_CHANNEL)
end end
end end
end end