StatsFormatHelper.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include "Mesh.h"
  3. class StatsFormatHelper {
  4. public:
  5. static void formatCoreStats(char* reply,
  6. mesh::MainBoard& board,
  7. mesh::MillisecondClock& ms,
  8. uint16_t err_flags,
  9. mesh::PacketManager* mgr) {
  10. sprintf(reply,
  11. "{\"battery_mv\":%u,\"uptime_secs\":%u,\"errors\":%u,\"queue_len\":%u}",
  12. board.getBattMilliVolts(),
  13. ms.getMillis() / 1000,
  14. err_flags,
  15. mgr->getOutboundCount(0xFFFFFFFF)
  16. );
  17. }
  18. template<typename RadioDriverType>
  19. static void formatRadioStats(char* reply,
  20. mesh::Radio* radio,
  21. RadioDriverType& driver,
  22. uint32_t total_air_time_ms,
  23. uint32_t total_rx_air_time_ms) {
  24. sprintf(reply,
  25. "{\"noise_floor\":%d,\"last_rssi\":%d,\"last_snr\":%.2f,\"tx_air_secs\":%u,\"rx_air_secs\":%u}",
  26. (int16_t)radio->getNoiseFloor(),
  27. (int16_t)driver.getLastRSSI(),
  28. driver.getLastSNR(),
  29. total_air_time_ms / 1000,
  30. total_rx_air_time_ms / 1000
  31. );
  32. }
  33. template<typename RadioDriverType>
  34. static void formatPacketStats(char* reply,
  35. RadioDriverType& driver,
  36. uint32_t n_sent_flood,
  37. uint32_t n_sent_direct,
  38. uint32_t n_recv_flood,
  39. uint32_t n_recv_direct) {
  40. sprintf(reply,
  41. "{\"recv\":%u,\"sent\":%u,\"flood_tx\":%u,\"direct_tx\":%u,\"flood_rx\":%u,\"direct_rx\":%u}",
  42. driver.getPacketsRecv(),
  43. driver.getPacketsSent(),
  44. n_sent_flood,
  45. n_sent_direct,
  46. n_recv_flood,
  47. n_recv_direct
  48. );
  49. }
  50. };