Skip to content

Commit

Permalink
you wanna play, eh?
Browse files Browse the repository at this point in the history
  • Loading branch information
caveman99 committed Oct 13, 2024
1 parent 74a7622 commit e9801a6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
1 change: 0 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "main.h"
#include "meshUtils.h"
#include "sleep.h"
#include <fmt/core.h>
#include <fmt/printf.h>

// Working USB detection for powered/charging states on the RAK platform
#ifdef NRF_APM
Expand Down Expand Up @@ -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++;
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/detect/ScanI2CTwoWire.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "ScanI2CTwoWire.h"
#include <fmt/core.h>
#include <fmt/printf.h>

#if !MESHTASTIC_EXCLUDE_I2C

Expand Down Expand Up @@ -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());

Expand All @@ -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());
Expand Down
4 changes: 1 addition & 3 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "RTC.h"
#include "Throttle.h"
#include "meshUtils.h"
#include <fmt/core.h>
#include <fmt/printf.h>

#include "main.h" // pmu_found
#include "sleep.h"
Expand Down Expand Up @@ -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++;
Expand Down
14 changes: 14 additions & 0 deletions src/meshUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> zc(iLen + 1);
std::vsnprintf(zc.data(), zc.size(), zcFormat, vaArgs);
va_end(vaArgs);
return std::string(zc.data(), iLen);
}
2 changes: 2 additions & 0 deletions src/meshUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
21 changes: 10 additions & 11 deletions src/modules/TraceRouteModule.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "TraceRouteModule.h"
#include "MeshService.h"
#include <fmt/core.h>
#include <fmt/printf.h>
#include "meshUtils.h"

TraceRouteModule *traceRouteModule;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e9801a6

Please sign in to comment.