K5 gps问题修正
authorp15692025051 <846603105@qq.com>
Mon, 18 Sep 2023 02:52:07 +0000 (10:52 +0800)
committerp15692025051 <846603105@qq.com>
Mon, 18 Sep 2023 02:52:07 +0000 (10:52 +0800)
19 files changed:
2.sdk/Helios_SDK/components/HX3918/hx3918.c
2.sdk/Helios_SDK/components/HX3918/hx3918_check_touch.c
2.sdk/Helios_SDK/components/HX3918/hx3918_factory_test.c
2.sdk/Helios_SDK/components/HX3918/hx3918_hrs_agc.c
2.sdk/Helios_SDK/components/HX3918/hx3918_hrv_agc.c
2.sdk/Helios_SDK/components/HX3918/hx3918_prox.c
2.sdk/Helios_SDK/components/HX3918/hx3918_prox.h
2.sdk/Helios_SDK/components/HX3918/hx3918_spo2_agc.c
2.sdk/Helios_SDK/services/microPython/ports/quectel/core/source/modGsensor_SC7A20.c
2.sdk/Helios_SDK/services/microPython/ports/quectel/core/source/modHsensor_HX3918.c
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/appFactoryMode.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/location.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/main_init.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/mgr.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/protocol.py
2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/images/DBG.7z
2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/images/firmware_base_release_pack.zip
2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/libraries/libHeliosAPI.lib
2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/libraries/ql_common_api.lib

index 486104f..c382624 100644 (file)
@@ -102,7 +102,9 @@ const int32_t  spo2_ir_wear_thres = 20000;
 const int32_t  check_mode_unwear_thre = 5000;
 const int32_t  check_mode_wear_thre = 6000;
 //const int32_t  check_mode_sar_thre = 6000;
-
+#ifndef  SAR_ALG_LIB
+#define NORMALWEARDIFF  12000
+#endif
 int32_t  sar_wear_thres = NORMALWEARDIFF/3;  // 可设定为正常的1/3, 必须小于32767
 int32_t  sar_unwear_thres = NORMALWEARDIFF/30*8; // 可设定为 sar_wear_thres *0.8
 
@@ -224,6 +226,7 @@ char hx3918_ppg_timerout_flag = 0;
 void hx3918_ppg_timerout_cb(void)
 {
     hx3918_ppg_timerout_flag = 1;
+    
 }
 void hx3918_ppg_timer_cfg(bool en)    //320ms
 {
@@ -231,13 +234,20 @@ void hx3918_ppg_timer_cfg(bool en)    //320ms
     {
         if(hx3918_ppg_timer == 0)
             hx3918_ppg_timer = Helios_Timer_init( (void* )hx3918_ppg_timerout_cb, NULL);
-        Helios_Timer_Start(hx3918_ppg_timer, 320, 1);
+        if(work_mode_flag == WEAR_MODE)
+        {
+            HX3918_LOG("work_mode_flag == WEAR_MODE\n\n\n\n");
+            Helios_Timer_Start(hx3918_ppg_timer, 3000, 1);
+            //Helios_Timer_Start(hx3918_ppg_timer, 320, 1);
+        }else
+            Helios_Timer_Start(hx3918_ppg_timer, 320, 1);
 
     }
     else
     {
         if(hx3918_ppg_timer != 0)
                {
+            HX3918_LOG("hx3918_ppg_timer_cfg Timer_Stop\n\n\n\n");
                        Helios_Timer_Stop(hx3918_ppg_timer);
                }
     }
@@ -547,11 +557,14 @@ bool hx3918_init(WORK_MODE_T mode)
         break;
 
     case FT_LEAK_LIGHT_MODE:
+        hx3918_hrs_disable();
+        HX3918_LOG("FT_LEAK_LIGHT_MODE1\n");
         if (!hx3918_chip_check())
         {
             AGC_LOG("hx3918 check id failed!\r\n");
             return false;
         }
+        HX3918_LOG("FT_LEAK_LIGHT_MODE2\n");
         hx3918_factroy_test(LEAK_LIGHT_TEST);
         break;
 
@@ -815,7 +828,7 @@ void hx3918_ppg_Int_handle(void)
     #if defined(INT_MODE)
         hx3918_agc_Int_handle();
     #endif
-        
+        //HX3918_LOG("hx3918_ppg_Int_handle\n\n\n\n");
 #ifdef SAR_ALG_LIB
                hx3918_report_prox_status();
 #endif
@@ -900,7 +913,7 @@ void hx3918_hrs_ppg_Int_handle(void)
         // gsen_fifo_z_send[ii] = gsen_fifo_z[32-*count+ii];
         
 #endif
-        //HX3918_LOG("ppg_Int_handle:%d %d %d %d %d %d\r\n", PPG_buf[ii],ir_buf[ii],gsen_fifo_x_send[ii],gsen_fifo_y_send[ii],gsen_fifo_z_send[ii]);
+        HX3918_LOG("ppg_Int_handle_da:%d %d %d %d %d %d \r\n", PPG_buf[ii],ir_buf[ii],gsen_fifo_x_send[ii],gsen_fifo_y_send[ii],gsen_fifo_z_send[ii],cal.led_cur);
     }
     hrs_wear_status = hx3918_hrs_get_wear_status();
        hrsresult.wearstatus = hrs_wear_status;
@@ -1019,7 +1032,7 @@ void hx3918_spo2_ppg_Int_handle(void)
 #endif
     for(ii=0; ii<*count; ii++)
     {
-         HX3918_LOG("%d/%d %d %d %d %d %d %d %d\r\n" ,1+ii,*count,\
+         HX3918_LOG("spo2_data : %d/%d %d %d %d %d %d %d %d\r\n" ,1+ii,*count,\
            red_buf[ii],ir_buf[ii],green_buf[ii],cal.red_idac,cal.ir_idac,cal.red_cur,cal.ir_cur);
     }
     spo2_wear_status = hx3918_spo2_get_wear_status();    
index 0b18834..8cc8374 100644 (file)
@@ -11,7 +11,9 @@
 //#include "tyhx_hrs_custom.h"
 #include "hx3918.h"
 #include "hx3918_check_touch.h"
+#ifdef SAR_ALG_LIB
 #include "hx3918_prox.h"
+#endif
 //#include "segger_rtt.h"
 
 hx3918_wear_msg_code_t hx3918_wear_status = MSG_NO_WEAR;
@@ -110,7 +112,9 @@ void hx3918_check_touch_init(void) //20200615 ericy ppg fs=25hz, phase3 conversi
     uint8_t force_LED_EN_cfg =0;
     uint8_t force_CKAFEINT_sel =0;
     uint8_t force_CKAFEINT_cfg =0;
-
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
     hx3918_write_reg(0X16, (ps3_enable<<3| ps2_enable<<2|ps1_enable<<1|ps0_enable));
     hx3918_write_reg(0X17, (ps3_osr<<6| ps2_osr<<4|ps1_osr<<2|ps0_osr));
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);
@@ -173,7 +177,9 @@ void hx3918_check_touch_init(void) //20200615 ericy ppg fs=25hz, phase3 conversi
     hx3918_delay(5);
     hx3918_write_reg(0X4d, 0X00);   //release
     hx3918_delay(5);
-       hx3918_prox_init();
+#ifdef SAR_ALG_LIB
+       hx3918_prox_reg_init();
+#endif
     read_fifo_first_flg = 1;
 }
 
@@ -200,15 +206,24 @@ SENSOR_ERROR_T hx3918_check_touch_enable(void)
     return SENSOR_OK;
 }
 
+extern int ir_wear ;//红外佩戴状态
 hx3918_wear_msg_code_t hx3918_check_touch(int32_t *ir_data, uint8_t data_len)
 {
     uint8_t ii;
-       TYHX_LOG("\r\n check touch  ir data:    ");
+               int16_t sar_data = 32767;
+#ifdef SAR_ALG_LIB
+       sar_data = hx90xx_get_prox_data();
+#endif
+    if (ir_data[0]>check_mode_wear_thre)
+        ir_wear = 1;
+    else
+        ir_wear = 0;
     for(ii=0; ii<data_len; ii++)
     {
-       TYHX_LOG("%d    ", ir_data[ii]);
-        if(ir_data[ii]>check_mode_wear_thre)
+       //HX3918_LOG("%d        \n", ir_data[ii]);
+        if(ir_data[ii]>check_mode_wear_thre&& sar_data > sar_wear_thres)
         {
+            
             if(notouch_cnt>0)
             {
                 notouch_cnt--;
@@ -223,7 +238,7 @@ hx3918_wear_msg_code_t hx3918_check_touch(int32_t *ir_data, uint8_t data_len)
                 touch_cnt++;
             }
         }
-        else if(ir_data[ii]<check_mode_unwear_thre)
+        else if(ir_data[ii]<check_mode_unwear_thre || sar_data < sar_unwear_thres)
         {
             if(touch_cnt>0)
             {
@@ -240,7 +255,16 @@ hx3918_wear_msg_code_t hx3918_check_touch(int32_t *ir_data, uint8_t data_len)
             }
         }
     }
-       TYHX_LOG("\r\n");
+
+               #ifdef SAR_ALG_LIB
+               if (hx3918_wear_status == MSG_NO_WEAR)
+               {
+                       hx3918_cali_with_ir(ir_data[0], check_mode_unwear_thre);
+               }
+               #endif
+               
+
+    HX3918_result_set_wear_status(hx3918_wear_status);
     return hx3918_wear_status;
 }
 
index 3f85370..2642888 100644 (file)
@@ -339,7 +339,6 @@ bool hx3918_chip_check_id(void)
 factory_result_t factory_reslts = {0,0,0};
 factory_result_t hx3918_factroy_test(uint32_t  test_mode)
 {
-    factory_result_t factory_reslts = {0,0,0};
     int32_t green_buffer[4] = {0,0,0,0};
     int32_t red_buffer[4] = {0,0,0,0};
     int32_t ir_buffer[4] = {0,0,0,0};
@@ -360,12 +359,12 @@ factory_result_t hx3918_factroy_test(uint32_t  test_mode)
 
     uint8_t ii = 0;
     uint8_t jj = 0;
-    
+    HX3918_LOG("hx3918_factroy_test1\n");
     if (hx3918_chip_check_id() == false)
     {
         return factory_reslts;
     }
-    
+    HX3918_LOG("hx3918_factroy_test2\n");
     switch(test_mode)
     {
         case LEAK_LIGHT_TEST:
@@ -385,7 +384,7 @@ factory_result_t hx3918_factroy_test(uint32_t  test_mode)
     {
         return factory_reslts;
     }
-
+    HX3918_LOG("hx3918_factroy_test3\n");
     for(ii=0; ii<4; ii++) //40ms read data
     {
         hx3918_delay(40);
@@ -423,7 +422,7 @@ factory_result_t hx3918_factroy_test(uint32_t  test_mode)
             }
         }
     }
-    
+    HX3918_LOG("hx3918_factroy_test4\n");
     if(test_mode == LEAK_LIGHT_TEST)
     {
         hx3918_write_reg(0X2a, 0x00);
index 620f242..45b2e5d 100644 (file)
@@ -122,6 +122,10 @@ void hx3918_hrs_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion r
     uint8_t force_CKAFEINT_sel =0;
     uint8_t force_CKAFEINT_cfg =0;
 
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
+
     hx3918_write_reg(0X16, (ps3_enable<<3| ps2_enable<<2|ps1_enable<<1|ps0_enable));
     hx3918_write_reg(0X17, (ps3_osr<<6| ps2_osr<<4|ps1_osr<<2|ps0_osr));
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);
@@ -418,7 +422,9 @@ void hx3918_hrs_cal_init(void) // 20200615 ericy afe cali online
     uint32_t prf_clk_num = 32000/sample_rate;        /*period in clk num, num = Fclk/fs */
     uint8_t thres_int =0;    //thres int enable
     uint8_t data_rdy_int =8;    //[3]:ps1_data2 [2]:ps1_data1 [1]:ps0_data2 [0]:ps0_data1
-
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);    // prf bit<7:0>6   default 0x00
     hx3918_write_reg(0X19, (uint8_t)(prf_clk_num>>8)); // prf bit<15:8>  default 0x03
     hx3918_write_reg(0x3d,0x00);     //bits<3:0> fifo data sel, 0000 = p1;0001= p2;0010=p3;0011=p4;bits<7> fifo enble
index bc221b1..3cf83f3 100644 (file)
@@ -161,7 +161,9 @@ void hx3918_hrv_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion r
     uint8_t sar_integ_num=8;
 
     uint8_t ch_num_sel=0;
-
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
     hx3918_write_reg(0X16, (ps3_enable<<3| ps2_enable<<2|ps1_enable<<1|ps0_enable));   //default 0x00
     hx3918_write_reg(0X17, (ps3_osr<<6| ps2_osr<<4|ps1_osr<<2|ps0_osr));       //default 0x00
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);    // prf bit<7:0>6   default 0x00
@@ -248,7 +250,6 @@ void hx3918_hrv_ppg_init(void) //20200615 ericy ppg fs=25hz, phase3 conversion r
     hx3918_delay(5);
     hx3918_write_reg(0X4d, 0X00);  //release
     hx3918_delay(5);
-       //hx3918_prox_init();
     read_fifo_first_flg = 1;
 }
 
@@ -453,6 +454,9 @@ void hx3918_hrv_cal_init(void) // 20200615 ericy afe cali online
     uint8_t thres_int =0;    //thres int enable
     uint8_t data_rdy_int =8;    //[3]:ps1_data2 [2]:ps1_data1 [1]:ps0_data2 [0]:ps0_data1
 
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);    // prf bit<7:0>6   default 0x00
     hx3918_write_reg(0X19, (uint8_t)(prf_clk_num>>8)); // prf bit<15:8>  default 0x03
 
@@ -631,6 +635,9 @@ void hx3918_hrv_low_power(void)
 
     uint8_t ch_num_sel=0;
 
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
     hx3918_write_reg(0X16, (ps3_enable<<3| ps2_enable<<2|ps1_enable<<1|ps0_enable));   //default 0x00
     hx3918_write_reg(0X17, (ps3_osr<<6| ps2_osr<<4|ps1_osr<<2|ps0_osr));       //default 0x00
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);    // prf bit<7:0>6   default 0x00
index 00a1547..0514fbf 100644 (file)
@@ -74,13 +74,21 @@ uint32_t fds_read[4] = {0}; //读出flash 存储数据的变量;
 uint32_t fds_write[4] = {0}; //写flash的变量, flash里面分别记录
 
 
-uint8_t data_updata_ready = 0;
+static uint8_t data_updata_ready = 0;
 uint8_t  is_factory_mode = 0;    // 产测模式, 用来读取整机对空时OFFSET和对空的nv_base值;
 uint8_t  is_offset_manual = 0;    // = 0自动校准模式, 用来读取整机对空时OFFSET和对空的nv_base值;
-static bool cap_wear = false;
-static bool cap_enable = false;
+static bool cap_enable = true;
 
 
+void hx3918_set_cap_enable(bool enable)
+{
+       cap_enable = enable;
+}
+
+void hx3918_set_cap_data_ready(uint8_t data_ready)
+{
+       data_updata_ready = data_ready;
+}
 
 /**
  * 读一组16bit 数据值
@@ -418,18 +426,23 @@ void hx3918_timerout_cb(void)
 * @param NULL
 */
 extern char is_open_sar ; //是否打开sar检测
-static int hx3918_timer = 0;
+
+extern int cap_wear ;//电容佩戴状态
+//static int hx3918_timer = 0;
 uint8_t hx3918_report_prox_status(void)
 {
     static uint8_t cap_wear_flag = 0;
     static int hx3918_report_prox_timer = 0;
     if(is_open_sar == 0)
-            return 1;
-    if(hx3918_timer== 0)
     {
-        hx3918_timer = Helios_Timer_init( (void* )hx3918_timerout_cb, NULL);
-        Helios_Timer_Start(hx3918_timer, 1500, 1);
-    }
+                       gdiff[0] = 32767;
+            return 1;
+       }
+    // if(hx3918_timer== 0)
+    // {
+    //     hx3918_timer = Helios_Timer_init( (void* )hx3918_timerout_cb, NULL);
+    //     Helios_Timer_Start(hx3918_timer, 1500, 1);
+    // }
     uint8_t ret = 0; 
     
     glp[0] = hx3918_read_diff_lp(WEAR_CH);
@@ -469,18 +482,19 @@ uint8_t hx3918_report_prox_status(void)
                                //hx3918_write_reg(0xa4,0x0f); // lp_out_delta_thres_ch1[11:8]
                                hx3918_write_reg(0x70,0x99); // RA_UP_ALP_1_0_CFG
                                data_updata_ready = 1;
-                               TYHX_LOG("data_updata_ready == 1\r\n");
+                               HX3918_LOG("data_updata_ready == 1\r\n");
                        }
                }
                if(gdiff[0]>sar_wear_thres)
             ret = 1;
         else
             ret = 0;
-        if(ret == 1)//
-            cap_wear_flag = 1;
-        if(cap_wear_flag == 0)
-            ret = 0;
-               TYHX_LOG("SARresult ready: %d, lp,%d,%d, bl,%d,%d, giff, %d,%d, offset, %d, nv_data,%d\r\n",data_updata_ready, glp[0],glp[1], gbl[0],gbl[1],gdiff[0],gdiff[1], nv_wear_offset[0],nv_base_data[0]);
+        // if(ret == 1)//
+        //     cap_wear_flag = 1;
+        // if(cap_wear_flag == 0)
+        //     ret = 1;
+        cap_wear = ret;
+               HX3918_LOG("SARresult ready: %d, lp,%d,%d, bl,%d,%d, giff, %d,%d, offset, %d, nv_data,%d\r\n",data_updata_ready, glp[0],glp[1], gbl[0],gbl[1],gdiff[0],gdiff[1], nv_wear_offset[0],nv_base_data[0]);
         return ret;
 }
 
@@ -490,13 +504,13 @@ int32_t hx90xx_get_prox_data(void)
        if (data_updata_ready == 1)
        {
                // 异常处理
-               if (nv_base_data[0] <-16384|| nv_base_data[0] > 25000 || hx3918_chip_id != PROX_CHIPID ||is_open_sar == 0)
+               if (nv_base_data[0] <-16384|| nv_base_data[0] > 25000 || hx3918_chip_id != PROX_CHIPID )
                {
                        gdiff[0] = 32767;
                }       
        }
        
-       if (is_offset_manual == 0)
+       if (is_offset_manual == 0 || cap_enable == false)
        {
                gdiff[0] = 32767;
        }
@@ -634,12 +648,8 @@ void hx3918_read_nv(void)
 */
 bool hx3918_prox_init(void)
 {
-#ifdef DEBUG_PPG_ONLY
-    return true;
-#endif
     int32_t i = 0;
     bool ret = false;
-    cap_wear = false;
     TYHX_LOG("[hx3918_prox_init]prox device_id is : 0x%.2x !\r\n", hx3918_chip_id);
     if (hx3918_chip_id != PROX_CHIPID)
     {
@@ -829,41 +839,6 @@ void hx3918_factory_cali_save_nv(void)
     //flash_fds_data_write(4);
 }
 
-/**
- * 最终用IR和PROX综合来判断佩戴结果
-* @param ppg_wear, PPG部分用IR检测的结果
-*/
-bool hx3918_get_wear_result(uint8_t ppg_wear)
-{
-    uint8_t prox_result;
-    // hx3918_prox_factory_hanging_cali();
-    // return true;
-    if(ppg_wear == 0)
-    {
-#ifdef DEBUG_PPG_ONLY
-        return false;
-#endif
-        return false;
-    }
-    else
-    {
-#ifdef DEBUG_PPG_ONLY
-        return true;
-#endif
-
-       prox_result = hx3918_report_prox_status();
-       //hx3918_prox_factory_hanging_cali();
-        HX3918_LOG("hx3918_get_wear_result:prox_result:%d",prox_result);
-        if(prox_result == 0)
-        {
-            return false;
-        }
-        else
-        {
-            return true;
-        }
-    }
-}
 #endif // SAR_ALG_LIB
 
 
index 25093eb..6069fdd 100644 (file)
@@ -54,7 +54,7 @@
 #define PROX_CHIPID         0x27
 
 
-#define NORMALWEARDIFF      18000                 //正常佩戴测试到的平均值, 宽松佩戴
+#define NORMALWEARDIFF      12000                 //正常佩戴测试到的平均值, 宽松佩戴
 
 #define WEAR_HIGH_DIFF         NORMALWEARDIFF/6
 #define WEAR_LOW_DIFF          NORMALWEARDIFF/8
@@ -67,8 +67,8 @@
 //#define FULL0625PF  //HX3918 full range cap = 0.625pf //一般不用这个, 这个满量程设置, 说明感应pad很小,
 //#define FULL125PF   //HX3918 full range cap = 1.25pf
 //#define FULL25PF      //HX3918 full range cap = 2.5pf, 一般PAD大小默认这个.
-#define FULL375PF   //HX3918 full range cap = 3.75 pf
-//#define FULL50PF    //HX3918 full range cap = 5.0 pf
+//#define FULL375PF   //HX3918 full range cap = 3.75 pf
+#define FULL50PF    //HX3918 full range cap = 5.0 pf
 
 //READ_DEVATION ,read offset 的偏差控制, 一个offset = 0.0586pf 按照不同量程, 对应的code, 留10%余量
 #ifdef FULL125PF 
@@ -127,11 +127,12 @@ void hx3918_prox_factory_hanging_cali(void);
 bool hx3918_prox_init(void);
 void hx3918_factory_cali_save_nv(void);
 int16_t hx3918_read_diff_lp(uint8_t chx_diff);
-bool hx3918_get_wear_result(uint8_t ppg_wear);
 bool hx3918_prox_factory_init(void);
 void hx_set_wear_detect_mode(uint8_t current_mode);
 int32_t hx90xx_get_prox_data(void);
 void hx3918_cali_with_ir(int32_t infrared_data, int32_t ir_thres);   
 void hx3918_update_min_nv_data(int16_t min_data);
+void hx3918_set_cap_enable(bool enable);
+void hx3918_set_cap_data_ready(uint8_t data_ready);
 
 #endif
index 86f0c00..03e0109 100644 (file)
@@ -122,6 +122,10 @@ void hx3918_spo2_ppg_init(void) //2023 3918
     uint8_t force_CKAFEINT_sel =0;
     uint8_t force_CKAFEINT_cfg =0;
 
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
+
     hx3918_write_reg(0X16, (ps3_enable<<3| ps2_enable<<2|ps1_enable<<1|ps0_enable));   //default 0x00
     hx3918_write_reg(0X17, (ps3_osr<<6| ps2_osr<<4|ps1_osr<<2|ps0_osr));       //default 0x00
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);    // prf bit<7:0>6   default 0x00
@@ -256,9 +260,7 @@ bool hx3918_spo2_check_wear(int32_t infrared_data)
     {
        
         spo2_wear_status = MSG_SPO2_WEAR;              
-               //TYHX_LOG("[hx3918_spo2_check_wear start] ir wear result = %d\r\n",spo2_wear_status);
-               spo2_wear_status = hx3918_get_wear_result(spo2_wear_status);
-               TYHX_LOG("[hx3918_spo2_check_wear end] final result = %d\r\n",spo2_wear_status);
+
         if(spo2_wear_status_pre != MSG_SPO2_WEAR)
         {
             AGC_LOG("hx3918_spo2_check_wear ir = %d\r\n", infrared_data);
@@ -464,7 +466,9 @@ void hx3918_spo2_cal_init(void) // 20200615 ericy afe cali offline
     uint32_t prf_clk_num = 32000/sample_rate;        /*period in clk num, num = Fclk/fs */
     uint8_t thres_int =0;    //thres int enable
     uint8_t data_rdy_int =8;    //[3]:ps1_data2 [2]:ps1_data1 [1]:ps0_data2 [0]:ps0_data1
-
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);    // prf bit<7:0>6   default 0x00
     hx3918_write_reg(0X19, (uint8_t)(prf_clk_num>>8)); // prf bit<15:8>  default 0x03
     hx3918_write_reg(0x3d,0x00);     //bits<3:0> fifo data sel, 0000 = p1;0001= p2;0010=p3;0011=p4;bits<7> fifo enble
@@ -554,7 +558,9 @@ void hx3918_spo2_low_power(void)
                                      64 = 512clk=128us ; 128= 1024clk=256us; 256= 2048clk=512us*/
     uint8_t ps3_led_on_time=64;    /* 0 = 32clk2=8us ; 8 = 64clk=16us; 16=128clk=32us ; 32 = 256clk=64us ;
                                      64 = 512clk=128us ; 128= 1024clk=256us; 256= 2048clk=512us*/
-
+#ifdef SAR_ALG_LIB
+               hx3918_set_cap_data_ready(0);
+#endif
     hx3918_write_reg(0X18, (uint8_t)prf_clk_num);    // prf bit<7:0>6   default 0x00
     hx3918_write_reg(0X19, (uint8_t)(prf_clk_num>>8)); // prf bit<11:8>  default 0x03
 
index 84c6c0b..3c73bd9 100644 (file)
@@ -285,7 +285,7 @@ unsigned int SC7A20_XYZ_Buf_tmp_len =0;
 unsigned char Gsensor_init_flag = 0;
 float x,y,z;
 bool SC7A20_INT_STATUS = true;
-unsigned int SC7A20_STATUS_COUNT = 0;
+unsigned int SC7A20_STATUS_COUNT = 3;
 unsigned int  SL_SC7A20_PEDO_KCAL_WRIST_SLEEP_SWAY_L_ALGO(void)
 {
 #if SL_Sensor_Algo_Release_Enable==0x00
index 8875b2b..a4aba30 100644 (file)
@@ -111,25 +111,27 @@ void HX3918_thread_do(void)
                        HX3918_close();
                        Helios_msleep(20);
                        HX3918_jobs_mode = NULL_MODE;
-               }else
-                       HX3918_restart();
+               }
+               // else
+               //      HX3918_restart();
                HX3918_test(HX3918_run_mode);
                HX3918_jobs_mode = HX3918_run_mode;
                HX3918_run_mode = NULL_MODE;
        }
+       if(hx3918_ppg_timerout_flag)
+       {
+               hx3918_ppg_Int_handle();
+               hx3918_ppg_timerout_flag = 0;
+       }
+       if(hx3918_agc_timerout_flag)
+       {
+               agc_timeout_handler(NULL);
+               hx3918_agc_timerout_flag =0;
+       }
        if(is_HX3918 == 1 && is_open_HX3918 == 1)//处理Hsensor定时数据
        {
 
-               if(hx3918_ppg_timerout_flag)
-               {
-                       hx3918_ppg_Int_handle();
-                       hx3918_ppg_timerout_flag = 0;
-               }
-               if(hx3918_agc_timerout_flag)
-               {
-                       agc_timeout_handler(NULL);
-                       hx3918_agc_timerout_flag =0;
-               }
+               
                if(timer_Gsensor_count>(500/TIMER_TIME_MS))//0.5秒定时,轮询更新Gsensor数据
                {
                        timer_Gsensor_count = 0;
@@ -147,22 +149,24 @@ void HX3918_thread_do(void)
                //      hx3918_ppg_Int_handle();
                //      hx3918_ppg_timerout_flag = 0;
                // }
-               wear_time++;
-               if(wear_time > 3)
-               {
-                       wear_time = 0;
+               // wear_time++;
+               // if(wear_time > 3)
+               // {
+               //      wear_time = 0;
                        
-                       //hx3918_prox_factory_hanging_cali();
-                       ir_wear = hx3918_get_wear_ppg_Int_handle();
-                       cap_wear = hx3918_report_prox_status();
+               //      //hx3918_prox_factory_hanging_cali();
                        
-                       HX3918_LOG("ir_wear:%d cap_wear%d\n",ir_wear,cap_wear);
-                       if(ir_wear == 1 && cap_wear==1)
-                       {
-                               s_HX3918_wear_status = 1;
-                       }else
-                               s_HX3918_wear_status = 0;
-               }
+               //      ir_wear = hx3918_get_wear_ppg_Int_handle();
+               //      #ifdef  SAR_ALG_LIB
+               //      cap_wear = hx3918_report_prox_status();
+               //      #endif
+               //      HX3918_LOG("ir_wear:%d cap_wear%d\n",ir_wear,cap_wear);
+               //      if(ir_wear == 1 && cap_wear==1)
+               //      {
+               //              s_HX3918_wear_status = 1;
+               //      }else
+               //              s_HX3918_wear_status = 0;
+               // }
                
                #if CONFIG_SC7A20
                if(ir_wear == 1 && cap_wear==1)
@@ -357,6 +361,9 @@ mp_obj_t mp_HX3918_init(mp_obj_t self_in)
                is_HX3918 = 1;
                // Helios_ExtInt_Init(self->irq,  &extint_struct1);//初始化中断
                // Helios_ExtInt_Enable(self->irq);//打开中断
+               #ifdef  SAR_ALG_LIB
+               hx3918_prox_init();
+               #endif
                hx3918_init(WEAR_MODE);//打开佩戴检测
                #if CONFIG_SC7A20
                if(Gsensor_init_flag == 0)//初始化Gsensor
@@ -407,7 +414,9 @@ void HX3918_test(uint32_t mode)
                // Helios_GPIO_SetLevel(g_HX3918->power, HELIOS_LVL_HIGH);
                // Helios_msleep(20);
                // hx3918_init(WEAR_MODE);//打开佩戴检测
+               #ifdef  SAR_ALG_LIB
                hx3918_prox_factory_hanging_cali();
+               #endif
        }
 
        
@@ -471,6 +480,9 @@ void HX3918_close(void)
        }
        is_open_HX3918 = 0;
        HX3918_restart();
+       #ifdef  SAR_ALG_LIB
+       hx3918_prox_init();
+       #endif
        hx3918_init(WEAR_MODE);//打开佩戴检测
 
 }
@@ -537,12 +549,22 @@ extern factory_result_t factory_reslts;
 // extern uint16_t prox_factory_offset0 ;
 // extern uint16_t prox_factory_offset1 ;
 // extern int16_t prox_factory_lp[2] ;
+#ifdef  SAR_ALG_LIB
 extern int16_t nv_wear_offset[2] ;    // 芯片产测校准的两个通道的OFFSET值, 值记录在fash里面
 extern int16_t nv_base_data[2];     // 芯片产测校准的两个通道的对空LP值, 值记录在flash里面
 //lp[0],bl[0],lp[1],bl[1],gdiff[0]
 extern int16_t glp[2] ;
 extern int16_t gbl[2];
 extern int16_t gdiff[2];
+#else
+ int16_t nv_wear_offset[2] ;    // 芯片产测校准的两个通道的OFFSET值, 值记录在fash里面
+ int16_t nv_base_data[2];     // 芯片产测校准的两个通道的对空LP值, 值记录在flash里面
+//lp[0],bl[0],lp[1],bl[1],gdiff[0]
+ int16_t glp[2] ;
+ int16_t gbl[2];
+ int16_t gdiff[2];
+#endif
+
 STATIC mp_obj_t mp_HX3918_get_test_data(mp_obj_t self_in)
 {
        mp_obj_t coordinate_list[15] = {mp_obj_new_int((int)factory_reslts.green_data_final),mp_obj_new_int((int)factory_reslts.red_data_final),mp_obj_new_int((int)factory_reslts.ir_data_final),
index 48e10c5..e9a232e 100644 (file)
@@ -303,6 +303,7 @@ class FactoryModeHsensorTestScreen(Screen):
         pass
 
     def HsensorCali_cb(self,e):
+        print("打开校准模式")
         self.Hsensor.set_sar(1)
         self.Hsensor.open_test(255) #打开校准模式
         utime.sleep_ms(500)
@@ -310,27 +311,32 @@ class FactoryModeHsensorTestScreen(Screen):
         self.hsensorTest_timer_count = 5
 
     def HsensorLeakLight_cb(self,e):
+        print("打开漏光检测")
         self.Hsensor.open_test(6) #打开漏光检测
         # utime.sleep_ms(500)
         # self.Hsensor.open_heart()
         self.hsensorTest_timer_count = 5
 
     def  hsensorTest_timer_cb(self,e):
+
         EventMesh.publish("system_sleep_rest")#防止黑屏 
         w_data = EventMesh.publish(constants.EVENT.GET_WEAR)#佩戴数据
         
         #print("FactoryModeHsensorTest{}".format(data))
         try:
             c_data = self.Hsensor.get_test_data()#校准数据和工厂数据
-            FactoryModeHsensorTest_label.set_text("   佩戴状态\n红外:{}活体:{}佩戴:{}\n{},{} \n{},{} \n{},{}\n校准数据:{},{},{},{}\n漏光数据:{},{},{}"
-                                                  .format(c_data[3],c_data[4],w_data,c_data[5],c_data[6],c_data[7],c_data[8],c_data[9],c_data[10],
-                                                          c_data[11],c_data[12],c_data[13],c_data[14],c_data[0],c_data[1],c_data[2],))
+            text_data = "   佩戴状态\n红外:{}活体:{}佩戴:{}\n{},{} \n{},{} \n{},{}\n校准数据:{},{},{},{}\n漏光数据:{},{},{}".format(
+                                                        c_data[3],c_data[4],w_data,c_data[5],c_data[6],c_data[7],c_data[8],c_data[9],c_data[10],
+                                                          c_data[11],c_data[12],c_data[13],c_data[14],c_data[0],c_data[1],c_data[2],)
+            FactoryModeHsensorTest_label.set_text(text_data)
+            #print("aaa:{},{},{}".format(c_data[9],c_data[13],c_data[14]))
         except Exception as e:
             FactoryModeHsensorTest_label.set_text("佩戴状态:\n{}".format(w_data))
         if(self.hsensorTest_timer_count != 0):
                 self.hsensorTest_timer_count -= 1
                 if self.hsensorTest_timer_count == 0:
-                    self.Hsensor.close()    
+                    self.Hsensor.close() 
+                    self.Hsensor.init();   
 
     def Close(self):
         self.hsensorTest_timer.stop()
@@ -513,6 +519,7 @@ class FactoryModeLocationScreen(Screen):
             gsv_data = msg[0][1].split("GSV")
             if len(rmc_data) >= 2 :
                 rmc_data = rmc_data[1:]
+                rmc_data = rmc_data[0].split("\r\n")
                 rmc_tmp = rmc_data[0].split(",")
                 if len(rmc_tmp) >= 2:
                     GNSS_DATA = GNSS_DATA + "{},{},{}\n".format(rmc_tmp[2],rmc_tmp[3],rmc_tmp[5])
index b546faf..ff9fa44 100644 (file)
@@ -501,25 +501,25 @@ class GPS(object):
         if self.__rmc_data and loc_status:
             if self.__nmea_statement_exist(self.__GGA) and not self.__gga_data:
                 self.__gga_data = self.__gps_match.GxGGA(self.__get_gps_data())
-            if self.__nmea_statement_exist(self.__GSV) and not self.__gsv_data:
-                self.__gsv_data = self.__gps_match.GxGSV(self.__get_gps_data())
-            if self.__nmea_statement_exist(self.__GSA) and not self.__gsa_data:
-                self.__gsa_data = self.__gps_match.GxGSA(self.__get_gps_data())
+            # if self.__nmea_statement_exist(self.__GSV) and not self.__gsv_data:
+            #     self.__gsv_data = self.__gps_match.GxGSV(self.__get_gps_data())
+            # if self.__nmea_statement_exist(self.__GSA) and not self.__gsa_data:
+            #     self.__gsa_data = self.__gps_match.GxGSA(self.__get_gps_data())
             if self.__nmea_statement_exist(self.__VTG) and not self.__vtg_data:
                 self.__vtg_data = self.__gps_match.GxVTG(self.__get_gps_data())
-            if self.__nmea_statement_exist(self.__GLL) and not self.__gll_data:
-                self.__gll_data = self.__gps_match.GxGLL(self.__get_gps_data())
+            # if self.__nmea_statement_exist(self.__GLL) and not self.__gll_data:
+            #     self.__gll_data = self.__gps_match.GxGLL(self.__get_gps_data())
 
             if self.__nmea_statement_exist(self.__GGA) and not self.__gga_data:
                 return False
-            if self.__nmea_statement_exist(self.__GSV) and not self.__gsv_data:
-                return False
-            if self.__nmea_statement_exist(self.__GSA) and not self.__gsa_data:
-                return False
-            if self.__nmea_statement_exist(self.__VTG) and not self.__vtg_data:
-                return False
-            if self.__nmea_statement_exist(self.__GLL) and not self.__gll_data:
-                return False
+            # if self.__nmea_statement_exist(self.__GSV) and not self.__gsv_data:
+            #     return False
+            # if self.__nmea_statement_exist(self.__GSA) and not self.__gsa_data:
+            #     return False
+            # if self.__nmea_statement_exist(self.__VTG) and not self.__vtg_data:
+            #     return False
+            # if self.__nmea_statement_exist(self.__GLL) and not self.__gll_data:
+            #     return False
             return True
 
         return False
index 12972a0..41f1e20 100644 (file)
@@ -55,6 +55,7 @@ def main_init():
     res = list(res)
     print('总ext空间:{} MB,剩余空间:{} MB'.format((((res[0] * res[2]) / 1024 / 1024)),((res[0] * res[3]) / 1024 / 1024)))
     #print("init1:{}".format(utime.localtime()))
+    EventMesh.txt_log("power on............\n")
     import EventMesh
     
     #print("init2:{}".format(utime.localtime()))
index f472c2f..ba13357 100644 (file)
@@ -22,6 +22,7 @@ import usys
 import audio
 from machine import I2C
 from Gsensor import SC7A20
+import pm
 try :
     from Hsensor import GH3018
 except Exception as e:
@@ -633,7 +634,7 @@ class DeviceInfoManager(Abstract):
         
         #self.battery_push_schedule = osTimer()
         self.check_battery_list = []
-        
+
         self.step = [0,0,0,0]
         self.timer_push=0
         self.timer_push_tmp=60
@@ -845,17 +846,21 @@ class DeviceInfoManager(Abstract):
             EventMesh.publish(constants.PROTOCOL.KA_SEND)
 
         """定时定位"""
+        #EventMesh.publish("set_upload_data",3*60)
         self.upload_time = EventMesh.publish("get_upload_data")
         #print("self.upload_time:{} math.fabs(time_tmp - self.UD_time):{}".format(self.upload_time,math.fabs(time_tmp - self.UD_time)))
         if self.upload_time != None :
             if  math.fabs(time_tmp - self.UD_time) > self.upload_time: #30分钟一次定位
                 self.UD_time = time_tmp
                 status_tmp = self.gsensor.get_status()#获取运动次数
+                #status_tmp = 4
                 #EventMesh.txt_log("status_count:{}".format(status_tmp))
                 if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and status_tmp > 3 :
                     EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
                     self.gsensor.clean_status()#清除运动次数
                 else : #关闭定位
+                    #EventMesh.txt_log("NO status")
+                    print("NO status")
                     EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
         EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
 
@@ -1788,6 +1793,7 @@ class DeviceInfoManager(Abstract):
 
 def wifiScan_cb(args):
         EventMesh.publish(constants.EVENT.WIFIINFO, args)
+        wifiScan.control(0)
 
 class LocationManager(Abstract):
 
@@ -1796,15 +1802,18 @@ class LocationManager(Abstract):
         self.match = GPSMatch()
         self.timer_read_GPS_info = osTimer()
         self.wifi_data = []
-        self.gps_data = []
+        self.gps_data  = {}
         self.cell_data = []
         self.location_timer_count = 0
         self.location_check_data_timer_count = 0
+        self.GGA_count = 0
+        self.RMC_A_count = 0
         self.location_type = 0 #定位类型,0:正常定位,有gps数据或60秒关闭;1:测试模式,只有发CLOSE_LOCATION消息才关闭
         self.location_flag = 0
         self.start_location_flag = 0
         self.location_thread_id  = 0
         self.location_queue = Queue(100)
+        self.lpm_fd = None
         #quecgnss.init()
         #quecgnss.gnssEnable(0)
     @staticmethod
@@ -1844,8 +1853,12 @@ class LocationManager(Abstract):
         return self.location_flag
     def start_location(self, event, msg):
         self.location_queue.put(msg)#测试类型入队
-        print("start_location:{}".format(msg))
+        self.gps_data = {}
+        self.wifi_data = []
+        self.cell_data = []
         self.location_timer_count = 0
+        self.GSV_sig_ok_count = 0
+        print("start_location:{}".format(msg))
         if( self.location_flag == 1):
             return
         self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
@@ -1879,11 +1892,12 @@ class LocationManager(Abstract):
 
     def WIFI_scan_open(self, event, msg):
         #print("WIFI_scan_open")
-        self.wifi_data = []
-        if wifiScan.support():
-            if wifiScan.getState() == False :
-                wifiScan.control(1)
-            wifiScan.setConfig(4, 2, 5, 6, 0)  #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
+        
+
+        if wifiScan.getState() == False :
+            self.wifi_data = []
+            wifiScan.control(1)
+            wifiScan.setCfgParam(6, 2, 5,  0)  #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
             wifiScan.setCallback(wifiScan_cb) #注册回调函数
             wifiScan.asyncStart()
             #print("wifiScan.asyncStart")
@@ -1903,6 +1917,8 @@ class LocationManager(Abstract):
 
     def Location_send(self, msg) :
         #print("Location_send1")
+        if self.location_queue.empty() == True:
+            return
         date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
         date = date[2:]
         #date = "180916,025723"
@@ -1935,6 +1951,7 @@ class LocationManager(Abstract):
             number = msg[0]["number"]
             precision = msg[0]["precision"]
             #date = msg[0]["date"]
+        
         #gsm 信号强度
         gsm_sig =  str((100//31)*EventMesh.publish("screen_get_sig"))
         # 电池电量百分比 
@@ -2013,36 +2030,48 @@ class LocationManager(Abstract):
         gnss_r_data = []
         self.GSV_sig_ok_count = 0
         self.GGA_count = 0
-
+        self.RMC_A_count = 0
+        if self.lpm_fd == None:
+            self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
+        pm.wakelock_lock(self.lpm_fd)
         print("location_thread:1")
         EventMesh.publish(constants.EVENT.GPSOPEN)
         print("location_thread:2")
         self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+        
         #utime.sleep_ms(1000)
         self.location_timer_count = 0
         #quecgnss.read(4096)#去掉第一次错误数据
         #EventMesh.txt_log("START_LOCATION")
+        # pm.autosleep(0)#唤醒
+        # pm.sclkEx_set(0, 1, 5)
         while self.location_flag == 1:
             try :   
                 
                 match_gga_data = []
                 #match_gsv_data = []
                 gnss_r_data = []
-                if self.location_check_data_timer_count > 3 :#3秒查一次基站数据和wifi数据
+                # if self.location_check_data_timer_count >= 3:
+                #     pm.autosleep(0)#唤醒
+                #     pm.sclkEx_set(0, 1, 5)
+                if self.location_check_data_timer_count >= 5 :#5秒查一次基站数据和wifi数据
                     self.location_check_data_timer_count = 0
                     #print(self.location_timer_count)
                     #GSV_dict= {}
                     
                     #检查GNSS数据
-                    if (self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
+                    if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
+                        
                         self.gps.__gps_nmea_data_clean()
                         #gnss_r_data = [0,1]
                         gnss_r_data = quecgnss.read(4096)
-                        print("location gnss_r_data:\n{}".format(gnss_r_data[1].decode()))
+                        #EventMesh.txt_log("gps Datalen:{}".format(gnss_r_data[0]))
+                        print("location gnss_r_data:len{}\n{}".format(gnss_r_data[0],gnss_r_data[1].decode()))
                         #print("gnss_r_data len:{}".format(gnss_r_data[0]))
                         if gnss_r_data[0] > 0 : #有数据
                             tmp_ok_count = 0
-                            gsv_data = gnss_r_data[1].split("GSV")           
+                            gsv_data = gnss_r_data[1].split("GSV")
+                                      
                             if len(gsv_data) >= 2 :  
                                 gsv_data = gsv_data[1:]
                                 for i in range(len(gsv_data)) :
@@ -2050,8 +2079,7 @@ class LocationManager(Abstract):
                                     gsv_tmp = gsv_data[i].split(",")
                                     if len(gsv_tmp) < 7 :
                                         break
-                                    #self.GGA_count = int(gsv_tmp[3])
-                                    
+                                     
                                     gsv_tmp = gsv_tmp[4:]
                                     #print("gsv_tmp:{}".format(gsv_tmp))
                                     for i in range(len(gsv_tmp)) :
@@ -2060,7 +2088,7 @@ class LocationManager(Abstract):
                                             try:
                                                 #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
                                                 if gsv_tmp[i+3] != "" :
-                                                    if int(gsv_tmp[i+3])>=25:
+                                                    if int(gsv_tmp[i+3])>=20:
                                                         tmp_ok_count +=1    
                                             except Exception as e:
                                                 usys.print_exception(e)
@@ -2070,61 +2098,93 @@ class LocationManager(Abstract):
                                 
                                 if(tmp_ok_count > self.GSV_sig_ok_count ):
                                     self.GSV_sig_ok_count = tmp_ok_count
-                                #print("GGA_count:{} GSV_sig_ok_coun:{}".format(self.GGA_count,self.GSV_sig_ok_count))
-                            match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
+                            
 
-                            if len(match_gga_data) > 8:
-                                #print(match_gga_data)
-                                self.GGA_count = int(match_gga_data[7]) #可用微信
+                            # if len(match_gga_data) > 8:
+                            #     #print(match_gga_data)
+                            #     if(match_gga_data[7] ):
+                            #         gga_count_tmp = int(match_gga_data[7]) #可用卫星
+                            #         if(gga_count_tmp > self.GGA_count):
+                            #             self.GGA_count = gga_count_tmp
                             print("GGA_count:{} GSV_sig_ok_coun:{} ".format(self.GGA_count,self.GSV_sig_ok_count))
-                            #match_gsv_data = self.match.GxGSV(gnss_r_data[1]).split(",")
+                            
                             match_rmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
+                             
                             #print("match_rmc_data:\n{}".format(match_rmc_data))
                             if len (match_rmc_data)>3: #有rmc数据
                                 if match_rmc_data[2] == 'A':
                                     
-                                    #match_rmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
-                                    match_vtg_data = self.match.GxVTG(gnss_r_data[1]).split(",")
-                                    if len(match_gga_data) < 8:
-                                        match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
-                                    gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
-                                    latitude_tmp = str(gps_data_tmp[1]).split(".")
-                                    if len(match_vtg_data)>5 and len(match_gga_data)>5 and len(latitude_tmp) >= 2:
+                                    if  self.gps.__check_gps_valid(gnss_r_data[1].decode()): #数据齐全 :
+                                        
+                                        #print("hhhhhh:{}\n\n".format(self.gps.__gsv_data))
+                                        match_vtg_data = self.gps.__vtg_data.split(",")#self.match.GxVTG(gnss_r_data[1]).split(",")
+                                        match_gga_data = self.gps.__gga_data.split(",")#self.match.GxGGA(gnss_r_data[1]).split(",")
+                                        #match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
                                         
+                                        EventMesh.txt_log("GGA:{}".format(match_gga_data))
+                                        # EventMesh.txt_log("VTG:{}".format(match_vtg_data))
+                                        # EventMesh.txt_log("RMC:{}".format(match_rmc_data)) 
+                                        # EventMesh.txt_log("timer:{} ok_count:{} count:{}\n".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))   
                                         print("LOCATION_ok :time:{}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n".format(self.location_timer_count))
-                                        gps_date = "%s,%s"%(match_rmc_data[9],match_rmc_data[1][:6])
-                                        latitude = "0"
-                                        if len(latitude_tmp[1])>=5:
-                                            latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:5])
-                                        latitude = "%s,%s"%(latitude,match_rmc_data[4] )
+                                        gps_date = "%s,%s"%(match_rmc_data[9],match_rmc_data[1][:6])#日期
+                                        gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
+                                        latitude = "0,N" #纬度
+                                        latitude_tmp = str(gps_data_tmp[1]).split(".")
+                                        if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
+                                            latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
+                                            latitude = "%s,%s"%(latitude,match_rmc_data[4] )
+
+                                        longitude = "0,E"#经度
                                         longitude_tmp = str(gps_data_tmp[0]).split(".")
-                                        longitude = "0"
-                                        if len(longitude_tmp[1])>=5:
+                                        if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
                                             longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
-                                        longitude = "%s,%s"%(longitude,match_rmc_data[6] ) #match_rmc_data[6] + str(gnss_r_data[1])
+                                            longitude = "%s,%s"%(longitude,match_rmc_data[6] ) #match_rmc_data[6] + str(gnss_r_data[1])
+                                        
+                                        high = "0"#高度
                                         high = str(gps_data_tmp[2])
+                                        number = "0"#可用卫星
+                                        precision = "5.8"#精度
+                                        if len(match_gga_data)>5 :
+                                            if match_gga_data[7]:
+                                                number = match_gga_data[7]
+                                            if match_gga_data[8]:
+                                                precision = match_gga_data[8]
+                                        direction = "249.5" #方向
+                                        speed = '0.00'    #速度    
+                                        if(len(match_vtg_data)>5 ):
+                                            if match_vtg_data[1]:
+                                                direction =  match_vtg_data[1]
+                                            if match_vtg_data[7]:    
+                                                speed =  match_vtg_data[7]
                                         self.gps_data = {
                                             "latitude": latitude,
                                             "longitude": longitude,
                                             "high": high,
-                                            "direction": match_vtg_data[1],
-                                            "speed": match_vtg_data[5],
-                                            "number": match_gga_data[7], 
+                                            "direction": direction,
+                                            "speed": speed,
+                                            "number": number, 
                                             "date":  gps_date,
-                                            "precision":  match_gga_data[8]
+                                            "precision":  precision
                                         }
-                    #检查wifi数据
-                    if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
-                        EventMesh.publish(constants.EVENT.WIFISCANOPEN)
-                
-                    #检查基站数据
-                    if self.cell_data == []:   
-                        data_tmp = net.getCellInfo()
-                        if(len(data_tmp)>=2):
-                            for cell in data_tmp:
-                                if cell and cell[0][0] == 0 and len(cell[0]) > 1:
-                                    self.cell_data = cell
-                                    break
+                                    else :
+                                        EventMesh.txt_log("gps数据不全")
+                        else :
+                            EventMesh.txt_log("gps 无数据")
+
+
+
+                #检查wifi数据
+                if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
+                    EventMesh.publish(constants.EVENT.WIFISCANOPEN)
+            
+                #检查基站数据
+                if self.cell_data == []:   
+                    data_tmp = net.getCellInfo()
+                    if(len(data_tmp)>=2):
+                        for cell in data_tmp:
+                            if cell and cell[0][0] == 0 and len(cell[0]) > 1:
+                                self.cell_data = cell
+                                break
 
                 if self.location_type == 1: #测试模式
                     self.location_timer_count = 0
@@ -2138,19 +2198,26 @@ class LocationManager(Abstract):
                         
 
                 elif self.location_type == 0: #正常模式     
-                    if self.gps_data  != {} or self.location_timer_count > 170: #or( self.wifi_data != [] and self.cell_data != []): 
+                    if self.gps_data  != {} or self.location_timer_count > 100: #or( self.wifi_data != [] and self.cell_data != []): 
+                        if self.location_queue.empty() == False:#有定位队列
+                            EventMesh.txt_log("LOCATION:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
                         upload_time = EventMesh.publish("get_upload_data")
-                        if upload_time > 200 or self.gps_data  != {} : #定位间隔小于3分钟且定位失败不关闭gps,不影响无信号判断
-                            EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
-                        EventMesh.txt_log("CLOSE_LOCATION:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
-                        self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
                         
-                    if  self.GGA_count < 3 and self.wifi_data  and self.cell_data  and self.location_timer_count > 20 and self.location_timer_count < 30: #超过20秒且有效卫星个数少于3
-                        EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位    
-                        EventMesh.txt_log("GGA_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+                            
                         self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                        #if upload_time > 200  : 
+                        EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+                        # else:   #定位间隔小于3分钟不关闭gps,不影响无信号判断
+                        #     self.location_timer_count = 0
+                        #     self.GSV_sig_ok_count = 0
+                            
                         
-                    if self.GSV_sig_ok_count < 3 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 40: #超过40秒且信号大于30的不足3个
+                    # if  (self.GGA_count < 3 and self.GSV_sig_ok_count < 2) and self.wifi_data  and self.cell_data  and self.location_timer_count > 30 and self.location_timer_count < 40: #超过20秒且有效卫星个数少于3
+                    #     EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位    
+                    #     EventMesh.txt_log("GGA_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+                    #     self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                        
+                    if self.GSV_sig_ok_count <= 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过40秒且信号大于30的不足3个
                         EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位   
                         EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
                         self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
@@ -2169,12 +2236,17 @@ class LocationManager(Abstract):
                 #print("location_thread:ERROR:{}".format(usys.print_exception(e)))
                 print("self.gps_data{},self.wifi_data{},self.cell_data{}".format(self.gps_data,self.wifi_data,self.cell_data))
                 #self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
-                #EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
-            utime.sleep_ms(1000)
+                EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
+            utime.sleep_ms(500)
         self.timer_read_GPS_info.stop()
         self.gps.power_switch(0)
         wifiScan.control(0)
-        
+        # if EventMesh.publish("get_lcd_state" ) == 0:#休眠的时候,恢复休眠
+        #     pm.autosleep(1)
+        #     pm.sclkEx_set(1, 1, 5)
+        if self.lpm_fd != None:
+            pm.wakelock_unlock(self.lpm_fd)
+        #pm.delete_wakelock(lpm_fd)
         print("CLOSE_LOCATION")
         #EventMesh.txt_log("CLOSE_LOCATION")
 
index e54fd94..79b173f 100644 (file)
@@ -25,7 +25,7 @@ import usys
 def server_init(server_type = None):
     #服务器选择1,防走丢,2大锤,3三基同创,4童信,5云米,6荣为
     if server_type == None:
-        server_type = 1
+        server_type = 4
     #print("server_init:server_type:{}".format(server_type))
     d_server_addr = "api.xcloudtech.com"
     d_server_port = 9000
@@ -552,7 +552,7 @@ class UD_ProtoCol(ProtoCol):
         
         MD5_SIGN = self.pack_MD5_head(MD5_head_data)
         data = "[%s%s]"%(str(MD5_SIGN),send_data)
-        print("UD:data:{}".format(data))
+        #EventMesh.txt_log("{}".format(data))
         # wt_data = EventMesh.publish("get_weather_data")
         # # #如果没有天气数据,则获取天气数据
         # if wt_data != None or wt_data[0] == None :
index d2a559e..3a29d48 100644 (file)
Binary files a/2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/images/DBG.7z and b/2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/images/DBG.7z differ
index fa044e0..9dc0f14 100644 (file)
Binary files a/2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/images/firmware_base_release_pack.zip and b/2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/images/firmware_base_release_pack.zip differ
index 3dc3b0f..b3a54e6 100644 (file)
Binary files a/2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/libraries/libHeliosAPI.lib and b/2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/libraries/libHeliosAPI.lib differ
index 9884587..ed5a990 100644 (file)
Binary files a/2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/libraries/ql_common_api.lib and b/2.sdk/project/K5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_ALIPAY/libraries/ql_common_api.lib differ