diff --git a/GLONASS/UNS.lua b/GLONASS/UNS.lua index 81fb0aa..d6c3bfb 100644 --- a/GLONASS/UNS.lua +++ b/GLONASS/UNS.lua @@ -8,11 +8,10 @@ TODO: Bring back cool logging! ]] local UNS_VERSION = 0 -local UNS_HOST_ID = "lavender-1" --- Modems declaration. Edit this! -local modems = { - { +-- modems format: +--[[ + { id = "modem_id", pos = { 1, -- x @@ -22,7 +21,11 @@ local modems = { 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) @@ -56,18 +59,11 @@ while true do local event, side, channel, replyChannel, message, distance repeat event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") - until channel == gps.CHANNEL_GPS + until channel == gps.CHANNEL_GPS and message == "PING" - 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) + 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 end \ No newline at end of file diff --git a/GLONASS/modems.info b/GLONASS/modems.info new file mode 100644 index 0000000..b16f0f2 --- /dev/null +++ b/GLONASS/modems.info @@ -0,0 +1,42 @@ +{ + { + id = "modem_0", + pos = { + 0, + 319, + 0 + }, + modem = nil, + primary = true + }, + { + id = "modem_1", + pos = { + 0, + 304, + 0 + }, + modem = nil, + primary = false + }, + { + id = "modem_2", + pos = { + 14, + 304, + 0 + }, + modem = nil, + primary = false + }, + { + id = "modem_3", + pos = { + 0, + 304, + 14 + }, + modem = nil, + primary = false + }, +} \ No newline at end of file