From ebf4c75bfa71587470738ad52d860da7cfc6052f Mon Sep 17 00:00:00 2001 From: liamcottle Date: Thu, 3 Oct 2024 09:52:41 +1300 Subject: [PATCH] use same logic as meshtastic firmware to obfuscate position --- src/mqtt.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/mqtt.js b/src/mqtt.js index 7ca7ea1..18a97e7 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -791,27 +791,12 @@ client.on("message", async (topic, message) => { if(position.latitudeI != null && position.longitudeI){ // if bitfield is not available, we are on firmware v2.4 or below - // if configured, truncate position packets to the provided number of decimal places + // if configured, position packets should have their precision reduced if(bitfield == null && oldFirmwarePositionPrecision != null){ - // convert lat/long to decimal as string - // e.g: -123456789 -> -12.3456789 - const latitudeString = (position.latitudeI / 10000000).toString(); - const longitudeString = (position.longitudeI / 10000000).toString(); - - // truncate to desired length - const truncatedLatitudeString = PositionUtil.truncateDecimalPlaces(latitudeString, oldFirmwarePositionPrecision); - const truncatedLongitudeString = PositionUtil.truncateDecimalPlaces(longitudeString, oldFirmwarePositionPrecision); - - // convert lat/long string back to integer from decimal - // e.g: -12.3456789 -> -123456789 - // fixme: sometimes we may get xx.xx99999 recurring, but don't worry about that for now, since we are mangling the precision anyway... - const truncatedLatitudeI = parseInt(parseFloat(truncatedLatitudeString) * 10000000); - const truncatedLongitudeI = parseInt(parseFloat(truncatedLongitudeString) * 10000000); - - // update position packet with truncated lat/long - position.latitudeI = truncatedLatitudeI; - position.longitudeI = truncatedLongitudeI; + // adjust precision of latitude and longitude + position.latitudeI = PositionUtil.setPositionPrecision(position.latitudeI, oldFirmwarePositionPrecision); + position.longitudeI = PositionUtil.setPositionPrecision(position.longitudeI, oldFirmwarePositionPrecision); // todo update position precision on packet to show that it is no longer full precision