hfp gsm: track alst dialed number

This commit is contained in:
Milanka Ringwald 2016-01-21 12:12:58 +01:00
parent a9093a8aec
commit b0d2e4a3d5
6 changed files with 82 additions and 245 deletions

View File

@ -1376,13 +1376,14 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
hfp_run_for_context(connection);
break;
}
hfp_gsm_handle_event(HFP_AG_OUTGOING_CALL_INITIATED);
hfp_gsm_handle_event_with_call_number(HFP_AG_OUTGOING_CALL_INITIATED, (const char *) &connection->line_buffer[3]);
connection->call_state = HFP_CALL_OUTGOING_INITIATED;
hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER, (const char *) &connection->line_buffer[3]);
break;
case HFP_AG_OUTGOING_REDIAL_INITIATED:
case HFP_AG_OUTGOING_REDIAL_INITIATED:{
// directly reject call if number of free slots is exceeded
if (!hfp_gsm_call_possible()){
connection->send_error = 1;
@ -1394,8 +1395,21 @@ static void hfp_ag_call_sm(hfp_ag_call_event_t event, hfp_connection_t * connect
connection->call_state = HFP_CALL_OUTGOING_INITIATED;
hfp_emit_event(hfp_callback, HFP_SUBEVENT_REDIAL_LAST_NUMBER, 0);
printf("\n** Redial last number\n");
hfp_gsm_call_t * last_dialed_call = hfp_gsm_last_dialed_call();
if (last_dialed_call){
printf("Last number exists: accept call %s\n", last_dialed_call->clip_number);
hfp_emit_string_event(hfp_callback, HFP_SUBEVENT_PLACE_CALL_WITH_NUMBER, last_dialed_call->clip_number);
hfp_ag_outgoing_call_accepted();
// TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now
// hfp_ag_outgoing_call_ringing();
} else {
printf("Last number missing: reject call\n");
hfp_ag_outgoing_call_rejected();
}
break;
}
case HFP_AG_OUTGOING_CALL_REJECTED:
connection = hfp_ag_connection_for_call_state(HFP_CALL_OUTGOING_INITIATED);
if (!connection){
@ -1593,7 +1607,7 @@ static void hfp_run_for_context(hfp_connection_t *context){
if (context->send_status_of_current_calls){
context->ok_pending = 0;
if (context->next_call_index < hfp_gsm_get_number_calls()){
if (context->next_call_index < hfp_gsm_get_number_of_calls()){
context->next_call_index++;
hfp_ag_send_call_status(context, context->next_call_index);
} else {

View File

@ -37,7 +37,7 @@
// *****************************************************************************
//
// Minimal setup for HFP Audio Gateway (AG) unit (!! UNDER DEVELOPMENT !!)
// GSM Model
//
// *****************************************************************************
@ -140,8 +140,9 @@ static int next_call_index(void){
}
static void hfp_gsm_set_clip(int index_in_table, uint8_t type, const char * number){
printf("HFP_AG_SET_CLIP index in table %d, index %d, %d, %s \n", index_in_table, gsm_calls[index_in_table].index, type, number);
printf("HFP_AG_SET_CLIP index in table %d, index %d, %d, %s, last dialed %d \n",
index_in_table, gsm_calls[index_in_table].index, type, number, gsm_calls[index_in_table].last_dialed);
gsm_calls[index_in_table].clip_type = type;
int clip_number_size = sizeof(gsm_calls[index_in_table].clip_number);
@ -166,45 +167,57 @@ static void delete_call(int delete_index_in_table){
gsm_calls[delete_index_in_table].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
}
static void set_last_dialed(int index_in_table){
hfp_gsm_clear_last_dialed_number();
gsm_calls[index_in_table].last_dialed = 1;
int i;
for (i = 0; i<HFP_GSM_MAX_NR_CALLS; i++){
printf("set_last_dialed index in table %d, index %d, %d, %s, last dialed %d \n",
i, gsm_calls[i].index, gsm_calls[i].clip_type, gsm_calls[i].clip_number, gsm_calls[i].last_dialed);
}
}
static void create_call(hfp_enhanced_call_dir_t direction){
// int i;
// for ( i=0; i<HFP_GSM_MAX_NR_CALLS; i++){
// printf("** table call before, table index %d, call index %d, type %d, number %s\n",
// i, gsm_calls[i].index, gsm_calls[i].clip_type, gsm_calls[i].clip_number);
// }
int next_free_slot = get_next_free_slot();
gsm_calls[next_free_slot].direction = direction;
gsm_calls[next_free_slot].index = next_call_index();
gsm_calls[next_free_slot].status = CALL_INITIATED;
// printf("create call, next free table index %d, call index %d, type %d, number %s\n",
// next_free_slot, gsm_calls[next_free_slot].index, clip_type, clip_number);
gsm_calls[next_free_slot].clip_type = 0;
gsm_calls[next_free_slot].clip_number[0] = '\0';
gsm_calls[next_free_slot].mpty = HFP_ENHANCED_CALL_MPTY_NOT_A_CONFERENCE_CALL;
hfp_gsm_set_clip(next_free_slot, clip_type, clip_number);
set_last_dialed(next_free_slot);
// for ( i=0; i<HFP_GSM_MAX_NR_CALLS; i++){
// printf("** table call after, table index %d, call index %d, type %d, number %s\n",
// i, gsm_calls[i].index, gsm_calls[i].clip_type, gsm_calls[i].clip_number);
// }
hfp_gsm_set_clip(next_free_slot, clip_type, clip_number);
}
int hfp_gsm_get_number_calls(void){
int hfp_gsm_get_number_of_calls(void){
return HFP_GSM_MAX_NR_CALLS - get_number_none_calls();
}
void hfp_gsm_clear_last_dialed_number(void){
int i;
for (i = 0; i<HFP_GSM_MAX_NR_CALLS; i++){
gsm_calls[i].last_dialed = 0;
}
}
hfp_gsm_call_t * hfp_gsm_last_dialed_call(void){
hfp_gsm_call_t * call = NULL;
int i;
for (i = 0; i<HFP_GSM_MAX_NR_CALLS; i++){
printf("hfp_gsm_last_dialed_call index in table %d, index %d, %d, %s, last dialed %d \n",
i, gsm_calls[i].index, gsm_calls[i].clip_type, gsm_calls[i].clip_number, gsm_calls[i].last_dialed);
if (gsm_calls[i].last_dialed == 1) {
call = &gsm_calls[i];
}
}
return call;
}
hfp_gsm_call_t * hfp_gsm_call(int call_index){
int i;
// for ( i=0; i<HFP_GSM_MAX_NR_CALLS; i++){
// printf("** table call - search call index %d, table index %d, call index %d, type %d, number %s\n",
// call_index, i, gsm_calls[i].index, gsm_calls[i].clip_type, gsm_calls[i].clip_number);
// }
for (i = 0; i < HFP_GSM_MAX_NR_CALLS; i++){
hfp_gsm_call_t * call = &gsm_calls[i];
@ -228,7 +241,6 @@ hfp_gsm_call_t * hfp_gsm_call(int call_index){
call->enhanced_status = HFP_ENHANCED_CALL_STATUS_INCOMING;
}
}
// printf("found call with table index %d, index %d, type %d, number %s\n", i, call->index, call->clip_type, call->clip_number);
return call;
}
return NULL;
@ -295,7 +307,7 @@ hfp_callsetup_status_t hfp_gsm_callsetup_status(void){
return callsetup_status;
}
int hfp_gsm_response_held_active(void){
static int hfp_gsm_response_held_active(void){
return get_response_held_call_index() != -1 ;
}
@ -315,6 +327,10 @@ void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t ind
hfp_gsm_handler(event, index, 0, NULL);
}
void hfp_gsm_handle_event_with_call_number(hfp_ag_call_event_t event, const char * number){
hfp_gsm_handler(event, 0, 0, number);
}
static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t type, const char * number){
int next_free_slot = get_next_free_slot();
int current_call_index = get_active_call_index();
@ -324,14 +340,20 @@ static void hfp_gsm_handler(hfp_ag_call_event_t event, uint8_t index, uint8_t ty
switch (event){
case HFP_AG_OUTGOING_CALL_INITIATED:
case HFP_AG_OUTGOING_REDIAL_INITIATED:
if (next_free_slot == -1){
log_error("gsm: max call nr exceeded");
return;
}
create_call(HFP_ENHANCED_CALL_DIR_OUTGOING);
break;
case HFP_AG_OUTGOING_REDIAL_INITIATED:{
hfp_gsm_call_t * last_dialed_call = hfp_gsm_last_dialed_call();
if (last_dialed_call){
gsm_calls[last_dialed_call->index].status = CALL_INITIATED;
}
break;
}
case HFP_AG_OUTGOING_CALL_REJECTED:
if (current_call_index != -1){
delete_call(current_call_index);

View File

@ -37,7 +37,7 @@
// *****************************************************************************
//
// GSM model (!! UNDER DEVELOPMENT !!)
// GSM model
//
// *****************************************************************************
@ -55,10 +55,6 @@ extern "C" {
/* API_START */
/**
* @brief
*/
typedef enum{
CALL_NONE,
CALL_INITIATED,
@ -74,6 +70,7 @@ typedef struct {
hfp_enhanced_call_status_t enhanced_status;
hfp_enhanced_call_mode_t mode;
hfp_enhanced_call_mpty_t mpty;
uint8_t last_dialed;
// TODO: sort on drop call, so that index corresponds to table index
int index;
uint8_t clip_type;
@ -84,7 +81,11 @@ hfp_callheld_status_t hfp_gsm_callheld_status(void);
hfp_call_status_t hfp_gsm_call_status(void);
hfp_callsetup_status_t hfp_gsm_callsetup_status(void);
int hfp_gsm_get_number_calls(void);
int hfp_gsm_get_number_of_calls(void);
hfp_gsm_call_t * hfp_gsm_last_dialed_call(void);
void hfp_gsm_clear_last_dialed_number(void);
hfp_gsm_call_t * hfp_gsm_call(int index);
int hfp_gsm_call_possible(void);
@ -96,163 +97,9 @@ void hfp_gsm_init(void);
void hfp_gsm_handle_event_with_clip(hfp_ag_call_event_t event, uint8_t type, const char * number);
void hfp_gsm_handle_event_with_call_index(hfp_ag_call_event_t event, uint8_t index);
void hfp_gsm_handle_event_with_call_number(hfp_ag_call_event_t event, const char * number);
void hfp_gsm_handle_event(hfp_ag_call_event_t event);
// /**
// * @brief
// */
// void hfp_gsm_incoming_call(void);
// /
// /**
// * @brief Report the change in AG's call status.
// * Call status:
// * - 0 = No calls (held or active)
// * - 1 = Call is present (active or held)
// */
// void hfp_gsm_transfer_call_status(bd_addr_t bd_addr, hfp_call_status_t status);
// /**
// * @brief Report the change in AG's call setup status.
// * Call setup status:
// * - 0 = No call setup in progress
// * - 1 = Incoming call setup in progress
// * - 2 = Outgoing call setup in dialing state
// * - 3 = Outgoing call setup in alerting state
// */
// void hfp_gsm_transfer_callsetup_status(bd_addr_t bd_addr, hfp_callsetup_status_t status);
// /**
// * @brief Report the change in AG's held call status.
// * Held call status:
// * - 0 = No calls held
// * - 1 = Call is placed on hold or active/held calls are swapped
// * - 2 = Call on hold, no active calls
// */
// void hfp_gsm_transfer_callheld_status(bd_addr_t bd_addr, hfp_callheld_status_t status);
// /**
// * @brief Enable in-band ring tone
// */
// void hfp_gsm_set_use_in_band_ring_tone(int use_in_band_ring_tone);
// /**
// * @brief number is stored.
// */
// void hfp_gsm_set_clip(uint8_t type, const char * number);
// /**
// * @brief
// */
// void hfp_gsm_outgoing_call_rejected(void);
// /**
// * @brief
// */
// void hfp_gsm_outgoing_call_accepted(void);
// /**
// * @brief
// */
// void hfp_gsm_outgoing_call_ringing(void);
// /**
// * @brief
// */
// void hfp_gsm_outgoing_call_established(void);
// *
// * @brief
// void hfp_gsm_call_dropped(void);
// /**
// * @brief
// */
// void hfp_gsm_answer_incoming_call(void);
// /**
// * @brief
// */
// void hfp_gsm_join_held_call(void);
// /**
// * @brief
// */
// void hfp_gsm_terminate_call(void);
// /*
// * @brief
// */
// void hfp_gsm_set_registration_status(int status);
// /*
// * @brief
// */
// void hfp_gsm_set_signal_strength(int strength);
// /*
// * @brief
// */
// void hfp_gsm_set_roaming_status(int status);
// /*
// * @brief
// */
// void hfp_gsm_activate_voice_recognition(bd_addr_t bd_addr, int activate);
// /*
// * @brief
// */
// void hfp_gsm_send_phone_number_for_voice_tag(bd_addr_t bd_addr, const char * number);
// /*
// * @brief
// */
// void hfp_gsm_reject_phone_number_for_voice_tag(bd_addr_t bd_addr);
// /*
// * @brief
// */
// void hfp_gsm_send_dtmf_code_done(bd_addr_t bd_addr);
// /*
// * @brief
// */
// void hfp_gsm_set_subcriber_number_information(hfp_phone_number_t * numbers, int numbers_count);
// /*
// * @brief
// */
// void hfp_gsm_send_current_call_status(bd_addr_t bd_addr, int idx, hfp_enhanced_call_dir_t dir,
// hfp_enhanced_call_status_t status, hfp_enhanced_call_mode_t mode,
// hfp_enhanced_call_mpty_t mpty, uint8_t type, const char * number);
// /*
// * @brief
// */
// void hfp_gsm_send_current_call_status_done(bd_addr_t bd_addr);
// /*
// * @brief
// */
// void hfp_gsm_hold_incoming_call(void);
// /*
// * @brief
// */
// void hfp_gsm_accept_held_incoming_call(void);
// /*
// * @brief
// */
// void hfp_gsm_reject_held_incoming_call(void);
/* API_END */
#if defined __cplusplus

View File

@ -108,17 +108,8 @@ static hfp_generic_status_indicator_t hf_indicators[] = {
{2, 1},
};
static uint8_t service_level_connection_established = 0;
static uint8_t codecs_connection_established = 0;
static uint8_t audio_connection_established = 0;
static uint8_t start_ringing = 0;
static uint8_t stop_ringing = 0;
static uint8_t call_termiated = 0;
static uint16_t handle = -1;
static int memory_1_enabled = 1;
static int last_number_exists = 1;
int has_more_hfp_ag_commands(){
return has_more_hfp_commands(2,2);
@ -227,11 +218,10 @@ static void user_command(char cmd){
break;
case 'l':
printf("Last dialed number cleared\n");
last_number_exists = 0;
hfp_gsm_clear_last_dialed_number();
break;
case 'L':
printf("Last dialed number set\n");
last_number_exists = 1;
break;
case 'n':
printf("Disable Voice Recognition\n");
@ -411,18 +401,6 @@ void packet_handler(uint8_t * event, uint16_t event_size){
hfp_ag_outgoing_call_rejected();
}
break;
case HFP_SUBEVENT_REDIAL_LAST_NUMBER:
printf("\n** Redial last number\n");
if (last_number_exists){
hfp_ag_outgoing_call_accepted();
printf("Last number exists: accept call\n");
// TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now
// hfp_ag_outgoing_call_ringing();
} else {
printf("Last number missing: reject call\n");
hfp_ag_outgoing_call_rejected();
}
break;
case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG:
printf("\n** Attach number to voice tag. Sending '1234567\n");
hfp_ag_send_phone_number_for_voice_tag(device_addr, "1234567");
@ -441,13 +419,6 @@ void packet_handler(uint8_t * event, uint16_t event_size){
TEST_GROUP(HFPClient){
void setup(void){
service_level_connection_established = 0;
codecs_connection_established = 0;
audio_connection_established = 0;
start_ringing = 0;
stop_ringing = 0;
call_termiated = 0;
hfp_ag_init(rfcomm_channel_nr, supported_features_with_codec_negotiation,
codecs, sizeof(codecs),
ag_indicators, ag_indicators_nr,
@ -458,10 +429,6 @@ TEST_GROUP(HFPClient){
void teardown(void){
hfp_ag_release_audio_connection(device_addr);
hfp_ag_release_service_level_connection(device_addr);
service_level_connection_established = 0;
codecs_connection_established = 0;
audio_connection_established = 0;
}
};

View File

@ -55,7 +55,7 @@ hsp_hs_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hsp_hs.o hsp_hs_test.c
hfp_hf_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hfp.o hfp_hf.o hfp_hf_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
hfp_ag_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hfp.o hfp_ag_model.o hfp_ag.o hfp_ag_test.c
hfp_ag_test: ${CORE_OBJ} ${COMMON_OBJ} ${SDP_CLIENT} hfp.o hfp_gsm_model.o hfp_ag.o hfp_ag_test.c
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
l2cap_test: ${CORE_OBJ} ${COMMON_OBJ} l2cap_test.c

View File

@ -78,7 +78,6 @@ static bd_addr_t speaker_addr = {0x00, 0x21, 0x3C, 0xAC, 0xF7, 0x38};
static uint8_t codecs[1] = {HFP_CODEC_CVSD};
static uint16_t handle = -1;
static int memory_1_enabled = 1;
static int last_number_exists = 1;
static int ag_indicators_nr = 7;
static hfp_ag_indicator_t ag_indicators[] = {
@ -470,12 +469,11 @@ static int stdin_process(struct data_source *ds){
case 'l':
log_info("USER:\'%c\'", cmd);
printf("Last dialed number cleared\n");
last_number_exists = 0;
hfp_gsm_clear_last_dialed_number();
break;
case 'L':
log_info("USER:\'%c\'", cmd);
printf("Last dialed number set\n");
last_number_exists = 1;
break;
case 'n':
log_info("USER:\'%c\'", cmd);
@ -600,7 +598,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
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)
&& event[2] != HFP_SUBEVENT_TRANSMIT_DTMF_CODES
&& event[2] != HFP_SUBEVENT_TRANSMIT_STATUS_OF_CURRENT_CALL){
printf("ERROR, status: %u\n", event[3]);
return;
@ -640,18 +638,7 @@ static void packet_handler(uint8_t * event, uint16_t event_size){
hfp_ag_outgoing_call_rejected();
}
break;
case HFP_SUBEVENT_REDIAL_LAST_NUMBER:
printf("\n** Redial last number\n");
if (last_number_exists){
hfp_ag_outgoing_call_accepted();
printf("Last number exists: accept call\n");
// TODO: calling ringing right away leads to callstatus=2 being skipped. don't call for now
// hfp_ag_outgoing_call_ringing();
} else {
printf("Last number missing: reject call\n");
hfp_ag_outgoing_call_rejected();
}
break;
case HFP_SUBEVENT_ATTACH_NUMBER_TO_VOICE_TAG:
printf("\n** Attach number to voice tag. Sending '1234567\n");
hfp_ag_send_phone_number_for_voice_tag(device_addr, "1234567");