Mp3文件传输重写 1005/4
authorhcj <1224667075@qq.com>
Tue, 24 Sep 2024 03:21:23 +0000 (11:21 +0800)
committerhcj <1224667075@qq.com>
Tue, 24 Sep 2024 03:21:23 +0000 (11:21 +0800)
code/sdk/application/wearable/service/ble_service/blemoder/bletest.h
code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c
code/sdk/application/wearable/service/msg_center/include/notify/transmitting.h
code/sdk/application/wearable/service/msg_center/src/notify/transmitting.cpp

index d3097be..9cf6cdb 100644 (file)
@@ -38,6 +38,10 @@ extern "C"
     TRANS_OTA_TRANSMITTING,
     TRANS_OTA_SUCC,
     TRANS_OTA_FAIL,
+
+    TRANS_MP3_TRANSMITTING,
+    TRANS_MP3_SUCC,
+    TRANS_MP3_FAIL,
     
     TRANS_FREE,
     } transmitting_type;
index 01ae8e1..dcbc61e 100644 (file)
@@ -6723,7 +6723,11 @@ errcode_t decode_mp3_json(ble_read_data *buffer_handle)
         buffer_handle->file_recv_stat.received_size = 0;\r
         buffer_handle->file_recv_stat.lrcvalue = 0;\r
         buffer_handle->receive_file_flag = 1;\r
+        TRANSMIT_DATA=TRANS_MP3_TRANSMITTING;\r
+        CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1);\r
+\r
         return ERRCODE_SUCC;\r
+\r
     }else{\r
         buffer_handle->receive_file_flag = 0;        \r
         return ERRCODE_FAIL;\r
@@ -7078,7 +7082,9 @@ void decode_file_checksum(ble_read_data *buffer_handle)
 \r
                     break;\r
                 case 2://mp3\r
-\r
+                    TRANSMIT_DATA=TRANS_MP3_SUCC;\r
+                    CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1);\r
+                    \r
                     ble_reply_cmd(DIAL_INSTALL_REPY_CMD,1);\r
                     ble_mp3_list_update();\r
 \r
@@ -7123,6 +7129,8 @@ void decode_file_checksum(ble_read_data *buffer_handle)
                     CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1);\r
                     break;\r
             case 2://mp3\r
+                    TRANSMIT_DATA=TRANS_MP3_FAIL;\r
+                    CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1);\r
 \r
                     break;\r
             case 3://dial\r
@@ -7144,6 +7152,9 @@ void decode_file_checksum(ble_read_data *buffer_handle)
                 CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1);\r
                 break;\r
         case 2://mp3\r
+                TRANSMIT_DATA=TRANS_MP3_FAIL;\r
+                CustomEventPublish(TOPIC_EVENT_BLE_TRANSMIT,&TRANSMIT_DATA,1);\r
+                \r
                 break;\r
         case 3://dial\r
                 TRANSMIT_DATA= TRANS_DIAL_FAIL;\r
@@ -7479,6 +7490,29 @@ static errcode_t check_package_same(uint8_t* lastdata,uint8_t *newdata , uint16_
         return ERRCODE_FAIL;\r
     }\r
 }\r
+//MP3文件重命名\r
+static errcode_t create_mp3_name(char* path,char*dir_path ,char* file_name)\r
+{\r
+\r
+    sprintf_s(path,256,"%s/",dir_path);\r
+    uint16_t path_len=strlen(path);\r
+\r
+    if(strstr(file_name,".mp3"))\r
+    {\r
+        int len=strlen(file_name)-strlen(".mp3");\r
+        for(int i=0;i<len;i++)\r
+        {\r
+            char UintBUF[3]={0};\r
+            sprintf(UintBUF,"%02X",file_name[i]);\r
+            memcpy_s(path+path_len,2,UintBUF,2);\r
+            path_len+=2;\r
+        }\r
+        memcpy_s(path+path_len,strlen(".mp3"),".mp3",strlen(".mp3"));\r
+        return ERRCODE_SUCC;\r
+    }\r
+    return ERRCODE_FAIL;\r
+    \r
+}\r
 errcode_t handle_recv_file(ble_read_data *buffer_handle,uint8_t *data, uint16_t event_size)\r
 {\r
 \r
@@ -7516,7 +7550,8 @@ errcode_t handle_recv_file(ble_read_data *buffer_handle,uint8_t *data, uint16_t
             char musicpath[64]={0};\r
             get_music_path(musicpath,64);\r
             char filepath[256]={0};\r
-            sprintf_s(filepath,256,"%s/%s",musicpath,buffer_handle->file_recv_stat.file_name);\r
+            create_mp3_name(filepath,musicpath,buffer_handle->file_recv_stat.file_name);\r
+\r
             buffer_handle->file_recv_stat.file = fopen(filepath,"w+");\r
             printf("%s\r\n",filepath);\r
         }\r
index ab79ce3..c228a94 100644 (file)
@@ -1,24 +1,12 @@
 #ifndef TRANSMITTING_H
 #define TRANSMITTING_H
 #include "components/ui_image_animator.h" 
+#include "bletest.h"
 
 namespace OHOS
 {
     // UIViewGroup *ChargingStatuShow(void);
     // UIView *view_ = nullptr;
-
-    typedef enum transmitting_type_t {
-    TRANS_DIAL_TRANSMITTING,
-    TRANS_DIAL_SUCC,
-    TRANS_DIAL_FAIL,
-
-    TRANS_OTA_TRANSMITTING,
-    TRANS_OTA_SUCC,
-    TRANS_OTA_FAIL,
-    
-    TRANS_FREE,
-    } transmitting_type_t;
-
     UIViewGroup* transmittingShow(void);
     void set_transmittingShow_falg(uint8_t falg);
     void Freetransmitting(void);
index 1341d74..e614e02 100644 (file)
@@ -427,8 +427,127 @@ namespace OHOS
         UIViewGroup_transmitting->Add(downImageAnimatorView);
     }
 
-    
 
+    void creat_down_MP3()
+    {
+        if (Title == nullptr) {
+        Title = new UILabel();
+        }
+        Title->SetPosition(158, 51);         // widget's left position and top position
+        Title->Resize(800, 88);          // widget's width and height
+        Title->SetViewId("label1");// Set style
+        Title->SetStyle(STYLE_TEXT_FONT, 30);
+
+        // Set additional property
+        Title->SetText("音乐传输中");
+        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);
+        Title->SetVisible(true);
+
+
+         if (label_ == nullptr) {
+        label_ = new UILabel();
+        }
+        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_->SetStyle(STYLE_TEXT_FONT, 30);
+
+        // Set additional property
+        label_->SetText("正在传输音乐,请不要做其他操作或关闭手表");
+        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);
+
+        // Add to rootView
+        UIViewGroup_transmitting->Add(label_);
+        label_->SetVisible(true);
+
+        CreatetransmittingAnimator();
+        // UIViewGroup_transmitting->Add(updatasider);
+       
+        UIViewGroup_transmitting->Add(downImageAnimatorView);
+    }
+
+    void creat_down_MP3_succ()
+    {
+        if (Title == nullptr) {
+        Title = new UILabel();
+        }
+        Title->SetPosition(173, 51);         // widget's left position and top position
+        Title->Resize(800, 88);          // widget's width and height
+        Title->SetViewId("label1");// Set style
+        Title->SetStyle(STYLE_TEXT_FONT, 30);
+
+        // Set additional property
+        Title->SetText("传输成功");
+        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);
+        Title->SetVisible(true);
+
+
+         if (label_ == nullptr) {
+        label_ = new UILabel();
+        }
+        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_->SetStyle(STYLE_TEXT_FONT, 30);
+
+        // Set additional property
+        label_->SetText("音乐传输成功正在校验,请稍等");
+        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);
+
+
+        
+        if (transmitting_img == nullptr)
+        {
+            transmitting_img = new UIImageView();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView::KUMILOGOImage new fail!");
+        }
+        transmitting_img->SetPosition(193, 150,80, 80);
+        const char *imagesPath = TRANSMITTING_SUCC_PATH;
+        transmitting_img->SetSrc(imagesPath);
+        UIViewGroup_transmitting->Add(transmitting_img);
+
+        uint32_t tick;
+        osStatus_t retTimer;
+        if(transmitting_timer!=NULL)
+        {
+            osTimerStop(transmitting_timer);
+            osTimerDelete(transmitting_timer);
+            transmitting_timer = NULL;
+        }
+        transmitting_timer = osTimerNew((osTimerFunc_t)dialtimerCallBack, osTimerPeriodic, NULL, NULL);
+        tick =2000;// osMs2Tick(1000);
+        retTimer = osTimerStart(transmitting_timer, tick);
+        if (retTimer != osOK && transmitting_timer != NULL) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
+            osTimerDelete(transmitting_timer);
+            transmitting_timer = NULL;
+            return ;
+        }
+
+        // Add to rootView
+        UIViewGroup_transmitting->Add(label_);
+        label_->SetVisible(true);
+    }
 
 
 
@@ -563,6 +682,63 @@ namespace OHOS
 
     }
 
+    void creat_down_MP3_fail()
+    {
+        if (Title == nullptr) {
+        Title = new UILabel();
+        }
+        Title->SetPosition(173, 51);         // widget's left position and top position
+        Title->Resize(800, 88);          // widget's width and height
+        Title->SetViewId("label1");// Set style
+        Title->SetStyle(STYLE_TEXT_FONT, 30);
+
+        // Set additional property
+        Title->SetText("传输失败");
+        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);
+        Title->SetVisible(true);
+
+
+         if (label_ == nullptr) {
+        label_ = new UILabel();
+        }
+        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_->SetStyle(STYLE_TEXT_FONT, 30);
+
+        // Set additional property
+        label_->SetText("音乐传输失败,请退出或重新安装");
+        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);
+
+
+         
+        if (transmitting_img == nullptr)
+        {
+            transmitting_img = new UIImageView();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemUpdateView::KUMILOGOImage new fail!");
+        }
+        transmitting_img->SetPosition(193, 150,80, 80);
+        const char *imagesPath = TRANSMITTING_FAIL_PATH;
+        transmitting_img->SetSrc(imagesPath);
+        UIViewGroup_transmitting->Add(transmitting_img);
+
+        // Add to rootView
+        UIViewGroup_transmitting->Add(label_);
+        label_->SetVisible(true);
+
+       
+
+    }
 
 
 
@@ -599,6 +775,16 @@ namespace OHOS
              case TRANS_OTA_FAIL:
                 creat_down_OTA_FAIL();
                 break;
+            case TRANS_MP3_TRANSMITTING:
+                creat_down_MP3();
+                break;
+             case TRANS_MP3_SUCC:
+                creat_down_MP3_succ();
+                break;
+             case TRANS_MP3_FAIL:
+                creat_down_MP3_fail();
+                break;
+            
         default:
             break;
         }
@@ -638,7 +824,7 @@ namespace OHOS
     bool transmittingViewEventListener::OnClick(UIView& view, const ClickEvent& event)
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick");
-        if(Transmitting_falg!=TRANS_DIAL_TRANSMITTING && Transmitting_falg!=TRANS_OTA_TRANSMITTING)
+        if(Transmitting_falg!=TRANS_DIAL_TRANSMITTING && Transmitting_falg!=TRANS_OTA_TRANSMITTING && Transmitting_falg!=TRANS_MP3_TRANSMITTING)
         {
             NotificationManager::GetInstance()->StopNotify();
         }