예제 #1
0
파일: hfp_ag.c 프로젝트: yourskp/btstack
static void hfp_run_for_context(hfp_connection_t *context){
    if (!context) return;
    if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return;
    
    if (context->command == HFP_CMD_UNKNOWN){
        context->ok_pending = 0;
        context->send_error = 0;
        context->command = HFP_CMD_NONE;
        hfp_ag_error(context->rfcomm_cid);
        return;
    }

    if (context->ok_pending){
        context->ok_pending = 0;
        context->command = HFP_CMD_NONE;
        hfp_ag_ok(context->rfcomm_cid);
        return;
    }

    if (context->send_error){
        context->send_error = 0;
        context->command = HFP_CMD_NONE;
        hfp_ag_error(context->rfcomm_cid); 
        return;
    }
    
    int done = hfp_ag_run_for_context_service_level_connection(context);
    if (!done){
        done = hfp_ag_run_for_context_service_level_connection_queries(context);
    } 

    if (!done){
        done = incoming_call_state_machine(context);
    }

    if (!done){  
        done = hfp_ag_run_for_audio_connection(context);
    }
    

    if (context->command == HFP_CMD_NONE && !done){
        log_info("context->command == HFP_CMD_NONE");
        switch(context->state){
            case HFP_W2_DISCONNECT_RFCOMM:
                context->state = HFP_W4_RFCOMM_DISCONNECTED;
                rfcomm_disconnect_internal(context->rfcomm_cid);
                break;
            default:
                break;
        }
    }
    if (done){
        context->command = HFP_CMD_NONE;
    }
}
예제 #2
0
void hfp_run_for_context(hfp_connection_t *context){
    if (!context) return;

    if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return;

    // printf("AG hfp_run_for_context 1 state %d, command %d\n", context->state, context->command);
    if (context->send_ok){
        hfp_ag_ok(context->rfcomm_cid);
        context->send_ok = 0;
        return;
    }

    if (context->send_error){
        hfp_ag_error(context->rfcomm_cid); 
        context->send_error = 0;
        return;
    }
    int done;
    if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return;
    hfp_ag_run_for_context_service_level_connection(context);

    if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return;
    done = hfp_ag_run_for_context_service_level_connection_queries(context);
    if (!rfcomm_can_send_packet_now(context->rfcomm_cid) || done) return;
    done = hfp_ag_run_for_context_codecs_connection(context);

    if (context->command == HFP_CMD_NONE){
        switch(context->state){
            case HFP_W2_DISCONNECT_RFCOMM:
                // printf("rfcomm_disconnect_internal cid 0x%02x\n", context->rfcomm_cid);
                context->state = HFP_W4_RFCOMM_DISCONNECTED;
                rfcomm_disconnect_internal(context->rfcomm_cid);
                break;
            default:
                break;
        }
    }
    context->command = HFP_CMD_NONE;

}