diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index 95c52ea6..16805ac2 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -64,6 +64,9 @@ struct RepeaterStats { uint32_t n_packets_sent; uint32_t total_air_time_secs; uint32_t total_up_time_secs; + uint32_t n_sent_flood, n_sent_direct; + uint32_t n_recv_flood, n_recv_direct; + uint32_t n_full_events; }; struct ClientInfo { @@ -120,6 +123,11 @@ class MyMesh : public mesh::Mesh { stats.n_packets_sent = my_radio->getPacketsSent(); stats.total_air_time_secs = getTotalAirTime() / 1000; stats.total_up_time_secs = _ms->getMillis() / 1000; + stats.n_sent_flood = getNumSentFlood(); + stats.n_sent_direct = getNumSentDirect(); + stats.n_recv_flood = getNumRecvFlood(); + stats.n_recv_direct = getNumRecvDirect(); + stats.n_full_events = getNumFullEvents(); memcpy(&reply_data[4], &stats, sizeof(stats)); diff --git a/examples/test_admin/main.cpp b/examples/test_admin/main.cpp index 08032276..33395026 100644 --- a/examples/test_admin/main.cpp +++ b/examples/test_admin/main.cpp @@ -51,6 +51,9 @@ struct RepeaterStats { uint32_t n_packets_sent; uint32_t total_air_time_secs; uint32_t total_up_time_secs; + uint32_t n_sent_flood, n_sent_direct; + uint32_t n_recv_flood, n_recv_direct; + uint32_t n_full_events; }; class MyMesh : public mesh::Mesh { diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index 02059cfc..0da93a76 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -7,6 +7,10 @@ namespace mesh { void Dispatcher::begin() { + n_sent_flood = n_sent_direct = 0; + n_recv_flood = n_recv_direct = 0; + n_full_events = 0; + _radio->begin(); } @@ -26,6 +30,11 @@ void Dispatcher::loop() { _radio->onSendFinished(); onPacketSent(outbound); + if (outbound->isRouteFlood()) { + n_sent_flood++; + } else { + n_sent_direct++; + } outbound = NULL; } else if (millisHasNowPassed(outbound_expiry)) { MESH_DEBUG_PRINTLN("Dispatcher::loop(): WARNING: outbound packed send timed out!"); @@ -85,6 +94,11 @@ void Dispatcher::checkRecv() { } } if (pkt) { + if (pkt->isRouteFlood()) { + n_recv_flood++; + } else { + n_recv_direct++; + } #if MESH_PACKET_LOGGING Serial.printf("PACKET: recv, len=%d (type=%d, route=%s, payload_len=%d) SNR=%d RSSI=%d\n", 2 + pkt->path_len + pkt->payload_len, pkt->getPayloadType(), pkt->isRouteDirect() ? "D" : "F", pkt->payload_len, @@ -142,7 +156,10 @@ void Dispatcher::checkSend() { } Packet* Dispatcher::obtainNewPacket() { - return _mgr->allocNew(); // TODO: zero out all fields + auto pkt = _mgr->allocNew(); // TODO: zero out all fields + if (pkt == NULL) n_full_events++; + + return pkt; } void Dispatcher::releasePacket(Packet* packet) { diff --git a/src/Dispatcher.h b/src/Dispatcher.h index ae33052f..eea31460 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -94,6 +94,9 @@ class Dispatcher { Packet* outbound; // current outbound packet unsigned long outbound_expiry, outbound_start, total_air_time; unsigned long next_tx_time; + uint32_t n_sent_flood, n_sent_direct; + uint32_t n_recv_flood, n_recv_direct; + uint32_t n_full_events; protected: PacketManager* _mgr; @@ -119,6 +122,11 @@ public: void sendPacket(Packet* packet, uint8_t priority, uint32_t delay_millis=0); unsigned long getTotalAirTime() const { return total_air_time; } // in milliseconds + uint32_t getNumSentFlood() const { return n_sent_flood; } + uint32_t getNumSentDirect() const { return n_sent_direct; } + uint32_t getNumRecvFlood() const { return n_recv_flood; } + uint32_t getNumRecvDirect() const { return n_recv_direct; } + uint32_t getNumFullEvents() const { return n_full_events; } // helper methods bool millisHasNowPassed(unsigned long timestamp) const;