OpenComputers Von Neumann Machine Programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
985 B

  1. local modem = require("component").modem
  2. local Server = Server or require("server")
  3. local computer = require("computer")
  4. local event = require("event")
  5. local os = require("os")
  6. local gps = {}
  7. gps.port = 20
  8. gps.server = Server(gps.port, "gps")
  9. function gps.startServer(x, y, z)
  10. gps.x = x
  11. gps.y = y
  12. gps.z = z
  13. gps.server:handle("/ping", function(...)
  14. local tmp = {...}
  15. computer.beep(500)
  16. print(tmp[3])
  17. modem.send(tmp[3], gps.port, "/location", tmp[7], x, y, z)
  18. end)
  19. end
  20. function gps.closeServer()
  21. gps.server:close()
  22. end
  23. function gps.getLocation()
  24. gps.locator:handle("/location", function(...)
  25. local tmp = {...}
  26. end)
  27. end
  28. gps.startServer()
  29. -- Soft interrupt
  30. local interrupted = false
  31. local interruptID = event.listen("interrupted", function() interrupted = true end)
  32. while not interrupted do
  33. os.sleep(1)
  34. end
  35. -- Don't forget to close the server
  36. event.cancel(interruptID)
  37. gps.closeServer()