chore: Remove tracked build artifacts

This commit is contained in:
lmx
2025-11-28 16:24:27 +08:00
parent 892ed9267b
commit 818e8c3778
2356 changed files with 0 additions and 587882 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,84 +0,0 @@
#ifndef _3TH_PROTOCOL_API_H
#define _3TH_PROTOCOL_API_H
#include<string.h>
#include <stdint.h>
#include "typedef.h"
#include "os/os_api.h"
#include "btstack/third_party/app_protocol_event.h"
#include "app_protocol_common.h"
#define APP_PROTOCOL_TASK_NAME "app_proto"
//定义这几个宏仅仅用于编译优化代码量。需要那个选哪个flash够大可以全部都打开的。
//不要在板级头文件重复定义。
#define APP_PROTOCOL_DEMO_CODE 0
#define APP_PROTOCOL_GMA_CODE 0
#define APP_PROTOCOL_AMA_CODE 0
#define APP_PROTOCOL_DMA_CODE 0
#define APP_PROTOCOL_TME_CODE 0
#define APP_PROTOCOL_MMA_CODE 0
#define APP_PROTOCOL_GFPS_CODE 1
#define APP_PROTOCOL_SPEECH_EN 0 //语音助手功能,若无此功能则关掉
#define APP_PROTOCOL_READ_CFG_EN 0 //从custom.dat中读取配置信息若无此功能则关掉
#define DEMO_HANDLER_ID 0x300 /*作为一个使用的例子同时也可作为客户自己添加协议的ID*/
#define GMA_HANDLER_ID 0x400 /*阿里天猫协议接口ID*/
#define MMA_HANDLER_ID 0x500 /*小米MMA协议接口ID*/
#define DMA_HANDLER_ID 0x600 /*百度DMA协议接口ID*/
#define TME_HANDLER_ID 0x700 /*腾讯酷狗TME协议接口ID*/
#define AMA_HANDLER_ID 0x800 /*亚马逊的AMA协议接口ID*/
#define GFPS_HANDLER_ID 0x900 /*谷歌快对的协议接口ID*/
//app os task message
enum {
//Q_USER =0x400000
APP_PROTOCOL_RX_DATA_EVENT = (Q_USER + 100),
APP_PROTOCOL_TX_DATA_EVENT,
APP_PROTOCOL_TASK_EXIT,
};
//参数配置类接口(在库外面的文件common区)
//配置在init之前的参数接口
void app_protocol_set_product_id(u32 handler_id, u32 pid);
void app_protocol_set_vendor_id(u32 handler_id, u32 vid);
void app_protocol_set_local_version(u32 handler_id, u32 version);
void app_protocol_set_info_group(u32 handler_id, void *addr); //如配置三元组
void app_protocol_tws_role_check_register(u8(*handler)(void)); /*注册获取tws状态的函数接口*/
void app_protocol_set_tws_sibling_mac(u8 *mac);
//公共类函数接口
/*这个接口主要是建立一个线程注册一些协议需要用的公共接口比如resumemessage_handler等函数。建立了线程之后初始化*/
void app_protocol_all_init();
void app_protocol_init(int handler_id);
/*主要是删除线程操作在删除完之后再释放APP协议栈的资源*/
void app_protocol_exit(int handler_id);
/*开始语音识别功能*/
int app_protocol_start_speech_cmd();
/*手动停止语音识别功能*/
int app_protocol_stop_speech_cmd();
int app_protocol_left_start_speech_cmd();
int app_protocol_right_start_speech_cmd();
void app_protocol_update_battery(u8 main, u8 left, u8 right, u8 box);
void app_protocol_ble_adv_switch(int sw);
void app_protocol_ibeacon_switch(int sw);
void app_protocol_disconnect(void *addr);
void app_protocol_get_tws_data_for_lib(u8 *data, u32 len);
/*发送mic相应编码后的数据*/
int app_protocol_send_voice_data(uint8_t *voice_buf, uint16_t voice_len);
/*获取有没有链路连接完成状态*/
int app_protocol_check_connect_success();
bool is_tws_master_role();
u32 app_protocol_get_cur_handle_id();
int app_protocol_get_version_by_id(int id);
int app_protocol_reply_frame_check_result(int result);
void app_protocal_update_tws_state_to_lib(int state);
#endif

View File

@ -1,774 +0,0 @@
#include "app_protocol_api.h"
#include "app_protocol_common.h"
#include "system/includes.h"
#include "app_config.h"
#include "audio_config.h"
#include "app_chargestore.h"
#include "app_power_manage.h"
#include "asm/charge.h"
#include "bt_tws.h"
#include "btstack/avctp_user.h"
#include "3th_profile_api.h"
#include "bt_common.h"
#include "tone_player.h"
#include "app_main.h"
#include "key_event_deal.h"
#if AI_APP_PROTOCOL
#if 1
#define APP_PROTOCOL_LOG printf
#define APP_PROTOCOL_DUMP put_buf
#else
#define APP_PROTOCOL_LOG(...)
#define APP_PROTOCOL_DUMP(...)
#endif
__attribute__((weak))
void app_protocol_tone_play(int index, int tws_sync)
{
}
static const char **app_tone_table = NULL;
static struct app_protocol_private_handle_t *private_handle;
extern u8 get_remote_dev_company(void);
#define REMOTE_DEV_ANDROID 1
#define REMOTE_DEV_IOS 2
bool is_ios_system(void)
{
APP_PROTOCOL_LOG("remote_dev_company :%d \n", get_remote_dev_company());
return (get_remote_dev_company() == REMOTE_DEV_IOS);
}
void app_protocol_tone_register(const char **tone_table)
{
app_tone_table = tone_table;
}
const char *app_protocol_get_tone(int index)
{
if (app_tone_table) {
return app_tone_table[index];
}
return NULL;
}
void app_protocol_handle_register(struct app_protocol_private_handle_t *hd)
{
private_handle = hd;
}
struct app_protocol_private_handle_t *app_protocol_get_handle()
{
return private_handle;
}
//协议私有同步消息处理函数
void app_protocol_tws_sync_private_deal(int cmd, int value)
{
if (private_handle && private_handle->tws_sync_func) {
private_handle->tws_sync_func(cmd, value);
}
}
//协议私有收到对耳数据处理函数
void app_protocol_tws_rx_data_private_deal(u16 opcode, u8 *data, u16 len)
{
if (private_handle && private_handle->tws_rx_from_siblling) {
private_handle->tws_rx_from_siblling(opcode, data, len);
}
}
int app_protocol_sys_event_private_deal(struct sys_event *event)
{
if (private_handle && private_handle->sys_event_handler) {
return private_handle->sys_event_handler(event);
}
return 0;
}
#if APP_PROTOCOL_SPEECH_EN
#define APP_PROTOCOL_MIC_TIMEOUT 8000 //mic使用超时时间0不限时
static u16 mic_timer = 0;
static u16 tone_after_exit_sniff_timer = 0;
static u8 exit_sniff_cnt = 0;
void __app_protocol_speech_stop(void)
{
if (ai_mic_is_busy()) {
if (mic_timer) {
sys_timeout_del(mic_timer);
mic_timer = 0;
}
APP_PROTOCOL_LOG("app_protocol_speech_stop\n");
ai_mic_rec_close();
app_protocol_stop_speech_cmd();
}
}
static void app_protocol_speech_timeout(void *priv)
{
APP_PROTOCOL_LOG(" speech timeout !!! \n");
__app_protocol_speech_stop();
}
static int app_protocol_speech_start_check()
{
if (BT_STATUS_TAKEING_PHONE == get_bt_connect_status()) {
APP_PROTOCOL_LOG("phone ing...\n");
return -1;
}
if (ai_mic_is_busy()) {
APP_PROTOCOL_LOG("mic activing...\n");
return -1;
}
return 0;
}
int __app_protocol_speech_start(void)
{
if (!app_protocol_speech_start_check() && ai_mic_rec_start() == 0) {
#if APP_PROTOCOL_MIC_TIMEOUT
mic_timer = sys_timeout_add(NULL, app_protocol_speech_timeout, APP_PROTOCOL_MIC_TIMEOUT);
#endif
return 0;
}
APP_PROTOCOL_LOG("speech start fail\n");
return -1;
}
int app_protocol_start_speech_by_app(u8 tone_en)
{
if (app_protocol_speech_start_check()) {
return -1;
}
if (app_var.siri_stu) {
APP_PROTOCOL_LOG("siri activing...\n");
return -1;
}
if (tone_en) {
app_protocol_tone_play(APP_RROTOCOL_TONE_SPEECH_APP_START, 1);
} else {
app_protocol_post_bt_event(AI_EVENT_SPEECH_START, NULL);
}
return 0;
}
int app_protocol_stop_speech_by_app()
{
app_protocol_post_bt_event(AI_EVENT_SPEECH_STOP, NULL);
return 0;
}
static void speech_tone_play_after_exit_sniff()
{
tone_after_exit_sniff_timer = 0;
if (bt_is_sniff_close() && exit_sniff_cnt < 13) {
exit_sniff_cnt++;
tone_after_exit_sniff_timer = sys_timeout_add(NULL, speech_tone_play_after_exit_sniff, 100);
return;
}
exit_sniff_cnt = 0;
if (!app_protocol_speech_start_check()) {
app_protocol_tone_play(APP_RROTOCOL_TONE_SPEECH_KEY_START, 1);
}
}
int app_protocol_start_speech_by_key(struct sys_event *event)
{
#if TCFG_USER_TWS_ENABLE
if (get_bt_tws_connect_status() && !is_tws_master_role()) {
APP_PROTOCOL_LOG("tws slave, return\n");
return 0;
}
#endif
user_send_cmd_prepare(USER_CTRL_HFP_GET_SIRI_STATUS, 0, NULL);
if (app_protocol_speech_start_check()) {
return -1;
}
if (app_protocol_check_connect_success() && (get_curr_channel_state()&A2DP_CH)) {
printf("no connect\n");
} else {
if (get_curr_channel_state()&A2DP_CH) {
//<协议未连接, 但是A2DP已连接 点击唤醒键, 提示TTS【请打开小度APP】
if (is_ios_system()) {
APP_PROTOCOL_LOG("ble adv ibeaconn");
app_protocol_ibeacon_switch(1);
} else {
user_send_cmd_prepare(USER_CTRL_HFP_GET_SIRI_OPEN, 0, NULL);
}
app_protocol_tone_play(APP_PROTOCOL_TONE_DISCONNECTED_ALL, 1);
} else {
//<蓝牙完全关闭状态, 用户按唤醒键, 提示TTS【蓝牙未连接 请用手机蓝牙和我连接吧】
app_protocol_tone_play(APP_RROTOCOL_TONE_OPEN_APP, 1);
}
APP_PROTOCOL_LOG("A2dp or protocol no connect err!!!\n");
return -1;
}
#if 1//等退出sniff后再播提示音
if (bt_is_sniff_close()) {
user_send_cmd_prepare(USER_CTRL_ALL_SNIFF_EXIT, 0, NULL);
if (tone_after_exit_sniff_timer == 0) {
tone_after_exit_sniff_timer = sys_timeout_add(NULL, speech_tone_play_after_exit_sniff, 100);
}
return 0;
}
exit_sniff_cnt = 0;
#endif
app_protocol_tone_play(APP_RROTOCOL_TONE_SPEECH_KEY_START, 1);
return 0;
}
int app_protocol_stop_speech_by_key(void)
{
return 0;
}
#else
void __app_protocol_speech_stop(void)
{
}
#endif
void app_speech_tone_play_end_callback(void *priv, int flag)
{
u32 index = (u32)priv;
switch (index) {
#if APP_PROTOCOL_SPEECH_EN
case APP_RROTOCOL_TONE_SPEECH_KEY_START:
APP_PROTOCOL_LOG("APP_RROTOCOL_TONE_SPEECH_KEY_START\n");
if (app_protocol_speech_start_check()) {
break;
}
if (app_var.siri_stu) {
APP_PROTOCOL_LOG("siri activing...\n");
break;
}
///按键启动需要report, app启动 直接启动语音即可
if (is_tws_master_role() && !app_protocol_start_speech_cmd()) {//从转发mic数据给主机或主机上报完成开启mic
APP_PROTOCOL_LOG("app_protocol_mic_status_report success\n");
app_protocol_post_bt_event(AI_EVENT_SPEECH_START, NULL);
}
break;
case APP_RROTOCOL_TONE_SPEECH_APP_START:
APP_PROTOCOL_LOG("APP_RROTOCOL_TONE_SPEECH_APP_START\n");
if (app_protocol_speech_start_check()) {
break;
}
if (app_var.siri_stu) {
APP_PROTOCOL_LOG("siri activing...\n");
break;
}
if (is_tws_master_role()) {
app_protocol_post_bt_event(AI_EVENT_SPEECH_START, NULL);
}
break;
#endif
default:
break;
}
}
int app_protocol_set_volume(u8 vol)
{
u8 vol_l = (vol * get_max_sys_vol()) / 0x64;
u8 vol_r = (vol * get_max_sys_vol()) / 0x64;
app_audio_set_volume(APP_AUDIO_STATE_MUSIC, APP_AUDIO_STATE_MUSIC, vol_r);
return 0;
}
__attribute__((weak))
bool vbat_is_low_power(void)
{
return 0;
}
u8 app_protocal_get_bat_by_type(u8 type)
{
u8 value = 0;
extern u8 get_tws_sibling_bat_persent(void);
u8 sibling_val = get_tws_sibling_bat_persent();
#if TCFG_CHARGESTORE_ENABLE
if (sibling_val == 0xff) {
sibling_val = chargestore_get_sibling_power_level();
}
#endif
switch (type) {
case APP_PROTOCOL_BAT_T_CHARGE_FLAG:
value = get_charge_online_flag();
break;
case APP_PROTOCOL_BAT_T_MAIN:
value = get_vbat_percent();
break;
#if TCFG_CHARGESTORE_ENABLE
case APP_PROTOCOL_BAT_T_BOX:
value = chargestore_get_power_level();
break;
#endif
case APP_PROTOCOL_BAT_T_TWS_LEFT:
value = (tws_api_get_local_channel() == 'L') ? get_vbat_percent() : sibling_val;
break;
case APP_PROTOCOL_BAT_T_TWS_RIGHT:
value = (tws_api_get_local_channel() == 'R') ? get_vbat_percent() : sibling_val;
break;
case APP_PROTOCOL_BAT_T_TWS_SIBLING:
value = sibling_val;
break;
case APP_PROTOCOL_BAT_T_LOW_POWER:
value = vbat_is_low_power();
break;
default:
break;
}
if (value == 0xff) { //获取不到电量返回0
value = 0;
}
return value;
}
u32 read_cfg_file(void *buf, u16 len, char *path)
{
FILE *fp = fopen(path, "r");
int rlen;
if (!fp) {
//printf("read_cfg_file:fopen err!\n");
return FALSE;
}
rlen = fread(fp, buf, len);
if (rlen <= 0) {
//printf("read_cfg_file:fread err!\n");
return FALSE;
}
fclose(fp);
return TRUE;
}
#define LIC_PAGE_OFFSET 80
#define FORCE_TO_ERASE 1
typedef enum _FLASH_ERASER {
CHIP_ERASER = 0,
BLOCK_ERASER,
SECTOR_ERASER,
PAGE_ERASER,
} FLASH_ERASER;
typedef struct __flash_of_lic_para_head {
s16 crc;
u16 string_len;
const u8 para_string[];
} __attribute__((packed)) _flash_of_lic_para_head;
static bool license_para_head_check(u8 *para)
{
_flash_of_lic_para_head *head;
//fill head
head = (_flash_of_lic_para_head *)para;
///crc check
u8 *crc_data = (u8 *)(para + sizeof(((_flash_of_lic_para_head *)0)->crc));
u32 crc_len = sizeof(_flash_of_lic_para_head) - sizeof(((_flash_of_lic_para_head *)0)->crc)/*head crc*/ + (head->string_len)/*content crc,include end character '\0'*/;
s16 crc_sum = 0;
crc_sum = CRC16(crc_data, crc_len);
if (crc_sum != head->crc) {
printf("license crc error !!! %x %x \n", (u32)crc_sum, (u32)head->crc);
return false;
}
return true;
}
//获取三元组信息的头指针
const u8 *app_protocal_get_license_ptr(void)
{
u32 flash_capacity = sdfile_get_disk_capacity();
u32 flash_addr = flash_capacity - 256 + LIC_PAGE_OFFSET;
u8 *lic_ptr = NULL;
_flash_of_lic_para_head *head;
printf("flash capacity:%x \n", flash_capacity);
lic_ptr = (u8 *)sdfile_flash_addr2cpu_addr(flash_addr);
//head length check
head = (_flash_of_lic_para_head *)lic_ptr;
if (head->string_len >= 0xff) {
printf("license length error !!! \n");
return NULL;
}
////crc check
if (license_para_head_check(lic_ptr) == (false)) {
printf("license head check fail\n");
return NULL;
}
//put_buf(lic_ptr, 128);
lic_ptr += sizeof(_flash_of_lic_para_head);
return lic_ptr;
}
extern bool sfc_erase(int cmd, u32 addr);
extern u32 sfc_write(const u8 *buf, u32 addr, u32 len);
//将三元组信息保存到flash里面
int app_protocol_license2flash(const u8 *data, u16 len)
{
_flash_of_lic_para_head header;
u8 buffer[256];
u32 flash_capacity = sdfile_get_disk_capacity();
u32 sector = flash_capacity - 4 * 1024;
u32 page_addr = flash_capacity - 256;
u8 *auif_ptr = (u8 *)sdfile_flash_addr2cpu_addr(page_addr);
#if (!FORCE_TO_ERASE)
APP_PROTOCOL_LOG("not supported flash erase !!! \n");
return (-1);
#endif
///save last 256 byte
/* memset(buffer, 0xff, sizeof(buffer)); */
memcpy(buffer, auif_ptr, sizeof(buffer));
auif_ptr += LIC_PAGE_OFFSET;
header.string_len = len;
///length
memcpy(&buffer[LIC_PAGE_OFFSET + sizeof(header.crc)], &(header.string_len), sizeof(header.string_len));
///context
memcpy(&buffer[LIC_PAGE_OFFSET + sizeof(header)], data, len);
///crc
header.crc = CRC16(&buffer[LIC_PAGE_OFFSET + sizeof(header.crc)], sizeof(header.string_len) + header.string_len);
memcpy(&buffer[LIC_PAGE_OFFSET], &(header.crc), sizeof(header.crc));
///check if need update data to flash,erease license erea if there are some informations in license erea
if (!memcmp(auif_ptr, buffer + LIC_PAGE_OFFSET, len + sizeof(_flash_of_lic_para_head))) {
APP_PROTOCOL_LOG("flash information the same with license\n");
return 0;
}
APP_PROTOCOL_LOG("erase license sector \n");
sfc_erase(SECTOR_ERASER, sector);
APP_PROTOCOL_LOG("write license to flash \n");
sfc_write(buffer, page_addr, 256);
return 0;
}
int app_protocol_tws_send_to_sibling(u16 opcode, u8 *data, u16 len)
{
u8 send_data[len + 4];
printf("app protocol send data to sibling \n");
send_data[0] = opcode & 0xff;
send_data[1] = opcode >> 8;
send_data[2] = len & 0xff;
send_data[3] = len >> 8;
memcpy(send_data + 4, data, len);
return tws_api_send_data_to_sibling(send_data, sizeof(send_data), APP_PROTOCOL_TWS_SEND_ID);
}
static void __tws_rx_from_sibling(u8 *data)
{
u16 opcode = (data[1] << 8) | data[0];
u16 len = (data[3] << 8) | data[2];
u8 *rx_data = data + 4;
switch (opcode) {
case APP_PROTOCOL_TWS_FOR_LIB:
APP_PROTOCOL_LOG("APP_PROTOCOL_TWS_FOR_LIB");
app_protocol_get_tws_data_for_lib(rx_data, len);
break;
}
app_protocol_tws_rx_data_private_deal(opcode, rx_data, len);
free(data);
}
static void app_protocol_rx_from_sibling(void *_data, u16 len, bool rx)
{
int err = 0;
if (rx) {
printf(">>>%s \n", __func__);
printf("len :%d\n", len);
put_buf(_data, len);
u8 *rx_data = malloc(len);
memcpy(rx_data, _data, len);
int msg[4];
msg[0] = (int)__tws_rx_from_sibling;
msg[1] = 1;
msg[2] = (int)rx_data;
err = os_taskq_post_type("app_core", Q_CALLBACK, 3, msg);
if (err) {
printf("tws rx post fail\n");
}
}
}
//发送给对耳
REGISTER_TWS_FUNC_STUB(app_vol_sync_stub) = {
.func_id = APP_PROTOCOL_TWS_SEND_ID,
.func = app_protocol_rx_from_sibling,
};
//对耳同步执行
int app_protocol_tws_sync_send(int cmd, int value)
{
int data[2];
data[0] = cmd;
data[1] = value;
return tws_api_send_data_to_slave(data, sizeof(data), APP_PROTOCOL_TWS_SYNC_ID);
}
void app_protocol_tws_sync_deal(int cmd, int value)
{
switch (cmd) {
case APP_PROTOCOL_SYNC_TONE:
printf("APP_PROTOCOL_SYNC_TONE:%d\n", value);
app_protocol_tone_play(value, 0);
break;
}
app_protocol_tws_sync_private_deal(cmd, value);
}
static void app_protocol_tws_sync_rx(void *data, u16 len, bool rx)
{
int err = 0;
int *arg = (int *)data;
int msg[8];
msg[0] = (int)app_protocol_tws_sync_deal;
msg[1] = len / sizeof(int);
msg[2] = arg[0]; //cmd
msg[3] = arg[1]; //value
err = os_taskq_post_type("app_core", Q_CALLBACK, 2 + len / sizeof(int), msg);
if (err) {
printf("tws sync post fail\n");
}
}
REGISTER_TWS_FUNC_STUB(app_protocol_sync) = {
.func_id = APP_PROTOCOL_TWS_SYNC_ID,
.func = app_protocol_tws_sync_rx,
};
//在app_core任务里面进行处理
int app_protocol_post_app_core_callback(int callback, void *priv)
{
int msg[8];
msg[0] = callback;
msg[1] = 1;
msg[2] = (int)priv;
return os_taskq_post_type("app_core", Q_CALLBACK, 3, msg);
}
void app_protocol_post_bt_event(u8 event, void *priv)
{
struct sys_event e;
memset(&e, 0, sizeof(e));
e.type = SYS_BT_EVENT;
e.arg = (void *)SYS_BT_AI_EVENT_TYPE_STATUS;
e.u.bt.event = event;
e.u.bt.value = (int)priv;
sys_event_notify(&e);
}
static int app_protocol_bt_status_event_handler(struct bt_event *bt)
{
switch (bt->event) {
case BT_STATUS_INIT_OK:
app_protocol_all_init();
break;
case BT_STATUS_SECOND_CONNECTED:
case BT_STATUS_FIRST_CONNECTED:
if (app_protocol_check_connect_success()) {
app_protocol_tone_play(APP_PROTOCOL_TONE_CONNECTED_ALL_FINISH, 1);
} else {
app_protocol_tone_play(APP_PROTOCOL_TONE_CONNECTED_NEED_OPEN_APP, 1);
}
break;
case BT_STATUS_FIRST_DISCONNECT:
case BT_STATUS_SECOND_DISCONNECT:
app_protocol_tone_play(APP_PROTOCOL_TONE_DISCONNECTED, 1);
app_protocal_update_tws_state_to_lib(USER_NOTIFY_STATE_MOBILE_DISCONNECTED);
break;
case BT_STATUS_PHONE_INCOME:
case BT_STATUS_PHONE_OUT:
case BT_STATUS_PHONE_ACTIVE:
__app_protocol_speech_stop();
app_protocol_ble_adv_switch(0);
break;
case BT_STATUS_PHONE_HANGUP:
app_protocol_ble_adv_switch(1);
break;
case BT_STATUS_PHONE_MANUFACTURER:
if (!app_protocol_check_connect_success()) {
if (is_ios_system()) {
app_protocol_ibeacon_switch(1);
}
if (get_call_status() != BT_CALL_HANGUP) {
app_protocol_ble_adv_switch(0);
}
}
break;
case BT_STATUS_VOICE_RECOGNITION:
if ((app_var.siri_stu == 1) || (app_var.siri_stu == 2)) {
__app_protocol_speech_stop();
app_protocol_ble_adv_switch(0);
} else if (app_var.siri_stu == 0) {
app_protocol_ble_adv_switch(1);
}
break;
case BT_STATUS_CONN_A2DP_CH:
app_protocal_update_tws_state_to_lib(USER_NOTIFY_STATE_MOBILE_CONNECTED);
break;
}
return 0;
}
static void app_protocol_bt_tws_event_handler(struct bt_event *bt)
{
int role = bt->args[0];
int phone_link_connection = bt->args[1];
int reason = bt->args[2];
switch (bt->event) {
case TWS_EVENT_CONNECTED:
if (!is_tws_master_role()) {
app_protocol_disconnect(NULL);
app_protocol_ble_adv_switch(0);
} else {
#if APP_PROTOCOL_SPEECH_EN
if (ai_mic_is_busy()) { //mic在解码过程中从机连接成功挂起音频
ai_mic_tws_sync_suspend();
}
#endif
}
app_protocal_update_tws_state_to_lib(USER_NOTIFY_STATE_TWS_CONNECT);
break;
case TWS_EVENT_CONNECTION_DETACH:
if (!app_protocol_check_connect_success()) { //APP未连接开启广播
if (0 == get_esco_coder_busy_flag()) {
//esco在用的时候开广播会影响质量
app_protocol_ble_adv_switch(1);
}
}
#if APP_PROTOCOL_SPEECH_EN
if (!ai_mic_is_busy()) {
__app_protocol_speech_stop(); //对耳断开时没启动mic停止语音
}
#endif
app_protocal_update_tws_state_to_lib(USER_NOTIFY_STATE_BATTERY_LEVEL_UPDATE); //主动上报电量
app_protocal_update_tws_state_to_lib(USER_NOTIFY_STATE_TWS_DISCONNECT);
break;
case TWS_EVENT_ROLE_SWITCH:
app_protocal_update_tws_state_to_lib(USER_NOTIFY_STATE_ROLE_SWITCH_FINISH);
app_protocol_disconnect(NULL);
if (role == TWS_ROLE_MASTER && (0 == get_esco_coder_busy_flag())) {
app_protocol_ble_adv_switch(1);
} else {
app_protocol_ble_adv_switch(0);
}
break;
}
}
static int app_protocol_bt_ai_event_handler(struct bt_event *bt)
{
switch (bt->event) {
#if APP_PROTOCOL_SPEECH_EN
case AI_EVENT_SPEECH_START:
APP_PROTOCOL_LOG("AI_EVENT_SPEECH_START");
__app_protocol_speech_start();
break;
case AI_EVENT_SPEECH_STOP:
APP_PROTOCOL_LOG("AI_EVENT_SPEECH_STOP");
__app_protocol_speech_stop();
break;
#endif
case AI_EVENT_APP_CONNECT:
APP_PROTOCOL_LOG("AI_EVENT_APP_CONNECT");
if (get_curr_channel_state()&A2DP_CH) {
app_protocol_tone_play(APP_PROTOCOL_TONE_CONNECTED_ALL_FINISH, 1);
} else {
app_protocol_tone_play(APP_PROTOCOL_TONE_PROTOCOL_CONNECTED, 1);
}
break;
case AI_EVENT_APP_DISCONNECT:
APP_PROTOCOL_LOG("AI_EVENT_APP_DISCONNECT");
__app_protocol_speech_stop();
break;
}
return 0;
}
int app_protocol_sys_event_handler(struct sys_event *event)
{
#if TCFG_USER_GFPS_PROCESS_CTL
if (app_user_protocol_sys_event_remap_hdl(event) == true) {
return 0;
}
#endif
switch (event->type) {
case SYS_BT_EVENT:
if ((u32)event->arg == SYS_BT_EVENT_TYPE_CON_STATUS) {
app_protocol_bt_status_event_handler(&event->u.bt);
}
#if TCFG_USER_TWS_ENABLE
else if (((u32)event->arg == SYS_BT_EVENT_FROM_TWS)) {
app_protocol_bt_tws_event_handler(&event->u.bt);
}
#endif
else if (((u32)event->arg == SYS_BT_AI_EVENT_TYPE_STATUS)) {
app_protocol_bt_ai_event_handler(&event->u.bt);
}
break;
case SYS_KEY_EVENT:
app_protocol_key_event_handler(event);
break;
}
app_protocol_sys_event_private_deal(event);
return 0;
}
void tell_lib_start_role_switch()
{
app_protocol_ble_adv_switch(0);
if (is_tws_master_role()) {
printf("master dev will role switch\n");
app_protocal_update_tws_state_to_lib(USER_NOTIFY_STATE_ROLE_SWITCH_START);
/* os_time_dly(10); */
}
}
#else
int app_protocol_sys_event_handler(struct sys_event *event)
{
return 0;
}
void tell_lib_start_role_switch()
{
}
#endif

View File

@ -1,108 +0,0 @@
#ifndef _3TH_PROTOCOL_COMMON_H
#define _3TH_PROTOCOL_COMMON_H
#include <string.h>
#include <stdint.h>
#include "typedef.h"
#include "tone_player.h"
#include "audio_base.h"
#include "system/event.h"
#ifndef TONE_RES_ROOT_PATH
#if TCFG_NOR_FS && (TCFG_VIRFAT_FLASH_ENABLE == 0)
#define NOR_FLASH_RES_ROOT_PATH "storage/res_nor/C/"
#define TONE_RES_ROOT_PATH NOR_FLASH_RES_ROOT_PATH //内置flash提示音根路径
#else
#define TONE_RES_ROOT_PATH SDFILE_RES_ROOT_PATH //内置flash提示音根路径
#endif//TCFG_NOR_FS
#endif
#define APP_PROTOCOL_TWS_SYNC_ID 0xFFFF321A
#define APP_PROTOCOL_TWS_SEND_ID 0xFFFF321B
enum {
APP_PROTOCOL_TONE_CONNECTED_ALL_FINISH = 0,//所有连接完成【已连接你可以按AI键来和我进行对话】 ok
APP_PROTOCOL_TONE_PROTOCOL_CONNECTED,//APP已连接经典蓝牙未连接【请在手机上完成蓝牙配对】 con
APP_PROTOCOL_TONE_CONNECTED_NEED_OPEN_APP,//经典蓝牙已连接app未连接【已配对请打开app进行连接】 btcon
APP_PROTOCOL_TONE_DISCONNECTED,//经典蓝牙已断开【蓝牙已断开,请在手机上完成蓝牙配对】 dis
APP_PROTOCOL_TONE_DISCONNECTED_ALL,//经典蓝牙和【蓝牙未连接请用手机蓝牙和我连接吧】alldis
APP_RROTOCOL_TONE_OPEN_APP,//经典蓝牙已连接APP未连接【请打开APP】 app
APP_RROTOCOL_TONE_SPEECH_APP_START,//手机APP启动语音助手
APP_RROTOCOL_TONE_SPEECH_KEY_START,//按键启动语音助手
APP_RROTOCOL_TONE_MAX,//提示音最大数量
};
//发送给对耳的消息格式为opcode len data
enum {
APP_PROTOCOL_TWS_FOR_LIB = 0,
GMA_TWS_CMD_SYNC_LIC,
};
//对耳同步的命令格式为cmd value
enum {
APP_PROTOCOL_SYNC_TONE = 0,
};
//发送到系统事件处理的事件
enum {
AI_EVENT_SPEECH_START = 0,
AI_EVENT_SPEECH_STOP,
AI_EVENT_APP_CONNECT,
AI_EVENT_APP_DISCONNECT,
};
struct app_protocol_private_handle_t {
void (*tws_rx_from_siblling)(u16 opcode, u8 *data, u16 len); //收到对耳数据的处理接口
void (*tws_sync_func)(int cmd, int value); //对耳同步执行的接口
int (*sys_event_handler)(struct sys_event *event); //系统事件
};
//提示音注册和播放
void app_protocol_tone_register(const char **tone_table);
const char *app_protocol_get_tone(int index);
void app_protocol_tone_play(int index, int tws_sync);
void app_speech_tone_play_end_callback(void *priv, int flag); //提示音播放完毕回调函数
extern int ai_mic_is_busy(void); //mic正在被使用
extern int ai_mic_rec_start(void); //启动mic和编码模块
extern int ai_mic_rec_close(void); //停止mic和编码模块
extern bool bt_is_sniff_close(void);
//语音识别接口
int mic_rec_pram_init(/* const char **name, */u32 enc_type, u8 opus_type, u16(*speech_send)(u8 *buf, u16 len), u16 frame_num, u16 cbuf_size);
int __app_protocol_speech_start(void);
void __app_protocol_speech_stop(void);
int app_protocol_start_speech_by_app(u8 tone_en); //APP启动
int app_protocol_stop_speech_by_app(); //APP停止
int app_protocol_start_speech_by_key(struct sys_event *event); //按键启动
int app_protocol_stop_speech_by_key(void); //按键停止
//协议获取和设置一些设备信息接口
int app_protocol_set_volume(u8 vol);
u8 app_protocal_get_bat_by_type(u8 type);
u32 read_cfg_file(void *buf, u16 len, char *path);
const u8 *app_protocal_get_license_ptr(void); //获取三元组信息的头指针
int app_protocol_license2flash(const u8 *data, u16 len); //将三元组信息保存到flash里面
//事件处理函数指针列表注册和接口
void app_protocol_handle_register(struct app_protocol_private_handle_t *hd);
struct app_protocol_private_handle_t *app_protocol_get_handle();
void app_protocol_tws_sync_private_deal(int cmd, int value); //对耳同步事件私有协议处理函数
void app_protocol_tws_rx_data_private_deal(u16 opcode, u8 *data, u16 len); //私有协议处理来自对耳的数据函数
int app_protocol_sys_event_private_deal(struct sys_event *event); //私有协议处理系统事件函数
void app_protocol_post_bt_event(u8 event, void *priv); //发送到系统事件处理
int app_protocol_post_app_core_callback(int callback, void *priv); //放到app_core中处理
int app_protocol_tws_send_to_sibling(u16 opcode, u8 *data, u16 len); //发送命令数据给对耳
int app_protocol_tws_sync_send(int cmd, int value); //对耳同步执行命令
int app_protocol_key_event_handler(struct sys_event *event); //按键事件处理函数
int app_protocol_sys_event_handler(struct sys_event *event); //系统事件处理函数
#endif

View File

@ -1,147 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "app_protocol_api.h"
#include "system/includes.h"
#include "vm.h"
#include "audio_config.h"
#include "app_power_manage.h"
#include "user_cfg.h"
#if APP_PROTOCOL_DMA_CODE
#if 1
#define APP_DMA_LOG printf
#define APP_DMA_DUMP put_buf
#else
#define APP_DMA_LOG(...)
#define APP_DMA_DUMP(...)
#endif
//*********************************************************************************//
// DMA认证信息 //
//*********************************************************************************//
#define DMA_PRODUCT_INFO_TEST 0
#if DMA_PRODUCT_INFO_TEST
static const char *dma_product_id = "abcdeYghv0fy6HFexl6bTIZU123Z4n6H";
static const char *dma_triad_id = "A254BcBb000E00D200A0C0E3";
static const char *dma_secret = "bab8d7e0dc616630";
#endif
static const char *dma_product_key = "rcPXDpFbBOxXaDL9GZ8qLTWq7Yz8rWFm";
#define DMA_PRODUCT_ID_LEN 65
#define DMA_PRODUCT_KEY_LEN 65
#define DMA_TRIAD_ID_LEN 32
#define DMA_SECRET_LEN 32
#define DMA_LEGAL_CHAR(c) ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
static u16 dma_get_one_info(const u8 *in, u8 *out)
{
int read_len = 0;
const u8 *p = in;
while (DMA_LEGAL_CHAR(*p) && *p != ',') { //read Product ID
*out++ = *p++;
read_len++;
}
return read_len;
}
u8 read_dma_product_info_from_flash(u8 *read_buf, u16 buflen)
{
u8 *rp = read_buf;
const u8 *dma_ptr = (u8 *)app_protocal_get_license_ptr();
if (dma_ptr == NULL) {
return FALSE;
}
if (dma_get_one_info(dma_ptr, rp) != 32) {
return FALSE;
}
dma_ptr += 33;
rp = read_buf + DMA_PRODUCT_ID_LEN;
memcpy(rp, dma_product_key, strlen(dma_product_key));
rp = read_buf + DMA_PRODUCT_ID_LEN + DMA_PRODUCT_KEY_LEN;
if (dma_get_one_info(dma_ptr, rp) != 24) {
return FALSE;
}
dma_ptr += 25;
rp = read_buf + DMA_PRODUCT_ID_LEN + DMA_PRODUCT_KEY_LEN + DMA_TRIAD_ID_LEN;
if (dma_get_one_info(dma_ptr, rp) != 16) {
return FALSE;
}
return TRUE;
}
__attribute__((weak))
void bt_update_testbox_addr(u8 *addr)
{
}
void dueros_dma_manufacturer_info_init()
{
u8 read_buf[DMA_PRODUCT_ID_LEN + DMA_PRODUCT_KEY_LEN + DMA_TRIAD_ID_LEN + DMA_SECRET_LEN + 1] = {0};
bool ret = FALSE;
APP_DMA_LOG("dueros_dma_manufacturer_info_init\n");
#if DMA_PRODUCT_INFO_TEST
memcpy(read_buf, dma_product_id, strlen(dma_product_id));
memcpy(read_buf + DMA_PRODUCT_ID_LEN, dma_product_key, strlen(dma_product_key));
memcpy(read_buf + DMA_PRODUCT_ID_LEN + DMA_PRODUCT_KEY_LEN, dma_triad_id, strlen(dma_triad_id));
memcpy(read_buf + DMA_PRODUCT_ID_LEN + DMA_PRODUCT_KEY_LEN + DMA_TRIAD_ID_LEN, dma_secret, strlen(dma_secret));
ret = TRUE;
#else
// ret = read_dma_product_info_from_flash(read_buf, sizeof(read_buf));
#endif
if (ret == TRUE) {
APP_DMA_LOG("read license success\n");
APP_DMA_LOG("product id: %s\n", read_buf);
APP_DMA_LOG("product key: %s\n", read_buf + DMA_PRODUCT_ID_LEN);
APP_DMA_LOG("triad id: %s\n", read_buf + DMA_PRODUCT_ID_LEN + DMA_PRODUCT_KEY_LEN);
APP_DMA_LOG("secret: %s\n", read_buf + DMA_PRODUCT_ID_LEN + DMA_PRODUCT_KEY_LEN + DMA_TRIAD_ID_LEN);
app_protocol_set_info_group(DMA_HANDLER_ID, read_buf);
} else {
app_protocol_set_info_group(DMA_HANDLER_ID, NULL);
}
#if 1
u8 mac[] = {0xF4, 0x43, 0x8D, 0x29, 0x17, 0x02};
u8 ble_mac[6];
void bt_update_mac_addr(u8 * addr);
void lmp_hci_write_local_address(const u8 * addr);
void bt_update_testbox_addr(u8 * addr);
extern int le_controller_set_mac(void *addr);
//extern void lib_make_ble_address(u8 * ble_address, u8 * edr_address);
bt_update_mac_addr(mac);
lmp_hci_write_local_address(mac);
bt_update_testbox_addr(mac);
//lib_make_ble_address(ble_mac, mac);
le_controller_set_mac(mac); //修改BLE地址
APP_DMA_DUMP(mac, 6);
APP_DMA_DUMP(ble_mac, 6);
#endif
}
//*********************************************************************************//
// DMA提示音 //
//*********************************************************************************//
const char *dma_notice_tab[APP_RROTOCOL_TONE_MAX] = {
[APP_PROTOCOL_TONE_CONNECTED_ALL_FINISH] = TONE_RES_ROOT_PATH"tone/xd_ok.*",//所有连接完成【已连接你可以按AI键来和我进行对话】
[APP_PROTOCOL_TONE_PROTOCOL_CONNECTED] = TONE_RES_ROOT_PATH"tone/xd_con.*",//小度APP已连接经典蓝牙未连接【请在手机上完成蓝牙配对】
[APP_PROTOCOL_TONE_CONNECTED_NEED_OPEN_APP] = TONE_RES_ROOT_PATH"tone/xd_btcon.*",//经典蓝牙已连接小度app未连接【已配对请打开小度app进行连接】
[APP_PROTOCOL_TONE_DISCONNECTED] = TONE_RES_ROOT_PATH"tone/xd_dis.*",//经典蓝牙已断开【蓝牙已断开,请在手机上完成蓝牙配对】
[APP_PROTOCOL_TONE_DISCONNECTED_ALL] = TONE_RES_ROOT_PATH"tone/xd_alldis.*",//经典蓝牙和小度都断开了【蓝牙未连接,请用手机蓝牙和我连接吧】
[APP_RROTOCOL_TONE_SPEECH_APP_START] = TONE_NORMAL,
[APP_RROTOCOL_TONE_SPEECH_KEY_START] = TONE_NORMAL,
};
#endif

View File

@ -1,424 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "app_protocol_api.h"
#include "system/includes.h"
#include "vm.h"
#include "audio_config.h"
#include "app_power_manage.h"
#include "user_cfg.h"
#include "earphone.h"
#include "btstack/avctp_user.h"
#include "btstack/bluetooth.h"
#include "bt_tws.h"
#if AI_APP_PROTOCOL
#if APP_PROTOCOL_GFPS_CODE
extern void *gfps_app_ble_hdl;
/* extern u32 unactice_device_cmd_prepare(USER_CMD_TYPE cmd, u16 param_len, u8 *param); */
extern void tws_dual_conn_close();
extern int gfps_tws_data_deal(u8 *data, int len);
extern void audio_app_volume_set(u8 state, s16 volume, u8 fade);
extern bool get_gfps_pair_state(void);
extern void set_gfps_pair_state(u8 state);
extern void gfps_set_battery_ui_enable(uint8_t enable);
extern void gfps_set_pair_mode(void *priv);
extern void gfps_all_info_recover(u8 name_reset);
extern void gfps_sibling_sync_info();
extern int gfps_disconnect(void *addr);
extern void gfps_bt_ble_adv_enable(u8 enable);
extern void gfps_adv_interval_set(u16 value);
extern void gfps_sibling_data_send(u8 type, u8 *data, u16 len);
extern int gfps_ble_adv_enable(u8 enable);
extern void gfps_battery_update(void);
extern void bt_set_need_keep_scan(u8 en);
extern int audio_digital_vol_update_parm(u8 dvol_idx, s32 param);
extern void set_wait_poweroff_time(u16 time);
/**
弹窗的逻辑:
1、没有任何手机配对记录情况广播初始配对广播。
2、开机有配对记录广播后续配对广播回连超时进入配对状态时广播初始配对广播。
3、回连手机发现linkkey_missing且没有任何手机配对记录了广播初始配对广播。
4、连上任意一台手机后 广播后续配对广播,断开进入配对状态也是广播后续配对广播。(客户要求断开后也广播初始配对广播)
5、恢复出厂设置时需要调用一下gfps_all_info_recover(1)清除一下GFP的账号信息和修改的蓝牙名字
6、认证的时候需要有一个UI来触发初始配对广播调用gfps_set_pair_mode(NULL)可以为长按左右耳5秒之类的
7、耳机关机要关电量显示
*/
#define TONE_GOOGLE "tone_en/google.*"
#define GFPS_SIBLING_SYNC_TYPE_ADV_MAC_STATE 0x04
#define ADV_INIT_PAIR_IN_PAIR_MODE 0 //进入配对状态广播初始配对广播
struct gfps_protocol_t {
u8 poweron_reconn;
u8 close_icon;
};
static struct gfps_protocol_t gfps_protocol = {0};
#define __this (&gfps_protocol)
#define INIT_PAIR_ADV_INTERVAL 150
#define SUBS_PAIR_ADV_INTERVAL 352
void gfps_set_pair_mode_by_user(u8 disconn_ble)
{
if (disconn_ble) {
gfps_disconnect(NULL);
}
gfps_adv_interval_set(INIT_PAIR_ADV_INTERVAL);
set_gfps_pair_state(0);
gfps_bt_ble_adv_enable(0);
gfps_bt_ble_adv_enable(1);
}
//重写弱函数,获取电量
extern u8 get_charge_online_flag(void);
extern u8 get_tws_sibling_bat_persent(void);
void generate_rfcomm_battery_data(u8 *data)
{
u8 self_val = get_charge_online_flag() << 7 | get_vbat_percent();
#if TCFG_USER_TWS_ENABLE
u8 sibling_val = get_tws_sibling_bat_persent();
data[2] = 0xFF; //充电仓电量
#if TCFG_CHARGESTORE_ENABLE
if (self_val >> 7 || sibling_val >> 7) { //有任意一直耳机充电时才显示充电仓电量
data[2] = chargestore_get_power_level(); //充电仓电量
}
#endif
data[0] = (tws_api_get_local_channel() == 'L') ? self_val : sibling_val; //左耳电量
data[1] = (tws_api_get_local_channel() == 'R') ? self_val : sibling_val; //右耳电量
#else
data[0] = self_val;
data[1] = 0xFF;
data[2] = 0xFF;
#endif
printf("%s, l:%x, r:%x, bat:%x", __func__, data[0], data[1], data[2]);
}
extern int lmp_hci_write_scan_enable(u8 enable);
static void gfps_ctl_bt_enter_pair_mode()
{
printf("%s", __func__);
tws_dual_conn_close();
lmp_hci_write_scan_enable((1 << 1) | 1);
bt_set_need_keep_scan(1);
}
//重写弱函数GFP-BLE配对认证成功后需要先断开一个设备或者开可连接等手机连接经典蓝牙
extern u8 *get_cur_connect_phone_mac_addr(void);
void gfps_before_pair_new_device(u8 *seeker_addr)
{
#if TCFG_USER_GFPS_PROCESS_CTL
app_user_gfps_before_pair_new_device(seeker_addr);
#else
u8 remote_edr_addr[6];
u8 *tmp_addr = NULL;
for (int i = 0; i < 6; i ++) {
remote_edr_addr[i] = seeker_addr[5 - i];
}
if (get_curr_channel_state()) {
tmp_addr = get_cur_connect_phone_mac_addr();
if (memcmp(tmp_addr, remote_edr_addr, 6) != 0) {
printf("Subsequent pair\n");
printf("USER_CTRL_DISCONNECTION_HCI send\n");
user_send_cmd_prepare(USER_CTRL_DISCONNECTION_HCI, 0, NULL);
} else {
printf("Retroactive Pair\n");
}
}
printf("func:%s, line:%d", __FUNCTION__, __LINE__);
#endif
}
struct google_tone_ctl_t {
u8 l_en;
u8 r_en;
u8 l_mute;
u8 r_mute;
};
static struct google_tone_ctl_t google_tone_ctl = {0};
static void google_tone_set_volume()
{
printf("google_tone_set_volume");
/* printf("func:%s:%d", __FUNCTION__, app_audio_volume_max_query(SysVol_TONE)); */
/* u32 param = VOLUME_NODE_CMD_SET_VOL | app_audio_volume_max_query(SysVol_TONE); */
/* jlstream_set_node_param(NODE_UUID_VOLUME_CTRLER, "Vol_BtcRing", &param, sizeof(param)); */
}
/* #if TCFG_USER_TWS_ENABLE */
/* static void tws_google_tone_callback(int priv, enum stream_event event) */
/* { */
/* printf("func:%s, event:%d", __FUNCTION__, event); */
/* if (event == STREAM_EVENT_START) { */
/* int msg[] = {(int)google_tone_set_volume, 0}; */
/* os_taskq_post_type("app_core", Q_CALLBACK, ARRAY_SIZE(msg), msg); */
/* } */
/* } */
/* REGISTER_TWS_TONE_CALLBACK(tws_google_tone_stub) = { */
/* .func_uuid = 0x2EC850AE, */
/* .callback = tws_google_tone_callback, */
/* }; */
/* #endif */
/* static int google_tone_play_callback(void *priv, enum stream_event event) */
/* { */
/* printf("func:%s, event:%d", __FUNCTION__, event); */
/* if (event == STREAM_EVENT_START) { */
/* int msg[] = {(int)google_tone_set_volume, 0}; */
/* os_taskq_post_type("app_core", Q_CALLBACK, ARRAY_SIZE(msg), msg); */
/* } */
/* return 0; */
/* } */
void google_tone_play_deal()
{
if (strcmp(os_current_task(), "app_core")) {
printf("%s, task:%s", __func__, os_current_task());
int msg[] = {(int)google_tone_play_deal, 0};
os_taskq_post_type("app_core", Q_CALLBACK, ARRAY_SIZE(msg), msg);
return;
}
/* tone_player_stop(); */
/* tone_player_play(); */
}
void google_tone_mute_ctl(u8 self, u8 charge_flag)
{
u8 *mute = &google_tone_ctl.l_mute;
if ((tws_api_get_local_channel() == 'L' && !self) ||
(tws_api_get_local_channel() == 'R' && self)) {
mute = &google_tone_ctl.r_mute;
printf("%s, r_mute:%d, charge_flag:%d", __func__, *mute, charge_flag);
} else {
printf("%s, l_mute:%d, charge_flag:%d", __func__, *mute, charge_flag);
}
if (*mute != charge_flag) {
*mute = charge_flag;
google_tone_play_deal();
}
}
int gfps_protocol_tws_send_to_sibling(u16 opcode, u8 *data, u16 len)
{
return tws_api_send_data_to_sibling(data, len, 0x23080315);
}
static void __tws_rx_from_sibling(u8 *data, int len)
{
gfps_tws_data_deal(data, len);
switch (data[0]) {
case GFPS_SIBLING_SYNC_TYPE_ADV_MAC_STATE:
gfps_adv_interval_set(data[1] ? SUBS_PAIR_ADV_INTERVAL : INIT_PAIR_ADV_INTERVAL);
set_gfps_pair_state(data[1]);
le_controller_set_mac((void *)&data[2]);
gfps_bt_ble_adv_enable(0);
gfps_bt_ble_adv_enable(1);
break;
}
free(data);
}
static void gfps_protocol_rx_from_sibling(void *_data, u16 len, bool rx)
{
int err = 0;
if (rx) {
printf(">>>%s \n", __func__);
printf("len :%d\n", len);
put_buf(_data, len);
u8 *rx_data = malloc(len);
if (!rx_data) {
return;
}
memcpy(rx_data, _data, len);
int msg[4];
msg[0] = (int)__tws_rx_from_sibling;
msg[1] = 2;
msg[2] = (int)rx_data;
msg[3] = (int)len;
err = os_taskq_post_type("app_core", Q_CALLBACK, ARRAY_SIZE(msg), msg);
if (err) {
printf("tws rx post fail\n");
}
}
}
//发送给对耳
REGISTER_TWS_FUNC_STUB(app_vol_sync_stub) = {
.func_id = 0x23080315,
.func = gfps_protocol_rx_from_sibling,
};
int gfps_message_deal_handler(int id, int opcode, u8 *data, u32 len)
{
switch (opcode) {
case APP_PROTOCOL_LIB_TWS_DATA_SYNC:
gfps_protocol_tws_send_to_sibling(opcode, data, len);
break;
case APP_PROTOCOL_GFPS_RING_STOP_ALL:
printf("GFPS_RING_STOP_ALL");
google_tone_ctl.l_en = 0;
google_tone_ctl.r_en = 0;
google_tone_play_deal();
break;
case APP_PROTOCOL_GFPS_RING_RIGHT:
printf("GFPS_RING_RIGHT");
google_tone_ctl.l_en = 0;
google_tone_ctl.r_en = 1;
google_tone_play_deal();
break;
case APP_PROTOCOL_GFPS_RING_LEFT:
printf("GFPS_RING_LEFT");
google_tone_ctl.l_en = 1;
google_tone_ctl.r_en = 0;
google_tone_play_deal();
break;
case APP_PROTOCOL_GFPS_RING_ALL:
printf("GFPS_RING_ALL");
google_tone_ctl.l_en = 1;
google_tone_ctl.r_en = 1;
google_tone_play_deal();
break;
case APP_PROTOCOL_GFPS_HEARABLE_CONTROLS:
printf("APP_PROTOCOL_GFPS_HEARABLE_CONTROLS display:%x settable:%x current:%x\n", data[0], data[1], data[2]);
break;
}
return 0;
}
//关机广播收仓
void gfps_need_adv_close_icon_set(u8 en)
{
printf("func:%s, en:%d", __FUNCTION__, en);
__this->close_icon = en;
}
void gfps_poweroff_adv_close_icon()
{
printf("func:%s, line:%d", __FUNCTION__, __LINE__);
if (__this->close_icon) {
void set_wait_poweroff_time(u16 time);
set_wait_poweroff_time(2000); //广播800ms
gfps_adv_interval_set(48); //连接上手机间隔改为30ms
gfps_set_battery_ui_enable(0); //关闭电量显示,会重新开关广播
}
}
int gfps_hci_event_handler(struct bt_event *bt)
{
switch (bt->event) {
case HCI_EVENT_DISCONNECTION_COMPLETE:
switch (bt->value) {
case ERROR_CODE_PIN_OR_KEY_MISSING:
printf("GFP linkkey missing");
if (!btstack_get_num_of_remote_device_recorded()) { //没有配对记录的时候,广播初始配对广播
gfps_all_info_recover(0);
gfps_adv_interval_set(INIT_PAIR_ADV_INTERVAL); //连接上手机间隔改为93.75ms
gfps_set_pair_mode_by_user(0);
}
break;
}
break;
}
return 0;
}
int gfps_bt_status_event_handler(struct bt_event *bt)
{
u8 ret = 0;
switch (bt->event) {
// 需要切换蓝牙的命令
case BT_STATUS_A2DP_MEDIA_START:
break;
case BT_STATUS_INIT_OK:
if (btstack_get_num_of_remote_device_recorded()) {
__this->poweron_reconn = 1;
}
break;
case BT_STATUS_SECOND_CONNECTED:
case BT_STATUS_FIRST_CONNECTED:
__this->poweron_reconn = 0;
gfps_adv_interval_set(SUBS_PAIR_ADV_INTERVAL); //连接上手机间隔改为220ms防止fast pair validator测试fail
set_gfps_pair_state(1);
gfps_bt_ble_adv_enable(0);
gfps_bt_ble_adv_enable(1);
break;
case BT_STATUS_PHONE_INCOME:
case BT_STATUS_PHONE_OUT:
case BT_STATUS_PHONE_ACTIVE:
gfps_ble_adv_enable(0);
break;
case BT_STATUS_PHONE_HANGUP:
gfps_ble_adv_enable(1);
break;
}
return 0;
}
static int gfps_app_power_event_handler(struct device_event *dev)
{
switch (dev->event) {
#if TCFG_USER_TWS_ENABLE
case POWER_EVENT_SYNC_TWS_VBAT_LEVEL:
printf("update gfps bat");
if (get_tws_sibling_bat_persent() != 0xFF) {
google_tone_mute_ctl(0, get_tws_sibling_bat_persent() >> 7);
}
gfps_battery_update();
break;
#endif
case POWER_EVENT_POWER_CHANGE:
printf("update gfps bat");
google_tone_mute_ctl(1, get_charge_online_flag());
gfps_battery_update();
break;
}
return 0;
}
int gfps_sys_event_handler_specific(struct sys_event *event)
{
switch (event->type) {
case SYS_DEVICE_EVENT:
if ((u32)event->arg == DEVICE_EVENT_FROM_POWER) {
gfps_app_power_event_handler(&event->u.dev);
}
break;
case SYS_BT_EVENT:
if ((u32)event->arg == SYS_BT_EVENT_TYPE_CON_STATUS) {
gfps_bt_status_event_handler(&event->u.bt);
} else if ((u32)event->arg == SYS_BT_EVENT_TYPE_HCI_STATUS) {
gfps_hci_event_handler(&event->u.bt);
}
break;
}
return 0;
}
struct app_protocol_private_handle_t gfps_private_handle = {
.sys_event_handler = gfps_sys_event_handler_specific,
};
#endif
#endif

View File

@ -1,557 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "app_protocol_api.h"
#include "system/includes.h"
#include "vm.h"
#include "audio_config.h"
#include "app_power_manage.h"
#include "user_cfg.h"
#if APP_PROTOCOL_GMA_CODE
#if 1
#define APP_GMA_LOG printf
#define APP_GMA_DUMP put_buf
#else
#define APP_GMA_LOG(...)
#define APP_GMA_DUMP(...)
#endif
//*********************************************************************************//
// GMA认证信息 //
//*********************************************************************************//
#define GMA_GMA_FROM_FLASH 0
#define GMA_GMA_FROM_FILE 1
#define GMA_GMA_SOURCH GMA_GMA_FROM_FLASH
extern int le_controller_set_mac(void *addr);
extern void lmp_hci_write_local_address(const u8 *addr);
extern void lmp_hci_read_local_address(u8 *addr);
extern void bt_update_testbox_addr(u8 *addr);
typedef struct {
uint8_t mac[6];
uint32_t pid;
uint8_t secret[16];
} ali_para_s;
static ali_para_s ali_para;
static ali_para_s *active_ali_para = NULL;
///mac reverse
void gma_mac_addr_reverse_get(uint8_t *buf)
{
memcpy(buf, (const void *)active_ali_para->mac, 6);
}
#define LEGAL_PID_NUM(cha) (cha>='0' && cha<='9')
#define LEGAL_MAC_NUM(cha) ((cha>='0'&&cha<='9') || (cha>='a'&&cha<='f') || (cha>='A'&&cha<='F') || (cha==':'))
#define LEGAL_SECRET_NUM(cha) ((cha>='0'&&cha<='9') || (cha>='a'&&cha<='f') || (cha>='A'&&cha<='F'))
#define USELESS_CHAR ':'
#define GMA_ALI_PARA_END_CHAR ','
#define GMA_ALI_PARA_MAC_CHAR_NUMS (sizeof(((ali_para_s *)0)->mac))
#define GMA_ALI_PARA_PID_CHAR_NUMS 4//(sizeof(((ali_para_s *)0)->pid))
#define GMA_ALI_PARA_SECRET_CHAR_NUMS (sizeof(((ali_para_s *)0)->secret))
static u8 gma_ali_para_char2num(u8 cha)
{
u8 num = 0;
if (cha >= '0' && cha <= '9') {
num = cha - '0';
} else if (cha >= 'a' && cha <= 'f') {
num = cha - 'a' + 10;
} else if (cha >= 'A' && cha <= 'F') {
num = cha - 'A' + 10;
}
return num;
}
static int gma_license_set(ali_para_s *ali_para)
{
const u8 *gma_ptr = (u8 *)app_protocal_get_license_ptr();
if (gma_ptr == NULL) {
return -1;
}
///license fill
//pid
memcpy((u8 *) & (ali_para->pid), gma_ptr, sizeof(ali_para->pid));
gma_ptr += sizeof(ali_para->pid);
APP_GMA_LOG("gma pid:%d \n", ali_para->pid);
//secret
memcpy((u8 *)(ali_para->secret), gma_ptr, sizeof(ali_para->secret));
gma_ptr += sizeof(ali_para->secret);
APP_GMA_LOG("gma secret:");
APP_GMA_DUMP(ali_para->secret, sizeof(ali_para->secret));
//mac
memcpy((u8 *)(ali_para->mac), gma_ptr, sizeof(ali_para->mac));
gma_ptr += sizeof(ali_para->mac);
{
//mac reverse
u8 mac_backup_buf[6];
memcpy(mac_backup_buf, ali_para->mac, 6);
int i;
for (i = 0; i < 6; i++) {
ali_para->mac[i] = (mac_backup_buf)[5 - i];
}
}
APP_GMA_LOG("gma mac:");
APP_GMA_DUMP(ali_para->mac, sizeof(ali_para->mac));
return 0;
}
#if GMA_GMA_SOURCH == GMA_GMA_FROM_FILE
#define ALI_PARA_ACTIVE_NUM 1
static const char *ali_para_string[] = {
"jl_auif",
//Product ID,Device Secret,Mac,Md5
//此处可以用户自行填写从阿里申请的三元组信息
" ",
};
static bool gma_ali_para_info_fill(const u8 *para, ali_para_s *ali_para)
{
const u8 *para_string = para;
u8 highbit_en = 0;
uint32_t pid = 0;
uint32_t char_nums = 0;
uint8_t *secret = ali_para->secret;
uint8_t *mac = ali_para->mac;
while (*para_string && *para_string != GMA_ALI_PARA_END_CHAR) {
if (!LEGAL_PID_NUM(*para_string)) {
/* APP_GMA_LOG("pid illegal character !!! \n"); */
para_string++;
continue;
}
///check pid character numbers legal scope
char_nums++;
if (char_nums > GMA_ALI_PARA_PID_CHAR_NUMS) {
APP_GMA_LOG("pid character numbers overflow !!! \n");
return false;
}
pid *= 10;
pid += gma_ali_para_char2num(*para_string);
para_string++;
}
///check pid character numbers legal scope
if (char_nums != GMA_ALI_PARA_PID_CHAR_NUMS) {
APP_GMA_LOG("pid character numbers error:%d !!! \n", char_nums);
return false;
}
APP_GMA_LOG(">>pid:%d \n", pid);
ali_para->pid = pid;
para_string++;
char_nums = 0;
memset(ali_para->secret, 0x00, sizeof(ali_para->secret));
while (*para_string != GMA_ALI_PARA_END_CHAR) {
if (!LEGAL_SECRET_NUM(*para_string)) {
APP_GMA_LOG("secret illegal character !!! \n");
para_string++;
continue;
}
///assignment secret
if (!highbit_en) {
*secret += gma_ali_para_char2num(*para_string);
highbit_en ^= 1;
} else {
///check secret character numbers legal scope
char_nums++;
if (char_nums > GMA_ALI_PARA_SECRET_CHAR_NUMS) {
APP_GMA_LOG("secret character number overflow !!! \n");
return false;
}
*secret <<= 4;
*secret++ += gma_ali_para_char2num(*para_string);
highbit_en ^= 1;
}
para_string++;
}
///check secret character numbers legal scope
if (char_nums != GMA_ALI_PARA_SECRET_CHAR_NUMS) {
APP_GMA_LOG("secret character number error !!! :%d \n", char_nums);
return false;
}
///print secret
APP_GMA_LOG(">>ali_para secret: ");
for (int i = 0; i < sizeof(ali_para->secret) / sizeof(ali_para->secret[0]); i++) {
APP_GMA_LOG("%x ", ali_para->secret[i]);
}
memset(ali_para->mac, 0x00, sizeof(ali_para->mac));
para_string++;
highbit_en = 0;
char_nums = 0;
while (*para_string != GMA_ALI_PARA_END_CHAR) {
//if legal character
if (!LEGAL_MAC_NUM(*para_string)) {
APP_GMA_LOG("mac illegal character !!! \n");
para_string++;
continue;
// return false;
}
if (*para_string == USELESS_CHAR) {
para_string++;
continue;
}
///assignment mac
if (!highbit_en) {
*mac += gma_ali_para_char2num(*para_string);
highbit_en ^= 1;
} else {
//check mac character numbers legal scope
char_nums++;
if (char_nums > GMA_ALI_PARA_MAC_CHAR_NUMS) {
APP_GMA_LOG("mac character numbers overflow !!! \n");
return false;
}
*mac <<= 4;
*mac++ += gma_ali_para_char2num(*para_string);
highbit_en ^= 1;
}
para_string++;
}
//check mac character numbers legal scope
if (char_nums != GMA_ALI_PARA_MAC_CHAR_NUMS) {
APP_GMA_LOG("mac character numbers error !!! \n");
return false;
}
///mac reverse
for (int i = 0, tmp_mac = 0, array_size = (sizeof(ali_para->mac) / sizeof(ali_para->mac[0])); \
i < (sizeof(ali_para->mac) / sizeof(ali_para->mac[0]) / 2); i++) {
tmp_mac = ali_para->mac[i];
ali_para->mac[i] = ali_para->mac[array_size - 1 - i];
ali_para->mac[array_size - 1 - i] = tmp_mac;
}
///print secret
APP_GMA_LOG(">>ali_para mac: ");
for (int i = 0; i < sizeof(ali_para->mac) / sizeof(ali_para->mac[0]); i++) {
APP_GMA_LOG("%x ", ali_para->mac[i]);
}
return true;
}
static int gma_license2flash(const ali_para_s *ali_para)
{
int i;
u8 mac[6];
u8 rdata[sizeof(ali_para_s)];
for (i = 0; i < sizeof(mac); i++) {
mac[i] = ali_para->mac[5 - i];
}
memcpy(rdata, &ali_para->pid, sizeof(ali_para->pid));
memcpy(rdata + sizeof(ali_para->pid), ali_para->secret, sizeof(ali_para->secret));
memcpy(rdata + sizeof(ali_para->pid) + sizeof(ali_para->secret), mac, sizeof(mac));
return app_protocol_license2flash(rdata, sizeof(rdata));
}
#endif
#if TCFG_USER_TWS_ENABLE
#include "bt_tws.h"
static ali_para_s ali_para_remote; //对耳的三元组
//VM_GMA_MAC 对耳的地址
//VM_GMA_ALI_PARA 对耳的三元组
static int gma_strcmp(const u8 *ptr1, const u8 *ptr2, u8 len)
{
while (len--) {
if (*ptr1 != *ptr2) {
return (*ptr1 - *ptr2);
}
ptr1++;
ptr2++;
}
return 0;
}
///mac reverse
u8 *gma_sibling_mac_get() //获取地址较小的那个
{
ali_para_s *sibling_ali_para = NULL;//&ali_para;
if (active_ali_para == &ali_para) {
printf("ali_para active \n");
sibling_ali_para = &ali_para_remote;
}
if (active_ali_para == &ali_para_remote) {
printf("ali_para active \n");
sibling_ali_para = &ali_para;
}
return (sibling_ali_para ? sibling_ali_para->mac : NULL);
}
int gma_select_ali_para_by_common_mac()
{
u8 ret = 0;
u8 mac[6];
u8 mac_buf_tmp[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
ret = syscfg_read(CFG_TWS_COMMON_ADDR, mac, 6);
if (ret != 6 || !memcmp(mac, mac_buf_tmp, 6)) {
printf("tws no conn\n");
return -1;
}
APP_GMA_LOG("active mac:");
APP_GMA_DUMP(mac, 6);
///select para
ali_para_s ali_para_temp;
syscfg_read(VM_GMA_ALI_PARA, (u8 *) &ali_para_temp, sizeof(ali_para_s));
if (ali_para_temp.pid == ali_para.pid) {
memcpy(&ali_para_remote, &ali_para_temp, sizeof(ali_para_s));
APP_GMA_LOG("remote mac:");
APP_GMA_DUMP(ali_para_remote.mac, 6);
APP_GMA_LOG("remote pid:%d \n", ali_para_remote.pid);
APP_GMA_LOG("remote secret:");
APP_GMA_DUMP(ali_para_remote.secret, sizeof(ali_para_remote.secret));
if (gma_strcmp(mac, ali_para_remote.mac, 6) == 0) {
APP_GMA_LOG("used remote para \n");
active_ali_para = &ali_para_remote;
return 0;
} else if (gma_strcmp(mac, ali_para.mac, 6) == 0) {
APP_GMA_LOG("used local para \n");
active_ali_para = &ali_para;
return 0;
} else {
APP_GMA_LOG("MAC ERROR !!!!!!!!!!!!!!!!\n");
return -1;
}
} else {
APP_GMA_LOG("no remote mac \n");
}
return -1;
}
void gma_slave_sync_remote_addr(u8 *buf)
{
u8 common_addr[6];
///remote ali_para fill
memcpy(&ali_para_remote, buf, sizeof(ali_para_remote));
syscfg_write(VM_GMA_MAC, ali_para_remote.mac, 6);
///write ali para to vm
syscfg_write(VM_GMA_ALI_PARA, (u8 *)&ali_para_remote, sizeof(ali_para_remote));
tws_api_get_local_addr(common_addr);
if (memcmp(active_ali_para->mac, common_addr, 6)) { //common地址发生变化
APP_GMA_LOG("gma addr change");
///used slave address
active_ali_para = &ali_para_remote;
app_protocol_set_tws_sibling_mac(ali_para.mac);
app_protocol_set_info_group(GMA_HANDLER_ID, active_ali_para); //设置三元组
//断开APP接口
if (is_tws_master_role()) {
APP_GMA_LOG("gma need reconn app");
app_protocol_disconnect(NULL);
app_protocol_ble_adv_switch(0);
le_controller_set_mac(active_ali_para->mac);
app_protocol_ble_adv_switch(1);
}
}
}
#ifdef CONFIG_NEW_BREDR_ENABLE
void tws_host_get_common_addr(u8 *remote_addr, u8 *common_addr, char channel)
#else
void tws_host_get_common_addr(u8 *local_addr, u8 *remote_addr, u8 *common_addr, char channel)
#endif
{
APP_GMA_LOG(">>>>>>>>>tws_host_get_common_addr ch:%c \n", channel);
u8 mac_buf[6];
gma_mac_addr_reverse_get(mac_buf);
APP_GMA_LOG(">>>local mac: ");
APP_GMA_DUMP(mac_buf, 6);
///used the bigger one as host bt mac
if (gma_strcmp(mac_buf, (const u8 *)remote_addr, 6) < 0) {
///used slave mac addr;remote_addr from slave addr reverse
memcpy(common_addr, remote_addr, 6);
} else {
///used master mac addr
gma_mac_addr_reverse_get(common_addr);
}
APP_GMA_LOG("common_addr: ");
APP_GMA_DUMP((const u8 *)common_addr, 6);
APP_GMA_LOG("remote_addr: ");
APP_GMA_DUMP((const u8 *)remote_addr, 6);
}
void gma_kick_license_to_sibling(void)
{
APP_GMA_LOG("send license info to sibling\n");
app_protocol_tws_send_to_sibling(GMA_TWS_CMD_SYNC_LIC, (u8 *) & (ali_para), sizeof(ali_para));;
}
void gma_tws_remove_paired(void)
{
ali_para_s ali_para_temp;
memset(&ali_para_temp, 0xff, sizeof(ali_para_s));
syscfg_write(VM_GMA_ALI_PARA, (u8 *)&ali_para_temp, sizeof(ali_para_s));
active_ali_para = &ali_para;
app_protocol_set_tws_sibling_mac(ali_para_temp.mac);
app_protocol_set_info_group(GMA_HANDLER_ID, active_ali_para); //设置三元组
app_protocol_disconnect(NULL);
app_protocol_ble_adv_switch(0);
le_controller_set_mac(active_ali_para->mac);
app_protocol_ble_adv_switch(1);
}
#endif
__attribute__((weak))
void bt_update_testbox_addr(u8 *addr)
{
}
int gma_prev_init(void)
{
int err = 0;
/* ali_para_s ali_para; */
#if GMA_GMA_SOURCH == GMA_GMA_FROM_FLASH
err = gma_license_set(&ali_para);
#elif GMA_GMA_SOURCH == GMA_GMA_FROM_FILE
u8 *ali_str = ali_para_string[ALI_PARA_ACTIVE_NUM];
u8 ali_license[128] = {0};
//check if exist flash file
if (read_cfg_file(ali_license, sizeof(ali_license), SDFILE_RES_ROOT_PATH"license.txt") == TRUE) {
ali_str = ali_license;
}
APP_GMA_LOG("ali_str:%s\n", ali_str);
if (gma_ali_para_info_fill((const u8 *)ali_str, &ali_para) == false) {
APP_GMA_LOG("array context not good \n");
///read license from flash
err = gma_license_set(&ali_para);
}
///write license to flash
if (!err) {
gma_license2flash(&ali_para);
}
#endif
if (!err) {
active_ali_para = &ali_para;
#if TCFG_USER_TWS_ENABLE
if (!gma_select_ali_para_by_common_mac()) {
app_protocol_set_tws_sibling_mac(gma_sibling_mac_get());
}
#endif
app_protocol_set_info_group(GMA_HANDLER_ID, active_ali_para); //设置三元组
bt_update_mac_addr(active_ali_para->mac);
lmp_hci_write_local_address(active_ali_para->mac);
app_protocol_ble_adv_switch(0);
le_controller_set_mac(active_ali_para->mac); //修改BLE地址
bt_update_testbox_addr(ali_para.mac);
}
return err;
}
//*********************************************************************************//
// GMA 提示音 //
//*********************************************************************************//
const char *gma_tone_tab[APP_RROTOCOL_TONE_MAX] = {
[APP_RROTOCOL_TONE_SPEECH_KEY_START] = TONE_NORMAL,
};
//*********************************************************************************//
// DMA私有消息处理 //
//*********************************************************************************//
#if TCFG_USER_TWS_ENABLE
void gma_rx_tws_data_deal(u16 opcode, u8 *data, u16 len)
{
switch (opcode) {
case GMA_TWS_CMD_SYNC_LIC:
printf(">>> TWS_AI_GMA_START_SYNC_LIC \n");
gma_slave_sync_remote_addr(data);
break;
}
}
static void gma_bt_tws_event_handler(struct bt_event *bt)
{
int role = bt->args[0];
int phone_link_connection = bt->args[1];
int reason = bt->args[2];
switch (bt->event) {
case TWS_EVENT_CONNECTED:
gma_kick_license_to_sibling();
break;
case TWS_EVENT_REMOVE_PAIRS:
gma_tws_remove_paired();
break;
}
}
#endif
static int gma_bt_status_event_handler(struct bt_event *bt)
{
return 0;
}
int gma_sys_event_deal(struct sys_event *event)
{
switch (event->type) {
case SYS_BT_EVENT:
if ((u32)event->arg == SYS_BT_EVENT_TYPE_CON_STATUS) {
gma_bt_status_event_handler(&event->u.bt);
}
#if TCFG_USER_TWS_ENABLE
else if (((u32)event->arg == SYS_BT_EVENT_FROM_TWS)) {
gma_bt_tws_event_handler(&event->u.bt);
}
#endif
break;
}
return 0;
}
struct app_protocol_private_handle_t gma_private_handle = {
#if TCFG_USER_TWS_ENABLE
.tws_rx_from_siblling = gma_rx_tws_data_deal,
#endif
/* .tws_sync_func = ; */
.sys_event_handler = gma_sys_event_deal,
};
#endif

View File

@ -1,146 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "app_protocol_api.h"
#include "system/includes.h"
#include "audio_config.h"
#include "app_power_manage.h"
#include "user_cfg.h"
#include "bt_tws.h"
#include "custom_cfg.h"
#if APP_PROTOCOL_MMA_CODE
#if 1
#define APP_MMA_LOG printf
#define APP_MMA_DUMP put_buf
#else
#define APP_MMA_LOG(...)
#define APP_MMA_DUMP(...)
#endif
//*********************************************************************************//
// MMA初始化 //
//*********************************************************************************//
void mma_prev_init()
{
u16 pid = 0x210c;
u16 vid = 0x05d6;
u16 ver = 0x1100;
#if APP_PROTOCOL_READ_CFG_EN
vid = get_vid_pid_ver_from_cfg_file(GET_VID_FROM_EX_CFG);
pid = get_vid_pid_ver_from_cfg_file(GET_PID_FROM_EX_CFG);
ver = get_vid_pid_ver_from_cfg_file(GET_VER_FROM_EX_CFG);
#endif
APP_MMA_LOG("mma pid:%x, vid:%x, ver:%x\n", pid, vid, ver);
app_protocol_set_vendor_id(MMA_HANDLER_ID, vid);
app_protocol_set_product_id(MMA_HANDLER_ID, pid);
app_protocol_set_local_version(MMA_HANDLER_ID, ver);
}
//*********************************************************************************//
// MMA提示音 //
//*********************************************************************************//
const char *mma_notice_tab[APP_RROTOCOL_TONE_MAX] = {
[APP_RROTOCOL_TONE_SPEECH_KEY_START] = TONE_NORMAL,
};
//*********************************************************************************//
// MMA私有消息处理 //
//*********************************************************************************//
#if 1
extern int le_controller_get_mac(void *addr);
#ifdef CONFIG_NEW_BREDR_ENABLE
void tws_host_get_common_addr(u8 *remote_addr, u8 *common_addr, char channel)
#else
void tws_host_get_common_addr(u8 *local_addr, u8 *remote_addr, u8 *common_addr, char channel)
#endif
{
APP_MMA_LOG(">>>>>>>>>tws_host_get_common_addr ch:%c \n", channel);
if (channel == 'L') {
memcpy(common_addr, bt_get_mac_addr(), 6);
} else {
memcpy(common_addr, remote_addr, 6);
}
APP_MMA_LOG(">>>local mac: ");
APP_MMA_DUMP(bt_get_mac_addr(), 6);
APP_MMA_LOG("remote_addr: ");
APP_MMA_DUMP((const u8 *)remote_addr, 6);
APP_MMA_LOG("common_addr: ");
APP_MMA_DUMP((const u8 *)common_addr, 6);
}
static void mma_tws_get_data_analysis(u16 cmd, u8 *data, u16 len)
{
}
static void mma_update_ble_addr()
{
u8 ble_old_addr[6];
u8 ble_new_addr[6];
u8 comm_addr[6];
tws_api_get_local_addr(comm_addr);
le_controller_get_mac(ble_old_addr);
void ble_update_address_tws_paired(u8 * comm_addr);
ble_update_address_tws_paired(comm_addr);
le_controller_get_mac(ble_new_addr);
if (is_tws_master_role() && memcmp(ble_old_addr, ble_new_addr, 6)) {
app_protocol_disconnect(NULL);
app_protocol_ble_adv_switch(0);
app_protocol_ble_adv_switch(1);
}
}
static void mma_bt_tws_event_handler(struct bt_event *bt)
{
int role = bt->args[0];
int phone_link_connection = bt->args[1];
int reason = bt->args[2];
switch (bt->event) {
case TWS_EVENT_CONNECTED:
mma_update_ble_addr();
break;
case TWS_EVENT_REMOVE_PAIRS:
mma_update_ble_addr();
break;
}
}
static int mma_bt_status_event_handler(struct bt_event *bt)
{
return 0;
}
int mma_sys_event_deal(struct sys_event *event)
{
switch (event->type) {
case SYS_BT_EVENT:
if ((u32)event->arg == SYS_BT_EVENT_TYPE_CON_STATUS) {
mma_bt_status_event_handler(&event->u.bt);
}
#if TCFG_USER_TWS_ENABLE
else if (((u32)event->arg == SYS_BT_EVENT_FROM_TWS)) {
mma_bt_tws_event_handler(&event->u.bt);
}
#endif
break;
}
return 0;
}
struct app_protocol_private_handle_t mma_private_handle = {
/* .tws_rx_from_siblling = mma_tws_get_data_analysis, */
.sys_event_handler = mma_sys_event_deal,
};
#endif
#endif

View File

@ -1,527 +0,0 @@
#include "app_config.h"
#if AI_APP_PROTOCOL
#include "app_protocol_ota.h"
#include "app_protocol_api.h"
#include "fs.h"
#include "os/os_error.h"
#include "update_loader_download.h"
#include "dual_bank_updata_api.h"
#include "update.h"
#include "timer.h"
#include "debug.h"
#define LOG_TAG_CONST APP_OTA
#define LOG_TAG "[APP_OTA]"
int clk_set(const char *name, int clk);
update_op_tws_api_t *get_tws_update_api(void);
void tws_sync_update_crc_handler_register(void (*crc_init_hdl)(void), u32(*crc_calc_hdl)(u32 init_crc, u8 *data, u32 len));
#define APP_UPDATE_FAILED 0
#define APP_UPDATE_SUCC 1
#define APP_CHECK_CRC_SUCC 0
#define APP_CHECK_CRC_FAILED 1
typedef struct _app_protocol_ota_param_t {
u32 state;
u32 read_len;
u32 need_rx_len;
u8 *read_buf;
void (*resume_hdl)(void *priv);
int (*sleep_hdl)(void *priv);
app_protocol_ota_api ota_api;
u32 file_offset;
u8 seek_type;
u8 update_result;
u8 sync_update_first_packet;
u8 ota_cancle_flag;
u8 wait_app_reboot;
OS_SEM ota_sem;
} app_protocol_ota_param_t;
static app_protocol_ota_param_t app_protocol_ota_param;
static update_op_tws_api_t *app_protocol_update_tws_api = NULL;
#define __this (&app_protocol_ota_param)
enum {
BT_SEEK_SET = 0x01,
BT_SEEK_CUR = 0x02,
BT_SEEK_TYPE_UPDATE_LEN = 0x10,
};
typedef enum {
UPDATA_START = 0x00,
UPDATA_REV_DATA,
UPDATA_STOP,
} UPDATA_BIT_FLAG;
#define RETRY_TIMES 3
const app_protocol_ota_type_map ota_type_map[] = {
{.protocol_id = GMA_HANDLER_ID, .ota_type = PASSIVE_OTA},
{.protocol_id = MMA_HANDLER_ID, .ota_type = INITIATIVE_OTA},
{.protocol_id = DMA_HANDLER_ID, .ota_type = NO_SUPPORT_OTA},
{.protocol_id = TME_HANDLER_ID, .ota_type = INITIATIVE_OTA},
{.protocol_id = AMA_HANDLER_ID, .ota_type = NO_SUPPORT_OTA},
};
//根据protocol_id获取协议升级类型
u8 check_ota_type_by_protocol_id(int id)
{
u8 i = 0;
for (; i < sizeof(ota_type_map) / sizeof(app_protocol_ota_type_map); i++) {
if (id == ota_type_map[i].protocol_id) {
return ota_type_map[i].ota_type;
}
}
return NO_SUPPORT_OTA;
}
static void initiative_ota_resume_hdl_register(void (*resume_hdl)(void *priv), int (*sleep_hdl)(void *priv))
{
__this->resume_hdl = resume_hdl;
__this->sleep_hdl = sleep_hdl;
}
void app_protocol_ota_init(app_protocol_ota_api *api, u8 need_wait_app_reboot)
{
memcpy(&(__this->ota_api), api, sizeof(app_protocol_ota_api));
__this->wait_app_reboot = need_wait_app_reboot;
#if OTA_TWS_SAME_TIME_ENABLE
tws_sync_update_crc_handler_register(__this->ota_api.ota_crc_init_hdl, __this->ota_api.ota_crc_calc_hdl);
g_printf("crc_init_hdl:0x%x crc_calc_hdl:0x%x\n", __this->ota_api.ota_crc_init_hdl, __this->ota_api.ota_crc_calc_hdl);
#endif
}
void initiative_ota_init(void (*resume_hdl)(void *priv), int (*sleep_hdl)(void *priv))
{
os_sem_create(&(__this->ota_sem), 0);
initiative_ota_resume_hdl_register(resume_hdl, sleep_hdl);
}
u16 initiative_ota_f_open(void)
{
log_info(">>>initiative_ota_f_open\n");
__this->file_offset = 0;
__this->seek_type = BT_SEEK_SET;
return 1;
}
void initiative_ota_handle(u8 state, void *buf, int len)
{
/* log_info("R"); */
if (state != __this->state) {
log_info(">>>initiative state err\n");
return;
}
switch (state) {
case UPDATA_REV_DATA:
if (__this->read_buf) {
memcpy(__this->read_buf, buf, len);
__this->read_len = len;
__this->state = 0;
}
break;
case UPDATA_STOP:
__this->state = 0;
break;
}
if (__this->resume_hdl) {
__this->resume_hdl(NULL);
}
}
u16 initiative_ota_f_read(void *fp, u8 *buff, u16 len)
{
u8 retry_cnt = 0;
__this->need_rx_len = len;
__this->state = UPDATA_REV_DATA;
__this->read_len = 0;
__this->read_buf = buff;
__RETRY:
if (app_protocol_get_cur_handle_id() == 0) { //如果已经断开连接直接返回-1 */
return -1;
}
if (__this->ota_cancle_flag) {
return -1;
}
if (__this->ota_api.ota_request_data == NULL) {
return -1;
}
printf("initiative_ota_read\n");
__this->ota_api.ota_request_data(fp, __this->file_offset, len);
while (!((0 == __this->state) && (__this->read_len == len))) {
if (__this->sleep_hdl && app_protocol_get_cur_handle_id()) {
__this->sleep_hdl(NULL);
} else {
len = -1;
break;
}
if (!((0 == __this->state) && (__this->read_len == len))) {
if (retry_cnt++ > RETRY_TIMES) {
len = (u16) - 1;
break;
} else {
goto __RETRY;
}
}
}
if ((u16) - 1 != len) {
__this->file_offset += len;
}
return len;
}
int initiative_ota_f_seek(void *fp, u8 type, u32 offset)
{
if (type == SEEK_SET) {
__this->file_offset = offset;
__this->seek_type = BT_SEEK_SET;
} else if (type == SEEK_CUR) {
__this->file_offset += offset;
__this->seek_type = BT_SEEK_CUR;
}
return 0;//FR_OK;
}
static u16 initiative_ota_f_stop(u8 err)
{
//err = update_result_handle(err);
__this->state = UPDATA_STOP;
log_info(">>>initiative_ota_stop:%x err:0x%x\n", __this->state, err);
if (__this->ota_cancle_flag) {
return -1;
}
if (__this->ota_api.ota_request_data) {
__this->ota_api.ota_request_data(NULL, 0, 0);
}
while (!(0 == __this->state)) {
if (__this->sleep_hdl) { // && get_rcsp_connect_status()) {
if (__this->sleep_hdl(NULL) == OS_TIMEOUT) {
break;
}
} else {
break;
}
}
if (__this->ota_api.ota_report_result) {
__this->ota_api.ota_report_result(err);
}
return 1;
}
static int initiative_ota_notify_update_content_size(void *priv, u32 size)
{
int err;
u8 data[4];
/* WRITE_BIG_U32(data, size); */
/* user_change_ble_conn_param(0); */
log_info("send content_size:%x\n", size);
if (__this->ota_api.ota_notify_file_size) {
__this->ota_api.ota_notify_file_size(size);
}
/* err = JL_CMD_send(JL_OPCODE_NOTIFY_UPDATE_CONENT_SIZE, data, sizeof(data), JL_NEED_RESPOND); */
return err;
}
const update_op_api_t initiative_update_op = {
.ch_init = initiative_ota_init,
.f_open = initiative_ota_f_open,
.f_read = initiative_ota_f_read,
.f_seek = initiative_ota_f_seek,
.f_stop = initiative_ota_f_stop,
.notify_update_content_size = initiative_ota_notify_update_content_size,
};
void app_protocol_ota_update_success_reset(void *priv)
{
cpu_reset();
}
static void initiative_ota_state_cbk(int type, u32 state, void *priv)
{
update_ret_code_t *ret_code = (update_ret_code_t *)priv;
if (ret_code) {
log_info("state:%x err:%x\n", ret_code->stu, ret_code->err_code);
}
switch (state) {
case UPDATE_CH_EXIT:
if (UPDATE_DUAL_BANK_IS_SUPPORT()) {
if ((0 == ret_code->stu) && (0 == ret_code->err_code)) {
/* set_jl_update_flag(1); */
log_info(">>>initiative update succ\n");
update_result_set(UPDATA_SUCC);
__this->update_result = APP_UPDATE_SUCC;
#if !OTA_TWS_SAME_TIME_ENABLE
sys_timeout_add(NULL, app_protocol_ota_update_success_reset, 2000); //延时一段时间再reset保证命令已经发送
#endif
} else {
log_info(">>>initiative update failed\n");
update_result_set(UPDATA_DEV_ERR);
__this->update_result = APP_UPDATE_FAILED;
}
} else {
if ((0 == ret_code->stu) && (0 == ret_code->err_code)) {
__this->update_result = APP_UPDATE_SUCC;
/* set_jl_update_flag(1); */
}
}
os_sem_post(&(__this->ota_sem));
break;
}
}
//被动升级请求下一帧数据
int passive_ota_write_callback(void *priv)
{
if (__this->ota_api.ota_request_data) {
__this->ota_api.ota_request_data(NULL, 0, 0);
}
return 0;
}
int passive_ota_set_boot_info_callback(int ret)
{
if (__this->ota_api.ota_report_result) {
__this->ota_api.ota_report_result(ret);
}
if (ret == 0) { //0表示boot info写成功
#if OTA_TWS_SAME_TIME_ENABLE
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_result_hdl && !__this->wait_app_reboot) {
app_protocol_update_tws_api->tws_ota_result_hdl(0);
}
#else
sys_timeout_add(NULL, app_protocol_ota_update_success_reset, 2000); //延时一段时间再reset保证命令已经发送
#endif
__this->update_result = APP_UPDATE_SUCC;
} else {
dual_bank_passive_update_exit(NULL);
#if OTA_TWS_SAME_TIME_ENABLE
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_err) {
app_protocol_update_tws_api->tws_ota_err(0);
}
__this->update_result = APP_UPDATE_FAILED;
#endif
}
return 0;
}
int passive_ota_crc_result_call_back(int crc_res)
{
if (crc_res) { //校验成功
log_info("crc check succ, write boot_info\n");
u8 update_boot_info_flag, verify_err;
#if OTA_TWS_SAME_TIME_ENABLE
if (app_protocol_update_tws_api && app_protocol_update_tws_api->exit_verify_hdl) {
if (app_protocol_update_tws_api->exit_verify_hdl(&verify_err, &update_boot_info_flag)) {
dual_bank_update_burn_boot_info((int (*)(int))passive_ota_set_boot_info_callback);
} else { //从机写boot_info失败
if (__this->ota_api.ota_report_result) {
__this->ota_api.ota_report_result(APP_CHECK_CRC_FAILED);
}
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_err) { //通知从机升级失败
app_protocol_update_tws_api->tws_ota_err(0);
}
__this->update_result = APP_UPDATE_FAILED;
}
} else
#endif
{
dual_bank_update_burn_boot_info((int (*)(int))passive_ota_set_boot_info_callback);
}
} else { //校验失败
if (__this->ota_api.ota_report_result) {
__this->ota_api.ota_report_result(APP_CHECK_CRC_FAILED);
}
#if OTA_TWS_SAME_TIME_ENABLE
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_err) { //通知从机升级失败
app_protocol_update_tws_api->tws_ota_err(0);
}
#endif
__this->update_result = APP_UPDATE_FAILED;
//app_protocol_reply_frame_check_result(crc_res);
dual_bank_passive_update_exit(NULL);
}
return 0;
}
int app_protocol_ota_interrupt_by_disconnect(int id)
{
if (check_ota_type_by_protocol_id(id) == INITIATIVE_OTA) {
} else {
#if OTA_TWS_SAME_TIME_ENABLE
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_err) {
app_protocol_update_tws_api->tws_ota_err(0);
}
#endif
dual_bank_passive_update_exit(NULL);
}
return 0;
}
int app_protocol_update_success_flag(void)
{
return __this->update_result;
}
int app_protocol_ota_message_handler(int id, int opcode, u8 *data, u32 len)
{
int err_code = UPDATE_RESULT_ERR_NONE;
int ret = 0;
switch (opcode) {
case APP_PROTOCOL_OTA_CHECK:
log_info("APP_PROTOCOL_OTA_CHECK\n");
ota_frame_info *frame_info = data;
dual_bank_passive_update_init(frame_info->frame_crc, frame_info->frame_size, frame_info->max_pkt_len, NULL);
ret = dual_bank_update_allow_check(frame_info->frame_size);
if (ret) {
err_code = UPDATE_RESULT_RESOURCE_LIMIT;
dual_bank_passive_update_exit(NULL);
} else { //for tws sync update init
#if OTA_TWS_SAME_TIME_ENABLE
app_protocol_update_tws_api = get_tws_update_api();
struct __tws_ota_para tws_update_para;
tws_update_para.fm_size = frame_info->frame_size;
tws_update_para.fm_crc16 = frame_info->frame_crc;
tws_update_para.max_pkt_len = frame_info->max_pkt_len;
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_start) {
if (app_protocol_update_tws_api->tws_ota_start(&tws_update_para)) {
err_code = UPDATE_RESULT_OTA_TWS_START_ERR;
dual_bank_passive_update_exit(NULL);
}
}
__this->sync_update_first_packet = 1;
#endif
}
break;
case APP_PROTOCOL_OTA_BEGIN:
update_mode_info_t info = {
.type = BLE_APP_UPDATA,
.state_cbk = initiative_ota_state_cbk,
.p_op_api = &initiative_update_op,
.task_en = 1,
};
__this->ota_cancle_flag = 0;
app_active_update_task_init(&info);
break;
case APP_PROTOCOL_OTA_TRANS_DATA:
log_info("APP_PROTOCOL_OTA_TRANS_DATA\n");
if (check_ota_type_by_protocol_id(id) == INITIATIVE_OTA) {
initiative_ota_handle(UPDATA_REV_DATA, data, len);
} else {
#if OTA_TWS_SAME_TIME_ENABLE
if (!__this->sync_update_first_packet) { //第一次传输不需要pend
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_data_send_pend) {
if (app_protocol_update_tws_api->tws_ota_data_send_pend()) {
log_info(" UPDATE_ERR_WAIT_TWS_RESPONSE_TIMEOUT\n");
err_code = UPDATE_RESULT_OTA_TWS_NO_RSP;
break;
}
}
}
__this->sync_update_first_packet = 0;
#endif
dual_bank_update_write(data, len, passive_ota_write_callback);
#if OTA_TWS_SAME_TIME_ENABLE
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_data_send) {
app_protocol_update_tws_api->tws_ota_data_send(data, len);
}
#endif
}
break;
case APP_PROTOCOL_OTA_GET_APP_VERSION:
u32 fm_version = app_protocol_get_version_by_id(id);
break;
case APP_PROTOCOL_OTA_CHECK_CRC:
if (check_ota_type_by_protocol_id(id) == INITIATIVE_OTA) {
os_sem_pend(&(__this->ota_sem), 0);
err_code = __this->update_result;
} else {
clk_set("sys", 120 * 1000000L); //提升主频加快CRC校验速度
#if OTA_TWS_SAME_TIME_ENABLE
if (app_protocol_update_tws_api && app_protocol_update_tws_api->tws_ota_data_send_pend) { //pend 最后一包数据
if (app_protocol_update_tws_api->tws_ota_data_send_pend()) {
log_info(" UPDATE_ERR_WAIT_TWS_RESPONSE_TIMEOUT\n");
err_code = UPDATE_RESULT_OTA_TWS_NO_RSP;
break;
}
}
if (app_protocol_update_tws_api && app_protocol_update_tws_api->enter_verfiy_hdl) {
if (app_protocol_update_tws_api->enter_verfiy_hdl(NULL)) { //从机校验CRC
log_info("update enter verify err\n");
if (__this->ota_api.ota_report_result) {
__this->ota_api.ota_report_result(APP_CHECK_CRC_FAILED);
}
} else {
log_info("update enter verify succ\n");
dual_bank_update_verify(__this->ota_api.ota_crc_init_hdl, __this->ota_api.ota_crc_calc_hdl, passive_ota_crc_result_call_back);
}
} else
#endif
{
dual_bank_update_verify(__this->ota_api.ota_crc_init_hdl, __this->ota_api.ota_crc_calc_hdl, passive_ota_crc_result_call_back);
}
}
break;
case APP_PROTOCOL_OTA_CANCLE:
__this->ota_cancle_flag = 1;
break;
case APP_PROTOCOL_OTA_REBOOT:
__this->state = 0;
/* #if OTA_TWS_SAME_TIME_ENABLE //同步升级在update lib里进行重启 */
/* g_printf("APP_PROTOCOL_OTA_REBOOT!!!\n"); */
/* #else */
/* cpu_reset(); */
/* #endif */
break;
case APP_PROTOCOL_OTA_PERCENT:
break;
case APP_PROTOCOL_OTA_END:
break;
case APP_PROTOCOL_OTA_SUCCESS:
break;
case APP_PROTOCOL_OTA_FAIL:
break;
}
return err_code;
}
#endif

View File

@ -1,28 +0,0 @@
#ifndef __APP_PROTOCOL_OTA_H__
#define __APP_PROTOCOL_OTA_H__
#include "typedef.h"
#define NO_SUPPORT_OTA 0xff
#define INITIATIVE_OTA 0x01
#define PASSIVE_OTA 0x02
typedef struct app_protocol_ota_type_map_t {
u32 protocol_id;
u8 ota_type;
} app_protocol_ota_type_map;
typedef struct app_protocol_ota_api_t {
u32(*ota_request_data)(void *priv, u32 offset, u16 len);
u32(*ota_report_result)(u8 result);
void (*ota_notify_file_size)(u32 file_size);
void (*ota_crc_init_hdl)(void);
u16(*ota_crc_calc_hdl)(u16 init_crc, u8 *data, u32 len);
} app_protocol_ota_api;
int app_protocol_ota_message_handler(int id, int opcode, u8 *data, u32 len);
void app_protocol_ota_init(app_protocol_ota_api *api, u8 need_wait_app_reboot);
int app_protocol_ota_interrupt_by_disconnect(int id);
int app_protocol_update_success_flag(void);
#endif //__APP_PROTOCOL_OTA_H__

View File

@ -1,126 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "app_protocol_api.h"
#include "system/includes.h"
#include "audio_config.h"
#include "app_power_manage.h"
#include "user_cfg.h"
#include "btstack/avctp_user.h"
#include "bt_tws.h"
#if APP_PROTOCOL_TME_CODE
extern void TME_set_edr_connected(u8 flag);
//*********************************************************************************//
// TME认证信息 //
//*********************************************************************************//
//*********************************************************************************//
// TME提示音 //
//*********************************************************************************//
const char *tme_notice_tab[APP_RROTOCOL_TONE_MAX] = {
[APP_RROTOCOL_TONE_SPEECH_KEY_START] = TONE_NORMAL,
};
//*********************************************************************************//
// TME弱函数实现 //
//*********************************************************************************//
//*********************************************************************************//
// TME私有消息处理 //
//*********************************************************************************//
#if 1
extern int le_controller_set_mac(void *addr);
extern int le_controller_get_mac(void *addr);
#if TCFG_USER_TWS_ENABLE
static void tme_tws_rx_from_sibling(u16 cmd, u8 *data, u16 len)
{
#if TCFG_USER_TWS_ENABLE
switch (cmd) {
}
#endif
}
static void tme_update_ble_addr()
{
u8 ble_old_addr[6];
u8 ble_new_addr[6];
u8 comm_addr[6];
printf("%s\n", __func__);
tws_api_get_local_addr(comm_addr);
le_controller_get_mac(ble_old_addr);
lib_make_ble_address(ble_new_addr, comm_addr);
le_controller_set_mac(ble_new_addr); //地址发生变化,更新地址
if (is_tws_master_role() && memcmp(ble_old_addr, ble_new_addr, 6)) {
app_protocol_disconnect(NULL);
app_protocol_ble_adv_switch(0);
app_protocol_ble_adv_switch(1);
}
}
static void tme_bt_tws_event_handler(struct bt_event *bt)
{
int role = bt->args[0];
int phone_link_connection = bt->args[1];
int reason = bt->args[2];
switch (bt->event) {
case TWS_EVENT_CONNECTED:
tme_update_ble_addr();
if (BT_STATUS_WAITINT_CONN != get_bt_connect_status()) {
TME_set_edr_connected(1);
}
break;
case TWS_EVENT_REMOVE_PAIRS:
tme_update_ble_addr();
break;
}
}
#endif
static int tme_bt_status_event_handler(struct bt_event *bt)
{
switch (bt->event) {
case BT_STATUS_SECOND_CONNECTED:
case BT_STATUS_FIRST_CONNECTED:
TME_set_edr_connected(1); //连接过经典蓝牙标志
break;
}
return 0;
}
int tme_sys_event_deal(struct sys_event *event)
{
switch (event->type) {
case SYS_BT_EVENT:
if ((u32)event->arg == SYS_BT_EVENT_TYPE_CON_STATUS) {
tme_bt_status_event_handler(&event->u.bt);
}
#if TCFG_USER_TWS_ENABLE
else if (((u32)event->arg == SYS_BT_EVENT_FROM_TWS)) {
tme_bt_tws_event_handler(&event->u.bt);
}
#endif
break;
}
return 0;
}
struct app_protocol_private_handle_t tme_private_handle = {
/* .tws_rx_from_siblling = tme_tws_rx_from_sibling, */
.sys_event_handler = tme_sys_event_deal,
};
#endif
#endif