Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local useport = 1351 -- make sure this number is the same as the drone program
- local component = require("component")
- if not component.isAvailable("modem") then
- io.stderr:write("This program needs a modem to run.\n")
- return
- end
- local event = require("event")
- local seri = require("serialization")
- local modem = component.modem
- local RED, YELLOW, GREEN, BLUE, CLEAR = "\27[31m", "\27[33m", "\27[32m", "\27[36m", "\27[0m"
- modem.open(useport)
- modem.broadcast(useport, "_BROADCAST_TARGETS_PS_BOOT")
- print(YELLOW.."Waiting for drones booting..."..CLEAR)
- os.sleep(1)
- local droneaddresses = {}
- modem.broadcast(useport, "_BROADCAST_TARGETS_PS_K")
- while true do
- local name, _, sender = event.pull(2, "modem_message")
- if name == "modem_message" then
- table.insert(droneaddresses, sender)
- else
- break
- end
- end
- print(BLUE.."Select a drone:"..CLEAR)
- for i, v in ipairs(droneaddresses) do
- print(tostring(i)..". "..v)
- end
- io.write(BLUE.."Input number:"..CLEAR)
- local drone = droneaddresses[tonumber(io.read())]
- local function invoke(command)
- modem.send(drone, useport, command)
- local name, _, _, _, _, ret = event.pull(20, "modem_message")
- if name == "modem_message" then
- return ret
- else
- return RED.."Response timed out."..CLEAR
- end
- end
- print(GREEN.."Drone remote controller"..CLEAR)
- print(GREEN.."Programmed by Micrafast"..CLEAR)
- print(BLUE..'Type "exit" to exit.'..CLEAR)
- while true do
- io.write(BLUE..drone.."> "..CLEAR)
- local cmd = io.read()
- if cmd == "exit" then
- print(YELLOW.."Bye!"..CLEAR)
- return
- end
- print(invoke(cmd))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement