From cdc66b5eb8d7f9a749c9003bdeb0f95de0a1be78 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 23 Mar 2021 11:24:05 +0100 Subject: [PATCH] hci_dump: add hci_dump_enable_packet_log to enable/disable packet logging --- src/hci_dump.c | 14 +++++++++++++- src/hci_dump.h | 23 +++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/hci_dump.c b/src/hci_dump.c index 15ad5df9f..c402f6a3e 100644 --- a/src/hci_dump.c +++ b/src/hci_dump.c @@ -51,6 +51,7 @@ static const hci_dump_t * hci_dump_impl; static int max_nr_packets; static int nr_packets; +static bool packet_log_enabled; // levels: debug, info, error static bool log_level_enabled[3] = { 1, 1, 1}; @@ -66,14 +67,25 @@ void hci_dump_init(const hci_dump_t * impl){ max_nr_packets = -1; nr_packets = 0; hci_dump_impl = impl; + packet_log_enabled = true; } void hci_dump_set_max_packets(int packets){ max_nr_packets = packets; } +void hci_dump_enable_packet_log(bool enabled){ + packet_log_enabled = enabled; +} + void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) { - if (hci_dump_impl == NULL) return; + if (hci_dump_impl == NULL) { + return; + } + if (packet_log_enabled == false) { + return; + } + if (max_nr_packets > 0){ if ((nr_packets >= max_nr_packets) && (hci_dump_impl->reset != NULL)) { nr_packets = 0; diff --git a/src/hci_dump.h b/src/hci_dump.h index 273281831..312926486 100644 --- a/src/hci_dump.h +++ b/src/hci_dump.h @@ -48,6 +48,7 @@ #include #include // for va_list +#include "btstack_bool.h" #ifdef __AVR__ #include @@ -85,18 +86,29 @@ typedef struct { #endif } hci_dump_t; -/* +/** * @brief Init HCI Dump * @param hci_dump_impl - platform-specific implementation */ void hci_dump_init(const hci_dump_t * hci_dump_impl); +/** + * @brief Enable packet logging + * @param enabled default: true + */ +void hci_dump_enable_packet_log(bool enabled); + +/** + * @brief + */ +void hci_dump_enable_log_level(int log_level, int enable); + /* * @brief Set max number of packets - output file might be truncated */ void hci_dump_set_max_packets(int packets); // -1 for unlimited -/* +/** * @brief Dump Packet * @param packet_type * @param in is 1 for incoming, 0 for outoing @@ -105,7 +117,7 @@ void hci_dump_set_max_packets(int packets); // -1 for unlimited */ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len); -/* +/** * @brief Dump Message * @param log_level * @param format @@ -149,11 +161,6 @@ void hci_dump_setup_header_packetlogger(uint8_t * buffer, uint32_t tv_sec, uint3 */ void hci_dump_setup_header_bluez(uint8_t * buffer, uint32_t tv_sec, uint32_t tv_us, uint8_t packet_type, uint8_t in, uint16_t len); -/* - * @brief - */ -void hci_dump_enable_log_level(int log_level, int enable); - /* API_END */