hsp_hs_test work in progress

This commit is contained in:
Matthias Ringwald 2015-11-12 23:07:36 +01:00
parent 694df8bf19
commit ad8e5e09eb

View File

@ -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 uint8_t rfcomm_channel_nr = 1;
const char hsp_hs_service_name[] = "Headset Test"; const char hsp_hs_service_name[] = "Headset Test";
static uint16_t sco_handle = 0; 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 = {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 = {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 = {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 bd_addr_t current_addr;
static char hs_cmd_buffer[100]; static char hs_cmd_buffer[100];
@ -92,7 +93,7 @@ static char hs_cmd_buffer[100];
// portaudio globals // portaudio globals
static PaStream * stream; static PaStream * stream;
static int8_t sine[TABLE_SIZE]; static int8_t sine[TABLE_SIZE];
static int phase = 0; int phase = 0;
// prototypes // prototypes
static void show_usage(); static void show_usage();
@ -207,13 +208,15 @@ static int stdin_process(struct data_source *ds){
return 0; return 0;
} }
#if 0
static void try_send_sco(void){ static void try_send_sco(void){
printf("try send handle %x\n", sco_handle);
if (!sco_handle) return; if (!sco_handle) return;
if (!hci_can_send_sco_packet_now(sco_handle)) { if (!hci_can_send_sco_packet_now(sco_handle)) {
printf("try_send_sco, cannot send now\n"); printf("try_send_sco, cannot send now\n");
return; return;
} }
const int frames_per_packet = 20; const int frames_per_packet = 9;
hci_reserve_packet_buffer(); hci_reserve_packet_buffer();
uint8_t * sco_packet = hci_get_outgoing_packet_buffer(); uint8_t * sco_packet = hci_get_outgoing_packet_buffer();
// set handle + flags // set handle + flags
@ -226,16 +229,26 @@ static void try_send_sco(void){
phase++; phase++;
if (phase >= TABLE_SIZE) phase = 0; 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){ static void packet_handler(uint8_t * event, uint16_t event_size){
// printf("Packet handler event 0x%02x\n", event[0]); // printf("Packet handler event 0x%02x\n", event[0]);
// try_send_sco(); // try_send_sco();
switch (event[0]) { 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: case DAEMON_EVENT_HCI_PACKET_SENT:
// printf("DAEMON_EVENT_HCI_PACKET_SENT\n"); // printf("DAEMON_EVENT_HCI_PACKET_SENT\n");
try_send_sco(); // try_send_sco();
break; break;
case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE: case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE:
// printf("HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE status %u, %x\n", event[2], READ_BT_16(event, 3)); // 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: case HSP_SUBEVENT_AUDIO_CONNECTION_COMPLETE:
if (event[3] == 0){ if (event[3] == 0){
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle); printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
try_send_sco(); // try_send_sco();
} else { } else {
printf("Audio connection establishment failed with status %u\n", event[3]); printf("Audio connection establishment failed with status %u\n", event[3]);
} }