fix: Improve message processing and command transmission in turtle system

This commit is contained in:
MayaTheShy
2026-02-16 01:37:24 -05:00
parent 5ec385c1f2
commit 175c6add10
2 changed files with 26 additions and 13 deletions

View File

@@ -565,27 +565,33 @@ local commands = {
-- Process incoming messages
local function processMessage(message)
print("Received message on modem")
print(" Type: " .. type(message))
if type(message) ~= "table" then
return
end
-- Check if message is targeted to this turtle
local myID = os.getComputerID()
if message.target and message.target ~= myID then
-- This command is for a different turtle, ignore it
return
end
print("Received command message")
print(" Target: " .. tostring(message.target))
print(" My ID: " .. myID)
if type(message) == "table" then
print(" Has command: " .. tostring(message.command ~= nil))
if message.command then
print(" Command: " .. message.command)
end
end
if type(message) == "table" and message.command then
print("Processing command: " .. message.command)
local handler = commands[message.command]
if handler then
print(" Executing command...")
local success, result = handler(message.param)
modem.transmit(CHANNEL_SEND, CHANNEL_RECEIVE, {
status = success and "ok" or "error",
message = result or "",
turtleID = os.getComputerID()
turtleID = myID
})
broadcastStatus()

View File

@@ -301,11 +301,18 @@ while true do
stats.commandsSent = stats.commandsSent + 1
addLog("CMD: " .. cmd.command .. " -> Turtle #" .. turtleID, colors.yellow)
modem.transmit(COMMAND_CHANNEL, CHANNEL_RECEIVE, {
local commandPacket = {
command = cmd.command,
param = cmd.param,
target = turtleID
})
}
modem.transmit(COMMAND_CHANNEL, CHANNEL_RECEIVE, commandPacket)
-- Debug: show what we're sending
if not hasMonitor then
print(" Sent to channel " .. COMMAND_CHANNEL .. ": target=" .. turtleID)
end
end
end