From 0ebae5fdf31f98cc2c257e134530d3292415d4dc Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Wed, 13 Jan 2016 15:06:36 +0100 Subject: [PATCH] hfp: add new call state --- src/hfp_gsm_model.c | 39 ++++++++++++++++++++++++++++------- src/hfp_gsm_model.h | 2 ++ test/hfp/hfp_ag_client_test.c | 3 ++- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/hfp_gsm_model.c b/src/hfp_gsm_model.c index 77ab7b6c8..383085691 100644 --- a/src/hfp_gsm_model.c +++ b/src/hfp_gsm_model.c @@ -65,6 +65,7 @@ typedef enum{ CALL_NONE, + CALL_INITIATED, CALL_ACTIVE, CALL_HELD } hfp_gsm_call_status_t; @@ -106,6 +107,10 @@ static inline int get_active_call_index(){ return get_call_index_with_status(CALL_ACTIVE); } +static inline int get_initiated_call_index(){ + return get_call_index_with_status(CALL_INITIATED); +} + // static inline int get_number_none_calls(){ // return get_number_calls_with_status(CALL_NONE); // } @@ -140,32 +145,50 @@ hfp_callsetup_status_t hfp_gsm_callsetup_status(){ return callsetup_status; } +int hfp_gsm_call_possible(void){ + int next_free_slot = get_none_call_index(); + return next_free_slot != -1; +} + void hfp_gsm_handle_event(hfp_ag_call_event_t event){ int next_free_slot = get_none_call_index(); int current_call_index = get_active_call_index(); - + int initiated_call_index = get_initiated_call_index(); + switch (event){ case HFP_AG_OUTGOING_CALL_INITIATED: case HFP_AG_OUTGOING_REDIAL_INITIATED: - if (next_free_slot == -1){ - log_error("max nr gsm call exceeded"); + log_error("gsm: max call nr exceeded"); return; } + break; + case HFP_AG_OUTGOING_CALL_REJECTED: + if (current_call_index != -1){ + gsm_calls[current_call_index].status = CALL_NONE; + } + callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + break; + + case HFP_AG_OUTGOING_CALL_ACCEPTED: if (current_call_index != -1){ gsm_calls[current_call_index].status = CALL_HELD; } - gsm_calls[next_free_slot].status = CALL_ACTIVE; + gsm_calls[next_free_slot].status = CALL_INITIATED; callsetup_status = HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_DIALING_STATE; break; - case HFP_AG_OUTGOING_CALL_REJECTED: - break; - case HFP_AG_OUTGOING_CALL_ACCEPTED: - break; + case HFP_AG_OUTGOING_CALL_RINGING: + if (current_call_index == -1){ + log_error("gsm: no active call"); + return; + } + callsetup_status = HFP_CALLSETUP_STATUS_OUTGOING_CALL_SETUP_IN_ALERTING_STATE; break; case HFP_AG_OUTGOING_CALL_ESTABLISHED: + callsetup_status = HFP_CALLSETUP_STATUS_NO_CALL_SETUP_IN_PROGRESS; + gsm_calls[initiated_call_index].status = CALL_ACTIVE; break; default: break; diff --git a/src/hfp_gsm_model.h b/src/hfp_gsm_model.h index dd72c3d7b..75f25926e 100644 --- a/src/hfp_gsm_model.h +++ b/src/hfp_gsm_model.h @@ -63,6 +63,8 @@ hfp_callheld_status_t hfp_gsm_callheld_status(); hfp_call_status_t hfp_gsm_call_status(); hfp_callsetup_status_t hfp_gsm_callsetup_status(); +int hfp_gsm_call_possible(void); + void hfp_gsm_handle_event(hfp_ag_call_event_t event); // /** diff --git a/test/hfp/hfp_ag_client_test.c b/test/hfp/hfp_ag_client_test.c index febe4dbd9..525339a1c 100644 --- a/test/hfp/hfp_ag_client_test.c +++ b/test/hfp/hfp_ag_client_test.c @@ -337,7 +337,8 @@ static void simulate_test_sequence(hfp_test_item_t * test_item){ int previous_step = -1; while ( i < test_item->len){ previous_step++; - if (i < previous_step) exit(0); + CHECK_EQUAL(i >= previous_step, 1); + char * expected_cmd = test_steps[i]; int expected_cmd_len = strlen(expected_cmd); printf("\nStep %d, %s \n", i, expected_cmd);