From: SnickerSun Date: Wed, 6 Mar 2024 13:28:22 +0000 (+0800) Subject: 修复经典蓝牙开启时初始地址生成随机地址的方法。 X-Git-Tag: release_V1.2.70_20241020_135402~1274^2~19^2~7^2~2 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=028ce346a52e5679326778ef8b6ebf9e1eccba6e;p=mirrors%2FFD230.git 修复经典蓝牙开启时初始地址生成随机地址的方法。 修复版本号时间显示问题 --- diff --git a/code/sdk/drivers/peripheral/utils/CMakeLists.txt b/code/sdk/drivers/peripheral/utils/CMakeLists.txt index 33ba8c3f5..348ac28d3 100644 --- a/code/sdk/drivers/peripheral/utils/CMakeLists.txt +++ b/code/sdk/drivers/peripheral/utils/CMakeLists.txt @@ -17,6 +17,8 @@ set(PRIVATE_HEADER ) set(PRIVATE_DEFINES + TARGET_NAME="${TARGET_COMMAND}" + BUILD_TIME="${BUILD_TIME}" ) set(PUBLIC_DEFINES diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index b76323585..b6fdaef44 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -372,16 +372,19 @@ errcode_t uapi_get_btname(uint8_t *buf_btname, uint32_t *len_btname) { if(buf_btname == NULL || len_btname == NULL) { + printf("ERROR param NULL"); return ERRCODE_FAIL; } - memset(buf_btname,0,*len_btname); - - errcode_t res = bluetooth_get_local_name((unsigned char*)buf_btname, (unsigned char*)len_btname); + unsigned char namelen = 248; + unsigned char name[248] = {0}; + errcode_t res = bluetooth_get_local_name(name, &namelen); if (res == 0) { char str[256] = "^btname:"; - strcat_s(str, strlen(str) + strlen((char*)buf_btname), (char*)buf_btname); + strcat_s(str, strlen(str) + strlen((char*)name), (char*)name); printf("%s\r\n", &str[0]); - printf("name: %s, length: %d\n", buf_btname, *len_btname); + printf("name: %s, length: %d\n", name, namelen); + sprintf((char*)buf_btname,"%s",name); + *len_btname = strlen((const char*)name); return ERRCODE_SUCC; } else { printf("bluetooth_get_local_name ret = 0x%X\n",res); @@ -392,6 +395,7 @@ errcode_t uapi_get_btname(uint8_t *buf_btname, uint32_t *len_btname) errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr) { if (buf_btaddr == NULL || len_btaddr == NULL) { + printf("ERROR param NULL"); return ERRCODE_FAIL; } errcode_t res; @@ -451,32 +455,72 @@ errcode_t init_btaddr_btname(void) #define BT_MAC_LEN 6 unsigned int len = BT_MAC_LEN; unsigned char addr[BT_MAC_LEN] = {0}; + //获取蓝牙名 + unsigned char namelen = 248; + unsigned char name[248] = {0}; + srand(time(0)); res = bluetooth_get_local_addr(&addr[0], len); if (res == 0) { - char str[64] = "^PHYNUM:MACBT,"; - strcat_s(str, strlen(str) + strlen((char*)addr), (char*)addr); - printf("%s\r\n", &str[0]); + // char str[64] = "^PHYNUM:MACBT,"; + // strcat_s(str, strlen(str) + strlen((char*)addr), (char*)addr); + // printf("%s\r\n", &str[0]); printf("local_addr : ******%02x%02x%02x\n", addr[3], addr[4], addr[5]); } else { printf("bluetooth_get_local_addr err 0x%X\r\n",res); // return ERRCODE_FAIL; } - //默认是:281106856959 - addr[3] = rand() % 0xFF; - addr[4] = rand() % 0xFF; - addr[5] = rand() % 0xFF; - res = bluetooth_set_local_addr(addr, (uint8_t)6); - if (res == 0) { - printf("bluetooth_set_local_addr OK\r\n"); - } else { - printf("bluetooth_set_local_addr fail\r\n"); - // return ERRCODE_FAIL; + //如果 + if ( addr[0] == 0x59 && + addr[1] == 0x69 && + addr[2] == 0x85 && + addr[3] == 0x06 && + addr[4] == 0x11 && + addr[5] == 0x28 ) + { + //默认是:281106856959 + addr[3] = rand() % 0xFF; + addr[4] = rand() % 0xFF; + addr[5] = rand() % 0xFF; + + memset(name,0,sizeof(name)); + sprintf((char*)name,"%02X%02X%02X%02X%02X%02X",addr[0],addr[1],addr[2],addr[3],addr[4],addr[5]); + printf("creat new local_addr : ******%02x%02x%02x , %s\n", addr[3], addr[4], addr[5],name); + + unsigned char t ; + t=addr[0]; + addr[0]=addr[5]; + addr[5]=t; + t=addr[1]; + addr[1]=addr[4]; + addr[4]=t; + t=addr[2]; + addr[2]=addr[3]; + addr[3]=t; + res = bluetooth_set_local_addr(addr, sizeof(addr)); + if (res == 0) { + printf("bluetooth_set_local_addr OK\r\n"); + memset(name,0,sizeof(name)); + res = bluetooth_get_local_addr(&addr[0], len); + if (res == 0) { + // char str[64] = "^PHYNUM:MACBT,"; + // strcat_s(str, strlen(str) + strlen((char*)addr), (char*)addr); + // printf("%s\r\n", &str[0]); + printf("check local_addr : ******%02x%02x%02x\n", addr[3], addr[4], addr[5]); + } else { + printf("check bluetooth_get_local_addr err 0x%X\r\n",res); + // return ERRCODE_FAIL; + } + printf("bluetooth_set_local_addr check name %s \r\n",name); + + } else { + printf("bluetooth_set_local_addr fail\r\n"); + return ERRCODE_FAIL; + } } - unsigned char namelen = 248; - unsigned char name[248] = {0}; + memset(name,0,sizeof(name)); res = bluetooth_get_local_name(name, &namelen); if (res == 0) { char str[256] = "^btname:"; @@ -488,6 +532,7 @@ errcode_t init_btaddr_btname(void) printf("bluetooth_get_local_name ret = 0x%X\n",res); // return ERRCODE_FAIL; } + if(strcmp((const char*)name,"WatchSoar")==0) { memset(name,0,sizeof(name)); @@ -575,7 +620,7 @@ errcode_t uapi_get_buildversion(uint8_t *para, uint32_t para_len) char str[VER_STR_MAX]; #if !(defined BUILD_TIME) -// #warning no BUILD_TIME +#warning no BUILD_TIME (void)sprintf_s(str, VER_STR_MAX, "\r\nVersion:%s \r\n", get_version_string());