diff --git a/GLONASS/UNS.lua b/GLONASS/UNS.lua index d6c3bfb..c867073 100644 --- a/GLONASS/UNS.lua +++ b/GLONASS/UNS.lua @@ -1,5 +1,5 @@ --[[ -Unitary Navigational System v0 +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 @@ -9,23 +9,6 @@ TODO: Bring back cool logging! local UNS_VERSION = 0 --- modems 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 file = fs.open("modems.info", "r") -local contents = file.readAll() -file.close() -local modems = textutils.unserialise(contents) -- Simple logging. It's not ideal but will do as a "temporary" solution local function log(message) @@ -40,6 +23,40 @@ 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 @@ -47,7 +64,7 @@ for i, modem in ipairs(modems) do if modems[i].primary then primary_modem = modems[i].modem end - log("load <" .. modem.id .. "> pos - " .. textutils.serialise(modem.pos)) + log("loaded <" .. modem.id .. "> pos - " .. textutils.serialise(modem.pos)) end if primary_modem == nil then primary_modem = modems[0].modem @@ -61,9 +78,9 @@ while true do event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") until channel == gps.CHANNEL_GPS and message == "PING" - log("Recieved location request, d-" .. distance) + 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") + log("modem <" .. modem.id .. "> transmitted location") end end \ No newline at end of file