feat: Enhance logging for modem communication in turtle and webbridge; improve command transmission feedback
This commit is contained in:
32
turtle.lua
32
turtle.lua
@@ -53,6 +53,8 @@ if not modem then
|
|||||||
error("No wireless modem found!")
|
error("No wireless modem found!")
|
||||||
end
|
end
|
||||||
modem.open(CHANNEL_RECEIVE)
|
modem.open(CHANNEL_RECEIVE)
|
||||||
|
print("📻 Modem opened on channel " .. CHANNEL_RECEIVE)
|
||||||
|
print(" Listening for commands...")
|
||||||
|
|
||||||
print("Advanced Mining Turtle System")
|
print("Advanced Mining Turtle System")
|
||||||
print("ID: " .. os.getComputerID())
|
print("ID: " .. os.getComputerID())
|
||||||
@@ -994,12 +996,34 @@ parallel.waitForAny(
|
|||||||
|
|
||||||
function()
|
function()
|
||||||
-- Command processing loop
|
-- Command processing loop
|
||||||
|
print("🎧 Command listener started - waiting for messages...")
|
||||||
while true do
|
while true do
|
||||||
local event, side, channel, replyChannel, message = os.pullEvent()
|
local event, side, channel, replyChannel, message = os.pullEvent()
|
||||||
|
|
||||||
if event == "modem_message" then
|
-- Log ALL events for debugging
|
||||||
print("Modem message on channel " .. channel)
|
if event ~= "modem_message" then
|
||||||
|
-- Skip non-modem events to reduce spam
|
||||||
|
else
|
||||||
|
print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||||
|
print("📻 MODEM MESSAGE DETECTED!")
|
||||||
|
print(" Event: " .. event)
|
||||||
|
print(" Side: " .. tostring(side))
|
||||||
|
print(" Channel: " .. channel)
|
||||||
|
print(" Reply channel: " .. replyChannel)
|
||||||
|
print(" Message type: " .. type(message))
|
||||||
|
print(" CHANNEL_RECEIVE value: " .. CHANNEL_RECEIVE)
|
||||||
|
|
||||||
|
if type(message) == "table" then
|
||||||
|
print(" Message contents:")
|
||||||
|
for k, v in pairs(message) do
|
||||||
|
print(" " .. k .. " = " .. tostring(v))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||||
|
|
||||||
if channel == CHANNEL_RECEIVE then
|
if channel == CHANNEL_RECEIVE then
|
||||||
|
print(" ✅ Channel matches CHANNEL_RECEIVE!")
|
||||||
|
|
||||||
-- Handle home position sync responses
|
-- Handle home position sync responses
|
||||||
if type(message) == "table" then
|
if type(message) == "table" then
|
||||||
if message.type == "home_position" and message.turtleID == os.getComputerID() then
|
if message.type == "home_position" and message.turtleID == os.getComputerID() then
|
||||||
@@ -1016,11 +1040,15 @@ parallel.waitForAny(
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Regular command processing
|
-- Regular command processing
|
||||||
|
print(" Passing to processMessage()")
|
||||||
processMessage(message)
|
processMessage(message)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
print(" Message not a table, passing to processMessage()")
|
||||||
processMessage(message)
|
processMessage(message)
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
print(" ❌ Channel mismatch! Expected " .. CHANNEL_RECEIVE .. ", got " .. channel)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ modem.open(CHANNEL_RECEIVE)
|
|||||||
modem.open(STATUS_CHANNEL)
|
modem.open(STATUS_CHANNEL)
|
||||||
modem.open(POCKET_CHANNEL)
|
modem.open(POCKET_CHANNEL)
|
||||||
|
|
||||||
|
print("Webbridge Channel Configuration:")
|
||||||
|
print(" CHANNEL_RECEIVE: " .. CHANNEL_RECEIVE)
|
||||||
|
print(" STATUS_CHANNEL: " .. STATUS_CHANNEL)
|
||||||
|
print(" COMMAND_CHANNEL: " .. COMMAND_CHANNEL .. " (transmit only)")
|
||||||
|
print(" POCKET_CHANNEL: " .. POCKET_CHANNEL)
|
||||||
|
|
||||||
-- Track turtles and stats
|
-- Track turtles and stats
|
||||||
local turtles = {}
|
local turtles = {}
|
||||||
local stats = {
|
local stats = {
|
||||||
@@ -322,15 +328,22 @@ while true do
|
|||||||
target = turtleID
|
target = turtleID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("📡 Transmitting command to Turtle #" .. turtleID)
|
||||||
|
print(" Channel: " .. COMMAND_CHANNEL)
|
||||||
|
print(" Command: " .. cmd.command)
|
||||||
|
print(" Target: " .. turtleID)
|
||||||
|
print(" Packet: " .. textutils.serialize(commandPacket))
|
||||||
|
|
||||||
-- Send command multiple times for reliability
|
-- Send command multiple times for reliability
|
||||||
for i = 1, 3 do
|
for i = 1, 3 do
|
||||||
modem.transmit(COMMAND_CHANNEL, CHANNEL_RECEIVE, commandPacket)
|
modem.transmit(COMMAND_CHANNEL, CHANNEL_RECEIVE, commandPacket)
|
||||||
|
print(" Transmission " .. i .. "/3 sent")
|
||||||
os.sleep(0.05) -- Small delay between retransmissions
|
os.sleep(0.05) -- Small delay between retransmissions
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Debug: show what we're sending
|
-- Debug: show what we're sending
|
||||||
if not hasMonitor then
|
if not hasMonitor then
|
||||||
print(" Sent to channel " .. COMMAND_CHANNEL .. ": target=" .. turtleID)
|
print(" ✅ Sent 3 times on channel " .. COMMAND_CHANNEL)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user