mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-30 07:21:20 +00:00
hci_dump: use printf for log_... if packet log is not open on posix
This commit is contained in:
parent
e950fa96e9
commit
6401061a3c
@ -164,8 +164,23 @@ static void printf_packet(uint8_t packet_type, uint8_t in, uint8_t * packet, uin
|
|||||||
printf_hexdump(packet, len);
|
printf_hexdump(packet, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_POSIX_FILE_IO
|
|
||||||
static void printf_timestamp(void){
|
static void printf_timestamp(void){
|
||||||
|
#ifdef HAVE_POSIX_FILE_IO
|
||||||
|
struct tm* ptm;
|
||||||
|
struct timeval curr_time;
|
||||||
|
gettimeofday(&curr_time, NULL);
|
||||||
|
time_t curr_time_secs = curr_time.tv_sec;
|
||||||
|
/* Obtain the time of day, and convert it to a tm struct. */
|
||||||
|
ptm = localtime (&curr_time_secs);
|
||||||
|
/* assert localtime was successful */
|
||||||
|
if (!ptm) return;
|
||||||
|
/* Format the date and time, down to a single second. */
|
||||||
|
strftime (time_string, sizeof (time_string), "[%Y-%m-%d %H:%M:%S", ptm);
|
||||||
|
/* Compute milliseconds from microseconds. */
|
||||||
|
uint16_t milliseconds = curr_time.tv_usec / 1000;
|
||||||
|
/* Print the formatted time, in seconds, followed by a decimal point and the milliseconds. */
|
||||||
|
printf ("%s.%03u] ", time_string, milliseconds);
|
||||||
|
#else
|
||||||
uint32_t time_ms = btstack_run_loop_get_time_ms();
|
uint32_t time_ms = btstack_run_loop_get_time_ms();
|
||||||
int seconds = time_ms / 1000;
|
int seconds = time_ms / 1000;
|
||||||
int minutes = seconds / 60;
|
int minutes = seconds / 60;
|
||||||
@ -175,8 +190,8 @@ static void printf_timestamp(void){
|
|||||||
uint16_t p_seconds = seconds - (minutes * 60);
|
uint16_t p_seconds = seconds - (minutes * 60);
|
||||||
uint16_t p_minutes = minutes - (hours * 60);
|
uint16_t p_minutes = minutes - (hours * 60);
|
||||||
printf("[%02u:%02u:%02u.%03u] ", hours, p_minutes, p_seconds, p_ms);
|
printf("[%02u:%02u:%02u.%03u] ", hours, p_minutes, p_seconds, p_ms);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) {
|
void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) {
|
||||||
|
|
||||||
@ -196,22 +211,11 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t
|
|||||||
|
|
||||||
// get time
|
// get time
|
||||||
struct timeval curr_time;
|
struct timeval curr_time;
|
||||||
struct tm* ptm;
|
|
||||||
gettimeofday(&curr_time, NULL);
|
gettimeofday(&curr_time, NULL);
|
||||||
time_t curr_time_secs = curr_time.tv_sec;
|
|
||||||
|
|
||||||
switch (dump_format){
|
switch (dump_format){
|
||||||
case HCI_DUMP_STDOUT: {
|
case HCI_DUMP_STDOUT: {
|
||||||
/* Obtain the time of day, and convert it to a tm struct. */
|
printf_timestamp();
|
||||||
ptm = localtime (&curr_time_secs);
|
|
||||||
/* assert localtime was successful */
|
|
||||||
if (!ptm) break;
|
|
||||||
/* Format the date and time, down to a single second. */
|
|
||||||
strftime (time_string, sizeof (time_string), "[%Y-%m-%d %H:%M:%S", ptm);
|
|
||||||
/* Compute milliseconds from microseconds. */
|
|
||||||
uint16_t milliseconds = curr_time.tv_usec / 1000;
|
|
||||||
/* Print the formatted time, in seconds, followed by a decimal point and the milliseconds. */
|
|
||||||
printf ("%s.%03u] ", time_string, milliseconds);
|
|
||||||
printf_packet(packet_type, in, packet, len);
|
printf_packet(packet_type, in, packet, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -280,17 +284,19 @@ static int hci_dump_log_level_active(int log_level){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void hci_dump_log_va_arg(int log_level, const char * format, va_list argptr){
|
void hci_dump_log_va_arg(int log_level, const char * format, va_list argptr){
|
||||||
if (hci_dump_log_level_active(log_level)) {
|
if (!hci_dump_log_level_active(log_level)) return;
|
||||||
|
|
||||||
#ifdef HAVE_POSIX_FILE_IO
|
#ifdef HAVE_POSIX_FILE_IO
|
||||||
|
if (dump_file >= 0){
|
||||||
int len = vsnprintf(log_message_buffer, sizeof(log_message_buffer), format, argptr);
|
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);
|
hci_dump_packet(LOG_MESSAGE_PACKET, 0, (uint8_t*) log_message_buffer, len);
|
||||||
#else
|
|
||||||
printf_timestamp();
|
|
||||||
printf("LOG -- ");
|
|
||||||
vprintf(format, argptr);
|
|
||||||
printf("\n");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
printf_timestamp();
|
||||||
|
printf("LOG -- ");
|
||||||
|
vprintf(format, argptr);
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void hci_dump_log(int log_level, const char * format, ...){
|
void hci_dump_log(int log_level, const char * format, ...){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user