优化a5133收发协议 596/1 596/head 597/target/1
authorpenglei <1624952103@qq.com>
Fri, 26 Jul 2024 14:30:41 +0000 (22:30 +0800)
committerpenglei <1624952103@qq.com>
Fri, 26 Jul 2024 14:30:41 +0000 (22:30 +0800)
code/sdk/application/wearable/fd230app/nativeui/producttest/include/testA5133.h
code/sdk/application/wearable/fd230app/nativeui/producttest/src/testA5133.cpp
code/sdk/application/wearable/fd230app/nativeui/producttest/src/testPresenter.cpp
code/sdk/drivers/peripheral/a5133/A5133Main.c

index 9bb5779..bd98ea4 100644 (file)
@@ -1,3 +1,13 @@
+/*
+ * @Author: penglei 1624952103@qq.com
+ * @Date: 2024-07-20 14:09:23
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2024-07-26 18:56:38
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/producttest/include/testA5133.h
+ * @Description: 
+ * 
+ * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
+ */
 #ifndef TEST_A5133_VIEW_H
 #define TEST_A5133_VIEW_H
 
@@ -54,13 +64,14 @@ namespace OHOS
         virtual ~testA5133View();
         static testA5133View *GetInstance(void);
         void dial_112(bool);
-        void BT_discovery_callback(void);
-
+        void a5133_receive_callback(void);
+        void a5133_transmit_callback(void);
+        void a5133_send_data_callback(int cmd);
+        
         UIScrollView *testA5133InitIView(uint8_t);
         void ClearAll(void);
         void set_BR_connect(char *);
-        bool  br_scan_set_text(unsigned char *name ,unsigned char *addr,int16_t rssi,int i);
-        UILabelButtonExt* button{NULL};
+        bool  a5133_set_text(uint8_t *databuf,int i);
 
     private:
         UILabelButtonExt *SetTheButton_ext(ButtonConfig_ext_t &buttonconfig);//, UIView::OnTouchListener *clickListener);
@@ -73,7 +84,9 @@ namespace OHOS
         UILabel *label_a5133_SCAN[5]{nullptr};
 
         bool initViewStatus{false};
+        UILabelButtonExt* button[4]{NULL};
         UILabel *Title{nullptr};           // 标题
+        UIImageView *image3_{nullptr};  
        
     };
 }
index 0a0a2c2..6a49d8e 100644 (file)
 #include "bleService.h"
 #include "BluetoothModel.h"
 #include "producttest/include/testView.h"
+#ifdef SUPPORT_A5133_SERVICE
+#include "service/a5133_service.h"
+#endif
+
 #ifdef __cplusplus
 #if __cplusplus
 extern "C"
@@ -49,7 +53,7 @@ namespace OHOS
     {
         return g_ptestA5133View;
     }
-    static osTimerId_t BR_TEST_timer=NULL;
+    static osTimerId_t A5133_TEST_timer=NULL;
     void testA5133View::ClearAll()
     {
         if(testa5133ScrollView)
@@ -58,25 +62,38 @@ namespace OHOS
 
             testa5133ScrollView->RemoveAll();
 
-            if (BR_TEST_timer != NULL) {
-                osTimerStop(BR_TEST_timer);
-                osTimerDelete(BR_TEST_timer);
-                BR_TEST_timer = NULL;
+            if (A5133_TEST_timer != NULL) {
+                osTimerStop(A5133_TEST_timer);
+                osTimerDelete(A5133_TEST_timer);
+                A5133_TEST_timer = NULL;
                 return ;
             }
-            if(button)
+            if(button[0])
             {
-                delete button;
-                button=nullptr;
+                delete button[0];
+                button[0]=nullptr;
+            }
+            if(button[1])
+            {
+                delete button[1];
+                button[1]=nullptr;
+            }
+            if(button[2])
+            {
+                delete button[2];
+                button[2]=nullptr;
+            }
+            if(button[3])
+            {
+                delete button[3];
+                button[3]=nullptr;
             }
-
             if(labelButton_next)
             {
                 delete labelButton_next;
                 labelButton_next=nullptr;
             }
          
-
             if(Title)
             {
                 delete Title;
@@ -137,30 +154,88 @@ namespace OHOS
         // button->SetDraggable(false);
         return button;
     }
-    static bool speakfalg=false;
-   
-    static bool discovery_falg=false;
-   
-    void testA5133View:: BT_discovery_callback( void)
+
+    static bool receive_flag=false;
+
+    static bool transmit_flag=false;
+
+    void testA5133View::a5133_send_data_callback(int cmd)
     {
-        
-        bool reT_gap;
-        if(discovery_falg==false)
+        uint8 send_data_1[64] = {"前方路段发生塌方,请紧急制动"};
+        uint8 send_data_2[64] = {"前方道路拥堵,请减速慢行,注意安全"};
+        errcode_t ret = 0;
+        if(cmd)
         {
+            ret = uapi_a5133_set_send_data(send_data_1,64);
+            if(ret != ERRCODE_SUCC)
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_a5133_set_send_data_1 failed %d",ret);
+        }
+        else
+        {   
+            ret = uapi_a5133_set_send_data(send_data_2,64);
+            if(ret != ERRCODE_SUCC)
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_a5133_set_send_data_2 failed %d",ret);
+        }
+    }
+
+    static uint8_t a1533_count = 0;
+
+    void testA5133View::a5133_transmit_callback( void)
+    {
+        int ret = 0;
+        if(transmit_flag==false)
+        {
+            uapi_set4GCapability(true);
+            send_a5133_cmd_msg(9);
+            button[1]->SetText("start transmit");
+            button[1]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);
+            transmit_flag = true;
+            if(A5133_TEST_timer)
+            {
+                ret = osTimerStart(A5133_TEST_timer, 1000);
+                if(ret != 0)
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"osTimerStart A5133_TEST_timer failed %d",ret);
+            }
 
-            
-            button->SetText("scaning");
-            button->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);
-            discovery_falg=true;
         }
         else
         {
-            
-            button->SetText("discovery");
-            button->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);   
+            button[1]->SetText("stop transmit");
+            button[1]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);   
+            transmit_flag = false;
+            if(A5133_TEST_timer)
+            {
+                ret = osTimerStop(A5133_TEST_timer);
+                if(ret != 0)
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"osTimerStop A5133_TEST_timer failed %d",ret);
+                a1533_count = 0;
+            }
+        } 
+    }
+
+
+    void testA5133View::a5133_receive_callback( void)
+    {
+        if(receive_flag==false)
+        {
+            uapi_set4GCapability(true);
+            send_a5133_cmd_msg(10);
+            button[0]->SetText("start receive");
+            button[0]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);
+            receive_flag = true;
 
-            discovery_falg=false;
+        }
+        else
+        {
+            button[0]->SetText("stop receive");
+            button[0]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);   
+
+            receive_flag = false;
+            for(int i = 0 ; i < 1; i++)
+                label_a5133_SCAN[i]->SetText("");
+            
         } 
+        RootView::GetInstance()->Invalidate();
     }
 
 
@@ -176,9 +251,11 @@ namespace OHOS
         label->SetStyle(STYLE_LINE_HEIGHT, labelConfig.lineHeigh);                                    // 字体行高
         label->SetText(labelConfig.text);                                                             // 内容
         label->SetLineBreakMode(labelConfig.lineBreakMode);                                           // 断行模式。
-        label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP);
+        label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelConfig.fontSize);
         label->SetAlign(TEXT_ALIGNMENT_LEFT);
+        label->SetStyle(STYLE_BORDER_COLOR, 0xff0176ff);
+        label->SetStyle(STYLE_BORDER_COLOR, 0xff0176ff);
         return label;
     }
 
@@ -203,25 +280,22 @@ namespace OHOS
         free(device_name);
     }
 
-
     static void  mgdataTimerCallBack(int data)
     {
+        uint8_t rxdata[80] = {0};
+        uapi_get_a5133_rxdata(rxdata,80);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "rxdata:%s",rxdata);
+        testA5133View::GetInstance()->a5133_set_text(rxdata,0);
+        RootView::GetInstance()->Invalidate();
+    } 
 
-        
-
-    }  
-
-    bool  testA5133View::br_scan_set_text(unsigned char *name ,unsigned char *addr,int16_t rssi,int i)
+    bool  testA5133View::a5133_set_text(uint8_t *databuf,int i)
     {
-        if(i>=5)
-        {
-            return false;
-        }
-        char buf[128]={0};
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rssi %d",rssi);
+       
+        //unsigned char buf[80]= {0};
 
-        sprintf_s(buf,128,"addr:%02X %02X %02X %02X %02X %02X\nRssi:%d",addr[0],addr[1],addr[2],addr[3],addr[4],addr[5],rssi);
-        label_a5133_SCAN[i]->SetText(buf);
+        //sprintf_s(buf,128,"addr:%02X %02X %02X %02X %02X %02X\nRssi:%d",addr[0],addr[1],addr[2],addr[3],addr[4],addr[5],rssi);
+        label_a5133_SCAN[a1533_count]->SetText((char *)databuf);
         RootView::GetInstance()->Invalidate();
         
         return true;
@@ -247,24 +321,80 @@ namespace OHOS
         testa5133ScrollView->SetDirection(1);
 
 
-        LabelConfig Config = {
-            .left = 33,
-            .top = 80,
-            .width = 400,
-            .height = 44,
-            .fontSize = 30,
-            .lineHeigh = 0,
-            .text = "",
-            .lineBreakMode = UILabel::LINE_BREAK_WRAP,
-        };
+    //      if (label5_ == nullptr) {
+    //     label5_ = new UILabel();
+    // }
+     //label5_->SetPosition(79, 203);         // widget's left position and top position
+    // label5_->Resize(306, 49);          // widget's width and height
+    // label5_->SetViewId("label5");// Set style
+    // label5_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff007dff);
+    // label5_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+    // label5_->SetStyle(STYLE_BORDER_COLOR, 0xff0176ff);
+    // label5_->SetStyle(STYLE_TEXT_FONT, 30);
+
+    // // Set additional property
+    // label5_->SetText("28%");
+    // label5_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+    // label5_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+    // label5_->SetRollSpeed(0);
+    // label5_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+
+            // Add ImageView to App
+        if (image3_ == nullptr) {
+            image3_ = new UIImageView();
+        }
+        image3_->SetPosition(40, 192);         // widget's left position and top position
+        image3_->Resize(379, 100);          // widget's width and height
+        image3_->SetViewId("image3");// Set style
+        image3_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+        image3_->SetStyle(STYLE_BORDER_WIDTH, 3);
+        image3_->SetStyle(STYLE_BORDER_COLOR, 0xffffffff);
 
+        // Set additional property
 
-        for(int i=0 ;i<5;i++)
-        {
-            Config.top+=100;
-            label_a5133_SCAN[i]= InitLabel(Config);
-            testa5133ScrollView->Add(label_a5133_SCAN[i]);
+        // Add to rootView
+        testa5133ScrollView->Add(image3_);
+        image3_->SetVisible(true);
+
+        if (label_a5133_SCAN[0] == nullptr) {
+            label_a5133_SCAN[0] = new UILabel();
         }
+        label_a5133_SCAN[0]->SetPosition(0, 193);         // widget's left position and top position
+        label_a5133_SCAN[0]->Resize(466, 100);          // widget's width and height
+        label_a5133_SCAN[0]->SetViewId("label5");// Set style
+        label_a5133_SCAN[0]->SetStyle(STYLE_TEXT_FONT, 25);
+
+        // Set additional property
+        label_a5133_SCAN[0]->SetText("default");
+        label_a5133_SCAN[0]->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+        label_a5133_SCAN[0]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        label_a5133_SCAN[0]->SetRollSpeed(0);
+        label_a5133_SCAN[0]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 25);
+
+        // Add to rootView
+        testa5133ScrollView->Add(label_a5133_SCAN[0]);
+        label_a5133_SCAN[0]->SetVisible(true);
+
+
+        // LabelConfig Config = {
+        //     .left = 79,
+        //     .top = 80,
+        //     .width = 306,
+        //     .height = 49,
+        //     .fontSize = 30,
+        //     .lineHeigh = 0,
+        //     .text = "",
+        //     .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS,
+        // };
+
+
+        // for(int i=0 ;i<5;i++)
+        // {
+        //     Config.top+=100;
+        //     label_a5133_SCAN[i]= InitLabel(Config);
+        //     testa5133ScrollView->Add(label_a5133_SCAN[i]);
+        // }
+
 
         ButtonConfig_ext_t buttonconfig;
         buttonconfig.x = 55;
@@ -274,13 +404,54 @@ namespace OHOS
         buttonconfig.label_x=40;
         buttonconfig.label_y=0;
         buttonconfig.Fontsize=30;
-        buttonconfig.ViewId="discovery";
-        buttonconfig.str="discovery";
+        buttonconfig.ViewId="receive";
+        buttonconfig.str="receive";
         buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT;
 
-        button=SetTheButton_ext(buttonconfig);
-        testa5133ScrollView->Add(button);
-
+        button[0]=SetTheButton_ext(buttonconfig);
+        testa5133ScrollView->Add(button[0]);
+
+
+        // buttonconfig.x = 55;
+        // buttonconfig.y = 200;
+        // buttonconfig.w = 180;
+        // buttonconfig.h = 88;
+        // buttonconfig.label_x=40;
+        // buttonconfig.label_y=0;
+        // buttonconfig.Fontsize=30; 
+        // buttonconfig.ViewId="transmit";
+        // buttonconfig.str="transmit";
+        // buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT;
+        // button[1]=SetTheButton_ext(buttonconfig);
+        // testa5133ScrollView->Add(button[1]);
+
+        // buttonconfig.x = 55;
+        // buttonconfig.y = 220;
+        // buttonconfig.w = 180;
+        // buttonconfig.h = 88;
+        // buttonconfig.label_x=40;
+        // buttonconfig.label_y=0;
+        // buttonconfig.Fontsize=30; 
+        // buttonconfig.ViewId="send_data_1";
+        // buttonconfig.str="1";
+        // buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT;
+        // button[2]=SetTheButton_ext(buttonconfig);
+        // testa5133ScrollView->Add(button[2]);
+
+        // buttonconfig.x = 55;
+        // buttonconfig.y = 280;
+        // buttonconfig.w = 180;
+        // buttonconfig.h = 88;
+        // buttonconfig.label_x=40;
+        // buttonconfig.label_y=0;
+        // buttonconfig.Fontsize=30; 
+        // buttonconfig.ViewId="send_data_2";
+        // buttonconfig.str="2";
+        // buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT;
+        // button[3]=SetTheButton_ext(buttonconfig);
+        // testa5133ScrollView->Add(button[3]);
+
+       
 
         UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(testPresenter::GetInstance());
         if (draglistener == nullptr)
@@ -295,7 +466,7 @@ namespace OHOS
         labelButton_next= testAboutView::GetInstance()->init_button_next(270,80,Test_ViewMapper_t[id].viewid_str_next);
         testa5133ScrollView->Add(labelButton_next);
         
-        Title= testAboutView::GetInstance()->init_title(165,45,"BT_TEST");
+        Title= testAboutView::GetInstance()->init_title(165,45,"A5133_TEST");
         testa5133ScrollView->Add(Title);
 
 
@@ -303,17 +474,12 @@ namespace OHOS
         testa5133ScrollView->SetDraggable(true);
         uint32_t tick;
         osStatus_t retTimer;
-        BR_TEST_timer = osTimerNew((osTimerFunc_t)mgdataTimerCallBack, osTimerPeriodic, NULL, NULL);
-        tick =5000;// osMs2Tick(1000);
-        retTimer = osTimerStart(BR_TEST_timer, tick);
-        if (retTimer != osOK && BR_TEST_timer != NULL) {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
-            osTimerDelete(BR_TEST_timer);
-            BR_TEST_timer = NULL;
-            return false;
-        }
+        A5133_TEST_timer = osTimerNew((osTimerFunc_t)mgdataTimerCallBack, osTimerPeriodic, NULL, NULL);
+        if(A5133_TEST_timer)
+            osTimerStart(A5133_TEST_timer, 1000);
 
-        discovery_falg=false;
+        receive_flag=false;
+        transmit_flag = false;
         uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST);
         if (cnt == 0) {
             uapi_pm_add_sleep_veto(PM_ID_P_TEST);
index 60351b6..92417ff 100644 (file)
@@ -255,7 +255,27 @@ namespace OHOS
 \r
             testBTView::GetInstance()->BT_discovery_callback();\r
         }\r
-       \r
+\r
+        if(strcmp(view.GetViewId(),"receive") == 0)\r
+        { \r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "strcmp(view.GetViewId()recevie");\r
+            testA5133View::GetInstance()->a5133_receive_callback();\r
+        }\r
+        if(strcmp(view.GetViewId(),"transmit") == 0)\r
+        { \r
+            testA5133View::GetInstance()->a5133_receive_callback();\r
+        }\r
+        if(strcmp(view.GetViewId(),"send_data_1") == 0)\r
+        { \r
+\r
+            testA5133View::GetInstance()->a5133_receive_callback();\r
+        }\r
+        if(strcmp(view.GetViewId(),"send_data_2") == 0)\r
+        { \r
+\r
+            testA5133View::GetInstance()->a5133_receive_callback();\r
+        }\r
+\r
         return false;\r
     }\r
 \r
index 39fa3a8..0de9fa8 100644 (file)
@@ -529,25 +529,27 @@ void RxPacket(void)
        //crccheck\r
 \r
        a5133_gpio_scs_set_value(1);\r
-       uint8_t datalen = tmpbuf[8];\r
-       if (datalen >0 && datalen <= (64-8-1))\r
+       uint8_t datalen = tmpbuf[4];\r
+       if (datalen >0 && datalen <= (64-4-1))\r
        {\r
-               uint16_t crc = CRC16_XMODEM(&tmpbuf[1+8],datalen);\r
-               uint16_t recv_crc =  *(uint16_t*)&tmpbuf[1+datalen+8];\r
+               uint16_t crc = CRC16_XMODEM(&tmpbuf[1+4],datalen);\r
+               uint16_t recv_crc =  *(uint16_t*)&tmpbuf[1+datalen+4];\r
                PRINT("crc[%X] , recv_crc %X\n",crc,recv_crc);\r
                if (crc != recv_crc)\r
                {\r
                        err = 1;\r
-               }else{\r
+               }\r
+               // else\r
+               {\r
                        tmpbuf_len = datalen;\r
                        memset(tmpbuf_rx, 0 ,sizeof(tmpbuf_rx));\r
-                       memcpy(tmpbuf_rx, &tmpbuf[1+8],datalen);\r
+                       memcpy(tmpbuf_rx, &tmpbuf[1+4],datalen);\r
                }\r
                printf("=====RxPacket \n");\r
                \r
        }else{\r
                err = 1 ;\r
-               printf("=====RxPacket failed \n");\r
+               printf("=====RxPacket failed datalen[%d]\n",datalen);\r
        }\r
        dump_tmpbuf();\r
        if (err)//packet error\r