diff --git a/inventoryClient.lua b/inventoryClient.lua index d954991..fb7fc8c 100644 --- a/inventoryClient.lua +++ b/inventoryClient.lua @@ -105,10 +105,14 @@ end ------------------------------------------------- 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 message.commandId = newCommandId() 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) end diff --git a/inventoryManager.lua b/inventoryManager.lua index 2a0bd52..e33cd80 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -541,14 +541,23 @@ local function main() -- Task 13: Network order/command listener function() if not ctx.networkModem then + log.warn("NET", "No modem — listener disabled") while true do sleep(3600) end end + log.info("NET", "Listener started on channel %d (modem: %s)", cfg.ORDER_CHANNEL, ctx.networkModemName or "?") + local cmdCount = 0 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") + 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 isCommandDuplicate(message.commandId) then log.debug("NET", "Duplicate command skipped: %s", tostring(message.commandId)) else + cmdCount = cmdCount + 1 + log.info("NET", "Command #%d accepted: type=%s cmdId=%s", cmdCount, tostring(message.type), tostring(message.commandId)) recordCommandId(message.commandId) cleanupCommandIds() local handlerOk, handlerErr = pcall(function() @@ -794,8 +803,12 @@ local function main() end) -- pcall handler if not handlerOk then log.error("NET", "Handler error: %s", tostring(handlerErr)) + else + log.info("NET", "Command #%d handled OK", cmdCount) end end -- idempotency else + else + log.info("NET", "Ignored: ch=%d (want %d) or not table", channel or -1, cfg.ORDER_CHANNEL) end end end