--[[ Unitary Navigational System v0 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 = 0 local UNS_HOST_ID = "lavender-1" -- Modems declaration. Edit this! local modems = { { id = "modem_id", pos = { 1, -- x 1, -- y 1 -- z }, primary = true, -- The modem that does listening modem = nil, -- Declared below, leave as nil } } -- Simple logging. It's not ideal but will do as a "temporary" solution local function log(message) term.write(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) -- 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("load <" .. 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 if message == "PING" then -- Normal location request log("Recieved location request, d-" .. distance) for _, modem in ipairs(modems) do modem.modem.transmit(channel, replyChannel, modem.pos) log("Modem <" .. modem.id .. "> transmitted location") end elseif message == "INFO" then -- Host query log("Recieved info request, d-" .. distance) primary_modem.transmit(channel, replyChannel, {version = UNS_VERSION, host = UNS_HOST_ID, modems = modems}) elseif distance > 30 then -- TODO: How do I and *should* I even ensure I don't recieve my own messages? log("Recieved broken request, d-" .. distance) end end