From 0d884d159a88fcb4871bff30c413d5a696f1ad0a Mon Sep 17 00:00:00 2001 From: a-f-G-U-C <65810997+a-f-G-U-C@users.noreply.github.com> Date: Sun, 24 Oct 2021 00:10:36 +0000 Subject: [PATCH] implement position packet optional fields (#892) --- src/plugins/PositionPlugin.cpp | 40 +++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index 9dfe07d5..b772954c 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -38,7 +38,45 @@ MeshPacket *PositionPlugin::allocReply() NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position assert(node->has_position); - Position p = node->position; + // configuration of POSITION packet + // consider making this a function argument? + uint32_t pos_flags = radioConfig.preferences.position_flags; + + // Populate a Position struct with ONLY the requested fields + Position p = Position_init_default; // Start with an empty structure + + // lat/lon are unconditionally included - IF AVAILABLE! + p.latitude_i = node->position.latitude_i; + p.longitude_i = node->position.longitude_i; + p.time = node->position.time; + + if (pos_flags & PositionFlags_POS_BATTERY) + p.battery_level = node->position.battery_level; + + if (pos_flags & PositionFlags_POS_ALTITUDE) { + if (pos_flags & PositionFlags_POS_ALT_MSL) + p.altitude = node->position.altitude; + else + p.altitude_hae = node->position.altitude_hae; + + if (pos_flags & PositionFlags_POS_GEO_SEP) + p.alt_geoid_sep = node->position.alt_geoid_sep; + } + + if (pos_flags & PositionFlags_POS_DOP) { + if (pos_flags & PositionFlags_POS_HVDOP) { + p.HDOP = node->position.HDOP; + p.VDOP = node->position.VDOP; + } else + p.PDOP = node->position.PDOP; + } + + if (pos_flags & PositionFlags_POS_SATINVIEW) + p.sats_in_view = node->position.sats_in_view; + + if (pos_flags & PositionFlags_POS_TIMESTAMP) + p.pos_timestamp = node->position.pos_timestamp; + // Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other // nodes shouldn't trust it anyways) Note: we allow a device with a local GPS to include the time, so that gpsless