Improved status response.
This commit is contained in:
parent
9f6a4e5e1c
commit
7e7aa9febc
@ -30,7 +30,6 @@ local FAILED = "failed"
|
|||||||
running = true
|
running = true
|
||||||
local modem = peripheral.find("modem")
|
local modem = peripheral.find("modem")
|
||||||
|
|
||||||
|
|
||||||
print("Checking for modem.")
|
print("Checking for modem.")
|
||||||
if (modem == nil) then
|
if (modem == nil) then
|
||||||
error("Modem not found.")
|
error("Modem not found.")
|
||||||
@ -101,6 +100,11 @@ local function handleMessage(sender, type, data)
|
|||||||
|
|
||||||
if type == LOG then
|
if type == LOG then
|
||||||
print("[" .. sender .. "]: " .. data["log"] .. ": " .. (data["content"]["n"] >= 1 and tostring(data["content"][1]) or ""))
|
print("[" .. sender .. "]: " .. data["log"] .. ": " .. (data["content"]["n"] >= 1 and tostring(data["content"][1]) or ""))
|
||||||
|
if data["log"] == STATUS then
|
||||||
|
print("Relative position: " .. tostring(data["content"][1]["relative_position"]["coordinates"]))
|
||||||
|
print("Position" .. tostring(data["content"][1]["position"]["coordinates"]))
|
||||||
|
print("fuel: " .. tostring(data["content"][1]["fuel"]))
|
||||||
|
print("current task: " .. data["content"][1]["task"])
|
||||||
elseif type == REQUEST then
|
elseif type == REQUEST then
|
||||||
handleRequest(sender, data["request"], data["content"])
|
handleRequest(sender, data["request"], data["content"])
|
||||||
end
|
end
|
||||||
|
@ -221,13 +221,13 @@ local function orient(v, forward, right)
|
|||||||
print("Orientation complete.")
|
print("Orientation complete.")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function attemptStartTask(f, ...)
|
local function attemptStartTask(name, f, ...)
|
||||||
sendLog(TASK, "Attempting to start task.")
|
sendLog(TASK, "Attempting to start task.")
|
||||||
if task ~= nil then
|
if task ~= nil then
|
||||||
sendLog(FAILED, "Unable to start task due to another task running.")
|
sendLog(FAILED, "Unable to start task due to another task running.")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
task = f
|
task = {name=name, func=f, args=arg}
|
||||||
taskArgs = arg
|
taskArgs = arg
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -314,7 +314,8 @@ end
|
|||||||
local function executeTasks()
|
local function executeTasks()
|
||||||
while running do
|
while running do
|
||||||
if task ~= nil then
|
if task ~= nil then
|
||||||
task(unpack(taskArgs))
|
sendLog(TASK, "Executing task: " .. task["name"])
|
||||||
|
task["func"](unpack(task["args"]))
|
||||||
task = nil
|
task = nil
|
||||||
end
|
end
|
||||||
sleep(5)
|
sleep(5)
|
||||||
@ -349,11 +350,11 @@ local function listen()
|
|||||||
if heading ~= nil then
|
if heading ~= nil then
|
||||||
print("Using actual coordinates.")
|
print("Using actual coordinates.")
|
||||||
sendLog(MOVETO, "Using actual coordinates to move.")
|
sendLog(MOVETO, "Using actual coordinates to move.")
|
||||||
attemptStartTask(moveTo, vector.new(x,y,z), heading, rightAxis)
|
attemptStartTask(MOVETO, moveTo, vector.new(x,y,z), heading, rightAxis)
|
||||||
else
|
else
|
||||||
print("Using relative coordinates.")
|
print("Using relative coordinates.")
|
||||||
sendLog(MOVETO, "Using relative coordinates to move.")
|
sendLog(MOVETO, "Using relative coordinates to move.")
|
||||||
attemptStartTask(moveTo, vector.new(x,y,z), relHeading, relRightAxis)
|
attemptStartTask(MOVETO, moveTo, vector.new(x,y,z), relHeading, relRightAxis)
|
||||||
end
|
end
|
||||||
elseif data["request"] == MOVEBY then
|
elseif data["request"] == MOVEBY then
|
||||||
local x = data["content"][1]
|
local x = data["content"][1]
|
||||||
@ -362,11 +363,11 @@ local function listen()
|
|||||||
if heading ~= nil then
|
if heading ~= nil then
|
||||||
print("Using actual coordinates.")
|
print("Using actual coordinates.")
|
||||||
sendLog(MOVEBY, "Using actual coordinates to move.")
|
sendLog(MOVEBY, "Using actual coordinates to move.")
|
||||||
attemptStartTask(moveBy, vector.new(x,y,z), heading, rightAxis)
|
attemptStartTask(MOVEBY, moveBy, vector.new(x,y,z), heading, rightAxis)
|
||||||
else
|
else
|
||||||
print("Using relative coordinates.")
|
print("Using relative coordinates.")
|
||||||
sendLog(MOVEBY, "Using relative coordinates to move.")
|
sendLog(MOVEBY, "Using relative coordinates to move.")
|
||||||
attemptStartTask(moveBy, vector.new(x,y,z), relHeading, relRightAxis)
|
attemptStartTask(MOVEBY, moveBy, vector.new(x,y,z), relHeading, relRightAxis)
|
||||||
end
|
end
|
||||||
elseif data["request"] == STATUS then
|
elseif data["request"] == STATUS then
|
||||||
status = {
|
status = {
|
||||||
@ -381,6 +382,7 @@ local function listen()
|
|||||||
right=rightAxis
|
right=rightAxis
|
||||||
},
|
},
|
||||||
fuel=turtle.getFuelLevel(),
|
fuel=turtle.getFuelLevel(),
|
||||||
|
task=task["name"]
|
||||||
}
|
}
|
||||||
sendLog(STATUS, status)
|
sendLog(STATUS, status)
|
||||||
elseif data["request"] == POSITION then
|
elseif data["request"] == POSITION then
|
||||||
|
Loading…
Reference in New Issue
Block a user