mirror of
https://github.com/torlando-tech/pyxis.git
synced 2026-07-17 11:32:06 +00:00
feat(ble): TX/RX fragment + byte counters in BLE heartbeat
Pre-this the 10s heartbeat reported running/scanning/connected/peers state but nothing about whether data was actually flowing. With the counters added to BLEInterface and threaded into the heartbeat snprintf, the line now also surfaces: tx_pkt — outbound RNS packets attempted tx_frag — BLE fragments actually written/notified tx_b — total bytes written tx_fail — platform write/notify returned false rx_frag — BLE fragments handed to the reassembler rx_b — total bytes received That was enough to root-cause the Columba-side stalls observed during the BLE end-to-end testing session: pyxis showed connected=1 but tx_pkt frozen, surfacing that the keepalive loop wasn't firing for a peer whose handshake had completed but identity recording raced. Cumulative-since-start, no reset; cheap to keep on always.
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user