modem declaration through files
This commit is contained in:
parent
5318967c09
commit
c5d7dfdc6e
2 changed files with 55 additions and 17 deletions
|
@ -8,11 +8,10 @@ TODO: Bring back cool logging!
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local UNS_VERSION = 0
|
local UNS_VERSION = 0
|
||||||
local UNS_HOST_ID = "lavender-1"
|
|
||||||
|
|
||||||
-- Modems declaration. Edit this!
|
-- modems format:
|
||||||
local modems = {
|
--[[
|
||||||
{
|
{
|
||||||
id = "modem_id",
|
id = "modem_id",
|
||||||
pos = {
|
pos = {
|
||||||
1, -- x
|
1, -- x
|
||||||
|
@ -22,7 +21,11 @@ local modems = {
|
||||||
primary = true, -- The modem that does listening
|
primary = true, -- The modem that does listening
|
||||||
modem = nil, -- Declared below, leave as nil
|
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)
|
||||||
|
@ -56,18 +59,11 @@ while true do
|
||||||
local event, side, channel, replyChannel, message, distance
|
local event, side, channel, replyChannel, message, distance
|
||||||
repeat
|
repeat
|
||||||
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
|
until channel == gps.CHANNEL_GPS and message == "PING"
|
||||||
|
|
||||||
if message == "PING" then -- Normal location request
|
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
|
|
||||||
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
|
||||||
end
|
end
|
42
GLONASS/modems.info
Normal file
42
GLONASS/modems.info
Normal file
|
@ -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
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in a new issue