From 5732eed86bc67f783c53ba02348b9fc3c831f16a Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 26 Mar 2024 07:29:07 -0500 Subject: [PATCH] Fixed position admin messages (#3490) * Bespoke admin messages for setting and clearing fixed positions * Add guards against remote admin messages setting things * Flip ifs --- src/modules/AdminModule.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 50cec824d..2c04916dd 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -17,6 +17,7 @@ #include "unistd.h" #endif #include "Default.h" +#include "TypeConversions.h" #if !MESHTASTIC_EXCLUDE_MQTT #include "mqtt/MQTT.h" @@ -205,6 +206,31 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } break; } + case meshtastic_AdminMessage_set_fixed_position_tag: { + if (fromOthers) { + LOG_INFO("Ignoring set_fixed_position command from another node.\n"); + } else { + LOG_INFO("Client is receiving a set_fixed_position command.\n"); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); + node->has_position = true; + node->position = TypeConversions::ConvertToPositionLite(r->set_fixed_position); + nodeDB->setLocalPosition(r->set_fixed_position); + config.position.fixed_position = true; + saveChanges(SEGMENT_DEVICESTATE | SEGMENT_CONFIG, false); + } + break; + } + case meshtastic_AdminMessage_remove_fixed_position_tag: { + if (fromOthers) { + LOG_INFO("Ignoring remove_fixed_position command from another node.\n"); + } else { + LOG_INFO("Client is receiving a remove_fixed_position command.\n"); + nodeDB->clearLocalPosition(); + config.position.fixed_position = false; + saveChanges(SEGMENT_DEVICESTATE | SEGMENT_CONFIG, false); + } + break; + } case meshtastic_AdminMessage_enter_dfu_mode_request_tag: { LOG_INFO("Client is requesting to enter DFU mode.\n"); #if defined(ARCH_NRF52) || defined(ARCH_RP2040)