diff --git a/example/embedded/hfp_ag_demo.c b/example/embedded/hfp_ag_demo.c index 5ab7df5e4..842e08ad8 100644 --- a/example/embedded/hfp_ag_demo.c +++ b/example/embedded/hfp_ag_demo.c @@ -42,6 +42,9 @@ // ***************************************************************************** /* EXAMPLE_START(hfp_ag_demo): HFP Audio Gateway (AG) Demo * + * @text This HFP Audio Gateway example demonstrates how to receive + * an output from a remote HFP Hands-Free (HF) unit, and, + * if HAVE_STDIO is defined, how to control the HFP HF. */ // ***************************************************************************** @@ -652,14 +655,25 @@ static hfp_phone_number_t subscriber_number = { 129, "225577" }; +/* @section Main Application Setup + * + * @text Listing MainConfiguration shows main application code. + * To run a HFP AG service you need to initialize the SDP, and to create and register HFP AG record with it. + * The packet_handler is used for sending commands to the HFP HF. It also receives the HFP HF's answers. + * The stdin_process callback allows for sending commands to the HFP HF. + * At the end the Bluetooth stack is started. + */ + +/* LISTING_START(MainConfiguration): Setup HFP Audio Gateway */ + int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ // HFP HS address is hardcoded, please change it - // init L2CAP l2cap_init(); rfcomm_init(); - + sdp_init(); + hfp_ag_init(rfcomm_channel_nr); hfp_ag_init_supported_features(0x3ef | (1<service_record, rfcomm_channel_nr, hfp_ag_service_name, 0, 0); + printf("SDP service buffer size: %u\n", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); + sdp_register_service_internal(NULL, service_record_item); +/* LISTING_PAUSE */ +#else + hfp_ag_create_sdp_record((uint8_t *) hfp_service_buffer, rfcomm_channel_nr, hfp_ag_service_name, 0, 0); + printf("SDP service record size: %u\n", de_get_len((uint8_t*) hfp_service_buffer)); + sdp_register_service_internal(NULL, (uint8_t*)hfp_service_buffer); +#endif +/* LISTING_RESUME */ #ifdef HAVE_STDIO btstack_stdin_setup(stdin_process); @@ -684,3 +707,4 @@ int btstack_main(int argc, const char * argv[]){ hci_power_control(HCI_POWER_ON); return 0; } +/* LISTING_END */ diff --git a/example/embedded/hfp_hf_demo.c b/example/embedded/hfp_hf_demo.c index 332536390..838a7b4e2 100644 --- a/example/embedded/hfp_hf_demo.c +++ b/example/embedded/hfp_hf_demo.c @@ -43,6 +43,9 @@ // ***************************************************************************** /* EXAMPLE_START(hfp_hs_demo): HFP Hands-Free (HF) Demo * + * @text This HFP Hands-Free example demonstrates how to receive + * an output from a remote HFP audio gateway (AG), and, + * if HAVE_STDIO is defined, how to control the HFP AG. */ // ***************************************************************************** @@ -515,15 +518,24 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ } } +/* @section Main Application Setup + * + * @text Listing MainConfiguration shows main application code. + * To run a HFP HF service you need to initialize the SDP, and to create and register HFP HF record with it. + * The packet_handler is used for sending commands to the HFP AG. It also receives the HFP AG's answers. + * The stdin_process callback allows for sending commands to the HFP AG. + * At the end the Bluetooth stack is started. + */ + +/* LISTING_START(MainConfiguration): Setup HFP Hands-Free unit */ int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ // HFP AG address is hardcoded, please change it - // init L2CAP l2cap_init(); rfcomm_init(); - - // hfp_hf_init(rfcomm_channel_nr, HFP_DEFAULT_HF_SUPPORTED_FEATURES, codecs, sizeof(codecs), indicators, sizeof(indicators)/sizeof(uint16_t), 1); + sdp_init(); + hfp_hf_init(rfcomm_channel_nr); hfp_hf_init_supported_features(438 | (1<service_record, rfcomm_channel_nr, hfp_hf_service_name, 0); + printf("SDP service buffer size: %u\n", (uint16_t) (sizeof(service_record_item_t) + de_get_len((uint8_t*) &service_record_item->service_record))); + sdp_register_service_internal(NULL, service_record_item); +/* LISTING_PAUSE */ +#else + hfp_hf_create_sdp_record((uint8_t *) hfp_service_buffer, rfcomm_channel_nr, hfp_hf_service_name, 0); + printf("SDP service record size: %u\n", de_get_len((uint8_t*) hfp_service_buffer)); + sdp_register_service_internal(NULL, (uint8_t*)hfp_service_buffer); +#endif +/* LISTING_RESUME */ #ifdef HAVE_STDIO btstack_stdin_setup(stdin_process); @@ -544,3 +566,4 @@ int btstack_main(int argc, const char * argv[]){ hci_power_control(HCI_POWER_ON); return 0; } +/* LISTING_END */ diff --git a/example/embedded/hsp_ag_demo.c b/example/embedded/hsp_ag_demo.c index 5621e31fb..c865073c8 100644 --- a/example/embedded/hsp_ag_demo.c +++ b/example/embedded/hsp_ag_demo.c @@ -322,7 +322,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ * At the end the Bluetooth stack is started. */ -/* LISTING_START(MainConfiguration): Setup packet handlers and audio data channel for HSP Audio Gateway */ +/* LISTING_START(MainConfiguration): Setup HSP Audio Gateway */ int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ l2cap_init(); @@ -330,7 +330,6 @@ int btstack_main(int argc, const char * argv[]){ sdp_init(); memset((uint8_t *)hsp_service_buffer, 0, sizeof(hsp_service_buffer)); - /* LISTING_PAUSE */ #ifdef EMBEDDED /* LISTING_RESUME */ @@ -348,7 +347,6 @@ int btstack_main(int argc, const char * argv[]){ hci_register_sco_packet_handler(&sco_packet_handler); hsp_ag_init(rfcomm_channel_nr); - hsp_ag_register_packet_handler(packet_handler); #ifdef HAVE_STDIO @@ -358,10 +356,10 @@ int btstack_main(int argc, const char * argv[]){ gap_set_local_name("BTstack HSP AG"); hci_discoverable_control(1); hci_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO); - // turn on! hci_set_class_of_device(0x400204); + // turn on! hci_power_control(HCI_POWER_ON); - return 0; } +/* LISTING_END */ diff --git a/example/embedded/hsp_hs_demo.c b/example/embedded/hsp_hs_demo.c index af714a5f7..fa3ac18d8 100644 --- a/example/embedded/hsp_hs_demo.c +++ b/example/embedded/hsp_hs_demo.c @@ -319,7 +319,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){ * At the end the Bluetooth stack is started. */ -/* LISTING_START(MainConfiguration): Setup packet handlers and audio data channel for HSP Headset */ +/* LISTING_START(MainConfiguration): Setup HSP Headset */ int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ l2cap_init(); @@ -327,7 +327,6 @@ int btstack_main(int argc, const char * argv[]){ sdp_init(); memset((uint8_t *)hsp_service_buffer, 0, sizeof(hsp_service_buffer)); - /* LISTING_PAUSE */ #ifdef EMBEDDED /* LISTING_RESUME */ @@ -355,10 +354,10 @@ int btstack_main(int argc, const char * argv[]){ gap_set_local_name("BTstack HSP HS"); hci_discoverable_control(1); hci_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO); - // turn on! hci_set_class_of_device(0x240404); + // turn on! hci_power_control(HCI_POWER_ON); - return 0; } +/* LISTING_END */