mirror of
https://github.com/bluekitchen/btstack.git
synced 2024-12-29 09:26:08 +00:00
HCI Dump RTT STDOUT: drop messages if RTT buffer is full and RTT is configured for non-blocking
This commit is contained in:
parent
eb0d557942
commit
7dfe4b1c91
@ -10,8 +10,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
### Added
|
||||
- HCI Dump: Support BTSnoop format in hci_dump_posix_fs.c for format = HCI_DUMP_BTSNOOP
|
||||
- HCI Dump RTT STDOUT: drop messages if RTT buffer is full and RTT is configured for non-blocking
|
||||
|
||||
### Fixed
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
|
@ -49,6 +49,48 @@
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
|
||||
// [00:00:37.514] LOG -- xxx\n
|
||||
#define ADDITIONAL_CHARS_PER_LINE (14+1+6+1+1)
|
||||
|
||||
static void hci_dump_segger_rtt_stdout_timestamp(void);
|
||||
|
||||
#if SEGGER_RTT_MODE_DEFAULT != SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
|
||||
|
||||
// avoid trunkated log lines by calculating requires space in rtt buffer
|
||||
// if message needs to be skipped, report number skipped messages
|
||||
|
||||
static const char * message_packets_skipped = "RTT buffer full, %3u packet(s) skipped";
|
||||
|
||||
static bool hci_dump_segger_prepare_message(uint16_t message_size){
|
||||
|
||||
static uint32_t hci_dump_rtt_num_skipped = 0;
|
||||
|
||||
// calculate num chars required for line
|
||||
uint16_t required_space = ADDITIONAL_CHARS_PER_LINE + message_size;
|
||||
|
||||
// if we have dropped packets before, we want to print a warning
|
||||
if (hci_dump_rtt_num_skipped > 0){
|
||||
required_space += ADDITIONAL_CHARS_PER_LINE + strlen(message_packets_skipped);
|
||||
}
|
||||
|
||||
// not enough space yet, drop message
|
||||
if (required_space > SEGGER_RTT_GetAvailWriteSpace(0)){
|
||||
hci_dump_rtt_num_skipped++;
|
||||
return false;
|
||||
}
|
||||
|
||||
// print message if dropped packets
|
||||
if (hci_dump_rtt_num_skipped > 0){
|
||||
hci_dump_segger_rtt_stdout_timestamp();
|
||||
SEGGER_RTT_printf(0, "LOG -- ");
|
||||
SEGGER_RTT_printf(0, message_packets_skipped, hci_dump_rtt_num_skipped);
|
||||
SEGGER_RTT_printf(0, "\n");
|
||||
hci_dump_rtt_num_skipped = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void hci_dump_segger_rtt_hexdump(const void *data, int size){
|
||||
char buffer[4];
|
||||
buffer[2] = ' ';
|
||||
@ -98,9 +140,6 @@ static void hci_dump_segger_rtt_stdout_packet(uint8_t packet_type, uint8_t in, u
|
||||
SEGGER_RTT_printf(0, "SCO => ");
|
||||
}
|
||||
break;
|
||||
case LOG_MESSAGE_PACKET:
|
||||
SEGGER_RTT_printf(0, "LOG -- %s\n", (char*) packet);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
@ -108,11 +147,25 @@ static void hci_dump_segger_rtt_stdout_packet(uint8_t packet_type, uint8_t in, u
|
||||
}
|
||||
|
||||
static void hci_dump_segger_rtt_stdout_log_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) {
|
||||
#if SEGGER_RTT_MODE_DEFAULT != SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
|
||||
uint16_t message_len = len * 3;
|
||||
bool ready = hci_dump_segger_prepare_message(message_len);
|
||||
if (!ready) return;
|
||||
#endif
|
||||
|
||||
// print packet
|
||||
hci_dump_segger_rtt_stdout_timestamp();
|
||||
hci_dump_segger_rtt_stdout_packet(packet_type, in, packet, len);
|
||||
}
|
||||
|
||||
static void hci_dump_segger_rtt_stdout_log_message(const char * format, va_list argptr){
|
||||
#if SEGGER_RTT_MODE_DEFAULT != SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
|
||||
// to avoid using snprintf for this, we cheat and assume that the messages is less then HCI_DUMP_MAX_MESSAGE_LEN
|
||||
bool ready = hci_dump_segger_prepare_message(HCI_DUMP_MAX_MESSAGE_LEN);
|
||||
if (!ready) return;
|
||||
#endif
|
||||
|
||||
// print message
|
||||
hci_dump_segger_rtt_stdout_timestamp();
|
||||
SEGGER_RTT_printf(0, "LOG -- ");
|
||||
SEGGER_RTT_vprintf(0, format, &argptr);
|
||||
|
Loading…
Reference in New Issue
Block a user