mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-25 09:35:42 +00:00
allow to enable/disable log_info and log_debug for HAVE_HCI_DUMP
This commit is contained in:
parent
52a6864fcb
commit
8a37b10a01
10
src/debug.h
10
src/debug.h
@ -62,16 +62,16 @@ static inline void __log_unused(const char *format, ...) {
|
||||
#endif
|
||||
|
||||
#ifdef __AVR__
|
||||
#define HCI_DUMP_LOG(format, ...) hci_dump_log_P(PSTR(format), ## __VA_ARGS__)
|
||||
#define HCI_DUMP_LOG(log_level, format, ...) hci_dump_log_P(log_level, PSTR(format), ## __VA_ARGS__)
|
||||
#define PRINTF(format, ...) printf_P(PSTR(format), ## __VA_ARGS__)
|
||||
#else
|
||||
#define HCI_DUMP_LOG(format, ...) hci_dump_log(format, ## __VA_ARGS__)
|
||||
#define HCI_DUMP_LOG(log_level, format, ...) hci_dump_log(log_level, format, ## __VA_ARGS__)
|
||||
#define PRINTF(format, ...) printf(format, ## __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_LOG_DEBUG
|
||||
#ifdef HAVE_HCI_DUMP
|
||||
#define log_debug(format, ...) HCI_DUMP_LOG(format, ## __VA_ARGS__)
|
||||
#define log_debug(format, ...) HCI_DUMP_LOG(LOG_LEVEL_DEBUG, format, ## __VA_ARGS__)
|
||||
#else
|
||||
#define log_debug(format, ...) PRINTF(format "\n", ## __VA_ARGS__)
|
||||
#endif
|
||||
@ -81,7 +81,7 @@ static inline void __log_unused(const char *format, ...) {
|
||||
|
||||
#ifdef ENABLE_LOG_INFO
|
||||
#ifdef HAVE_HCI_DUMP
|
||||
#define log_info(format, ...) HCI_DUMP_LOG(format, ## __VA_ARGS__)
|
||||
#define log_info(format, ...) HCI_DUMP_LOG(LOG_LEVEL_INFO, format, ## __VA_ARGS__)
|
||||
#else
|
||||
#define log_info(format, ...) PRINTF(format "\n", ## __VA_ARGS__)
|
||||
#endif
|
||||
@ -91,7 +91,7 @@ static inline void __log_unused(const char *format, ...) {
|
||||
|
||||
#ifdef ENABLE_LOG_ERROR
|
||||
#ifdef HAVE_HCI_DUMP
|
||||
#define log_error(format, ...) HCI_DUMP_LOG(format, ## __VA_ARGS__)
|
||||
#define log_error(format, ...) HCI_DUMP_LOG(LOG_LEVEL_ERROR, format, ## __VA_ARGS__)
|
||||
#else
|
||||
#define log_error(format, ...) PRINTF(format "\n", ## __VA_ARGS__)
|
||||
#endif
|
||||
|
@ -102,6 +102,9 @@ static int nr_packets = 0;
|
||||
static char log_message_buffer[256];
|
||||
#endif
|
||||
|
||||
// levels: debug, info, error
|
||||
static int log_level_enabled[3] = { 1, 1, 1};
|
||||
|
||||
void hci_dump_open(const char *filename, hci_dump_format_t format){
|
||||
#ifdef EMBEDDED
|
||||
dump_file = 1;
|
||||
@ -125,7 +128,7 @@ void hci_dump_set_max_packets(int packets){
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void printf_packet(uint8_t packet_type, uint8_t in, uint8_t * packet, uint16_t len){
|
||||
static void printf_packet(uint8_t packet_type, uint8_t in, uint8_t * packet, uint16_t len){
|
||||
switch (packet_type){
|
||||
case HCI_COMMAND_DATA_PACKET:
|
||||
printf("CMD => ");
|
||||
@ -243,8 +246,14 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t
|
||||
#endif
|
||||
}
|
||||
|
||||
void hci_dump_log(const char * format, ...){
|
||||
if (dump_file < 0) return; // not activated yet
|
||||
static int hci_dump_log_level_active(int log_level){
|
||||
if (log_level < 0) return 0;
|
||||
if (log_level > LOG_LEVEL_ERROR) return 0;
|
||||
return log_level_enabled[log_level];
|
||||
}
|
||||
|
||||
void hci_dump_log(int log_level, const char * format, ...){
|
||||
if (!hci_dump_log_level_active(log_level)) return;
|
||||
va_list argptr;
|
||||
va_start(argptr, format);
|
||||
#ifdef EMBEDDED
|
||||
@ -259,8 +268,8 @@ void hci_dump_log(const char * format, ...){
|
||||
}
|
||||
|
||||
#ifdef __AVR__
|
||||
void hci_dump_log_P(PGM_P format, ...){
|
||||
if (dump_file < 0) return; // not activated yet
|
||||
void hci_dump_log_P(int log_level, PGM_P format, ...){
|
||||
if (!hci_dump_log_level_active(log_level)) return;
|
||||
va_list argptr;
|
||||
va_start(argptr, format);
|
||||
printf_P(PSTR("LOG -- "));
|
||||
@ -277,3 +286,9 @@ void hci_dump_close(void){
|
||||
#endif
|
||||
}
|
||||
|
||||
void hci_dump_enable_log_level(int log_level, int enable){
|
||||
if (log_level < 0) return;
|
||||
if (log_level > LOG_LEVEL_ERROR) return;
|
||||
log_level_enabled[log_level] = enable;
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LOG_LEVEL_DEBUG 0
|
||||
#define LOG_LEVEL_INFO 1
|
||||
#define LOG_LEVEL_ERROR 2
|
||||
|
||||
typedef enum {
|
||||
HCI_DUMP_BLUEZ = 0,
|
||||
HCI_DUMP_PACKETLOGGER,
|
||||
@ -65,11 +69,12 @@ typedef enum {
|
||||
void hci_dump_open(const char *filename, hci_dump_format_t format);
|
||||
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);
|
||||
void hci_dump_log(const char * format, ...);
|
||||
void hci_dump_log(int log_level, const char * format, ...);
|
||||
void hci_dump_enable_log_level(int log_level, int enable);
|
||||
void hci_dump_close(void);
|
||||
|
||||
#ifdef __AVR__
|
||||
void hci_dump_log_P(PGM_P format, ...);
|
||||
void hci_dump_log_P(int log_level, PGM_P format, ...);
|
||||
#endif
|
||||
|
||||
#if defined __cplusplus
|
||||
|
Loading…
x
Reference in New Issue
Block a user