mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
enable HCI packet logs to console for EMBEDDED
This commit is contained in:
parent
41d81c3411
commit
198a9e1b41
@ -52,12 +52,12 @@
|
|||||||
#include "hci.h"
|
#include "hci.h"
|
||||||
#include "hci_transport.h"
|
#include "hci_transport.h"
|
||||||
#include <btstack/hci_cmds.h>
|
#include <btstack/hci_cmds.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#ifndef EMBEDDED
|
#ifndef EMBEDDED
|
||||||
#include <fcntl.h> // open
|
#include <fcntl.h> // open
|
||||||
#include <arpa/inet.h> // hton..
|
#include <arpa/inet.h> // hton..
|
||||||
#include <unistd.h> // write
|
#include <unistd.h> // write
|
||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h> // for timestamps
|
#include <sys/time.h> // for timestamps
|
||||||
#include <sys/stat.h> // for mode flags
|
#include <sys/stat.h> // for mode flags
|
||||||
@ -90,8 +90,8 @@ __attribute__ ((packed))
|
|||||||
#endif
|
#endif
|
||||||
pktlog_hdr;
|
pktlog_hdr;
|
||||||
|
|
||||||
#ifndef EMBEDDED
|
|
||||||
static int dump_file = -1;
|
static int dump_file = -1;
|
||||||
|
#ifndef EMBEDDED
|
||||||
static int dump_format;
|
static int dump_format;
|
||||||
static hcidump_hdr header_bluez;
|
static hcidump_hdr header_bluez;
|
||||||
static pktlog_hdr header_packetlogger;
|
static pktlog_hdr header_packetlogger;
|
||||||
@ -102,7 +102,9 @@ static char log_message_buffer[256];
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void hci_dump_open(const char *filename, hci_dump_format_t format){
|
void hci_dump_open(const char *filename, hci_dump_format_t format){
|
||||||
#ifndef EMBEDDED
|
#ifdef EMBEDDED
|
||||||
|
dump_file = 1;
|
||||||
|
#else
|
||||||
dump_format = format;
|
dump_format = format;
|
||||||
if (dump_format == HCI_DUMP_STDOUT) {
|
if (dump_format == HCI_DUMP_STDOUT) {
|
||||||
dump_file = fileno(stdout);
|
dump_file = fileno(stdout);
|
||||||
@ -118,11 +120,37 @@ void hci_dump_set_max_packets(int packets){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static inline 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 => ");
|
||||||
|
break;
|
||||||
|
case HCI_EVENT_PACKET:
|
||||||
|
printf("EVT <= ");
|
||||||
|
break;
|
||||||
|
case HCI_ACL_DATA_PACKET:
|
||||||
|
if (in) {
|
||||||
|
printf("ACL <= ");
|
||||||
|
} else {
|
||||||
|
printf("ACL => ");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LOG_MESSAGE_PACKET:
|
||||||
|
printf("LOG -- %s\n", (char*) packet);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf_hexdump(packet, len);
|
||||||
|
}
|
||||||
|
|
||||||
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) {
|
||||||
#ifndef EMBEDDED
|
|
||||||
|
|
||||||
if (dump_file < 0) return; // not activated yet
|
if (dump_file < 0) return; // not activated yet
|
||||||
|
|
||||||
|
#ifdef EMBEDDED
|
||||||
|
printf_packet(packet_type, in, packet, len);
|
||||||
|
#else
|
||||||
// don't grow bigger than max_nr_packets
|
// don't grow bigger than max_nr_packets
|
||||||
if (dump_format != HCI_DUMP_STDOUT && max_nr_packets > 0){
|
if (dump_format != HCI_DUMP_STDOUT && max_nr_packets > 0){
|
||||||
if (nr_packets >= max_nr_packets){
|
if (nr_packets >= max_nr_packets){
|
||||||
@ -149,29 +177,7 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t
|
|||||||
/* Print the formatted time, in seconds, followed by a decimal point
|
/* Print the formatted time, in seconds, followed by a decimal point
|
||||||
and the milliseconds. */
|
and the milliseconds. */
|
||||||
printf ("%s.%03u] ", time_string, milliseconds);
|
printf ("%s.%03u] ", time_string, milliseconds);
|
||||||
switch (packet_type){
|
printf_packet(packet_type, in, packet, len);
|
||||||
case HCI_COMMAND_DATA_PACKET:
|
|
||||||
printf("CMD => ");
|
|
||||||
break;
|
|
||||||
case HCI_EVENT_PACKET:
|
|
||||||
printf("EVT <= ");
|
|
||||||
break;
|
|
||||||
case HCI_ACL_DATA_PACKET:
|
|
||||||
if (in) {
|
|
||||||
printf("ACL <= ");
|
|
||||||
} else {
|
|
||||||
printf("ACL => ");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LOG_MESSAGE_PACKET:
|
|
||||||
// assume buffer is big enough
|
|
||||||
packet[len] = 0;
|
|
||||||
printf("LOG -- %s\n", (char*) packet);
|
|
||||||
return;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
printf_hexdump(packet, len);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user