mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-15 23:42:52 +00:00
fixed hfp hf client test
This commit is contained in:
parent
07648fce78
commit
3bfacaf947
@ -718,6 +718,8 @@ static void process_command(hfp_connection_t * context){
|
||||
return;
|
||||
}
|
||||
|
||||
if (strncmp((char *)context->line_buffer+offset, "NOP", 3) == 0) return;
|
||||
|
||||
printf(" process unknown command 3 %s \n", context->line_buffer);
|
||||
}
|
||||
|
||||
|
20
src/hfp_ag.c
20
src/hfp_ag.c
@ -369,7 +369,7 @@ static uint8_t hfp_ag_suggest_codec(hfp_connection_t *context){
|
||||
|
||||
static int hfp_ag_run_for_context_service_level_connection(hfp_connection_t * context){
|
||||
if (context->state >= HFP_CODECS_CONNECTION_ESTABLISHED) return 0;
|
||||
printf(" AG run for context_service_level_connection \n");
|
||||
//printf(" AG run for context_service_level_connection \n");
|
||||
int done = 0;
|
||||
|
||||
switch(context->command){
|
||||
@ -397,7 +397,7 @@ static int hfp_ag_run_for_context_service_level_connection(hfp_connection_t * co
|
||||
break;
|
||||
case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED:
|
||||
context->suggested_codec = hfp_ag_suggest_codec(context);
|
||||
printf("received BAC == new HF codecs, suggested codec %d\n", context->suggested_codec);
|
||||
//printf("received BAC == new HF codecs, suggested codec %d\n", context->suggested_codec);
|
||||
hfp_ag_ok(context->rfcomm_cid);
|
||||
done = 1;
|
||||
break;
|
||||
@ -498,12 +498,12 @@ static int hfp_ag_run_for_context_service_level_connection(hfp_connection_t * co
|
||||
static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connection_t * context){
|
||||
if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
|
||||
int done = 0;
|
||||
printf(" SLC queries: ");
|
||||
//printf(" SLC queries: ");
|
||||
|
||||
switch(context->command){
|
||||
case HFP_CMD_AVAILABLE_CODECS:
|
||||
context->suggested_codec = hfp_ag_suggest_codec(context);
|
||||
printf("received BAC == new HF codecs, suggested codec %d\n", context->suggested_codec);
|
||||
//printf("received BAC == new HF codecs, suggested codec %d\n", context->suggested_codec);
|
||||
hfp_ag_ok(context->rfcomm_cid);
|
||||
done = 1;
|
||||
break;
|
||||
@ -541,7 +541,7 @@ static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connectio
|
||||
}
|
||||
case HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP:
|
||||
if (context->hf_trigger_codec_connection_setup){ // received BCC
|
||||
printf(" received BCC \n");
|
||||
//printf(" received BCC \n");
|
||||
context->hf_trigger_codec_connection_setup = 0;
|
||||
context->ag_trigger_codec_connection_setup = 1;
|
||||
context->state = HFP_SLE_W2_EXCHANGE_COMMON_CODEC;
|
||||
@ -551,7 +551,7 @@ static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connectio
|
||||
}
|
||||
|
||||
if (context->ag_trigger_codec_connection_setup){ // received BCS
|
||||
printf(" send BCS \n");
|
||||
//printf(" send BCS \n");
|
||||
context->ag_trigger_codec_connection_setup = 0;
|
||||
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
|
||||
context->suggested_codec = hfp_ag_suggest_codec(context);
|
||||
@ -582,11 +582,11 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
|
||||
context->state > HFP_CODECS_CONNECTION_ESTABLISHED) return 0;
|
||||
|
||||
int done = 0;
|
||||
printf(" AG run for context_codecs_connection: ");
|
||||
//printf(" AG run for context_codecs_connection: ");
|
||||
switch (context->state){
|
||||
case HFP_SLE_W2_EXCHANGE_COMMON_CODEC:
|
||||
if (context->ag_trigger_codec_connection_setup){ // received BCS
|
||||
printf(" send BCS \n");
|
||||
//printf(" send BCS \n");
|
||||
context->ag_trigger_codec_connection_setup = 0;
|
||||
context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC;
|
||||
context->suggested_codec = hfp_ag_suggest_codec(context);
|
||||
@ -599,7 +599,7 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
|
||||
switch(context->command){
|
||||
case HFP_CMD_AVAILABLE_CODECS:
|
||||
if (context->notify_ag_on_new_codecs){ // received BAC
|
||||
printf(" received BAC\n");
|
||||
//printf(" received BAC\n");
|
||||
context->notify_ag_on_new_codecs = 0;
|
||||
if (context->suggested_codec != hfp_ag_suggest_codec(context)){
|
||||
context->suggested_codec = hfp_ag_suggest_codec(context);
|
||||
@ -612,7 +612,7 @@ static int hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){
|
||||
}
|
||||
break;
|
||||
case HFP_CMD_HF_CONFIRMED_CODEC:
|
||||
printf(" received AT+BCS\n");
|
||||
//printf(" received AT+BCS\n");
|
||||
if (context->codec_confirmed != context->suggested_codec){
|
||||
context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED;
|
||||
hfp_ag_error(context->rfcomm_cid);
|
||||
|
@ -249,8 +249,11 @@ static void hfp_emit_network_operator_event(hfp_callback_t callback, int status,
|
||||
(*callback)(event, sizeof(event));
|
||||
}
|
||||
|
||||
static void hfp_hf_run_for_context_service_level_connection(hfp_connection_t * context){
|
||||
if (context->state >= HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return;
|
||||
static int hfp_hf_run_for_context_service_level_connection(hfp_connection_t * context){
|
||||
if (context->state >= HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0;
|
||||
int done = 0;
|
||||
if (context->wait_ok) return done;
|
||||
|
||||
switch (context->state){
|
||||
case HFP_EXCHANGE_SUPPORTED_FEATURES:
|
||||
hfp_hf_cmd_exchange_supported_features(context->rfcomm_cid);
|
||||
@ -606,7 +609,7 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
|
||||
packet[size] = 0;
|
||||
int pos, i;
|
||||
printf("\nHF received: %s", packet+2);
|
||||
//printf("\nHF received: %s", packet+2);
|
||||
for (pos = 0; pos < size ; pos++){
|
||||
hfp_parse(context, packet[pos]);
|
||||
|
||||
|
@ -53,8 +53,7 @@ VPATH += ${BTSTACK_ROOT}/platforms/posix/src
|
||||
CFLAGS = -g -Wall -I. -I../ -I${BTSTACK_ROOT}/src -I${BTSTACK_ROOT}/include -I${BTSTACK_ROOT}/ble
|
||||
LDFLAGS += -lCppUTest -lCppUTestExt
|
||||
|
||||
EXAMPLES = hfp_ag_client_test
|
||||
#hfp_hf_parser_test hfp_hf_client_test hfp_ag_parser_test
|
||||
EXAMPLES = hfp_ag_parser_test hfp_ag_client_test hfp_hf_parser_test hfp_hf_client_test
|
||||
|
||||
all: ${BTSTACK_ROOT}/src/version.h ${EXAMPLES}
|
||||
|
||||
@ -74,8 +73,8 @@ hfp_ag_client_test: ${MOCK_OBJ} hfp_ag.o hfp.o hfp_ag_client_test.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
test: all
|
||||
#./hfp_hf_parser_test
|
||||
#./hfp_ag_parser_test
|
||||
#./hfp_hf_client_test
|
||||
./hfp_ag_parser_test
|
||||
./hfp_ag_client_test
|
||||
./hfp_hf_parser_test
|
||||
./hfp_hf_client_test
|
||||
|
||||
|
@ -118,11 +118,10 @@ void simulate_test_sequence(char ** test_steps, int nr_test_steps){
|
||||
int i = 0;
|
||||
for (i=0; i < nr_test_steps; i++){
|
||||
char * cmd = test_steps[i];
|
||||
printf("\n --> Test step %d: ", i);
|
||||
printf("\n---> NEXT STEP %s\n", cmd);
|
||||
if (memcmp(cmd, "AT", 2) == 0){
|
||||
inject_rfcomm_command_to_ag((uint8_t*)cmd, strlen(cmd));
|
||||
} else if (memcmp(cmd, "NOP", 3) == 0){
|
||||
printf("Trigger AG to run state machine\n");
|
||||
inject_rfcomm_command_to_ag((uint8_t*)"NOP",3);
|
||||
} else {
|
||||
int expected_cmd = expected_rfcomm_command(cmd);
|
||||
|
@ -111,16 +111,18 @@ void hfp_hf_run_test_sequence(char ** test_steps, int nr_test_steps){
|
||||
int i = 0;
|
||||
for (i=0; i < nr_test_steps; i++){
|
||||
char * cmd = test_steps[i];
|
||||
// printf("---> next step %s\n", cmd);
|
||||
printf("\n---> NEXT STEP %s\n", cmd);
|
||||
if (memcmp(cmd, "AT", 2) == 0){
|
||||
int parsed_codecs[2];
|
||||
uint8_t new_codecs[2];
|
||||
if (memcmp(cmd, "AT+BAC=", 7) == 0){
|
||||
printf("Send BAC\n");
|
||||
sscanf(&cmd[7],"%d,%d", &parsed_codecs[0], &parsed_codecs[1]);
|
||||
new_codecs[0] = parsed_codecs[0];
|
||||
new_codecs[1] = parsed_codecs[1];
|
||||
hfp_hf_set_codecs((uint8_t*)new_codecs, 2);
|
||||
} else {
|
||||
printf("Verify\n");
|
||||
int expected_cmd = expected_rfcomm_command(cmd);
|
||||
if (expected_cmd){
|
||||
printf("\nError: Expected:'%s', but got:'%s'", cmd, (char *)get_rfcomm_payload());
|
||||
@ -128,7 +130,7 @@ void hfp_hf_run_test_sequence(char ** test_steps, int nr_test_steps){
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inject_rfcomm_command((uint8_t*)cmd, strlen(cmd));
|
||||
inject_rfcomm_command_to_hf((uint8_t*)cmd, strlen(cmd));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -213,9 +215,13 @@ TEST_GROUP(HFPClient){
|
||||
|
||||
|
||||
TEST(HFPClient, HFCodecsConnectionEstablished){
|
||||
verify_hfp_service_level_connection_established(default_slc_setup(), default_slc_setup_size());
|
||||
for (int i = 0; i < cc_tests_size(); i++){
|
||||
verify_hfp_codecs_connection_established(hfp_cc_tests()[i].test, hfp_cc_tests()[i].len);
|
||||
setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size());
|
||||
CHECK_EQUAL(service_level_connection_established, 1);
|
||||
|
||||
setup_hfp_codecs_connection(hfp_cc_tests()[i].test, hfp_cc_tests()[i].len);
|
||||
//CHECK_EQUAL(codecs_connection_established, 1);
|
||||
teardown();
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +235,9 @@ TEST(HFPClient, HFServiceLevelConnectionCommands){
|
||||
|
||||
TEST(HFPClient, HFServiceLevelConnectionEstablished){
|
||||
for (int i = 0; i < slc_tests_size(); i++){
|
||||
verify_hfp_service_level_connection_established(hfp_slc_tests()[i].test, hfp_slc_tests()[i].len);
|
||||
setup_hfp_service_level_connection(hfp_slc_tests()[i].test, hfp_slc_tests()[i].len);
|
||||
CHECK_EQUAL(service_level_connection_established, 1);
|
||||
teardown();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ static void prepare_rfcomm_buffer(uint8_t * data, int len){
|
||||
static void print_without_newlines(uint8_t *data, uint16_t len){
|
||||
int found_newline = 0;
|
||||
int found_item = 0;
|
||||
printf("\n");
|
||||
|
||||
for (int i=0; i<len; i++){
|
||||
if (data[i] == '\r' || data[i] == '\n'){
|
||||
if (!found_newline && found_item) printf("\n");
|
||||
@ -217,26 +217,14 @@ void rfcomm_accept_connection_internal(uint16_t rfcomm_cid){
|
||||
}
|
||||
|
||||
|
||||
void inject_rfcomm_command(uint8_t * data, int len){
|
||||
prepare_rfcomm_buffer(data, len);
|
||||
if (memcmp((char*)data, "AT", 2) == 0){
|
||||
printf("\n\n ---> Send cmd to AG state machine: %s", data);
|
||||
} else if (memcmp((char*)data, "+", 1) == 0){
|
||||
|
||||
} else {
|
||||
printf("\n\n ---> Send cmd to HF state machine: %s", data);
|
||||
}
|
||||
(*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len);
|
||||
}
|
||||
|
||||
void inject_rfcomm_command_to_hf(uint8_t * data, int len){
|
||||
if (memcmp((char*)data, "AT", 2) == 0) return;
|
||||
|
||||
prepare_rfcomm_buffer(data, len);
|
||||
if (data[0] == '+'){
|
||||
printf("Send cmd to HF state machine: %s", data);
|
||||
if (data[0] == '+' || (data[0] == 'O' && data[1] == 'K')){
|
||||
printf("Send cmd to HF state machine: %s\n", data);
|
||||
} else {
|
||||
printf("Trigger HF state machine: %s", data);
|
||||
printf("Trigger HF state machine - %s", data);
|
||||
}
|
||||
(*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len);
|
||||
}
|
||||
@ -248,7 +236,7 @@ void inject_rfcomm_command_to_ag(uint8_t * data, int len){
|
||||
if (memcmp((char*)data, "AT", 2) == 0){
|
||||
printf("Send cmd to AG state machine: %s\n", data);
|
||||
} else {
|
||||
printf("Trigger AG state machine: %s", data);
|
||||
printf("Trigger AG state machine - %s", data);
|
||||
}
|
||||
(*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len);
|
||||
}
|
||||
|
@ -49,7 +49,6 @@
|
||||
// HFP Mock API
|
||||
uint8_t * get_rfcomm_payload();
|
||||
uint16_t get_rfcomm_payload_len();
|
||||
void inject_rfcomm_command(uint8_t * data, int len);
|
||||
|
||||
void inject_rfcomm_command_to_ag(uint8_t * data, int len);
|
||||
void inject_rfcomm_command_to_hf(uint8_t * data, int len);
|
||||
|
@ -82,29 +82,10 @@ const char * slc_cmds_test1[] = {
|
||||
"OK"
|
||||
};
|
||||
|
||||
const char * slc_cmds_test2[] = {
|
||||
"AT+BAC=1,3",
|
||||
"OK"
|
||||
};
|
||||
|
||||
const char * slc_cmds_test3[] = {
|
||||
"AT+BAC=1,3",
|
||||
"OK"
|
||||
};
|
||||
|
||||
const char * slc_cmds_test4[] = {
|
||||
"AT+BAC=1,3",
|
||||
"OK"
|
||||
};
|
||||
|
||||
const char * slc_cmds_test5[] = {
|
||||
"AT+BAC=1,3",
|
||||
"OK"
|
||||
};
|
||||
|
||||
hfp_test_item_t slc_cmds_tests[] = {
|
||||
TEST_SEQUENCE(slc_cmds_test1)
|
||||
};
|
||||
|
||||
/* Codecs Connection (cc) test sequences */
|
||||
const char * cc_test1[] = {
|
||||
"AT+BCC",
|
||||
|
Loading…
x
Reference in New Issue
Block a user