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