diff --git a/platformio.ini b/platformio.ini index e3fc01efbd..2e3ee56f95 100644 --- a/platformio.ini +++ b/platformio.ini @@ -94,7 +94,6 @@ lib_deps = https://github.com/meshtastic/arduino-fsm.git#7db3702bf0cfe97b783d6c72595e3f38e0b19159 https://github.com/meshtastic/TinyGPSPlus.git#71a82db35f3b973440044c476d4bcdc673b104f4 https://github.com/meshtastic/ArduinoThread.git#1ae8778c85d0a2a729f989e0b1e7d7c4dc84eef0 - https://github.com/fmtlib/fmt.git#6.2.1 nanopb/Nanopb@^0.4.9 erriez/ErriezCRC32@^1.0.1 diff --git a/src/Power.cpp b/src/Power.cpp index bb873a5d19..f9b04dfd55 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -19,8 +19,6 @@ #include "main.h" #include "meshUtils.h" #include "sleep.h" -#include -#include // Working USB detection for powered/charging states on the RAK platform #ifdef NRF_APM @@ -666,7 +664,7 @@ void Power::readPowerStatus() for (int i = 0; i < MAX_THREADS; i++) { auto thread = concurrency::mainController.get(i); if ((thread != nullptr) && (thread->enabled)) { - threadlist += fmt::sprintf(" %s", thread->ThreadName.c_str()); + threadlist += vformat(" %s", thread->ThreadName.c_str()); running++; } } diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 61b66e3eea..0401a5ecc8 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -1,6 +1,4 @@ #include "ScanI2CTwoWire.h" -#include -#include #if !MESHTASTIC_EXCLUDE_I2C @@ -92,12 +90,12 @@ void ScanI2CTwoWire::printATECCInfo() const std::string atecc_numbers = "ATECC608B Serial Number: "; for (int i = 0; i < 9; i++) { - atecc_numbers += fmt::sprintf("%02x", atecc.serialNumber[i]); + atecc_numbers += vformat("%02x", atecc.serialNumber[i]); } atecc_numbers += ", Rev Number: "; for (int i = 0; i < 4; i++) { - atecc_numbers += fmt::sprintf("%02x", atecc.revisionNumber[i]); + atecc_numbers += vformat("%02x", atecc.revisionNumber[i]); } LOG_DEBUG(atecc_numbers.c_str()); @@ -111,7 +109,7 @@ void ScanI2CTwoWire::printATECCInfo() const } else { atecc_publickey += "ATECC608B Public Key: "; for (int i = 0; i < 64; i++) { - atecc_publickey += fmt::sprintf("%02x", atecc.publicKey64Bytes[i]); + atecc_publickey += vformat("%02x", atecc.publicKey64Bytes[i]); } } LOG_DEBUG(atecc_publickey.c_str()); diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index e979c48450..18feb6daa1 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -8,8 +8,6 @@ #include "RTC.h" #include "Throttle.h" #include "meshUtils.h" -#include -#include #include "main.h" // pmu_found #include "sleep.h" @@ -176,7 +174,7 @@ GPS_RESPONSE GPS::getACK(const char *message, uint32_t waitMillis) b = _serial_gps->read(); #ifdef GPS_DEBUG - debugmsg += fmt::sprintf("%c", (b >= 32 && b <= 126) ? b : '.'); + debugmsg += vformat("%c", (b >= 32 && b <= 126) ? b : '.'); #endif buffer[bytesRead] = b; bytesRead++; diff --git a/src/meshUtils.cpp b/src/meshUtils.cpp index e98a6f1ce6..d211f29225 100644 --- a/src/meshUtils.cpp +++ b/src/meshUtils.cpp @@ -94,4 +94,18 @@ bool isOneOf(int item, int count, ...) } va_end(args); return found; +} + +const std::string vformat(const char *const zcFormat, ...) +{ + va_list vaArgs; + va_start(vaArgs, zcFormat); + va_list vaArgsCopy; + va_copy(vaArgsCopy, vaArgs); + const int iLen = std::vsnprintf(NULL, 0, zcFormat, vaArgsCopy); + va_end(vaArgsCopy); + std::vector zc(iLen + 1); + std::vsnprintf(zc.data(), zc.size(), zcFormat, vaArgs); + va_end(vaArgs); + return std::string(zc.data(), iLen); } \ No newline at end of file diff --git a/src/meshUtils.h b/src/meshUtils.h index aff3976f48..47d42b41b9 100644 --- a/src/meshUtils.h +++ b/src/meshUtils.h @@ -24,4 +24,6 @@ bool memfll(const uint8_t *mem, uint8_t find, size_t numbytes); bool isOneOf(int item, int count, ...); +const std::string vformat(const char *const zcFormat, ...); + #define IS_ONE_OF(item, ...) isOneOf(item, sizeof((int[]){__VA_ARGS__}) / sizeof(int), __VA_ARGS__) diff --git a/src/modules/TraceRouteModule.cpp b/src/modules/TraceRouteModule.cpp index 7e0d95a319..79b14de0a2 100644 --- a/src/modules/TraceRouteModule.cpp +++ b/src/modules/TraceRouteModule.cpp @@ -1,7 +1,6 @@ #include "TraceRouteModule.h" #include "MeshService.h" -#include -#include +#include "meshUtils.h" TraceRouteModule *traceRouteModule; @@ -111,37 +110,37 @@ void TraceRouteModule::printRoute(meshtastic_RouteDiscovery *r, uint32_t origin, { #ifdef DEBUG_PORT std::string route = "Route traced:"; - route += fmt::sprintf("0x%x --> ", origin); + route += vformat("0x%x --> ", origin); for (uint8_t i = 0; i < r->route_count; i++) { if (i < r->snr_towards_count && r->snr_towards[i] != INT8_MIN) - route += fmt::sprintf("0x%x (%.2fdB) --> ", r->route[i], (float)r->snr_towards[i] / 4); + route += vformat("0x%x (%.2fdB) --> ", r->route[i], (float)r->snr_towards[i] / 4); else - route += fmt::sprintf("0x%x (?dB) --> ", r->route[i]); + route += vformat("0x%x (?dB) --> ", r->route[i]); } // If we are the destination, or it has already reached the destination, print it if (dest == nodeDB->getNodeNum() || !isTowardsDestination) { if (r->snr_towards_count > 0 && r->snr_towards[r->snr_towards_count - 1] != INT8_MIN) - route += fmt::sprintf("0x%x (%.2fdB)", dest, (float)r->snr_towards[r->snr_towards_count - 1] / 4); + route += vformat("0x%x (%.2fdB)", dest, (float)r->snr_towards[r->snr_towards_count - 1] / 4); else - route += fmt::sprintf("0x%x (?dB)", dest); + route += vformat("0x%x (?dB)", dest); } else route += "..."; // If there's a route back (or we are the destination as then the route is complete), print it if (r->route_back_count > 0 || origin == nodeDB->getNodeNum()) { if (r->snr_towards_count > 0 && origin == nodeDB->getNodeNum()) - route += fmt::sprintf("(%.2fdB) 0x%x <-- ", (float)r->snr_back[r->snr_back_count - 1] / 4, origin); + route += vformat("(%.2fdB) 0x%x <-- ", (float)r->snr_back[r->snr_back_count - 1] / 4, origin); else route += "..."; for (int8_t i = r->route_back_count - 1; i >= 0; i--) { if (i < r->snr_back_count && r->snr_back[i] != INT8_MIN) - route += fmt::sprintf("(%.2fdB) 0x%x <-- ", (float)r->snr_back[i] / 4, r->route_back[i]); + route += vformat("(%.2fdB) 0x%x <-- ", (float)r->snr_back[i] / 4, r->route_back[i]); else - route += fmt::sprintf("(?dB) 0x%x <-- ", r->route_back[i]); + route += vformat("(?dB) 0x%x <-- ", r->route_back[i]); } - route += fmt::sprintf("0x%x", dest); + route += vformat("0x%x", dest); } LOG_INFO(route.c_str()); #endif