Files
Jord 4827498188
CI / setup (all) (push) Has been cancelled
CI / setup (check) (push) Has been cancelled
CI / version (push) Has been cancelled
CI / build-debian-src (push) Has been cancelled
CI / MacOS (15) (push) Has been cancelled
CI / MacOS (26) (push) Has been cancelled
CI / package-pio-deps-native-tft (push) Has been cancelled
CI / test-native (push) Has been cancelled
CI / docker (alpine, native, linux/amd64) (push) Has been cancelled
CI / docker (alpine, native, linux/arm64) (push) Has been cancelled
CI / docker (alpine, native-tft, linux/amd64) (push) Has been cancelled
CI / docker (debian, native, linux/amd64) (push) Has been cancelled
CI / docker (debian, native, linux/arm/v7) (push) Has been cancelled
CI / docker (debian, native, linux/arm64) (push) Has been cancelled
CI / docker (debian, native-tft, linux/amd64) (push) Has been cancelled
CI / check (push) Has been cancelled
CI / build (push) Has been cancelled
CI / gather-artifacts (esp32) (push) Has been cancelled
CI / gather-artifacts (esp32c3) (push) Has been cancelled
CI / gather-artifacts (esp32c6) (push) Has been cancelled
CI / gather-artifacts (esp32s3) (push) Has been cancelled
CI / gather-artifacts (nrf52840) (push) Has been cancelled
CI / gather-artifacts (rp2040) (push) Has been cancelled
CI / gather-artifacts (rp2350) (push) Has been cancelled
CI / gather-artifacts (stm32) (push) Has been cancelled
CI / shame (push) Has been cancelled
CI / release-artifacts (push) Has been cancelled
CI / release-firmware (esp32) (push) Has been cancelled
CI / release-firmware (esp32c3) (push) Has been cancelled
CI / release-firmware (esp32c6) (push) Has been cancelled
CI / release-firmware (esp32s3) (push) Has been cancelled
CI / release-firmware (nrf52840) (push) Has been cancelled
CI / release-firmware (rp2040) (push) Has been cancelled
CI / release-firmware (rp2350) (push) Has been cancelled
CI / release-firmware (stm32) (push) Has been cancelled
CI / publish-firmware (push) Has been cancelled
Clamp direct position packets to channel precision (fixes #8640) (#10383)
* Fix position precision for direct sends

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Clarify zero position precision logging

* Use const channel reference for position precision

* Use C linkage for position precision test entrypoints

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-05-14 20:51:44 -05:00

101 lines
3.6 KiB
C++

#include "PositionPrecision.h"
#include "TestUtil.h"
#include "mesh-pb-constants.h"
#include <unity.h>
static meshtastic_Position makePosition()
{
meshtastic_Position position = meshtastic_Position_init_default;
position.has_latitude_i = true;
position.latitude_i = static_cast<int32_t>(0x12345678);
position.has_longitude_i = true;
position.longitude_i = static_cast<int32_t>(0x22345678);
position.has_altitude = true;
position.altitude = 123;
position.time = 42;
position.location_source = meshtastic_Position_LocSource_LOC_EXTERNAL;
position.timestamp = 43;
position.sats_in_view = 10;
return position;
}
static void test_applyPositionPrecision_clampsLatLonAndSetsPrecisionBits()
{
meshtastic_Position position = makePosition();
applyPositionPrecision(position, 16);
TEST_ASSERT_EQUAL_INT32(static_cast<int32_t>(0x12348000), position.latitude_i);
TEST_ASSERT_EQUAL_INT32(static_cast<int32_t>(0x22348000), position.longitude_i);
TEST_ASSERT_EQUAL_UINT32(16, position.precision_bits);
TEST_ASSERT_TRUE(position.has_latitude_i);
TEST_ASSERT_TRUE(position.has_longitude_i);
}
static void test_applyPositionPrecision_fullPrecisionKeepsLatLon()
{
meshtastic_Position position = makePosition();
applyPositionPrecision(position, 32);
TEST_ASSERT_EQUAL_INT32(static_cast<int32_t>(0x12345678), position.latitude_i);
TEST_ASSERT_EQUAL_INT32(static_cast<int32_t>(0x22345678), position.longitude_i);
TEST_ASSERT_EQUAL_UINT32(32, position.precision_bits);
}
static void test_applyPositionPrecision_zeroScrubsLocationButKeepsTime()
{
meshtastic_Position position = makePosition();
applyPositionPrecision(position, 0);
TEST_ASSERT_FALSE(position.has_latitude_i);
TEST_ASSERT_EQUAL_INT32(0, position.latitude_i);
TEST_ASSERT_FALSE(position.has_longitude_i);
TEST_ASSERT_EQUAL_INT32(0, position.longitude_i);
TEST_ASSERT_FALSE(position.has_altitude);
TEST_ASSERT_EQUAL_INT32(0, position.altitude);
TEST_ASSERT_EQUAL_UINT32(42, position.time);
TEST_ASSERT_EQUAL_UINT32(0, position.timestamp);
TEST_ASSERT_EQUAL_UINT32(0, position.sats_in_view);
TEST_ASSERT_EQUAL_UINT32(0, position.precision_bits);
}
static void test_applyPositionPrecision_reencodesPositionPacket()
{
meshtastic_Position position = makePosition();
meshtastic_MeshPacket packet = meshtastic_MeshPacket_init_default;
packet.which_payload_variant = meshtastic_MeshPacket_decoded_tag;
packet.decoded.portnum = meshtastic_PortNum_POSITION_APP;
packet.decoded.payload.size = pb_encode_to_bytes(packet.decoded.payload.bytes, sizeof(packet.decoded.payload.bytes),
&meshtastic_Position_msg, &position);
TEST_ASSERT_TRUE(applyPositionPrecision(packet, 16));
meshtastic_Position decoded = meshtastic_Position_init_default;
TEST_ASSERT_TRUE(
pb_decode_from_bytes(packet.decoded.payload.bytes, packet.decoded.payload.size, &meshtastic_Position_msg, &decoded));
TEST_ASSERT_EQUAL_INT32(static_cast<int32_t>(0x12348000), decoded.latitude_i);
TEST_ASSERT_EQUAL_INT32(static_cast<int32_t>(0x22348000), decoded.longitude_i);
TEST_ASSERT_EQUAL_UINT32(16, decoded.precision_bits);
}
void setUp(void) {}
void tearDown(void) {}
extern "C" {
void setup()
{
initializeTestEnvironment();
UNITY_BEGIN();
RUN_TEST(test_applyPositionPrecision_clampsLatLonAndSetsPrecisionBits);
RUN_TEST(test_applyPositionPrecision_fullPrecisionKeepsLatLon);
RUN_TEST(test_applyPositionPrecision_zeroScrubsLocationButKeepsTime);
RUN_TEST(test_applyPositionPrecision_reencodesPositionPacket);
exit(UNITY_END());
}
void loop() {}
}