From 1de28009234fc6fc0604fb93b6b475141e08c270 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Wed, 30 Oct 2024 11:51:12 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8OTA=E7=9B=B8?= =?utf8?q?=E5=85=B3AT=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/auto_ota/auto_ota_service.c | 69 +++++++++++++++++++ .../wearable/auto_ota/auto_ota_service.h | 4 ++ .../peripheral/utils/custom_utils_at_cmd.c | 50 ++++++++++++++ 3 files changed, 123 insertions(+) diff --git a/code/sdk/application/wearable/auto_ota/auto_ota_service.c b/code/sdk/application/wearable/auto_ota/auto_ota_service.c index 460aabaa5..ffa79a818 100644 --- a/code/sdk/application/wearable/auto_ota/auto_ota_service.c +++ b/code/sdk/application/wearable/auto_ota/auto_ota_service.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "cmsis_os2.h" #include "systick.h" #include "soc_errno.h" @@ -230,6 +231,54 @@ static void auto_ota_add_node_to_found_dev_list(const bd_addr_t *bd_addr, const osal_list_add_tail((struct osal_list_head *)node, &g_auto_ota_found_dev_list_head); } +//直接写入需要升级的设备进列表 +void AT_auto_ota_add_node_to_found_dev_list(uint8_t *char_addr) +{ + if(strlen((char *)char_addr)<12) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "char_addr erro"); /* addr下标 0 1 2 3 */ + return; + } + bd_addr_t bd_addr={}; + int y=0; + for(int i=0;i<6;i+=1) + { + + char buf[3]={0}; + memcpy_s(buf,2,char_addr+y,2); + y+=2; + bd_addr.addr[i]= (uint8_t)strtol(buf,NULL,16); + } + + int cod = gap_get_device_class(&bd_addr); + uint8_t *name=(uint8_t *)"test watch"; + + + + auto_ota_found_dev_list_node *node = + (auto_ota_found_dev_list_node *)(void *)oal_mem_alloc(sizeof(auto_ota_found_dev_list_node)); + if (node == NULL) { + return; + } + (void)memset_s(node, sizeof(auto_ota_found_dev_list_node), 0, sizeof(auto_ota_found_dev_list_node)); + + if (memcpy_s(&node->bd_addr, sizeof(node->bd_addr), &bd_addr, sizeof(bd_addr_t)) != EOK) { + oal_mem_free(node); + return; + } + + if (memcpy_s(node->name, sizeof(node->name), name, BD_NAME_LEN) != EOK) { + oal_mem_free(node); + return; + } + + node->cod = cod; + node->rssi = 0xffff; + osal_list_add_tail((struct osal_list_head *)node, &g_auto_ota_found_dev_list_head); +} + + + static void auto_ota_sort_found_dev_list(void) { struct osal_list_head *list_head = &g_auto_ota_found_dev_list_head; @@ -349,6 +398,26 @@ static void auto_ota_discovery_result_callback(const bd_addr_t *bd_addr) WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "auto_ota_discovery_result_callback end\n"); return; } +//方便直接生成版本文件 +void write_ver_txt(uint8_t V_1,uint8_t V_2,uint8_t V_3) +{ + FILE *fp = NULL; + + fp = fopen(AUTO_OTA_DST_UPG_VER_PATH, "wb+"); + if (fp == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "open %s fail.\r\n", AUTO_OTA_DST_UPG_VER_PATH); + return ; + } + char buf[32]={0}; + + sprintf(buf,"%d.%d.%d",V_1,V_2,V_3); + + fwrite(buf,1,strlen(buf)+1,fp); + + fclose(fp); + + +} static bool auto_ota_upg_check(void) { diff --git a/code/sdk/application/wearable/auto_ota/auto_ota_service.h b/code/sdk/application/wearable/auto_ota/auto_ota_service.h index 322835e4b..94cb52ed5 100644 --- a/code/sdk/application/wearable/auto_ota/auto_ota_service.h +++ b/code/sdk/application/wearable/auto_ota/auto_ota_service.h @@ -21,6 +21,10 @@ bool auto_ota_dev_del(uint8_t *addr); void auto_ota_dev_show(void); void auto_ota_task_main(void); +void AT_auto_ota_add_node_to_found_dev_list(uint8_t *char_addr); + +void write_ver_txt(uint8_t V_1,uint8_t V_2,uint8_t V_3); + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 1e62501e4..c5b758e2a 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -1341,6 +1341,54 @@ static uint32_t leantest(uint8_t *para, uint32_t paraLen, char *strCommonCmd) #endif return ERRCODE_SUCC; } + +static uint32_t Add_addrss_atuoota(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + uint8_t send_data[8] = {0}; + + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + wstp_print("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + #ifdef SUPPORT_AUTO_OTA + AT_auto_ota_add_node_to_found_dev_list((uint8_t*)argv[0]); + #endif + return ERRCODE_SUCC; + +} + +static uint32_t Add_VER_txt_atuoota(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + UNUSED(strCommonCmd); + uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + uint8_t send_data[8] = {0}; + + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != CUSTOM_UTILS_SUCCESS) { + wstp_print("CUSTOM_UTILSTEST ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + #ifdef SUPPORT_AUTO_OTA + write_ver_txt( + (uint8_t)atoi((char*)argv[0]), + (uint8_t)atoi((char*)argv[1]), + (uint8_t)atoi((char*)argv[2])); + #endif + return ERRCODE_SUCC; + +} + + + + + static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^CUSTOM_SN", custom_utils_setsn, (char *)"123456789ABCDEF2345678" }, { (char *)"AT^CUSTOM_SN_REQ", custom_utils_getsn, (char *)" " }, @@ -1424,6 +1472,8 @@ static const at_cmd_table_t g_custom_utils_cmd[] = { { (char *)"AT^LEANTEST", leantest, (char *)" " }, { (char *)"AT^ENABLEDRAG", enabledrag, (char *)" " }, { (char *)"AT^SETDRAGLIMIT", setdraglimit, (char *)" " }, + { (char *)"AT^ADDADRESSAUTOOTA", Add_addrss_atuoota, (char *)" " }, + { (char *)"AT^ADDVRETXT", Add_VER_txt_atuoota, (char *)" " }, }; -- 2.17.1