diff --git a/lib/ble_interface/BLEInterface.cpp b/lib/ble_interface/BLEInterface.cpp index e7c1f6e2..31ddee4e 100644 --- a/lib/ble_interface/BLEInterface.cpp +++ b/lib/ble_interface/BLEInterface.cpp @@ -235,6 +235,8 @@ void BLEInterface::loop() { continue; } } + _stat_rx_fragments++; + _stat_rx_bytes += _pending_data_pool[i].data.size(); _reassembler.processFragment(stored_id, _pending_data_pool[i].data); } _pending_data_count = requeue_count; @@ -242,11 +244,21 @@ void BLEInterface::loop() { // Debug: log loop status every 10 seconds if (now - last_loop_log >= 10.0) { + char stats[160]; + snprintf(stats, sizeof(stats), + " tx_pkt=%lu tx_frag=%lu tx_b=%lu tx_fail=%lu rx_frag=%lu rx_b=%lu", + (unsigned long)_stat_tx_packets, + (unsigned long)_stat_tx_fragments, + (unsigned long)_stat_tx_bytes, + (unsigned long)_stat_tx_fail, + (unsigned long)_stat_rx_fragments, + (unsigned long)_stat_rx_bytes); INFO("BLE: running=" + std::string(_platform && _platform->isRunning() ? "yes" : "no") + " scanning=" + std::string(_platform && _platform->isScanning() ? "yes" : "no") + " connected=" + std::to_string(_peer_manager.connectedCount()) + " peers=" + std::to_string(_peer_manager.getAllPeers().size()) + - " heap=" + std::to_string(ESP.getFreeHeap())); + " heap=" + std::to_string(ESP.getFreeHeap()) + + stats); last_loop_log = now; } @@ -384,6 +396,7 @@ bool BLEInterface::sendToPeer(const Bytes& peer_identity, const Bytes& data) { // Send each fragment bool all_sent = true; + _stat_tx_packets++; for (const Bytes& fragment : fragments) { bool sent = false; @@ -397,7 +410,11 @@ bool BLEInterface::sendToPeer(const Bytes& peer_identity, const Bytes& data) { sent = _platform->notify(peer->conn_handle, fragment); } - if (!sent) { + if (sent) { + _stat_tx_fragments++; + _stat_tx_bytes += fragment.size(); + } else { + _stat_tx_fail++; WARNING("BLEInterface: Failed to send fragment to " + peer_identity.toHex().substr(0, 8) + " conn=" + std::to_string(peer->conn_handle)); diff --git a/lib/ble_interface/BLEInterface.h b/lib/ble_interface/BLEInterface.h index 17e864b6..f12a3162 100644 --- a/lib/ble_interface/BLEInterface.h +++ b/lib/ble_interface/BLEInterface.h @@ -281,6 +281,18 @@ private: PendingData _pending_data_pool[MAX_PENDING_DATA]; size_t _pending_data_count = 0; + // Diagnostic counters — included in the periodic BLE heartbeat + // log so we can see "did fragments actually flow over a peer + // connection" without per-event logs flooding USB CDC. Cumulative + // since interface start. + uint32_t _stat_tx_packets = 0; // outbound RNS packets attempted + uint32_t _stat_tx_fragments = 0; // BLE fragments actually written/notified + uint32_t _stat_tx_bytes = 0; // total bytes written + uint32_t _stat_tx_fail = 0; // platform write/notify returned false + uint32_t _stat_rx_fragments = 0; // BLE fragments handed to reassembler + uint32_t _stat_rx_bytes = 0; // total bytes received + uint32_t _stat_rx_packets_complete = 0; // reassembled packets passed up + // Thread safety for callbacks from BLE stack // Using recursive_mutex because handleIncomingData holds the lock while // calling processReceivedData, which can trigger onHandshakeComplete callback