add error if modems.info missing
This commit is contained in:
parent
c5d7dfdc6e
commit
0fc3255934
1 changed files with 38 additions and 21 deletions
|
@ -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!
|
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
|
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
|
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
|
-- Simple logging. It's not ideal but will do as a "temporary" solution
|
||||||
local function log(message)
|
local function log(message)
|
||||||
|
@ -40,6 +23,40 @@ term.clear()
|
||||||
term.setCursorPos(1, 1)
|
term.setCursorPos(1, 1)
|
||||||
log("UNS v" .. UNS_VERSION)
|
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
|
-- Prepare all modems
|
||||||
local primary_modem = nil
|
local primary_modem = nil
|
||||||
for i, modem in ipairs(modems) do
|
for i, modem in ipairs(modems) do
|
||||||
|
@ -47,7 +64,7 @@ for i, modem in ipairs(modems) do
|
||||||
if modems[i].primary then
|
if modems[i].primary then
|
||||||
primary_modem = modems[i].modem
|
primary_modem = modems[i].modem
|
||||||
end
|
end
|
||||||
log("load <" .. modem.id .. "> pos - " .. textutils.serialise(modem.pos))
|
log("loaded <" .. modem.id .. "> pos - " .. textutils.serialise(modem.pos))
|
||||||
end
|
end
|
||||||
if primary_modem == nil then
|
if primary_modem == nil then
|
||||||
primary_modem = modems[0].modem
|
primary_modem = modems[0].modem
|
||||||
|
@ -61,9 +78,9 @@ while true do
|
||||||
event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||||
until channel == gps.CHANNEL_GPS and message == "PING"
|
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
|
for _, modem in ipairs(modems) do
|
||||||
modem.modem.transmit(channel, replyChannel, modem.pos)
|
modem.modem.transmit(channel, replyChannel, modem.pos)
|
||||||
log("Modem <" .. modem.id .. "> transmitted location")
|
log("modem <" .. modem.id .. "> transmitted location")
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue