This commit is contained in:
Andrew-71 2024-03-14 12:40:59 +03:00
parent 5b23ea99fd
commit 5318967c09
2 changed files with 43 additions and 31 deletions

View file

@ -1 +1,3 @@
I originally made this project in 2022 as a proof of concept.
# Unitary Navigational System
I originally made this project in 2022 as a proof of concept, but now it's *mostly* ready for production. It's a very basic script.

View file

@ -1,39 +1,29 @@
--[[
Unitary Navigational System v0.0
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 made in 2022 after discovering CC
It was made out of project "GLONASS Tower" I wrote back in 2022 after first discovering CC
TODO: Bring back cool logging!
]]
-- Modems declaration. Edit this
local UNS_VERSION = 0
local UNS_HOST_ID = "lavender-1"
-- Modems declaration. Edit this!
local modems = {
{
id = "modem_id_here",
id = "modem_id",
pos = {
x = 1,
y = 1,
z = 1
1, -- x
1, -- y
1 -- z
},
modem = nil,
primary = true -- Highest modem, to increase coverage ever so slightly
primary = true, -- The modem that does listening
modem = nil, -- Declared below, leave as nil
}
}
-- Prepare all modems
local primary_modem = nil
for i = 1 .. #modems do
modems[i].modem = peripheral.wrap(modems[i].id)
if modems[i].primary then
primary_modem = modems[i].modem
end
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
-- Simple logging. It's not ideal but will do as a "temporary" solution
local function log(message)
term.write(message)
@ -45,19 +35,39 @@ local function log(message)
end
term.clear()
term.setCursorPos(1, 1)
log("UNS v0.0 starting...")
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 GPS query
-- 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 request, distance: " .. distance)
until channel == gps.CHANNEL_GPS
-- Send data from all modems
if message == "PING" then -- Normal location request
log("Recieved location request, d-" .. distance)
for _, modem in ipairs(modems) do
modem.transmit(channel, replyChannel, modem.pos)
log("Modem ID <" .. modem.id .. "> transmitted location")
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