gps server record positions
This commit is contained in:
@@ -6,6 +6,7 @@ local args = { ... }
|
||||
local gps = _G.gps
|
||||
local os = _G.os
|
||||
local peripheral = _G.peripheral
|
||||
local term = _G.term
|
||||
local turtle = _G.turtle
|
||||
local vector = _G.vector
|
||||
|
||||
@@ -65,6 +66,10 @@ local function server()
|
||||
local modems = Config.load('gpsServer')
|
||||
local computers = { }
|
||||
|
||||
if #modems == 0 then
|
||||
error('Missing usr/config/gpsServer configuration file')
|
||||
end
|
||||
|
||||
for k, modem in pairs(modems) do
|
||||
Util.merge(modem, peripheral.wrap(k))
|
||||
modem.open(gps.CHANNEL_GPS)
|
||||
@@ -74,11 +79,12 @@ local function server()
|
||||
local e, p1, p2, p3, p4, p5 = os.pullEvent( "modem_message" )
|
||||
if e == "modem_message" then
|
||||
-- We received a message from a modem
|
||||
local sSide, channel, computerId, sMessage, distance = p1, p2, p3, p4, p5
|
||||
local side, channel, computerId, sMessage, distance = p1, p2, p3, p4, p5
|
||||
if channel == gps.CHANNEL_GPS and sMessage == "PING" then
|
||||
-- We received a ping message on the GPS channel, send a response
|
||||
local modem = modems[side]
|
||||
if modem then
|
||||
local computer = memoize(computers, computerId, function() return { } end)
|
||||
local modem = modems[sSide]
|
||||
table.insert(computer, {
|
||||
position = vector.new(modem.x, modem.y, modem.z), distance = distance
|
||||
})
|
||||
@@ -100,6 +106,7 @@ local function server()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if args[1] == 'build' then
|
||||
local y = tonumber(args[2] or 0)
|
||||
|
||||
Reference in New Issue
Block a user