diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index a88e0b6a..ae1beae4 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -106,6 +106,7 @@ struct RepeaterStats { uint32_t n_sent_flood, n_sent_direct; uint32_t n_recv_flood, n_recv_direct; uint32_t n_full_events; + uint16_t n_direct_dups, n_flood_dups; }; struct ClientInfo { @@ -183,6 +184,8 @@ class MyMesh : public mesh::Mesh { stats.n_recv_flood = getNumRecvFlood(); stats.n_recv_direct = getNumRecvDirect(); stats.n_full_events = getNumFullEvents(); + stats.n_direct_dups = ((SimpleMeshTables *)getTables())->getNumDirectDups(); + stats.n_flood_dups = ((SimpleMeshTables *)getTables())->getNumFloodDups(); memcpy(&reply_data[4], &stats, sizeof(stats)); @@ -467,7 +470,7 @@ protected: } public: - MyMesh(mesh::MainBoard& board, RadioLibWrapper& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables) + MyMesh(mesh::MainBoard& board, RadioLibWrapper& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, SimpleMeshTables& tables) : mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables), _board(&board) { my_radio = &radio; @@ -734,7 +737,7 @@ void setup() { #else float tcxo = 1.6f; #endif - + #if defined(NRF52_PLATFORM) SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); SPI.begin(); diff --git a/src/Mesh.h b/src/Mesh.h index e5da9406..d6e8a1b1 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -139,6 +139,8 @@ protected: { } + MeshTables* getTables() const { return _tables; } + public: void begin(); void loop(); diff --git a/src/helpers/SimpleMeshTables.h b/src/helpers/SimpleMeshTables.h index c98704a7..87fd65b8 100644 --- a/src/helpers/SimpleMeshTables.h +++ b/src/helpers/SimpleMeshTables.h @@ -11,11 +11,13 @@ class SimpleMeshTables : public mesh::MeshTables { uint8_t _hashes[MAX_PACKET_HASHES*MAX_HASH_SIZE]; int _next_idx; + uint32_t _direct_dups, _flood_dups; public: SimpleMeshTables() { memset(_hashes, 0, sizeof(_hashes)); _next_idx = 0; + _direct_dups = _flood_dups = 0; } #ifdef ESP32 @@ -35,7 +37,14 @@ public: const uint8_t* sp = _hashes; for (int i = 0; i < MAX_PACKET_HASHES; i++, sp += MAX_HASH_SIZE) { - if (memcmp(hash, sp, MAX_HASH_SIZE) == 0) return true; + if (memcmp(hash, sp, MAX_HASH_SIZE) == 0) { + if (packet->isRouteDirect()) { + _direct_dups++; // keep some stats + } else { + _flood_dups++; + } + return true; + } } memcpy(&_hashes[_next_idx*MAX_HASH_SIZE], hash, MAX_HASH_SIZE); @@ -44,5 +53,7 @@ public: return false; } + uint32_t getNumDirectDups() const { return _direct_dups; } + uint32_t getNumFloodDups() const { return _flood_dups; } };