From ad8e5e09ebbf645048a683d554ee8d378ad42a86 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 12 Nov 2015 23:07:36 +0100 Subject: [PATCH] hsp_hs_test work in progress --- test/pts/hsp_hs_test.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/pts/hsp_hs_test.c b/test/pts/hsp_hs_test.c index b5c46e329..2591af2ee 100644 --- a/test/pts/hsp_hs_test.c +++ b/test/pts/hsp_hs_test.c @@ -81,10 +81,11 @@ const uint32_t hsp_service_buffer[150/4]; // implicit alignment to 4-byte memo const uint8_t rfcomm_channel_nr = 1; const char hsp_hs_service_name[] = "Headset Test"; static uint16_t sco_handle = 0; -static bd_addr_t pts_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF}; +static bd_addr_t pts_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF}; // PTS dongle static bd_addr_t local_mac = {0x04, 0x0C, 0xCE, 0xE4, 0x85, 0xD3}; // MacBook Air 2011 // static bd_addr_t local_mac = {0x84, 0x38, 0x35, 0x65, 0xD1, 0x15}; // MacBook Air 2013 // static bd_addr_t local_mac = {0x54, 0xe4, 0x3a, 0x26, 0xa2, 0x39}; // iPhone 5S +// static bd_addr_t local_mac = {0x00,0x1a,0x7d,0xda,0x71,0x0a}; // CSR Dongle static bd_addr_t current_addr; static char hs_cmd_buffer[100]; @@ -92,7 +93,7 @@ static char hs_cmd_buffer[100]; // portaudio globals static PaStream * stream; static int8_t sine[TABLE_SIZE]; -static int phase = 0; +int phase = 0; // prototypes static void show_usage(); @@ -207,13 +208,15 @@ static int stdin_process(struct data_source *ds){ return 0; } +#if 0 static void try_send_sco(void){ + printf("try send handle %x\n", sco_handle); if (!sco_handle) return; if (!hci_can_send_sco_packet_now(sco_handle)) { printf("try_send_sco, cannot send now\n"); return; } - const int frames_per_packet = 20; + const int frames_per_packet = 9; hci_reserve_packet_buffer(); uint8_t * sco_packet = hci_get_outgoing_packet_buffer(); // set handle + flags @@ -226,16 +229,26 @@ static void try_send_sco(void){ phase++; if (phase >= TABLE_SIZE) phase = 0; } - hci_send_sco_packet_buffer(frames_per_packet); + hci_send_sco_packet_buffer(3 + frames_per_packet); } +#endif static void packet_handler(uint8_t * event, uint16_t event_size){ // printf("Packet handler event 0x%02x\n", event[0]); // try_send_sco(); switch (event[0]) { + case BTSTACK_EVENT_STATE: + if (event[2] != HCI_STATE_WORKING) break; + // request loopback mode + hci_send_cmd(&hci_write_synchronous_flow_control_enable, 1); + break; + case HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS: + // printf("HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS\n"); + // try_send_sco(); + break; case DAEMON_EVENT_HCI_PACKET_SENT: // printf("DAEMON_EVENT_HCI_PACKET_SENT\n"); - try_send_sco(); + // try_send_sco(); break; case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE: // printf("HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE status %u, %x\n", event[2], READ_BT_16(event, 3)); @@ -247,7 +260,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE: if (event[3] == 0){ printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); - try_send_sco(); + // try_send_sco(); } else { printf("Audio connection establishment failed with status %u\n", event[3]); }