autoconnect if STDIN is not defined

This commit is contained in:
Milanka Ringwald 2017-08-22 14:43:50 +02:00
parent 695025bf1c
commit 05d93378f0
4 changed files with 74 additions and 31 deletions

View File

@ -93,8 +93,8 @@ static const int16_t sine_int16[] = {
};
static const char * device_name = "A2DP Source Demo 00:00:00:00:00:00";
static btstack_packet_callback_registration_t hci_event_callback_registration;
#ifdef HAVE_BTSTACK_STDIN
// mac 2011: static const char * device_addr_string = "04:0C:CE:E4:85:D3";
// pts: static const char * device_addr_string = "00:1B:DC:08:0A:A5";
// mac 2013: static const char * device_addr_string = "84:38:35:65:d1:15";
@ -103,7 +103,6 @@ static const char * device_name = "A2DP Source Demo 00:00:00:00:00:00";
static const char * device_addr_string = "00:21:3C:AC:F7:38";
// head phones: static const char * device_addr_string = "00:18:09:28:50:18";
// bt dongle: static const char * device_addr_string = "00:15:83:5F:9D:46";
#endif
static bd_addr_t device_addr;
static uint8_t sdp_a2dp_source_service_buffer[150];
@ -303,6 +302,19 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
bd_addr_t address;
if (packet_type != HCI_EVENT_PACKET) return;
#ifndef HAVE_BTSTACK_STDIN
if (hci_event_packet_get_type(packet) == BTSTACK_EVENT_STATE){
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
printf("Create AVDTP Source connection to addr %s.\n", bd_addr_to_str(device_addr));
status = a2dp_source_establish_stream(device_addr, media_tracker.local_seid, &media_tracker.a2dp_cid);
if (status != ERROR_CODE_SUCCESS){
printf("Could not perform command, status 0x%2x\n", status);
}
return;
}
#endif
if (hci_event_packet_get_type(packet) != HCI_EVENT_A2DP_META) return;
switch (packet[2]){
@ -507,6 +519,10 @@ int btstack_main(int argc, const char * argv[]){
UNUSED(argc);
(void)argv;
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
l2cap_init();
// Initialize AVDTP Source
a2dp_source_init();
@ -549,9 +565,10 @@ int btstack_main(int argc, const char * argv[]){
now_playing_info.total_tracks = 10;
now_playing_info.song_length_ms = 3655;
#ifdef HAVE_BTSTACK_STDIN
// parse human readable Bluetooth address
sscanf_bd_addr(device_addr_string, device_addr);
#ifdef HAVE_BTSTACK_STDIN
btstack_stdin_setup(stdin_process);
#endif
// turn on!

View File

@ -67,7 +67,7 @@ const uint8_t rfcomm_channel_nr = 1;
const char hfp_ag_service_name[] = "HFP AG Demo";
static bd_addr_t device_addr;
static const char * device_addr_string = "00:15:83:5F:9D:46";
static const char * device_addr_string = "00:21:3C:AC:F7:38";
#ifdef ENABLE_HFP_WIDE_BAND_SPEECH
static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC};
@ -141,8 +141,8 @@ static void show_usage(void){
printf("\n--- Bluetooth HFP Audiogateway (AG) unit Test Console %s ---\n", bd_addr_to_str(iut_address));
printf("\n");
printf("a - establish HFP connection to PTS module %s\n", bd_addr_to_str(device_addr));
// printf("A - release HFP connection to PTS module\n");
printf("a - establish HFP connection to %s\n", bd_addr_to_str(device_addr));
// printf("A - release HFP connection\n");
printf("b - establish AUDIO connection | B - release AUDIO connection\n");
printf("c - simulate incoming call from 1234567 | C - simulate call from 1234567 dropped\n");
@ -176,7 +176,7 @@ static void stdin_process(char cmd){
switch (cmd){
case 'a':
log_info("USER:\'%c\'", cmd);
printf("Establish HFP service level connection to PTS module %s...\n", bd_addr_to_str(device_addr));
printf("Establish HFP service level connection to %s...\n", bd_addr_to_str(device_addr));
hfp_ag_establish_service_level_connection(device_addr);
break;
case 'A':
@ -395,9 +395,17 @@ static void stdin_process(char cmd){
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
UNUSED(channel);
bd_addr_t addr;
uint8_t status;
switch (packet_type){
case HCI_EVENT_PACKET:
switch (event[0]){
switch(hci_event_packet_get_type(event)){
#ifndef HAVE_BTSTACK_STDIN
case BTSTACK_EVENT_STATE:
if (btstack_event_state_get_state(event) != HCI_STATE_WORKING) break;
printf("Establish HFP AG service level connection to %s...\n", bd_addr_to_str(device_addr));
hfp_ag_establish_service_level_connection(device_addr);
break;
#endif
case GAP_EVENT_INQUIRY_RESULT:
gap_event_inquiry_result_get_bd_addr(event, addr);
// print info
@ -430,23 +438,33 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
break;
}
if (event[0] != HCI_EVENT_HFP_META) return;
if (hci_event_packet_get_type(event) != HCI_EVENT_HFP_META) return;
if (event[3]
&& event[2] != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER
&& event[2] != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG
&& event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES){
&& hci_event_hfp_meta_get_subevent_code(event) != HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER
&& hci_event_hfp_meta_get_subevent_code(event) != HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG
&& hci_event_hfp_meta_get_subevent_code(event) != HFP_SUBEVENT_TRANSMIT_DTMF_CODES){
printf("ERROR, status: %u\n", event[3]);
return;
}
switch (event[2]) {
switch (hci_event_hfp_meta_get_subevent_code(event)) {
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
status = hfp_subevent_service_level_connection_established_get_status(event);
if (status){
printf("Connection failed, staus 0x%02x\n", status);
break;
}
acl_handle = hfp_subevent_service_level_connection_established_get_con_handle(event);
hfp_subevent_service_level_connection_established_get_bd_addr(event, device_addr);
printf("Service level connection established from %s.\n", bd_addr_to_str(device_addr));
printf("Service level connection established to %s.\n", bd_addr_to_str(device_addr));
dump_supported_codecs();
break;
#ifndef HAVE_BTSTACK_STDIN
log_info("Establish Audio connection %s", bd_addr_to_str(device_addr));
printf("Establish Audio connection %s...\n", bd_addr_to_str(device_addr));
hfp_ag_establish_audio_connection(acl_handle);
#endif
break;
case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_RELEASED:
printf("Service level connection released.\n");
sco_handle = 0;
@ -511,7 +529,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
printf("Call answered by HF\n");
break;
default:
printf("Event not handled %u\n", event[2]);
printf("Event not handled %u\n", hci_event_hfp_meta_get_subevent_code(event));
break;
}
break;

View File

@ -71,7 +71,9 @@ static uint16_t sco_handle = 0;
static char hs_cmd_buffer[100];
static bd_addr_t device_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
static const char * device_name = "HSP AG Demo 00:00:00:00:00:00";
static const char * device_addr_string = "00:1b:dc:07:32:ef";
static bd_addr_t device_addr;
/* @section Audio Transfer Setup
*
@ -97,6 +99,8 @@ static bd_addr_t device_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
*/
#ifdef HAVE_BTSTACK_STDIN
static void show_usage(void){
bd_addr_t iut_address;
gap_local_bd_addr(iut_address);
@ -104,7 +108,7 @@ static void show_usage(void){
printf("\n--- Bluetooth HSP Audio Gateway Test Console %s ---\n", bd_addr_to_str(iut_address));
printf("---\n");
printf("c - Connect to %s\n", bd_addr_to_str(device_addr));
printf("c - Connect to %s\n", device_addr_string);
printf("C - Disconnect\n");
printf("a - establish audio connection\n");
printf("A - release audio connection\n");
@ -118,11 +122,10 @@ static void show_usage(void){
printf("\n");
}
#ifdef HAVE_BTSTACK_STDIN
static void stdin_process(char c){
switch (c){
case 'c':
printf("Connect to %s\n", bd_addr_to_str(device_addr));
printf("Connect to %s\n", device_addr_string);
hsp_ag_connect(device_addr);
break;
case 'C':
@ -176,17 +179,19 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
UNUSED(channel);
switch (packet_type){
case HCI_SCO_DATA_PACKET:
sco_demo_receive(event, event_size);
break;
case HCI_EVENT_PACKET:
switch (event[0]) {
switch (hci_event_packet_get_type(event)) {
#ifndef HAVE_BTSTACK_STDIN
case BTSTACK_EVENT_STATE:
if (event[2] != HCI_STATE_WORKING) break;
show_usage();
if (btstack_event_state_get_state(event) != HCI_STATE_WORKING) break;
printf("Establish HSP AG service to %s...\n", device_addr_string);
hsp_ag_connect(device_addr);
break;
#endif
case HCI_EVENT_SCO_CAN_SEND_NOW:
sco_demo_send(sco_handle);
break;
@ -195,9 +200,13 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
case HSP_SUBEVENT_RFCOMM_CONNECTION_COMPLETE:
if (hsp_subevent_rfcomm_connection_complete_get_status(event)){
printf("RFCOMM connection establishement failed with status %u\n", hsp_subevent_rfcomm_connection_complete_get_status(event));
} else {
printf("RFCOMM connection established.\n");
break;
}
printf("RFCOMM connection established.\n");
#ifndef HAVE_BTSTACK_STDIN
printf("Establish Audio connection to %s...\n", device_addr_string);
hsp_ag_establish_audio_connection();
#endif
break;
case HSP_SUBEVENT_RFCOMM_DISCONNECTION_COMPLETE:
if (hsp_subevent_rfcomm_disconnection_complete_get_status(event)){
@ -289,11 +298,14 @@ int btstack_main(int argc, const char * argv[]){
hsp_ag_register_packet_handler(&packet_handler);
hci_register_sco_packet_handler(&packet_handler);
// parse human readable Bluetooth address
sscanf_bd_addr(device_addr_string, device_addr);
#ifdef HAVE_BTSTACK_STDIN
btstack_stdin_setup(stdin_process);
#endif
gap_set_local_name("HSP AG Demo 00:00:00:00:00:00");
gap_set_local_name(device_name);
gap_discoverable_control(1);
gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO);
gap_set_class_of_device(0x400204);

View File

@ -55,10 +55,6 @@
#include "btstack_stdin.h"
#endif
#ifndef HAVE_BTSTACK_STDIN
static int step = 0;
#endif
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static bd_addr_t remote_addr;