hci_dump: add hci_dump_enable_packet_log to enable/disable packet logging

This commit is contained in:
Matthias Ringwald 2021-03-23 11:24:05 +01:00
parent a5cfd2f568
commit cdc66b5eb8
2 changed files with 28 additions and 9 deletions

View File

@ -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;

View File

@ -48,6 +48,7 @@
#include <stdint.h>
#include <stdarg.h> // for va_list
#include "btstack_bool.h"
#ifdef __AVR__
#include <avr/pgmspace.h>
@ -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 */