--[[ Unitary Navigational System This basic script attempts to consolidate a GPS constellation into a single computer. Because using 4 is plain wasteful! It was made out of project "GLONASS Tower" I wrote back in 2022 after first discovering CC TODO: Bring back cool logging! ]] local UNS_VERSION = 1 -- Simple logging. It's not ideal but will do as a "temporary" solution local function log(message) local time_str = os.date('%H:%M ') term.write(time_str .. message) term.setCursorPos(1, select(2, term.getCursorPos()) + 1) if select(2, term.getCursorPos()) >= select(2, term.getSize()) then term.scroll(1) term.setCursorPos(1, select(2, term.getCursorPos()) - 1) end end term.clear() term.setCursorPos(1, 1) log("UNS v" .. UNS_VERSION) -- modems.info format: --[[ { id = "modem_id", pos = { 1, -- x 1, -- y 1 -- z }, primary = true, -- The modem that does listening modem = nil, -- Declared below, leave as nil } ]] local modems if fs.exists("modems.info") then local file = fs.open("modems.info", "r") local contents = file.readAll() file.close() modems = textutils.unserialise(contents) else log("error: modems.info file missing") -- TODO: Automatic setup print("attempt automatic setup? (Y/n) : ") local ans = read() if ans:lower() == "y" or ans == "" then log("not implemented yet, sorry!") else log("nothing to do") os.exit() end end -- Prepare all modems local primary_modem = nil for i, modem in ipairs(modems) do modems[i].modem = peripheral.wrap(modems[i].id) if modems[i].primary then primary_modem = modems[i].modem end log("loaded <" .. modem.id .. "> pos - " .. textutils.serialise(modem.pos)) end if primary_modem == nil then primary_modem = modems[0].modem end primary_modem.open(gps.CHANNEL_GPS) -- Only *listen* on 1 modem to avoid repeats while true do -- Wait for a request on channel local event, side, channel, replyChannel, message, distance repeat event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") until channel == gps.CHANNEL_GPS and message == "PING" log("recieved location request, d-" .. string.format("%.3f", distance)) for _, modem in ipairs(modems) do modem.modem.transmit(channel, replyChannel, modem.pos) log("modem <" .. modem.id .. "> transmitted location") end end