Gaming Dongle Feature Application Note

stitchCat發表於2024-07-01

References:

  • Gaming Dongle Feature Application Note

dongle傳送給headset的spp指令格式

image

(PS:這部分指令的的接收可以在headset的app_dongle_spp_cback函式看到,但在dongle部分的傳送指令原始碼似乎在sdk中看不到Σ(っ °Д °;)っ)

功能實現函式

headset部分

// headset和dongle連線且dongle判斷到pc/cellphone正在通話中,則dongle
// 會向headset傳送開啟enable mic的spp指令
// 處理enable mic的spp指令的回撥函式如下
static void app_dongle_spp_cback(T_BT_EVENT event_type, void *event_buf, uint16_t buf_len)
{
	...
    case BT_EVENT_SPP_DATA_IND:
        {
	...
		// 此處判斷Command type(Byte 3)是否為0x03,即DONGLE_CMD_REQ_OPEN_MIC
		else if (p_data[3] == DONGLE_CMD_REQ_OPEN_MIC)
		{
#if F_APP_APT_SUPPORT
                                uint8_t action = MMI_NULL;
#endif
				// 此處判斷Byte 4 為0x01(turn on mic)或0x00(turn off mic)
                                if (p_data[4] == 1)
                                {
                                    app_dongle_updata_mic_data_idx(true);
                                    app_transfer_queue_reset(CMD_PATH_SPP);

#if F_APP_APT_SUPPORT
                                    if (app_cfg_const.normal_apt_support &&
                                        app_apt_is_apt_on_state((T_ANC_APT_STATE)app_db.current_listening_state))
                                    {
                                        action = MMI_AUDIO_APT;
                                        app_db.dongle_is_disable_apt = true;
                                        app_dongle_control_apt(action);
                                    }
#endif
                                    app_bt_policy_qos_param_update(app_db.br_link[app_idx].bd_addr, BP_TPOLL_SPP_ENABLE);

#if F_APP_24G_BT_AUDIO_SOURCE_CTRL_SUPPORT
                                    if ((app_cfg_const.enable_24g_bt_audio_source_switch
                                         && (app_cfg_nv.allowed_source != ALLOWED_SOURCE_24G))
                                        || (app_hfp_get_call_status() != APP_CALL_IDLE))
                                    {
                                        // not to start recording, restore recording if needed.
                                        app_db.restore_dongle_recording = true;
                                    }
                                    else
#endif
                                    {
                                        app_dongle_update_is_mic_enable(true);
                                        app_dongle_start_recording(app_db.br_link[app_idx].bd_addr);
                                    }
                                }
                                else
                                {
                                    app_db.restore_dongle_recording = false;
                                    app_dongle_updata_mic_data_idx(true);
                                    app_dongle_update_is_mic_enable(false);
                                    app_dongle_stop_recording(app_db.br_link[app_idx].bd_addr);

                                    app_bt_policy_qos_param_update(app_db.br_link[app_idx].bd_addr, BP_TPOLL_SPP_DISABLE);

#if F_APP_APT_SUPPORT
                                    if (app_db.dongle_is_disable_apt &&
                                        (!app_apt_is_apt_on_state((T_ANC_APT_STATE)app_db.current_listening_state)))
                                    {
                                        action = MMI_AUDIO_APT;
                                        app_db.dongle_is_disable_apt = false;
                                        app_dongle_control_apt(action);
                                    }
#endif
                                }
                            }
                            else if (p_data[3] == DONGLE_CMD_SET_VOL_BALANCE)
                            {
                                if (p_data[4] == 1) // dongle to earphone
                                {
                                    // update record
                                    app_db.gaming_balance = p_data[5];
                                    app_db.chat_balance = p_data[6];
                                    app_dongle_volume_balance_report(DONGLE_CMD_ACK);
                                }
                            }
                            else if (p_data[3] == DONGLE_CMD_CTRL_RAW_DATA)
                            {
                                app_dongle_rcv_ctrl_data(p_data + 4, data_len - 4);
                            }
                            else if (p_data[3] == DONGLE_CMD_PASS_THROUGH_DATA)
                            {
                                if (p_data[4] == CMD_SYNC_BYTE) //AudioConnect cmd header check
                                {
                                    uint16_t cmd_len = (p_data[6] | (p_data[7] << 8)) + 4; //sync_byte, seqn, length_low, length_high
                                    uint8_t seqn = p_data[5];

                                    APP_PRINT_TRACE2("app_dongle_cmd_pass_through: 0x%02X, 0x%02X", cmd_len, seqn);

                                    app_cmd_handler(&p_data[8], (cmd_len - 4), CMD_PATH_SPP, seqn, app_idx);
                                }
                            }
#endif
#if F_APP_CFU_SPP_SUPPORT
                            else if (p_data[3] == DONGLE_CMD_CFU_DATA)
                            {
                                T_APP_CFU_DATA cfu_data;
                                memcpy(cfu_data.spp_data.bd_addr, param->spp_data_ind.bd_addr, 6);
                                if (app_cfu_spp_header_parse(payload_len - 1, p_data + 4, &cfu_data))
                                {
                                    app_cfu_handle_report(cfu_data.spp_data.report_id, APP_CFU_REPORT_SOURCE_SPP, &cfu_data);
                                }

                            }
#endif
#if F_APP_CUSTOMIZED_SBC_VP_FLOW_SUPPORT
                            else if (p_data[3] == DONGLE_CMD_ERASE_FLASH)
                            {
                                //Do erase & Send ack
                                app_dongle_receive_erase_cmd(p_data + 4);
                            }
                            else if (p_data[3] == DONGLE_CMD_WRITE_CUSTOMIZED_VP)
                            {
                                //Do write & Send ack
                                app_dongle_receive_customized_vp_data(payload_len - 1, p_data + 4);
                            }
                            else if (p_data[3] == DONGLE_CMD_WRITE_VP_FINISH)
                            {
                                //Dongle notifies write finish
                                app_dongle_write_vp_finish();
                            }
#endif
                        }
                    }
                }
            }
        }
        break;


}

連線dongle通話headset自動開啟mic log

 0008451  06-03#16:59:28.948  064  0044991.291  [BTM] bt_mgr_dispatch: msg 0x0704
 0008452  06-03#16:59:28.948  065  0044991.315  [BTM] !**bt_mgr_event_post: event_type 0x3005
 0008453  06-03#16:59:28.948  066  0044991.434  [PROFILE] !**spp_send_credit: addr[11::22::33::44::55::FE] server chann[0x11] credit[1]
 0008454  06-03#16:59:28.948  067  0044991.490  [RFCOMM] rfc_data_cfm: dlci 0x22, given credits 1
 0008455  06-03#16:59:28.948  068  0044991.510  [APP] app_dongle_spp_cback: 0x01, 0x02
 0008456  06-03#16:59:28.948  069  0044991.535  [APP] !**app_dongle_spp_cback 52, 01, 02, 03, 01, 54,
 0008457  06-03#16:59:28.948  070  0044991.655  [APP] !!*app_stop_timer: handle error 0, pointer 0x2c13f0
 0008458  06-03#16:59:28.948  071  0044991.961  [APP] app_bt_policy_qos_param_update: event 18, sco 0, a2dp_idx 0, avrcp 1, stream 1, active_tpoll 0, inactive_idx 4, bau_idx 4
 0008459  06-03#16:59:28.948  072  0044991.979  [APP] app_bt_policy_qos_param_update: enable_mic 0, gaming 1
 0008460  06-03#16:59:28.948  073  0044992.014  [APP] app_dongle_update_is_mic_enable: 1
 0008461  06-03#16:59:28.948  080  0044994.235  [APP] !**app_dongle_start_recording

dongle部分

該部分程式碼涉及到usb部分知識,因為不熟悉usb所以無能為力,但是在log部分可以看到一些通話開啟時usb的狀態變化

Line  8607:  0008607  06-27#16:19:18.743  160  0029084.647  [USB] !**usb_audio_driver_streaming_activate:dir:1,bit_width:16, cur_sample_rate:48000, chann_num:2, sample_rate_max_tolerance:48000
Line  8633:  0008633  06-27#16:19:18.757  188  0029091.647  [APP] !**ds_moniter_timeout_handle: set ds_streaming true
Line 19702:  0019702  06-27#16:19:33.031  132  0043350.966  [USB] !**usb_audio_driver_streaming_deactivate:1

相關文章