hsp_ag.c (13839019fac3531c95d6d5428516acfddf89b2dc) hsp_ag.c (94d78ec3c1abdbaeedfec89a0650e3d2d36f1b57)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 335 unchanged lines hidden (view full) ---

344 ag_speaker_gain = gain;
345 hsp_run();
346}
347
348static void hsp_ringing_timeout_handler(btstack_timer_source_t * timer){
349 ag_ring = 1;
350 btstack_run_loop_set_timer(&hs_timeout, 2000); // 2 seconds timeout
351 btstack_run_loop_add_timer(&hs_timeout);
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 335 unchanged lines hidden (view full) ---

344 ag_speaker_gain = gain;
345 hsp_run();
346}
347
348static void hsp_ringing_timeout_handler(btstack_timer_source_t * timer){
349 ag_ring = 1;
350 btstack_run_loop_set_timer(&hs_timeout, 2000); // 2 seconds timeout
351 btstack_run_loop_add_timer(&hs_timeout);
352 hsp_run();
352}
353
354static void hsp_ringing_timer_start(void){
355 btstack_run_loop_remove_timer(&hs_timeout);
356 btstack_run_loop_set_timer_handler(&hs_timeout, hsp_ringing_timeout_handler);
357 btstack_run_loop_set_timer(&hs_timeout, 2000); // 2 seconds timeout
358 btstack_run_loop_add_timer(&hs_timeout);
359}
360
361static void hsp_ringing_timer_stop(void){
362 btstack_run_loop_remove_timer(&hs_timeout);
363}
364
365void hsp_ag_start_ringing(void){
353}
354
355static void hsp_ringing_timer_start(void){
356 btstack_run_loop_remove_timer(&hs_timeout);
357 btstack_run_loop_set_timer_handler(&hs_timeout, hsp_ringing_timeout_handler);
358 btstack_run_loop_set_timer(&hs_timeout, 2000); // 2 seconds timeout
359 btstack_run_loop_add_timer(&hs_timeout);
360}
361
362static void hsp_ringing_timer_stop(void){
363 btstack_run_loop_remove_timer(&hs_timeout);
364}
365
366void hsp_ag_start_ringing(void){
366 if (hsp_state != HSP_W2_CONNECT_SCO) return;
367 ag_ring = 1;
367 ag_ring = 1;
368 hsp_state = HSP_W4_RING_ANSWER;
368 if (hsp_state == HSP_W2_CONNECT_SCO) {
369 hsp_state = HSP_W4_RING_ANSWER;
370 }
369 hsp_ringing_timer_start();
370}
371
372void hsp_ag_stop_ringing(void){
373 ag_ring = 0;
371 hsp_ringing_timer_start();
372}
373
374void hsp_ag_stop_ringing(void){
375 ag_ring = 0;
374 ag_num_button_press_received = 0;
375 hsp_state = HSP_W2_CONNECT_SCO;
376 if (hsp_state == HSP_W4_RING_ANSWER){
377 hsp_state = HSP_W2_CONNECT_SCO;
378 }
376 hsp_ringing_timer_stop();
377}
378
379static void hsp_run(void){
380
379 hsp_ringing_timer_stop();
380}
381
382static void hsp_run(void){
383
381 int err;
382
383 if (ag_send_ok){
384 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
385 rfcomm_request_can_send_now_event(rfcomm_cid);
386 return;
387 }
388 ag_send_ok = 0;
389 hsp_ag_send_str_over_rfcomm(rfcomm_cid, HSP_AG_OK);
390 return;
391 }
392
393 if (ag_send_error){
394 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
395 rfcomm_request_can_send_now_event(rfcomm_cid);
396 return;
397 }
398 ag_send_error = 0;
384 if (ag_send_ok){
385 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
386 rfcomm_request_can_send_now_event(rfcomm_cid);
387 return;
388 }
389 ag_send_ok = 0;
390 hsp_ag_send_str_over_rfcomm(rfcomm_cid, HSP_AG_OK);
391 return;
392 }
393
394 if (ag_send_error){
395 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
396 rfcomm_request_can_send_now_event(rfcomm_cid);
397 return;
398 }
399 ag_send_error = 0;
399 err = hsp_ag_send_str_over_rfcomm(rfcomm_cid, HSP_AG_ERROR);
400 if (err) {
401 ag_send_error = 1;
400 hsp_ag_send_str_over_rfcomm(rfcomm_cid, HSP_AG_ERROR);
401 return;
402 }
403
404 if (ag_ring){
405 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
406 rfcomm_request_can_send_now_event(rfcomm_cid);
407 return;
402 }
408 }
409 ag_ring = 0;
410 hsp_ag_send_str_over_rfcomm(rfcomm_cid, HSP_AG_RING);
403 return;
404 }
405
406 if (hsp_establish_audio_connection){
407 if (!hci_can_send_command_packet_now()) return;
408 hsp_establish_audio_connection = 0;
409 hci_send_cmd(&hci_setup_synchronous_connection, rfcomm_handle, 8000, 8000, 0xFFFF, hci_get_sco_voice_setting(), 0xFF, 0x003F);
410 return;

--- 15 unchanged lines hidden (view full) ---

426 switch (hsp_state){
427 case HSP_SDP_QUERY_RFCOMM_CHANNEL:
428 hsp_state = HSP_W4_SDP_EVENT_QUERY_COMPLETE;
429 log_info("Start SDP query %s, 0x%02x", bd_addr_to_str(remote), SDP_HSP);
430 sdp_client_query_rfcomm_channel_and_name_for_uuid(&handle_query_rfcomm_event, remote, SDP_HSP);
431 break;
432
433 case HSP_W4_RING_ANSWER:
411 return;
412 }
413
414 if (hsp_establish_audio_connection){
415 if (!hci_can_send_command_packet_now()) return;
416 hsp_establish_audio_connection = 0;
417 hci_send_cmd(&hci_setup_synchronous_connection, rfcomm_handle, 8000, 8000, 0xFFFF, hci_get_sco_voice_setting(), 0xFF, 0x003F);
418 return;

--- 15 unchanged lines hidden (view full) ---

434 switch (hsp_state){
435 case HSP_SDP_QUERY_RFCOMM_CHANNEL:
436 hsp_state = HSP_W4_SDP_EVENT_QUERY_COMPLETE;
437 log_info("Start SDP query %s, 0x%02x", bd_addr_to_str(remote), SDP_HSP);
438 sdp_client_query_rfcomm_channel_and_name_for_uuid(&handle_query_rfcomm_event, remote, SDP_HSP);
439 break;
440
441 case HSP_W4_RING_ANSWER:
434 if (ag_ring){
435 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
436 rfcomm_request_can_send_now_event(rfcomm_cid);
437 return;
438 }
439 ag_ring = 0;
440 err = hsp_ag_send_str_over_rfcomm(rfcomm_cid, HSP_AG_RING);
441 if (err) {
442 ag_ring = 1;
443 }
444 break;
442 if (!ag_num_button_press_received) break;
443
444 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
445 rfcomm_request_can_send_now_event(rfcomm_cid);
446 return;
445 }
446
447 }
448
447 if (!ag_num_button_press_received) break;
448 ag_send_ok = 0;
449 ag_send_ok = 0;
449
450 ag_num_button_press_received = 0;
451 hsp_state = HSP_W2_CONNECT_SCO;
452
450 ag_num_button_press_received = 0;
451 hsp_state = HSP_W2_CONNECT_SCO;
452
453 err = hsp_ag_send_str_over_rfcomm(rfcomm_cid, HSP_AG_OK);
454 if (err) {
455 hsp_state = HSP_W4_RING_ANSWER;
456 ag_num_button_press_received = 1;
457 }
453 hsp_ag_send_str_over_rfcomm(rfcomm_cid, HSP_AG_OK);
458 break;
459
460 case HSP_W2_CONNECT_SCO:
461 if (!hci_can_send_command_packet_now()) return;
462 hsp_state = HSP_W4_SCO_CONNECTED;
463 hci_send_cmd(&hci_setup_synchronous_connection, rfcomm_handle, 8000, 8000, 0xFFFF, hci_get_sco_voice_setting(), 0xFF, 0x003F);
464 break;
465

--- 15 unchanged lines hidden (view full) ---

481 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
482 rfcomm_request_can_send_now_event(rfcomm_cid);
483 return;
484 }
485 int gain = ag_microphone_gain;
486 ag_microphone_gain = -1;
487 char buffer[10];
488 sprintf(buffer, "%s=%d\r\n", HSP_MICROPHONE_GAIN, gain);
454 break;
455
456 case HSP_W2_CONNECT_SCO:
457 if (!hci_can_send_command_packet_now()) return;
458 hsp_state = HSP_W4_SCO_CONNECTED;
459 hci_send_cmd(&hci_setup_synchronous_connection, rfcomm_handle, 8000, 8000, 0xFFFF, hci_get_sco_voice_setting(), 0xFF, 0x003F);
460 break;
461

--- 15 unchanged lines hidden (view full) ---

477 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
478 rfcomm_request_can_send_now_event(rfcomm_cid);
479 return;
480 }
481 int gain = ag_microphone_gain;
482 ag_microphone_gain = -1;
483 char buffer[10];
484 sprintf(buffer, "%s=%d\r\n", HSP_MICROPHONE_GAIN, gain);
489 err = hsp_ag_send_str_over_rfcomm(rfcomm_cid, buffer);
490 if (err) {
491 ag_microphone_gain = gain;
492 }
485 hsp_ag_send_str_over_rfcomm(rfcomm_cid, buffer);
493 break;
494 }
495
496 if (ag_speaker_gain >= 0){
497 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
498 rfcomm_request_can_send_now_event(rfcomm_cid);
499 return;
500 }
501 int gain = ag_speaker_gain;
502 ag_speaker_gain = -1;
503 char buffer[10];
504 sprintf(buffer, "%s=%d\r\n", HSP_SPEAKER_GAIN, gain);
486 break;
487 }
488
489 if (ag_speaker_gain >= 0){
490 if (!rfcomm_can_send_packet_now(rfcomm_cid)) {
491 rfcomm_request_can_send_now_event(rfcomm_cid);
492 return;
493 }
494 int gain = ag_speaker_gain;
495 ag_speaker_gain = -1;
496 char buffer[10];
497 sprintf(buffer, "%s=%d\r\n", HSP_SPEAKER_GAIN, gain);
505 err = hsp_ag_send_str_over_rfcomm(rfcomm_cid, buffer);
506 if (err) {
507 ag_speaker_gain = gain;
508 }
498 hsp_ag_send_str_over_rfcomm(rfcomm_cid, buffer);
509 break;
510 }
511 break;
512 default:
513 break;
514 }
515}
516

--- 194 unchanged lines hidden ---
499 break;
500 }
501 break;
502 default:
503 break;
504 }
505}
506

--- 194 unchanged lines hidden ---