mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 01:27:41 +00:00
provide _va_arg type variants for hci_send_cmd and hci_dump_log
This commit is contained in:
parent
74dbc779e1
commit
94be1a6633
19
src/hci.c
19
src/hci.c
@ -3069,11 +3069,8 @@ void gap_ssp_set_auto_accept(int auto_accept){
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* pre: numcmds >= 0 - it's allowed to send a command to the controller
|
||||
*/
|
||||
int hci_send_cmd(const hci_cmd_t *cmd, ...){
|
||||
|
||||
// va_list part of hci_send_cmd
|
||||
int hci_send_cmd_va_arg(const hci_cmd_t *cmd, va_list argptr){
|
||||
if (!hci_can_send_command_packet_now()){
|
||||
log_error("hci_send_cmd called but cannot send packet now");
|
||||
return 0;
|
||||
@ -3085,13 +3082,19 @@ int hci_send_cmd(const hci_cmd_t *cmd, ...){
|
||||
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t * packet = hci_stack->hci_packet_buffer;
|
||||
uint16_t size = hci_cmd_create_from_template(packet, cmd, argptr);
|
||||
return hci_send_cmd_packet(packet, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* pre: numcmds >= 0 - it's allowed to send a command to the controller
|
||||
*/
|
||||
int hci_send_cmd(const hci_cmd_t *cmd, ...){
|
||||
va_list argptr;
|
||||
va_start(argptr, cmd);
|
||||
uint16_t size = hci_cmd_create_from_template(packet, cmd, argptr);
|
||||
int res = hci_send_cmd_va_arg(cmd, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
return hci_send_cmd_packet(packet, size);
|
||||
return res;
|
||||
}
|
||||
|
||||
// Create various non-HCI events.
|
||||
|
@ -900,6 +900,10 @@ void hci_release_packet_buffer(void);
|
||||
/* API_END */
|
||||
|
||||
|
||||
/**
|
||||
* va_list version of hci_send_cmd
|
||||
*/
|
||||
int hci_send_cmd_va_arg(const hci_cmd_t *cmd, va_list argtr);
|
||||
|
||||
/**
|
||||
* Get connection iterator. Only used by l2cap.c and sm.c
|
||||
|
@ -62,7 +62,6 @@
|
||||
#include <time.h>
|
||||
#include <sys/time.h> // for timestamps
|
||||
#include <sys/stat.h> // for mode flags
|
||||
#include <stdarg.h> // for va_list
|
||||
#endif
|
||||
|
||||
// BLUEZ hcidump - struct not used directly, but left here as documentation
|
||||
@ -265,19 +264,24 @@ static int hci_dump_log_level_active(int log_level){
|
||||
return log_level_enabled[log_level];
|
||||
}
|
||||
|
||||
void hci_dump_log_va_arg(int log_level, const char * format, va_list argptr){
|
||||
if (hci_dump_log_level_active(log_level)) {
|
||||
#ifdef HAVE_POSIX_FILE_IO
|
||||
int len = vsnprintf(log_message_buffer, sizeof(log_message_buffer), format, argptr);
|
||||
hci_dump_packet(LOG_MESSAGE_PACKET, 0, (uint8_t*) log_message_buffer, len);
|
||||
#else
|
||||
printf_timestamp();
|
||||
printf("LOG -- ");
|
||||
vprintf(format, argptr);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
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 HAVE_POSIX_FILE_IO
|
||||
int len = vsnprintf(log_message_buffer, sizeof(log_message_buffer), format, argptr);
|
||||
hci_dump_packet(LOG_MESSAGE_PACKET, 0, (uint8_t*) log_message_buffer, len);
|
||||
#else
|
||||
printf_timestamp();
|
||||
printf("LOG -- ");
|
||||
vprintf(format, argptr);
|
||||
printf("\n");
|
||||
#endif
|
||||
hci_dump_log_va_arg(log_level, format, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@
|
||||
#define __HCI_DUMP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h> // for va_list
|
||||
|
||||
#ifdef __AVR__
|
||||
#include <avr/pgmspace.h>
|
||||
@ -104,6 +105,8 @@ void hci_dump_close(void);
|
||||
|
||||
/* API_END */
|
||||
|
||||
void hci_dump_log_va_arg(int log_level, const char * format, va_list argtr);
|
||||
|
||||
#ifdef __AVR__
|
||||
void hci_dump_log_P(int log_level, PGM_P format, ...);
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user