Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local sides = rs.getSides()
- function clearTerm()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function getChannel(t)
- if t == "motor" then
- return "coms_turtles_motor"
- elseif t == "miner" then
- return "coms_turtles_miner"
- elseif t == "master" then
- return "coms_turtles_master"
- end
- return nil
- end
- for i = 1, #sides do
- if peripheral.isPresent(sides[i]) and peripheral.getType(sides[i]) == "modem" then
- rednet.open(sides[i])
- break
- end
- end
- if #args < 3 then
- print("Usage: update [turtle-type] [program-name] [paste-code]")
- else
- clearTerm()
- turtle_channel = getChannel(args[1])
- programName = args[2]
- pasteCode = args[3]
- if not turtle_channel then
- print("Invalid turtle type. Use motor|miner")
- return
- end
- print("Updating over protocol: " .. turtle_channel)
- shell.run("pastebin get " .. pasteCode .. " program")
- print("Program downloaded.")
- sleep(1.5)
- rednet.broadcast("UPDATE", turtle_channel)
- while(true) do
- print("Waiting for ready response from turtles..")
- id, msg, proto = rednet.receive(turtle_channel, 2)
- if not proto then
- clearTerm()
- term.setTextColor(colors.red)
- print("No turtle was listening to update request.")
- break
- end
- if msg == "UPDATE_READY" then
- f = fs.open("program", "r")
- packet = textutils.serialize(
- {
- name = programName,
- content = f.readAll()
- })
- f.close()
- print("Sending program packet.")
- rednet.broadcast(packet, "coms_turtles_payload")
- sleep(1.5)
- clearTerm()
- term.setTextColor(colors.green)
- print("Update complete.")
- break
- end
- end
- fs.delete("program")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement