在逗猫棒的基础上实现蓝牙转USB功能,目前功能已经实现,还需裁剪掉之前逗猫棒的业务程序
This commit is contained in:
@@ -0,0 +1,248 @@
|
||||
#include "system/includes.h"
|
||||
#include "app_config.h"
|
||||
#include "asm/pwm_led.h"
|
||||
#include "tone_player.h"
|
||||
#include "ui_manage.h"
|
||||
#include "app_main.h"
|
||||
#include "app_task.h"
|
||||
#include "asm/charge.h"
|
||||
#include "app_power_manage.h"
|
||||
#include "app_charge.h"
|
||||
#include "user_cfg.h"
|
||||
|
||||
#include "audio.h"
|
||||
#include "vm.h"
|
||||
#include "bleproto.h"
|
||||
#include "bleproto_api.h"
|
||||
|
||||
#include "bleproto.h"
|
||||
#define LOG_TAG_CONST APP
|
||||
#define LOG_TAG "[APP]"
|
||||
#define LOG_ERROR_ENABLE
|
||||
#define LOG_DEBUG_ENABLE
|
||||
#define LOG_INFO_ENABLE
|
||||
/* #define LOG_DUMP_ENABLE */
|
||||
#define LOG_CLI_ENABLE
|
||||
#include "debug.h"
|
||||
|
||||
extern u8 muti_adv_data[31];//={0};
|
||||
extern u8 muti_adv_data_len;
|
||||
|
||||
extern u8 usr_get_full();
|
||||
extern u16 usr_get_conn_service();
|
||||
extern int muti_make_set_adv_data(u8* data,u8 data_len);
|
||||
extern void usr_clear_plan();
|
||||
extern void usr_reset_device_sta();
|
||||
extern u8 usr_get_ldoin_all();
|
||||
|
||||
void usr_ble_adv_updata();
|
||||
|
||||
static int le_timer_handle=0;
|
||||
static int le_timer_handle2=0;
|
||||
|
||||
|
||||
extern void usr_led_w_out(u8 flag);
|
||||
extern void usr_led_b_out(u8 flag);
|
||||
extern u8 get_ldo5v_online_hw(void);
|
||||
extern u8 usr_get_work_status();
|
||||
extern void usr_printf_sta();
|
||||
extern int muti_make_set_adv_data_updata();
|
||||
|
||||
void usr_get_pair_info()
|
||||
{
|
||||
int ret = 0xffff;
|
||||
ret = syscfg_read(CFG_USER_PAIR_INFO, (u8 *)&usr_auth_data, sizeof(usr_auth_data));
|
||||
if(ret<=0)
|
||||
{
|
||||
memset(&usr_auth_data,0x00,sizeof(usr_auth_data));
|
||||
usr_auth_data.paired_flag=0;
|
||||
syscfg_write(CFG_USER_PAIR_INFO, (u8 *)&usr_auth_data, sizeof(usr_auth_data));
|
||||
}
|
||||
}
|
||||
void usr_write_pair_info()
|
||||
{
|
||||
usr_auth_data.paired_flag=1;
|
||||
syscfg_write(CFG_USER_PAIR_INFO, (u8 *)&usr_auth_data, sizeof(usr_auth_data));
|
||||
}
|
||||
|
||||
void usr_clear_pair_info()
|
||||
{
|
||||
printf("usr_clear_pair_info\n");
|
||||
memset(&usr_auth_data,0x00,sizeof(usr_auth_data));
|
||||
usr_auth_data.paired_flag=0;
|
||||
syscfg_write(CFG_USER_PAIR_INFO, (u8 *)&usr_auth_data, sizeof(usr_auth_data));
|
||||
usr_clear_plan();
|
||||
if(_usr_module_cfg.power_on_flag)sys_timeout_add(NULL,cpu_reset,600);
|
||||
else sys_enter_soft_poweroff(NULL);
|
||||
}
|
||||
void usr_clear_pair_info_noreset()
|
||||
{
|
||||
printf("usr_clear_pair_info2\n");
|
||||
memset(&usr_auth_data,0x00,sizeof(usr_auth_data));
|
||||
usr_auth_data.paired_flag=0;
|
||||
syscfg_write(CFG_USER_PAIR_INFO, (u8 *)&usr_auth_data, sizeof(usr_auth_data));
|
||||
usr_clear_plan();
|
||||
usr_reset_device_sta();
|
||||
//sys_timeout_add(NULL,cpu_reset,600);
|
||||
}
|
||||
extern void usr_set_adv_interval(u16 val);
|
||||
extern u16 usr_get_adv_interval();
|
||||
extern void ble_multi_trans_disconnect(void);
|
||||
void usr_ble_adv_init();
|
||||
void usr_goto_pair_mode()
|
||||
{
|
||||
ble_multi_trans_disconnect();
|
||||
usr_clear_pair_info_noreset();
|
||||
usr_var.usr_goto_pair=1;
|
||||
_usr_module_cfg.local_moto_mode=3;
|
||||
os_time_dly(5);
|
||||
usr_ble_adv_init();
|
||||
}
|
||||
|
||||
|
||||
void usr_ble_adv_init()
|
||||
{
|
||||
int8_t txpower = 0;
|
||||
uint8_t manucode[BLEPROTO_ADV_TLV_LENGTH_MANUCODE] = { 0 };
|
||||
uint8_t prodcode[BLEPROTO_ADV_TLV_LENGTH_PRODCODE] = {'C', 'B', 'C', '0'};
|
||||
uint8_t gmac[6]={0};
|
||||
uint8_t pcode[6]={'P','I','C','B','C','0'};
|
||||
usr_set_adv_interval(80);
|
||||
if(usr_var.usr_ota_succ_flag)return;
|
||||
//muti_adv_data
|
||||
if(usr_var.usr_goto_pair)
|
||||
{
|
||||
usr_clear_pair_info_noreset();
|
||||
printf("power on force to par flag= %d\n",usr_auth_data.paired_flag);
|
||||
//if(usr_auth_data.paired_flag==0)
|
||||
{
|
||||
muti_adv_data_len=bleproto_advdata_encode4bind(muti_adv_data,txpower,manucode,pcode,prodcode);
|
||||
}
|
||||
usr_var.usr_adv_flag=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
usr_get_pair_info();
|
||||
if(usr_auth_data.paired_flag==0)
|
||||
{
|
||||
muti_adv_data_len=bleproto_advdata_encode4bind(muti_adv_data,txpower,manucode,pcode,prodcode);
|
||||
usr_var.usr_adv_flag=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(gmac,usr_auth_data.gwmac,6);
|
||||
muti_adv_data_len=bleproto_advdata_encode4reconn(muti_adv_data,txpower,gmac,manucode,pcode,prodcode);
|
||||
usr_var.usr_adv_flag=1;
|
||||
}
|
||||
}
|
||||
|
||||
usr_ble_adv_updata();
|
||||
if(le_timer_handle==0)le_timer_handle = sys_timer_add(NULL, usr_ble_adv_updata, 500);
|
||||
//user_send_cmd_prepare(USER_CTRL_ALL_SNIFF_EXIT, 0, NULL);
|
||||
}
|
||||
|
||||
u8 usr_get_pair_flag()
|
||||
{
|
||||
return usr_auth_data.paired_flag;
|
||||
}
|
||||
/*
|
||||
void usr_reconn_adv()
|
||||
{
|
||||
int8_t txpower = 0;
|
||||
uint8_t gmac[6]={0};
|
||||
uint8_t manucode[BLEPROTO_ADV_TLV_LENGTH_MANUCODE] = { 0 };
|
||||
uint8_t prodcode[BLEPROTO_ADV_TLV_LENGTH_PRODCODE] = {'C', 'B', 'F', 'D'};
|
||||
uint8_t pcode[6]={'P','C','B','F','D','0'};
|
||||
memcpy(gmac,usr_auth_data.gwmac,6);
|
||||
muti_adv_data_len=bleproto_advdata_encode4reconn(muti_adv_data,txpower,gmac,manucode,pcode,prodcode);
|
||||
usr_adv_flag=1;
|
||||
}*/
|
||||
extern u16 get_vbat_level(void);
|
||||
|
||||
extern void ble_trans_module_enable(u8 flag);
|
||||
extern u8 usr_get_ota_status();
|
||||
void usr_ble_adv_updata()
|
||||
{
|
||||
//printf("usr_ble_adv_updata\n");
|
||||
static u16 usr_goto_slow_adv=0;
|
||||
if(usr_var.usr_adv_flag)
|
||||
{
|
||||
ble_trans_module_enable(0);
|
||||
usr_var.usr_adv_flag=0;
|
||||
muti_make_set_adv_data(muti_adv_data,muti_adv_data_len);
|
||||
printf("###muti_adv_data = ");
|
||||
printf_buf(muti_adv_data,muti_adv_data_len);
|
||||
ble_trans_module_enable(1);
|
||||
}
|
||||
|
||||
if(usr_get_conn_service()==0)
|
||||
{
|
||||
if(usr_get_adv_interval()==80)
|
||||
{
|
||||
if((usr_var.usr_goto_pair==0)&&(usr_auth_data.paired_flag))
|
||||
{
|
||||
if(usr_var.usr_ota_succ_flag==0)
|
||||
{
|
||||
usr_goto_slow_adv++;
|
||||
printf("usr_goto_slow_adv = %d\n",usr_goto_slow_adv);
|
||||
}
|
||||
if(usr_goto_slow_adv>=120)
|
||||
{
|
||||
usr_goto_slow_adv=0;
|
||||
usr_set_adv_interval(80*10);
|
||||
usr_var.usr_adv_flag=1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
usr_goto_slow_adv=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
usr_goto_slow_adv=0;
|
||||
}
|
||||
|
||||
|
||||
if(usr_get_ota_status()==0)
|
||||
{
|
||||
if(usr_get_conn_service()==0)
|
||||
{
|
||||
if(usr_var.usr_ota_succ_flag==0)usr_ota_exit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void usr_ble_adv_updata_OTA()
|
||||
{
|
||||
//printf("usr_ble_adv_updata\n");
|
||||
if(1)
|
||||
{
|
||||
ble_trans_module_enable(0);
|
||||
usr_var.usr_adv_flag=0;
|
||||
|
||||
#if 1
|
||||
extern u8 usr_mac_addr[6];
|
||||
//u8 ble_mac[6];
|
||||
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);
|
||||
usr_mac_addr[0]=usr_mac_addr[0]+1;
|
||||
le_controller_set_mac(usr_mac_addr); //修改BLE地址
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
muti_make_set_adv_data_updata();
|
||||
printf("###muti_adv_data = ");
|
||||
printf_buf(muti_adv_data,muti_adv_data_len);
|
||||
ble_trans_module_enable(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user