From: luozheng <1732036298@qq.com> Date: Thu, 5 Feb 2026 06:38:58 +0000 (+0800) Subject: 解决苹果ota升级失败问题 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=9818f6e7a4a9d43bc9b912593dc94f1b63ee3c70;p=mirrors%2FFD230.git 解决苹果ota升级失败问题 --- diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/transmitting.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/transmitting.cpp index 05edf00b9..adb32dd78 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/transmitting.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/transmitting.cpp @@ -228,39 +228,37 @@ namespace OHOS void creat_down_OTA() { - if (Title == nullptr) { - Title = new UILabelExt(); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "OTA 界面创建"); + if (Title == nullptr) + { + Title = new UILabelExt(); + if(Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - Title->SetPosition(83, 50); // widget's left position and top position - Title->Resize(300, 35); // widget's width and height - Title->SetViewId("label1");// Set style + Title->SetPosition(83, 50); + Title->Resize(300, 35); Title->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property Title->SetText("OTA下载中"); Title->SetTextId (STR_OTA_DOWNLOAD); - Title->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); Title->SetRollSpeed(0); Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - - // Add to rootView UIViewGroup_transmitting->Add(Title); - if (updatasider == nullptr) { updatasider = new UISlider(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); - + if(updatasider == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - updatasider->SetSliderColor(Color::Gray(), Color::Silver()); updatasider->SetPosition(63, 317, 340, 50); updatasider->SetViewId("SystemUpdateView_updatasider"); - updatasider->SetRange(0, 100); - + updatasider->SetRange(100, 0); updatasider->SetStyle(STYLE_BORDER_RADIUS, 100); updatasider->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); updatasider->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); @@ -270,17 +268,18 @@ namespace OHOS updatasider->SetTouchable(false); updatasider->SetValue(0); UIViewGroup_transmitting->Add(updatasider); - - - if (label_ == nullptr) { - label_ = new UILabelExt(); + /* -------------------------------------------------------------------------- */ + if (label_ == nullptr) + { + label_ = new UILabelExt(); + if(label_ == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - label_->SetPosition(60, 220); // widget's left position and top position - label_->Resize(345, 101); // widget's width and height - label_->SetViewId("label2");// Set style + label_->SetPosition(60, 220); + label_->Resize(345, 101); label_->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property label_->SetText("软件正在更新"); label_->SetTextId(STR_OTA_DOWNLOADING); label_->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); @@ -288,16 +287,15 @@ namespace OHOS label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label_->SetRollSpeed(0); label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to rootView UIViewGroup_transmitting->Add(label_); - - //Add ImageView to App - + /* -------------------------------------------------------------------------- */ if (transmitting_img == nullptr) { transmitting_img = new UIImageView(); - + if(transmitting_img == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } transmitting_img->SetPosition(193, 130, 80, 88); const char *imagesPath = TRANSMITTING_OTA_DOWN; @@ -360,46 +358,46 @@ namespace OHOS void Creat_OTA_Updata_FAIL() { - if (Title == nullptr) { - Title = new UILabelExt(); + + if (Title == nullptr) + { + Title = new UILabelExt(); + if(Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - Title->SetPosition(83, 50); // widget's left position and top position - Title->Resize(300, 35); // widget's width and height - Title->SetViewId("label1");// Set style + Title->SetPosition(83, 50); + Title->Resize(300, 35); Title->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property Title->SetText("OTA upgrade failure"); Title->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); Title->SetRollSpeed(0); Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); - UIViewGroup_transmitting->Add(Title); - - if (label_ == nullptr) { - label_ = new UILabelExt(); + /* -------------------------------------------------------------------------- */ + if (label_ == nullptr) + { + label_ = new UILabelExt(); + if(label_ == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - label_->SetPosition(60, 281); // widget's left position and top position - label_->Resize(345, 101); // widget's width and height - label_->SetViewId("label2");// Set style + label_->SetPosition(60, 281); + label_->Resize(345, 101); + label_->SetViewId("label2"); label_->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property char fail_str[128]={0}; sprintf_s(fail_str,128,"ota升级失败,请尝试重启设备"); - label_->SetText(fail_str); label_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); label_->SetTextColor(Color::GetColorFromRGBA(0xAA, 0xAA, 0xAA, 0xff)); label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label_->SetRollSpeed(0); label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); - UIViewGroup_transmitting->Add(label_); - - //Add ImageView to App - if (transmitting_img == nullptr) { transmitting_img = new UIImageView(); @@ -412,45 +410,43 @@ namespace OHOS void Creat_CAT1_OTA_Updata() { - if (Title == nullptr) { - Title = new UILabelExt(); + if (Title == nullptr) + { + Title = new UILabelExt(); + if(Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - Title->SetPosition(83, 50); // widget's left position and top position - Title->Resize(300, 35); // widget's width and height - Title->SetViewId("label1");// Set style + Title->SetPosition(83, 50); + Title->Resize(300, 35); Title->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property Title->SetText("CAT1 OTA upgradeing"); Title->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); Title->SetRollSpeed(0); Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); - UIViewGroup_transmitting->Add(Title); - - if (label_ == nullptr) { - label_ = new UILabelExt(); + /* -------------------------------------------------------------------------- */ + if (label_ == nullptr) + { + label_ = new UILabelExt(); + if(label_ == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - label_->SetPosition(60, 281); // widget's left position and top position - label_->Resize(345, 101); // widget's width and height - label_->SetViewId("label2");// Set style + label_->SetPosition(60, 281); + label_->Resize(345, 101); label_->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property - - label_->SetText("4G模块OTA升级中,请勿操作,升级成功后会自动重启"); label_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); label_->SetTextColor(Color::GetColorFromRGBA(0xAA, 0xAA, 0xAA, 0xff)); label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label_->SetRollSpeed(0); label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); - UIViewGroup_transmitting->Add(label_); - - // Add ImageView to App - + /* -------------------------------------------------------------------------- */ if (transmitting_img == nullptr) { transmitting_img = new UIImageView(); @@ -465,53 +461,47 @@ namespace OHOS UIViewGroup_transmitting->Add(transmitting_img); } - - - - void creat_down_OTA_FAIL() - { - if (Title == nullptr) { - Title = new UILabelExt(); + { + if (Title == nullptr) + { + Title = new UILabelExt(); + if(Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - Title->SetPosition(143, 51); // widget's left position and top position - Title->Resize(800, 88); // widget's width and height - Title->SetViewId("label1");// Set style + Title->SetPosition(143, 51); + Title->Resize(800, 88); Title->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property Title->SetText("OTA下载失败"); Title->SetTextId (STR_OTA_DOWNLOADFIAL); Title->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); Title->SetRollSpeed(0); Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - - // Add to rootView + /* -------------------------------------------------------------------------- */ UIViewGroup_transmitting->Add(Title); - if (label_ == nullptr) { - label_ = new UILabelExt(); + /* -------------------------------------------------------------------------- */ + if (label_ == nullptr) + { + label_ = new UILabelExt(); + if(label_ == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - label_->SetPosition(60, 281); // widget's left position and top position - label_->Resize(345, 101); // widget's width and height - label_->SetViewId("label2");// Set style + label_->SetPosition(60, 281); + label_->Resize(345, 101); label_->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property label_->SetText("下载升级包失败,请退出或者重新下载"); label_->SetTextId(STR_OTA_DOWNLOADFIAL_TRY); - label_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); label_->SetTextColor(Color::GetColorFromRGBA(0xAA, 0xAA, 0xAA, 0xff)); label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label_->SetRollSpeed(0); label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - UIViewGroup_transmitting->Add(label_); - - //Add ImageView to App - if (transmitting_img == nullptr) { transmitting_img = new UIImageView(); @@ -524,35 +514,36 @@ namespace OHOS void creat_down_OTA_SUCC() { - if (Title == nullptr) { - Title = new UILabelExt(); + if (Title == nullptr) + { + Title = new UILabelExt(); + if(Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - Title->SetPosition(143, 51); // widget's left position and top position - Title->Resize(800, 88); // widget's width and height - Title->SetViewId("label1");// Set style + Title->SetPosition(143, 51); + Title->Resize(800, 88); Title->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property Title->SetText("OTA下载成功"); Title->SetTextId (STR_OTA_DOWNLOADSUCC); Title->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); Title->SetRollSpeed(0); Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - - // Add to rootView UIViewGroup_transmitting->Add(Title); - if (label_ == nullptr) { - label_ = new UILabelExt(); + if (label_ == nullptr) + { + label_ = new UILabelExt(); + if(label_ == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } - label_->SetPosition(60, 281); // widget's left position and top position - label_->Resize(345, 101); // widget's width and height - label_->SetViewId("label2");// Set style + label_->SetPosition(60, 281); + label_->Resize(345, 101); label_->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property label_->SetText("下载升级包成功,可以开始升级手表"); label_->SetTextId(STR_OTA_DOWNLOADSUCC_UPDATA); label_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); @@ -560,26 +551,20 @@ namespace OHOS label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label_->SetRollSpeed(0); label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to rootView UIViewGroup_transmitting->Add(label_); - - - //Add ImageView to App - if (transmitting_img == nullptr) { transmitting_img = new UIImageView(); - + if(transmitting_img == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView new fail"); + } } transmitting_img->SetPosition(193, 130, 80, 88); const char *imagesPath = TRANSMITTING_OTA_DOWN; transmitting_img->SetSrc(imagesPath); UIViewGroup_transmitting->Add(transmitting_img); } - - - void creat_down_Dial() { diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c index 919f8b7fe..2cd425434 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c @@ -4475,24 +4475,46 @@ static void switchDialCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *total //关于本机内容 static void aboutDeviceCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) { + // 1. 入口日志:记录请求基本信息 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 进入接口,cmd:%d, data_len:%d, crcvalue:0x%02X", cmd, len, crcvalue); uint8_t _major,_mid,_minor; - uapi_get_fw_version(&_major,&_mid,&_minor); + // 2. 获取固件版本日志 + int fw_ret = uapi_get_fw_version(&_major,&_mid,&_minor); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 获取固件版本:ret:%d, major:%d, mid:%d, minor:%d", fw_ret, _major, _mid, _minor); + cJSON *dataJSON = cJSON_CreateObject(); + if (dataJSON == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AboutDevice] JSON 对象创建失败!"); + return; + } cJSON_AddNumberToObject(dataJSON,"code",1); cJSON_AddNumberToObject(dataJSON,"major",_major); cJSON_AddNumberToObject(dataJSON,"mid",_mid); cJSON_AddNumberToObject(dataJSON,"minor",_minor); - unsigned char addr[6]; - bluetooth_get_local_addr(&addr[0],6); - char mac_data[24]; + + // 3. 获取MAC地址日志 + unsigned char addr[6] = {0}; + int bt_ret = bluetooth_get_local_addr(&addr[0],6); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 获取蓝牙MAC地址:ret:%d, addr:[%02X:%02X:%02X:%02X:%02X:%02X]", + bt_ret, addr[5],addr[4],addr[3],addr[2],addr[1],addr[0]); + + char mac_data[24] = {0}; memset(mac_data,0,24); sprintf(mac_data,"%02X:%02X:%02X:%02X:%02X:%02X",addr[5],addr[4],addr[3],addr[2],addr[1],addr[0]); cJSON_AddStringToObject(dataJSON, "macAddress",mac_data); + // 4. JSON 序列化日志 char *json_format = cJSON_PrintUnformatted(dataJSON); cJSON_Delete(dataJSON); + if (json_format == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AboutDevice] JSON 序列化失败!"); + return; + } uint32_t data_len = strlen(json_format); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[AboutDevice] JSON 序列化完成:len:%d, content:%s", data_len, json_format); + + // 5. 构建发送数据缓冲区日志 uint8_t value[data_len+19]; memset(value,0,data_len+19); uint32_t tmp = 1; @@ -4504,22 +4526,34 @@ static void aboutDeviceCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota memcpy(value+7,&data_len,4); memcpy(value+11,&tmp,4); memcpy(value+15,&tmp_data,2); - if(Check_CRC(data,len,crcvalue)) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 构建发送缓冲区:总长度:%d, 头部[0-16]: 0x%02X 0x%02X 0x%02X ...", + data_len+19, value[0], value[1], value[2]); + + // 6. CRC 校验日志 + int crc_check = Check_CRC(data,len,crcvalue); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AboutDevice] CRC 校验结果:%d (1=成功,0=失败)", crc_check); + + if(crc_check) { - memcpy(value+17,(uint8_t *)json_format,data_len);//17+69 = 86 - - value[data_len+17] = Calculate_CRC(value,data_len+17);// - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"data_len:%d %x %d!!!!!\r\n",data_len,value[data_len+17],data_len+17); + memcpy(value+17,(uint8_t *)json_format,data_len); + value[data_len+17] = Calculate_CRC(value,data_len+17); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 准备发送有效数据:长度:%d, CRC值:0x%02X", + data_len+18, value[data_len+17]); sendBleData(value,data_len+18); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 有效数据已调用 sendBleData 发送"); }else { value[17] = 0; uint8_t lrc = Calculate_CRC(value,18); value[18] = lrc; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 准备发送错误数据:长度:19, CRC值:0x%02X", lrc); sendBleData(value,19); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 错误数据已调用 sendBleData 发送"); } + // 7. 释放资源日志 cJSON_free(json_format); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[AboutDevice] 接口执行完成,资源已释放"); } //查找手表 01 04 //设置查找手表的状态,1 校验成 2手表已找到,停止查找手表 @@ -5263,7 +5297,7 @@ static void GetWatchStatusCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *t memcpy(value+15,&tmp_data,2); //0空闲状态 9 usb状态 10 运动训练状态 - uint8_t watchStatus = 0; + uint8_t watchStatus = 0; if(uapi_dev_runtime_get_train_status()) watchStatus=10; @@ -7534,7 +7568,7 @@ static void ble_transfer_Timer_CallBack(int data) cancel_recv_file(1); } } -uint8_t OTA_FILE_value=0; +uint32_t OTA_FILE_value=0; errcode_t decode_ota_data(ble_read_data *buffer_handle,uint8_t *data,uint16_t datalen,uint8_t crcvalue) { @@ -7726,8 +7760,9 @@ errcode_t decode_ota_data(ble_read_data *buffer_handle,uint8_t *data,uint16_t da buffer_handle->file_recv_stat.lrcvalue = calculate_lrc(data_,datalen,buffer_handle->file_recv_stat.lrcvalue); buffer_handle->file_recv_stat.received_size += datalen; OTA_FILE_value= ((float) buffer_handle->file_recv_stat.received_size / (float)buffer_handle->file_recv_stat.file_size) *100; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"handle_recv_file received_size %d %0.3lf\n",buffer_handle->file_recv_stat.received_size - ,(float) buffer_handle->file_recv_stat.received_size / (float)buffer_handle->file_recv_stat.file_size); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"handle_recv_file received_size %d %0.3lf\n",buffer_handle->file_recv_stat.received_size + ,(float) buffer_handle->file_recv_stat.received_size / (float)buffer_handle->file_recv_stat.file_size); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"OTA_FILE_value %d \n",OTA_FILE_value); }else{ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"handle_recv_file write file failed! ret %d != %d\n",writtensize,datalen); @@ -9300,7 +9335,7 @@ errcode_t cancel_recv_file(uint8_t flag) return ERRCODE_SUCC; } -uint8_t get_OTA_recv_value() +uint32_t get_OTA_recv_value() { return OTA_FILE_value; } diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h index 520de68dd..2d7ead016 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.h @@ -771,7 +771,7 @@ typedef struct -uint8_t get_OTA_recv_value(void); +uint32_t get_OTA_recv_value(void); void Set_OTA_recv_value(void);