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