Created
August 14, 2022 17:36
-
-
Save SammyForReal/38c5e02545778ed7fdc460d4ad47b742 to your computer and use it in GitHub Desktop.
Host GPS with a single PC, instead of 4!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Insert name of 'wireless_modems' (attatched to wired_modems), used for GPS here | |
-- Remove the already existing onces! | |
-- EXAMPLE: ["modem_0"] = {x=1, y=2, z=3} | |
local point = { | |
["modem_0"] = {x=151, y=56, z=-43}, | |
["modem_1"] = {x=156, y=56, z=-43}, | |
["modem_2"] = {x=151, y=56, z=-38}, | |
["modem_3"] = {x=151, y=60, z=-43} | |
} | |
local CHANNEL_GPS = gps.CHANNEL_GPS | |
----------------------------------------- | |
-- END OF CONFIGURATION | |
----------------------------------------- | |
local bRunning = true | |
local function main() | |
local modem = {} | |
for name,_ in pairs(point) do | |
modem[#modem+1] = {p=peripheral.wrap(name), n=name} | |
end | |
local function listener(modem) | |
modem.p.open(CHANNEL_GPS) | |
while bRunning do | |
local event, sSide, sChannel, sReplyChannel, sMessage, nDistance = os.pullEvent( "modem_message" ) | |
if event == "modem_message" then | |
if sSide == modem.n and sChannel == CHANNEL_GPS and sMessage == "PING" and nDistance then | |
modem.p.transmit( sReplyChannel, CHANNEL_GPS, { point[modem.n].x, point[modem.n].y, point[modem.n].z } ) | |
end | |
end | |
end | |
modem.p.close(CHANNEL_GPS) | |
end | |
parallel.waitForAll( | |
function() listener(modem[1]) end, | |
function() listener(modem[2]) end, | |
function() listener(modem[3]) end, | |
function() listener(modem[4]) end | |
) | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment