From 81bde47cd415f91d3369036ff4f819c8624db452 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 8 Feb 2026 10:14:40 -0600 Subject: [PATCH] Move pb string length method and fix linker error --- src/meshUtils.cpp | 11 +++++++++++ src/meshUtils.h | 3 +++ src/modules/AtakPluginModule.cpp | 18 +----------------- test/test_atak/test_main.cpp | 11 +---------- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/meshUtils.cpp b/src/meshUtils.cpp index ea2ba641b..1a4497101 100644 --- a/src/meshUtils.cpp +++ b/src/meshUtils.cpp @@ -106,4 +106,15 @@ const std::string vformat(const char *const zcFormat, ...) std::vsnprintf(zc.data(), zc.size(), zcFormat, vaArgs); va_end(vaArgs); return std::string(zc.data(), iLen); +} + +size_t pb_string_length(const char *str, size_t max_len) +{ + size_t len = 0; + for (size_t i = 0; i < max_len; i++) { + if (str[i] != '\0') { + len = i + 1; + } + } + return len; } \ No newline at end of file diff --git a/src/meshUtils.h b/src/meshUtils.h index 9fcf6f8a8..67446f91f 100644 --- a/src/meshUtils.h +++ b/src/meshUtils.h @@ -35,4 +35,7 @@ bool isOneOf(int item, int count, ...); const std::string vformat(const char *const zcFormat, ...); +// Get actual string length for nanopb char array fields. +size_t pb_string_length(const char *str, size_t max_len); + #define IS_ONE_OF(item, ...) isOneOf(item, sizeof((int[]){__VA_ARGS__}) / sizeof(int), __VA_ARGS__) diff --git a/src/modules/AtakPluginModule.cpp b/src/modules/AtakPluginModule.cpp index 416c36cb6..bddb6276b 100644 --- a/src/modules/AtakPluginModule.cpp +++ b/src/modules/AtakPluginModule.cpp @@ -6,27 +6,11 @@ #include "configuration.h" #include "main.h" #include "mesh/compression/unishox2.h" +#include "meshUtils.h" #include "meshtastic/atak.pb.h" AtakPluginModule *atakPluginModule; -/** - * Get actual string length for nanopb char array fields. - * Nanopb stores strings as fixed-size char arrays that may contain embedded nulls. - * strlen() would stop at the first null, but we need to find the last non-null character. - * This is critical for Android UIDs that can contain 0x00 bytes (e.g., ANDROID-e7e455b40002429d). - */ -static size_t pb_string_length(const char *str, size_t max_len) -{ - size_t len = 0; - for (size_t i = 0; i < max_len; i++) { - if (str[i] != '\0') { - len = i + 1; - } - } - return len; -} - AtakPluginModule::AtakPluginModule() : ProtobufModule("atak", meshtastic_PortNum_ATAK_PLUGIN, &meshtastic_TAKPacket_msg), concurrency::OSThread("AtakPlugin") { diff --git a/test/test_atak/test_main.cpp b/test/test_atak/test_main.cpp index 4247f37ac..84078b300 100644 --- a/test/test_atak/test_main.cpp +++ b/test/test_atak/test_main.cpp @@ -2,16 +2,7 @@ #include #include "TestUtil.h" - -/** - * Get actual string length for nanopb char array fields. - * Nanopb stores strings as fixed-size char arrays that may contain embedded nulls. - * strlen() would stop at the first null, but we need to find the last non-null character. - * This is critical for Android UIDs that can contain 0x00 bytes (e.g., ANDROID-e7e455b40002429d). - * - * Use the firmware implementation declared elsewhere so tests exercise the same logic. - */ -extern size_t pb_string_length(const char *str, size_t max_len); +#include "meshUtils.h" void setUp(void) {