bootstrap from floppy
This commit is contained in:
parent
29a6fd486e
commit
3a05db554c
2 changed files with 41 additions and 10 deletions
|
@ -1,4 +1,18 @@
|
||||||
|
-- wget run http://68.46.126.104:48228/turtle/client.lua
|
||||||
|
|
||||||
local ipaddr = "68.46.126.104"
|
local ipaddr = "68.46.126.104"
|
||||||
|
|
||||||
|
if not ipaddr then
|
||||||
|
if fs.exists("/disk/ip") then
|
||||||
|
local ipfile = fs.open("/disk/ip")
|
||||||
|
ipaddr = ipfile.readAll()
|
||||||
|
ipfile.close()
|
||||||
|
else
|
||||||
|
print("enter server ip:")
|
||||||
|
ipaddr = read("l")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local port = "48228"
|
local port = "48228"
|
||||||
|
|
||||||
local endpoint = "http://" .. ipaddr .. ":" .. port
|
local endpoint = "http://" .. ipaddr .. ":" .. port
|
||||||
|
@ -11,17 +25,18 @@ local backoff = 0;
|
||||||
|
|
||||||
if not idfile then
|
if not idfile then
|
||||||
local fuel = turtle.getFuelLevel()
|
local fuel = turtle.getFuelLevel()
|
||||||
local stdin = io.input()
|
if fs.exists("/disk/pos") then
|
||||||
|
io.input("/disk/pos")
|
||||||
|
end
|
||||||
|
local startpos = io.input()
|
||||||
print("Direction (North, South, East, West):")
|
print("Direction (North, South, East, West):")
|
||||||
local direction = stdin:read("l")
|
local direction = startpos:read("l")
|
||||||
print("X:")
|
print("X:")
|
||||||
local x = tonumber(stdin:read("l"))
|
local x = tonumber(startpos:read("l"))
|
||||||
print("Y:")
|
print("Y:")
|
||||||
local x = tonumber(stdin:read("l"))
|
local y = tonumber(startpos:read("l"))
|
||||||
print("Z:")
|
print("Z:")
|
||||||
local x = tonumber(stdin:read("l"))
|
local z = tonumber(startpos:read("l"))
|
||||||
local y = tonumber(stdin:read("l"))
|
|
||||||
local z = tonumber(stdin:read("l"))
|
|
||||||
|
|
||||||
local info = {
|
local info = {
|
||||||
fuel = fuel,
|
fuel = fuel,
|
||||||
|
@ -60,13 +75,26 @@ repeat
|
||||||
elseif command == "Right" then
|
elseif command == "Right" then
|
||||||
turtle.right()
|
turtle.right()
|
||||||
elseif command == "Update" then
|
elseif command == "Update" then
|
||||||
|
args = {...}
|
||||||
|
if args[1] == "nested" then
|
||||||
|
-- no exec = stack overflow
|
||||||
|
break
|
||||||
|
end
|
||||||
local req = http.get(endpoint .. "/turtle/client.lua")
|
local req = http.get(endpoint .. "/turtle/client.lua")
|
||||||
|
if not req then
|
||||||
|
os.reboot()
|
||||||
|
end
|
||||||
local update = req.readAll()
|
local update = req.readAll()
|
||||||
req.close()
|
req.close()
|
||||||
|
fs.delete("startup-backup")
|
||||||
|
if fs.exists("/startup") then
|
||||||
|
-- pcall does not work with cc fs
|
||||||
|
fs.move("startup", "startup-backup")
|
||||||
|
end
|
||||||
local startup = fs.open("startup", "w")
|
local startup = fs.open("startup", "w")
|
||||||
startup.write(update)
|
startup.write(update)
|
||||||
startup.close()
|
startup.close()
|
||||||
os.reboot()
|
shell.run("startup", "nested")
|
||||||
end
|
end
|
||||||
|
|
||||||
local ahead = "minecraft:air"
|
local ahead = "minecraft:air"
|
||||||
|
|
|
@ -115,7 +115,7 @@ async fn create_turtle(
|
||||||
|
|
||||||
println!("turt {id}");
|
println!("turt {id}");
|
||||||
|
|
||||||
Json(TurtleResponse {name: Name::from_num(id).to_str(), id, command: TurtleCommand::Wait})
|
Json(TurtleResponse {name: Name::from_num(id).to_str(), id, command: TurtleCommand::Update})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn command(
|
async fn command(
|
||||||
|
@ -125,9 +125,10 @@ async fn command(
|
||||||
) -> Json<TurtleCommand> {
|
) -> Json<TurtleCommand> {
|
||||||
let turtles = &state.read().await.turtles;
|
let turtles = &state.read().await.turtles;
|
||||||
println!("{id}");
|
println!("{id}");
|
||||||
|
println!("above: {}, below: {}, ahead: {}", req.above, req.below, req.ahead);
|
||||||
|
|
||||||
|
|
||||||
Json(TurtleCommand::Update)
|
Json(TurtleCommand::Wait)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
@ -152,6 +153,8 @@ struct TurtleUpdate {
|
||||||
fuel: usize,
|
fuel: usize,
|
||||||
/// Block name
|
/// Block name
|
||||||
ahead: String,
|
ahead: String,
|
||||||
|
above: String,
|
||||||
|
below: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|
Loading…
Reference in a new issue