From b121189f368cb5d93045b20709ee9522796d62ec Mon Sep 17 00:00:00 2001 From: Matthew Wilbern <39929480+fatboychummy@users.noreply.github.com> Date: Sat, 11 Nov 2023 02:22:19 -0700 Subject: [PATCH 1/5] Include distance in GPS host response. --- .../main/resources/data/computercraft/lua/rom/programs/gps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/gps.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/gps.lua index 3a65fd8ae7..ca6c06ee0f 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/programs/gps.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/programs/gps.lua @@ -79,7 +79,7 @@ elseif sCommand == "host" then local sSide, sChannel, sReplyChannel, sMessage, nDistance = p1, p2, p3, p4, p5 if sSide == sModemSide and sChannel == gps.CHANNEL_GPS and sMessage == "PING" and nDistance then -- We received a ping message on the GPS channel, send a response - modem.transmit(sReplyChannel, gps.CHANNEL_GPS, { x, y, z }) + modem.transmit(sReplyChannel, gps.CHANNEL_GPS, { x, y, z, nDistance }) -- Print the number of requests handled nServed = nServed + 1 From 4ced8429ad5f8991c3430f835ac1eb79180d07dd Mon Sep 17 00:00:00 2001 From: Matthew Wilbern <39929480+fatboychummy@users.noreply.github.com> Date: Sat, 11 Nov 2023 02:25:18 -0700 Subject: [PATCH 2/5] Make gps.locate use distance received instead of modem distance. --- .../main/resources/data/computercraft/lua/rom/apis/gps.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua index d1eafec2c7..13b1f71636 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua @@ -148,8 +148,8 @@ function locate(_nTimeout, _bDebug) local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5 if sSide == sModemSide and sChannel == CHANNEL_GPS and sReplyChannel == CHANNEL_GPS and nDistance then -- Received the correct message from the correct modem: use it to determine position - if type(tMessage) == "table" and #tMessage == 3 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then - local tFix = { vPosition = vector.new(tMessage[1], tMessage[2], tMessage[3]), nDistance = nDistance } + if type(tMessage) == "table" and #tMessage == 4 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) and tonumber(tMessage[4]) then + local tFix = { vPosition = vector.new(tMessage[1], tMessage[2], tMessage[3]), nDistance = tMessage[4] } if _bDebug then print(tFix.nDistance .. " metres from " .. tostring(tFix.vPosition)) end From 7a69b6ae00980829c60bb857eca5f4cdb413029d Mon Sep 17 00:00:00 2001 From: Matthew Wilbern <39929480+fatboychummy@users.noreply.github.com> Date: Sat, 11 Nov 2023 02:34:40 -0700 Subject: [PATCH 3/5] Allow clients to fallback to default GPS usage for 'old' hosts. --- .../src/main/resources/data/computercraft/lua/rom/apis/gps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua index 13b1f71636..badeaac485 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua @@ -149,7 +149,7 @@ function locate(_nTimeout, _bDebug) if sSide == sModemSide and sChannel == CHANNEL_GPS and sReplyChannel == CHANNEL_GPS and nDistance then -- Received the correct message from the correct modem: use it to determine position if type(tMessage) == "table" and #tMessage == 4 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) and tonumber(tMessage[4]) then - local tFix = { vPosition = vector.new(tMessage[1], tMessage[2], tMessage[3]), nDistance = tMessage[4] } + local tFix = { vPosition = vector.new(tMessage[1], tMessage[2], tMessage[3]), nDistance = tonumber(tMessage[4]) and tMessage[4] or nDistance } if _bDebug then print(tFix.nDistance .. " metres from " .. tostring(tFix.vPosition)) end From bb4d1ca3de78ae9144b3a3dd18ea1311353e131d Mon Sep 17 00:00:00 2001 From: Matthew Wilbern <39929480+fatboychummy@users.noreply.github.com> Date: Sat, 11 Nov 2023 02:35:44 -0700 Subject: [PATCH 4/5] Woops, this would need to be removed as well to fallback. --- .../src/main/resources/data/computercraft/lua/rom/apis/gps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua index badeaac485..3a8dd34af9 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua @@ -148,7 +148,7 @@ function locate(_nTimeout, _bDebug) local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5 if sSide == sModemSide and sChannel == CHANNEL_GPS and sReplyChannel == CHANNEL_GPS and nDistance then -- Received the correct message from the correct modem: use it to determine position - if type(tMessage) == "table" and #tMessage == 4 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) and tonumber(tMessage[4]) then + if type(tMessage) == "table" and #tMessage == 4 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then local tFix = { vPosition = vector.new(tMessage[1], tMessage[2], tMessage[3]), nDistance = tonumber(tMessage[4]) and tMessage[4] or nDistance } if _bDebug then print(tFix.nDistance .. " metres from " .. tostring(tFix.vPosition)) From 135a756e5bdd8f60fcc492728f2b022ba2f38481 Mon Sep 17 00:00:00 2001 From: Matthew Wilbern <39929480+fatboychummy@users.noreply.github.com> Date: Sat, 11 Nov 2023 02:38:40 -0700 Subject: [PATCH 5/5] It's nearly 3am, can you tell? Fix fallback failure: we should check for both 3 and 4 arguments. --- .../main/resources/data/computercraft/lua/rom/apis/gps.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua index 3a8dd34af9..7360108113 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/apis/gps.lua @@ -148,8 +148,8 @@ function locate(_nTimeout, _bDebug) local sSide, sChannel, sReplyChannel, tMessage, nDistance = p1, p2, p3, p4, p5 if sSide == sModemSide and sChannel == CHANNEL_GPS and sReplyChannel == CHANNEL_GPS and nDistance then -- Received the correct message from the correct modem: use it to determine position - if type(tMessage) == "table" and #tMessage == 4 and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then - local tFix = { vPosition = vector.new(tMessage[1], tMessage[2], tMessage[3]), nDistance = tonumber(tMessage[4]) and tMessage[4] or nDistance } + if type(tMessage) == "table" and (#tMessage == 3 or #tMessage == 4 and tonumber(tMessage[4])) and tonumber(tMessage[1]) and tonumber(tMessage[2]) and tonumber(tMessage[3]) then + local tFix = { vPosition = vector.new(tMessage[1], tMessage[2], tMessage[3]), nDistance = tonumber(tMessage[4]) or nDistance } if _bDebug then print(tFix.nDistance .. " metres from " .. tostring(tFix.vPosition)) end