mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-06 07:14:26 +00:00
example/hsp+hfp: extract SCO test code into sco_demo_util
This commit is contained in:
parent
47c58a2a6e
commit
185c8cd41d
@ -160,16 +160,16 @@ led_counter: ${CORE_OBJ} ${COMMON_OBJ} led_counter.c
|
||||
gap_le_advertisements: ${CORE_OBJ} ${COMMON_OBJ} ad_parser.c gap_le_advertisements.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
hsp_hs_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_hs.o hsp_hs_demo.c
|
||||
hsp_hs_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} sco_demo_util.o hsp_hs.o hsp_hs_demo.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
hsp_ag_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_ag.o hsp_ag_demo.c
|
||||
hsp_ag_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} sco_demo_util.o hsp_ag.o hsp_ag_demo.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
hfp_ag_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hfp.o hfp_gsm_model.o hfp_ag.o hfp_ag_demo.c
|
||||
hfp_ag_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} sco_demo_util.o hfp.o hfp_gsm_model.o hfp_ag.o hfp_ag_demo.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
hfp_hf_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hfp.o hfp_hf.o hfp_hf_demo.c
|
||||
hfp_hf_demo: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} sco_demo_util.o hfp.o hfp_hf.o hfp_hf_demo.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
clean:
|
||||
|
@ -56,22 +56,11 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "btstack.h"
|
||||
#include "sco_demo_util.h"
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
#include "stdin_support.h"
|
||||
#endif
|
||||
|
||||
|
||||
static int phase = 0;
|
||||
|
||||
// input signal: pre-computed sine wave, 160 Hz
|
||||
static const uint8_t sine[] = {
|
||||
0, 15, 31, 46, 61, 74, 86, 97, 107, 114,
|
||||
120, 124, 126, 126, 124, 120, 114, 107, 97, 86,
|
||||
74, 61, 46, 31, 15, 0, 241, 225, 210, 195,
|
||||
182, 170, 159, 149, 142, 136, 132, 130, 130, 132,
|
||||
136, 142, 149, 159, 170, 182, 195, 210, 225, 241,
|
||||
};
|
||||
|
||||
uint8_t hfp_service_buffer[150];
|
||||
const uint8_t rfcomm_channel_nr = 1;
|
||||
const char hfp_ag_service_name[] = "BTstack HFP AG Test";
|
||||
@ -79,7 +68,9 @@ const char hfp_ag_service_name[] = "BTstack HFP AG Test";
|
||||
// PTS
|
||||
// static bd_addr_t device_addr = {0x00,0x15,0x83,0x5F,0x9D,0x46};
|
||||
// BT-201
|
||||
static bd_addr_t device_addr = {0x00, 0x07, 0xB0, 0x83, 0x02, 0x5E};
|
||||
// static bd_addr_t device_addr = {0x00, 0x07, 0xB0, 0x83, 0x02, 0x5E};
|
||||
// CC256x
|
||||
bd_addr_t device_addr = { 0xD0, 0x39, 0x72, 0xCD, 0x83, 0x45};
|
||||
|
||||
static uint8_t codecs[1] = {HFP_CODEC_CVSD};
|
||||
static uint16_t handle = -1;
|
||||
@ -565,36 +556,6 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
|
||||
}
|
||||
#endif
|
||||
|
||||
#define SCO_REPORT_PERIOD 100
|
||||
static void send_sco_data(void){
|
||||
if (!sco_handle) return;
|
||||
|
||||
const int sco_packet_length = hci_get_sco_packet_length();
|
||||
const int sco_payload_length = sco_packet_length - 3;
|
||||
const int frames_per_packet = sco_payload_length; // for 8-bit data. for 16-bit data it's /2
|
||||
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t * sco_packet = hci_get_outgoing_packet_buffer();
|
||||
// set handle + flags
|
||||
little_endian_store_16(sco_packet, 0, sco_handle);
|
||||
// set len
|
||||
sco_packet[2] = sco_payload_length;
|
||||
int i;
|
||||
for (i=0;i<frames_per_packet;i++){
|
||||
sco_packet[3+i] = sine[phase];
|
||||
phase++;
|
||||
if (phase >= sizeof(sine)) phase = 0;
|
||||
}
|
||||
hci_send_sco_packet_buffer(sco_packet_length);
|
||||
|
||||
// request another send event
|
||||
hci_request_sco_can_send_now_event();
|
||||
|
||||
static int count = 0;
|
||||
count++;
|
||||
if ((count % SCO_REPORT_PERIOD) == 0) printf("Sent %u\n", count);
|
||||
}
|
||||
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
|
||||
switch (packet_type){
|
||||
case HCI_EVENT_PACKET:
|
||||
@ -606,7 +567,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
inquiry_packet_handler(HCI_EVENT_PACKET, event, event_size);
|
||||
break;
|
||||
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
||||
send_sco_data();
|
||||
sco_demo_send(sco_handle);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -680,6 +641,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
printf("Event not handled %u\n", event[2]);
|
||||
break;
|
||||
}
|
||||
case HCI_SCO_DATA_PACKET:
|
||||
sco_demo_receive(event, event_size);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -703,6 +667,8 @@ static hfp_phone_number_t subscriber_number = {
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
sco_demo_init();
|
||||
|
||||
gap_discoverable_control(1);
|
||||
|
||||
// L2CAP
|
||||
|
@ -59,20 +59,24 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "btstack.h"
|
||||
#include "sco_demo_util.h"
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
#include "stdin_support.h"
|
||||
#endif
|
||||
|
||||
|
||||
uint8_t hfp_service_buffer[150];
|
||||
const uint8_t rfcomm_channel_nr = 1;
|
||||
const char hfp_hf_service_name[] = "BTstack HFP HF Demo";
|
||||
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
static bd_addr_t device_addr = {0xD8,0xBb,0x2C,0xDf,0xF1,0x08};
|
||||
static bd_addr_t device_addr = {0x80,0xbe,0x05,0xd5,0x28,0x48};
|
||||
// 80:BE:05:D5:28:48
|
||||
// prototypes
|
||||
static void show_usage(void);
|
||||
#endif
|
||||
static uint16_t handle = -1;
|
||||
static hci_con_handle_t sco_handle;
|
||||
static uint8_t codecs[] = {HFP_CODEC_CVSD, HFP_CODEC_MSBC};
|
||||
static uint16_t indicators[1] = {0x01};
|
||||
|
||||
@ -445,6 +449,12 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
|
||||
#endif
|
||||
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
|
||||
|
||||
if (event[0] == HCI_EVENT_SCO_CAN_SEND_NOW){
|
||||
sco_demo_send(sco_handle);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event[0] != HCI_EVENT_HFP_META) return;
|
||||
|
||||
switch (event[2]) {
|
||||
@ -456,10 +466,18 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
printf("Service level connection released.\n\n");
|
||||
break;
|
||||
case HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED:
|
||||
printf("\n** Audio connection established **\n");
|
||||
if (hfp_subevent_audio_connection_established_get_status(event)){
|
||||
sco_handle = 0;
|
||||
printf("Audio connection establishment failed with status %u\n", hfp_subevent_audio_connection_established_get_status(event));
|
||||
} else {
|
||||
sco_handle = hfp_subevent_audio_connection_established_get_handle(event);
|
||||
printf("Audio connection established with SCO handle 0x%04x.\n", sco_handle);
|
||||
hci_request_sco_can_send_now_event();
|
||||
}
|
||||
break;
|
||||
case HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED:
|
||||
printf("\n** Audio connection released **\n");
|
||||
sco_handle = 0;
|
||||
printf("Audio connection released\n");
|
||||
break;
|
||||
case HFP_SUBEVENT_COMPLETE:
|
||||
switch (cmd){
|
||||
@ -512,6 +530,11 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
/* LISTING_START(MainConfiguration): Setup HFP Hands-Free unit */
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
sco_demo_init();
|
||||
|
||||
gap_discoverable_control(1);
|
||||
|
||||
// HFP AG address is hardcoded, please change it
|
||||
// init L2CAP
|
||||
l2cap_init();
|
||||
@ -524,6 +547,7 @@ int btstack_main(int argc, const char * argv[]){
|
||||
hfp_hf_init_codecs(sizeof(codecs), codecs);
|
||||
|
||||
hfp_hf_register_packet_handler(packet_handler);
|
||||
hci_register_sco_packet_handler(&packet_handler);
|
||||
|
||||
memset(hfp_service_buffer, 0, sizeof(hfp_service_buffer));
|
||||
hfp_hf_create_sdp_record(hfp_service_buffer, 0x10001, rfcomm_channel_nr, hfp_hf_service_name, 0);
|
||||
|
@ -59,12 +59,11 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "btstack.h"
|
||||
#include "sco_demo_util.h"
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
#include "stdin_support.h"
|
||||
#endif
|
||||
|
||||
#define SCO_REPORT_PERIOD 255
|
||||
|
||||
static uint8_t hsp_service_buffer[150];
|
||||
static const uint8_t rfcomm_channel_nr = 1;
|
||||
static const char hsp_ag_service_name[] = "Audio Gateway Test";
|
||||
@ -74,17 +73,6 @@ static char hs_cmd_buffer[100];
|
||||
|
||||
static bd_addr_t device_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
|
||||
|
||||
static int phase = 0;
|
||||
|
||||
// input signal: pre-computed sine wave, 160 Hz
|
||||
static const uint8_t sine[] = {
|
||||
0, 15, 31, 46, 61, 74, 86, 97, 107, 114,
|
||||
120, 124, 126, 126, 124, 120, 114, 107, 97, 86,
|
||||
74, 61, 46, 31, 15, 0, 241, 225, 210, 195,
|
||||
182, 170, 159, 149, 142, 136, 132, 130, 130, 132,
|
||||
136, 142, 149, 159, 170, 182, 195, 210, 225, 241,
|
||||
};
|
||||
|
||||
/* @section Audio Transfer Setup
|
||||
*
|
||||
* @text A pre-computed sine wave (160Hz) is used as the input audio signal. 160 Hz.
|
||||
@ -190,44 +178,12 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
|
||||
}
|
||||
#endif
|
||||
|
||||
static void send_sco_data(void){
|
||||
if (!sco_handle) return;
|
||||
|
||||
const int sco_packet_length = hci_get_sco_packet_length();
|
||||
const int sco_payload_length = sco_packet_length - 3;
|
||||
const int frames_per_packet = sco_payload_length; // for 8-bit data. for 16-bit data it's /2
|
||||
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t * sco_packet = hci_get_outgoing_packet_buffer();
|
||||
// set handle + flags
|
||||
little_endian_store_16(sco_packet, 0, sco_handle);
|
||||
// set len
|
||||
sco_packet[2] = sco_payload_length;
|
||||
int i;
|
||||
for (i=0;i<frames_per_packet;i++){
|
||||
sco_packet[3+i] = sine[phase];
|
||||
phase++;
|
||||
if (phase >= sizeof(sine)) phase = 0;
|
||||
}
|
||||
hci_send_sco_packet_buffer(sco_packet_length);
|
||||
|
||||
// request another send event
|
||||
hci_request_sco_can_send_now_event();
|
||||
|
||||
static int count = 0;
|
||||
if ((count % SCO_REPORT_PERIOD) == 0) printf("Sent %u\n", count);
|
||||
}
|
||||
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
|
||||
|
||||
static int count = 0;
|
||||
|
||||
switch (packet_type){
|
||||
|
||||
case HCI_SCO_DATA_PACKET:
|
||||
count++;
|
||||
if ((count & SCO_REPORT_PERIOD)) return;
|
||||
printf("SCO packets received: %u\n", count);
|
||||
sco_demo_receive(event, event_size);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_PACKET:
|
||||
@ -237,7 +193,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
show_usage();
|
||||
break;
|
||||
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
||||
send_sco_data();
|
||||
sco_demo_send(sco_handle);
|
||||
break;
|
||||
case HCI_EVENT_HSP_META:
|
||||
switch (event[2]) {
|
||||
@ -319,6 +275,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
sco_demo_init();
|
||||
|
||||
l2cap_init();
|
||||
|
||||
sdp_init();
|
||||
|
@ -59,12 +59,11 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "btstack.h"
|
||||
#include "sco_demo_util.h"
|
||||
#ifdef HAVE_POSIX_STDIN
|
||||
#include "stdin_support.h"
|
||||
#endif
|
||||
|
||||
#define SCO_REPORT_PERIOD 255
|
||||
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
static uint8_t hsp_service_buffer[150];
|
||||
@ -75,17 +74,6 @@ static hci_con_handle_t sco_handle = 0;
|
||||
static char hs_cmd_buffer[100];
|
||||
static bd_addr_t device_addr = {0x00,0x1b,0xDC,0x07,0x32,0xEF};
|
||||
|
||||
static int phase = 0;
|
||||
|
||||
// input signal: pre-computed sine wave, 160 Hz
|
||||
static const uint8_t sine[] = {
|
||||
0, 15, 31, 46, 61, 74, 86, 97, 107, 114,
|
||||
120, 124, 126, 126, 124, 120, 114, 107, 97, 86,
|
||||
74, 61, 46, 31, 15, 0, 241, 225, 210, 195,
|
||||
182, 170, 159, 149, 142, 136, 132, 130, 130, 132,
|
||||
136, 142, 149, 159, 170, 182, 195, 210, 225, 241,
|
||||
};
|
||||
|
||||
/* @section Audio Transfer Setup
|
||||
*
|
||||
* @text A pre-computed sine wave (160Hz) is used as the input audio signal. 160 Hz.
|
||||
@ -190,42 +178,10 @@ static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callbac
|
||||
}
|
||||
#endif
|
||||
|
||||
static void send_sco_data(void){
|
||||
if (!sco_handle) return;
|
||||
|
||||
const int sco_packet_length = hci_get_sco_packet_length();
|
||||
const int sco_payload_length = sco_packet_length - 3;
|
||||
const int frames_per_packet = sco_payload_length; // for 8-bit data. for 16-bit data it's /2
|
||||
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t * sco_packet = hci_get_outgoing_packet_buffer();
|
||||
// set handle + flags
|
||||
little_endian_store_16(sco_packet, 0, sco_handle);
|
||||
// set len
|
||||
sco_packet[2] = sco_payload_length;
|
||||
int i;
|
||||
for (i=0;i<frames_per_packet;i++){
|
||||
sco_packet[3+i] = sine[phase];
|
||||
phase++;
|
||||
if (phase >= sizeof(sine)) phase = 0;
|
||||
}
|
||||
hci_send_sco_packet_buffer(sco_packet_length);
|
||||
|
||||
// request another send event
|
||||
hci_request_sco_can_send_now_event();
|
||||
|
||||
static int count = 0;
|
||||
count++;
|
||||
if ((count % SCO_REPORT_PERIOD) == 0) printf("Sent %u\n", count);
|
||||
}
|
||||
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * event, uint16_t event_size){
|
||||
static int sco_rev_count = 0;
|
||||
switch (packet_type){
|
||||
case HCI_SCO_DATA_PACKET:
|
||||
sco_rev_count++;
|
||||
if ((sco_rev_count & SCO_REPORT_PERIOD)) break;
|
||||
printf("SCO packets received: %u\n", sco_rev_count);
|
||||
sco_demo_receive(event, event_size);
|
||||
break;
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (event[0]) {
|
||||
@ -234,7 +190,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
show_usage();
|
||||
break;
|
||||
case HCI_EVENT_SCO_CAN_SEND_NOW:
|
||||
send_sco_data();
|
||||
sco_demo_send(sco_handle);
|
||||
break;
|
||||
case HCI_EVENT_HSP_META:
|
||||
switch (event[2]) {
|
||||
@ -321,6 +277,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * even
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
int btstack_main(int argc, const char * argv[]){
|
||||
|
||||
sco_demo_init();
|
||||
|
||||
// register for HCI events
|
||||
hci_event_callback_registration.callback = &packet_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
@ -28,4 +28,11 @@ CFLAGS += $(shell pkg-config libusb-1.0 --cflags)
|
||||
LDFLAGS += $(shell pkg-config libusb-1.0 --libs)
|
||||
endif
|
||||
|
||||
# use pkg-config for portaudio
|
||||
# CFLAGS += $(shell pkg-config portaudio-2.0 --cflags) -DHAVE_PORTAUDIO
|
||||
# LDFLAGS += $(shell pkg-config portaudio-2.0 --libs)
|
||||
# hard coded flags for portaudio in /usr/local/lib
|
||||
# CFLAGS += -I/usr/local/include -DHAVE_PORTAUDIO
|
||||
# LDFLAGS += -L/sw/lib -lportaudio -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,Carbon
|
||||
|
||||
all: ${EXAMPLES}
|
||||
|
@ -2,7 +2,6 @@
|
||||
BTSTACK_ROOT = ../..
|
||||
|
||||
CORE += \
|
||||
bluetooth_init_cc2564B_1.4_BT_Spec_4.1.c \
|
||||
btstack_chipset_cc256x.c \
|
||||
btstack_chipset_csr.c \
|
||||
btstack_chipset_em9301.c \
|
||||
@ -14,6 +13,8 @@ CORE += \
|
||||
hci_transport_h4.c \
|
||||
main.c \
|
||||
stdin_support.c \
|
||||
bluetooth_init_cc2564B_1.4_BT_Spec_4.1.c \
|
||||
# bluetooth_init_cc2564_2.14.c \
|
||||
# btstack_chipset_bcm.c \
|
||||
|
||||
# TI-WL183x requires TIInit_11.8.32.c
|
||||
@ -53,4 +54,11 @@ ifneq ($(OS),Windows_NT)
|
||||
EXAMPLES += ${EXAMPLES_CLI}
|
||||
endif
|
||||
|
||||
# use pkg-config for portaudio
|
||||
# CFLAGS += $(shell pkg-config portaudio-2.0 --cflags) -DHAVE_PORTAUDIO
|
||||
# LDFLAGS += $(shell pkg-config portaudio-2.0 --libs)
|
||||
# hard coded flags for portaudio in /usr/local/lib
|
||||
# CFLAGS += -I/usr/local/include -DHAVE_PORTAUDIO
|
||||
# LDFLAGS += -L/sw/lib -lportaudio -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,Carbon
|
||||
|
||||
all: ${EXAMPLES}
|
||||
|
@ -54,4 +54,11 @@ ifneq ($(OS),Windows_NT)
|
||||
EXAMPLES += ${EXAMPLES_CLI}
|
||||
endif
|
||||
|
||||
# use pkg-config for portaudio
|
||||
# CFLAGS += $(shell pkg-config portaudio-2.0 --cflags) -DHAVE_PORTAUDIO
|
||||
# LDFLAGS += $(shell pkg-config portaudio-2.0 --libs)
|
||||
# hard coded flags for portaudio in /usr/local/lib
|
||||
# CFLAGS += -I/usr/local/include -DHAVE_PORTAUDIO
|
||||
# LDFLAGS += -L/sw/lib -lportaudio -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit -Wl,-framework,Carbon
|
||||
|
||||
all: ${EXAMPLES}
|
||||
|
Loading…
x
Reference in New Issue
Block a user