From 6b2f2ecf013d554ae37cc4c7f144242da708d919 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Thu, 21 May 2026 09:14:16 +0200 Subject: [PATCH] fix: replace base64.hpp include with local encoder to fix ODR link error base64.hpp is header-only; including it in a .h file pulled into multiple translation units caused duplicate symbol errors at link time. Replaced with a self-contained static pubKeyToBase64() method inside NearbyScreen that implements the same standard base64 encoding without any external include. Co-Authored-By: Claude Sonnet 4.6 --- .../companion_radio/ui-new/NearbyScreen.h | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/companion_radio/ui-new/NearbyScreen.h b/examples/companion_radio/ui-new/NearbyScreen.h index 0d4f5e27..2e3c0c51 100644 --- a/examples/companion_radio/ui-new/NearbyScreen.h +++ b/examples/companion_radio/ui-new/NearbyScreen.h @@ -1,6 +1,5 @@ #pragma once #include -#include #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -56,6 +55,21 @@ class NearbyScreen : public UIScreen { bool _ddetail; // ── helpers ────────────────────────────────────────────────────────────────── + static void pubKeyToBase64(const uint8_t* key, char* out, int out_len) { + static const char T[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + int j = 0; + for (int i = 0; i < PUB_KEY_SIZE && j + 5 < out_len; i += 3) { + uint32_t b = ((uint32_t)key[i] << 16) + | (i+1 < PUB_KEY_SIZE ? (uint32_t)key[i+1] << 8 : 0) + | (i+2 < PUB_KEY_SIZE ? (uint32_t)key[i+2] : 0); + out[j++] = T[(b >> 18) & 63]; + out[j++] = T[(b >> 12) & 63]; + if (i+1 < PUB_KEY_SIZE) out[j++] = T[(b >> 6) & 63]; + if (i+2 < PUB_KEY_SIZE) out[j++] = T[b & 63]; + } + out[j] = '\0'; + } + static float haversineKm(int32_t lat1, int32_t lon1, int32_t lat2, int32_t lon2) { static const float DEG2RAD = (float)M_PI / 180.0f; float la1 = lat1 * (1e-6f * DEG2RAD); @@ -200,10 +214,9 @@ class NearbyScreen : public UIScreen { display.fillRect(0, 10, display.width(), 1); // public key as base64, truncated with ... by drawTextEllipsized - uint8_t b64[48]; - encode_base64(r.pub_key, PUB_KEY_SIZE, b64); - b64[44] = '\0'; - display.drawTextEllipsized(2, 12, display.width() - 4, (const char*)b64); + char b64[48]; + pubKeyToBase64(r.pub_key, b64, sizeof(b64)); + display.drawTextEllipsized(2, 12, display.width() - 4, b64); char buf[32];