diff --git a/src/hci_dump.c b/src/hci_dump.c index 995f7f271..9af2b12b5 100644 --- a/src/hci_dump.c +++ b/src/hci_dump.c @@ -150,6 +150,20 @@ static void printf_packet(uint8_t packet_type, uint8_t in, uint8_t * packet, uin printf_hexdump(packet, len); } +#ifndef HAVE_POSIX_FILE_IO +static void printf_timestamp(void){ + uint32_t time_ms = btstack_run_loop_get_time_ms(); + int seconds = time_ms / 1000; + int minutes = seconds / 60; + int hours = minutes / 60; + + int p_ms = time_ms - (seconds * 1000); + int p_seconds = seconds - (minutes * 60); + int p_minutes = minutes - (hours * 60); + printf("[%02u:%02u:%02u.%03u] ", hours, p_minutes, p_seconds, p_ms); +} +#endif + void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) { if (dump_file < 0) return; // not activated yet @@ -239,10 +253,7 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t } #else -// #ifdef HAVE_EMBEDDED_TICK -// uint32_t time_ms = btstack_run_loop_embedded_get_time_ms(); -// printf("[%06u] ", time_ms); -// #endif + printf_timestamp(); printf_packet(packet_type, in, packet, len); #endif @@ -262,6 +273,7 @@ void hci_dump_log(int log_level, const char * format, ...){ 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"); diff --git a/tool/create_packet_log.py b/tool/create_packet_log.py index 7e54639c7..090dea736 100755 --- a/tool/create_packet_log.py +++ b/tool/create_packet_log.py @@ -17,8 +17,10 @@ import sys import time import os +default_date="2001-01-01" +default_hours = 12 packet_counter = 0 -last_time = None +last_time = default_date + " " + str(default_hours) + ":00:00.000" def chop(line, prefix): if line.startswith(prefix): @@ -42,17 +44,30 @@ def generateTimestamp(t): t = last_time if t: last_time = t + + # check for date + parts = t.split(' ') + have_date = True + if len(parts) == 1: + # only time, prepend fixed date + have_date = False + t = "2000-01-01 " + t; + # handle ms try: (t1, t2) = t.split('.') if t1 and t2: - t_obj = time.strptime(t1, "%Y-%m-%d %H:%M:%S") + t_obj = time.strptime(t1, "%Y-%m-%d %H:%M:%S") tv_sec = int(time.mktime(t_obj)) + if not have_date: + # start at 12:00 + tv_sec += 12*60*60 tv_usec = int(t2) * 1000 return (tv_sec, tv_usec) except ValueError: # print 'Cannot parse time', t pass + packet_counter += 1 return (packet_counter, 0) @@ -91,7 +106,7 @@ with open (outfile, 'wb') as fout: packet_counter = 0 for line in fin: timestamp = None - parts = parts = re.match('\[(.*)\] (.*)', line) + parts = re.match('\[(.*)\] (.*)', line) if parts and len(parts.groups()) == 2: (timestamp, line) = parts.groups() rest = chop(line,'CMD => ')