63 lines
No EOL
1.8 KiB
Lua
63 lines
No EOL
1.8 KiB
Lua
--[[
|
|
Unitary Navigational System v0.0
|
|
|
|
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
|
|
|
|
TODO: Bring back cool logging!
|
|
]]
|
|
|
|
-- Modems declaration. Edit this
|
|
local modems = {
|
|
{
|
|
id = "modem_id_here",
|
|
pos = {
|
|
x = 1,
|
|
y = 1,
|
|
z = 1
|
|
},
|
|
modem = nil,
|
|
primary = true -- Highest modem, to increase coverage ever so slightly
|
|
}
|
|
}
|
|
|
|
-- 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)
|
|
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 v0.0 starting...")
|
|
|
|
while true do
|
|
-- Wait for a GPS query
|
|
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)
|
|
|
|
-- Send data from all modems
|
|
for _, modem in ipairs(modems) do
|
|
modem.transmit(channel, replyChannel, modem.pos)
|
|
log("Modem ID <" .. modem.id .. "> transmitted location")
|
|
end
|
|
end |