D15:
authordxy15521469561 <1731678236@qq.com>
Thu, 18 Jan 2024 11:46:03 +0000 (19:46 +0800)
committerdxy15521469561 <1731678236@qq.com>
Thu, 18 Jan 2024 11:46:03 +0000 (19:46 +0800)
视频通话未完

35 files changed:
2.sdk/Helios_SDK/components/juphoon/lib/libjrtc.a
2.sdk/Helios_SDK/services/microPython/ports/quectel/core/source/modVideoCall_juphoon.c
2.sdk/project/C06S/sdk/services/microPython/ports/quectel/core/appWechat.py
2.sdk/project/D10/audio.bin
2.sdk/project/D10/audio/R_NO_SET_VIDOE.mp3 [new file with mode: 0644]
2.sdk/project/D10/audio/R_VIDEO_ANSWER.mp3 [new file with mode: 0644]
2.sdk/project/D10/audio/R_VIDEO_ANSWERING.mp3 [new file with mode: 0644]
2.sdk/project/D10/audio/R_VIDEO_CALL_CONNECT.mp3 [new file with mode: 0644]
2.sdk/project/D10/audio/R_VIDEO_CALL_ENDING.mp3 [new file with mode: 0644]
2.sdk/project/D10/audio/R_VIDEO_CALL_IN.mp3 [new file with mode: 0644]
2.sdk/project/D10/audio/R_VIDEO_VOICE_IN.mp3 [new file with mode: 0644]
2.sdk/project/D10/audio/R_VIDEO_WAITING.mp3 [new file with mode: 0644]
2.sdk/project/D10/list.json
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/EventMesh.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/Makefile
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/btn_device_ec800m_d15.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/constants.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/led_d15.py [new file with mode: 0644]
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/main_init.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr_d15.py [new file with mode: 0644]
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/protocol.py
2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/sleep_test.py
2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/autoconf.h
2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/config.in
2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/config/config.mk
2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack.zip
2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/libraries/libHeliosAPI.lib
2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/libraries/ql_common_api.lib
2.sdk/project/D10/usr/static/audio.bin
2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/appWechat.py
2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/protocol.py
2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/ui.py
2.sdk/project/K01/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack.zip

index cb42772..6885f14 100644 (file)
Binary files a/2.sdk/Helios_SDK/components/juphoon/lib/libjrtc.a and b/2.sdk/Helios_SDK/components/juphoon/lib/libjrtc.a differ
index 19c0fe8..daf2f01 100644 (file)
@@ -22,7 +22,7 @@
 #include "jrtc0.h"
 #include "callbackdeal.h"
 #include "helios_debug.h"
-
+#include "helios_datacall.h"
 #include "autoconf.h"
 #include "lvgl.h"
 #include <helios_lcd.h>
@@ -116,6 +116,15 @@ typedef struct _jrtc_obj_t
     mp_obj_base_t base;   //定义的对象结构体要包含该成员
 }jrtc_obj_t;
 
+// 定义MsgQ数据类型
+typedef struct _jrtc_open_msg_t
+{
+    struct jrtc_image_t *video;
+    struct jrtc_image_t *camera;
+    char *ticket;
+    char *roomid;
+}jrtc_open_msg_t;
+
 const mp_obj_type_t jrtc_type;
 
 /** 当前的版本号 */
@@ -200,47 +209,47 @@ STATIC mp_obj_t remove_img(void) {
 STATIC MP_DEFINE_CONST_FUN_OBJ_0(remove_img_obj, remove_img);
 
 void jrtc_handle(void * argv) {
-    uint8_t open_state = 0;
+    jrtc_open_msg_t open_msg = {0};
     int ret = -1;
     while (1) {
-        ret = Helios_MsgQ_Get(int_happen_q, (void *)&open_state, sizeof(uint8_t), HELIOS_WAIT_FOREVER);
+        ret = Helios_MsgQ_Get(int_happen_q, (void *)&open_msg, sizeof(jrtc_open_msg_t), HELIOS_WAIT_FOREVER);
                if (ret != 0)
                {
                        HELIOS_JRTC_LOG("interrupt handle thread failed to get queue\n");
                        continue;
                }
-        if (open_state == 1) {
-            if (test == NULL) {
-                test = jrtc_open(roomid_temp, ticket_temp, &recieve, &send);
-                if (test == NULL) {
-                    HELIOS_JRTC_LOG("jrtc_open fail\n");
-                    continue;
-                }
-                jrtc_activate(test, JRTC_AUDIO|JRTC_CAMERA);
-                // 等待对方视频对讲结束
-                while(jrtc_state(test) != JRTC_CLOSED)
-                {
-                    struct jrtc_image_t* image;
-                    image = &recieve;
-                    if (image->get != image->put) {
-                        update_display(image->data, image->width, image->height);
-                        image->get = image->put;
-                    }
-                    Helios_msleep(20);
-                }
+        HELIOS_JRTC_LOG("roomid:%s, ticket:%s, video:%x, camera:%x.", open_msg.roomid, open_msg.ticket, open_msg.video, open_msg.camera);
 
-                // 判断是对方挂断,产生回调
-                st_CallBack_jrtc *jrtc_int = malloc(sizeof(st_CallBack_jrtc));
-                if(NULL != jrtc_int) { 
-                    jrtc_int->result = 0;
-                    jrtc_int->callback = cb;
-                    qpy_send_msg_to_callback_deal_thread(CALLBACK_TYPE_ID_JRTC, jrtc_int);
+        if (test == NULL) {
+            test = jrtc_open(open_msg.roomid, open_msg.ticket, open_msg.video, open_msg.camera);
+            if (test == NULL) {
+                HELIOS_JRTC_LOG("jrtc_open fail\n");
+                continue;
+            }
+            jrtc_activate(test, JRTC_AUDIO|JRTC_CAMERA);
+            // 等待对方视频对讲结束
+            while(jrtc_state(test) != JRTC_CLOSED)
+            {
+                struct jrtc_image_t* image;
+                image = &recieve;
+                if (image->get != image->put) {
+                    update_display(image->data, image->width, image->height);
+                    image->get = image->put;
                 }
+                Helios_msleep(20);
             }
-            else {
-                HELIOS_JRTC_LOG("jrtc has opened\n");
+
+            // 判断是对方挂断,产生回调
+            st_CallBack_jrtc *jrtc_int = malloc(sizeof(st_CallBack_jrtc));
+            if(NULL != jrtc_int) { 
+                jrtc_int->result = 0;
+                jrtc_int->callback = cb;
+                qpy_send_msg_to_callback_deal_thread(CALLBACK_TYPE_ID_JRTC, jrtc_int);
             }
-        } 
+        }
+        else {
+            HELIOS_JRTC_LOG("jrtc has opened\n");
+        }
     }
 }
 
@@ -258,7 +267,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_set_callback_obj, set_callback);
 STATIC mp_obj_t mp_jrtc_init(void) {
     Helios_ThreadAttr attr = {0};
        if (int_happen_q == 0) {
-               int_happen_q = Helios_MsgQ_Create(1, sizeof(uint8_t));
+               int_happen_q = Helios_MsgQ_Create(1, sizeof(jrtc_open_msg_t));
        }
        if(int_handle_task_id == 0)
        {
@@ -330,6 +339,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_jrtc_set_rotate_obj, mp_jrtc_set_rotate);
 STATIC mp_obj_t mp_jrtc_open (size_t n_args, const mp_obj_t *args, mp_map_t *kw_args)
 {
     int ret = 0;
+    jrtc_open_msg_t open_msg = {0};
 
     HELIOS_JRTC_LOG("mp_jrtc_open execute!!!");
     if(protect != 1){
@@ -353,19 +363,37 @@ STATIC mp_obj_t mp_jrtc_open (size_t n_args, const mp_obj_t *args, mp_map_t *kw_
     
     size_t len;
     mp_obj_t *elem;
-    mp_obj_get_array(vals[ARG_send].u_obj, &len, &elem);
-    recieve.fps = mp_obj_get_int(elem[0]);
-    recieve.kbps = mp_obj_get_int(elem[1]);
-    recieve.width = mp_obj_get_int(elem[2]);
-    recieve.height= mp_obj_get_int(elem[3]);
     mp_obj_get_array(vals[ARG_recieve].u_obj, &len, &elem);
-    send.fps = mp_obj_get_int(elem[0]);
-    send.kbps = mp_obj_get_int(elem[1]);
-    send.width = mp_obj_get_int(elem[2]);
-    send.height = mp_obj_get_int(elem[3]);
+    HELIOS_JRTC_LOG("mp_jrtc_open recieve para len:%d", len);
+    if (len == 4) {
+        recieve.fps = mp_obj_get_int(elem[0]);
+        recieve.kbps = mp_obj_get_int(elem[1]);
+        recieve.width = mp_obj_get_int(elem[2]);
+        recieve.height= mp_obj_get_int(elem[3]);
+        open_msg.video = &recieve;
+    } else if (len == 0){
+        open_msg.video = NULL;
+    } else {
+        mp_raise_ValueError("video parameter num error\n");
+    }
+    
+    mp_obj_get_array(vals[ARG_send].u_obj, &len, &elem);
+    HELIOS_JRTC_LOG("mp_jrtc_open send para len:%d", len);
+    if (len == 4) {
+        send.fps = mp_obj_get_int(elem[0]);
+        send.kbps = mp_obj_get_int(elem[1]);
+        send.width = mp_obj_get_int(elem[2]);
+        send.height = mp_obj_get_int(elem[3]);
+        open_msg.camera = &send;
+    } else if (len == 0){
+        open_msg.camera = NULL;
+    } else {
+        mp_raise_ValueError("video parameter num error\n");
+    }
+    open_msg.ticket = ticket_temp;
+    open_msg.roomid = roomid_temp;
 
-    uint8_t int_happen = 1;
-    Helios_MsgQ_Put(int_happen_q, (const void *)&int_happen, sizeof(uint8_t), HELIOS_NO_WAIT);
+    Helios_MsgQ_Put(int_happen_q, (const void *)&open_msg, sizeof(jrtc_open_msg_t), HELIOS_NO_WAIT);
     
     return mp_obj_new_int(ret);
 }
@@ -375,7 +403,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mp_jrtc_open_obj, 4, mp_jrtc_open);
 STATIC mp_obj_t mp_jrtc_close (mp_obj_t err_j)
 {
     int ret = 0;
-    HELIOS_JRTC_LOG("mp_jrtc_close execute!!!");
     int err = mp_obj_get_int(err_j);
     if((err != 0) && (err != 1) && (err != 64) && (err != 71) && (err != 90) && (err != 104) && 
     (err != 101) && (err != 111) && (err != 128) && (err != 129) && (err != 130) && (err != 131) && 
index 3d4c3d0..2d8eb83 100644 (file)
@@ -126,7 +126,7 @@ class WechatScreen(Screen):
         #         self.wechat_recode_list = ujson.load(fd)#读取每一个amr音频文件的时长ui_setting.py
 
         self.record_test = audio.Record()
-        self.record_test.gain(4,12)
+        self.record_test.gain_set(4,12)
         self.aud = audio.Audio(0)
         # self.aud.set_pa(Pin.GPIO29)
 
index 7ff1a31..e02e6af 100644 (file)
Binary files a/2.sdk/project/D10/audio.bin and b/2.sdk/project/D10/audio.bin differ
diff --git a/2.sdk/project/D10/audio/R_NO_SET_VIDOE.mp3 b/2.sdk/project/D10/audio/R_NO_SET_VIDOE.mp3
new file mode 100644 (file)
index 0000000..18e2189
Binary files /dev/null and b/2.sdk/project/D10/audio/R_NO_SET_VIDOE.mp3 differ
diff --git a/2.sdk/project/D10/audio/R_VIDEO_ANSWER.mp3 b/2.sdk/project/D10/audio/R_VIDEO_ANSWER.mp3
new file mode 100644 (file)
index 0000000..842b893
Binary files /dev/null and b/2.sdk/project/D10/audio/R_VIDEO_ANSWER.mp3 differ
diff --git a/2.sdk/project/D10/audio/R_VIDEO_ANSWERING.mp3 b/2.sdk/project/D10/audio/R_VIDEO_ANSWERING.mp3
new file mode 100644 (file)
index 0000000..516900b
Binary files /dev/null and b/2.sdk/project/D10/audio/R_VIDEO_ANSWERING.mp3 differ
diff --git a/2.sdk/project/D10/audio/R_VIDEO_CALL_CONNECT.mp3 b/2.sdk/project/D10/audio/R_VIDEO_CALL_CONNECT.mp3
new file mode 100644 (file)
index 0000000..7448c91
Binary files /dev/null and b/2.sdk/project/D10/audio/R_VIDEO_CALL_CONNECT.mp3 differ
diff --git a/2.sdk/project/D10/audio/R_VIDEO_CALL_ENDING.mp3 b/2.sdk/project/D10/audio/R_VIDEO_CALL_ENDING.mp3
new file mode 100644 (file)
index 0000000..2e25bb7
Binary files /dev/null and b/2.sdk/project/D10/audio/R_VIDEO_CALL_ENDING.mp3 differ
diff --git a/2.sdk/project/D10/audio/R_VIDEO_CALL_IN.mp3 b/2.sdk/project/D10/audio/R_VIDEO_CALL_IN.mp3
new file mode 100644 (file)
index 0000000..b42d2b8
Binary files /dev/null and b/2.sdk/project/D10/audio/R_VIDEO_CALL_IN.mp3 differ
diff --git a/2.sdk/project/D10/audio/R_VIDEO_VOICE_IN.mp3 b/2.sdk/project/D10/audio/R_VIDEO_VOICE_IN.mp3
new file mode 100644 (file)
index 0000000..1539195
Binary files /dev/null and b/2.sdk/project/D10/audio/R_VIDEO_VOICE_IN.mp3 differ
diff --git a/2.sdk/project/D10/audio/R_VIDEO_WAITING.mp3 b/2.sdk/project/D10/audio/R_VIDEO_WAITING.mp3
new file mode 100644 (file)
index 0000000..7afc11e
Binary files /dev/null and b/2.sdk/project/D10/audio/R_VIDEO_WAITING.mp3 differ
index 4a528de..ca60502 100644 (file)
@@ -1 +1 @@
-['audio_find_haixiu', 'R_ALARM_NEW', 'R_BLOOD_SUGAR', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_CUR_BATTERY_LEVEL', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HOME_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_RESET_ALARM', 'R_RESET_END_ALARM', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SLEEP_ALARM', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_WAKEUP_ALARM', 'R_WECHAT_RECV']
\ No newline at end of file
+['audio_find_haixiu', 'R_ALARM_NEW', 'R_BLOOD_SUGAR', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_CUR_BATTERY_LEVEL', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HOME_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SET_VIDOE', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_RESET_ALARM', 'R_RESET_END_ALARM', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SLEEP_ALARM', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_VIDEO_ANSWER', 'R_VIDEO_ANSWERING', 'R_VIDEO_CALL_CONNECT', 'R_VIDEO_CALL_ENDING', 'R_VIDEO_CALL_IN', 'R_VIDEO_VOICE_IN', 'R_VIDEO_WAITING', 'R_WAKEUP_ALARM', 'R_WECHAT_RECV']
\ No newline at end of file
index 193be7b..53ab6c8 100644 (file)
@@ -3,11 +3,14 @@ import usys
 import versions
 import ql_fs
 
-model = "D15_"
+model = "D15"
+
+project = "D15"
+
 
 # model = "G10W_DT_YBX_"
 
-softversion = "{}{}".format(model,versions.Version)
+softversion = "{}_{}".format(project,versions.Version)
 builTime = "{}".format(versions.Build_Time)
 
 class EventStore(object):
@@ -105,7 +108,7 @@ debug_Log = 1
 def debug_log(*data):
     if debug_Log != 0 :
         print(data)
-Txt_Log = 1
+Txt_Log = 0
 def txt_log(data):
     if Txt_Log != 0 :
         print(data)
index 702b211..1d26bac 100644 (file)
@@ -356,6 +356,8 @@ SRC_QSTR += \
                        source/modGsensor_SC7A20.c \
                        source/modHsensor.c \
                        source/modHsensor_GH3018.c \
+                       source/modVideoCall.c \
+                       source/modVideoCall_juphoon.c \
                        source/modHsensor_HX3918.c \
                        source/modrsa.c \
                        source/utils_crc32.c \
@@ -667,7 +669,9 @@ endif
 ifeq ($(CONFIG_SC7A20), y)
 INC += -I$(ROOT)/components/SC7A20
 endif
-
+ifeq ($(CONFIG_juphoon), y)
+INC += -I$(ROOT)/components/juphoon
+endif
 ifeq ($(CONFIG_POC_BND), y)
 INC += -I$(ROOT)/components/poc
 INC += -I$(ROOT)/components/poc/bnd/inc
@@ -961,6 +965,8 @@ frozen_mpy_list =   $(BUILD)/_boot.mpy \
                                        $(BUILD)/versions.mpy \
                                        $(BUILD)/led.mpy \
                                        $(BUILD)/btn_device_ec800m_d15.mpy \
+                                       $(BUILD)/led_d15.mpy \
+                                       $(BUILD)/mgr_d15.mpy \
 
 endif
 
index 922a2f8..2663a0b 100644 (file)
@@ -19,16 +19,8 @@ import _thread
 import usys
 import sms
 from Gsensor import SC7A20
-if EventMesh.model == "D10_" :
-    # motor_pin = Pin(Pin.GPIO20, Pin.OUT, Pin.PULL_PD, 0)
-    motor_pin = 1
-    def open_motor():
-        motor_pin.write(1)
-
-    def close_motor():
-        motor_pin.write(0)
-
-    audio_buf = ['audio_find_haixiu', 'R_ALARM_NEW', 'R_BLOOD_SUGAR', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_CUR_BATTERY_LEVEL', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HOME_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_RESET_ALARM', 'R_RESET_END_ALARM', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SLEEP_ALARM', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_WAKEUP_ALARM', 'R_WECHAT_RECV']
+if EventMesh.model == "D10" :
+    audio_buf = ['audio_find_haixiu', 'R_ALARM_NEW', 'R_BLOOD_SUGAR', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_CUR_BATTERY_LEVEL', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HOME_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SET_VIDOE', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_RESET_ALARM', 'R_RESET_END_ALARM', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SLEEP_ALARM', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_VIDEO_ANSWER', 'R_VIDEO_ANSWERING', 'R_VIDEO_CALL_CONNECT', 'R_VIDEO_CALL_ENDING', 'R_VIDEO_CALL_IN', 'R_VIDEO_VOICE_IN', 'R_VIDEO_WAITING', 'R_WAKEUP_ALARM', 'R_WECHAT_RECV']
 
 
     class intervManager(Abstract):
@@ -99,7 +91,7 @@ if EventMesh.model == "D10_" :
             EventMesh.subscribe("publish_message_event_audio",self.publish_message_event_audio)
 
             self.record_test = audio.Record()
-            self.record_test.gain(4,12)
+            self.record_test.gain_set(4,12)
 
             self.timeSecond = 0
             self.wechat_show = 0
@@ -600,7 +592,8 @@ if EventMesh.model == "D10_" :
             #播报当前时间
 
         def recv_wechat_audio(self,event,str_data):#接收微聊语音播放
-            if self.call_state == 0 and self.fall_flag == 0:
+            wechat_state = EventMesh.publish("get_wechat_state")
+            if self.call_state == 0 and self.fall_flag == 0 and wechat_state == 0: 
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_WECHAT_RECV"))
                 EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
 
@@ -1197,14 +1190,14 @@ if EventMesh.model == "D10_" :
             pass
         def app_restart_cb(self,*argc):
             Power.powerRestart()
-            
+
         def open_power_on(self, event, msg): #msg 1 开机 2 关机 3 重启  4恢复出厂设置 5静音关机
             EventMesh.publish("close_timer_all")#
             if msg == 1:
                 EventMesh.publish("close_hr_sop2")#
                 # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_POWER_OFF_1"))
                 # EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件('U:/static/audio.bin',1,1,str_data)
-                self.pwk_timer1.start(3000,0,self.power_on_audio_cb)
+                self.pwk_timer1.start(1000,0,self.power_on_audio_cb)
                 
             elif msg == 2:
                 flag = EventMesh.publish("get_call_state") 
index cc5abad..4c58f7a 100644 (file)
@@ -12,7 +12,7 @@ import ql_fs
 import ujson
 import voiceCall
 from misc import Power
-from led import red_green_light,green_light_fast,led_mode,open_led_red,close_led_red,open_led_green,close_led_green,close_led_white
+
 from machine import RTC
 from queue import Queue
 import _thread
@@ -20,11 +20,14 @@ import usys
 import sms
 from Gsensor import SC7A20
 NEW_ENABLE = 0 #1代表旧的按键功能定义 0代表新的按键功能定义
-if EventMesh.model == "D15_" :
-    
+if EventMesh.model == "D15" :
+    from led_d15 import red_green_light,green_light_fast,led_mode,open_led_red,close_led_red,open_led_green,close_led_green,close_led_white
+
     motor_pin = Pin(Pin.GPIO20, Pin.OUT, Pin.PULL_PD, 0)
 
-    audio_buf = ['audio_find_haixiu', 'R_ALARM_NEW', 'R_BLOOD_SUGAR', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_CUR_BATTERY_LEVEL', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HOME_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_RESET_ALARM', 'R_RESET_END_ALARM', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SLEEP_ALARM', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_WAKEUP_ALARM', 'R_WECHAT_RECV']
+    audio_buf = ['audio_find_haixiu', 'R_ALARM_NEW', 'R_BLOOD_SUGAR', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_CUR_BATTERY_LEVEL', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HOME_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SET_VIDOE', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_RESET_ALARM', 'R_RESET_END_ALARM', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SLEEP_ALARM', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_VIDEO_ANSWER', 'R_VIDEO_ANSWERING', 'R_VIDEO_CALL_CONNECT', 'R_VIDEO_CALL_ENDING', 'R_VIDEO_CALL_IN', 'R_VIDEO_VOICE_IN', 'R_VIDEO_WAITING', 'R_WAKEUP_ALARM', 'R_WECHAT_RECV']
+
+
     class call:
         CALL_OUT = 1
         CALL_IN = 2
@@ -99,7 +102,7 @@ if EventMesh.model == "D15_" :
             EventMesh.subscribe("publish_message_event_audio",self.publish_message_event_audio)
 
             self.record_test = audio.Record()
-            self.record_test.gain(4,12)
+            self.record_test.gain_set(4,12)
 
             self.timeSecond = 0
             self.wechat_show = 0
@@ -127,6 +130,11 @@ if EventMesh.model == "D15_" :
             self.hr_auto = 0
 
             self.temp_auto = 0
+
+            self.video_count = 0
+            self.video_call_state = 0#视频通话拨进来还是拨出去的状态 1代表是正在拨进或者拨出去
+
+            self.video_call_in_mode = 0 #0是语音 1是视频通话
             
             check_txt = ql_fs.path_exists("/usr/static/storage_file/wechat_record.json")
             if check_txt == True :
@@ -189,6 +197,23 @@ if EventMesh.model == "D15_" :
 
             EventMesh.subscribe("close_audio_play", self.close_audio_play)#关闭音频
 
+            #视频通话
+            EventMesh.subscribe("video_call_in_event", self.video_call_in_event)#视频通话拨进中
+            EventMesh.subscribe("video_call_out_cb", self.video_call_out_cb)#视频通话拨进中
+            EventMesh.subscribe("video_waite_timer_cb", self.video_waite_timer_cb)#对方正在接听中
+
+            EventMesh.subscribe("video_answer_timer_cb", self.video_answer_timer_cb)#对方已接听
+            EventMesh.subscribe("video_answer_mode_timer_cb", self.video_answer_mode_timer_cb)#对方已接听
+
+            EventMesh.subscribe("video_reject_timer_cb", self.video_reject_timer_cb)#对方未接通挂断了
+
+            
+
+            EventMesh.subscribe("get_video_in_out_state", self.get_video_in_out_state)#获取拨进还是拨出的状态
+            EventMesh.subscribe("set_video_in_out_state", self.set_video_in_out_state)#清除标识
+            
+            
+            
 
             EventMesh.subscribe("start_wechat_record", self.start_wechat_record)#手表开始录音
             EventMesh.subscribe("send_wechat_record", self.send_wechat_record)#发送微聊语音文件to app
@@ -256,7 +281,13 @@ if EventMesh.model == "D15_" :
             self.interInfo_queue.put(msg)
 
         def publish_call_event_cb(self, *args, **kwargs):#拨打电话
-            EventMesh.publish("publish_message_event_interInfo",{"func":self.call_timer_cb,"data":0})  
+            EventMesh.publish("publish_message_event_interInfo",{"func":self.call_timer_cb,"data":0})
+
+        def publish_video_in_event_cb(self, *args, **kwargs):#视频通话拨入
+            EventMesh.publish("publish_message_event_interInfo",{"func":self.video_in_timer_cb,"data":0})  
+
+        def publish_video_out_event_cb(self, *args, **kwargs):#拨打视频通话
+            EventMesh.publish("publish_message_event_interInfo",{"func":self.video_out_timer_cb,"data":0})  
 
         def publish_resatrt_down_event_cb(self, *args, **kwargs):#重启设备
             EventMesh.publish("publish_message_event_interInfo",{"func":self.powe_resatrt_down_fun,"data":0})  
@@ -297,14 +328,16 @@ if EventMesh.model == "D15_" :
 
         def reset_alarm_event(self,args,msg):#该休息了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count = 0
                 self.alarm_timer1.start(2000, 1, self.publish_reset_alarm_ring_event_cb)
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_RESET_ALARM"))
                 EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
         def reset_alarm_event_cb(self,args):#该休息了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count += 1
                 if self.alarm_count >= 3:
                     self.alarm_count = 0
@@ -318,7 +351,8 @@ if EventMesh.model == "D15_" :
 
         def reset_end_alarm_event(self,args,msg):#休息结束了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count = 0
                 self.alarm_timer1.start(2000, 1, self.reset_end_alarm_event_cb)
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_RESET_END_ALARM"))
@@ -326,7 +360,8 @@ if EventMesh.model == "D15_" :
         
         def reset_end_alarm_event_cb(self,args):#休息结束了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count += 1
                 if self.alarm_count >= 3:
                     self.alarm_count = 0
@@ -340,14 +375,16 @@ if EventMesh.model == "D15_" :
         
         def sleep_alarm_event(self,args,msg):#该睡觉了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count = 0
                 self.alarm_timer1.start(2000, 1, self.publish_sleep_alarm_ring_event_cb)
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_SLEEP_ALARM"))
                 EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
         def sleep_alarm_event_cb(self,args):#该睡觉了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count += 1
                 if self.alarm_count >= 3:
                     self.alarm_count = 0
@@ -362,7 +399,8 @@ if EventMesh.model == "D15_" :
 
         def home_alarm_event(self,args,msg):#该回家了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count = 0
                 self.alarm_timer1.start(2000, 1, self.publish_home_ring_event_cb)
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HOME_ALARM"))
@@ -370,7 +408,8 @@ if EventMesh.model == "D15_" :
         
         def home_alarm_event_cb(self,args):#该回家了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count += 1
                 if self.alarm_count >= 3:
                     self.alarm_count = 0
@@ -384,7 +423,8 @@ if EventMesh.model == "D15_" :
         
         def wakeup_alarm_event(self,args,msg):#该起床了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count = 0
                 self.alarm_timer1.start(2000, 1, self.publish_wakeup_ring_event_cb)
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_WAKEUP_ALARM"))
@@ -392,7 +432,8 @@ if EventMesh.model == "D15_" :
         
         def wakeup_alarm_event_cb(self,args):#该起床了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count += 1
                 if self.alarm_count >= 3:
                     self.alarm_count = 0
@@ -407,7 +448,8 @@ if EventMesh.model == "D15_" :
 
         def medicine_alarm_event(self,args,msg):#该吃药了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count = 0
                 self.alarm_timer1.start(2000, 1, self.publish_medicine_ring_event_cb)
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_MEDICINE_ALARM"))
@@ -415,7 +457,8 @@ if EventMesh.model == "D15_" :
 
         def medicine_alarm_event_cb(self,args):#该吃药了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count += 1
                 if self.alarm_count >= 3:
                     self.alarm_count = 0
@@ -429,7 +472,8 @@ if EventMesh.model == "D15_" :
 
         def drink_alarm_event(self,args,msg):#该喝水了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count = 0
                 self.alarm_timer1.start(2000, 1, self.publish_drink_ring_event_cb)
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_DRINK_ALARM"))
@@ -439,7 +483,8 @@ if EventMesh.model == "D15_" :
 
         def drink_alarm_event_cb(self,args):#该喝水了
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 self.alarm_count += 1# 1 2 
                 if self.alarm_count >= 3:
                     self.alarm_count = 0
@@ -454,7 +499,8 @@ if EventMesh.model == "D15_" :
         def falldown_alarm_event(self,args,msg):#跌倒报警启动中提示
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
             wechat_state = EventMesh.publish("get_wechat_state")
-            if flag == 0 and wechat_state == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and wechat_state == 0 and video_state == 0:
                 EventMesh.publish("close_timer_all")#
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_FALL_ALARM"))
                 self.time_count = 0
@@ -466,7 +512,9 @@ if EventMesh.model == "D15_" :
 
         def falldown_alarm_cb(self,*args):
             wechat_state = EventMesh.publish("get_wechat_state")
-            if self.call_state == 0 and wechat_state == 0:
+            flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and self.call_state == 0 and wechat_state == 0 and video_state == 0:
                 self.time_count+=1
                 if self.time_count >= 5:
                     self.time_count = 0
@@ -508,7 +556,8 @@ if EventMesh.model == "D15_" :
                     return
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
             wechat_state = EventMesh.publish("get_wechat_state")
-            if flag == 0 and wechat_state == 0 and self.fall_flag == 0: 
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0: 
                 EventMesh.publish("close_timer_all")#
                 self.find_state = 1
                 self.FIND_timer_count = 0
@@ -529,7 +578,8 @@ if EventMesh.model == "D15_" :
         def FIND_timer_cb(self, data):
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
             wechat_state = EventMesh.publish("get_wechat_state")
-            if flag == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 if self.find_state == 1:
                     # EventMesh.debug_log("self.FIND_timer_count:{}".format(self.FIND_timer_count))
                     str_data = 'mp3files={}.mp3'.format(audio_buf.index("audio_find_haixiu"))
@@ -556,7 +606,8 @@ if EventMesh.model == "D15_" :
                     return
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
             wechat_state = EventMesh.publish("get_wechat_state")
-            if flag == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0 :
                 EventMesh.publish("close_timer_all")#
                 self.alarm_state = 1
                 self.alarm_timer_count = 0
@@ -577,7 +628,8 @@ if EventMesh.model == "D15_" :
         def Alarm_timer_cb(self, data):
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
             wechat_state = EventMesh.publish("get_wechat_state")
-            if flag == 0 and wechat_state == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0:
                 if self.alarm_state == 1:
                     # EventMesh.debug_log("self.alarm_timer_count:{}".format(self.alarm_timer_count))
                     str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_ALARM_NEW"))
@@ -597,11 +649,18 @@ if EventMesh.model == "D15_" :
             EventMesh.publish("close_audio_play")#强制关闭音频文件播放
             EventMesh.publish("STOP_FIND_WATCH")#停止查找设备
             EventMesh.publish("STOP_ALARM_RING")#停止闹钟响铃
+            if NEW_ENABLE == 0:#新的按键功能定义
+                video_state = EventMesh.publish("get_video_state")
+                if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                    EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                    return
             EventMesh.publish("play_cur_time_event")#播报当前时间
             #播报当前时间
 
         def recv_wechat_audio(self,event,str_data):#接收微聊语音播放
-            if self.call_state == 0 and self.fall_flag == 0:
+            wechat_state = EventMesh.publish("get_wechat_state")
+            video_state = EventMesh.publish("get_video_state")
+            if self.call_state == 0 and self.fall_flag == 0 and wechat_state == 0 and self.fall_flag == 0 and video_state == 0: 
                 str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_WECHAT_RECV"))
                 EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
 
@@ -636,6 +695,7 @@ if EventMesh.model == "D15_" :
             if power_off != None:
                 if power_off == 1:
                     return
+            self.aud.stopPlayStream()
             self.aud.montage_play('U:/static/audio.bin',1,data[1],data[0])
             # EventMesh.debug_log("play_audio_file end",data[0],data[1])#路径 str_data[1] 是否需要被打断
             
@@ -678,9 +738,8 @@ if EventMesh.model == "D15_" :
             if power_off != None:
                 if power_off == 1:
                     return
+                
             self.aud.stopPlayStream()
-            
-            
             self.timer.stop()
             self.sos_timer2.stop()
             self.sos_timer1.stop()
@@ -703,6 +762,186 @@ if EventMesh.model == "D15_" :
         def set_call_state(self, event, msg): #
             self.call_state = msg
 
+
+        def video_call_in_event(self, event, msg):#视频通话拨入
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取关机标识
+            if open_power != None and power_off != None:
+                if open_power == 0 or power_off == 1:
+                    return
+            EventMesh.publish("close_timer_all")#
+            EventMesh.publish("close_wechat_btn_timer")#
+            EventMesh.publish("set_led_time_arg",[1,2,10*2,led_mode.FLASH_LIGHT_RED,10,5,led_mode.VIDEO_MEASURE_MODE])#測量成功
+            self.video_call_state = 1
+            self.video_count=0
+            self.video_call_in_mode = msg
+            EventMesh.publish("clear_video_timer_state")
+            EventMesh.publish("set_app_dev_end_state")
+            print("voice in!!!",msg,self.video_call_in_mode)
+            if self.video_call_in_mode == 0:
+                
+                self.timer.start(2000, 1, self.publish_video_in_event_cb)
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_VOICE_IN"))
+                EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件
+            else:
+                self.timer.start(2000, 1, self.publish_video_in_event_cb)
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_CALL_IN"))
+                EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件
+            # EventMesh.publish("play_audio_file",str_data)#获取播放音频文件('U:/static/audio.bin',1,1,str_data)
+        def video_in_timer_cb(self,data):
+
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取关机标识
+            if open_power != None and power_off != None:
+                if open_power == 0 or power_off == 1:
+                    return
+            
+            video_state = EventMesh.publish("get_video_state")
+            print("video_state",video_state)
+            
+            self.video_count+=1
+            if self.video_count >= 30 or video_state == 0:#一分钟挂断视频通话
+                EventMesh.publish("video_reject_cb",None)#挂断视频通话
+                self.video_call_state = 0
+                self.video_count=0
+                return
+            if video_state != 6 or self.video_call_state == 0:#视频电话呼入
+                EventMesh.publish("stop_led_timer")#设置参数
+                EventMesh.publish("close_timer_all")#
+                return
+            if self.video_call_in_mode == 0:
+                EventMesh.publish("set_led_time_arg",[1,2,10*2,led_mode.FLASH_LIGHT_RED,10,5,led_mode.VIDEO_MEASURE_MODE])#測量成功
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_VOICE_IN"))
+                EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+            else:
+                EventMesh.publish("set_led_time_arg",[1,2,10*2,led_mode.FLASH_LIGHT_RED,10,5,led_mode.VIDEO_MEASURE_MODE])#測量成功
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_CALL_IN"))
+                EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+
+        def video_call_out_cb(self, event, msg):#视频通话拨出
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取关机标识
+            if open_power != None and power_off != None:
+                if open_power == 0 or power_off == 1:
+                    return
+            EventMesh.publish("close_timer_all")#
+            EventMesh.publish("close_wechat_btn_timer")#
+            # EventMesh.publish("set_led_time_arg",[1,2,10*10,led_mode.FLASH_LIGHT_RED,10,5,led_mode.OTHER_MEASURE_MODE])#測量成功
+            EventMesh.publish("clear_video_timer_state")
+            EventMesh.publish("set_app_dev_end_state")
+            if msg != None:
+                self.video_count = 0
+                self.video_call_state = 1
+                self.timer.start(2000, 1, self.publish_video_out_event_cb)
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_WAITING"))
+                EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件
+            else:
+                self.video_call_state = 0
+                self.video_count=0
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_NO_SET_VIDOE"))
+                EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件
+                pass
+        
+        def video_out_timer_cb(self,data):
+
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取关机标识
+            if open_power != None and power_off != None:
+                if open_power == 0 or power_off == 1 :
+                    return
+            video_state = EventMesh.publish("get_video_state")#加入中
+            print("video_out_timer_cb video_state",video_state)
+            
+            self.video_count+=1
+            if self.video_count >= 30 or video_state == 0:#40s挂断视频通话 对方无响应
+                EventMesh.publish("video_reject_cb",None)#挂断视频通话
+                self.video_call_state = 0
+                self.video_count = 0
+                
+                return
+            if video_state == 4 or self.video_call_state == 0 :#视频电话呼出 如果接通了就不需要了
+                self.video_call_state = 0
+                self.video_count=0
+                print("video calling")
+                EventMesh.publish("stop_led_timer")#设置参数
+                EventMesh.publish("close_timer_all")#
+                return
+            
+
+            # EventMesh.publish("set_led_time_arg",[1,2,10*10,led_mode.FLASH_LIGHT_RED,10,5,led_mode.OTHER_MEASURE_MODE])#測量成功
+            str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_WAITING"))
+            EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+
+        def video_waite_timer_cb(self,event,msg):#等待对方接听音频
+            print("video_waite_timer_cb 1")
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取关机标识
+            if open_power != None and power_off != None:
+                if open_power == 0 or power_off == 1 or self.video_call_state == 0:
+                    return
+            play_state = EventMesh.publish("get_audio_state")
+            if play_state == 0:
+                print("video_waite_timer_cb 2")
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_WAITING"))
+                EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+        
+        
+        def video_answer_timer_cb(self,event,msg):#对方已接听可正常通话了
+            print("video_answer_timer_cb 1")
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取关机标识
+            if open_power != None and power_off != None:
+                if open_power == 0 or power_off == 1  or self.video_call_state == 0 :
+                    return
+            print("video_answer_timer_cb 2")
+            str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_ANSWER"))
+            EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+
+        def video_answer_mode_timer_cb(self,event,msg):#1:#正在等待对方接听中,请稍候   2:#对方已接听可正常通话 3:#正在接听中
+            # print("video_answer_mode_timer_cb 1",msg)
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取关机标识
+            if open_power != None and power_off != None:
+                if open_power == 0 or power_off == 1:
+                    return
+            # print("video_answer_mode_timer_cb 2",msg)
+            if msg == 1:#正在等待对方接听中,请稍候
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_WAITING"))
+                EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+            elif msg == 2:#已接通
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_ANSWER"))
+                EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+                pass
+            elif msg == 3:#正在连接中...
+                if EventMesh.publish("get_audio_state") == 0:
+                    str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_ANSWERING"))
+                    EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+                pass
+            elif msg == 4:#对方已挂断...
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_CALL_ENDING"))
+                EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+                pass
+            elif msg == 5:#对方已挂断或网络不好
+                print("video_reject_timer_cb",msg)
+                str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_VIDEO_CALL_CONNECT"))#播放音频
+                EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件
+
+        def video_reject_timer_cb(self,event,msg):#网络不好或者对方未接通挂断了
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取关机标识
+            if open_power != None and power_off != None:
+                if open_power == 0 or power_off == 1:
+                    return
+           
+        
+        def get_video_in_out_state(self,event,msg):
+            return self.video_call_state
+        
+        def set_video_in_out_state(self,event,msg):
+            self.video_call_state = msg
+        
+
+
         def dialin_call_event(self, event, msg):
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             if open_power != None:
@@ -712,6 +951,11 @@ if EventMesh.model == "D15_" :
             if power_off != None:
                 if power_off == 1:
                     return
+            video_state = EventMesh.publish("get_video_state")
+            if video_state != 0:#视频电话呼入
+                self.call_state = 0
+                voiceCall.callEnd()
+                return
             EventMesh.publish("close_timer_all")#
             EventMesh.publish("close_wechat_btn_timer")#
             EventMesh.publish("set_led_time_arg",[1,2,10*10,led_mode.FLASH_LIGHT_RED,10,5,led_mode.OTHER_MEASURE_MODE])#測量成功
@@ -729,6 +973,13 @@ if EventMesh.model == "D15_" :
             if power_off != None:
                 if power_off == 1:
                     return
+            video_state = EventMesh.publish("get_video_state")
+            if video_state != 0:#视频电话呼入
+                self.call_state = 0
+                voiceCall.callEnd()
+                EventMesh.publish("stop_led_timer")#设置参数
+                EventMesh.publish("close_timer_all")#
+                return
             if self.call_state != 2:
                 EventMesh.publish("stop_led_timer")#设置参数
                 EventMesh.publish("close_timer_all")#
@@ -760,6 +1011,10 @@ if EventMesh.model == "D15_" :
                     str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_SOS_ALERT"))
                     EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件
                     self.timer1.start(2000, 0, self.time_out_phone)
+
+        
+
+
                     
         
         def time_out_phone(self, msg):#电话拨出去
@@ -831,6 +1086,9 @@ if EventMesh.model == "D15_" :
 
         def play_cur_step_event(self, event, msg): #msg 1 播放当前步数
             flag = EventMesh.publish("get_call_state") 
+            video_state = EventMesh.publish("get_video_state")
+            if video_state != 0:
+                return
             if flag == 0:#电话通话中 或者呼叫中挂断中断
                 if self.fall_flag == 0:
                     EventMesh.publish("close_timer_all")#
@@ -1087,6 +1345,7 @@ if EventMesh.model == "D15_" :
                 if power_off == 1:
                     return
             flag = EventMesh.publish("get_call_state") 
+            video_state = EventMesh.publish("get_video_state")
             get_hr_state = EventMesh.publish("get_hr_state")
             get_spo2_state = EventMesh.publish("get_spo2_state")
             get_bp_state  = EventMesh.publish("get_bp_state")
@@ -1133,7 +1392,7 @@ if EventMesh.model == "D15_" :
                 self.usbState = msg
                 str_buf = [1,1,10,led_mode.LONG_LIGHT_RED,4,2,led_mode.CHARGE_IN_MODE]
                 EventMesh.publish("set_led_time_arg",str_buf)#
-                if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+                if flag == 0 and self.fall_flag == 0 and video_state == 0:#电话通话中 或者呼叫中挂断中断
                     EventMesh.publish("close_timer_all")#
                     self.aud.stop()
                     self.aud.play(1,1,'U:/static/R_CHARGE_IN.mp3')
@@ -1142,13 +1401,13 @@ if EventMesh.model == "D15_" :
                 EventMesh.debug_log("charge R_CHARGE_IN")
                 
                 
-            elif msg == 2:
+            elif msg == 2 or msg == 0:
                 self.usbState = msg
                 EventMesh.publish("stop_led_timer")#设置参数
                 # EventMesh.publish("set_led_time_arg",[0,1000,1,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.CHARGE_OUT_MODE])#測量成功
                 EventMesh.publish("set_led_time_arg",[1,1,0,led_mode.FLASH_LIGHT_GREEN,4,4,led_mode.CHARGE_OUT_MODE])#測量成功
                 EventMesh.debug_log("charge R_CHARGE_OUT")
-                if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+                if flag == 0 and self.fall_flag == 0 and video_state == 0:#电话通话中 或者呼叫中挂断中断
                     EventMesh.publish("close_timer_all")#
                     self.aud.stop()
                     self.aud.play(1,1,'U:/static/R_CHARGE_OUT.mp3')
@@ -1162,7 +1421,7 @@ if EventMesh.model == "D15_" :
                 EventMesh.debug_log("charge full")
                 str_buf = [1,1,10,led_mode.LONG_LIGHT_GREEN,4,2,led_mode.CHARGE_FULL_MODE]
                 EventMesh.publish("set_led_time_arg",str_buf)#
-                # if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+                # if flag == 0 and self.fall_flag == 0 and video_state == 0:#电话通话中 或者呼叫中挂断中断
                 #     EventMesh.publish("close_timer_all")#
                 #     str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_CHARGE_FULL"))
                 #     EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data)
@@ -1207,7 +1466,7 @@ if EventMesh.model == "D15_" :
                 EventMesh.publish("close_hr_sop2")#
                 # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_POWER_OFF_1"))
                 # EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件('U:/static/audio.bin',1,1,str_data)
-                self.pwk_timer1.start(3000,0,self.power_on_audio_cb)
+                self.pwk_timer1.start(1000,0,self.power_on_audio_cb)
                 
             elif msg == 2:
                 flag = EventMesh.publish("get_call_state") 
@@ -1453,9 +1712,10 @@ if EventMesh.model == "D15_" :
             
             
         def play_temp_value(self, event, msg): #播放体温数值
+            video_state = EventMesh.publish("get_video_state")
             flag = EventMesh.publish("get_call_state") 
             if msg != None:
-                if flag == 0 and self.fall_flag == 0:
+                if flag == 0 and self.fall_flag == 0 and video_state == 0:
                     EventMesh.publish("close_timer_all")#
                     if msg > 0:
                         # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_OK"))
@@ -1516,9 +1776,10 @@ if EventMesh.model == "D15_" :
                             
 
         def play_hr_value(self, event, msg): #播放心率数值
+            video_state = EventMesh.publish("get_video_state")
             flag = EventMesh.publish("get_call_state") 
             if msg != None:
-                if flag == 0 and self.fall_flag == 0:
+                if flag == 0 and self.fall_flag == 0 and video_state == 0:
                     EventMesh.publish("close_timer_all")#
                     if msg >= 50:
                         # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_OK"))
@@ -1535,9 +1796,10 @@ if EventMesh.model == "D15_" :
                     EventMesh.publish("set_hr_blood_led",3)#测量异常
 
         def play_hr_fun(self,argc):#播放心率测试值
+            video_state = EventMesh.publish("get_video_state")
             flag = EventMesh.publish("get_call_state") 
             
-            if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+            if flag == 0 and self.fall_flag == 0 and video_state == 0:#电话通话中 或者呼叫中挂断中断
                 EventMesh.publish("close_timer_all")#
                 data = self.hr_value
                 if data > 220:
@@ -1578,7 +1840,8 @@ if EventMesh.model == "D15_" :
 
         def play_battery_level_value(self, event, msg): #播放当前电量
             flag = EventMesh.publish("get_call_state") 
-            if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and self.fall_flag == 0 and video_state == 0 :#电话通话中 或者呼叫中挂断中断
                 EventMesh.publish("close_timer_all")#
                 battery = EventMesh.publish("screen_get_battery")
                 print("cur level",battery)
@@ -1609,9 +1872,10 @@ if EventMesh.model == "D15_" :
 
 
         def play_sugar_value(self, event, msg): #播放血糖数值
+            video_state = EventMesh.publish("get_video_state")
             flag = EventMesh.publish("get_call_state") 
             if msg != None:
-                if flag == 0 and self.fall_flag == 0:
+                if flag == 0 and self.fall_flag == 0 and video_state == 0:
                     EventMesh.publish("close_timer_all")#
                     if msg != 0:
                         # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_OK"))
@@ -1628,8 +1892,8 @@ if EventMesh.model == "D15_" :
 
         def play_sugar_fun(self,argc):#播放血糖测试值
             flag = EventMesh.publish("get_call_state") 
-            
-            if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and self.fall_flag == 0 and video_state == 0:#电话通话中 或者呼叫中挂断中断
                 EventMesh.publish("close_timer_all")#
                 data = str(argc)
                 data_shi = 0
@@ -1652,8 +1916,9 @@ if EventMesh.model == "D15_" :
 
         def play_spo2_value(self, event, msg): #播放血样数值
             flag = EventMesh.publish("get_call_state") 
+            video_state = EventMesh.publish("get_video_state")
             if msg != None:
-                if flag == 0 and self.fall_flag == 0:
+                if flag == 0 and self.fall_flag == 0 and video_state == 0:
                     EventMesh.publish("close_timer_all")#
                     if msg >= 85:
                         # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_OK"))
@@ -1695,7 +1960,8 @@ if EventMesh.model == "D15_" :
 
         def set_sim_mode(self, event, msg): #mode 1 蓝灯闪烁 可识别卡 但未联网 2 可绑定appsim正常 3 手表不识别卡或者未插卡
             flag = EventMesh.publish("get_call_state") 
-            if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and self.fall_flag == 0 and video_state == 0 :#电话通话中 或者呼叫中挂断中断
                 EventMesh.publish("close_timer_all")#
                 # EventMesh.publish("stop_led_timer")#设置参数
                 mode = 0
@@ -1728,7 +1994,8 @@ if EventMesh.model == "D15_" :
             
         def dial_sos_phone(self, event, msg): #拨打紧急求助电话
             flag = EventMesh.publish("get_call_state")
-            if flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and video_state == 0:
             
                 signal = EventMesh.publish("screen_get_sig")
                 if signal != None:
@@ -1758,7 +2025,8 @@ if EventMesh.model == "D15_" :
         
         def play_cur_time_event(self, event, msg): #播放当前时间
             flag = EventMesh.publish("get_call_state") 
-            if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and self.fall_flag == 0 and video_state == 0:#电话通话中 或者呼叫中挂断中断
                 EventMesh.publish("close_timer_all")#
                 
                 data = RTC().datetime()
@@ -1961,7 +2229,8 @@ if EventMesh.model == "D15_" :
 
         def play_center_phone(self, event, msg): #msg
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许设备再次拨出
-            if flag == 0 and self.fall_flag == 0:
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and self.fall_flag == 0 and video_state == 0:
                 EventMesh.publish("close_timer_all")#
             
                 center_dial = EventMesh.publish("get_storage_config","center_dial")
@@ -1985,7 +2254,8 @@ if EventMesh.model == "D15_" :
 
         def play_imei_event(self, event, msg): #msg
             flag = EventMesh.publish("get_call_state") 
-            if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and self.fall_flag == 0 and video_state == 0:
                 EventMesh.publish("close_timer_all")#
                 imei = EventMesh.publish(constants.EVENT.GET_IMEI)
                 EventMesh.debug_log(imei)
@@ -1996,7 +2266,8 @@ if EventMesh.model == "D15_" :
                 audio_buf.index("R_READ_TIME_{}".format(imei[12])),audio_buf.index("R_READ_TIME_{}".format(imei[13])),audio_buf.index("R_READ_TIME_{}".format(imei[14])))
                 EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data)
 
-
+                str_data = 'mp3files=R_READ_TIME_1.mp3+R_READ_TIME_2.mp3+R_READ_TIME_3.mp3+R_READ_TIME_4.mp3+R_READ_TIME_5.mp3+R_READ_TIME_6.mp3+R_READ_TIME_7.mp3+R_READ_TIME_8.mp3+R_READ_TIME_9.mp3+R_READ_TIME_0.mp3+R_READ_TIME_1.mp3+R_READ_TIME_1.mp3+R_READ_TIME_2.mp3+R_READ_TIME_3.mp3+R_READ_TIME_4.mp3'
+                
         def get_unread_wechat_state(self,event, msg): 
 
             return self.set_unread_wechat
@@ -2025,7 +2296,8 @@ if EventMesh.model == "D15_" :
         def start_wechat_record(self, event, msg): #开始录音相关配置
             if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#未联网不需要录音
                 flag = EventMesh.publish("get_call_state") 
-                if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+                video_state = EventMesh.publish("get_video_state")
+                if flag == 0 and self.fall_flag == 0 and video_state == 0:
                     if self.press_btn == 0:
                         self.press_btn = 1
                         audio_state = EventMesh.publish("get_audio_state")
@@ -2158,10 +2430,11 @@ if EventMesh.model == "D15_" :
                             if check_amr == True:
                                 self.aud.play(1, 1, '/usr/static/storage_file/{}.amr'.format(num))  #文件名前面要加上路径
 
-
         def play_unread_wechat_infor(self,event,msg):#未读微聊语音
             flag = EventMesh.publish("get_call_state") 
-            if flag == 0 and self.press_btn == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断
+            video_state = EventMesh.publish("get_video_state")
+            if flag == 0 and self.press_btn == 0 and self.fall_flag == 0 and video_state == 0:#电话通话中 或者呼叫中挂断中断
+            
                 if self.wechat_recode_list != None:
                     num = 0
                     play_state = 0
@@ -2250,7 +2523,7 @@ if EventMesh.model == "D15_" :
             self.extint_22 = 0
             self.GPIO22_status = 1
 
-            self.extint_17= 0
+            self.extint_17= 1
             self.KeyCall2_status = 1
 
             self.extint_19= 0
@@ -2327,14 +2600,14 @@ if EventMesh.model == "D15_" :
             self.pwk_key26 = ExtInt(ExtInt.GPIO26, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_DISABLE, self.pwk_extint_cb)
             self.pwk_key26.enable() 
 
-            self.sosKey = ExtInt(ExtInt.GPIO6,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.sosKey_extint_cb)#S0S键
-            self.sosKey.enable()
+            # self.sosKey = ExtInt(ExtInt.GPIO6,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.sosKey_extint_cb)#S0S键
+            # self.sosKey.enable()
 
             self.extint_19 = ExtInt(ExtInt.GPIO19,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.key19_extint_cb)
             self.extint_19.enable()
 
-            self.extint_17 = ExtInt(ExtInt.GPIO17,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.key17_extint_cb)
-            self.extint_17.enable()
+            # self.extint_17 = ExtInt(ExtInt.GPIO17,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.key17_extint_cb)
+            # self.extint_17.enable()
 
             self.wechatKey = ExtInt(ExtInt.GPIO22, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.wechatKey_extint_cb)
             self.wechatKey.enable()
@@ -2343,8 +2616,10 @@ if EventMesh.model == "D15_" :
         def key17_extint_cb(self,args):#call 1
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
-            if open_power != None and open_power_off != None:
-                if open_power == 0 or open_power_off == 1:
+            dev_app_mode = EventMesh.publish("get_dev_app_mode")
+
+            if open_power != None and open_power_off != None and dev_app_mode != None: 
+                if open_power == 0 or open_power_off == 1 or dev_app_mode == 1:
                     return
             fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
@@ -2353,12 +2628,22 @@ if EventMesh.model == "D15_" :
                     return
             
             self.KeyCall1_status = int(args[1]) 
-            # EventMesh.txt_log('self.KeyCall2_level :{}'.format(args,self.KeyCall2_status,GPIO17_status))
+            EventMesh.txt_log('key17_extint_cb :{}'.format(args))
             if self.KeyCall1_status == 0:
                 self.KeyCall1_status = 1
             else:
                 self.KeyCall1_status = 0
                 pass
+            if NEW_ENABLE == 0:#新的按键功能定义
+                if self.KeyCall1_status == 0:
+                    video_state = EventMesh.publish("get_video_state")
+                    if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                        if video_state == 6:#6是app打手表需要接通
+                            print("key17_extint_cb")
+                            EventMesh.publish("video_answer_cb")
+                        else:
+                            EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                        return
             self.WeChatKey_status = self.wechatKey.read_level()
             self.GPIO26_status = self.pwk_key26.read_level()
             self.KeyCall2_status = self.extint_19.read_level()
@@ -2366,9 +2651,24 @@ if EventMesh.model == "D15_" :
             # EventMesh.debug_log('key17_extint_cb1',args,self.KeyCall2_status,self.Keycall2_press,self.Keycall2_long_press)
             # EventMesh.debug_log('key17_extint_cb2',self.Keycall2_press) # args[0]:gpio号 args[1]:上升沿或下降沿
 
-            # EventMesh.debug_log('key17_extint_cb',args,self.KeyCall2_status,self.WeChatKey_status,self.GPIO26_status,self.KeyCall1_status,self.sosKey_status) # args[0]:gpio号 args[1]:上升沿或下降沿
+            EventMesh.debug_log('key17_extint_cb',args,self.KeyCall2_status,self.WeChatKey_status,self.GPIO26_status,self.KeyCall1_status,self.sosKey_status) # args[0]:gpio号 args[1]:上升沿或下降沿
             if self.WeChatKey_status != 0 and self.GPIO26_status != 0 and self.KeyCall2_status != 0 and self.sosKey_status != 0:
                 if self.KeyCall1_status == 0:#按下
+                    # if NEW_ENABLE == 0:#新的按键功能定义
+                    #     video_state = EventMesh.publish("get_video_state")
+                    #     if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                    #         if video_state == 6:#6是app打手表需要接通
+                    #             print("key17_extint_cb")
+                    #             EventMesh.publish("video_answer_cb")
+                    #         else:
+                    #             EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                    #         self.Keycall1_press_count=0
+                    #         self.wechatKey_timer.stop()
+                    #         self.pwkey_timer.stop()
+                    #         self.sosKey_timer.stop()
+                    #         self.Keycall2_timer.stop()
+                    #         self.Keycall1_timer.stop()
+                    #         return
                     EventMesh.publish("close_wechat_btn_timer")
                     if self.Keycall1_press == 0 :
                         self.wechatKey_timer.stop()
@@ -2405,6 +2705,7 @@ if EventMesh.model == "D15_" :
         def call1Key_press_cb(self, data):
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
+            video_state = EventMesh.publish("get_video_state")
             if open_power != None and open_power_off != None:
                 if open_power == 0 or open_power_off == 1:
                     self.Keycall1_timer.stop()
@@ -2418,6 +2719,16 @@ if EventMesh.model == "D15_" :
             if self.Keycall1_press == 1 :
                 self.Keycall1_count += 1
                 if self.Keycall1_count >= 10*3: #长按3s 
+                    flag = EventMesh.publish("get_call_state")#获取通话状态
+                    fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
+                    if fall_down != None:
+                        if fall_down != 0 or flag == 2:
+                            self.Keycall1_count = 0
+                            self.Keycall1_press = 0
+                            self.Keycall1_press_count = 0
+                            self.Keycall1_long_press = 0
+                            self.Keycall1_timer.stop()
+                            return
                     if self.Keycall1_long_press == 0:
                         self.Keycall1_long_press = 1
                         flag = EventMesh.publish("get_call_state")#获取通话状态
@@ -2453,12 +2764,13 @@ if EventMesh.model == "D15_" :
         def call1Key_timeout_cb(self, data):#
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
+            video_state = EventMesh.publish("get_video_state")
             if open_power != None and open_power_off != None:
-                if open_power == 0 or open_power_off == 1:
+                if open_power == 0 or open_power_off == 1 :
                     self.Keycall1_timer.stop()
                     self.Keycall1_count = 0
                     self.Keycall1_press = 0
-                    self.Keycall1_press_count+=1
+                    self.Keycall1_press_count=0
                     self.Keycall1_long_press = 0
                     return
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
@@ -2466,7 +2778,7 @@ if EventMesh.model == "D15_" :
             # print("call2Key_timeout_cb",self.Keycall2_press_count,flag)
             if self.Keycall1_press_count > 1:#
                 if fall_down != None:
-                    if fall_down != 0 or flag != 0:#在打电话或者跌倒报警提醒中不允许按键触发
+                    if fall_down != 0 or flag != 0 or video_state != 0:#在打电话或者跌倒报警提醒中不允许按键触发
                         self.Keycall1_press_count = 0
                         return
             if self.Keycall1_press_count == 3:#心率血压测试
@@ -2483,6 +2795,11 @@ if EventMesh.model == "D15_" :
             elif self.Keycall1_press_count == 1:#
                 self.Keycall1_press_count = 0
                 EventMesh.publish("stop_led_timer")#设置参数
+                print("video_state call",video_state)
+                # if video_state != 0:
+                #     if video_state == 6:#6 是app拨打手表 1 是手表打app 3 是正在视频通话中 0 关闭只有第一次视频通话打入才允许接听 接通之后不允许接听了
+                #         EventMesh.publish("video_answer_cb")
+                #     return
                 call_state = EventMesh.publish("get_call_state") 
                 if call_state == 2:#电话拨进需要接听
                     EventMesh.publish("answer_call_event")#接听电话
@@ -2494,11 +2811,13 @@ if EventMesh.model == "D15_" :
 
 
         def key19_extint_cb(self,args):#call 2
-            
+            EventMesh.txt_log('key19_extint_cb :{}'.format(args))
             power_off = EventMesh.publish("get_power_off_state")#获取关机标识
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
-            if power_off != None and open_power != None:
-                if power_off == 1 or open_power == 0:
+            dev_app_mode = EventMesh.publish("get_dev_app_mode")
+            video_state = EventMesh.publish("get_video_state")#获取视频通话状态 5在通话状态不允许按键输入
+            if open_power != None and power_off != None and dev_app_mode != None:
+                if open_power == 0 or power_off == 1 or dev_app_mode == 1: 
                     return
             fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
             flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
@@ -2511,14 +2830,40 @@ if EventMesh.model == "D15_" :
             else:
                 self.KeyCall2_status = 0
                 pass
+            
+            if NEW_ENABLE == 0:#新的按键功能定义
+                if self.KeyCall2_status == 0:
+                    video_state = EventMesh.publish("get_video_state")
+                    if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                        if video_state == 6:#6是app打手表需要接通
+                            print("key17_extint_cb")
+                            EventMesh.publish("video_answer_cb")
+                        else:
+                            EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                        return
             self.WeChatKey_status = self.wechatKey.read_level()
             self.GPIO26_status = self.pwk_key26.read_level()
-            self.KeyCall1_status = self.extint_17.read_level()
-            self.sosKey_status = self.sosKey.read_level()
+            # self.KeyCall1_status = self.extint_17.read_level()
+            # self.sosKey_status = self.sosKey.read_level()
             # EventMesh.debug_log('key19_extint_cb ',args,self.KeyCall1_status,self.GPIO26_status,self.WeChatKey_status,self.sosKey_status,self.KeyCall2_status,self.GPIO26_status) # args[0]:gpio号 args[1]:上升沿或下降沿
             # EventMesh.debug_log('self.KeyCall1_status :{}',args,self.KeyCall1_status) # args[0]:gpio号 args[1]:上升沿或下降沿
             if self.WeChatKey_status != 0 and self.GPIO26_status != 0 and self.KeyCall1_status != 0 and self.sosKey_status != 0:
                 if self.KeyCall2_status == 0:#按下
+                    video_state = EventMesh.publish("get_video_state")
+                    if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                        if video_state == 6:#6是app打手表需要接通
+                            print("key19_extint_cb")
+                            EventMesh.publish("video_answer_cb")
+                        # else:
+                        #     EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                            
+                        self.Keycall2_press_count = 0
+                        self.wechatKey_timer.stop()
+                        self.pwkey_timer.stop()
+                        self.sosKey_timer.stop()
+                        self.Keycall2_timer.stop()
+                        self.Keycall1_timer.stop()
+                        return
                     EventMesh.publish("close_wechat_btn_timer")
                     if self.Keycall2_press == 0 :
                         self.wechatKey_timer.stop()
@@ -2557,25 +2902,32 @@ if EventMesh.model == "D15_" :
             '''KEY2:联动屏幕右下角或返回键长按关机'''
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
+            video_state = EventMesh.publish("get_video_state")
             if open_power != None and open_power_off != None:
                 if open_power == 0 or open_power_off == 1:
                     self.Keycall2_timer.stop()
                     self.Keycall2_count = 0
                     self.Keycall2_press = 0
-                    self.Keycall2_press_count=0
+                    self.Keycall2_press_count =0
                     self.Keycall2_long_press = 0
                     return
             self.KeyCall2_status = self.extint_19.read_level()
             if self.Keycall2_press == 1 :
                 self.Keycall2_count += 1
                 if self.Keycall2_count >= 10*3: #长按3s 
+                    flag = EventMesh.publish("get_call_state")#获取通话状态
+                    fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
+                    if fall_down != None and video_state != None:
+                        if fall_down != 0 or flag != 0 or video_state != 0:
+                            self.Keycall2_count = 0
+                            self.Keycall2_press = 0
+                            self.Keycall2_press_count = 0
+                            self.Keycall2_long_press = 0
+                            self.Keycall2_timer.stop()
+                            return
                     if self.Keycall2_long_press == 0:
                         self.Keycall2_long_press = 1
-                        flag = EventMesh.publish("get_call_state")#获取通话状态
-                        fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
-                        if fall_down != None:
-                            if fall_down != 0 or flag == 2:
-                                return
+                        
                         EventMesh.publish("stop_led_timer")#设置参数
                         EventMesh.publish("call_phonebook_num",2)
                         return
@@ -2602,8 +2954,9 @@ if EventMesh.model == "D15_" :
         def call2Key_timeout_cb(self, data):#
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
+            video_state = EventMesh.publish("get_video_state")
             if open_power != None and open_power_off != None:
-                if open_power == 0 or open_power_off == 1:
+                if open_power == 0 or open_power_off == 1 :
                     self.Keycall2_timer.stop()
                     self.Keycall2_count = 0
                     self.Keycall2_press = 0
@@ -2614,7 +2967,7 @@ if EventMesh.model == "D15_" :
             # print("call1Key_timeout_cb",self.Keycall1_press_count,flag)
             if self.Keycall2_press_count > 1:#
                 if fall_down != None:
-                    if fall_down != 0 or flag != 0:#在打电话或者跌倒报警提醒中不允许按键触发
+                    if fall_down != 0 or flag != 0 or video_state != 0:#在打电话或者跌倒报警提醒中不允许按键触发
                         self.Keycall2_press_count = 0
                         return
             
@@ -2631,8 +2984,16 @@ if EventMesh.model == "D15_" :
                             EventMesh.publish("set_manual_measure_mode",3)#测量体温
             elif self.Keycall2_press_count == 1:#
                 self.Keycall2_press_count = 0
+                # video_state = EventMesh.publish("get_video_state") 
+                # print("video_state ",video_state)
+                # if video_state != 0:
+                #     if video_state == 2:#2 是app拨打手表 1 是手表打app 3 是正在视频通话中 0 关闭只有第一次视频通话打入才允许接听 接通之后不允许接听了
+                #         EventMesh.publish("video_answer_cb")
+                #     return
                 EventMesh.publish("stop_led_timer")#设置参数
                 call_state = EventMesh.publish("get_call_state") 
+                
+                
                 if call_state == 2:#电话拨进需要接听
                     EventMesh.publish("answer_call_event")#接听电话
                     return
@@ -2643,12 +3004,15 @@ if EventMesh.model == "D15_" :
 
 
         def pwk_extint_cb(self,args):#侧边按键
-            # self.GPIO26_status = self.pwk_key26.read_level()
+            EventMesh.txt_log('pwk_extint_cb :{}'.format(args))
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
-            if open_power != None and open_power_off != None:
-                if open_power == 0 or open_power_off == 1:
+            video_state = EventMesh.publish("get_video_state")
+            dev_app_mode = EventMesh.publish("get_dev_app_mode")
+            if open_power != None and open_power_off != None and dev_app_mode != None:
+                if open_power == 0 or open_power_off == 1 or dev_app_mode == 1:
                     return
+            
             flag = EventMesh.publish("get_call_state")#获取通话状态
             fall_down = EventMesh.publish("get_fall_down_state")#获取跌倒报警标识
             if fall_down != None:
@@ -2660,15 +3024,41 @@ if EventMesh.model == "D15_" :
             else:
                 self.GPIO26_status = 0
                 pass
+            if NEW_ENABLE == 0:#新的按键功能定义
+                if self.GPIO26_status == 0:
+                    video_state = EventMesh.publish("get_video_state")
+                    if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                        if video_state == 6:#6是app打手表需要接通
+                            print("pwk_extint_cb")
+                            # EventMesh.publish("video_answer_cb")
+                        else:
+                            EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                        return
+                    
             self.WeChatKey_status = self.wechatKey.read_level()
-            self.KeyCall2_status = self.extint_17.read_level()
+            # self.KeyCall2_status = self.extint_17.read_level()
             self.KeyCall1_status = self.extint_19.read_level()
-            self.sosKey_status = self.sosKey.read_level()
+            # self.sosKey_status = self.sosKey.read_level()
             # EventMesh.debug_log('pwk_extint_cb ',args,self.GPIO26_status,self.WeChatKey_status,self.sosKey_status,self.KeyCall1_status,self.KeyCall2_status) # args[0]:gpio号 args[1]:上升沿或下降沿
             # self.GPIO26_status = ~args[1]
             # EventMesh.debug_log('### GPIO26_status  {} self.GPIO26_status :{}'.format(args,self.GPIO26_status)) # args[0]:gpio号 args[1]:上升沿或下降沿
             if self.WeChatKey_status != 0 and self.KeyCall1_status != 0 and self.sosKey_status != 0 and self.KeyCall2_status != 0:
                 if self.GPIO26_status == 0:#按下
+                    # if NEW_ENABLE == 0:#新的按键功能定义
+                    #     video_state = EventMesh.publish("get_video_state")
+                    #     if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                    #         if video_state == 6:#6是app打手表需要接通
+                    #             pass
+                    #             # EventMesh.publish("video_answer_cb")
+                    #         else:
+                    #             EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                    #         self.Keycall1_press_count=0
+                    #         self.wechatKey_timer.stop()
+                    #         self.pwkey_timer.stop()
+                    #         self.sosKey_timer.stop()
+                    #         self.Keycall2_timer.stop()
+                    #         self.Keycall1_timer.stop()
+                    #         return
                     EventMesh.publish("close_wechat_btn_timer")
                     if self.pwkey_press == 0 :
                         self.aud.stop()  #播放声音 
@@ -2712,8 +3102,9 @@ if EventMesh.model == "D15_" :
         def pwKey_press_cb(self, data):
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
-            if open_power != None and open_power_off != None:
-                if open_power == 0 or open_power_off == 1:
+            video_state = EventMesh.publish("get_video_state")
+            if open_power != None and open_power_off != None and video_state != None:
+                if open_power == 0 or open_power_off == 1 or video_state != 0:
                     self.pwkey_timer.stop()
                     self.pwkey_count = 0
                     self.pwkey_press = 0
@@ -2820,8 +3211,9 @@ if EventMesh.model == "D15_" :
                 usys.print_exception(e)
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
-            if open_power != None and open_power_off != None:
-                if open_power == 0 or open_power_off == 1:
+            video_state = EventMesh.publish("get_video_state")
+            if open_power != None and open_power_off != None and video_state != None:
+                if open_power == 0 or open_power_off == 1 or video_state != 0:
                     self.pwkey_timer.stop()
                     self.pwkey_count = 0
                     self.pwkey_press = 0
@@ -2866,6 +3258,7 @@ if EventMesh.model == "D15_" :
             self.pwKey_press_count = 0
 
         def sosKey_extint_cb(self,args):
+            EventMesh.debug_log('sosKey_extint_cb ',args)
             power_off = EventMesh.publish("get_power_off_state")#获取关机标识
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             if power_off != None and open_power != None:
@@ -2877,17 +3270,39 @@ if EventMesh.model == "D15_" :
             else:
                 self.sosKey_status = 0
                 pass
+            if NEW_ENABLE == 0:#新的按键功能定义
+                if self.sosKey_status == 0:
+                    video_state = EventMesh.publish("get_video_state")
+                    if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                        if video_state == 6:#6是app打手表需要接通
+                            print("pwk_extint_cb")
+                            # EventMesh.publish("video_answer_cb")
+                        else:
+                            EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                        return
 
             self.WeChatKey_status = self.wechatKey.read_level()
             self.GPIO26_status = self.pwk_key26.read_level()
             self.KeyCall1_status = self.extint_19.read_level()
-            self.KeyCall2_status = self.extint_17.read_level()
+            # self.KeyCall2_status = self.extint_17.read_level()
 
             # EventMesh.debug_log('sosKey_extint_cb ',args,self.sosKey_status,self.WeChatKey_status,self.KeyCall1_status,self.KeyCall2_status,self.GPIO26_status) # args[0]:gpio号 args[1]:上升沿或下降沿
             if self.WeChatKey_status != 0 and self.GPIO26_status != 0 and self.KeyCall1_status != 0 and self.KeyCall2_status != 0:
                 if self.sosKey_status == 0:#按下
+                    if NEW_ENABLE == 0:#新的按键功能定义
+                        video_state = EventMesh.publish("get_video_state")
+                        if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                            EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                            self.sosKey_press_count=0
+                            self.wechatKey_timer.stop()
+                            self.pwkey_timer.stop()
+                            self.sosKey_timer.stop()
+                            self.Keycall2_timer.stop()
+                            self.Keycall1_timer.stop()
+                            return
                     EventMesh.publish("close_falldown_alarm_event")#关闭跌倒报警提醒事件
                     EventMesh.publish("close_wechat_btn_timer")
+
                     if self.sosKey_press == 0 :
                         self.wechatKey_timer.stop()
                         self.pwkey_timer.stop()
@@ -2947,13 +3362,19 @@ if EventMesh.model == "D15_" :
                     #     EventMesh.publish("set_led_time_arg",[1000,200,1,led_mode.FLASH_LIGHT_RED,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#设置参数
                 self.sosKey_count += 1
                 if self.sosKey_count >= 10*3: #长按3s sos拨号
+                    flag = EventMesh.publish("get_call_state")#获取通话状态
+                    fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
+                    video_state = EventMesh.publish("get_video_state")#获取视频通话状态
+                    if fall_down != None and video_state != None:
+                        if fall_down != 0 or flag == 2 or video_state != 0:
+                            self.sosKey_count = 0
+                            self.sosKey_long_press = 0
+                            self.sosKey_press = 0
+                            self.sosKey_timer.stop()
+                            return
                     if self.sosKey_long_press == 0:
                         self.sosKey_long_press = 1
-                        flag = EventMesh.publish("get_call_state")#获取通话状态
-                        fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
-                        if fall_down != None:
-                            if fall_down != 0 or flag == 2:
-                                return
+                       
                         EventMesh.publish_async("dial_sos_phone")#拨打sos号码
                         return
                     if self.sosKey_status == 1:#松开
@@ -2980,6 +3401,7 @@ if EventMesh.model == "D15_" :
         # 4、短按六次,播报IMEI号
         # 5、短按十次,解绑APP,同时恢复出厂设置
         def sosKey_timeout_cb(self, data):#
+            print("sosKey_timeout_cb",self.sosKey_press_count)
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
             if open_power != None and open_power_off != None:
@@ -2996,7 +3418,7 @@ if EventMesh.model == "D15_" :
                 fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
                 if self.sosKey_press_count > 1:#短按十次解绑app
                     if fall_down != None:
-                        if fall_down != 0 or flag == 2:
+                        if fall_down != 0 or flag != 0:
                             self.sosKey_press_count = 0
                             return
                 if self.sosKey_press_count == 10:#
@@ -3053,9 +3475,12 @@ if EventMesh.model == "D15_" :
                 # EventMesh.debug_log("sosKey_press_count!!!!!!!!!!!!!! ",self.sosKey_press_count)
                 flag = EventMesh.publish("get_call_state")#获取通话状态
                 fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
+                video_state = EventMesh.publish("get_video_state")#获取视频通话状态
+                
+                
                 if self.sosKey_press_count > 1:#短按十次解绑app
-                    if fall_down != None:
-                        if fall_down != 0 or flag == 2:
+                    if fall_down != None and video_state != None and flag != None:
+                        if fall_down != 0 or flag != 0 or video_state != 0:#获取视频通话状态:
                             self.sosKey_press_count = 0
                             return
                 if self.sosKey_press_count == 10:#
@@ -3089,16 +3514,14 @@ if EventMesh.model == "D15_" :
                 elif self.sosKey_press_count == 3:#视频通话
                     self.sosKey_press_count = 0
                     
-                    # call_state = EventMesh.publish("get_call_state")
-                    # battery = EventMesh.publish("screen_get_battery")
-                    # if call_state == None:
-                    #     call_state = 0
-                    # if call_state == 0: 
-                    #     if battery != None:
-                    #         if battery[0] != "1":#在充电得时候
-                    #             EventMesh.publish("stop_led_timer")#设置参数
-                    #             EventMesh.publish("set_manual_measure_mode",1)#
-                    # pass
+                    call_state = EventMesh.publish("get_call_state")
+                    battery = EventMesh.publish("screen_get_battery")
+                    if call_state == None:
+                        call_state = 0
+                    if call_state == 0: 
+                        EventMesh.publish("stop_led_timer")#设置参数
+                        EventMesh.publish("call_viode_book_num")
+                    pass
                 elif self.sosKey_press_count == 2:#播报当前步数
                     self.sosKey_press_count = 0
                     # EventMesh.publish("stop_led_timer")#设置参数
@@ -3117,29 +3540,56 @@ if EventMesh.model == "D15_" :
         def wechatKey_extint_cb(self,args):
             power_off = EventMesh.publish("get_power_off_state")#获取关机标识
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
-            if power_off != None and open_power != None:
-                if power_off != 0 or open_power == 0:
+            dev_app_mode = EventMesh.publish("get_dev_app_mode")
+            video_state = EventMesh.publish("get_video_state")#获取视频通话状态 5在通话状态不允许按键输入
+            if open_power != None and power_off != None and dev_app_mode != None:
+                if open_power == 0 or power_off == 1 or dev_app_mode == 1 :
                     return
             fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
             if fall_down != None:
                 if fall_down != 0:
                     return
+            # EventMesh.txt_log('wechatKey_extint_cb :{}'.format(args))
             self.WeChatKey_status = int(args[1])
             if self.WeChatKey_status == 0:
                 self.WeChatKey_status = 1
             else:
                 self.WeChatKey_status = 0
                 pass
-
-            self.sosKey_status = self.sosKey.read_level()
+            if NEW_ENABLE == 0:#新的按键功能定义
+                if self.WeChatKey_status == 0:
+                    video_state = EventMesh.publish("get_video_state")
+                    if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                        if video_state == 6:#6是app打手表需要接通
+                            # print("wechatKey_extint_cb")
+                            EventMesh.publish("video_answer_cb")
+                        else:
+                            EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                        return
+                    
+            # self.sosKey_status = self.sosKey.read_level()
             self.GPIO26_status = self.pwk_key26.read_level()
             self.KeyCall1_status = self.extint_19.read_level()
-            self.KeyCall2_status = self.extint_17.read_level()
+            # self.KeyCall2_status = self.extint_17.read_level()
             # EventMesh.debug_log('wechatKey_extint_cb ',args,self.WeChatKey_status,self.sosKey_status,self.KeyCall1_status,self.KeyCall2_status,self.GPIO26_status) # args[0]:gpio号 args[1]:上升沿或下降沿
             # if self.sosKey_status != 0 and self.GPIO26_status != 0:
             if self.sosKey_status != 0 and self.GPIO26_status != 0 and self.KeyCall1_status != 0 and self.KeyCall2_status != 0:
                 if self.WeChatKey_status == 0:#按下
-
+                    video_state = EventMesh.publish("get_video_state")
+                    if video_state != 0:#视频通话打入或者接听后允许挂断视频通话
+                        if video_state == 6:#6是app打手表需要接通
+                            print("wechatKey_extint_cb")
+                            EventMesh.publish("video_answer_cb")
+                        # else:
+                        #     EventMesh.publish("video_reject_cb",2)#挂断视频通话
+                            
+                        self.wechatKey_press_count = 0
+                        self.wechatKey_timer.stop()
+                        self.pwkey_timer.stop()
+                        self.sosKey_timer.stop()
+                        self.Keycall2_timer.stop()
+                        self.Keycall1_timer.stop()
+                        return
                     if self.wechatKey_press == 0:
                         self.wechatKey_timer.stop()
                         self.pwkey_timer.stop()
@@ -3204,8 +3654,10 @@ if EventMesh.model == "D15_" :
         def wechatKey_press_cb(self,data):
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
+            video_state = EventMesh.publish("get_video_state")
             if open_power != None and open_power_off != None:
-                if open_power == 0 or open_power_off == 1:
+                if open_power == 0 or open_power_off == 1 :
+                    
                     self.wechatKey_timer.stop()
                     self.wechatKey_count = 0
                     self.wechatKey_press = 0
@@ -3227,7 +3679,7 @@ if EventMesh.model == "D15_" :
                     flag = EventMesh.publish("get_call_state") 
                     fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
                     if flag != None:
-                        if flag == 0 and fall_down == 0:
+                        if flag == 0 and fall_down == 0 and video_state == 0:
                             if self.WeChatKey_status == 0:
                                 if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#未联网不需要录音
                                     if self.wechat_state == 0:#按下超过s开始录音
@@ -3311,6 +3763,7 @@ if EventMesh.model == "D15_" :
         def wechatKey_timeout_cb(self,data):#微聊键
             open_power = EventMesh.publish("get_power_on_state")#获取开机标识
             open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
+            video_state = EventMesh.publish("get_video_state")
             if open_power != None and open_power_off != None:
                 if open_power == 0 or open_power_off == 1:
                     self.wechatKey_timer.stop()
@@ -3376,8 +3829,8 @@ if EventMesh.model == "D15_" :
                 flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备
                 fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
                 if self.wechatKey_press_count > 1:#
-                    if fall_down != None:
-                        if fall_down != 0 or flag == 2:
+                    if fall_down != None and flag != None and video_state != None:
+                        if fall_down != 0 or flag != 0 or video_state != 0:
                             self.wechatKey_press_count = 0
                             return
                 # EventMesh.debug_log("wechatKey_timeout_cb!!!!!!!!!!!!!! ",self.wechatKey_press_count)
@@ -3425,6 +3878,12 @@ if EventMesh.model == "D15_" :
                 elif self.wechatKey_press_count == 1:#播放最后收到的语音
                     self.wechatKey_press_count = 0
                     EventMesh.publish("stop_led_timer")#设置参数
+                    video_state = EventMesh.publish("get_video_state") 
+                    print("video_state call",video_state)
+                    if video_state != 0:
+                        if video_state == 2:#2 是app拨打手表 1 是手表打app 3 是正在视频通话中 0 关闭只有第一次视频通话打入才允许接听 接通之后不允许接听了
+                            EventMesh.publish("video_answer_cb")
+                        return
                     call_state = EventMesh.publish("get_call_state") 
                     if call_state == 0:
                         fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
index fb5e347..38d9214 100644 (file)
@@ -149,6 +149,37 @@ class PROTOCOL:
 
     SCREEN_SHOW_SEND = "SCREEN_SHOW_SEND"
     SCREEN_SHOW_RECV = "SCREEN_SHOW_RECV"
+
+    JPREG_SEND = "JPREG_SEND"
+    JPREG_RECV = "JPREG_RECV"
+
+    MEMBERS_SEND = "MEMBERS_SEND"
+    MEMBERS_RECV = "MEMBERS_RECV"
+
+    CALLING_SEND = "CALLING_SEND"
+    CALLING_RECV = "CALLING_RECV"
+    
+
+    RCALLING_SEND  = "RCALLING_SEND"
+    RCALLING_RECV  = "RCALLING_RECV"
+
+    AGTALK_SEND = "AGTALK_SEND"
+    AGTALK_RECV = "AGTALK_RECV"
+
+    RTALK_SEND = "RTALK_SEND"
+    RTALK_RECV = "RTALK_RECV"
+
+    JMEMBERS_SEND = "JMEMBERS_SEND"
+    JMEMBERS_RECV = "JMEMBERS_RECV"
+
+    RINGING_SEND = "RINGING_SEND"
+    RINGING_RECV = "RINGING_RECV"
+
+    HANGUP_SEND = "HANGUP_SEND"
+    HANGUP_RECV = "HANGUP_RECV"
+
+    CALLCANCEL_SEND ="CALLCANCEL_SEND"
+    CALLCANCEL_RECV = "CALLCANCEL_RECV"
     
 
 class EVENT:
diff --git a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/led_d15.py b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/led_d15.py
new file mode 100644 (file)
index 0000000..235aca4
--- /dev/null
@@ -0,0 +1,591 @@
+from common import Abstract
+import osTimer
+import EventMesh
+from machine import Pin
+import utime
+from queue import Queue
+import _thread
+import usys
+if EventMesh.model == "D15":
+
+    led_red = Pin(Pin.GPIO36, Pin.OUT, Pin.PULL_PD, 0)
+
+    led_green = Pin(Pin.GPIO44, Pin.OUT, Pin.PULL_PD, 0)
+
+    led_white = Pin(Pin.GPIO21, Pin.OUT, Pin.PULL_PD, 0)
+
+
+
+    def green_light_fast(num,freq):#快闪 num 循环闪烁次数 freq 交替闪烁的频率ms单位 
+        for i in range(num):
+            led_green.write(1)
+            utime.sleep_ms(freq)
+            led_green.write(0)
+            utime.sleep_ms(freq)
+
+    def red_light_fast(num,freq):#快闪 #快闪 num 循环闪烁次数 freq 交替闪烁的频率ms单位 
+        for i in range(num):
+            led_red.write(1)
+            utime.sleep_ms(freq)
+            led_red.write(0)
+            utime.sleep_ms(freq)
+    def red_light_slow(num,freq):#慢闪 #快闪 num 循环闪烁次数 freq 交替闪烁的频率ms单位 
+        for i in range(10):
+            led_red.write(1)
+            utime.sleep_ms(500)
+            led_red.write(0)
+            utime.sleep_ms(500)
+
+    def red_green_light(num,freq):#红绿灯交替闪烁 
+        for i in range(num):
+            led_red.write(1)
+            utime.sleep_ms(freq)
+            led_red.write(0)
+            utime.sleep_ms(freq)
+            led_green.write(1)
+            utime.sleep_ms(freq)
+            led_green.write(0)
+            utime.sleep_ms(freq)
+
+    def open_led_red():
+        led_red.write(1)
+
+    def close_led_red():
+        led_red.write(0)
+
+    def open_led_white():
+        led_white.write(1)
+
+    def close_led_white():
+        led_white.write(0)
+
+    def open_led_green():
+        led_green.write(1)
+
+    def close_led_green():
+        led_green.write(0)
+
+
+
+    LED_TIMER_OUT = 100 
+    class led_mode:
+        LONG_LIGHT_RED = 1
+        LONG_LIGHT_GREEN = 2
+        LONG_LIGHT_WHITE = 3
+        FLASH_LIGHT_RED = 4
+        FLASH_LIGHT_GREEN = 5
+        FLASH_LIGHT_WHITE = 6
+        FLASH_LIGHT_RED_GREEN = 7
+        FLASH_LIGHT_RED_WHITE = 8
+        FLASH_LIGHT_GREEN_WHITE = 9
+        LIGHT_NONE = FLASH_LIGHT_GREEN_WHITE+1
+
+        DEFAULT_LONG_LIGHT_MODE = 0+LIGHT_NONE #默认是关闭
+        OPEN_LONG_LIGHT_MODE = 1+LIGHT_NONE#开启
+        CLOSE_LONG_LIGHT_MODE = 2+LIGHT_NONE#需要关闭
+        INTERVAL_LIGHT_RED  = 3+LIGHT_NONE
+        INTERVAL_LIGHT_GREEN  = 4+LIGHT_NONE
+        INTERVAL_LIGHT_WHITE  = 5+LIGHT_NONE
+
+        OTHER_MEASURE_MODE = 200
+
+        HEALTH_LED_MODE = 201 #健康测试模式
+        WECHAT_LED_MODE = 202 #微聊模式
+        CHARGE_IN_MODE = 203 #充电模式
+        CHARGE_OUT_MODE = 204 #充电已移出
+        CHARGE_FULL_MODE = 205 #充电已满
+        POWER_OFF_MODE = 206 #关机模式
+
+        VIDEO_MEASURE_MODE = 207 #视频通话
+
+
+
+
+
+    class ledEventManager(Abstract):#灯事件
+        def __init__(self):
+            self.timer = osTimer()
+            self.freq_time = 0#交替闪烁时间 最小100ms 
+            self.freq_num = 0#交替闪烁的次数
+            self.flash_light = 0
+            self.total_time = 0
+            self.long_count = 0
+            self.timer_state = 0
+            self.total_count = 0
+            self.freq = 0
+            self.led_state = 0
+            self.long_light_mode = 0
+            self.hr_state = 0
+            self.wechat_btn = 1
+            self.need_hr_btn = 0
+            self.led_open_time = 0
+            self.led_close_time = 0
+            self.led_total_time = 0#闪的总时间
+            self.led_enable = 0
+            self.led_mode = 0
+            self.working_led_mode = None
+            self.ledInfo_queue = Queue()
+            _thread.stack_size(10*1024)
+            _thread.start_new_thread(self.ledInfo_queue_thread, ())
+            _thread.stack_size(8*1024)
+            EventMesh.subscribe("publish_message_event_ledInfo",self.publish_message_event_ledInfo)
+            pass
+        
+            
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_led_time_arg", self.set_led_time_arg)#设置参数
+            EventMesh.subscribe("get_led_state", self.get_led_state)#设置参数
+
+            EventMesh.subscribe("set_hr_blood_led", self.set_hr_blood_led)#设置参数
+
+            EventMesh.subscribe("set_find_watch_led", self.set_find_watch_led)#设置参数
+
+            EventMesh.subscribe("close_all_led", self.close_all_led)#设置参数
+
+            EventMesh.subscribe("stop_led_timer", self.stop_led_timer)#设置参数
+
+            EventMesh.subscribe("read_red_led_level", self.read_red_led_level)#读取红灯的电平状态
+
+            EventMesh.subscribe("read_green_led_level", self.read_green_led_level)#读取绿灯的电平状态
+
+            EventMesh.subscribe("read_white_led_level", self.read_white_led_level)#读取白灯的电平状态
+
+            EventMesh.subscribe("close_led_pin", self.close_led_pin)#读取白灯的电平状态def close_led_pin(self, event, msg):
+
+
+        def ledInfo_queue_thread(self):
+            while True:
+                data = self.ledInfo_queue.get()
+                #EventMesh.debug_log("ledInfo_queue:data = {}".format(data))
+                if data != None:
+                    try:
+                        data["func"](data["data"])
+                    except Exception as e:
+                        EventMesh.debug_log("ledInfo_queue:ERROR:{}".format(e))
+                        usys.print_exception(e)
+        def publish_message_event_ledInfo(self,event,msg):
+            self.ledInfo_queue.put(msg)
+
+        def publish_led_event_cb(self, *args, **kwargs):
+            EventMesh.publish("publish_message_event_ledInfo",{"func":self.led_fun_cb,"data":0})  
+
+        def read_red_led_level(self, event, msg): #
+            red_level = led_red.read()
+            return red_level
+
+        def read_green_led_level(self, event, msg): #
+            green_level = led_green.read()
+            return green_level
+        
+        def read_white_led_level(self, event, msg): #
+            white_level = led_green.read()
+            return white_level
+
+        def set_hr_blood_led(self, event, msg): #
+            EventMesh.debug_log("set_hr_blood_led :{}".format(msg))
+            if msg != None:
+                if msg == 1:
+                    EventMesh.publish("set_led_time_arg",[1,2,10*70*2,led_mode.FLASH_LIGHT_RED_GREEN,10,5,led_mode.HEALTH_LED_MODE])#測量成功
+                    # EventMesh.publish("set_led_time_arg",[1000,200,300,led_mode.FLASH_LIGHT_RED_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.HEALTH_LED_MODE])#開始測量
+                elif msg == 2:
+                    EventMesh.publish("set_led_time_arg",[1,2,60,led_mode.FLASH_LIGHT_GREEN,60,30,led_mode.OTHER_MEASURE_MODE])#測量成功
+                    # EventMesh.publish("set_led_time_arg",[3000,1000,1,led_mode.LONG_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#測量成功
+                elif msg == 3:#测量失败
+                    EventMesh.publish("stop_led_timer")
+                    # EventMesh.publish("set_led_time_arg",[1,1,1,led_mode.FLASH_LIGHT_RED,31,10*3,led_mode.OTHER_MEASURE_MODE])#測量成功
+                    pass
+                    # EventMesh.publish("set_led_time_arg",[1,1,30,led_mode.FLASH_LIGHT_RED,31,10*3,led_mode.OTHER_MEASURE_MODE])#测量失败
+                    #加音频文件
+
+        def set_find_watch_led(self, event, msg): #查找设备
+            EventMesh.publish("OPEN_FIND_WATCH")#
+        
+            # EventMesh.publish("set_led_time_arg",[37000,1000,1,led_mode.LONG_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#查找设备绿灯长亮37s
+
+        def get_led_state(self, event, msg): #
+            return self.timer_state
+        def open_timer(self,msg): #msg 0 使能 1总的时间 2 灯模式 3 开启时间 4 关闭时间 
+            if msg != None:
+                if len(msg) != 0:
+                    self.led_total_time = msg[2]#
+                    # EventMesh.debug_log("open_timer:{}".format(msg))
+                    if self.led_total_time != None:
+
+                        if self.led_total_time > 0:
+                            self.led_enable=msg[0]
+                            if self.led_enable != 0:
+                                self.led_mode = msg[1]
+                                self.long_light_mode = msg[3]
+                                self.led_open_time = msg[4]
+                                self.led_close_time = msg[5]
+                                self.working_led_mode = msg[6]
+                                self.long_count = 0
+
+                                if self.timer_state == 0:
+                                    self.timer_state = 1
+                                    self.timer.stop()
+                                    # self.timer.start(LED_TIMER_OUT,1,self.led_fun_cb)
+                                    self.timer.start(LED_TIMER_OUT,1,self.publish_led_event_cb)
+                    
+            
+
+
+        def set_led_time_arg(self, event, msg): #msg 
+            
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            power_off = EventMesh.publish("get_power_off_state")#获取开机标识
+            # EventMesh.debug_log("set_led_time_arg",msg,open_power,power_off)
+            if open_power != None:
+                if open_power == 0:
+                    return
+            if power_off != None:
+                if power_off == 1:
+                    return
+            usb_in = EventMesh.publish("get_usb")#
+
+            if msg != None:
+                if msg[6] != led_mode.POWER_OFF_MODE:#插入usb关机以防不亮红绿灯
+                    # EventMesh.debug_log("usb_in",usb_in)
+                    if usb_in != None:
+                        if usb_in == 1 or usb_in == 3:#正在充电或者充电已满都不要被打断
+                            if self.timer_state == 1:
+                                self.timer_state = 0
+                                self.timer.stop()
+                            if usb_in == 1:
+                                if self.working_led_mode != led_mode.CHARGE_IN_MODE:
+                                    str_buf = [1,1,10,led_mode.LONG_LIGHT_RED,4,2,led_mode.CHARGE_IN_MODE]
+                                    self.open_timer(str_buf)
+                                self.working_led_mode = led_mode.CHARGE_IN_MODE
+
+                            elif usb_in == 3:
+                                if self.working_led_mode != led_mode.CHARGE_FULL_MODE:
+                                    str_buf = [1,1,10,led_mode.LONG_LIGHT_GREEN,4,2,led_mode.CHARGE_FULL_MODE]
+                                    self.open_timer(str_buf)
+                                self.working_led_mode = led_mode.CHARGE_FULL_MODE
+                            
+                            return
+                        else:
+                            if msg[5] != led_mode.HEALTH_LED_MODE:
+                                self.working_led_mode = led_mode.OTHER_MEASURE_MODE
+
+                            get_hr_state = EventMesh.publish("get_hr_state")
+                            get_spo2_state = EventMesh.publish("get_spo2_state")
+                            
+                            wechat_state = EventMesh.publish("get_wechat_state")
+                            temp_state = EventMesh.publish("get_temp_state")
+                            bp_state = EventMesh.publish("get_bp_state")
+                            bg_state = EventMesh.publish("get_bg_state")
+                            EventMesh.debug_log("get_hr_state",get_hr_state,get_spo2_state,temp_state,wechat_state,self.working_led_mode)
+                            if wechat_state != None: #获取微聊状态
+                                if wechat_state == 1:
+                                    if self.working_led_mode != led_mode.WECHAT_LED_MODE:#如果不在亮微聊模式需要亮微聊模式
+                                        self.timer_state = 0
+                                        self.timer.stop()
+                                        str_buf = [1,1,1,led_mode.LONG_LIGHT_GREEN,4,2,led_mode.WECHAT_LED_MODE]
+                                        self.open_timer(str_buf)
+                                        self.working_led_mode = led_mode.WECHAT_LED_MODE
+                                        return
+                                    else:
+                                        return
+                                else:
+                                    self.wechat_btn = 0
+                                    # if get_hr_state != 0 or get_spo2_state != 0 or temp_state != 0 or bp_state != 0 or bg_state != 0 :#心率血氧优先级高
+                                    if get_hr_state == 1 or get_spo2_state == 1 or temp_state == 1 \
+                                    or bp_state == 1  or bg_state == 1:
+                                        if self.working_led_mode != led_mode.HEALTH_LED_MODE:#如果不在亮微聊模式需要亮微聊模式
+                                            EventMesh.debug_log("set_hr_blood_led!!!!!!!!!!")
+                                            str_buf = [1,2,10*70*2,led_mode.FLASH_LIGHT_RED_GREEN,10,5,led_mode.HEALTH_LED_MODE]#測量成功
+                                            self.timer_state = 0
+                                            self.timer.stop()
+                                            self.open_timer(str_buf)
+                                            self.working_led_mode = led_mode.HEALTH_LED_MODE
+                                            return
+                                        else:
+                                            EventMesh.debug_log("set_hr_blood_led stop!!!!!!!!!!")
+                                            return
+                                    else:# 0 2都认为其他模式灯亮 不是测试健康灯
+                                        self.working_led_mode = led_mode.OTHER_MEASURE_MODE
+            
+            if EventMesh.model == "D15":
+                if EventMesh.publish("get_video_state") != 0:
+                    if msg[6] != led_mode.VIDEO_MEASURE_MODE:
+                        return
+            self.open_timer(msg)
+
+
+    
+        # EventMesh.publish("set_led_time_arg",[1,2,2*300,led_mode.FLASH_LIGHT_RED_GREEN,2,1,led_mode.HEALTH_LED_MODE])#測量成功
+        def led_fun_cb(self, data):#
+            if self.led_enable == 0 or self.led_total_time == 0:
+                return
+            call_state = EventMesh.publish("get_call_state")
+            if call_state == None:
+                call_state = 0
+            if call_state != 0:
+                battery = EventMesh.publish("screen_get_battery")
+                if battery != None:
+                    if battery[0] != "1":#在充电得时候
+                        get_hr_state = EventMesh.publish("get_hr_state")
+                        get_spo2_state = EventMesh.publish("get_spo2_state")
+                        get_temp_state = EventMesh.publish("get_temp_state")
+                        get_bp_state = EventMesh.publish("get_bp_state")
+                        get_bg_state = EventMesh.publish("get_bg_state")
+                        if get_hr_state != None and  get_spo2_state != None and get_temp_state != None and get_bp_state != None and get_bg_state != None:
+                            if get_hr_state == 1 or get_spo2_state == 1 or get_temp_state == 1 or get_bp_state == 1 or get_bg_state == 1:
+                                    EventMesh.publish("close_hr_sop2")
+                                    EventMesh.publish("close_led_pin")
+                                    return
+            # EventMesh.debug_log("self.long_count",self.long_count)
+            if self.led_total_time != 0:
+                #红灯闪烁
+                if self.long_light_mode == led_mode.FLASH_LIGHT_RED :#
+                    if self.led_mode == 1:
+                        if self.led_total_time > 0:
+                            self.led_total_time-=1
+                            if self.led_total_time > 0:
+                                close_led_green()
+                                close_led_white()
+                                open_led_red()
+                            else:
+                                EventMesh.publish("stop_led_timer")#关闭所有的灯
+                    elif self.led_mode == 2:
+                        # EventMesh.debug_log("led red!!!!!!!")
+                        
+                        if self.long_count % (self.led_open_time) <=  self.led_close_time: # 4*cnt cnt 多少次 4 开启时间保护关闭时间 2 关闭时间 100ms 4-2关闭时间为200ms 开启时间也为200ms 
+                            close_led_green()
+                            close_led_white()
+                            open_led_red()
+                        else:
+                            close_led_green()
+                            close_led_white()
+                            close_led_red()
+                        if self.long_count >= self.led_total_time-1:#大于总的时间 4
+                            EventMesh.publish("stop_led_timer")#设置参数
+                            return
+                        self.long_count+=1
+                #绿灯闪烁
+                elif self.long_light_mode == led_mode.FLASH_LIGHT_GREEN:#
+                    if self.led_mode == 1:#长亮时间限制
+                        
+                        if self.led_total_time > 0:
+                            self.led_total_time-=1
+                            if self.led_total_time > 0:
+                                close_led_red()
+                                close_led_white()
+                                open_led_green()
+                            else:
+                                EventMesh.publish("stop_led_timer")#关闭所有的灯
+                            
+
+                    elif self.led_mode == 2:
+                        
+                        if self.long_count % (self.led_open_time) <=  self.led_close_time: # 4*cnt cnt 多少次 4 开启时间保护关闭时间 2 关闭时间 100ms 4-2关闭时间为200ms 开启时间也为200ms 
+                            close_led_red()
+                            close_led_white()
+                            open_led_green()
+                            pass
+                        else:
+                            close_led_green()
+                            close_led_white()
+                            close_led_red()
+                            pass
+                        
+                        if self.long_count >= self.led_total_time-1:#大于总的时间 4
+                            EventMesh.publish("stop_led_timer")#设置参数
+                            return
+                        self.long_count+=1
+                #蓝灯闪烁 暂时是白色灯
+                elif self.long_light_mode == led_mode.FLASH_LIGHT_WHITE:#
+                    if self.led_mode == 1:#长亮时间限制
+                        if self.led_total_time > 0:
+                            self.led_total_time-=1
+                            if self.led_total_time > 0:
+                                close_led_red()
+                                close_led_green()
+                                open_led_white()
+                            else:
+                                EventMesh.publish("stop_led_timer")#关闭所有的灯
+                    elif self.led_mode == 2:
+                        if self.long_count % (self.led_open_time) <=  self.led_close_time: # 4*cnt cnt 多少次 4 开启时间保护关闭时间 2 关闭时间 100ms 4-2关闭时间为200ms 开启时间也为200ms 
+                            close_led_red()
+                            close_led_green()
+                            open_led_white()
+                            pass
+                        else:
+                            close_led_green()
+                            close_led_white()
+                            close_led_red()
+                            pass
+                        if self.long_count >= self.led_total_time-1:#大于总的时间 4
+                            EventMesh.publish("stop_led_timer")#设置参数
+                            return
+                        self.long_count+=1
+                #红绿灯闪烁
+                elif self.long_light_mode == led_mode.FLASH_LIGHT_RED_GREEN:#
+                    
+                    
+                    if self.long_count % (self.led_open_time) <=  self.led_close_time: # 4*cnt cnt 多少次 4 开启时间保护关闭时间 2 关闭时间 100ms 4-2关闭时间为200ms 开启时间也为200ms 
+                        close_led_white()#白色灯
+                        close_led_green()
+                        open_led_red()
+                        pass
+                    else: 
+                        close_led_white()
+                        close_led_red()
+                        open_led_green()
+                        pass
+                    if self.long_count >= self.led_total_time-1:#大于总的时间 4
+                        EventMesh.publish("stop_led_timer")#设置参数
+                        return
+                    self.long_count+=1
+                #红蓝灯闪烁 蓝变成白色灯
+                elif self.long_light_mode == led_mode.FLASH_LIGHT_RED_WHITE:#
+                    if self.long_count % (self.led_open_time) <=  self.led_close_time: # 4*cnt cnt 多少次 4 开启时间保护关闭时间 2 关闭时间 100ms 4-2关闭时间为200ms 开启时间也为200ms 
+                        close_led_white()#白色灯
+                        close_led_green()
+                        open_led_red()
+                        pass
+                    else:
+                        close_led_green()
+                        close_led_red()
+                        open_led_white()
+                        pass
+                    if self.long_count >= self.led_total_time-1:#大于总的时间 4
+                        EventMesh.publish("stop_led_timer")#设置参数
+                        return
+                    self.long_count+=1
+                #蓝绿灯闪烁
+                elif self.long_light_mode == led_mode.FLASH_LIGHT_GREEN_WHITE:#
+
+                    
+                    if self.long_count % (self.led_open_time) <=  self.led_close_time: # 4*cnt cnt 多少次 4 开启时间保护关闭时间 2 关闭时间 100ms 4-2关闭时间为200ms 开启时间也为200ms 
+                        close_led_white()#白色灯
+                        close_led_red()
+                        open_led_green()
+                        pass
+                    else:
+                        close_led_green()
+                        close_led_red()
+                        open_led_white()
+                        pass
+                    if self.long_count >= self.led_total_time-1:#大于总的时间 4
+                        EventMesh.publish("stop_led_timer")#设置参数
+                        return
+                    self.long_count+=1
+                #红灯长亮
+                elif self.long_light_mode == led_mode.LONG_LIGHT_RED:#
+                    close_led_white()#白色灯
+                    close_led_green()
+                    open_led_red()
+                    self.timer.stop()
+                    self.timer_state = 0
+                    self.led_total_time = 0
+                    self.led_enable = 0
+                    self.led_mode = 0
+                    self.long_light_mode = 0
+                    self.led_open_time = 0
+                    self.led_close_time = 0
+                    self.working_led_mode = 0
+                    self.long_count = 0
+
+                #绿灯长亮
+                elif self.long_light_mode == led_mode.LONG_LIGHT_GREEN:#
+                    close_led_white()#白色灯
+                    close_led_red()
+                    open_led_green()
+                    self.timer.stop()
+                    self.timer_state = 0
+                    self.led_total_time = 0
+                    self.led_enable = 0
+                    self.led_mode = 0
+                    self.long_light_mode = 0
+                    self.led_open_time = 0
+                    self.led_close_time = 0
+                    self.working_led_mode = 0
+                    self.long_count = 0
+                #蓝灯长亮
+                elif self.long_light_mode == led_mode.LONG_LIGHT_WHITE:#
+                    close_led_green()#白色灯
+                    close_led_red()
+                    open_led_white()
+                    self.timer.stop()
+                    self.timer_state = 0
+                    self.led_total_time = 0
+                    self.led_enable = 0
+                    self.led_mode = 0
+                    self.long_light_mode = 0
+                    self.led_open_time = 0
+                    self.led_close_time = 0
+                    self.working_led_mode = 0
+                    self.long_count = 0
+        
+        def close_led_pin(self, event, msg):
+            EventMesh.debug_log("close_led_pin!!!")
+
+            self.timer.stop()
+            self.timer_state = 0
+            self.led_total_time = 0
+            self.led_enable = 0
+            self.led_mode = 0
+            self.long_light_mode = 0
+            self.led_open_time = 0
+            self.led_close_time = 0
+            self.working_led_mode = 0
+            self.long_count = 0
+            close_led_red()
+            close_led_green()
+            close_led_white()
+
+        def stop_led_timer(self, event, msg):
+            EventMesh.publish("close_all_led")#关闭所有的灯
+        
+        def close_all_led(self, event, msg):
+            self.close_all_led_do(0)
+        def close_all_led_do(self,data):   
+            open_power = EventMesh.publish("get_power_on_state")#获取开机标识
+            if open_power != None:
+                if open_power == 0:
+                    return
+            usb_in = EventMesh.publish("get_usb")#
+            open_power_off = EventMesh.publish("get_power_off_state")#获取开机标识
+            if open_power_off != None:
+                if open_power_off != 1:
+                    if usb_in != None:
+                        if usb_in == 1 or usb_in == 3:#正在充电或者充电已满都不要被打断
+                            if self.timer_state == 1:
+                                self.timer_state = 0
+                                self.timer.stop()
+                            return
+                        else:
+                            get_hr_state = EventMesh.publish("get_hr_state")
+                            get_spo2_state = EventMesh.publish("get_spo2_state")
+                            
+                            wechat_state = EventMesh.publish("get_wechat_state")
+                            temp_state = EventMesh.publish("get_temp_state")
+                            bp_state = EventMesh.publish("get_bp_state")
+                            bg_state = EventMesh.publish("get_bg_state")
+                            # EventMesh.debug_log("get_hr_state",get_hr_state,get_spo2_state,wechat_state,self.working_led_mode)
+                            if wechat_state != None: #获取微聊状态
+                                if wechat_state == 1 or get_spo2_state == 1  or get_hr_state == 1  or temp_state == 1 or bp_state == 1 \
+                                    or bg_state == 1 :
+                                    return
+            if self.timer_state == 1:
+                self.timer.stop()
+            self.timer_state = 0
+            self.led_total_time = 0
+            self.led_enable = 0
+            self.led_mode = 0
+            self.long_light_mode = 0
+            self.led_open_time = 0
+            self.led_close_time = 0
+            self.working_led_mode = 0
+            self.long_count = 0
+            close_led_red()
+            close_led_green()
+            close_led_white()
+            # EventMesh.debug_log("close led!!!")
+
+        def led_test_fun_cb(self, data):
+            return
+    
index 52fa200..8bda242 100644 (file)
@@ -2,7 +2,9 @@ import sms
 import atcmd
 import net
 import machine
-from led import ledEventManager,led_mode
+import EventMesh
+
+    
 resp=bytearray(50)
 # atcmd.sendSync('AT+log=52,1\r\n',resp,'',200)
 # EventMesh.debug_log("AT+log=52,1:{}".format(resp))
@@ -56,7 +58,7 @@ def main_init():
     
     EventMesh.debug_log("init2:{}".format(utime.localtime()))
     EventMesh.debug_log("init3:{}".format(utime.localtime()))
-    if EventMesh.model == "D10_":
+    if EventMesh.model == "D10":
         from btn_device_ec800m import BtnDevice,intervManager
     else:
         from btn_device_ec800m_d15 import BtnDevice,intervManager
@@ -65,6 +67,12 @@ def main_init():
     btn_device.start()
     
     import ui as _ui
+
+    if EventMesh.model == "D10":
+        from led import ledEventManager
+    else:
+        EventMesh.debug_log("charge full")
+        from led_d15 import ledEventManager
     # import ui as _ui
     EventMesh.debug_log("init4:{}".format(utime.localtime()))
     ui = _ui.UI()
@@ -80,7 +88,10 @@ def main_init():
     #     TEMP_ProtoCol,DLT_ProtoCol,WT_ProtoCol,UD_ProtoCol,REMIND_ProtoCol, CR_ProtoCol,KA_ProtoCol,FIND_ProtoCol,POWEROFF_ProtoCol,Time_ProtoCol,TKS_ProtoCol,FALLDOWN_ProtoCol,\
     #         ProtoColResolver,SILENCETIME2_ProtoCol,PHL_ProtoCol,MONITOR_ProtoCol,bootoff_ProtoCol,WDSTART_ProtoCol,LOWBAT_ProtoCol,sosHome_dial_ProtoCol,SockManager,NetManager
     import  protocol  
-    import mgr 
+    if EventMesh.model == "D10":
+        import mgr as mgr
+    else:
+        import mgr_d15 as mgr
     EventMesh.debug_log("init7:{}".format(utime.localtime()))
     
     
@@ -117,7 +128,7 @@ def main_init():
         # .append_manager(mgr.StopwatchManager()) \
         # .append_manager(mgr.CountdownManager()) \
 
-   
+    
     app.append_manager(mgr.ConfigStoreManager())
     app.append_manager(protocol.NetManager())
     app.append_manager(mgr.LocationManager())
@@ -147,10 +158,13 @@ def main_init():
     app.append_manager(mgr.testSmsSetIPManager())
     app.append_manager(mgr.deleteSmsManager())
     app.append_manager(mgr.schoolclassManager())
+    if EventMesh.model == "D15":
+        app.append_manager(mgr.vedioInforManager())
 
     EventMesh.debug_log("init21:{}".format(utime.localtime()))    
     
     EventMesh.debug_log("init11:{}".format(utime.localtime()))    
+    EventMesh.publish("open_power_on", 1)#
     pcr = protocol.ProtoColResolver()
     pcr.add_support(protocol.LK_ProtoCol())
     pcr.add_support(protocol.PING_ProtoCol())
@@ -204,6 +218,17 @@ def main_init():
     pcr.add_support(protocol.REMIND_CH_SIT_ProtoCol())
     pcr.add_support(protocol.SCREEN_SHOWProtoCol())
 
+    #视频通话
+    if EventMesh.model == "D15":
+        pcr.add_support(protocol.JPREG_ProtoCol())
+        pcr.add_support(protocol.MEMBERS_ProtoCol())
+        pcr.add_support(protocol.CALLING_ProtoCol())
+        pcr.add_support(protocol.RCALLING_ProtoCol())
+        pcr.add_support(protocol.AGTALK_ProtoCol())
+        pcr.add_support(protocol.RTALK_ProtoCol())
+
+
+
     sm = protocol.SockManager()
     sm.add_support_resolver(pcr)
     app.append_manager(sm)
@@ -223,7 +248,7 @@ def main_init():
             next_alarm_time = utime.localtime(timeSecond)
             machine.RTC().datetime((next_alarm_time[0],next_alarm_time[1],next_alarm_time[2],next_alarm_time[6],next_alarm_time[3],next_alarm_time[4],next_alarm_time[5],0))
     
-    EventMesh.publish("open_power_on", 1)#
+    
     
     # EventMesh.publish("load_screen", {"screen": "main_menu"})
 
index 06bbb89..4684072 100644 (file)
@@ -42,1681 +42,1419 @@ import voiceCall
 from misc import PWM
 from led import led_mode,open_led_green,close_led_green,open_led_red,close_led_red,close_led_white
 from queue import Queue
+if EventMesh.model == "D10":
+    heartbeat_time = 7*60 #心跳时间
 
-heartbeat_time = 7*60 #心跳时间
-
-def get_autoblood_value():#血压值
-    data = RTC().datetime()
-    hour = int(data[4])
-    blood_Maxvalue = 0
-    blood_Minvalue = 0
-    if hour >= 6 and hour <= 10:
-        random_numMax = urandom.randint(0, 30)
-        random_numMin = urandom.randint(0, 20)
-        blood_Maxvalue = 120+random_numMax
-        blood_Minvalue = 75+random_numMin
-
-        print("get_autoblood_value 6 -10",blood_Maxvalue,blood_Minvalue)
-        # return [self.blood_Maxvalue,self.blood_Minvalue]
-    elif hour > 10 and hour <= 14:#10-14(10,14]
-        random_numMax = urandom.randint(0, 20)
-        random_numMin = urandom.randint(0, 25)
-        blood_Maxvalue = 115+random_numMax
-        blood_Minvalue = 60+random_numMin
-        print("get_autoblood_value 10 -14",blood_Maxvalue,blood_Minvalue)
-        # return [self.blood_Maxvalue,self.blood_Minvalue]
-    elif hour > 14 and hour <= 18:#14-18
-        random_numMax = urandom.randint(0, 25)
-        random_numMin = urandom.randint(0, 15)
-        blood_Maxvalue = 115+random_numMax
-        blood_Minvalue = 70+random_numMin
-
-        print("get_autoblood_value 14 -18",blood_Maxvalue,blood_Minvalue)
-        # return [self.blood_Maxvalue,self.blood_Minvalue]
-    elif hour > 2 and hour < 6:#2-6
-        random_numMax = urandom.randint(0, 30)
-        random_numMin = urandom.randint(0, 20)
-        blood_Maxvalu = 105+random_numMax
-        blood_Minvalue = 65+random_numMin
+    def get_autoblood_value():#血压值
+        data = RTC().datetime()
+        hour = int(data[4])
+        blood_Maxvalue = 0
+        blood_Minvalue = 0
+        if hour >= 6 and hour <= 10:
+            random_numMax = urandom.randint(0, 30)
+            random_numMin = urandom.randint(0, 20)
+            blood_Maxvalue = 120+random_numMax
+            blood_Minvalue = 75+random_numMin
+
+            print("get_autoblood_value 6 -10",blood_Maxvalue,blood_Minvalue)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        elif hour > 10 and hour <= 14:#10-14(10,14]
+            random_numMax = urandom.randint(0, 20)
+            random_numMin = urandom.randint(0, 25)
+            blood_Maxvalue = 115+random_numMax
+            blood_Minvalue = 60+random_numMin
+            print("get_autoblood_value 10 -14",blood_Maxvalue,blood_Minvalue)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        elif hour > 14 and hour <= 18:#14-18
+            random_numMax = urandom.randint(0, 25)
+            random_numMin = urandom.randint(0, 15)
+            blood_Maxvalue = 115+random_numMax
+            blood_Minvalue = 70+random_numMin
+
+            print("get_autoblood_value 14 -18",blood_Maxvalue,blood_Minvalue)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        elif hour > 2 and hour < 6:#2-6
+            random_numMax = urandom.randint(0, 30)
+            random_numMin = urandom.randint(0, 20)
+            blood_Maxvalu = 105+random_numMax
+            blood_Minvalue = 65+random_numMin
 
+            
+            print("get_autoblood_value 2 -6",blood_Maxvalue,blood_Minvalue)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        else:#18-2 19 20 21 22 23 1 2
+            random_numMax = urandom.randint(0, 30)
+            random_numMin = urandom.randint(0, 20)
+            blood_Maxvalue = 100+random_numMax
+            blood_Minvalue = 60+random_numMin
+            print("get_autoblood_value 18 -2",blood_Maxvalue,blood_Minvalue)
+        return [blood_Maxvalue,blood_Minvalue]
+
+    def get_blood_sugar_value():#血糖值
+        data = RTC().datetime()
+        hour = int(data[4])
+        blood_sugar = 0
+        if (hour >= 6 and hour <= 8) or (hour >= 12 and hour <= 13) or (hour >= 18 and hour <= 19):#6-8 12-13 18-19 
+            random_value = urandom.randint(39, 61)
+            blood_sugar = random_value/10
+            print("get_blood_sugar_value 6 -10",blood_sugar)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        elif (hour > 8 and hour <= 9) or (hour >= 14 and hour <= 15) or (hour >= 20 and hour <= 21):#8-9 14-15 20-21
+            random_value = urandom.randint(67, 90)
+            blood_sugar = random_value/10
+            print("get_blood_sugar_value 10 -14",blood_sugar)
+        else:#18-2 19 20 21 22 23 1 2 10-11 16-17 21-22
+            random_value = urandom.randint(39, 78)
+            blood_sugar = random_value/10
+            print("get_blood_sugar_value 18 -2",blood_sugar)
+        return blood_sugar
+
+
+
+
+    class PhoneVolumeLevelManager(Abstract):
+        def __init__(self):
+            self.level = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("push_add_phonering_level", self.add)
+            EventMesh.subscribe("push_reduce_phonering_level", self.reduce)
+            EventMesh.subscribe("get_phonering_level", self.get)
+
+        def add(self, event, msg):
+            if self.level < 7:
+                self.level = self.level + 1
+
+        def reduce(self, event, msg):
+            if self.level > 0:
+                self.level = self.level - 1
+
+        def get(self, event=None, msg=None):
+            return self.level
+
+    class MsgVolumeLevelManager(Abstract):
+        def __init__(self):
+            self.level = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("push_add_msgvolume_level", self.add)
+            EventMesh.subscribe("push_reduce_msgvolume_level", self.reduce)
+            EventMesh.subscribe("get_msgvolume_level", self.get)
+
+        def add(self, event, msg):
+            if self.level < 7:
+                self.level = self.level + 1
+
+        def reduce(self, event, msg):
+            if self.level > 0:
+                self.level = self.level - 1
+
+        def get(self, event=None, msg=None):
+            return self.level
+
+    class AlarmVolumeLevelManager(Abstract):
+        def __init__(self):
+            self.level = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("push_add_alarmvolume_level", self.add)
+            EventMesh.subscribe("push_reduce_alarmvolume_level", self.reduce)
+            EventMesh.subscribe("get_alarmvolume_level", self.get)
+
+        def add(self, event, msg):
+            if self.level < 7:
+                self.level = self.level + 1
+
+        def reduce(self, event, msg):
+            if self.level > 0:
+                self.level = self.level - 1
+
+        def get(self, event=None, msg=None):
+            return self.level
+            
+    class StopwatchManager(Abstract):
+        def __init__(self):
+            self.level = 0
+            self.ms_value = 0
+            self.sec_value = 0
+            self.min_value = 0
+            self.timer = Timer(Timer.Timer1)
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("stopwatch_start", self.start)
+            EventMesh.subscribe("stopwatch_stop", self.paused)
+            EventMesh.subscribe("stopwatch_reset", self.reset)
+            EventMesh.subscribe("get_stopwatch_ms", self.get_ms)
+            EventMesh.subscribe("get_stopwatch_sec", self.get_sec)
+            EventMesh.subscribe("get_stopwatch_min", self.get_min)
+
+        def start(self, event, msg):        
+            self.timer.start(period=100, mode=self.timer.PERIODIC, callback=self.fun)
         
-        print("get_autoblood_value 2 -6",blood_Maxvalue,blood_Minvalue)
-        # return [self.blood_Maxvalue,self.blood_Minvalue]
-    else:#18-2 19 20 21 22 23 1 2
-        random_numMax = urandom.randint(0, 30)
-        random_numMin = urandom.randint(0, 20)
-        blood_Maxvalue = 100+random_numMax
-        blood_Minvalue = 60+random_numMin
-        print("get_autoblood_value 18 -2",blood_Maxvalue,blood_Minvalue)
-    return [blood_Maxvalue,blood_Minvalue]
-
-def get_blood_sugar_value():#血糖值
-    data = RTC().datetime()
-    hour = int(data[4])
-    blood_sugar = 0
-    if (hour >= 6 and hour <= 8) or (hour >= 12 and hour <= 13) or (hour >= 18 and hour <= 19):#6-8 12-13 18-19 
-        random_value = urandom.randint(39, 61)
-        blood_sugar = random_value/10
-        print("get_blood_sugar_value 6 -10",blood_sugar)
-        # return [self.blood_Maxvalue,self.blood_Minvalue]
-    elif (hour > 8 and hour <= 9) or (hour >= 14 and hour <= 15) or (hour >= 20 and hour <= 21):#8-9 14-15 20-21
-        random_value = urandom.randint(67, 90)
-        blood_sugar = random_value/10
-        print("get_blood_sugar_value 10 -14",blood_sugar)
-    else:#18-2 19 20 21 22 23 1 2 10-11 16-17 21-22
-        random_value = urandom.randint(39, 78)
-        blood_sugar = random_value/10
-        print("get_blood_sugar_value 18 -2",blood_sugar)
-    return blood_sugar
-
-
-
-
-class PhoneVolumeLevelManager(Abstract):
-    def __init__(self):
-        self.level = 0
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("push_add_phonering_level", self.add)
-        EventMesh.subscribe("push_reduce_phonering_level", self.reduce)
-        EventMesh.subscribe("get_phonering_level", self.get)
-
-    def add(self, event, msg):
-        if self.level < 7:
-            self.level = self.level + 1
-
-    def reduce(self, event, msg):
-        if self.level > 0:
-            self.level = self.level - 1
-
-    def get(self, event=None, msg=None):
-        return self.level
-
-class MsgVolumeLevelManager(Abstract):
-    def __init__(self):
-        self.level = 0
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("push_add_msgvolume_level", self.add)
-        EventMesh.subscribe("push_reduce_msgvolume_level", self.reduce)
-        EventMesh.subscribe("get_msgvolume_level", self.get)
-
-    def add(self, event, msg):
-        if self.level < 7:
-            self.level = self.level + 1
-
-    def reduce(self, event, msg):
-        if self.level > 0:
-            self.level = self.level - 1
-
-    def get(self, event=None, msg=None):
-        return self.level
-
-class AlarmVolumeLevelManager(Abstract):
-    def __init__(self):
-        self.level = 0
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("push_add_alarmvolume_level", self.add)
-        EventMesh.subscribe("push_reduce_alarmvolume_level", self.reduce)
-        EventMesh.subscribe("get_alarmvolume_level", self.get)
-
-    def add(self, event, msg):
-        if self.level < 7:
-            self.level = self.level + 1
-
-    def reduce(self, event, msg):
-        if self.level > 0:
-            self.level = self.level - 1
-
-    def get(self, event=None, msg=None):
-        return self.level
+        def paused(self, event, msg):        
+            self.timer.stop()
         
-class StopwatchManager(Abstract):
-    def __init__(self):
-        self.level = 0
-        self.ms_value = 0
-        self.sec_value = 0
-        self.min_value = 0
-        self.timer = Timer(Timer.Timer1)
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("stopwatch_start", self.start)
-        EventMesh.subscribe("stopwatch_stop", self.paused)
-        EventMesh.subscribe("stopwatch_reset", self.reset)
-        EventMesh.subscribe("get_stopwatch_ms", self.get_ms)
-        EventMesh.subscribe("get_stopwatch_sec", self.get_sec)
-        EventMesh.subscribe("get_stopwatch_min", self.get_min)
-
-    def start(self, event, msg):        
-        self.timer.start(period=100, mode=self.timer.PERIODIC, callback=self.fun)
-    
-    def paused(self, event, msg):        
-        self.timer.stop()
-    
-    def reset(self, event, msg):
-        self.timer.stop()
-
-        self.sec_value = 0
-        self.min_value = 0
-        self.ms_value = 0
-
-    def fun(self):
-        self.ms_value += 1
-        if self.ms_value > 9:
-            self.ms_value = 0   
-            self.sec_value += 1
-        if self.sec_value > 60:
-            self.sec_value = 0
-            self.min_value += 1
-        if self.min_value > 60:
+        def reset(self, event, msg):
             self.timer.stop()
 
-    def get_ms(self, event=None, msg=None):
-        return self.ms_value
-
-    def get_min(self, event=None, msg=None):
-        return self.min_value
-
-    def get_sec(self, event=None, msg=None):
-        return self.sec_value
+            self.sec_value = 0
+            self.min_value = 0
+            self.ms_value = 0
+
+        def fun(self):
+            self.ms_value += 1
+            if self.ms_value > 9:
+                self.ms_value = 0   
+                self.sec_value += 1
+            if self.sec_value > 60:
+                self.sec_value = 0
+                self.min_value += 1
+            if self.min_value > 60:
+                self.timer.stop()
+
+        def get_ms(self, event=None, msg=None):
+            return self.ms_value
+
+        def get_min(self, event=None, msg=None):
+            return self.min_value
+
+        def get_sec(self, event=None, msg=None):
+            return self.sec_value
+
+    class CountdownManager(Abstract):
+        def __init__(self):
+            self.sec = 0
+            self.min = 0
+            self.hour = 0
+            self.timer = osTimer()
+            self.total = 0
+            self.time_cb = 0
+            self.time_play = 0
+            self.total_sec = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("add_countdown_sec", self.add_sec)
+            EventMesh.subscribe("reduce_countdown_sec", self.reduce_sec)
+            EventMesh.subscribe("add_countdown_min", self.add_min)
+            EventMesh.subscribe("reduce_countdown_min", self.reduce_min)
+            EventMesh.subscribe("add_countdown_hour", self.add_hour)
+            EventMesh.subscribe("reduce_countdown_hour", self.reduce_hour)
+            EventMesh.subscribe("get_countdown_sec", self.get_sec)
+            EventMesh.subscribe("get_countdown_min", self.get_min)
+            EventMesh.subscribe("get_countdown_hour", self.get_hour)
+
+            EventMesh.subscribe("set_countdown_off_state", self.set_countdown_off_state)
+            EventMesh.subscribe("get_countdown_off_state", self.get_countdown_off_state)
+
+
+            EventMesh.subscribe("set_countdown_all_time", self.set_countdown_all_time)
+            EventMesh.subscribe("get_countdown_all_time", self.get_countdown_all_time)
+
+            EventMesh.subscribe("countdown_end_cb", self.countdown_end_cb)
+
+            EventMesh.subscribe("reset_time_countdown",self.reset)
+
+        def set_countdown_all_time(self, event, msg):
+            self.total = msg[0]
+            self.total_sec = msg[1]
+            # EventMesh.debug_log("self.total:{} self.total_sec:{}".format(self.total,self.total_sec))
+
+
+        def get_countdown_all_time(self, event, msg):
+            return self.total
+        
+        def set_countdown_off_state(self, event, msg):
 
-class CountdownManager(Abstract):
-    def __init__(self):
-        self.sec = 0
-        self.min = 0
-        self.hour = 0
-        self.timer = osTimer()
-        self.total = 0
-        self.time_cb = 0
-        self.time_play = 0
-        self.total_sec = 0
+            self.time_cb = msg[0]
+            self.time_play = msg[1]
+            # EventMesh.debug_log("self.time_cb:{} self.total_sec:{}".format(self.time_cb,self.time_play))
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("add_countdown_sec", self.add_sec)
-        EventMesh.subscribe("reduce_countdown_sec", self.reduce_sec)
-        EventMesh.subscribe("add_countdown_min", self.add_min)
-        EventMesh.subscribe("reduce_countdown_min", self.reduce_min)
-        EventMesh.subscribe("add_countdown_hour", self.add_hour)
-        EventMesh.subscribe("reduce_countdown_hour", self.reduce_hour)
-        EventMesh.subscribe("get_countdown_sec", self.get_sec)
-        EventMesh.subscribe("get_countdown_min", self.get_min)
-        EventMesh.subscribe("get_countdown_hour", self.get_hour)
 
-        EventMesh.subscribe("set_countdown_off_state", self.set_countdown_off_state)
-        EventMesh.subscribe("get_countdown_off_state", self.get_countdown_off_state)
+        def get_countdown_off_state(self, event, msg):
+            return [self.time_cb,self.time_play]
+        
+        def countdown_end_cb(self, event, msg):
+            
+            if self.time_cb == 1 and self.time_play == 1:
+                date_tmp = utime.localtime()
+                time_tmp = utime.mktime(date_tmp) 
+                reduce = time_tmp- self.total_sec
+                EventMesh.debug_log("self.time_cb:{} self.time_play:{} self.total:{} self.total_sec:{}".format(self.time_cb,self.time_play, self.total,self.total_sec))
+                self.total = self.total - reduce
+                if self.total <= 0:
+                    self.total = 0
+                    self.time_cb = 0
+                    self.time_play = 0
+                    self.sec = 0
+                    self.min = 0
+                    self.hour = 0
+                    
+                    EventMesh.publish("load_screen", {"screen": "countdown_end"})
+                    return
+                self.total_sec = time_tmp
 
 
-        EventMesh.subscribe("set_countdown_all_time", self.set_countdown_all_time)
-        EventMesh.subscribe("get_countdown_all_time", self.get_countdown_all_time)
+        def add_sec(self, event, msg):
+            if self.sec < 59:
+                self.sec = self.sec + 1
 
-        EventMesh.subscribe("countdown_end_cb", self.countdown_end_cb)
+        def reduce_sec(self, event, msg):
+            if self.sec > 0:
+                self.sec = self.sec - 1
 
-        EventMesh.subscribe("reset_time_countdown",self.reset)
+        def add_min(self, event, msg):
+            if self.min < 59:
+                self.min = self.min + 1
 
-    def set_countdown_all_time(self, event, msg):
-        self.total = msg[0]
-        self.total_sec = msg[1]
-        # EventMesh.debug_log("self.total:{} self.total_sec:{}".format(self.total,self.total_sec))
+        def reduce_min(self, event, msg):
+            if self.min > 0:
+                self.min = self.min - 1
 
+        def add_hour(self, event, msg):
+            if self.hour < 99:
+                self.hour = self.hour + 1
 
-    def get_countdown_all_time(self, event, msg):
-        return self.total
-    
-    def set_countdown_off_state(self, event, msg):
+        def reduce_hour(self, event, msg):
+            if self.hour > 0:
+                self.hour = self.hour - 1
 
-        self.time_cb = msg[0]
-        self.time_play = msg[1]
-        # EventMesh.debug_log("self.time_cb:{} self.total_sec:{}".format(self.time_cb,self.time_play))
+        def get_sec(self, event=None, msg=None):
+            return self.sec
 
+        def get_min(self, event=None, msg=None):
+            return self.min
 
-    def get_countdown_off_state(self, event, msg):
-        return [self.time_cb,self.time_play]
-    
-    def countdown_end_cb(self, event, msg):
+        def get_hour(self, event=None, msg=None):
+            return self.hour
         
-        if self.time_cb == 1 and self.time_play == 1:
-            date_tmp = utime.localtime()
-            time_tmp = utime.mktime(date_tmp) 
-            reduce = time_tmp- self.total_sec
-            EventMesh.debug_log("self.time_cb:{} self.time_play:{} self.total:{} self.total_sec:{}".format(self.time_cb,self.time_play, self.total,self.total_sec))
-            self.total = self.total - reduce
-            if self.total <= 0:
-                self.total = 0
-                self.time_cb = 0
-                self.time_play = 0
-                self.sec = 0
-                self.min = 0
-                self.hour = 0
-                
-                EventMesh.publish("load_screen", {"screen": "countdown_end"})
-                return
-            self.total_sec = time_tmp
 
+        
+        def reset(self, event=None, msg=None):
+            self.hour = 0
+            self.min = 0
+            self.sec = 0
+        
+        
 
-    def add_sec(self, event, msg):
-        if self.sec < 59:
-            self.sec = self.sec + 1
+    BATTERY_OCV_TABLE = {
+        "nix_coy_mnzo2": {
+            55: {
+                4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
+                3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
+            },
+            20: {
+                4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
+                3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
+            },
+            0: {
+                4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
+                3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
+            },
+        },
+    }
 
-    def reduce_sec(self, event, msg):
-        if self.sec > 0:
-            self.sec = self.sec - 1
 
-    def add_min(self, event, msg):
-        if self.min < 59:
-            self.min = self.min + 1
 
-    def reduce_min(self, event, msg):
-        if self.min > 0:
-            self.min = self.min - 1
+    class Battery(object):
+        """This class is for battery info.
 
-    def add_hour(self, event, msg):
-        if self.hour < 99:
-            self.hour = self.hour + 1
+        This class can get battery voltage and energy.
+        if adc_args is not None, use cbc to read battery
 
-    def reduce_hour(self, event, msg):
-        if self.hour > 0:
-            self.hour = self.hour - 1
+        adc_args: (adc_num, adc_period, factor)
 
-    def get_sec(self, event=None, msg=None):
-        return self.sec
+            adc_num: ADC channel num
+            adc_period: Cyclic read ADC cycle period
+            factor: calculation coefficient
+        """
 
-    def get_min(self, event=None, msg=None):
-        return self.min
+        def __init__(self, adc_args=None, chrg_gpion=None, stdby_gpion=None):
+            self.__energy = 100
+            self.__temp = 55
+
+            # ADC params
+            self.__adc = None
+            if adc_args:
+                self.__adc_num, self.__adc_period, self.__factor = adc_args
+                if not isinstance(self.__adc_num, int):
+                    raise TypeError("adc_args adc_num is not int number.")
+                if not isinstance(self.__adc_period, int):
+                    raise TypeError("adc_args adc_period is not int number.")
+                if not isinstance(self.__factor, float):
+                    raise TypeError("adc_args factor is not int float.")
+                self.__adc = ADC()
+
+            # Charge params
+            self.__charge_callback = None
+            self.__charge_status = None
+            self.__chrg_gpion = chrg_gpion
+            self.__stdby_gpion = stdby_gpion
+            self.__chrg_gpio = None
+            self.__stdby_gpio = None
+            self.__chrg_exint = None
+            self.__stdby_exint = None
+            if self.__chrg_gpion is not None and self.__stdby_gpion is not None:
+                self.__init_charge()
+
+        def __chrg_callback(self, args):
+            self.__update_charge_status()
+            if self.__charge_callback is not None:
+                self.__charge_callback(self.__charge_status)
+
+        def __stdby_callback(self, args):
+            self.__update_charge_status()
+            if self.__charge_callback is not None:
+                self.__charge_callback(self.__charge_status)
+
+        def __update_charge_status(self):
+            if self.__chrg_gpio.read() == 1 and self.__stdby_gpio.read() == 1:
+                self.__charge_status = 0
+            elif self.__chrg_gpio.read() == 0 and self.__stdby_gpio.read() == 1:
+                self.__charge_status = 1
+            elif self.__chrg_gpio.read() == 1 and self.__stdby_gpio.read() == 0:
+                self.__charge_status = 2
+            else:
+                raise TypeError("CHRG and STDBY cannot be 0 at the same time!")
+
+        def __init_charge(self):
+            self.__chrg_gpio = Pin(self.__chrg_gpion, Pin.IN, Pin.PULL_DISABLE)
+            self.__stdby_gpio = Pin(self.__stdby_gpion, Pin.IN, Pin.PULL_DISABLE)
+            self.__chrg_exint = ExtInt(self.__chrg_gpion, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.__chrg_callback)
+            self.__stdby_exint = ExtInt(self.__stdby_gpion, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU,
+                                        self.__stdby_callback)
+            self.__chrg_exint.enable()
+            self.__stdby_exint.enable()
+            self.__update_charge_status()
+
+        def __get_soc_from_dict(self, key, volt_arg):
+            """Get battery energy from map"""
+            if key in BATTERY_OCV_TABLE["nix_coy_mnzo2"]:
+                volts = sorted(BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].keys(), reverse=True)
+                pre_volt = 0
+                volt_not_under = 0  # Determine whether the voltage is lower than the minimum voltage value of soc.
+                for volt in volts:
+                    if volt_arg > volt:
+                        volt_not_under = 1
+                        soc1 = BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].get(volt, 0)
+                        soc2 = BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].get(pre_volt, 0)
+                        break
+                    else:
+                        pre_volt = volt
+                # EventMesh.debug_log("__get_soc_from_dict:{}".format(soc2 - (soc2 - soc1) * (pre_volt - volt_arg) // (pre_volt - volt)))
+                if pre_volt == 0:  # Input Voltarg > Highest Voltarg
+                    return soc1
+                elif volt_not_under == 0:
+                    return 0
+                else:
+                    return soc2 - (soc2 - soc1) * (pre_volt - volt_arg) // (pre_volt - volt)
+
+        def __get_soc(self, temp, volt_arg, bat_type="nix_coy_mnzo2"):
+            """Get battery energy by temperature and voltage"""
+            if bat_type == "nix_coy_mnzo2":
+                if temp > 30:
+                    return self.__get_soc_from_dict(55, volt_arg)
+                elif temp < 10:
+                    return self.__get_soc_from_dict(0, volt_arg)
+                else:
+                    return self.__get_soc_from_dict(20, volt_arg)
 
-    def get_hour(self, event=None, msg=None):
-        return self.hour
-    
+        def __get_power_vbatt(self):
+            return int(sum([Power.getVbatt() for i in range(100)]) / 100)
 
-    
-    def reset(self, event=None, msg=None):
-        self.hour = 0
-        self.min = 0
-        self.sec = 0
-    
-    
+        def __get_adc_vbatt(self):
+            self.__adc.open()
+            utime.sleep_ms(self.__adc_period)
+            adc_list = list()
+            for i in range(self.__adc_period):
+                adc_list.append(self.__adc.read(self.__adc_num))
+                utime.sleep_ms(self.__adc_period)
+            adc_list.remove(min(adc_list))
+            adc_list.remove(max(adc_list))
+            adc_value = int(sum(adc_list) / len(adc_list))
+            self.__adc.close()
+            vbatt_value = adc_value * (self.__factor + 1)
+            return vbatt_value
+
+        def set_temp(self, temp):
+            """Set now temperature."""
+            if isinstance(temp, int) or isinstance(temp, float):
+                self.__temp = temp
+                return True
+            return False
 
-BATTERY_OCV_TABLE = {
-    "nix_coy_mnzo2": {
-        55: {
-            4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
-            3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
-        },
-        20: {
-            4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
-            3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
-        },
-        0: {
-            4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
-            3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
-        },
-    },
-}
-
-
-
-class Battery(object):
-    """This class is for battery info.
-
-    This class can get battery voltage and energy.
-    if adc_args is not None, use cbc to read battery
-
-    adc_args: (adc_num, adc_period, factor)
-
-        adc_num: ADC channel num
-        adc_period: Cyclic read ADC cycle period
-        factor: calculation coefficient
-    """
-
-    def __init__(self, adc_args=None, chrg_gpion=None, stdby_gpion=None):
-        self.__energy = 100
-        self.__temp = 55
-
-        # ADC params
-        self.__adc = None
-        if adc_args:
-            self.__adc_num, self.__adc_period, self.__factor = adc_args
-            if not isinstance(self.__adc_num, int):
-                raise TypeError("adc_args adc_num is not int number.")
-            if not isinstance(self.__adc_period, int):
-                raise TypeError("adc_args adc_period is not int number.")
-            if not isinstance(self.__factor, float):
-                raise TypeError("adc_args factor is not int float.")
-            self.__adc = ADC()
-
-        # Charge params
-        self.__charge_callback = None
-        self.__charge_status = None
-        self.__chrg_gpion = chrg_gpion
-        self.__stdby_gpion = stdby_gpion
-        self.__chrg_gpio = None
-        self.__stdby_gpio = None
-        self.__chrg_exint = None
-        self.__stdby_exint = None
-        if self.__chrg_gpion is not None and self.__stdby_gpion is not None:
-            self.__init_charge()
-
-    def __chrg_callback(self, args):
-        self.__update_charge_status()
-        if self.__charge_callback is not None:
-            self.__charge_callback(self.__charge_status)
-
-    def __stdby_callback(self, args):
-        self.__update_charge_status()
-        if self.__charge_callback is not None:
-            self.__charge_callback(self.__charge_status)
-
-    def __update_charge_status(self):
-        if self.__chrg_gpio.read() == 1 and self.__stdby_gpio.read() == 1:
-            self.__charge_status = 0
-        elif self.__chrg_gpio.read() == 0 and self.__stdby_gpio.read() == 1:
-            self.__charge_status = 1
-        elif self.__chrg_gpio.read() == 1 and self.__stdby_gpio.read() == 0:
-            self.__charge_status = 2
-        else:
-            raise TypeError("CHRG and STDBY cannot be 0 at the same time!")
-
-    def __init_charge(self):
-        self.__chrg_gpio = Pin(self.__chrg_gpion, Pin.IN, Pin.PULL_DISABLE)
-        self.__stdby_gpio = Pin(self.__stdby_gpion, Pin.IN, Pin.PULL_DISABLE)
-        self.__chrg_exint = ExtInt(self.__chrg_gpion, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.__chrg_callback)
-        self.__stdby_exint = ExtInt(self.__stdby_gpion, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU,
-                                    self.__stdby_callback)
-        self.__chrg_exint.enable()
-        self.__stdby_exint.enable()
-        self.__update_charge_status()
-
-    def __get_soc_from_dict(self, key, volt_arg):
-        """Get battery energy from map"""
-        if key in BATTERY_OCV_TABLE["nix_coy_mnzo2"]:
-            volts = sorted(BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].keys(), reverse=True)
-            pre_volt = 0
-            volt_not_under = 0  # Determine whether the voltage is lower than the minimum voltage value of soc.
-            for volt in volts:
-                if volt_arg > volt:
-                    volt_not_under = 1
-                    soc1 = BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].get(volt, 0)
-                    soc2 = BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].get(pre_volt, 0)
-                    break
-                else:
-                    pre_volt = volt
-            # EventMesh.debug_log("__get_soc_from_dict:{}".format(soc2 - (soc2 - soc1) * (pre_volt - volt_arg) // (pre_volt - volt)))
-            if pre_volt == 0:  # Input Voltarg > Highest Voltarg
-                return soc1
-            elif volt_not_under == 0:
-                return 0
+        def get_voltage(self):
+            """Get battery voltage"""
+            if self.__adc is None:
+                return self.__get_power_vbatt()
             else:
-                return soc2 - (soc2 - soc1) * (pre_volt - volt_arg) // (pre_volt - volt)
-
-    def __get_soc(self, temp, volt_arg, bat_type="nix_coy_mnzo2"):
-        """Get battery energy by temperature and voltage"""
-        if bat_type == "nix_coy_mnzo2":
-            if temp > 30:
-                return self.__get_soc_from_dict(55, volt_arg)
-            elif temp < 10:
-                return self.__get_soc_from_dict(0, volt_arg)
+                return self.__get_adc_vbatt()
+
+        def get_energy(self,volt_arg ):
+            """Get battery energy"""
+            if( volt_arg == None) :
+                volt_arg = self.get_voltage()
+            self.__energy = self.__get_soc(self.__temp, volt_arg)
+            # EventMesh.debug_log("get_energy:volt_arg {} __energy{}".format(volt_arg,self.__energy))
+            return self.__energy
+
+        def set_charge_callback(self, charge_callback):
+            if self.__chrg_gpion is not None and self.__stdby_gpion is not None:
+                if callable(charge_callback):
+                    self.__charge_callback = charge_callback
+                    return True
+            return False
+
+        def get_charge_status(self):
+            return self.__charge_status
+
+    class BatteryManager(Abstract):
+        def __init__(self):
+            """电池管理器"""
+            self.battery = Battery()
+            self.low_battery = False
+
+        def post_processor_after_instantiation(self):
+            """订阅此类所有的事件到 EventMesh中"""
+            EventMesh.subscribe("get_battery", self.get_battery)
+
+        def get_battery(self, event=None, msg=None):
+            battery = self.battery.get_energy(msg)
+            return battery
+
+        def get_voltage(self, event=None, msg=None):
+            voltage = self.battery.get_voltage()
+            return voltage
+
+    class ConfigStoreManager(Abstract):
+        """
+        持久化落盘存储
+        """
+
+        def __init__(self):
+            self.file_name = "/usr/conf_store.json"
+            self.lock = Lock()
+            self.map = dict()
+
+        def post_processor_after_instantiation(self):
+            if ql_fs.path_exists(self.file_name):
+                self.map = ql_fs.read_json(self.file_name)
             else:
-                return self.__get_soc_from_dict(20, volt_arg)
+                self.__store()
+            EventMesh.subscribe("persistent_config_get", self.__read)
+            EventMesh.subscribe("persistent_config_store", self.__store)
+
+        def __read(self, event, msg):
+            with self.lock:
+                return self.map.get(msg)
+
+        def __store(self, event=None, msg=None):
+            if msg is None:
+                msg = dict()
+            with self.lock:
+                self.map.update(msg)
+                ql_fs.touch(self.file_name, self.map)
+            
+    class sosInfoCallManager(Abstract):
+        # 通讯录
+        def __init__(self):
+            pass
 
-    def __get_power_vbatt(self):
-        return int(sum([Power.getVbatt() for i in range(100)]) / 100)
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_sos_info_call", self.set_sos_info_call)
+
+        def set_sos_info_call(self, event, msg):
+            hangup_mode = EventMesh.publish("get_hangup_mode")
+            if hangup_mode == 1:
+                EventMesh.publish("set_sos_flag",0)
+                EventMesh.publish("set_sos_num",0)
+                EventMesh.publish("set_hangup_mode",0)
+            EventMesh.debug_log('hangup_mode disconnect',hangup_mode)
+            sos_flag = EventMesh.publish("get_sos_flag")
+            EventMesh.debug_log('voicecall sos_flag',sos_flag)
+            if sos_flag == 0 :
+                EventMesh.publish("set_sos_num",0)
+            else:
+                num = EventMesh.publish("get_sos_num")
+                number = EventMesh.publish("get_dial_sos_number")
+                if number != None:
+                    if len(number) > 0:
+                        if num == None:
+                            num = 0
+                        num+=1
+                        num_len = 0
 
-    def __get_adc_vbatt(self):
-        self.__adc.open()
-        utime.sleep_ms(self.__adc_period)
-        adc_list = list()
-        for i in range(self.__adc_period):
-            adc_list.append(self.__adc.read(self.__adc_num))
-            utime.sleep_ms(self.__adc_period)
-        adc_list.remove(min(adc_list))
-        adc_list.remove(max(adc_list))
-        adc_value = int(sum(adc_list) / len(adc_list))
-        self.__adc.close()
-        vbatt_value = adc_value * (self.__factor + 1)
-        return vbatt_value
-
-    def set_temp(self, temp):
-        """Set now temperature."""
-        if isinstance(temp, int) or isinstance(temp, float):
-            self.__temp = temp
-            return True
-        return False
-
-    def get_voltage(self):
-        """Get battery voltage"""
-        if self.__adc is None:
-            return self.__get_power_vbatt()
-        else:
-            return self.__get_adc_vbatt()
-
-    def get_energy(self,volt_arg ):
-        """Get battery energy"""
-        if( volt_arg == None) :
-            volt_arg = self.get_voltage()
-        self.__energy = self.__get_soc(self.__temp, volt_arg)
-        # EventMesh.debug_log("get_energy:volt_arg {} __energy{}".format(volt_arg,self.__energy))
-        return self.__energy
-
-    def set_charge_callback(self, charge_callback):
-        if self.__chrg_gpion is not None and self.__stdby_gpion is not None:
-            if callable(charge_callback):
-                self.__charge_callback = charge_callback
-                return True
-        return False
-
-    def get_charge_status(self):
-        return self.__charge_status
-
-class BatteryManager(Abstract):
-    def __init__(self):
-        """电池管理器"""
-        self.battery = Battery()
-        self.low_battery = False
-
-    def post_processor_after_instantiation(self):
-        """订阅此类所有的事件到 EventMesh中"""
-        EventMesh.subscribe("get_battery", self.get_battery)
-
-    def get_battery(self, event=None, msg=None):
-        battery = self.battery.get_energy(msg)
-        return battery
-
-    def get_voltage(self, event=None, msg=None):
-        voltage = self.battery.get_voltage()
-        return voltage
-
-class ConfigStoreManager(Abstract):
-    """
-    持久化落盘存储
-    """
-
-    def __init__(self):
-        self.file_name = "/usr/conf_store.json"
-        self.lock = Lock()
-        self.map = dict()
-
-    def post_processor_after_instantiation(self):
-        if ql_fs.path_exists(self.file_name):
-            self.map = ql_fs.read_json(self.file_name)
-        else:
-            self.__store()
-        EventMesh.subscribe("persistent_config_get", self.__read)
-        EventMesh.subscribe("persistent_config_store", self.__store)
-
-    def __read(self, event, msg):
-        with self.lock:
-            return self.map.get(msg)
-
-    def __store(self, event=None, msg=None):
-        if msg is None:
-            msg = dict()
-        with self.lock:
-            self.map.update(msg)
-            ql_fs.touch(self.file_name, self.map)
-        
-class sosInfoCallManager(Abstract):
-    # 通讯录
-    def __init__(self):
-        pass
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_sos_info_call", self.set_sos_info_call)
-
-    def set_sos_info_call(self, event, msg):
-        hangup_mode = EventMesh.publish("get_hangup_mode")
-        if hangup_mode == 1:
-            EventMesh.publish("set_sos_flag",0)
-            EventMesh.publish("set_sos_num",0)
-            EventMesh.publish("set_hangup_mode",0)
-        EventMesh.debug_log('hangup_mode disconnect',hangup_mode)
-        sos_flag = EventMesh.publish("get_sos_flag")
-        EventMesh.debug_log('voicecall sos_flag',sos_flag)
-        if sos_flag == 0 :
-            EventMesh.publish("set_sos_num",0)
-        else:
-            num = EventMesh.publish("get_sos_num")
-            number = EventMesh.publish("get_dial_sos_number")
-            if number != None:
-                if len(number) > 0:
-                    if num == None:
-                        num = 0
-                    num+=1
-                    num_len = 0
-
-                    if len(number) == 1:
-                        num_len = len(number)
-                    elif len(number) == 2:
-                        num_len = len(number)+1
-                    elif len(number) == 3:
-                        num_len = len(number)+2  
-                    # EventMesh.debug_log("number:{} number_len :{} num:{} num_len:{}".format(number,len(number),num,num_len))
-                    if num > num_len :
                         if len(number) == 1:
-                            number1 = str(number[0])
-                            sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+                            num_len = len(number)
                         elif len(number) == 2:
-                            number1 = str(number[0])
-                            sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
-
-                            number2 = str(number[1])
-                            sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
+                            num_len = len(number)+1
                         elif len(number) == 3:
-                            number1 = str(number[0])
-                            sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
-                            number2 = str(number[1])
-                            sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
-                            number3 = str(number[2])
-                            sms.sendPduMsg(number3, '我需要你的帮助', 'UCS2')
-                        EventMesh.publish("set_sos_flag",0)
-                        EventMesh.publish("set_sos_num",0)
-                    else:
-                    # EventMesh.debug_log("number:{} number_len :{}".format(number,len(number)))
-                        EventMesh.publish("set_sos_num",num)
-                        if len(number) == 1:
-                            if len(number[0]) != 0:
-                                EventMesh.publish("set_callnumer_cb",number[0])
-                                EventMesh.debug_log("phone 1")
-                        elif len(number) == 2:
-                            if num == 1 or num == 3:
-                                if len(number[1]) != 0:
-                                    EventMesh.debug_log("phone 2")
-                                    EventMesh.publish("set_callnumer_cb",number[1])
-                            elif num == 2:
+                            num_len = len(number)+2  
+                        # EventMesh.debug_log("number:{} number_len :{} num:{} num_len:{}".format(number,len(number),num,num_len))
+                        if num > num_len :
+                            if len(number) == 1:
+                                number1 = str(number[0])
+                                sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+                            elif len(number) == 2:
+                                number1 = str(number[0])
+                                sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+
+                                number2 = str(number[1])
+                                sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
+                            elif len(number) == 3:
+                                number1 = str(number[0])
+                                sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+                                number2 = str(number[1])
+                                sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
+                                number3 = str(number[2])
+                                sms.sendPduMsg(number3, '我需要你的帮助', 'UCS2')
+                            EventMesh.publish("set_sos_flag",0)
+                            EventMesh.publish("set_sos_num",0)
+                        else:
+                        # EventMesh.debug_log("number:{} number_len :{}".format(number,len(number)))
+                            EventMesh.publish("set_sos_num",num)
+                            if len(number) == 1:
                                 if len(number[0]) != 0:
-                                    EventMesh.debug_log("phone 3")
                                     EventMesh.publish("set_callnumer_cb",number[0])
-                        elif len(number) == 3:
-                            if num == 1 or num == 4:
-                                if len(number[1]) != 0:
-                                    EventMesh.publish("set_callnumer_cb",number[1])
-                                    EventMesh.debug_log("phone 4")
-                            elif num == 2 or num == 5:
-                                if len(number[2]) != 0:
-                                    EventMesh.debug_log("phone 5")
-                                    EventMesh.publish("set_callnumer_cb",number[2])
-                            elif num == 3:
-                                if len(number[0]) != 0:
-                                    EventMesh.debug_log("phone 6")
-                                    EventMesh.publish("set_callnumer_cb",number[0])   
-WL_timer = osTimer()   
-def WL_timer_cb(*args):   
-    get_call = EventMesh.publish("get_call_state") 
-    if get_call == 2:#只有拨进来才给接听
-        EventMesh.publish("answer_call_event")#接听电话
-def voice_callback(args):
-   EventMesh.debug_log('voicecall iinfo:{}'.format(args))
-   if args[0] == 10:
-        get_UI_high_priority = EventMesh.publish("get_UI_high_priority")#如果在拨出去或者通话中屏蔽来电
-        if get_UI_high_priority == 1:
-            EventMesh.publish("set_interrup_incall",1)
-            return
-        EventMesh.debug_log('voicecall incoming call, PhoneNO.: ', args[6])
-        size_len = len(str(args[6]))
-        tmp = []
-        tmp = args[6]
-        find_num = tmp[0]
-        b = tmp[0].isdigit()#判断是否不是数字开头 暂时不用 因为截取了+判断不了 判断号码是否大于11位数,如果大于11位数 并且第一个字符是数字就按照最后11位做存储
-
-        if b == True and size_len > 11:
-            tmp = tmp[size_len-11:]
-        WLKEY = EventMesh.publish("get_storage_config","WLKEY") 
-        if WLKEY == "1" or WLKEY == "2":#开启了白名单
-            on_list_flag = 0
-            phonebook = EventMesh.publish("get_phonebook_list")
-            phonebook_list = phonebook[1]
-            EventMesh.debug_log("voice_callback:phonebook_list{}".format(phonebook_list))
-            try:
-                for value in phonebook_list.values():
-                    if value == args[6]:
-                        on_list_flag = 1
-                        break
-            except Exception as e:
-                usys.print_exception(e)
-            EventMesh.debug_log("voice_callback:on_list_flag{}".format(on_list_flag))
-            if on_list_flag == 1:#在白名单里
-                if WLKEY == "2":
-                    WL_timer.start(30000, 0, WL_timer_cb)
-            else:
-                EventMesh.debug_log("voice_callback:不在白名单中,挂断")
-                voiceCall.callEnd()
-                return 
-        EventMesh.publish("set_call_state",2) 
-        EventMesh.publish("dialin_call_event")#电话拨进响铃
-        # EventMesh.publish("load_screen", {"screen": "incoming_call","meta":str(tmp)})
-
-   elif args[0] == 11:
-        EventMesh.publish("set_UI_high_priority",0)
-        sos_flag = EventMesh.publish("get_sos_flag")
-        if sos_flag == 1:
-            sos_flag = 0
-            EventMesh.publish("set_sos_flag",0)
-
-        EventMesh.debug_log('voicecall connected, PhoneNO.: ', args[6])
-        size_len = len(str(args[6]))
-        tmp = []
-        tmp = args[6]
-        find_num = tmp[0]
-        b = tmp[0].isdigit()#判断是否不是数字开头 暂时不用 因为截取了+判断不了
-        if b == True and size_len > 11:
-            tmp = tmp[size_len-11:]
-        EventMesh.publish("set_call_state",3) 
-        # EventMesh.publish("load_screen", {"screen": "on_call","meta":str(tmp)})
-
-   elif args[0] == 12:
-        set_interrup_call = EventMesh.publish("get_interrup_incall")#打断这次不需要来电的ui事件 以免通话中退出当前界面进不去了
-        if set_interrup_call == 1:
-            EventMesh.publish("set_interrup_incall",0)
-            return
+                                    EventMesh.debug_log("phone 1")
+                            elif len(number) == 2:
+                                if num == 1 or num == 3:
+                                    if len(number[1]) != 0:
+                                        EventMesh.debug_log("phone 2")
+                                        EventMesh.publish("set_callnumer_cb",number[1])
+                                elif num == 2:
+                                    if len(number[0]) != 0:
+                                        EventMesh.debug_log("phone 3")
+                                        EventMesh.publish("set_callnumer_cb",number[0])
+                            elif len(number) == 3:
+                                if num == 1 or num == 4:
+                                    if len(number[1]) != 0:
+                                        EventMesh.publish("set_callnumer_cb",number[1])
+                                        EventMesh.debug_log("phone 4")
+                                elif num == 2 or num == 5:
+                                    if len(number[2]) != 0:
+                                        EventMesh.debug_log("phone 5")
+                                        EventMesh.publish("set_callnumer_cb",number[2])
+                                elif num == 3:
+                                    if len(number[0]) != 0:
+                                        EventMesh.debug_log("phone 6")
+                                        EventMesh.publish("set_callnumer_cb",number[0])   
+    WL_timer = osTimer()   
+    def WL_timer_cb(*args):   
+        get_call = EventMesh.publish("get_call_state") 
+        if get_call == 2:#只有拨进来才给接听
+            EventMesh.publish("answer_call_event")#接听电话
+    def voice_callback(args):
+        EventMesh.debug_log('voicecall iinfo:{}'.format(args))
+        if args[0] == 10:
+                get_UI_high_priority = EventMesh.publish("get_UI_high_priority")#如果在拨出去或者通话中屏蔽来电
+                if get_UI_high_priority == 1:
+                    EventMesh.publish("set_interrup_incall",1)
+                    return
+                EventMesh.debug_log('voicecall incoming call, PhoneNO.: ', args[6])
+                size_len = len(str(args[6]))
+                tmp = []
+                tmp = args[6]
+                find_num = tmp[0]
+                b = tmp[0].isdigit()#判断是否不是数字开头 暂时不用 因为截取了+判断不了 判断号码是否大于11位数,如果大于11位数 并且第一个字符是数字就按照最后11位做存储
+
+                if b == True and size_len > 11:
+                    tmp = tmp[size_len-11:]
+                WLKEY = EventMesh.publish("get_storage_config","WLKEY") 
+                if WLKEY == "1" or WLKEY == "2":#开启了白名单
+                    on_list_flag = 0
+                    phonebook = EventMesh.publish("get_phonebook_list")
+                    phonebook_list = phonebook[1]
+                    EventMesh.debug_log("voice_callback:phonebook_list{}".format(phonebook_list))
+                    try:
+                        for value in phonebook_list.values():
+                            if value == args[6]:
+                                on_list_flag = 1
+                                break
+                    except Exception as e:
+                        usys.print_exception(e)
+                    EventMesh.debug_log("voice_callback:on_list_flag{}".format(on_list_flag))
+                    if on_list_flag == 1:#在白名单里
+                        if WLKEY == "2":
+                            WL_timer.start(30000, 0, WL_timer_cb)
+                    else:
+                        EventMesh.debug_log("voice_callback:不在白名单中,挂断")
+                        voiceCall.callEnd()
+                        return 
+                fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
+                if fall_down != 0:
+                    voiceCall.callEnd()
+                    return
+                EventMesh.publish("set_call_state",2) 
+                EventMesh.publish("dialin_call_event")#电话拨进响铃
+                # EventMesh.publish("load_screen", {"screen": "incoming_call","meta":str(tmp)})
+
+        elif args[0] == 11:
+                EventMesh.publish("set_UI_high_priority",0)
+                sos_flag = EventMesh.publish("get_sos_flag")
+                if sos_flag == 1:
+                    sos_flag = 0
+                    EventMesh.publish("set_sos_flag",0)
+
+                EventMesh.debug_log('voicecall connected, PhoneNO.: ', args[6])
+                size_len = len(str(args[6]))
+                tmp = []
+                tmp = args[6]
+                find_num = tmp[0]
+                b = tmp[0].isdigit()#判断是否不是数字开头 暂时不用 因为截取了+判断不了
+                if b == True and size_len > 11:
+                    tmp = tmp[size_len-11:]
+                EventMesh.publish("set_call_state",3) 
+                # EventMesh.publish("load_screen", {"screen": "on_call","meta":str(tmp)})
+
+        elif args[0] == 12:
+                set_interrup_call = EventMesh.publish("get_interrup_incall")#打断这次不需要来电的ui事件 以免通话中退出当前界面进不去了
+                if set_interrup_call == 1:
+                    EventMesh.publish("set_interrup_incall",0)
+                    return
+
+                EventMesh.publish("set_interrup_incall",0)
+                EventMesh.publish("set_UI_high_priority",0)
+                
 
-        EventMesh.publish("set_interrup_incall",0)
-        EventMesh.publish("set_UI_high_priority",0)
-        
+                
+                
+                EventMesh.publish("set_sos_info_call")  
+                flag = EventMesh.publish("get_call_state") 
+                if flag == 2:
+                    EventMesh.publish("stop_led_timer")#设置参数
+                    EventMesh.publish("close_timer_all")#
+                EventMesh.publish("set_call_state",0) 
+                EventMesh.debug_log('voicecall disconnect end')
+                
 
-         
-        
-        EventMesh.publish("set_sos_info_call")  
-        flag = EventMesh.publish("get_call_state") 
-        if flag == 2:
-            EventMesh.publish("stop_led_timer")#设置参数
-            EventMesh.publish("close_timer_all")#
-        EventMesh.publish("set_call_state",0) 
-        EventMesh.debug_log('voicecall disconnect end')
-        
+        elif args[0] == 13:
+                EventMesh.debug_log('voicecall is waiting, PhoneNO.: ', args[6])
+        elif args[0] == 14:
 
-   elif args[0] == 13:
-        EventMesh.debug_log('voicecall is waiting, PhoneNO.: ', args[6])
-   elif args[0] == 14:
+                EventMesh.debug_log('voicecall dialing, PhoneNO.: ', args[6])
+                EventMesh.publish("set_UI_high_priority",0)
+                EventMesh.publish("set_call_state",1) 
+                # EventMesh.publish("load_screen", {"screen": "dialing"})
 
-        EventMesh.debug_log('voicecall dialing, PhoneNO.: ', args[6])
-        EventMesh.publish("set_UI_high_priority",0)
-        EventMesh.publish("set_call_state",1) 
-        # EventMesh.publish("load_screen", {"screen": "dialing"})
+                
+        elif args[0] == 15:
+                EventMesh.debug_log('voicecall alerting, PhoneNO.: ', args[6])
+                EventMesh.publish("set_call_state",1) 
+                
+        elif args[0] == 16:
+                EventMesh.debug_log('voicecall holding, PhoneNO.: ', args[6])
 
+    class DeviceInfoManager(Abstract):
         
-   elif args[0] == 15:
-        EventMesh.debug_log('voicecall alerting, PhoneNO.: ', args[6])
-        EventMesh.publish("set_call_state",1) 
-        
-   elif args[0] == 16:
-        EventMesh.debug_log('voicecall holding, PhoneNO.: ', args[6])
+        """
+            设备信息管理
+        """
 
-class DeviceInfoManager(Abstract):
-    
-    """
-        设备信息管理
-    """
-
-    def __init__(self):
-
-        self.DeviceInfo_queue = Queue()
-        _thread.stack_size((9+6)*1024)
-        _thread.start_new_thread(self.DeviceInfo_queue_thread, ())
-        _thread.stack_size(8*1024)
-        self.boot_time_count = 0
-        EventMesh.subscribe("publish_message_event_DeviceInfo",self.publish_message_event_DeviceInfo)
-        self.key = ""
-        self.imei = ""
-        self.cid = "ETEST20221014010"
-        self.imsi = ""
-        self.password = "000000"
-        #self.__city = None
-        #self.__location = None
-        self.timer_push_schedule = osTimer()
-        self.timer_pusht_test = osTimer()
-        
-        #self.battery_push_schedule = osTimer()
-        self.check_battery_list = []
-        
-        self.step = [0,0,0,0]
-        self.timer_push=0
-        self.timer_push_tmp=60
-        self.PING = "0" #绑定状态
-        self.connect = 0 #服务器连接状态
-        self.KA_time = 0
-        self.HR_time = 0
-        self.SENSOR_time = 0
-        self.HR_state = 0
-        self.HR_Onestate = 0
-        self.get_hr_state = 0
-        self.get_spo2_state = 0
-        self.set_hsenor_crt = 0
-        self.HR_OneTime = 0
-        self.Hr_Need_Open = 0
-        self.Spo2_Need_Open = 0
-        self.bat_time = 0
-        self.vbat_full_flag = 0
-        self.clear_step = 0
-        self.test = 0
-        self.old_time = 0
-        self.UD_time = 0
-        self.upload_time = 0
-        self.UD_timeout = 7*60
-
-        self.temp_time = 0
-        self.temp_state = 0
-        self.temp_one_state = 0
-        self.temp_warning = 0
-
-        self.bg_times = 0
-
-        self.bp_timeSecond = 0
-        self.bpauto_state = 0
-
-        self.spo2_timeSecond = 0
-        self.spo2auto_state = 0
-
-        self.vbat_count = 0
-
-        self.vbat_buf=[]
-
-        self.curr_battery_level = 4200
-        self.bat_count = 0
-
-        self.mearsure_btn = 0
-        self.mearsure_timer = 0
-
-        self.old_hr_time = 0
-        self.old_spo2_time = 0
-
-        self.no_smi_count = 0
-        self.no_smi_state = 0
-
-        self.old_bp_time = 0
-
-        self.medicine_count = 0
-        self.medicine_flag  = 0
-        self.medicine_oldtotalmin = 0
-        
-        self.wakeup_flag = 0
-        self.wakeup_count = 0
-        self.wakeup_oldtotalmin = 0
+        def __init__(self):
+
+            self.DeviceInfo_queue = Queue()
+            _thread.stack_size((9+6)*1024)
+            _thread.start_new_thread(self.DeviceInfo_queue_thread, ())
+            _thread.stack_size(8*1024)
+            self.boot_time_count = 0
+            EventMesh.subscribe("publish_message_event_DeviceInfo",self.publish_message_event_DeviceInfo)
+            self.key = ""
+            self.imei = ""
+            self.cid = "ETEST20221014010"
+            self.imsi = ""
+            self.password = "000000"
+            #self.__city = None
+            #self.__location = None
+            self.timer_push_schedule = osTimer()
+            self.timer_pusht_test = osTimer()
+            
+            #self.battery_push_schedule = osTimer()
+            self.check_battery_list = []
+            
+            self.step = [0,0,0,0]
+            self.timer_push=0
+            self.timer_push_tmp=60
+            self.PING = "0" #绑定状态
+            self.connect = 0 #服务器连接状态
+            self.KA_time = 0
+            self.HR_time = 0
+            self.SENSOR_time = 0
+            self.HR_state = 0
+            self.HR_Onestate = 0
+            self.get_hr_state = 0
+            self.get_spo2_state = 0
+            self.set_hsenor_crt = 0
+            self.HR_OneTime = 0
+            self.Hr_Need_Open = 0
+            self.Spo2_Need_Open = 0
+            self.bat_time = 0
+            self.vbat_full_flag = 0
+            self.clear_step = 0
+            self.test = 0
+            self.old_time = 0
+            self.UD_time = 0
+            self.upload_time = 0
+            self.UD_timeout = 7*60
 
-        self.sleep_flag = 0
-        self.sleep_count = 0
-        self.sleep_oldtotalmin = 0
+            self.temp_time = 0
+            self.temp_state = 0
+            self.temp_one_state = 0
+            self.temp_warning = 0
 
-        self.reset_flag = 0
-        self.reset_count = 0
-        self.reset_oldtotalmin = 0
+            self.bg_times = 0
 
-        self.home_flag = 0
-        self.home_count = 0
-        self.home_oldtotalmin = 0
+            self.bp_timeSecond = 0
+            self.bpauto_state = 0
 
-        self.normal_flag = 0
-        self.normal_count = 0
-        self.normal_oldtotalmin = 0
-        
-        self.charge_full_count = 0
-        self.GPS_step_t = 0#记录步数
-        self.usb = USB()
-        self.usb.setCallback(self.usb_event_cb)
-        self.log = LogAdapter(self.__class__.__name__)
-        self.rtc = RTC()
-        self.aud = audio.Audio(0)
-        EventMesh.debug_log("DeviceInfoManager:1")
-        self.gsensor = SC7A20()
-        EventMesh.debug_log("DeviceInfoManager:1.0")
-        self.gsensor.activate()
-        EventMesh.debug_log("DeviceInfoManager:1.1")
-        self.gsensor.init()
-        EventMesh.debug_log("DeviceInfoManager:2")
-        self.gsensor.set_callback(self.gsensor_cb)
-        try :
-            self.hsensor = HX3918()
-            
-        except Exception as e:
-            EventMesh.debug_log("Hsensor none HX3918:{}".format(e))   
-        try :
-            self.hsensor = GH3018()
-        except Exception as e:
-            EventMesh.debug_log("Hsensor none GH3018:{}".format(e))   
-        #
-        self.hsensor.activate()
-        self.hsensor.init()
-        self.hsensor.close()
-        try :
-            self.hsensor.set_sar(1)
-        except Exception as e:
-            EventMesh.debug_log("Hsensor none set_sar:{}".format(e)) 
-        self.old_temp_time = 0
-        # #EventMesh.debug_log("hsensor.open_heart:%d\r\n"%(self.hsensor.open_heart()))
-        EventMesh.debug_log("DeviceInfoManager:3")
-        self.i2c0 = I2C(I2C.I2C0, I2C.FAST_MODE)
-        self.stop_temp( None, None)
-        self.dev_state = 0
-        self.wear = 1
-        self.BG_state = 0
-        self.old_bg_time = 0
-
-        self.pull_time = 0
-
-        self.drink_time = 0
-
-        self.alarm_count = 0
-        self.alarm_flag = 0
-
-        self.time_count = 0
-        
-        self.auto_spo2_count = 0
-
-        self.auto_hr_count = 0
-
-        self.auto_temp_count = 0
-
-       
-
-    def post_processor_after_instantiation(self):
-        EventMesh.debug_log("post_processor_after_instantiation:1")
-        """订阅此类所有的事件到 EventMesh中"""
-        voiceCall.setCallback(voice_callback)
-        EventMesh.subscribe("screen_get_ope", self.get_device_ope)
-        EventMesh.subscribe("screen_get_sig", self.get_signal)
-        EventMesh.subscribe("screen_get_time", self.get_time)
-        EventMesh.subscribe("about_get_imei", self.get_imei)
-        EventMesh.subscribe("about_get_iccid", self.get_ic_cid)
-        EventMesh.subscribe("get_sim_Status", self.get_sim_Status)
-        EventMesh.subscribe("about_get_phonenum", self.get_phone_num)
-        EventMesh.subscribe("screen_get_battery", self.get_battery)
-        EventMesh.subscribe("set_curr_battery_level", self.set_curr_battery_level)
-        EventMesh.subscribe("get_curr_battery_level", self.get_curr_battery_level)
-        EventMesh.subscribe("get_fw_version", self.get_device_fw_version)
-        EventMesh.subscribe("get_standby_time", self.get_standby_time)
-        EventMesh.subscribe(constants.EVENT.GET_STEP, self.get_step_count)
-        EventMesh.subscribe("sim_slot_get", self.sim_slot_get)
-        EventMesh.subscribe("sim_slot_switch", self.sim_slot_switch)
-        EventMesh.subscribe(constants.EVENT.GET_KEY, self.get_key)
-        EventMesh.subscribe(constants.EVENT.SET_KEY, self.set_key)
-        EventMesh.subscribe(constants.EVENT.GET_IMEI, self.get_imei)
-        EventMesh.subscribe(constants.EVENT.GET_CID, self.get_cid)
-        EventMesh.subscribe(constants.EVENT.SET_CID, self.set_cid)
-        EventMesh.subscribe(constants.EVENT.GET_IMSI, self.get_imsi)
-        EventMesh.subscribe(constants.EVENT.GET_PASSWORD, self.get_password)
-        EventMesh.subscribe(constants.EVENT.SET_PASSWORD, self.set_password)     
-        EventMesh.subscribe(constants.EVENT.SET_PING, self.set_ping)
-        EventMesh.subscribe(constants.EVENT.GET_PING, self.get_ping)
-        EventMesh.subscribe(constants.EVENT.SET_CONNECT, self.set_connect)
-        EventMesh.subscribe(constants.EVENT.GET_CONNECT, self.get_connect)
+            self.spo2_timeSecond = 0
+            self.spo2auto_state = 0
 
-        
-        EventMesh.subscribe(constants.EVENT.START_BLOOD_OXYGEN, self.start_blood_oxygen)
-        EventMesh.subscribe(constants.EVENT.START_HEART, self.start_heart)
-        EventMesh.subscribe(constants.EVENT.STOP_BLOOD_OXYGEN, self.stop_blood_oxygen)
-        EventMesh.subscribe(constants.EVENT.STOP_HEART, self.stop_heart)
-        EventMesh.subscribe(constants.EVENT.GET_BLOOD_OXYGEN, self.get_blood_oxygen)
-        EventMesh.subscribe(constants.EVENT.GET_HEART, self.get_heart)
-        EventMesh.subscribe(constants.EVENT.GET_WEAR, self.get_wear)
-        EventMesh.subscribe("get_Hsensor", self.get_Hsensor)
-        EventMesh.subscribe("Hsensor_set_sleep", self.Hsensor_set_sleep)
-
-        EventMesh.subscribe(constants.EVENT.START_TEMP, self.start_temp)
-        EventMesh.subscribe(constants.EVENT.STOP_TEMP, self.stop_temp)
-        EventMesh.subscribe(constants.EVENT.GET_TEMP, self.get_temp)
-        EventMesh.subscribe("get_boot_time_count", self.get_boot_time_count)
-        EventMesh.subscribe("get_dev_state", self.get_dev_state)
-        EventMesh.subscribe("set_dev_state", self.set_dev_state)
-
-        EventMesh.subscribe("clear_health_state", self.clear_health_state)
-
-        EventMesh.subscribe("clear_home_alarm", self.clear_home_alarm)
-        EventMesh.subscribe("clear_medicine_alarm", self.clear_medicine_alarm)
-        EventMesh.subscribe("clear_wakeup_alarm", self.clear_wakeup_alarm)
-        EventMesh.subscribe("clear_sleep_alarm", self.clear_sleep_alarm)
-        EventMesh.subscribe("clear_normal_alarm", self.clear_normal_alarm)
-
-        EventMesh.subscribe("clear_manual_hr_flag", self.clear_manual_hr_flag)
-        EventMesh.subscribe("clear_manual_temp_flag", self.clear_manual_temp_flag)
-
-
-        EventMesh.subscribe("clear_usb_flag", self.clear_usb_flag)
-        
-        EventMesh.debug_log("post_processor_after_instantiation:2")
-        self.timer_push_schedule.start(10000, 1, self.publish_event_cb)
-        # self.timer_pusht_test.start(2000, 1, self.publish_test)
-        # self.battery_push_schedule.start(3000, 1, self.__check_battery)
-        self.log.debug("post_processor_after_instantiation finished")
-        #EventMesh.publish(constants.EVENT.START_HEART)
-        # 设备开机立刻更新一次参数
-        self.publish_event_cb()
-        
-        EventMesh.debug_log("post_processor_after_instantiation:3")
+            self.vbat_count = 0
 
-    def clear_manual_hr_flag(self,event,msg):
-        self.auto_hr_count = 0
-    
-    def clear_manual_temp_flag(self,event,msg):
-        self.auto_temp_count = 0
-
-    def publish_message_event_DeviceInfo(self,event,msg):
-        self.DeviceInfo_queue.put(msg)
-
-    #DeviceInfo的消息队列处理,防止卡顿
-    def DeviceInfo_queue_thread(self):
-        while True:
-            data = self.DeviceInfo_queue.get()
-            #EventMesh.debug_log("DeviceInfo_queue_thread:data = {}".format(data))
-            if data != None:
-                try:
-                    data["func"](data["data"])
-                except Exception as e:
-                    EventMesh.debug_log("DeviceInfo_queue_thread:ERROR:{}".format(e))
-                    usys.print_exception(e)
+            self.vbat_buf=[]
 
+            self.curr_battery_level = 4200
+            self.bat_count = 0
 
-    def gsensor_cb(self, para):
-        EventMesh.debug_log("gsensor_cb:{}".format(para))
-        flip_sw = EventMesh.publish("get_storage_config","flip_sw")
-        fall_sw = EventMesh.publish("get_storage_config","fall_sw")
-        if para == 0: #跌倒报警
-            pass
-            if fall_sw == "1":
-                EventMesh.publish("falldown_alarm_event")
-                dev_state =  EventMesh.publish("get_dev_state")
-
-                tmp = 1 << 21
-                dev_state = dev_state|tmp #第21位=1
-                EventMesh.publish("set_dev_state",dev_state)
-                EventMesh.publish(constants.EVENT.START_LOCATION,[constants.PROTOCOL.AL_SEND,dev_state]) #开始AL定位
-                pass
-            #EventMesh.publish("load_screen", {"screen": "FIND"})
-        elif para == 1: #抬腕
-            
-            if flip_sw == 1:
-                EventMesh.publish(constants.EVENT.SYSTEM_UP)
-            
-        elif para == 2: #放手
-            pass
-            # if flip_sw == 1:
-            #     EventMesh.publish(constants.EVENT.SYSTEM_SLEEP)
-    def get_boot_time_count(self, event, msg):
-        return self.boot_time_count
-    
-    def get_dev_state(self, event, msg):
-        return self.dev_state
-    def set_dev_state(self, event, msg):
-        self.dev_state = msg
-    
-    def publish_event_cb(self, *args, **kwargs):
-        if self.boot_time_count < 50000000:
-            self.boot_time_count += 10
-            #EventMesh.debug_log("boot_time_count:{}".format(self.boot_time_count))
-        EventMesh.publish("publish_message_event_DeviceInfo",{"func":self.publish_event,"data":0})  
-    def optimize_temp(self,temp):
-        temp += 0.5
-        get_temp_time  = EventMesh.publish("get_temp_time")
-        EventMesh.debug_log("temp:{}".format(temp))
-        if temp < 36 :#or temp > 37.5:
-            temp = 36+urandom.random()
-        if temp > 37.5:
+            self.mearsure_btn = 0
+            self.mearsure_timer = 0
+
+            self.old_hr_time = 0
+            self.old_spo2_time = 0
+
+            self.no_smi_count = 0
+            self.no_smi_state = 0
+
+            self.old_bp_time = 0
+
+            self.medicine_count = 0
+            self.medicine_flag  = 0
+            self.medicine_oldtotalmin = 0
             
-            self.temp_warning += 1
-            EventMesh.debug_log("temp_warning:{} get_temp_time{}".format(self.temp_warning,get_temp_time))
+            self.wakeup_flag = 0
+            self.wakeup_count = 0
+            self.wakeup_oldtotalmin = 0
+
+            self.sleep_flag = 0
+            self.sleep_count = 0
+            self.sleep_oldtotalmin = 0
+
+            self.reset_flag = 0
+            self.reset_count = 0
+            self.reset_oldtotalmin = 0
+
+            self.home_flag = 0
+            self.home_count = 0
+            self.home_oldtotalmin = 0
+
+            self.normal_flag = 0
+            self.normal_count = 0
+            self.normal_oldtotalmin = 0
             
-            if self.temp_warning < 5:#高温没连续超过3次,和谐成37.5度以下
-                temp = 37+(urandom.randint(1, 4)/10)
-            else:
-                self.temp_warning = 0
-        else:
-            if self.temp_warning>=1:
-                self.temp_warning -= 1
-        if temp >= 40:
-            temp = 40
-        return temp
-    def clear_health_state(self,event,msg):
-        print("clear_health_state")
-        self.old_bp_time = 0#关闭心率 血压 血氧 体温清除标志
-        self.old_time = 0
-        self.HR_Onestate = 0
-        self.HR_OneTime = 0
-        self.HR_state = 0
-        self.set_hsenor_crt = 0
-        self.old_bg_time = 0
-        self.old_hr_time = 0
-        self.old_spo2_time = 0
-        self.BG_state = 0
-        self.bpauto_state = 0
-        self.spo2auto_state = 0
-        pass
-
-    def clear_temp_state(self,event,msg):
-        print("clear_temp_state")
-        self.temp_state = 0
-        self.temp_one_state = 0
-        self.old_temp_time = 0
-        pass
-
-    def publish_event(self,data):
-        """
-        定时事件处理
-        :param args:
-        :param kwargs:
-        :return:
-        """
+            self.charge_full_count = 0
+            self.GPS_step_t = 0#记录步数
+            self.usb = USB()
+            self.usb.setCallback(self.usb_event_cb)
+            self.log = LogAdapter(self.__class__.__name__)
+            self.rtc = RTC()
+            self.aud = audio.Audio(0)
+            EventMesh.debug_log("DeviceInfoManager:1")
+            self.gsensor = SC7A20()
+            EventMesh.debug_log("DeviceInfoManager:1.0")
+            self.gsensor.activate()
+            EventMesh.debug_log("DeviceInfoManager:1.1")
+            self.gsensor.init()
+            EventMesh.debug_log("DeviceInfoManager:2")
+            self.gsensor.set_callback(self.gsensor_cb)
+            try :
+                self.hsensor = HX3918()
+                
+            except Exception as e:
+                EventMesh.debug_log("Hsensor none HX3918:{}".format(e))   
+            try :
+                self.hsensor = GH3018()
+            except Exception as e:
+                EventMesh.debug_log("Hsensor none GH3018:{}".format(e))   
+            #
+            self.hsensor.activate()
+            self.hsensor.init()
+            self.hsensor.close()
+            try :
+                self.hsensor.set_sar(1)
+            except Exception as e:
+                EventMesh.debug_log("Hsensor none set_sar:{}".format(e)) 
+            self.old_temp_time = 0
+            # #EventMesh.debug_log("hsensor.open_heart:%d\r\n"%(self.hsensor.open_heart()))
+            EventMesh.debug_log("DeviceInfoManager:3")
+            self.i2c0 = I2C(I2C.I2C0, I2C.FAST_MODE)
+            self.stop_temp( None, None)
+            self.dev_state = 0
+            self.wear = 1
+            self.BG_state = 0
+            self.old_bg_time = 0
 
-        date_tmp = utime.localtime()
-        time_tmp = utime.mktime(date_tmp)
-        # EventMesh.debug_log("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
-        
+            self.pull_time = 0
 
-        EventMesh.publish("countdown_end_cb")
-        """定时检查是否关闭gps失败"""
-        # gnss_state = quecgnss.get_state()
-        # get_location_flag = EventMesh.publish("get_location_flag")
-        # if get_location_flag != None:
-        #     # if gnss_state == 2 and get_location_flag == 0:
-        #     #     EventMesh.publish(constants.EVENT.GPSCLOSE)
-        #     if(get_location_flag == 0):
-        #         EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
-
-        """7分钟一次心跳"""
-        if  math.fabs(time_tmp - self.KA_time) > heartbeat_time: #7分钟一次心跳
-            self.KA_time = time_tmp
-            EventMesh.publish(constants.PROTOCOL.KA_SEND)
-
-        """定时定位"""
-        #EventMesh.publish("set_upload_data",3*60)
-        self.upload_time = EventMesh.publish("get_upload_data")
-        #EventMesh.debug_log("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")
-                    EventMesh.debug_log("NO status")
-                    EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
-        
-        EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
-
-        """电池平均值"""
-        temp = Power.getVbatt()
-        if self.bat_count < 10:
-            self.vbat_buf.append(temp)
-            self.bat_count += 1
-        else:
-            for i in range(9):
-                self.vbat_buf[i] = self.vbat_buf[i+1]
-            self.vbat_buf[9] = temp
-        curr_count = len(self.vbat_buf)
-        bat_total_value = 0
-        for i in range(curr_count):
-            bat_total_value += self.vbat_buf[i]
-        bat_total_value = bat_total_value//curr_count#一分钟更新一次电量 10个平均值
-        EventMesh.publish("set_curr_battery_level",bat_total_value)
-        # EventMesh.debug_log("self.vbat_buf:{} curr_count :{} bat_total_value:{} temp:{}".format(self.vbat_buf,curr_count,bat_total_value,temp))
-        bat_tmp = EventMesh.publish("screen_get_battery")
-        self.vbat_count+=10
-        if self.vbat_count >= 60:
-            self.vbat_count = 0
-            if bat_tmp != None:
-                bat_value = bat_tmp[1]
-                if bat_value <= 0:
-                    pass
-                    # EventMesh.publish("load_screen", {"screen": "LOW_ONE_POWER"})
-        
-        
-        """"隔天清步数"""
+            self.drink_time = 0
 
-        data = RTC().datetime()
+            self.alarm_count = 0
+            self.alarm_flag = 0
 
-        hour = int(data[4])
-        min = int(data[5])
+            self.time_count = 0
+            
+            self.auto_spo2_count = 0
+
+            self.auto_hr_count = 0
 
+            self.auto_temp_count = 0
 
+        
+
+        def post_processor_after_instantiation(self):
+            EventMesh.debug_log("post_processor_after_instantiation:1")
+            """订阅此类所有的事件到 EventMesh中"""
+            voiceCall.setCallback(voice_callback)
+            EventMesh.subscribe("screen_get_ope", self.get_device_ope)
+            EventMesh.subscribe("screen_get_sig", self.get_signal)
+            EventMesh.subscribe("screen_get_time", self.get_time)
+            EventMesh.subscribe("about_get_imei", self.get_imei)
+            EventMesh.subscribe("about_get_iccid", self.get_ic_cid)
+            EventMesh.subscribe("get_sim_Status", self.get_sim_Status)
+            EventMesh.subscribe("about_get_phonenum", self.get_phone_num)
+            EventMesh.subscribe("screen_get_battery", self.get_battery)
+            EventMesh.subscribe("set_curr_battery_level", self.set_curr_battery_level)
+            EventMesh.subscribe("get_curr_battery_level", self.get_curr_battery_level)
+            EventMesh.subscribe("get_fw_version", self.get_device_fw_version)
+            EventMesh.subscribe("get_standby_time", self.get_standby_time)
+            EventMesh.subscribe(constants.EVENT.GET_STEP, self.get_step_count)
+            EventMesh.subscribe("sim_slot_get", self.sim_slot_get)
+            EventMesh.subscribe("sim_slot_switch", self.sim_slot_switch)
+            EventMesh.subscribe(constants.EVENT.GET_KEY, self.get_key)
+            EventMesh.subscribe(constants.EVENT.SET_KEY, self.set_key)
+            EventMesh.subscribe(constants.EVENT.GET_IMEI, self.get_imei)
+            EventMesh.subscribe(constants.EVENT.GET_CID, self.get_cid)
+            EventMesh.subscribe(constants.EVENT.SET_CID, self.set_cid)
+            EventMesh.subscribe(constants.EVENT.GET_IMSI, self.get_imsi)
+            EventMesh.subscribe(constants.EVENT.GET_PASSWORD, self.get_password)
+            EventMesh.subscribe(constants.EVENT.SET_PASSWORD, self.set_password)     
+            EventMesh.subscribe(constants.EVENT.SET_PING, self.set_ping)
+            EventMesh.subscribe(constants.EVENT.GET_PING, self.get_ping)
+            EventMesh.subscribe(constants.EVENT.SET_CONNECT, self.set_connect)
+            EventMesh.subscribe(constants.EVENT.GET_CONNECT, self.get_connect)
 
-        cur_month = int(data[1])
-        cur_day = int(data[2])
-        cur_year = int(data[0])
+            
+            EventMesh.subscribe(constants.EVENT.START_BLOOD_OXYGEN, self.start_blood_oxygen)
+            EventMesh.subscribe(constants.EVENT.START_HEART, self.start_heart)
+            EventMesh.subscribe(constants.EVENT.STOP_BLOOD_OXYGEN, self.stop_blood_oxygen)
+            EventMesh.subscribe(constants.EVENT.STOP_HEART, self.stop_heart)
+            EventMesh.subscribe(constants.EVENT.GET_BLOOD_OXYGEN, self.get_blood_oxygen)
+            EventMesh.subscribe(constants.EVENT.GET_HEART, self.get_heart)
+            EventMesh.subscribe(constants.EVENT.GET_WEAR, self.get_wear)
+            EventMesh.subscribe("get_Hsensor", self.get_Hsensor)
+            EventMesh.subscribe("Hsensor_set_sleep", self.Hsensor_set_sleep)
+
+            EventMesh.subscribe(constants.EVENT.START_TEMP, self.start_temp)
+            EventMesh.subscribe(constants.EVENT.STOP_TEMP, self.stop_temp)
+            EventMesh.subscribe(constants.EVENT.GET_TEMP, self.get_temp)
+            EventMesh.subscribe("get_boot_time_count", self.get_boot_time_count)
+            EventMesh.subscribe("get_dev_state", self.get_dev_state)
+            EventMesh.subscribe("set_dev_state", self.set_dev_state)
+
+            EventMesh.subscribe("clear_health_state", self.clear_health_state)
+
+            EventMesh.subscribe("clear_home_alarm", self.clear_home_alarm)
+            EventMesh.subscribe("clear_medicine_alarm", self.clear_medicine_alarm)
+            EventMesh.subscribe("clear_wakeup_alarm", self.clear_wakeup_alarm)
+            EventMesh.subscribe("clear_sleep_alarm", self.clear_sleep_alarm)
+            EventMesh.subscribe("clear_normal_alarm", self.clear_normal_alarm)
+
+            EventMesh.subscribe("clear_manual_hr_flag", self.clear_manual_hr_flag)
+            EventMesh.subscribe("clear_manual_temp_flag", self.clear_manual_temp_flag)
+
+
+            EventMesh.subscribe("clear_usb_flag", self.clear_usb_flag)
+            
+            EventMesh.debug_log("post_processor_after_instantiation:2")
+            self.timer_push_schedule.start(10000, 1, self.publish_event_cb)
+            # self.timer_pusht_test.start(2000, 1, self.publish_test)
+            # self.battery_push_schedule.start(3000, 1, self.__check_battery)
+            self.log.debug("post_processor_after_instantiation finished")
+            #EventMesh.publish(constants.EVENT.START_HEART)
+            # 设备开机立刻更新一次参数
+            self.publish_event_cb()
+            
+            EventMesh.debug_log("post_processor_after_instantiation:3")
 
-        old_Timesec = EventMesh.publish("get_old_time_data")
-        # EventMesh.debug_log("hour:{} {} cur_month:{} {} next_alarm_time:{} old_Timesec:{}".format(hour,min,cur_month,cur_day,next_alarm_time,old_Timesec))
-        # EventMesh.debug_log("old_Timesec",old_Timesec)
-        if old_Timesec != None:
-            next_alarm_time = utime.localtime(int(old_Timesec))
-            month = int(next_alarm_time[1]) #00:00 18
-            day = int(next_alarm_time[2])
-            year = int(next_alarm_time[0])
-            if month != cur_month or day != cur_day or year != cur_year:#年 月 日只要其中一个都不一样就清零
-                EventMesh.publish("set_old_time_data",time_tmp)
-                self.gsensor.reset_step()
+        def clear_manual_hr_flag(self,event,msg):
+            self.auto_hr_count = 0
+        
+        def clear_manual_temp_flag(self,event,msg):
+            self.auto_temp_count = 0
+
+        def publish_message_event_DeviceInfo(self,event,msg):
+            self.DeviceInfo_queue.put(msg)
+
+        #DeviceInfo的消息队列处理,防止卡顿
+        def DeviceInfo_queue_thread(self):
+            while True:
+                data = self.DeviceInfo_queue.get()
+                #EventMesh.debug_log("DeviceInfo_queue_thread:data = {}".format(data))
+                if data != None:
+                    try:
+                        data["func"](data["data"])
+                    except Exception as e:
+                        EventMesh.debug_log("DeviceInfo_queue_thread:ERROR:{}".format(e))
+                        usys.print_exception(e)
+
+
+        def gsensor_cb(self, para):
+            EventMesh.debug_log("gsensor_cb:{}".format(para))
+            flip_sw = EventMesh.publish("get_storage_config","flip_sw")
+            fall_sw = EventMesh.publish("get_storage_config","fall_sw")
+            if para == 0: #跌倒报警
+                pass
+                if fall_sw == "1":
+                    EventMesh.publish("falldown_alarm_event")
+                    dev_state =  EventMesh.publish("get_dev_state")
 
-                EventMesh.publish("set_old_step_value",0)
+                    tmp = 1 << 21
+                    dev_state = dev_state|tmp #第21位=1
+                    EventMesh.publish("set_dev_state",dev_state)
+                    EventMesh.publish(constants.EVENT.START_LOCATION,[constants.PROTOCOL.AL_SEND,dev_state]) #开始AL定位
+                    pass
+                #EventMesh.publish("load_screen", {"screen": "FIND"})
+            elif para == 1: #抬腕
                 
-                hr = EventMesh.publish("get_old_hr_data")
-                if hr != 0:
-                    EventMesh.publish("set_old_hr_data", 0)
+                if flip_sw == 1:
+                    EventMesh.publish(constants.EVENT.SYSTEM_UP)
                 
-                spo2 = EventMesh.publish("get_old_spo2_data")
-                if spo2 != 0:
-                    EventMesh.publish("set_old_spo2_data", 0)
-                EventMesh.debug_log("clear step1111")
-            else:
+            elif para == 2: #放手
                 pass
+                # if flip_sw == 1:
+                #     EventMesh.publish(constants.EVENT.SYSTEM_SLEEP)
+        def get_boot_time_count(self, event, msg):
+            return self.boot_time_count
+        
+        def get_dev_state(self, event, msg):
+            return self.dev_state
+        def set_dev_state(self, event, msg):
+            self.dev_state = msg
+        
+        def publish_event_cb(self, *args, **kwargs):
+            if self.boot_time_count < 50000000:
+                self.boot_time_count += 10
+                #EventMesh.debug_log("boot_time_count:{}".format(self.boot_time_count))
+            EventMesh.publish("publish_message_event_DeviceInfo",{"func":self.publish_event,"data":0})  
+        def optimize_temp(self,temp):
+            temp += 0.5
+            get_temp_time  = EventMesh.publish("get_temp_time")
+            EventMesh.debug_log("temp:{}".format(temp))
+            if temp < 36 :#or temp > 37.5:
+                temp = 36+urandom.random()
+            if temp > 37.5:
                 
+                self.temp_warning += 1
+                EventMesh.debug_log("temp_warning:{} get_temp_time{}".format(self.temp_warning,get_temp_time))
                 
-        if hour == 23:#清步数23:59
-            if min == 59:#58 59
-                # if self.clear_step == 0:
-                #     self.clear_step = 1
-                EventMesh.publish("set_old_time_data",time_tmp)
-                self.gsensor.reset_step()
-                EventMesh.publish("set_old_step_value",0)
-
-                hr = EventMesh.publish("get_old_hr_data")
-                if hr != 0:
-                    EventMesh.publish("set_old_hr_data", 0)
-                
-                spo2 = EventMesh.publish("get_old_spo2_data")
-                if spo2 != 0:
-                    EventMesh.publish("set_old_spo2_data", 0)
-                EventMesh.debug_log("clear step2222")
-
+                if self.temp_warning < 5:#高温没连续超过3次,和谐成37.5度以下
+                    temp = 37+(urandom.randint(1, 4)/10)
+                else:
+                    self.temp_warning = 0
             else:
-                self.clear_step = 0
-        else:
-            self.clear_step = 0
-        
-        """电量小于0% 关机"""
-        get_low_btn = EventMesh.publish("get_low_bat_btn")#
-        battery = EventMesh.publish("screen_get_battery")
-        if battery[0] != '1':
-            if battery[1] == 0:
-                EventMesh.publish("open_power_on",2)#  #未检测到sim卡15分钟后关机
-        
-        """未联网提示关机"""
-        ble=EventMesh.publish(constants.EVENT.GET_CONNECT)
-        # EventMesh.debug_log("ble",ble)
-        if ble == 0:#未联网提示关机
-            if battery[0] != '1':
-                self.no_smi_count+=10
-                # EventMesh.debug_log("self.no_smi_count",self.no_smi_count)
-                if self.no_smi_count >= (15*60):#(15*60)
-                    self.no_smi_count = 0
-                    EventMesh.publish("open_power_on",2)#  #未检测到sim卡15分钟后关机
-                  
-        else:
-            self.no_smi_count = 0
+                if self.temp_warning>=1:
+                    self.temp_warning -= 1
+            if temp >= 40:
+                temp = 40
+            return temp
+        def clear_health_state(self,event,msg):
+            print("clear_health_state")
+            self.old_bp_time = 0#关闭心率 血压 血氧 体温清除标志
+            self.old_time = 0
+            self.HR_Onestate = 0
+            self.HR_OneTime = 0
+            self.HR_state = 0
+            self.set_hsenor_crt = 0
+            self.old_bg_time = 0
+            self.old_hr_time = 0
+            self.old_spo2_time = 0
+            self.BG_state = 0
+            self.bpauto_state = 0
+            self.spo2auto_state = 0
+            pass
 
-        msg_nums = sms.getMsgNums() #获取短信条数
-        # EventMesh.debug_log("msg_nums",msg_nums)
-        if(msg_nums != -1):
-            sms_data = sms.getSaveLoc()
-            sms_max = sms_data[0][2]
-            if msg_nums >= sms_max-1:
-                EventMesh.publish("delete_sms_event")#
-
-        #佩戴检测
-        WEAR = EventMesh.publish(constants.EVENT.GET_WEAR)#佩戴数据
-        if self.wear != WEAR:
-            remove_sw = EventMesh.publish("get_storage_config","remove_sw")
-            if remove_sw == "1":#开启了佩戴检测的开关
-                dev_state =  EventMesh.publish("get_dev_state")
-                
-                if WEAR != 1:
-                    tmp = 1 << 3
-                    tmp = ~tmp
-                    tmp = 1 << 20
-                    dev_state = dev_state|tmp #第20位=1
-                # else :     
-                #     pass              
-                    
-                #     tmp = 1 << 20
-                #     dev_state = dev_state|tmp #第20位=1
-                #     tmp = 1 << 3
-                #     dev_state = dev_state|tmp #第三位=1
-                    EventMesh.debug_log("佩戴检测:{}".format(dev_state))    
-                    EventMesh.publish("set_dev_state",dev_state)
-                    EventMesh.publish(constants.EVENT.START_LOCATION,[constants.PROTOCOL.AL_SEND,dev_state]) #开始AL定位,发送报警
-                    #EventMesh.publish(constants.PROTOCOL.HELP_SEND,65)
-        self.wear = WEAR
-        """定时测量心率,血氧,体温"""
-        self.get_hr_state = EventMesh.publish("get_hr_state")
-        self.get_spo2_state = EventMesh.publish("get_spo2_state")
-        get_temp_time  = EventMesh.publish("get_temp_time")
-        get_temp_state  = EventMesh.publish("get_temp_state")
-        get_bp_state  = EventMesh.publish("get_bp_state")
-        get_bg_state  = EventMesh.publish("get_bg_state")
-        if get_bg_state == None:
-            get_bg_state = 0
-        if get_bp_state == None:
-            get_bp_state = 0
-
-        if get_temp_state == None:
-            get_temp_state = 0
-
-        if self.get_hr_state == None:
-            self.get_hr_state = 0
-        if self.get_spo2_state == None:
-            self.get_spo2_state = 0 
-       
-        call_state = EventMesh.publish("get_call_state")
-        if call_state == None:
-            call_state = 0
-        if battery[0] != "1":
-            if get_temp_state != None and call_state != None: #突然脱腕
-
-                if get_temp_state > 1  and (WEAR != 1 or call_state != 0):
-                    EventMesh.publish(constants.EVENT.STOP_TEMP)
-                    EventMesh.publish("set_temp_state",0)       
-                    EventMesh.txt_log("auto stop_temp:22")
-
-                if (self.get_hr_state > 1 or self.get_spo2_state > 1 or get_bp_state > 1 or get_bg_state > 1) and (WEAR != 1 or call_state != 0):
-                    # print("wear faile")
-                    if self.get_hr_state > 1 :
-                        EventMesh.txt_log("auto stop_hr:22")
-                        EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
-                        EventMesh.publish(constants.EVENT.STOP_HEART) 
-                        if WEAR == 1:
-                            heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
-                            if heart_value > 50 and heart_value != None:
-                                EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
-                        
-                    if self.get_spo2_state > 1:
-                        EventMesh.txt_log("auto stop_spo2:22")
-                        EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+        def clear_temp_state(self,event,msg):
+            print("clear_temp_state")
+            self.temp_state = 0
+            self.temp_one_state = 0
+            self.old_temp_time = 0
+            pass
 
-                        EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
-                        spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
-                        if WEAR == 1:
-                            if spo2_value > 85 and spo2_value != None:
-                                EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
-                        
-                    if get_bp_state > 1:
+        def publish_event(self,data):
+            """
+            定时事件处理
+            :param args:
+            :param kwargs:
+            :return:
+            """
 
-                        EventMesh.txt_log("auto stop_bp:22")
-                        EventMesh.publish("set_bp_state",0)#2代表后台进入测试
-                        EventMesh.publish(constants.EVENT.STOP_HEART)
-                        if WEAR == 1:
-                            blood_data = get_autoblood_value()
-                            if blood_data == None:
-                                blood_data[0] = 0
-                                blood_data[1] = 0
+            date_tmp = utime.localtime()
+            time_tmp = utime.mktime(date_tmp)
+            # EventMesh.debug_log("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
+            
 
-                            max_value = blood_data[0]
-                            min_value = blood_data[1]
-                            if max_value != 0 and min_value != 0:
-                                EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
-                        
-                    if get_bg_state > 1:
-                        EventMesh.txt_log("auto stop_bg:22")
-                        
-                        EventMesh.publish("set_bg_state",0)#2代表后台进入测试
-                        EventMesh.publish(constants.EVENT.STOP_HEART)
-                        if WEAR == 1:
-                            bg_data = get_blood_sugar_value()
-                            if bg_data == None:
-                                bg_data = 0
-                            if bg_data != 0:
-                                # EventMesh.publish("play_sugar_value", bg_data)#播放血糖数值
-                                EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bg_data)
-                        
-        if self.pull_time == 0:
-            self.pull_time = time_tmp
+            EventMesh.publish("countdown_end_cb")
+            """定时检查是否关闭gps失败"""
+            # gnss_state = quecgnss.get_state()
+            # get_location_flag = EventMesh.publish("get_location_flag")
+            # if get_location_flag != None:
+            #     # if gnss_state == 2 and get_location_flag == 0:
+            #     #     EventMesh.publish(constants.EVENT.GPSCLOSE)
+            #     if(get_location_flag == 0):
+            #         EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
+
+            """7分钟一次心跳"""
+            if  math.fabs(time_tmp - self.KA_time) > heartbeat_time: #7分钟一次心跳
+                self.KA_time = time_tmp
+                EventMesh.publish(constants.PROTOCOL.KA_SEND)
+
+            """定时定位"""
+            #EventMesh.publish("set_upload_data",3*60)
+            self.upload_time = EventMesh.publish("get_upload_data")
+            #EventMesh.debug_log("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")
+                        EventMesh.debug_log("NO status")
+                        EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
+            
+            EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
 
-        # if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#已联网 并且不在充电 佩戴正常 不在通话就给测试心率
-        if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and battery[0] != "1" and WEAR == 1 and call_state == 0:
-            if time_tmp - self.pull_time >= 30:
-                # EventMesh.debug_log("shifens:")  
+            """电池平均值"""
+            temp = Power.getVbatt()
+            if self.bat_count < 10:
+                self.vbat_buf.append(temp)
+                self.bat_count += 1
+            else:
+                for i in range(9):
+                    self.vbat_buf[i] = self.vbat_buf[i+1]
+                self.vbat_buf[9] = temp
+            curr_count = len(self.vbat_buf)
+            bat_total_value = 0
+            for i in range(curr_count):
+                bat_total_value += self.vbat_buf[i]
+            bat_total_value = bat_total_value//curr_count#一分钟更新一次电量 10个平均值
+            EventMesh.publish("set_curr_battery_level",bat_total_value)
+            # EventMesh.debug_log("self.vbat_buf:{} curr_count :{} bat_total_value:{} temp:{}".format(self.vbat_buf,curr_count,bat_total_value,temp))
+            bat_tmp = EventMesh.publish("screen_get_battery")
+            self.vbat_count+=10
+            if self.vbat_count >= 60:
+                self.vbat_count = 0
+                if bat_tmp != None:
+                    bat_value = bat_tmp[1]
+                    if bat_value <= 0:
+                        pass
+                        # EventMesh.publish("load_screen", {"screen": "LOW_ONE_POWER"})
+            
+            
+            """"隔天清步数"""
 
-                get_hr_state = EventMesh.publish("get_hr_state")
-                get_spo2_state = EventMesh.publish("get_spo2_state")
-                get_bp_state  = EventMesh.publish("get_bp_state")
-                get_bg_state  = EventMesh.publish("get_bg_state")
-                get_temp_state  = EventMesh.publish("get_temp_state")
-                if get_hr_state == None:
-                    get_hr_state = 0
-                    self.old_hr_time = 0
+            data = RTC().datetime()
 
-                if get_spo2_state == None:
-                    get_spo2_state = 0
-                    self.old_spo2_time = 0
+            hour = int(data[4])
+            min = int(data[5])
 
-                if get_temp_state == None:
-                    get_temp_state = 0
-                    self.temp_one_state = 0
 
-                if get_bp_state == None:
-                    get_bp_state = 0
-                    self.old_bp_time = 0
-                
-                if get_bg_state == None:
-                    get_bg_state = 0
-                    self.old_bg_time = 0
-                
-                # print("bp get_bp_state ",get_bp_state,self.old_bp_time)
 
-                
-                if get_hr_state != None:
-                    if get_hr_state == 3:
-                        self.old_hr_time+=1
-                        if self.old_hr_time == 1:
-                            EventMesh.publish("set_hr_state",3)#2代表后台进入测试
-                            # EventMesh.publish("set_hr_blood_led",1)
-                            EventMesh.publish(constants.EVENT.START_HEART)
-                            EventMesh.txt_log("auto start_hr:333")
-                        elif self.old_hr_time > 6:
-                            self.old_hr_time = 0
-                            EventMesh.publish("set_hr_state",0)#2代表后台进入测试
-                            EventMesh.txt_log("auto stop_hr:333")
-                            EventMesh.publish(constants.EVENT.STOP_HEART)
-                            heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
-                            EventMesh.debug_log("heart_value:{}".format(heart_value))
-                            if heart_value > 50 and heart_value != None:
-                                EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
-                            EventMesh.debug_log("STOP_HEART:3")
-                    else:
-                        self.old_hr_time = 0
-                else:
-                    self.old_hr_time = 0
+            cur_month = int(data[1])
+            cur_day = int(data[2])
+            cur_year = int(data[0])
 
+            old_Timesec = EventMesh.publish("get_old_time_data")
+            # EventMesh.debug_log("hour:{} {} cur_month:{} {} next_alarm_time:{} old_Timesec:{}".format(hour,min,cur_month,cur_day,next_alarm_time,old_Timesec))
+            # EventMesh.debug_log("old_Timesec",old_Timesec)
+            if old_Timesec != None:
+                next_alarm_time = utime.localtime(int(old_Timesec))
+                month = int(next_alarm_time[1]) #00:00 18
+                day = int(next_alarm_time[2])
+                year = int(next_alarm_time[0])
+                if month != cur_month or day != cur_day or year != cur_year:#年 月 日只要其中一个都不一样就清零
+                    EventMesh.publish("set_old_time_data",time_tmp)
+                    self.gsensor.reset_step()
 
-                if get_spo2_state != None:
-                    if get_spo2_state == 3:
-                        self.old_spo2_time+=1
-                        if self.old_spo2_time == 1:
-                            EventMesh.publish("set_spo2_state",3)#2代表后台进入测试
-                            # EventMesh.publish("set_hr_blood_led",1)
-                            EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
-                            EventMesh.txt_log("auto start_spo2:333")
-                        elif self.old_spo2_time > 6:
-                            self.old_spo2_time = 0
-                            EventMesh.txt_log("auto stop_spo2:333")
-                            EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
-                            EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
-                            spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
-                            if spo2_value > 85 and spo2_value != None:
-                                EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
-                                
-                    else:
-                        self.old_spo2_time = 0
+                    EventMesh.publish("set_old_step_value",0)
+                    
+                    hr = EventMesh.publish("get_old_hr_data")
+                    if hr != 0:
+                        EventMesh.publish("set_old_hr_data", 0)
+                    
+                    spo2 = EventMesh.publish("get_old_spo2_data")
+                    if spo2 != 0:
+                        EventMesh.publish("set_old_spo2_data", 0)
+                    EventMesh.debug_log("clear step1111")
                 else:
-                    self.old_spo2_time = 0
+                    pass
+                    
+                    
+            if hour == 23:#清步数23:59
+                if min == 59:#58 59
+                    # if self.clear_step == 0:
+                    #     self.clear_step = 1
+                    EventMesh.publish("set_old_time_data",time_tmp)
+                    self.gsensor.reset_step()
+                    EventMesh.publish("set_old_step_value",0)
+
+                    hr = EventMesh.publish("get_old_hr_data")
+                    if hr != 0:
+                        EventMesh.publish("set_old_hr_data", 0)
+                    
+                    spo2 = EventMesh.publish("get_old_spo2_data")
+                    if spo2 != 0:
+                        EventMesh.publish("set_old_spo2_data", 0)
+                    EventMesh.debug_log("clear step2222")
 
+                else:
+                    self.clear_step = 0
+            else:
+                self.clear_step = 0
+            
+            """电量小于0% 关机"""
+            get_low_btn = EventMesh.publish("get_low_bat_btn")#
+            battery = EventMesh.publish("screen_get_battery")
+            if battery[0] != '1':
+                if battery[1] == 0:
+                    EventMesh.publish("open_power_on",2)#  #未检测到sim卡15分钟后关机
+            
+            """未联网提示关机"""
+            ble=EventMesh.publish(constants.EVENT.GET_CONNECT)
+            # EventMesh.debug_log("ble",ble)
+            if ble == 0:#未联网提示关机
+                if battery[0] != '1':
+                    self.no_smi_count+=10
+                    # EventMesh.debug_log("self.no_smi_count",self.no_smi_count)
+                    if self.no_smi_count >= (15*60):#(15*60)
+                        self.no_smi_count = 0
+                        EventMesh.publish("open_power_on",2)#  #未检测到sim卡15分钟后关机
+                    
+            else:
+                self.no_smi_count = 0
+
+            msg_nums = sms.getMsgNums() #获取短信条数
+            # EventMesh.debug_log("msg_nums",msg_nums)
+            if(msg_nums != -1):
+                sms_data = sms.getSaveLoc()
+                sms_max = sms_data[0][2]
+                if msg_nums >= sms_max-1:
+                    EventMesh.publish("delete_sms_event")#
+
+            #佩戴检测
+            WEAR = EventMesh.publish(constants.EVENT.GET_WEAR)#佩戴数据
+            if self.wear != WEAR:
+                remove_sw = EventMesh.publish("get_storage_config","remove_sw")
+                if remove_sw == "1":#开启了佩戴检测的开关
+                    dev_state =  EventMesh.publish("get_dev_state")
+                    
+                    if WEAR != 1:
+                        tmp = 1 << 3
+                        tmp = ~tmp
+                        tmp = 1 << 20
+                        dev_state = dev_state|tmp #第20位=1
+                    # else :     
+                    #     pass              
+                        
+                    #     tmp = 1 << 20
+                    #     dev_state = dev_state|tmp #第20位=1
+                    #     tmp = 1 << 3
+                    #     dev_state = dev_state|tmp #第三位=1
+                        EventMesh.debug_log("佩戴检测:{}".format(dev_state))    
+                        EventMesh.publish("set_dev_state",dev_state)
+                        EventMesh.publish(constants.EVENT.START_LOCATION,[constants.PROTOCOL.AL_SEND,dev_state]) #开始AL定位,发送报警
+                        #EventMesh.publish(constants.PROTOCOL.HELP_SEND,65)
+            self.wear = WEAR
+            """定时测量心率,血氧,体温"""
+            self.get_hr_state = EventMesh.publish("get_hr_state")
+            self.get_spo2_state = EventMesh.publish("get_spo2_state")
+            get_temp_time  = EventMesh.publish("get_temp_time")
+            get_temp_state  = EventMesh.publish("get_temp_state")
+            get_bp_state  = EventMesh.publish("get_bp_state")
+            get_bg_state  = EventMesh.publish("get_bg_state")
+            if get_bg_state == None:
+                get_bg_state = 0
+            if get_bp_state == None:
+                get_bp_state = 0
+
+            if get_temp_state == None:
+                get_temp_state = 0
+
+            if self.get_hr_state == None:
+                self.get_hr_state = 0
+            if self.get_spo2_state == None:
+                self.get_spo2_state = 0 
+        
+            call_state = EventMesh.publish("get_call_state")
+            if call_state == None:
+                call_state = 0
+            if battery[0] != "1":
+                if get_temp_state != None and call_state != None: #突然脱腕
+
+                    if get_temp_state > 1  and (WEAR != 1 or call_state != 0):
+                        EventMesh.publish(constants.EVENT.STOP_TEMP)
+                        EventMesh.publish("set_temp_state",0)       
+                        EventMesh.txt_log("auto stop_temp:22")
+
+                    if (self.get_hr_state > 1 or self.get_spo2_state > 1 or get_bp_state > 1 or get_bg_state > 1) and (WEAR != 1 or call_state != 0):
+                        # print("wear faile")
+                        if self.get_hr_state > 1 :
+                            EventMesh.txt_log("auto stop_hr:22")
+                            EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
+                            EventMesh.publish(constants.EVENT.STOP_HEART) 
+                            if WEAR == 1:
+                                heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                if heart_value > 50 and heart_value != None:
+                                    EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                            
+                        if self.get_spo2_state > 1:
+                            EventMesh.txt_log("auto stop_spo2:22")
+                            EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
 
-                if get_bp_state != None:
-                    if get_bp_state == 3:
-                        self.old_bp_time+=1
-                        if self.old_bp_time == 1:
-                            EventMesh.publish("set_bp_state",3)#2代表后台进入测试
-                            # EventMesh.publish("set_hr_blood_led",1)
-                            EventMesh.publish(constants.EVENT.START_HEART)
-                            EventMesh.txt_log("auto start_bp:333")
-                        elif self.old_bp_time > 6:
-                            self.old_bp_time = 0
+                            EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                            spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                            if WEAR == 1:
+                                if spo2_value > 85 and spo2_value != None:
+                                    EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
                             
-                            EventMesh.publish("set_bp_state",0)#2代表后台进入测试
-                            # EventMesh.publish("stop_led_timer")#设置参数
-                            blood_data = get_autoblood_value()
-                            if blood_data == None:
-                                blood_data[0] = 0
-                                blood_data[1] = 0
+                        if get_bp_state > 1:
 
-                            max_value = blood_data[0]
-                            min_value = blood_data[1]
-                            if max_value != 0 and min_value != 0:
-                                EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                            EventMesh.txt_log("auto stop_bp:22")
+                            EventMesh.publish("set_bp_state",0)#2代表后台进入测试
                             EventMesh.publish(constants.EVENT.STOP_HEART)
-                            EventMesh.txt_log("auto stop_bp:333")
-                    else:
-                        self.old_bp_time = 0
-                else:
-                    self.old_bp_time = 0
+                            if WEAR == 1:
+                                blood_data = get_autoblood_value()
+                                if blood_data == None:
+                                    blood_data[0] = 0
+                                    blood_data[1] = 0
 
-                if get_bg_state != None:
-                    if get_bg_state == 3:
-                        self.old_bg_time+=1
-                        if self.old_bg_time == 1:
-                            EventMesh.publish("set_bg_state",3)#2代表后台进入测试
-                            # EventMesh.publish("set_hr_blood_led",1)
-                            EventMesh.publish(constants.EVENT.START_HEART)
-                            EventMesh.txt_log("auto start_bg:333")
-                        elif self.old_bg_time > 6:
-                            self.old_bg_time = 0
+                                max_value = blood_data[0]
+                                min_value = blood_data[1]
+                                if max_value != 0 and min_value != 0:
+                                    EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                            
+                        if get_bg_state > 1:
+                            EventMesh.txt_log("auto stop_bg:22")
+                            
                             EventMesh.publish("set_bg_state",0)#2代表后台进入测试
                             EventMesh.publish(constants.EVENT.STOP_HEART)
-                            # EventMesh.publish("stop_led_timer")#设置参数
-                            bg_data = get_blood_sugar_value()
-                            if bg_data == None:
-                                bg_data = 0
-                            if bg_data != 0:
-                                EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bg_data)
-
-                            EventMesh.txt_log("auto stop_bp:333")
-                    else:
-                        self.old_bg_time = 0
-                else:
-                    self.old_bg_time = 0
-
-                
-                if get_temp_state != None:
-                    if get_temp_state == 3:#单次测量
-                        self.temp_one_state+=1
-                        if self.temp_one_state == 1:
-                            EventMesh.txt_log("auto start_temp:333")
-                            EventMesh.debug_log("AUTO one temp:2") 
-                            EventMesh.publish("set_temp_state",3)
-                            # EventMesh.publish("set_hr_blood_led",1)
-                            EventMesh.publish(constants.EVENT.START_TEMP)   
-                        elif self.temp_one_state > 3:
-                            self.temp_one_state = 0
-                            temp = EventMesh.publish(constants.EVENT.GET_TEMP) 
-                            temp = self.optimize_temp(temp)
+                            if WEAR == 1:
+                                bg_data = get_blood_sugar_value()
+                                if bg_data == None:
+                                    bg_data = 0
+                                if bg_data != 0:
+                                    # EventMesh.publish("play_sugar_value", bg_data)#播放血糖数值
+                                    EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bg_data)
                             
-                            EventMesh.publish("set_temp_state",0)
-                            tmp_f_tmp = 0
-                            tmp_d_tmp = 0
-                            if str(temp).find(".") != -1:
-                                tmp_f = str(temp).split('.')[0] 
-                                tmp_f_tmp = int(tmp_f)
-                                
-                                tmp_d = str(temp).split('.')[1][:1]
-                                tmp_d_tmp = int(tmp_d)
-                            else:
-                                tmp_f_tmp = temp
-                                
-                            if temp != None:
-                                if temp != 0:
-                                    EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
-                            EventMesh.publish(constants.EVENT.STOP_TEMP)
-                            EventMesh.txt_log("auto start_temp:333")
-
-
-      
-                
-                # EventMesh.debug_log("get_temp_time:{} self.temp_one_state:{}".format(get_temp_time,self.temp_one_state))
-                if get_temp_time != None:#定时测量体温
-                    if get_temp_time > 0:
-                        if get_temp_state != None:
-                            get_temp_state  = EventMesh.publish("get_temp_state")
-                            if get_temp_state == 0 or get_temp_state == 2:
-                                if (time_tmp-self.temp_time) >= get_temp_time:#大于一个周期的时间,重新赋值
-                                    self.temp_state = 0
-                                    self.temp_time = time_tmp
+            if self.pull_time == 0:
+                self.pull_time = time_tmp
+
+            # if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#已联网 并且不在充电 佩戴正常 不在通话就给测试心率
+            if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and battery[0] != "1" and WEAR == 1 and call_state == 0:
+                if time_tmp - self.pull_time >= 30:
+                    # EventMesh.debug_log("shifens:")  
+
+                    get_hr_state = EventMesh.publish("get_hr_state")
+                    get_spo2_state = EventMesh.publish("get_spo2_state")
+                    get_bp_state  = EventMesh.publish("get_bp_state")
+                    get_bg_state  = EventMesh.publish("get_bg_state")
+                    get_temp_state  = EventMesh.publish("get_temp_state")
+                    if get_hr_state == None:
+                        get_hr_state = 0
+                        self.old_hr_time = 0
 
-                                if self.old_temp_time != get_temp_time:#重复修改测量间隔时间
-                                    self.temp_time = time_tmp#防止改变时间的时候正在开启测量突然10s就停止测量 
-                                    self.temp_state = 0
-                                self.old_temp_time = get_temp_time
+                    if get_spo2_state == None:
+                        get_spo2_state = 0
+                        self.old_spo2_time = 0
 
-                                if (time_tmp-self.temp_time) == 0 and self.temp_state == 0:#一开始就测量 测量一分钟停止测量体温
-                                    self.temp_state = 1
-                                    EventMesh.publish("set_temp_state",2)
-                                    # EventMesh.publish("set_hr_blood_led",1)
-                                    EventMesh.debug_log("AUTO temp:") 
-                                    EventMesh.txt_log("auto START_temp:1")
-                                    EventMesh.publish(constants.EVENT.START_TEMP)
+                    if get_temp_state == None:
+                        get_temp_state = 0
+                        self.temp_one_state = 0
 
-                                elif (time_tmp-self.temp_time) >= 30 and self.temp_state == 1:
-                                    self.temp_state = 0
-                                    EventMesh.txt_log("auto stop_temp:1")
-                                    EventMesh.publish("set_temp_state",0)
-                                    temp = EventMesh.publish(constants.EVENT.GET_TEMP) 
-                                    temp = self.optimize_temp(temp)
-                                    
-                                    tmp_f_tmp = 0
-                                    tmp_d_tmp = 0
-                                    if str(temp).find(".") != -1:
-                                        tmp_f = str(temp).split('.')[0] 
-                                        tmp_f_tmp = int(tmp_f)
-                                        
-                                        tmp_d = str(temp).split('.')[1][:1]
-                                        tmp_d_tmp = int(tmp_d)
-                                    else:
-                                        tmp_f_tmp = temp
-                                        
-                                    if temp != None:
-                                        if temp != 0:
-                                            EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
-                                    EventMesh.publish(constants.EVENT.STOP_TEMP)
+                    if get_bp_state == None:
+                        get_bp_state = 0
+                        self.old_bp_time = 0
+                    
+                    if get_bg_state == None:
+                        get_bg_state = 0
+                        self.old_bg_time = 0
+                    
+                    # print("bp get_bp_state ",get_bp_state,self.old_bp_time)
 
-                            else:
-                                self.temp_state = 0
-                                self.old_temp_time = 0
+                    
+                    if get_hr_state != None:
+                        if get_hr_state == 3:
+                            self.old_hr_time+=1
+                            if self.old_hr_time == 1:
+                                EventMesh.publish("set_hr_state",3)#2代表后台进入测试
+                                # EventMesh.publish("set_hr_blood_led",1)
+                                EventMesh.publish(constants.EVENT.START_HEART)
+                                EventMesh.txt_log("auto start_hr:333")
+                            elif self.old_hr_time > 6:
+                                self.old_hr_time = 0
+                                EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                EventMesh.txt_log("auto stop_hr:333")
+                                EventMesh.publish(constants.EVENT.STOP_HEART)
+                                heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                EventMesh.debug_log("heart_value:{}".format(heart_value))
+                                if heart_value > 50 and heart_value != None:
+                                    EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                EventMesh.debug_log("STOP_HEART:3")
+                        else:
+                            self.old_hr_time = 0
                     else:
-                        temp_state  = EventMesh.publish("get_temp_state") 
-                        if temp_state == 2:
-                            EventMesh.publish("set_temp_state",0)#2代表后台进入测试
-                            # EventMesh.publish("stop_led_timer")#设置参数
-                            EventMesh.txt_log("auto wear stop_temp:2 ")
-                            EventMesh.publish(constants.EVENT.STOP_TEMP)
-                        self.temp_state = 0
-                        self.temp_time = 0
-                        self.old_temp_time = 0
-
-
-
-                hr_time = {}
-                hr_time = EventMesh.publish("get_time_hr")#获取时间是否大于0
+                        self.old_hr_time = 0
 
-                if hr_time[0] !=  None:
-                    self.mearsure_btn = int(hr_time[0])
-                    self.mearsure_timer = int(hr_time[1])
 
-                    if self.mearsure_btn != None and self.mearsure_timer != None:
-                        
-                        if self.mearsure_btn >= 1 and self.mearsure_timer > 0:#开关打开并且时间大于0就可以测试血糖
-                            get_hr_state = EventMesh.publish("get_hr_state")#心率
-                            get_spo2_state = EventMesh.publish("get_spo2_state")#血氧
-                            get_bp_state  = EventMesh.publish("get_bp_state")#血压
-                            get_bg_state  = EventMesh.publish("get_bg_state")#血糖
-                            # print("state hr",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
-                            if (get_bg_state == 0 and get_spo2_state == 0 and get_bp_state == 0) and  (get_hr_state == 2 or get_hr_state == 0):#心率血压血氧不在测试就测试血糖自动测量
-                                if (time_tmp-self.SENSOR_time) >= self.mearsure_timer:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
-                                    self.SENSOR_time = time_tmp
-                                    self.HR_Onestate = 0
-                                # print("time_tmp hr",time_tmp,self.SENSOR_time,time_tmp-self.SENSOR_time,self.mearsure_timer,self.HR_Onestate)
-                                if (time_tmp - self.SENSOR_time) == 0 and self.HR_Onestate == 0:
-                                    self.HR_Onestate = 1
-                                    EventMesh.txt_log("auto START_hr:1")
-                                    EventMesh.publish("set_hr_state",2)#2代表后台进入测试
-                                    # EventMesh.publish("set_hr_blood_led",1)
-                                    EventMesh.publish(constants.EVENT.START_HEART)
-                                    
-                                elif (time_tmp - self.SENSOR_time) >= 60 and self.HR_Onestate == 1:
-                                    self.HR_Onestate = 0
-                                    EventMesh.publish("set_hr_state",0)#2代表后台进入测试
-                                    EventMesh.debug_log("stop debug3")
-                                    EventMesh.txt_log("auto stop_hr:1")
-                                    EventMesh.publish(constants.EVENT.STOP_HEART)
-                                    heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
-                                    EventMesh.debug_log("heart_value:{}".format(heart_value))
-                                    # heart_value = 60+urandom.randint(0,10)
-                                    if heart_value > 50 and heart_value != None:
-                                        EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
-                                    #获取心率数据上传数据app
-                                    EventMesh.debug_log("STOP_HEART:")
-                                    
-                            else:
-                                self.HR_Onestate = 0
-                        else:
-                            self.SENSOR_time = 0
-                            self.HR_Onestate = 0
-                            hr_state = EventMesh.publish("get_hr_state")#心率
-                            if hr_state == 2:
-                                EventMesh.publish("set_hr_state",0)#2代表后台进入测试
-                                EventMesh.debug_log("33stop debug3")
-                                # EventMesh.publish("stop_led_timer")#设置参数
-                                EventMesh.publish(constants.EVENT.STOP_HEART)
-                                EventMesh.txt_log("auto wear stop_hr:2 ")
-
-                get_spo2time = EventMesh.publish("get_spo2_time")#血压自动测试
-                # print("get_spo2time",get_spo2time)
-                if get_spo2time != None:#血压时间不为0
-                    spo2_on = int(get_spo2time[0])
-                    spo2_time = int(get_spo2time[1])
-                    if spo2_on != 0 and spo2_time != 0:
-                        get_hr_state = EventMesh.publish("get_hr_state")
-                        get_spo2_state = EventMesh.publish("get_spo2_state")
-                        get_bp_state  = EventMesh.publish("get_bp_state")
-                        get_bg_state  = EventMesh.publish("get_bg_state")
-                        # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
-                        if (get_hr_state == 0 and get_bp_state == 0 and get_bg_state == 0) and (get_spo2_state == 2 or get_spo2_state == 0):#心率血压血氧不在测试就测试血糖自动测量
-                            if (time_tmp-self.spo2_timeSecond) >= spo2_time:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
-                                self.spo2_timeSecond = time_tmp
-                                self.spo2auto_state = 0
-                            # print("time_tmp spo2",time_tmp,self.spo2_timeSecond,time_tmp-self.spo2_timeSecond,self.bg_timer,self.bpauto_state)
-                            if (time_tmp - self.spo2_timeSecond) == 0 and self.spo2auto_state == 0:
-                                self.spo2auto_state = 1
-                                EventMesh.debug_log("START_spo2:auto")
-                                EventMesh.txt_log("auto START_spo2:1")
-                                EventMesh.publish("set_spo2_state",2)#2代表后台进入测试
+                    if get_spo2_state != None:
+                        if get_spo2_state == 3:
+                            self.old_spo2_time+=1
+                            if self.old_spo2_time == 1:
+                                EventMesh.publish("set_spo2_state",3)#2代表后台进入测试
+                                # EventMesh.publish("set_hr_blood_led",1)
                                 EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
-                                
-                            elif (time_tmp - self.spo2_timeSecond) >= 60 and self.spo2auto_state == 1:
+                                EventMesh.txt_log("auto start_spo2:333")
+                            elif self.old_spo2_time > 6:
+                                self.old_spo2_time = 0
+                                EventMesh.txt_log("auto stop_spo2:333")
                                 EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
-                                self.spo2auto_state = 0
                                 EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
                                 spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
                                 if spo2_value > 85 and spo2_value != None:
                                     EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
-                                EventMesh.txt_log("auto stop_spo2:1")
-                               
+                                    
                         else:
-                            self.spo2auto_state = 0
+                            self.old_spo2_time = 0
                     else:
-                        self.spo2_timeSecond = 0
-                        self.spo2auto_state = 0
-                        spo2_state = EventMesh.publish("get_spo2_state")#心率
-                        if spo2_state == 2:
-                            EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
-                            EventMesh.debug_log("spo2 stop debug3")
-                            EventMesh.txt_log("auto wear stop_spo2:2 ")
-                            EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                        self.old_spo2_time = 0
 
 
-                get_bptime = EventMesh.publish("get_bp_time")#血压自动测试
-                # print("get_bptime",get_bptime)
-                if get_bptime != None:#血压时间不为0
-                    bp_on = int(get_bptime[0])
-                    bp_time = int(get_bptime[1])
-                    if bp_on != 0 and bp_time != 0:
-                        get_hr_state = EventMesh.publish("get_hr_state")
-                        get_spo2_state = EventMesh.publish("get_spo2_state")
-                        get_bp_state  = EventMesh.publish("get_bp_state")
-                        get_bg_state  = EventMesh.publish("get_bg_state")
-                        # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
-                        
-                        if (get_hr_state == 0 and get_spo2_state == 0 and get_bg_state == 0) and (get_bp_state == 2 or get_bp_state == 0):#心率血压血氧不在测试就测试血糖自动测量
-                            if (time_tmp-self.bp_timeSecond) >= bp_time:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
-                                self.bp_timeSecond = time_tmp
-                                self.bpauto_state = 0
-                            # print("time_tmp bp",time_tmp,self.bp_timeSecond,time_tmp-self.bp_timeSecond,self.bg_timer,self.bpauto_state)
-                            if (time_tmp - self.bp_timeSecond) == 0 and self.bpauto_state == 0:
-                                self.bpauto_state = 1
-                                EventMesh.debug_log("START_bp:auto")
-                                EventMesh.txt_log("auto START_bp:1")
-                                EventMesh.publish("set_bp_state",2)#2代表后台进入测试
+                    if get_bp_state != None:
+                        if get_bp_state == 3:
+                            self.old_bp_time+=1
+                            if self.old_bp_time == 1:
+                                EventMesh.publish("set_bp_state",3)#2代表后台进入测试
                                 # EventMesh.publish("set_hr_blood_led",1)
                                 EventMesh.publish(constants.EVENT.START_HEART)
+                                EventMesh.txt_log("auto start_bp:333")
+                            elif self.old_bp_time > 6:
+                                self.old_bp_time = 0
                                 
-                            elif (time_tmp - self.bp_timeSecond) >= 60 and self.bpauto_state == 1:
-                                self.bpauto_state = 0
                                 EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                # EventMesh.publish("stop_led_timer")#设置参数
                                 blood_data = get_autoblood_value()
                                 if blood_data == None:
                                     blood_data[0] = 0
@@ -1727,77 +1465,369 @@ class DeviceInfoManager(Abstract):
                                 if max_value != 0 and min_value != 0:
                                     EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
                                 EventMesh.publish(constants.EVENT.STOP_HEART)
-                                EventMesh.txt_log("auto stop_bp:1")
-                                
+                                EventMesh.txt_log("auto stop_bp:333")
                         else:
-                            self.bpauto_state = 0
+                            self.old_bp_time = 0
                     else:
-                        self.bp_timeSecond = 0
-                        self.bpauto_state = 0
-                        bp_state = EventMesh.publish("get_bp_state")#心率
-                        if bp_state == 2:
-                            EventMesh.publish("set_bp_state",0)#2代表后台进入测试
-                            EventMesh.debug_log("bp stop debug3")
-                            EventMesh.txt_log("auto wear stop_bp:2 ")
-                            # EventMesh.publish("stop_led_timer")#设置参数
-                            EventMesh.publish(constants.EVENT.STOP_HEART)
-
-
+                        self.old_bp_time = 0
 
-                bg_time = {}
-                bg_time = EventMesh.publish("get_bgauto_time")
-                if bg_time[0] != None:
-                
-                    bg_btn = int(bg_time[0])
-                    bg_timer = int(bg_time[1]) 
-                    # print("state bg2",self.bg_btn,self.bg_timer)
-                    if bg_btn >= 1 and bg_timer > 0:#开关打开并且时间大于0就可以测试血糖
-                        get_hr_state = EventMesh.publish("get_hr_state")
-                        get_spo2_state = EventMesh.publish("get_spo2_state")
-                        get_bp_state  = EventMesh.publish("get_bp_state")
-                        get_bg_state  = EventMesh.publish("get_bg_state")
-                        # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
-                        
-                        if (get_hr_state == 0 and get_spo2_state == 0 and get_bp_state == 0) and (get_bg_state == 2 or get_bg_state == 0):#心率血压血氧不在测试就测试血糖自动测量
-                            if (time_tmp-self.bg_times) >= bg_timer:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
-                                self.bg_times = time_tmp #1780 
-                                self.BG_state = 0
-                            # print("time_tmp bg",time_tmp,self.bg_times,time_tmp-self.bg_times,bg_timer,self.BG_state)
-                            if (time_tmp - self.bg_times) == 0 and self.BG_state == 0:
-                                EventMesh.debug_log("START_bg:1")
-                                EventMesh.txt_log("auto START_bg:1")
-                                EventMesh.publish("set_bg_state",2)#2代表后台进入测试
+                    if get_bg_state != None:
+                        if get_bg_state == 3:
+                            self.old_bg_time+=1
+                            if self.old_bg_time == 1:
+                                EventMesh.publish("set_bg_state",3)#2代表后台进入测试
                                 # EventMesh.publish("set_hr_blood_led",1)
                                 EventMesh.publish(constants.EVENT.START_HEART)
-                                self.BG_state = 1
-                            elif (time_tmp - self.bg_times) >= 60 and self.BG_state == 1:
-                                self.BG_state = 0
+                                EventMesh.txt_log("auto start_bg:333")
+                            elif self.old_bg_time > 6:
+                                self.old_bg_time = 0
                                 EventMesh.publish("set_bg_state",0)#2代表后台进入测试
-                                # EventMesh.publish("stop_led_timer")#设置参数
-                                EventMesh.txt_log("auto stop_bg:1")
-                                EventMesh.debug_log("stop bgdebug3")
                                 EventMesh.publish(constants.EVENT.STOP_HEART)
-                                bgdata = get_blood_sugar_value()
-                                if bgdata == None:
-                                    bgdata = 0
-                                if bgdata != 0:
-                                    EventMesh.debug_log("bgdata",bgdata)
-                                    EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bgdata)#上传心率数据
+                                # EventMesh.publish("stop_led_timer")#设置参数
+                                bg_data = get_blood_sugar_value()
+                                if bg_data == None:
+                                    bg_data = 0
+                                if bg_data != 0:
+                                    EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bg_data)
+
+                                EventMesh.txt_log("auto stop_bp:333")
+                        else:
+                            self.old_bg_time = 0
+                    else:
+                        self.old_bg_time = 0
+
+                    
+                    if get_temp_state != None:
+                        if get_temp_state == 3:#单次测量
+                            self.temp_one_state+=1
+                            if self.temp_one_state == 1:
+                                EventMesh.txt_log("auto start_temp:333")
+                                EventMesh.debug_log("AUTO one temp:2") 
+                                EventMesh.publish("set_temp_state",3)
+                                # EventMesh.publish("set_hr_blood_led",1)
+                                EventMesh.publish(constants.EVENT.START_TEMP)   
+                            elif self.temp_one_state > 3:
+                                self.temp_one_state = 0
+                                temp = EventMesh.publish(constants.EVENT.GET_TEMP) 
+                                temp = self.optimize_temp(temp)
                                 
+                                EventMesh.publish("set_temp_state",0)
+                                tmp_f_tmp = 0
+                                tmp_d_tmp = 0
+                                if str(temp).find(".") != -1:
+                                    tmp_f = str(temp).split('.')[0] 
+                                    tmp_f_tmp = int(tmp_f)
+                                    
+                                    tmp_d = str(temp).split('.')[1][:1]
+                                    tmp_d_tmp = int(tmp_d)
+                                else:
+                                    tmp_f_tmp = temp
+                                    
+                                if temp != None:
+                                    if temp != 0:
+                                        EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                                EventMesh.publish(constants.EVENT.STOP_TEMP)
+                                EventMesh.txt_log("auto start_temp:333")
+
+
+        
+                    
+                    # EventMesh.debug_log("get_temp_time:{} self.temp_one_state:{}".format(get_temp_time,self.temp_one_state))
+                    if get_temp_time != None:#定时测量体温
+                        if get_temp_time > 0:
+                            if get_temp_state != None:
+                                get_temp_state  = EventMesh.publish("get_temp_state")
+                                if get_temp_state == 0 or get_temp_state == 2:
+                                    if (time_tmp-self.temp_time) >= get_temp_time:#大于一个周期的时间,重新赋值
+                                        self.temp_state = 0
+                                        self.temp_time = time_tmp
+
+                                    if self.old_temp_time != get_temp_time:#重复修改测量间隔时间
+                                        self.temp_time = time_tmp#防止改变时间的时候正在开启测量突然10s就停止测量 
+                                        self.temp_state = 0
+                                    self.old_temp_time = get_temp_time
+
+                                    if (time_tmp-self.temp_time) == 0 and self.temp_state == 0:#一开始就测量 测量一分钟停止测量体温
+                                        self.temp_state = 1
+                                        EventMesh.publish("set_temp_state",2)
+                                        # EventMesh.publish("set_hr_blood_led",1)
+                                        EventMesh.debug_log("AUTO temp:") 
+                                        EventMesh.txt_log("auto START_temp:1")
+                                        EventMesh.publish(constants.EVENT.START_TEMP)
+
+                                    elif (time_tmp-self.temp_time) >= 30 and self.temp_state == 1:
+                                        self.temp_state = 0
+                                        EventMesh.txt_log("auto stop_temp:1")
+                                        EventMesh.publish("set_temp_state",0)
+                                        temp = EventMesh.publish(constants.EVENT.GET_TEMP) 
+                                        temp = self.optimize_temp(temp)
+                                        
+                                        tmp_f_tmp = 0
+                                        tmp_d_tmp = 0
+                                        if str(temp).find(".") != -1:
+                                            tmp_f = str(temp).split('.')[0] 
+                                            tmp_f_tmp = int(tmp_f)
+                                            
+                                            tmp_d = str(temp).split('.')[1][:1]
+                                            tmp_d_tmp = int(tmp_d)
+                                        else:
+                                            tmp_f_tmp = temp
+                                            
+                                        if temp != None:
+                                            if temp != 0:
+                                                EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                                        EventMesh.publish(constants.EVENT.STOP_TEMP)
+
+                                else:
+                                    self.temp_state = 0
+                                    self.old_temp_time = 0
                         else:
+                            temp_state  = EventMesh.publish("get_temp_state") 
+                            if temp_state == 2:
+                                EventMesh.publish("set_temp_state",0)#2代表后台进入测试
+                                # EventMesh.publish("stop_led_timer")#设置参数
+                                EventMesh.txt_log("auto wear stop_temp:2 ")
+                                EventMesh.publish(constants.EVENT.STOP_TEMP)
+                            self.temp_state = 0
+                            self.temp_time = 0
+                            self.old_temp_time = 0
+
+
+
+                    hr_time = {}
+                    hr_time = EventMesh.publish("get_time_hr")#获取时间是否大于0
+
+                    if hr_time[0] !=  None:
+                        self.mearsure_btn = int(hr_time[0])
+                        self.mearsure_timer = int(hr_time[1])
+
+                        if self.mearsure_btn != None and self.mearsure_timer != None:
                             
+                            if self.mearsure_btn >= 1 and self.mearsure_timer > 0:#开关打开并且时间大于0就可以测试血糖
+                                get_hr_state = EventMesh.publish("get_hr_state")#心率
+                                get_spo2_state = EventMesh.publish("get_spo2_state")#血氧
+                                get_bp_state  = EventMesh.publish("get_bp_state")#血压
+                                get_bg_state  = EventMesh.publish("get_bg_state")#血糖
+                                # print("state hr",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                if (get_bg_state == 0 and get_spo2_state == 0 and get_bp_state == 0) and  (get_hr_state == 2 or get_hr_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                    if (time_tmp-self.SENSOR_time) >= self.mearsure_timer:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                        self.SENSOR_time = time_tmp
+                                        self.HR_Onestate = 0
+                                    # print("time_tmp hr",time_tmp,self.SENSOR_time,time_tmp-self.SENSOR_time,self.mearsure_timer,self.HR_Onestate)
+                                    if (time_tmp - self.SENSOR_time) == 0 and self.HR_Onestate == 0:
+                                        self.HR_Onestate = 1
+                                        EventMesh.txt_log("auto START_hr:1")
+                                        EventMesh.publish("set_hr_state",2)#2代表后台进入测试
+                                        # EventMesh.publish("set_hr_blood_led",1)
+                                        EventMesh.publish(constants.EVENT.START_HEART)
+                                        
+                                    elif (time_tmp - self.SENSOR_time) >= 60 and self.HR_Onestate == 1:
+                                        self.HR_Onestate = 0
+                                        EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                        EventMesh.debug_log("stop debug3")
+                                        EventMesh.txt_log("auto stop_hr:1")
+                                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                                        heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                        EventMesh.debug_log("heart_value:{}".format(heart_value))
+                                        # heart_value = 60+urandom.randint(0,10)
+                                        if heart_value > 50 and heart_value != None:
+                                            EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                        #获取心率数据上传数据app
+                                        EventMesh.debug_log("STOP_HEART:")
+                                        
+                                else:
+                                    self.HR_Onestate = 0
+                            else:
+                                self.SENSOR_time = 0
+                                self.HR_Onestate = 0
+                                hr_state = EventMesh.publish("get_hr_state")#心率
+                                if hr_state == 2:
+                                    EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                    EventMesh.debug_log("33stop debug3")
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    EventMesh.txt_log("auto wear stop_hr:2 ")
+
+                    get_spo2time = EventMesh.publish("get_spo2_time")#血压自动测试
+                    # print("get_spo2time",get_spo2time)
+                    if get_spo2time != None:#血压时间不为0
+                        spo2_on = int(get_spo2time[0])
+                        spo2_time = int(get_spo2time[1])
+                        if spo2_on != 0 and spo2_time != 0:
+                            get_hr_state = EventMesh.publish("get_hr_state")
+                            get_spo2_state = EventMesh.publish("get_spo2_state")
+                            get_bp_state  = EventMesh.publish("get_bp_state")
+                            get_bg_state  = EventMesh.publish("get_bg_state")
+                            # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                            if (get_hr_state == 0 and get_bp_state == 0 and get_bg_state == 0) and (get_spo2_state == 2 or get_spo2_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                if (time_tmp-self.spo2_timeSecond) >= spo2_time:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                    self.spo2_timeSecond = time_tmp
+                                    self.spo2auto_state = 0
+                                # print("time_tmp spo2",time_tmp,self.spo2_timeSecond,time_tmp-self.spo2_timeSecond,self.bg_timer,self.bpauto_state)
+                                if (time_tmp - self.spo2_timeSecond) == 0 and self.spo2auto_state == 0:
+                                    self.spo2auto_state = 1
+                                    EventMesh.debug_log("START_spo2:auto")
+                                    EventMesh.txt_log("auto START_spo2:1")
+                                    EventMesh.publish("set_spo2_state",2)#2代表后台进入测试
+                                    EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
+                                    
+                                elif (time_tmp - self.spo2_timeSecond) >= 60 and self.spo2auto_state == 1:
+                                    EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                                    self.spo2auto_state = 0
+                                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                    spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                    if spo2_value > 85 and spo2_value != None:
+                                        EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                    EventMesh.txt_log("auto stop_spo2:1")
+                                
+                            else:
+                                self.spo2auto_state = 0
+                        else:
+                            self.spo2_timeSecond = 0
+                            self.spo2auto_state = 0
+                            spo2_state = EventMesh.publish("get_spo2_state")#心率
+                            if spo2_state == 2:
+                                EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                                EventMesh.debug_log("spo2 stop debug3")
+                                EventMesh.txt_log("auto wear stop_spo2:2 ")
+                                EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+
+
+                    get_bptime = EventMesh.publish("get_bp_time")#血压自动测试
+                    # print("get_bptime",get_bptime)
+                    if get_bptime != None:#血压时间不为0
+                        bp_on = int(get_bptime[0])
+                        bp_time = int(get_bptime[1])
+                        if bp_on != 0 and bp_time != 0:
+                            get_hr_state = EventMesh.publish("get_hr_state")
+                            get_spo2_state = EventMesh.publish("get_spo2_state")
+                            get_bp_state  = EventMesh.publish("get_bp_state")
+                            get_bg_state  = EventMesh.publish("get_bg_state")
+                            # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                            
+                            if (get_hr_state == 0 and get_spo2_state == 0 and get_bg_state == 0) and (get_bp_state == 2 or get_bp_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                if (time_tmp-self.bp_timeSecond) >= bp_time:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                    self.bp_timeSecond = time_tmp
+                                    self.bpauto_state = 0
+                                # print("time_tmp bp",time_tmp,self.bp_timeSecond,time_tmp-self.bp_timeSecond,self.bg_timer,self.bpauto_state)
+                                if (time_tmp - self.bp_timeSecond) == 0 and self.bpauto_state == 0:
+                                    self.bpauto_state = 1
+                                    EventMesh.debug_log("START_bp:auto")
+                                    EventMesh.txt_log("auto START_bp:1")
+                                    EventMesh.publish("set_bp_state",2)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_HEART)
+                                    
+                                elif (time_tmp - self.bp_timeSecond) >= 60 and self.bpauto_state == 1:
+                                    self.bpauto_state = 0
+                                    EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                    blood_data = get_autoblood_value()
+                                    if blood_data == None:
+                                        blood_data[0] = 0
+                                        blood_data[1] = 0
+
+                                    max_value = blood_data[0]
+                                    min_value = blood_data[1]
+                                    if max_value != 0 and min_value != 0:
+                                        EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    EventMesh.txt_log("auto stop_bp:1")
+                                    
+                            else:
+                                self.bpauto_state = 0
+                        else:
+                            self.bp_timeSecond = 0
+                            self.bpauto_state = 0
+                            bp_state = EventMesh.publish("get_bp_state")#心率
+                            if bp_state == 2:
+                                EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                EventMesh.debug_log("bp stop debug3")
+                                EventMesh.txt_log("auto wear stop_bp:2 ")
+                                # EventMesh.publish("stop_led_timer")#设置参数
+                                EventMesh.publish(constants.EVENT.STOP_HEART)
+
+
+
+                    bg_time = {}
+                    bg_time = EventMesh.publish("get_bgauto_time")
+                    if bg_time[0] != None:
+                    
+                        bg_btn = int(bg_time[0])
+                        bg_timer = int(bg_time[1]) 
+                        # print("state bg2",self.bg_btn,self.bg_timer)
+                        if bg_btn >= 1 and bg_timer > 0:#开关打开并且时间大于0就可以测试血糖
+                            get_hr_state = EventMesh.publish("get_hr_state")
+                            get_spo2_state = EventMesh.publish("get_spo2_state")
+                            get_bp_state  = EventMesh.publish("get_bp_state")
+                            get_bg_state  = EventMesh.publish("get_bg_state")
+                            # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                            
+                            if (get_hr_state == 0 and get_spo2_state == 0 and get_bp_state == 0) and (get_bg_state == 2 or get_bg_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                if (time_tmp-self.bg_times) >= bg_timer:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                    self.bg_times = time_tmp #1780 
+                                    self.BG_state = 0
+                                # print("time_tmp bg",time_tmp,self.bg_times,time_tmp-self.bg_times,bg_timer,self.BG_state)
+                                if (time_tmp - self.bg_times) == 0 and self.BG_state == 0:
+                                    EventMesh.debug_log("START_bg:1")
+                                    EventMesh.txt_log("auto START_bg:1")
+                                    EventMesh.publish("set_bg_state",2)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_HEART)
+                                    self.BG_state = 1
+                                elif (time_tmp - self.bg_times) >= 60 and self.BG_state == 1:
+                                    self.BG_state = 0
+                                    EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    EventMesh.txt_log("auto stop_bg:1")
+                                    EventMesh.debug_log("stop bgdebug3")
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    bgdata = get_blood_sugar_value()
+                                    if bgdata == None:
+                                        bgdata = 0
+                                    if bgdata != 0:
+                                        EventMesh.debug_log("bgdata",bgdata)
+                                        EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bgdata)#上传心率数据
+                                    
+                            else:
+                                
+                                self.BG_state = 0
+                        else:
+                            bg_state  = EventMesh.publish("get_bg_state") 
+                            if bg_state == 2:
+                                EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                # EventMesh.publish("stop_led_timer")#设置参数
+                                EventMesh.debug_log("bg stop bgdebug3")
+                                EventMesh.txt_log("auto wear stop_bg:2 ")
+                                EventMesh.publish(constants.EVENT.STOP_HEART)
+                            self.bg_times = 0
                             self.BG_state = 0
-                    else:
-                        bg_state  = EventMesh.publish("get_bg_state") 
-                        if bg_state == 2:
-                            EventMesh.publish("set_bg_state",0)#2代表后台进入测试
-                            # EventMesh.publish("stop_led_timer")#设置参数
-                            EventMesh.debug_log("bg stop bgdebug3")
-                            EventMesh.txt_log("auto wear stop_bg:2 ")
-                            EventMesh.publish(constants.EVENT.STOP_HEART)
-                        self.bg_times = 0
-                        self.BG_state = 0
-                
+                    
+                else:
+                    self.old_temp_time = 0
+                    self.old_time = 0
+                    # self.SENSOR_time = time_tmp
+                    self.HR_Onestate = 0
+                    self.HR_OneTime = 0
+                    self.HR_state = 0
+                    self.old_time = 0    
+                    self.old_bp_time = 0
+                    self.old_hr_time = 0
+                    self.old_spo2_time = 0
+                    self.set_hsenor_crt = 0
+                    self.old_bg_time = 0
+                    # self.bg_times = time_tmp
+                    self.BG_state = 0
+                    # self.temp_time = time_tmp
+
+                    # self.bp_timeSecond = time_tmp
+                    self.bpauto_state = 0
+
+                    # self.spo2_timeSecond = time_tmp
+                    self.spo2auto_state = 0
+
+                    self.temp_state = 0
+                    self.temp_one_state = 0
+
             else:
                 self.old_temp_time = 0
                 self.old_time = 0
@@ -1812,6 +1842,7 @@ class DeviceInfoManager(Abstract):
                 self.set_hsenor_crt = 0
                 self.old_bg_time = 0
                 # self.bg_times = time_tmp
+
                 self.BG_state = 0
                 # self.temp_time = time_tmp
 
@@ -1824,213 +1855,74 @@ class DeviceInfoManager(Abstract):
                 self.temp_state = 0
                 self.temp_one_state = 0
 
-        else:
-            self.old_temp_time = 0
-            self.old_time = 0
-            # self.SENSOR_time = time_tmp
-            self.HR_Onestate = 0
-            self.HR_OneTime = 0
-            self.HR_state = 0
-            self.old_time = 0    
-            self.old_bp_time = 0
-            self.old_hr_time = 0
-            self.old_spo2_time = 0
-            self.set_hsenor_crt = 0
-            self.old_bg_time = 0
-            # self.bg_times = time_tmp
-
-            self.BG_state = 0
-            # self.temp_time = time_tmp
-
-            # self.bp_timeSecond = time_tmp
-            self.bpauto_state = 0
-
-            # self.spo2_timeSecond = time_tmp
-            self.spo2auto_state = 0
-
-            self.temp_state = 0
-            self.temp_one_state = 0
-
-            get_hr_state = EventMesh.publish("get_hr_state")
-            get_spo2_state = EventMesh.publish("get_spo2_state")
-            get_bp_state  = EventMesh.publish("get_bp_state")
-            get_bg_state  = EventMesh.publish("get_bg_state")
-            if get_hr_state != None and get_spo2_state != None and get_bp_state != None and get_bg_state != None:
-                if get_hr_state > 1:
-                    EventMesh.txt_log("auto stop_hr:44")
-                    EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
-                    # if get_hr_state == 3:
-                    #     EventMesh.publish("stop_led_timer")#设置参数
-                    EventMesh.debug_log("stop debug8")
-                    if WEAR == 1:
-                        heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
-                        if heart_value > 50 and heart_value != None:
-                            EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
-                    EventMesh.publish(constants.EVENT.STOP_HEART) 
-                elif get_spo2_state > 1:
-                    EventMesh.txt_log("auto stop_spo2:44")
-                    EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
-                    # if get_spo2_state == 3:
-                    #     EventMesh.publish("stop_led_timer")#设置参数
-                    if WEAR == 1:
-                        spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
-                        if spo2_value > 85 and spo2_value != None:
-                            EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
-                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
-                    EventMesh.debug_log("stop debug13")
-                elif get_bp_state > 1:
-                    EventMesh.txt_log("auto stop_bp:44")
-                    EventMesh.publish("set_bp_state",0)#2代表后台进入测试
-                    # if get_bp_state == 3:
-                    #     EventMesh.publish("stop_led_timer")#设置参数
-                    if WEAR == 1:
-                        blood_data = get_autoblood_value()
-                        if blood_data == None:
-                            blood_data[0] = 0
-                            blood_data[1] = 0
-
-                        max_value = blood_data[0]
-                        min_value = blood_data[1]
-                        if max_value != 0 and min_value != 0:
-                            EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
-                    EventMesh.publish(constants.EVENT.STOP_HEART)
-                    EventMesh.debug_log("stop debug14")
-                elif get_bg_state > 1:
-                    EventMesh.txt_log("auto stop_bg:44")
-                    EventMesh.publish("set_bg_state",0)#2代表后台进入测试
-                    # if get_bg_state == 3:
-                    #     EventMesh.publish("stop_led_timer")#设置参数
-                    EventMesh.publish(constants.EVENT.STOP_HEART)
-                    if WEAR == 1:
-                        bgdata = get_blood_sugar_value()
-                        if bgdata == None:
-                            bgdata = 0
-                        if bgdata != 0:
-                            EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bgdata)#上传心率数据
-                    EventMesh.debug_log("stop debug15")
-
-            if get_temp_time != None:
-                get_temp_state  = EventMesh.publish("get_temp_state")
-                if get_temp_state > 1:
-                    self.temp_one_state = 0
-                    self.temp_state = 0
-                    temp = EventMesh.publish(constants.EVENT.GET_TEMP)       
-                    temp = self.optimize_temp(temp)
-                    EventMesh.txt_log("auto stop_temp:44")
-                    EventMesh.publish("set_temp_state",0)
-                    if WEAR == 1:
-                        tmp_f_tmp = 0
-                        tmp_d_tmp = 0
-                        if str(temp).find(".") != -1:
-                            tmp_f = str(temp).split('.')[0] 
-                            tmp_f_tmp = int(tmp_f)
-                            
-                            tmp_d = str(temp).split('.')[1][:1]
-                            tmp_d_tmp = int(tmp_d)
-                        else:
-                            tmp_f_tmp = temp
-                            
-                        if temp != None:
-                            if temp != 0:
-                                EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
-                    EventMesh.publish(constants.EVENT.STOP_TEMP)
-
-        
-
-
-        hr_state = EventMesh.publish("get_hr_state")
-        spo2_state = EventMesh.publish("get_spo2_state")
-        temp_state  = EventMesh.publish("get_temp_state")
-        if hr_state != None or spo2_state != None or temp_state != None:#手动测试
-            auto_hr = EventMesh.publish("get_start_measure_time")#设置开始测量的时间戳时间
-            if auto_hr == None:
-                auto_hr = 0
-            if hr_state == 1:
-                if auto_hr != 0:
-                    self.auto_hr_count+=1
-                    if  self.auto_hr_count > 6:
-                        self.auto_hr_count = 0
-                        EventMesh.publish("set_hr_state",0)#0代表g关闭测试
-                        EventMesh.debug_log("stop debug7")
-                        EventMesh.publish(constants.EVENT.STOP_HEART)
-                        heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
-                        if heart_value > 50 and heart_value != None:
-                            EventMesh.publish("play_hr_value",heart_value)
-                            # EventMesh.publish("set_history_hr_value",heart_value)
-                            EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
-
-                            if EventMesh.model == "D15_" :#D15型号
-                                blood_data = get_autoblood_value()
-                                if blood_data == None:
-                                    blood_data[0] = 0
-                                    blood_data[1] = 0
-
-                                max_value = blood_data[0]
-                                min_value = blood_data[1]
-                                if max_value != 0 and min_value != 0:
-                                    EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
-                                pass
-
-                        else:
-                            EventMesh.publish("play_hr_value",0) 
-                        
-                        
-
-                    else :
-                        if WEAR != 1:
-                            EventMesh.publish("set_hr_state",0)#0代表g关闭测试
-                            EventMesh.debug_log("stop debug7")
-                            EventMesh.publish(constants.EVENT.STOP_HEART)                               
-                            EventMesh.publish("play_hr_value",0) 
-                            
-            else:
-                self.auto_hr_count = 0
-                
-
-            auto_spo2 = EventMesh.publish("get_start_measure_time")#设置开始测量的时间戳时间
-            if auto_spo2 == None:
-                auto_spo2 = 0
-            if spo2_state == 1:#手动测试血氧
-                if auto_spo2 != None:
-                    if auto_spo2 != 0:
-                        self.auto_spo2_count+=1
-                        if self.auto_spo2_count > 6:
-                            self.auto_spo2_count = 0
-                            EventMesh.publish("set_spo2_state",0)#0代表g关闭测试
-                            EventMesh.debug_log("stop spo2 debug7")
-                            EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                get_hr_state = EventMesh.publish("get_hr_state")
+                get_spo2_state = EventMesh.publish("get_spo2_state")
+                get_bp_state  = EventMesh.publish("get_bp_state")
+                get_bg_state  = EventMesh.publish("get_bg_state")
+                if get_hr_state != None and get_spo2_state != None and get_bp_state != None and get_bg_state != None:
+                    if get_hr_state > 1:
+                        EventMesh.txt_log("auto stop_hr:44")
+                        EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
+                        # if get_hr_state == 3:
+                        #     EventMesh.publish("stop_led_timer")#设置参数
+                        EventMesh.debug_log("stop debug8")
+                        if WEAR == 1:
+                            heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                            if heart_value > 50 and heart_value != None:
+                                EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                        EventMesh.publish(constants.EVENT.STOP_HEART) 
+                    elif get_spo2_state > 1:
+                        EventMesh.txt_log("auto stop_spo2:44")
+                        EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                        # if get_spo2_state == 3:
+                        #     EventMesh.publish("stop_led_timer")#设置参数
+                        if WEAR == 1:
                             spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
                             if spo2_value > 85 and spo2_value != None:
-                                EventMesh.publish("play_spo2_value",spo2_value)
-                                EventMesh.publish("set_old_spo2_data",spo2_value)
                                 EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
-                            else:
-                                EventMesh.publish("play_spo2_value",0)
-                           
-                        else:
-                            if WEAR != 1:
-                                EventMesh.publish("set_spo2_state",0)#0代表g关闭测试
-                                EventMesh.debug_log("stop debug8")
-                                EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)                               
-                                EventMesh.publish("play_spo2_value",0) 
-                                
-            else:
-                self.auto_spo2_count = 0
-
-            if temp_state == 1:#手动测试体温
-                auto_temp = EventMesh.publish("get_start_temp_measure_time")#设置开始测量的时间戳时间
-                if auto_temp == None:
-                    auto_temp = 0
-                if auto_temp != None:
-                    if auto_temp != 0:
-                        self.auto_temp_count += 1
-                        if self.auto_temp_count > 6:
-                            self.auto_temp_count = 0
-                            EventMesh.debug_log("体温测量结束")
-                            temp = EventMesh.publish(constants.EVENT.GET_TEMP)       
-                            temp = self.optimize_temp(temp)
-                            EventMesh.debug_log("temp",temp)
-                            EventMesh.publish("set_temp_state",0)
+                        EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                        EventMesh.debug_log("stop debug13")
+                    elif get_bp_state > 1:
+                        EventMesh.txt_log("auto stop_bp:44")
+                        EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                        # if get_bp_state == 3:
+                        #     EventMesh.publish("stop_led_timer")#设置参数
+                        if WEAR == 1:
+                            blood_data = get_autoblood_value()
+                            if blood_data == None:
+                                blood_data[0] = 0
+                                blood_data[1] = 0
+
+                            max_value = blood_data[0]
+                            min_value = blood_data[1]
+                            if max_value != 0 and min_value != 0:
+                                EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                        EventMesh.debug_log("stop debug14")
+                    elif get_bg_state > 1:
+                        EventMesh.txt_log("auto stop_bg:44")
+                        EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                        # if get_bg_state == 3:
+                        #     EventMesh.publish("stop_led_timer")#设置参数
+                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                        if WEAR == 1:
+                            bgdata = get_blood_sugar_value()
+                            if bgdata == None:
+                                bgdata = 0
+                            if bgdata != 0:
+                                EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bgdata)#上传心率数据
+                        EventMesh.debug_log("stop debug15")
+
+                if get_temp_time != None:
+                    get_temp_state  = EventMesh.publish("get_temp_state")
+                    if get_temp_state > 1:
+                        self.temp_one_state = 0
+                        self.temp_state = 0
+                        temp = EventMesh.publish(constants.EVENT.GET_TEMP)       
+                        temp = self.optimize_temp(temp)
+                        EventMesh.txt_log("auto stop_temp:44")
+                        EventMesh.publish("set_temp_state",0)
+                        if WEAR == 1:
                             tmp_f_tmp = 0
                             tmp_d_tmp = 0
                             if str(temp).find(".") != -1:
@@ -2044,2959 +1936,3071 @@ class DeviceInfoManager(Abstract):
                                 
                             if temp != None:
                                 if temp != 0:
-                                    # EventMesh.publish("set_history_temp_value",temp)
-                                    EventMesh.publish("play_temp_value",temp)#播放体温数值
                                     EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
-                                else:
-                                    # EventMesh.publish("set_history_temp_value",0)
-                                    EventMesh.publish("play_temp_value",0)#播放体温数值
-                            
-                            EventMesh.publish(constants.EVENT.STOP_TEMP)
+                        EventMesh.publish(constants.EVENT.STOP_TEMP)
 
-                        else :
-                            if WEAR  != 1:
-                                EventMesh.publish("set_temp_state",0)#0代表g关闭测试
-                                EventMesh.debug_log("stop debug9")
-                                EventMesh.publish(constants.EVENT.STOP_TEMP)                               
-                                EventMesh.publish("play_temp_value",0) 
-                                
-            else:
-                self.auto_temp_count = 0
+            
 
-        EventMesh.publish("play_unread_wechat_infor")#每10s检测是否有未读语音数据
 
-        usb_state = EventMesh.publish("get_usb")#
-        
+            hr_state = EventMesh.publish("get_hr_state")
+            spo2_state = EventMesh.publish("get_spo2_state")
+            temp_state  = EventMesh.publish("get_temp_state")
+            if hr_state != None or spo2_state != None or temp_state != None:#手动测试
+                auto_hr = EventMesh.publish("get_start_measure_time")#设置开始测量的时间戳时间
+                if auto_hr == None:
+                    auto_hr = 0
+                if hr_state == 1:
+                    if auto_hr != 0:
+                        self.auto_hr_count+=1
+                        if  self.auto_hr_count > 6:
+                            self.auto_hr_count = 0
+                            EventMesh.publish("set_hr_state",0)#0代表g关闭测试
+                            EventMesh.debug_log("stop debug7")
+                            EventMesh.publish(constants.EVENT.STOP_HEART)
+                            heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                            if heart_value > 50 and heart_value != None:
+                                EventMesh.publish("play_hr_value",heart_value)
+                                # EventMesh.publish("set_history_hr_value",heart_value)
+                                EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
 
-        if battery[0] == '1':
-            # EventMesh.debug_log("battery[1]",battery[1])
-            if self.vbat_full_flag <= 120:
-                self.vbat_full_flag+=10
-                if self.vbat_full_flag == 60:#开机检测一次如果是充电标识为1就不再提示
-                    if usb_state != 1:
-                        EventMesh.publish("set_usb",1)#
-            else:
-                if battery[1] >= 100:
-                    if self.charge_full_count == 0:#充电已满
-                        EventMesh.publish("set_usb",3)#
-                        EventMesh.debug_log("charge R_CHARGE_full")
-                        self.charge_full_count = 1
-                
-        else:
-            self.charge_full_count = 0
-            low_power = battery[1]
-            if low_power <= 5:#小于5%红色灯慢闪
-                EventMesh.publish("set_led_time_arg",[1,2,20*11,led_mode.FLASH_LIGHT_RED,20,10,led_mode.OTHER_MEASURE_MODE])#測量成功
-                # EventMesh.publish("set_led_time_arg",[1000,400,52,led_mode.FLASH_LIGHT_RED,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#開始測量
+                                if EventMesh.model == "D15" :#D15型号
+                                    blood_data = get_autoblood_value()
+                                    if blood_data == None:
+                                        blood_data[0] = 0
+                                        blood_data[1] = 0
 
-        
-        self.normal_alarm()
-        #喝水提醒
-        self.drink_alarm()
-        #该吃药了
-        self.medicine_alarm()
-        #该起床了
-        self.wakeup_alarm()
-        #该睡觉了
-        self.sleep_alarm()
-        #该回家了
-        self.home_alarm()
-        #该休息了
-        self.reset_alarm()
+                                    max_value = blood_data[0]
+                                    min_value = blood_data[1]
+                                    if max_value != 0 and min_value != 0:
+                                        EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                    pass
 
+                            else:
+                                EventMesh.publish("play_hr_value",0) 
+                            
+                            
 
-        if self.alarm_flag == 0:
-            self.alarm_flag = 1
-            EventMesh.publish("set_rtc_alarm")
+                        else :
+                            if WEAR != 1:
+                                EventMesh.publish("set_hr_state",0)#0代表g关闭测试
+                                EventMesh.debug_log("stop debug7")
+                                EventMesh.publish(constants.EVENT.STOP_HEART)                               
+                                EventMesh.publish("play_hr_value",0) 
+                                
+                else:
+                    self.auto_hr_count = 0
+                    
 
-    def clear_usb_flag(self,event,msg):
-        self.charge_full_count = 0
-    #普通闹钟
-    def normal_alarm(self):
-        data = RTC().datetime()
-        hour = data[4]
-        min = data[5]
-
-        week = int(data[3])
-
-        date1 = data[1]
-        date2 = data[2]
-        cur_total_min = int(hour)*60+int(min)
-        # EventMesh.debug_log("self.normal_oldtotalmin",self.normal_oldtotalmin,cur_total_min,self.alarm_flag)
-        if self.normal_oldtotalmin == 0:
-            self.normal_oldtotalmin = cur_total_min #549
-        if self.normal_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
-            if self.normal_flag == 1:
-                self.normal_flag = 0
-                self.normal_count = 0
-        normal_alarm = []
-        normal_alarm = EventMesh.publish("get_storage_config","normal_alarm")
-        # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
-        if self.normal_flag == 1:#表示闹钟响过清除标志
-            self.normal_count+=1
-            if self.normal_count > 6:
-                self.normal_count = 0
-                self.normal_flag = 0
-        if normal_alarm != None:
-            if len(normal_alarm) != 0 and normal_alarm != []:
-                j = 0
-                for i in range(len(normal_alarm)):
-                    # EventMesh.debug_log("normal_alarm normal_alarm 33",normal_alarm,j)
-                    normalalarm_hour = normal_alarm[j]["hour"]
-                    normalalarm_min = normal_alarm[j]["min"]
-                    normalalarm_day = normal_alarm[j]["day"]
-                    normalalarm_enale = normal_alarm[j]["enable"]
-                    normalalarm_totalmin = int(normalalarm_hour)*60+int(normalalarm_min)
-                    # EventMesh.debug_log("wake alarm",normalalarm_hour,sleep_min,sleep_day,sleep_enale,sleep_totalmin,week)
-                    if normalalarm_day == []:#单次闹钟只响一次
-                        if normalalarm_enale != 0:
-                            if cur_total_min > normalalarm_totalmin:
-                                normal_alarm.pop(j)
-                                self.normal_count = 0
-                                self.normal_flag  = 0 
-                                j=0
-                                # EventMesh.debug_log("wakeup wakeup dayu",sleep,j)
-                                EventMesh.publish("set_storage_config",["normal_alarm",normal_alarm])#删除之后重新保存
-                                # sleep = EventMesh.publish("get_storage_config","sleep_alarm")#删除之后重新保存
-                                continue
+                auto_spo2 = EventMesh.publish("get_start_measure_time")#设置开始测量的时间戳时间
+                if auto_spo2 == None:
+                    auto_spo2 = 0
+                if spo2_state == 1:#手动测试血氧
+                    if auto_spo2 != None:
+                        if auto_spo2 != 0:
+                            self.auto_spo2_count+=1
+                            if self.auto_spo2_count > 6:
+                                self.auto_spo2_count = 0
+                                EventMesh.publish("set_spo2_state",0)#0代表g关闭测试
+                                EventMesh.debug_log("stop spo2 debug7")
+                                EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                if spo2_value > 85 and spo2_value != None:
+                                    EventMesh.publish("play_spo2_value",spo2_value)
+                                    EventMesh.publish("set_old_spo2_data",spo2_value)
+                                    EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                else:
+                                    EventMesh.publish("play_spo2_value",0)
+                            
                             else:
-                                if normalalarm_totalmin == cur_total_min and self.normal_flag == 0:#14:00
-                                    self.normal_count = 0
-                                    self.normal_flag  = 0    
+                                if WEAR != 1:
+                                    EventMesh.publish("set_spo2_state",0)#0代表g关闭测试
+                                    EventMesh.debug_log("stop debug8")
+                                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)                               
+                                    EventMesh.publish("play_spo2_value",0) 
+                                    
+                else:
+                    self.auto_spo2_count = 0
+
+                if temp_state == 1:#手动测试体温
+                    auto_temp = EventMesh.publish("get_start_temp_measure_time")#设置开始测量的时间戳时间
+                    if auto_temp == None:
+                        auto_temp = 0
+                    if auto_temp != None:
+                        if auto_temp != 0:
+                            self.auto_temp_count += 1
+                            if self.auto_temp_count > 6:
+                                self.auto_temp_count = 0
+                                EventMesh.debug_log("体温测量结束")
+                                temp = EventMesh.publish(constants.EVENT.GET_TEMP)       
+                                temp = self.optimize_temp(temp)
+                                EventMesh.debug_log("temp",temp)
+                                EventMesh.publish("set_temp_state",0)
+                                tmp_f_tmp = 0
+                                tmp_d_tmp = 0
+                                if str(temp).find(".") != -1:
+                                    tmp_f = str(temp).split('.')[0] 
+                                    tmp_f_tmp = int(tmp_f)
+                                    
+                                    tmp_d = str(temp).split('.')[1][:1]
+                                    tmp_d_tmp = int(tmp_d)
+                                else:
+                                    tmp_f_tmp = temp
+                                    
+                                if temp != None:
+                                    if temp != 0:
+                                        # EventMesh.publish("set_history_temp_value",temp)
+                                        EventMesh.publish("play_temp_value",temp)#播放体温数值
+                                        EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                                    else:
+                                        # EventMesh.publish("set_history_temp_value",0)
+                                        EventMesh.publish("play_temp_value",0)#播放体温数值
+                                
+                                EventMesh.publish(constants.EVENT.STOP_TEMP)
+
+                            else :
+                                if WEAR  != 1:
+                                    EventMesh.publish("set_temp_state",0)#0代表g关闭测试
+                                    EventMesh.debug_log("stop debug9")
+                                    EventMesh.publish(constants.EVENT.STOP_TEMP)                               
+                                    EventMesh.publish("play_temp_value",0) 
+                                    
+                else:
+                    self.auto_temp_count = 0
+
+            EventMesh.publish("play_unread_wechat_infor")#每10s检测是否有未读语音数据
+
+            usb_state = EventMesh.publish("get_usb")#
+            
+
+            if battery[0] == '1':
+                # EventMesh.debug_log("battery[1]",battery[1])
+                if self.vbat_full_flag <= 120:
+                    self.vbat_full_flag+=10
+                    if self.vbat_full_flag == 60:#开机检测一次如果是充电标识为1就不再提示
+                        if usb_state != 1:
+                            EventMesh.publish("set_usb",1)#
+                else:
+                    if battery[1] >= 100:
+                        if self.charge_full_count == 0:#充电已满
+                            EventMesh.publish("set_usb",3)#
+                            EventMesh.debug_log("charge R_CHARGE_full")
+                            self.charge_full_count = 1
+                    
+            else:
+                self.charge_full_count = 0
+                low_power = battery[1]
+                if low_power <= 5:#小于5%红色灯慢闪
+                    EventMesh.publish("set_led_time_arg",[1,2,20*11,led_mode.FLASH_LIGHT_RED,20,10,led_mode.OTHER_MEASURE_MODE])#測量成功
+                    # EventMesh.publish("set_led_time_arg",[1000,400,52,led_mode.FLASH_LIGHT_RED,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#開始測量
+
+            
+            self.normal_alarm()
+            #喝水提醒
+            self.drink_alarm()
+            #该吃药了
+            self.medicine_alarm()
+            #该起床了
+            self.wakeup_alarm()
+            #该睡觉了
+            self.sleep_alarm()
+            #该回家了
+            self.home_alarm()
+            #该休息了
+            self.reset_alarm()
+
+
+            if self.alarm_flag == 0:
+                self.alarm_flag = 1
+                EventMesh.publish("set_rtc_alarm")
+
+        def clear_usb_flag(self,event,msg):
+            self.charge_full_count = 0
+        #普通闹钟
+        def normal_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.normal_oldtotalmin",self.normal_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.normal_oldtotalmin == 0:
+                self.normal_oldtotalmin = cur_total_min #549
+            if self.normal_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.normal_flag == 1:
+                    self.normal_flag = 0
+                    self.normal_count = 0
+            normal_alarm = []
+            normal_alarm = EventMesh.publish("get_storage_config","normal_alarm")
+            # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
+            if self.normal_flag == 1:#表示闹钟响过清除标志
+                self.normal_count+=1
+                if self.normal_count > 6:
+                    self.normal_count = 0
+                    self.normal_flag = 0
+            if normal_alarm != None:
+                if len(normal_alarm) != 0 and normal_alarm != []:
+                    j = 0
+                    for i in range(len(normal_alarm)):
+                        # EventMesh.debug_log("normal_alarm normal_alarm 33",normal_alarm,j)
+                        normalalarm_hour = normal_alarm[j]["hour"]
+                        normalalarm_min = normal_alarm[j]["min"]
+                        normalalarm_day = normal_alarm[j]["day"]
+                        normalalarm_enale = normal_alarm[j]["enable"]
+                        normalalarm_totalmin = int(normalalarm_hour)*60+int(normalalarm_min)
+                        # EventMesh.debug_log("wake alarm",normalalarm_hour,sleep_min,sleep_day,sleep_enale,sleep_totalmin,week)
+                        if normalalarm_day == []:#单次闹钟只响一次
+                            if normalalarm_enale != 0:
+                                if cur_total_min > normalalarm_totalmin:
                                     normal_alarm.pop(j)
-                                    # EventMesh.debug_log("wakeup wakeup1",sleep,j)
+                                    self.normal_count = 0
+                                    self.normal_flag  = 0 
+                                    j=0
+                                    # EventMesh.debug_log("wakeup wakeup dayu",sleep,j)
                                     EventMesh.publish("set_storage_config",["normal_alarm",normal_alarm])#删除之后重新保存
-                                    EventMesh.publish("OPEN_ALARM_RING")                                                                                                                                            
+                                    # sleep = EventMesh.publish("get_storage_config","sleep_alarm")#删除之后重新保存
+                                    continue
+                                else:
+                                    if normalalarm_totalmin == cur_total_min and self.normal_flag == 0:#14:00
+                                        self.normal_count = 0
+                                        self.normal_flag  = 0    
+                                        normal_alarm.pop(j)
+                                        # EventMesh.debug_log("wakeup wakeup1",sleep,j)
+                                        EventMesh.publish("set_storage_config",["normal_alarm",normal_alarm])#删除之后重新保存
+                                        EventMesh.publish("OPEN_ALARM_RING")                                                                                                                                            
+                                        break
+                        else:
+                            if normalalarm_enale != 0 and (week in normalalarm_day):#记录响过的时间分钟数
+                                if normalalarm_totalmin == cur_total_min and self.normal_flag == 0:#14:00
+                                    self.normal_flag  = 1
+                                    self.normal_count = 0
+                                    self.normal_oldtotalmin = normalalarm_totalmin
+                                    EventMesh.publish("OPEN_ALARM_RING")#                                                                                                                                                  
                                     break
-                    else:
-                        if normalalarm_enale != 0 and (week in normalalarm_day):#记录响过的时间分钟数
-                            if normalalarm_totalmin == cur_total_min and self.normal_flag == 0:#14:00
-                                self.normal_flag  = 1
-                                self.normal_count = 0
-                                self.normal_oldtotalmin = normalalarm_totalmin
-                                EventMesh.publish("OPEN_ALARM_RING")#                                                                                                                                                  
-                                break
-                    j+=1
+                        j+=1
 
 
-    #喝水提醒
-    def drink_alarm(self):
-        date_tmp = utime.localtime()
-        time_tmp = utime.mktime(date_tmp)
-       
-        if self.drink_time == 0:
-            self.drink_time = time_tmp
+        #喝水提醒
+        def drink_alarm(self):
+            date_tmp = utime.localtime()
+            time_tmp = utime.mktime(date_tmp)
         
-        on = EventMesh.publish("get_storage_config","drink_on")
-        time = EventMesh.publish("get_storage_config","drink_time")
-        # print("drink info2",on,time)
-        if on != None and time != None:
-            if on != 0 and time != 0:
-                if (time_tmp - self.drink_time) >= (time*60*60):#需要转换成小时3600
-                    self.drink_time = time_tmp 
-                    EventMesh.publish("drink_alarm_event")#该喝水了
-                    #该喝水了
+            if self.drink_time == 0:
+                self.drink_time = time_tmp
+            
+            on = EventMesh.publish("get_storage_config","drink_on")
+            time = EventMesh.publish("get_storage_config","drink_time")
+            # print("drink info2",on,time)
+            if on != None and time != None:
+                if on != 0 and time != 0:
+                    if (time_tmp - self.drink_time) >= (time*60*60):#需要转换成小时3600
+                        self.drink_time = time_tmp 
+                        EventMesh.publish("drink_alarm_event")#该喝水了
+                        #该喝水了
+                else:
+                    self.drink_time = 0
             else:
                 self.drink_time = 0
-        else:
-            self.drink_time = 0
 
-    #吃药提醒
-    def medicine_alarm(self):
-        data = RTC().datetime()
-        hour = data[4]
-        min = data[5]
-
-        week = int(data[3])
-
-        date1 = data[1]
-        date2 = data[2]
-        cur_total_min = int(hour)*60+int(min)
-        # print("self.medicine_oldtotalmin",self.medicine_oldtotalmin,cur_total_min,self.alarm_flag)
-        if self.medicine_oldtotalmin == 0:
-            self.medicine_oldtotalmin = cur_total_min #549
-        if self.medicine_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
-            if self.medicine_flag == 1:
-                self.medicine_flag = 0
-                self.medicine_count = 0
-        medicine = EventMesh.publish("get_storage_config","medicine")
-        # print("medicine info2",medicine,cur_total_min)
-        if self.medicine_flag == 1:#表示闹钟响过清除标志
-            self.medicine_count+=1
-            if self.medicine_count > 6:
-                self.medicine_count = 0
-                self.medicine_flag = 0
-        if medicine != None:
-            if len(medicine) != 0 and medicine != []:
-                for i in range(len(medicine)):
-                    medicine_hour = medicine[i]["hour"]
-                    medicine_min = medicine[i]["min"]
-                    medicine_day = medicine[i]["day"]
-                    medicine_enale = medicine[i]["enable"]
-                    medicine_totalmin = int(medicine_hour)*60+int(medicine_min)
-                    # print("medicine alarm",medicine_hour,medicine_min,medicine_day,medicine_enale,medicine_totalmin,week)
-                    if medicine_day == []:
-                        if medicine_enale != 0:
-                            if medicine_totalmin == cur_total_min and self.medicine_flag == 0:#14:00
-                                self.medicine_count = 0
-                                self.medicine_flag  = 1    
-                                self.medicine_oldtotalmin = medicine_totalmin#记录响过的时间分钟数
-                                # print("medicine alarm1")
-                                EventMesh.publish("medicine_alarm_event")#该吃药了                                                                                                                                              
-                                break
-                    else:
-                        if medicine_enale != 0 and (week in medicine_day):#记录响过的时间分钟数
-                            if medicine_totalmin == cur_total_min and self.medicine_flag == 0:#14:00
-                                self.medicine_flag  = 1
-                                self.medicine_count = 0
-                                self.medicine_oldtotalmin = medicine_totalmin
-                                # print("medicine alarm2",)
-                                EventMesh.publish("medicine_alarm_event")#该吃药了                                                                                                                                                   
-                                break
-    #该起床了
-    def wakeup_alarm(self):
-        data = RTC().datetime()
-        hour = data[4]
-        min = data[5]
-
-        week = int(data[3])
-
-        date1 = data[1]
-        date2 = data[2]
-        cur_total_min = int(hour)*60+int(min)
-        # EventMesh.debug_log("self.wakeup_oldtotalmin",self.wakeup_oldtotalmin,cur_total_min,self.alarm_flag)
-        if self.wakeup_oldtotalmin == 0:
-            self.wakeup_oldtotalmin = cur_total_min #549
-        if self.wakeup_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
-            if self.wakeup_flag == 1:
-                self.wakeup_flag = 0
-                self.wakeup_count = 0
-        wakeup = []
-        wakeup = EventMesh.publish("get_storage_config","wakeup_alarm")
-        # EventMesh.debug_log("wakeup info2",wakeup,cur_total_min)
-        if self.wakeup_flag == 1:#表示闹钟响过清除标志
-            self.wakeup_count+=1
-            if self.wakeup_count > 6:
-                self.wakeup_count = 0
-                self.wakeup_flag = 0
-        if wakeup != None:
-            if len(wakeup) != 0 and wakeup != []:
-                j = 0
-                for i in range(len(wakeup)):
-                    wakeup_hour = wakeup[j]["hour"]
-                    wakeup_min = wakeup[j]["min"]
-                    wakeup_day = wakeup[j]["day"]
-                    wakeup_enale = wakeup[j]["enable"]
-                    wakeup_totalmin = int(wakeup_hour)*60+int(wakeup_min)
-                    # EventMesh.debug_log("wake alarm",wakeup_hour,wakeup_min,wakeup_day,wakeup_enale,wakeup_totalmin,week)
-                    if wakeup_day == []:#单次闹钟只响一次
-                        if wakeup_enale != 0:
-                            if cur_total_min > wakeup_totalmin:
-                                self.wakeup_count = 0
-                                self.wakeup_flag  = 0    
-                                wakeup.pop(j)
-                                j=0#每次删除都从0开始遍历
-                                # EventMesh.debug_log("wakeup wakeup1 dayu",wakeup,j)
-                                EventMesh.publish("set_storage_config",["wakeup_alarm",wakeup])
-                                continue
-                            else:
-                                if wakeup_totalmin == cur_total_min and self.wakeup_flag == 0:#14:00
+        #吃药提醒
+        def medicine_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # print("self.medicine_oldtotalmin",self.medicine_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.medicine_oldtotalmin == 0:
+                self.medicine_oldtotalmin = cur_total_min #549
+            if self.medicine_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.medicine_flag == 1:
+                    self.medicine_flag = 0
+                    self.medicine_count = 0
+            medicine = EventMesh.publish("get_storage_config","medicine")
+            # print("medicine info2",medicine,cur_total_min)
+            if self.medicine_flag == 1:#表示闹钟响过清除标志
+                self.medicine_count+=1
+                if self.medicine_count > 6:
+                    self.medicine_count = 0
+                    self.medicine_flag = 0
+            if medicine != None:
+                if len(medicine) != 0 and medicine != []:
+                    for i in range(len(medicine)):
+                        medicine_hour = medicine[i]["hour"]
+                        medicine_min = medicine[i]["min"]
+                        medicine_day = medicine[i]["day"]
+                        medicine_enale = medicine[i]["enable"]
+                        medicine_totalmin = int(medicine_hour)*60+int(medicine_min)
+                        # print("medicine alarm",medicine_hour,medicine_min,medicine_day,medicine_enale,medicine_totalmin,week)
+                        if medicine_day == []:
+                            if medicine_enale != 0:
+                                if medicine_totalmin == cur_total_min and self.medicine_flag == 0:#14:00
+                                    self.medicine_count = 0
+                                    self.medicine_flag  = 1    
+                                    self.medicine_oldtotalmin = medicine_totalmin#记录响过的时间分钟数
+                                    # print("medicine alarm1")
+                                    EventMesh.publish("medicine_alarm_event")#该吃药了                                                                                                                                              
+                                    break
+                        else:
+                            if medicine_enale != 0 and (week in medicine_day):#记录响过的时间分钟数
+                                if medicine_totalmin == cur_total_min and self.medicine_flag == 0:#14:00
+                                    self.medicine_flag  = 1
+                                    self.medicine_count = 0
+                                    self.medicine_oldtotalmin = medicine_totalmin
+                                    # print("medicine alarm2",)
+                                    EventMesh.publish("medicine_alarm_event")#该吃药了                                                                                                                                                   
+                                    break
+        #该起床了
+        def wakeup_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.wakeup_oldtotalmin",self.wakeup_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.wakeup_oldtotalmin == 0:
+                self.wakeup_oldtotalmin = cur_total_min #549
+            if self.wakeup_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.wakeup_flag == 1:
+                    self.wakeup_flag = 0
+                    self.wakeup_count = 0
+            wakeup = []
+            wakeup = EventMesh.publish("get_storage_config","wakeup_alarm")
+            # EventMesh.debug_log("wakeup info2",wakeup,cur_total_min)
+            if self.wakeup_flag == 1:#表示闹钟响过清除标志
+                self.wakeup_count+=1
+                if self.wakeup_count > 6:
+                    self.wakeup_count = 0
+                    self.wakeup_flag = 0
+            if wakeup != None:
+                if len(wakeup) != 0 and wakeup != []:
+                    j = 0
+                    for i in range(len(wakeup)):
+                        wakeup_hour = wakeup[j]["hour"]
+                        wakeup_min = wakeup[j]["min"]
+                        wakeup_day = wakeup[j]["day"]
+                        wakeup_enale = wakeup[j]["enable"]
+                        wakeup_totalmin = int(wakeup_hour)*60+int(wakeup_min)
+                        # EventMesh.debug_log("wake alarm",wakeup_hour,wakeup_min,wakeup_day,wakeup_enale,wakeup_totalmin,week)
+                        if wakeup_day == []:#单次闹钟只响一次
+                            if wakeup_enale != 0:
+                                if cur_total_min > wakeup_totalmin:
                                     self.wakeup_count = 0
                                     self.wakeup_flag  = 0    
                                     wakeup.pop(j)
-                                    EventMesh.debug_log("wakeup wakeup1",wakeup,j)
+                                    j=0#每次删除都从0开始遍历
+                                    # EventMesh.debug_log("wakeup wakeup1 dayu",wakeup,j)
                                     EventMesh.publish("set_storage_config",["wakeup_alarm",wakeup])
-                                    EventMesh.publish("wakeup_alarm_event")#该吃药了                                                                                                                                              
+                                    continue
+                                else:
+                                    if wakeup_totalmin == cur_total_min and self.wakeup_flag == 0:#14:00
+                                        self.wakeup_count = 0
+                                        self.wakeup_flag  = 0    
+                                        wakeup.pop(j)
+                                        EventMesh.debug_log("wakeup wakeup1",wakeup,j)
+                                        EventMesh.publish("set_storage_config",["wakeup_alarm",wakeup])
+                                        EventMesh.publish("wakeup_alarm_event")#该吃药了                                                                                                                                              
+                                        break
+                        else:
+                            if wakeup_enale != 0 and (week in wakeup_day):#记录响过的时间分钟数
+                                if wakeup_totalmin == cur_total_min and self.wakeup_flag == 0:#14:00
+                                    self.wakeup_flag  = 1
+                                    self.wakeup_count = 0
+                                    self.wakeup_oldtotalmin = wakeup_totalmin
+                                    EventMesh.publish("wakeup_alarm_event")#该吃药了                                                                                                                                                   
                                     break
-                    else:
-                        if wakeup_enale != 0 and (week in wakeup_day):#记录响过的时间分钟数
-                            if wakeup_totalmin == cur_total_min and self.wakeup_flag == 0:#14:00
-                                self.wakeup_flag  = 1
-                                self.wakeup_count = 0
-                                self.wakeup_oldtotalmin = wakeup_totalmin
-                                EventMesh.publish("wakeup_alarm_event")#该吃药了                                                                                                                                                   
-                                break
-                    j+=1
+                        j+=1
 
 
-    #该睡觉了
-    def sleep_alarm(self):
-        data = RTC().datetime()
-        hour = data[4]
-        min = data[5]
-
-        week = int(data[3])
-
-        date1 = data[1]
-        date2 = data[2]
-        cur_total_min = int(hour)*60+int(min)
-        # EventMesh.debug_log("self.sleep_oldtotalmin",self.sleep_oldtotalmin,cur_total_min,self.alarm_flag)
-        if self.sleep_oldtotalmin == 0:
-            self.sleep_oldtotalmin = cur_total_min #549
-        if self.sleep_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
-            if self.sleep_flag == 1:
-                self.sleep_flag = 0
-                self.sleep_count = 0
-        sleep = []
-        sleep = EventMesh.publish("get_storage_config","sleep_alarm")
-        # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
-        if self.sleep_flag == 1:#表示闹钟响过清除标志
-            self.sleep_count+=1
-            if self.sleep_count > 6:
-                self.sleep_count = 0
-                self.sleep_flag = 0
-        if sleep != None:
-            if len(sleep) != 0 and sleep != []:
-                j = 0
-                count = int(len(sleep))
-                for i in range(len(sleep)):
-                    # EventMesh.debug_log("wakeup wakeup 33",sleep,j)
-                    sleep_hour = sleep[j]["hour"]
-                    sleep_min = sleep[j]["min"]
-                    sleep_day = sleep[j]["day"]
-                    sleep_enale = sleep[j]["enable"]
-                    sleep_totalmin = int(sleep_hour)*60+int(sleep_min)
-                    # EventMesh.debug_log("wake alarm",sleep_hour,sleep_min,sleep_day,sleep_enale,sleep_totalmin,week)
-                    if sleep_day == []:#单次闹钟只响一次
-                        if sleep_enale != 0:
-                            if cur_total_min > sleep_totalmin:
-                                sleep.pop(j)
-                                self.sleep_count = 0
-                                self.sleep_flag  = 0 
-                                j=0
-                                # EventMesh.debug_log("wakeup wakeup dayu",sleep,j)
-                                EventMesh.publish("set_storage_config",["sleep_alarm",sleep])#删除之后重新保存
-                                # sleep = EventMesh.publish("get_storage_config","sleep_alarm")#删除之后重新保存
-                                continue
-                            else:
-                                if sleep_totalmin == cur_total_min and self.sleep_flag == 0:#14:00
-                                    self.sleep_count = 0
-                                    self.sleep_flag  = 0    
+        #该睡觉了
+        def sleep_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.sleep_oldtotalmin",self.sleep_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.sleep_oldtotalmin == 0:
+                self.sleep_oldtotalmin = cur_total_min #549
+            if self.sleep_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.sleep_flag == 1:
+                    self.sleep_flag = 0
+                    self.sleep_count = 0
+            sleep = []
+            sleep = EventMesh.publish("get_storage_config","sleep_alarm")
+            # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
+            if self.sleep_flag == 1:#表示闹钟响过清除标志
+                self.sleep_count+=1
+                if self.sleep_count > 6:
+                    self.sleep_count = 0
+                    self.sleep_flag = 0
+            if sleep != None:
+                if len(sleep) != 0 and sleep != []:
+                    j = 0
+                    count = int(len(sleep))
+                    for i in range(len(sleep)):
+                        # EventMesh.debug_log("wakeup wakeup 33",sleep,j)
+                        sleep_hour = sleep[j]["hour"]
+                        sleep_min = sleep[j]["min"]
+                        sleep_day = sleep[j]["day"]
+                        sleep_enale = sleep[j]["enable"]
+                        sleep_totalmin = int(sleep_hour)*60+int(sleep_min)
+                        # EventMesh.debug_log("wake alarm",sleep_hour,sleep_min,sleep_day,sleep_enale,sleep_totalmin,week)
+                        if sleep_day == []:#单次闹钟只响一次
+                            if sleep_enale != 0:
+                                if cur_total_min > sleep_totalmin:
                                     sleep.pop(j)
-                                    # EventMesh.debug_log("wakeup wakeup1",sleep,j)
+                                    self.sleep_count = 0
+                                    self.sleep_flag  = 0 
+                                    j=0
+                                    # EventMesh.debug_log("wakeup wakeup dayu",sleep,j)
                                     EventMesh.publish("set_storage_config",["sleep_alarm",sleep])#删除之后重新保存
-                                    EventMesh.publish("sleep_alarm_event")#该吃药了                                                                                                                                              
+                                    # sleep = EventMesh.publish("get_storage_config","sleep_alarm")#删除之后重新保存
+                                    continue
+                                else:
+                                    if sleep_totalmin == cur_total_min and self.sleep_flag == 0:#14:00
+                                        self.sleep_count = 0
+                                        self.sleep_flag  = 0    
+                                        sleep.pop(j)
+                                        # EventMesh.debug_log("wakeup wakeup1",sleep,j)
+                                        EventMesh.publish("set_storage_config",["sleep_alarm",sleep])#删除之后重新保存
+                                        EventMesh.publish("sleep_alarm_event")#该吃药了                                                                                                                                              
+                                        break
+                        else:
+                            if sleep_enale != 0 and (week in sleep_day):#记录响过的时间分钟数
+                                if sleep_totalmin == cur_total_min and self.sleep_flag == 0:#14:00
+                                    self.sleep_flag  = 1
+                                    self.sleep_count = 0
+                                    self.sleep_oldtotalmin = sleep_totalmin
+                                    EventMesh.publish("sleep_alarm_event")#该吃药了                                                                                                                                                   
                                     break
-                    else:
-                        if sleep_enale != 0 and (week in sleep_day):#记录响过的时间分钟数
-                            if sleep_totalmin == cur_total_min and self.sleep_flag == 0:#14:00
-                                self.sleep_flag  = 1
-                                self.sleep_count = 0
-                                self.sleep_oldtotalmin = sleep_totalmin
-                                EventMesh.publish("sleep_alarm_event")#该吃药了                                                                                                                                                   
-                                break
-                    j+=1
+                        j+=1
 
 
-    #该回家了
-    def home_alarm(self):
-        data = RTC().datetime()
-        hour = data[4]
-        min = data[5]
-
-        week = int(data[3])
-
-        date1 = data[1]
-        date2 = data[2]
-        cur_total_min = int(hour)*60+int(min)
-        # EventMesh.debug_log("self.home_oldtotalmin",self.home_oldtotalmin,cur_total_min,self.alarm_flag)
-        if self.home_oldtotalmin == 0:
-            self.home_oldtotalmin = cur_total_min #549
-        if self.home_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
-            if self.home_flag == 1:
-                self.home_flag = 0
-                self.home_count = 0
-        home = ''
-        home = EventMesh.publish("get_storage_config","home_alarm")
-        # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
-        if self.home_flag == 1:#表示闹钟响过清除标志
-            self.home_count+=1
-            if self.home_count > 6:
-                self.home_count = 0
-                self.home_flag = 0
-        if home != None:
-            if len(str(home)) != 0 and str(home) != '':
-                # EventMesh.debug_log("home home 33",home)
-                home_hour = int(str(home).split(":")[0])
-                home_min = int(str(home).split(":")[1])
-                
-                home_totalmin = int(home_hour)*60+int(home_min)
-                if home_totalmin == cur_total_min and self.home_flag == 0:#14:00
-                    self.home_flag  = 1
+        #该回家了
+        def home_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.home_oldtotalmin",self.home_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.home_oldtotalmin == 0:
+                self.home_oldtotalmin = cur_total_min #549
+            if self.home_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.home_flag == 1:
+                    self.home_flag = 0
                     self.home_count = 0
-                    self.home_oldtotalmin = home_totalmin
-                    EventMesh.publish("home_alarm_event")#该回家了                                                                                                                                                   
-
-
-    
-    #该休息了
-    def reset_alarm(self):
-        data = RTC().datetime()
-        hour = data[4]
-        min = data[5]
-
-        week = int(data[3])
-
-        date1 = data[1]
-        date2 = data[2]
-        cur_total_min = int(hour)*60+int(min)
-        # EventMesh.debug_log("self.reset_oldtotalmin",self.reset_oldtotalmin,cur_total_min,self.alarm_flag)
-        if self.reset_oldtotalmin == 0:
-            self.reset_oldtotalmin = cur_total_min #549
-        if self.reset_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
-            if self.reset_flag == 1:
-                self.reset_flag = 0
-                self.reset_count = 0
-        reset_alarm = []
-        reset_alarm = EventMesh.publish("get_storage_config","reset_alarm")
-        # EventMesh.debug_log("reset_alarm info2",len(reset_alarm),cur_total_min)
-        if self.reset_flag == 1:#表示闹钟响过清除标志
-            self.reset_count+=1
-            if self.reset_count > 6:
-                self.reset_count = 0
-                self.reset_flag = 0
-        if reset_alarm != None:
-            if len(str(reset_alarm)) != 0 and str(reset_alarm) != []:
-                for i in range(len(reset_alarm)):
-                    # print("i",i)
-                    start_hour = int(reset_alarm[i]["start_hour"])
-                    start_min = int(reset_alarm[i]["start_min"])
-
-                    end_hour = int(reset_alarm[i]["end_hour"])
-                    end_min = int(reset_alarm[i]["end_min"])
-
-                    # EventMesh.debug_log("reset_alarm home 33",reset_alarm)
+            home = ''
+            home = EventMesh.publish("get_storage_config","home_alarm")
+            # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
+            if self.home_flag == 1:#表示闹钟响过清除标志
+                self.home_count+=1
+                if self.home_count > 6:
+                    self.home_count = 0
+                    self.home_flag = 0
+            if home != None:
+                if len(str(home)) != 0 and str(home) != '':
+                    # EventMesh.debug_log("home home 33",home)
+                    home_hour = int(str(home).split(":")[0])
+                    home_min = int(str(home).split(":")[1])
                     
-                    start_totalmin = int(start_hour)*60+int(start_min)
-                    end_totalmin = int(end_hour)*60+int(end_min)
-
-                    if start_totalmin == cur_total_min and self.reset_flag == 0:#14:00
-                        self.reset_flag  = 1
-                        self.reset_count = 0
-                        self.reset_oldtotalmin = start_totalmin
-                        EventMesh.publish("reset_alarm_event")#该休息了     
-                        break
-
-                    if end_totalmin == cur_total_min and self.reset_flag == 0:
-                        self.reset_flag  = 1
-                        self.reset_count = 0
-                        self.reset_oldtotalmin = end_totalmin
-                        EventMesh.publish("reset_end_alarm_event")#休息结束了     
-                        break
-                                                                                                                                                                  
+                    home_totalmin = int(home_hour)*60+int(home_min)
+                    if home_totalmin == cur_total_min and self.home_flag == 0:#14:00
+                        self.home_flag  = 1
+                        self.home_count = 0
+                        self.home_oldtotalmin = home_totalmin
+                        EventMesh.publish("home_alarm_event")#该回家了                                                                                                                                                   
 
-    def clear_normal_alarm(self,event,msg):#普通闹钟清除标志
-        self.normal_flag = 0
-        self.normal_count = 0
-        self.normal_oldtotalmin = 0
 
-    def clear_reset_alarm(self,event,msg):#休息清除标志
-        self.reset_flag = 0
-        self.reset_count = 0
-        self.reset_oldtotalmin = 0
+        
+        #该休息了
+        def reset_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.reset_oldtotalmin",self.reset_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.reset_oldtotalmin == 0:
+                self.reset_oldtotalmin = cur_total_min #549
+            if self.reset_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.reset_flag == 1:
+                    self.reset_flag = 0
+                    self.reset_count = 0
+            reset_alarm = []
+            reset_alarm = EventMesh.publish("get_storage_config","reset_alarm")
+            # EventMesh.debug_log("reset_alarm info2",len(reset_alarm),cur_total_min)
+            if self.reset_flag == 1:#表示闹钟响过清除标志
+                self.reset_count+=1
+                if self.reset_count > 6:
+                    self.reset_count = 0
+                    self.reset_flag = 0
+            if reset_alarm != None:
+                if len(str(reset_alarm)) != 0 and str(reset_alarm) != []:
+                    for i in range(len(reset_alarm)):
+                        # print("i",i)
+                        start_hour = int(reset_alarm[i]["start_hour"])
+                        start_min = int(reset_alarm[i]["start_min"])
+
+                        end_hour = int(reset_alarm[i]["end_hour"])
+                        end_min = int(reset_alarm[i]["end_min"])
+
+                        # EventMesh.debug_log("reset_alarm home 33",reset_alarm)
+                        
+                        start_totalmin = int(start_hour)*60+int(start_min)
+                        end_totalmin = int(end_hour)*60+int(end_min)
+
+                        if start_totalmin == cur_total_min and self.reset_flag == 0:#14:00
+                            self.reset_flag  = 1
+                            self.reset_count = 0
+                            self.reset_oldtotalmin = start_totalmin
+                            EventMesh.publish("reset_alarm_event")#该休息了     
+                            break
+
+                        if end_totalmin == cur_total_min and self.reset_flag == 0:
+                            self.reset_flag  = 1
+                            self.reset_count = 0
+                            self.reset_oldtotalmin = end_totalmin
+                            EventMesh.publish("reset_end_alarm_event")#休息结束了     
+                            break
+                                                                                                                                                                    
+
+        def clear_normal_alarm(self,event,msg):#普通闹钟清除标志
+            self.normal_flag = 0
+            self.normal_count = 0
+            self.normal_oldtotalmin = 0
+
+        def clear_reset_alarm(self,event,msg):#休息清除标志
+            self.reset_flag = 0
+            self.reset_count = 0
+            self.reset_oldtotalmin = 0
+
+        def clear_home_alarm(self,event,msg):#回家清除标志
+            self.home_flag = 0
+            self.home_count = 0
+            self.home_oldtotalmin = 0
+
+
+        def clear_medicine_alarm(self,event,msg):#吃药清除标志
+            self.medicine_count = 0
+            self.medicine_flag  = 0
+            self.medicine_oldtotalmin = 0
+        
 
-    def clear_home_alarm(self,event,msg):#回家清除标志
-        self.home_flag = 0
-        self.home_count = 0
-        self.home_oldtotalmin = 0
+        def clear_wakeup_alarm(self,event,msg):#起床标识
+            self.wakeup_flag = 0
+            self.wakeup_count = 0
+            self.wakeup_oldtotalmin = 0
 
+        def clear_sleep_alarm(self,event,msg):#睡觉标识
 
-    def clear_medicine_alarm(self,event,msg):#吃药清除标志
-        self.medicine_count = 0
-        self.medicine_flag  = 0
-        self.medicine_oldtotalmin = 0
-    
+            self.sleep_flag = 0
+            self.sleep_count = 0
+            self.sleep_oldtotalmin = 0
 
-    def clear_wakeup_alarm(self,event,msg):#起床标识
-        self.wakeup_flag = 0
-        self.wakeup_count = 0
-        self.wakeup_oldtotalmin = 0
+            
 
-    def clear_sleep_alarm(self,event,msg):#睡觉标识
 
-        self.sleep_flag = 0
-        self.sleep_count = 0
-        self.sleep_oldtotalmin = 0
+        def get_sim_Status(self, event, msg):
+            return sim.getStatus()
+        def get_device_ope(self, event, msg):
+            """
+            获取设备运营商信息
+            :param event:
+            :param msg:
+            :return: 运营商
+            """
+            net_ope_map = {
+                "UNICOM": "中国联通HD",
+                "CMCC": "中国移动HD",
+                "CT": "中国电信HD"
+            }
+            """获取运营商"""
+            try:
+                short_eons = net.operatorName()[1]
+            except Exception:
+                return "无"
+            return net_ope_map.get(short_eons, None)
+
+        def get_signal(self, event=None, msg=None):
+            """
+            获取信号事件
+            :param event:
+            :param msg:
+            :return: int 类型
+            """
+            return net.csqQueryPoll()
+
+        def get_time_bucket(self, time):
+            if time < 12:
+                return '上午'
+            else:
+                return '下午'
+
+        def get_week(self, week):
+            if week == 1:
+                return '一'
+            elif week == 2:
+                return '二'
+            elif week == 3:
+                return '三'
+            elif week == 4:
+                return '四'
+            elif week == 5:
+                return '五'
+            elif week == 6:
+                return '六'
+            elif week == 7 or week == 0:
+                return '日'
+
+        def get_time(self, event=None, msg=None):
+            """
+            获取时间事件
+            :param event:
+            :param msg:
+            :return: HH:MM 格式
+            """
+            rtc_time = self.rtc.datetime()
+            
+            date = ("%d月%d日" % (rtc_time[1], rtc_time[2]))
+            year = ("%04d年" % (rtc_time[0]))
+            week = ("星期%s"%(self.get_week(rtc_time[3])))
+            week_data = rtc_time[3]
+            time = [rtc_time[4], rtc_time[5]]
+            time_quantum = ("%s" % (self.get_time_bucket(rtc_time[4])))
+            
+            result = [time, time_quantum, date , week,year,week_data]
+            #时分,上午下午,日期,星期,年 星期
+            return result
+
+        def get_step_count(self, event=None, msg=None):
+            """
+            获取步数
+            """
+            # print("11111:{}".format(EventMesh.publish("get_storage_config","clear_state3")))
+            XYZ = self.gsensor.get_x_y_z()
+            tmp = 0
+            step =[0,0,0,0]
+            tmp =  self.gsensor.get_step() 
+            # EventMesh.debug_log("x:%d,y:%d,z:%d tmp %d",XYZ[0],XYZ[1],XYZ[2],tmp)
+            step[0]= tmp 
+            step[1] = XYZ[0]
+            step[2] = XYZ[1]
+            step[3] = XYZ[2]
+            # print("1222:{}".format(EventMesh.publish("get_storage_config","clear_state3")))
+            return step
+
+        def get_ic_cid(self, event, msg):
+            """
+            获取ic cid事件
+            :param event:
+            :param msg:
+            :return: str ic cid
+            """
+            return sim.getIccid()
+
+        def get_phone_num(self, event, msg):
+            """
+            获取电话号码事件
+            :param event:
+            :param msg:
+            :return: str number
+            """
+            return sim.getPhoneNumber()
+
+        def get_battery(self, event=None, msg=None):
+            """
+            获取电池事件,暂时没支持
+            :param event:
+            :param msg:
+            :return:
+            """
 
-        
+            charge_state = '0'
+            if self.get_usb_state() == 1:
+                charge_state = '1'
+            else:
+                charge_state = '0'
+
+            #temp = Power.getVbatt()
+            temp = EventMesh.publish("get_curr_battery_level")
+            vbat = EventMesh.publish("get_battery",temp)
+            if vbat == None:
+                vbat = 100
+            # EventMesh.debug_log("vbat",vbat)
+            # if temp != None :
+            #     if temp <= 3505:
+            #         vbat = 0 
+            #     elif temp <= 3699:
+            #         vbat = 20 #"E:/vbat_20.jpg"
+            #     elif temp <= 3772:
+            #         vbat = 40 #"E:/vbat_40.jpg"
+            #     elif temp <= 3882:
+            #         vbat = 60 #"E:/vbat_60.jpg"
+            #     elif temp <= 4070:
+            #         vbat = 80 #"E:/vbat_80.jpg"
+            #     elif temp <= 4200:
+            #         vbat = 90 #
+            #     else:
+            #         vbat = 100 #"E:/vbat_100.jpg"
+            # else:
+            #     vbat = 100
 
+            result = [charge_state, vbat]
 
-    def get_sim_Status(self, event, msg):
-        return sim.getStatus()
-    def get_device_ope(self, event, msg):
-        """
-        获取设备运营商信息
-        :param event:
-        :param msg:
-        :return: 运营商
-        """
-        net_ope_map = {
-            "UNICOM": "中国联通HD",
-            "CMCC": "中国移动HD",
-            "CT": "中国电信HD"
-        }
-        """获取运营商"""
-        try:
-            short_eons = net.operatorName()[1]
-        except Exception:
-            return "无"
-        return net_ope_map.get(short_eons, None)
-
-    def get_signal(self, event=None, msg=None):
-        """
-        获取信号事件
-        :param event:
-        :param msg:
-        :return: int 类型
-        """
-        return net.csqQueryPoll()
-
-    def get_time_bucket(self, time):
-        if time < 12:
-            return '上午'
-        else:
-            return '下午'
-
-    def get_week(self, week):
-        if week == 1:
-            return '一'
-        elif week == 2:
-            return '二'
-        elif week == 3:
-            return '三'
-        elif week == 4:
-            return '四'
-        elif week == 5:
-            return '五'
-        elif week == 6:
-            return '六'
-        elif week == 7 or week == 0:
-            return '日'
-
-    def get_time(self, event=None, msg=None):
-        """
-        获取时间事件
-        :param event:
-        :param msg:
-        :return: HH:MM 格式
-        """
-        rtc_time = self.rtc.datetime()
+            return result
+        #Set the current average battery level
+        def set_curr_battery_level(self, event=None, msg=None):
+            self.curr_battery_level = msg
+        
+        def get_curr_battery_level(self, event=None, msg=None):
+            return self.curr_battery_level
+
+        def get_device_fw_version(self, *args):
+            '''
+            获取设备固件版本号
+            '''
+            fw_version = modem.getDevFwVersion()
+            if isinstance(fw_version, str):
+                return fw_version
+            return "--"
+
+        def get_standby_time(self, *args):
+            '''
+            获取设备单次开机待机时间
+            '''
+            time_msg = utime.time()
+            d = int(
+                time_msg / 86400)  # The int call removes the decimals.  Conveniently, it always rounds down.  int(2.9) returns 2 instead of 3, for example.
+            time_msg -= (
+                    d * 86400)  # This updates the value of x to show that the already counted seconds won't be double counted or anything.
+            h = int(time_msg / 3600)
+            time_msg -= (h * 3600)
+            m = int(time_msg / 60)
+            time_msg -= (m * 60)
+            s = time_msg
+            result = "{}天{}小时{}分".format(d, h, m)
+            return result
+
+        def set_key(self, topic, msg):
+            self.key = msg["value"]
+        def get_key(self, topic, msg):
+            return self.key
+
+        def get_imei(self, topic, msg):
+            if not self.imei:
+                self.imei = modem.getDevImei()
+            # self.imei = "860132060128634" #860132060128634
+            return self.imei
+
+        def get_cid(self, topic, msg):
+            return self.cid
+
+        def set_cid(self, topic, msg):
+            self.cid = msg["value"]
+
+        def get_imsi(self, topic, msg):
+            if not self.imei:
+                self.imei = sim.getImsi()
+            return self.imsi
+
+        def get_password(self, topic, msg):
+            return self.password
+
+        def set_password(self, topic, msg):
+            self.password = msg["value"]
+
+        def set_ping(self, topic, msg):
+            self.PING = msg
+        def get_ping(self, topic, msg):
+            return self.PING
+
+        def set_connect(self, topic, msg):
+            #EventMesh.debug_log("set_connect:{}".format(msg))
+            self.connect = msg
+        def get_connect(self, topic, msg):
+            return self.connect
+
+        def start_blood_oxygen(self, topic, msg):
+            EventMesh.debug_log("start_blood_oxygen!!!")
+            self.hsensor.open_blood_oxygen()
+
+        def start_heart(self, topic, msg):
+            EventMesh.debug_log("start_heart!!!")
+            self.hsensor.open_heart()
+
+        def stop_blood_oxygen(self, topic, msg):
+            EventMesh.debug_log("stop_blood_oxygen!!!")
+            self.hsensor.close()
+
+        def stop_heart(self, topic, msg):
+            EventMesh.debug_log("stop_heart!!!")
+            self.hsensor.close()
+
+        def get_blood_oxygen(self, topic, msg):
+            data = self.hsensor.get_all_data()
+            return data[1]
+
+        def get_heart(self, topic, msg):
+            data = self.hsensor.get_all_data()
+            return data[0]
         
-        date = ("%d月%d日" % (rtc_time[1], rtc_time[2]))
-        year = ("%04d年" % (rtc_time[0]))
-        week = ("星期%s"%(self.get_week(rtc_time[3])))
-        week_data = rtc_time[3]
-        time = [rtc_time[4], rtc_time[5]]
-        time_quantum = ("%s" % (self.get_time_bucket(rtc_time[4])))
+        def get_wear(self, topic, msg):
+            return self.hsensor.get_wear()
         
-        result = [time, time_quantum, date , week,year,week_data]
-        #时分,上午下午,日期,星期,年 星期
-        return result
+        def get_Hsensor(self, topic, msg):
+            return self.hsensor
+        
+        def Hsensor_set_sleep(self, topic, msg):
+            self.hsensor.set_sleep()
+
+        def start_temp(self, topic, msg):
+            EventMesh.debug_log("start_temp!!!!!!!")
+            WHO_AM_I = bytearray([0x01, 0])
+            I2C_SLAVE_ADDR = 0x49
+            #I2C_SLAVE_ADDR = 0x48
+            r_data = bytearray(2)
+            data = bytearray([0x61A0, 0])   # 唤醒
+            return self.i2c0.write(I2C_SLAVE_ADDR, WHO_AM_I, 1, data, 2)
+        def stop_temp(self, topic, msg):
+            EventMesh.debug_log("stop_temp!!!!!!!")
+            WHO_AM_I = bytearray([0x01, 0])
+            I2C_SLAVE_ADDR = 0x49
+            #I2C_SLAVE_ADDR = 0x48
+            r_data = bytearray(2)
+            data = bytearray([0x60A0, 0])   #休眠
+            return self.i2c0.write(I2C_SLAVE_ADDR, WHO_AM_I, 1, data, 2)
+            
+        def get_temp(self, topic, msg):
+            WHO_AM_I = bytearray([0x00, 0])
+            I2C_SLAVE_ADDR = 0x49
+            #I2C_SLAVE_ADDR = 0x48
+            r_data = bytearray(2)
+            self.i2c0.read(I2C_SLAVE_ADDR, WHO_AM_I, 1, r_data, 2, 0)
+            #EventMesh.debug_log("temp_data:{}".format(r_data))
+            temp_s = ((r_data[0]<<8) | (r_data[1]))>>4
+            #EventMesh.debug_log("temp_s:{}".format(temp_s))
+            temp_data = temp_s * 0.0625
+            EventMesh.debug_log("temp_data:{}".format(temp_data))
+            return temp_data
+    
+                
 
-    def get_step_count(self, event=None, msg=None):
-        """
-        获取步数
-        """
-        # print("11111:{}".format(EventMesh.publish("get_storage_config","clear_state3")))
-        XYZ = self.gsensor.get_x_y_z()
-        tmp = 0
-        step =[0,0,0,0]
-        tmp =  self.gsensor.get_step() 
-        # EventMesh.debug_log("x:%d,y:%d,z:%d tmp %d",XYZ[0],XYZ[1],XYZ[2],tmp)
-        step[0]= tmp 
-        step[1] = XYZ[0]
-        step[2] = XYZ[1]
-        step[3] = XYZ[2]
-        # print("1222:{}".format(EventMesh.publish("get_storage_config","clear_state3")))
-        return step
-
-    def get_ic_cid(self, event, msg):
-        """
-        获取ic cid事件
-        :param event:
-        :param msg:
-        :return: str ic cid
-        """
-        return sim.getIccid()
+        def sim_slot_get(self, topic=None, msg=None):
+            return sim.getCurSimid()
+
+        def sim_slot_switch(self, topic=None, slot=None):
+            """
+            sim 卡槽切换
+            :param topic:
+            :param slot:
+            :return: 切换sim卡卡槽  0 切换成功, 1 无需切换, -1 切换失败
+            """
+            if self.sim_slot_get() == slot:
+                return 1
+            else:
+                return sim.switchCard(slot)
 
-    def get_phone_num(self, event, msg):
-        """
-        获取电话号码事件
-        :param event:
-        :param msg:
-        :return: str number
-        """
-        return sim.getPhoneNumber()
+        def usb_event_cb(self, state):
+            status = state
 
-    def get_battery(self, event=None, msg=None):
-        """
-        获取电池事件,暂时没支持
-        :param event:
-        :param msg:
-        :return:
-        """
+            if status == 1:#插入USB
+                EventMesh.debug_log("charge R_CHARGE_in")
+                EventMesh.publish("clear_usb_flag")
+                EventMesh.publish("set_usb", 1)#
+                pass
+            elif status == 0:#拨出usbs
+                EventMesh.publish("clear_usb_flag")
+                EventMesh.publish("set_usb", 2)#
+                EventMesh.debug_log("charge R_CHARGE_out")
 
-        charge_state = '0'
-        if self.get_usb_state() == 1:
-            charge_state = '1'
-        else:
-            charge_state = '0'
+                
+                
 
-        #temp = Power.getVbatt()
-        temp = EventMesh.publish("get_curr_battery_level")
-        vbat = EventMesh.publish("get_battery",temp)
-        if vbat == None:
-            vbat = 100
-        # EventMesh.debug_log("vbat",vbat)
-        # if temp != None :
-        #     if temp <= 3505:
-        #         vbat = 0 
-        #     elif temp <= 3699:
-        #         vbat = 20 #"E:/vbat_20.jpg"
-        #     elif temp <= 3772:
-        #         vbat = 40 #"E:/vbat_40.jpg"
-        #     elif temp <= 3882:
-        #         vbat = 60 #"E:/vbat_60.jpg"
-        #     elif temp <= 4070:
-        #         vbat = 80 #"E:/vbat_80.jpg"
-        #     elif temp <= 4200:
-        #         vbat = 90 #
-        #     else:
-        #         vbat = 100 #"E:/vbat_100.jpg"
-        # else:
-        #     vbat = 100
-
-        result = [charge_state, vbat]
-
-        return result
-    #Set the current average battery level
-    def set_curr_battery_level(self, event=None, msg=None):
-        self.curr_battery_level = msg
-    
-    def get_curr_battery_level(self, event=None, msg=None):
-        return self.curr_battery_level
-
-    def get_device_fw_version(self, *args):
-        '''
-        获取设备固件版本号
-        '''
-        fw_version = modem.getDevFwVersion()
-        if isinstance(fw_version, str):
-            return fw_version
-        return "--"
-
-    def get_standby_time(self, *args):
-        '''
-        获取设备单次开机待机时间
-        '''
-        time_msg = utime.time()
-        d = int(
-            time_msg / 86400)  # The int call removes the decimals.  Conveniently, it always rounds down.  int(2.9) returns 2 instead of 3, for example.
-        time_msg -= (
-                d * 86400)  # This updates the value of x to show that the already counted seconds won't be double counted or anything.
-        h = int(time_msg / 3600)
-        time_msg -= (h * 3600)
-        m = int(time_msg / 60)
-        time_msg -= (m * 60)
-        s = time_msg
-        result = "{}天{}小时{}分".format(d, h, m)
-        return result
-
-    def set_key(self, topic, msg):
-        self.key = msg["value"]
-    def get_key(self, topic, msg):
-        return self.key
-
-    def get_imei(self, topic, msg):
-        if not self.imei:
-            self.imei = modem.getDevImei()
-        # self.imei = "860132060128634" #860132060128634
-        return self.imei
-
-    def get_cid(self, topic, msg):
-        return self.cid
-
-    def set_cid(self, topic, msg):
-        self.cid = msg["value"]
-
-    def get_imsi(self, topic, msg):
-        if not self.imei:
-            self.imei = sim.getImsi()
-        return self.imsi
-
-    def get_password(self, topic, msg):
-        return self.password
-
-    def set_password(self, topic, msg):
-        self.password = msg["value"]
-
-    def set_ping(self, topic, msg):
-        self.PING = msg
-    def get_ping(self, topic, msg):
-        return self.PING
-
-    def set_connect(self, topic, msg):
-        #EventMesh.debug_log("set_connect:{}".format(msg))
-        self.connect = msg
-    def get_connect(self, topic, msg):
-        return self.connect
-
-    def start_blood_oxygen(self, topic, msg):
-        EventMesh.debug_log("start_blood_oxygen!!!")
-        self.hsensor.open_blood_oxygen()
-
-    def start_heart(self, topic, msg):
-        EventMesh.debug_log("start_heart!!!")
-        self.hsensor.open_heart()
-
-    def stop_blood_oxygen(self, topic, msg):
-        EventMesh.debug_log("stop_blood_oxygen!!!")
-        self.hsensor.close()
-
-    def stop_heart(self, topic, msg):
-        EventMesh.debug_log("stop_heart!!!")
-        self.hsensor.close()
-
-    def get_blood_oxygen(self, topic, msg):
-        data = self.hsensor.get_all_data()
-        return data[1]
-
-    def get_heart(self, topic, msg):
-        data = self.hsensor.get_all_data()
-        return data[0]
-    
-    def get_wear(self, topic, msg):
-        return self.hsensor.get_wear()
-    
-    def get_Hsensor(self, topic, msg):
-        return self.hsensor
-    
-    def Hsensor_set_sleep(self, topic, msg):
-        self.hsensor.set_sleep()
-
-    def start_temp(self, topic, msg):
-        EventMesh.debug_log("start_temp!!!!!!!")
-        WHO_AM_I = bytearray([0x01, 0])
-        I2C_SLAVE_ADDR = 0x49
-        #I2C_SLAVE_ADDR = 0x48
-        r_data = bytearray(2)
-        data = bytearray([0x61A0, 0])   # 唤醒
-        return self.i2c0.write(I2C_SLAVE_ADDR, WHO_AM_I, 1, data, 2)
-    def stop_temp(self, topic, msg):
-        EventMesh.debug_log("stop_temp!!!!!!!")
-        WHO_AM_I = bytearray([0x01, 0])
-        I2C_SLAVE_ADDR = 0x49
-        #I2C_SLAVE_ADDR = 0x48
-        r_data = bytearray(2)
-        data = bytearray([0x60A0, 0])   #休眠
-        return self.i2c0.write(I2C_SLAVE_ADDR, WHO_AM_I, 1, data, 2)
         
-    def get_temp(self, topic, msg):
-        WHO_AM_I = bytearray([0x00, 0])
-        I2C_SLAVE_ADDR = 0x49
-        #I2C_SLAVE_ADDR = 0x48
-        r_data = bytearray(2)
-        self.i2c0.read(I2C_SLAVE_ADDR, WHO_AM_I, 1, r_data, 2, 0)
-        #EventMesh.debug_log("temp_data:{}".format(r_data))
-        temp_s = ((r_data[0]<<8) | (r_data[1]))>>4
-        #EventMesh.debug_log("temp_s:{}".format(temp_s))
-        temp_data = temp_s * 0.0625
-        EventMesh.debug_log("temp_data:{}".format(temp_data))
-        return temp_data
- 
-            
 
-    def sim_slot_get(self, topic=None, msg=None):
-        return sim.getCurSimid()
+        def get_usb_state(self):
+            state = self.usb.getStatus()
+            if state == -1:
+                state = 0
+            return state
+        
 
-    def sim_slot_switch(self, topic=None, slot=None):
-        """
-        sim 卡槽切换
-        :param topic:
-        :param slot:
-        :return: 切换sim卡卡槽  0 切换成功, 1 无需切换, -1 切换失败
-        """
-        if self.sim_slot_get() == slot:
-            return 1
-        else:
-            return sim.switchCard(slot)
-
-    def usb_event_cb(self, state):
-        status = state
-
-        if status == 1:#插入USB
-            EventMesh.debug_log("charge R_CHARGE_in")
-            EventMesh.publish("clear_usb_flag")
-            EventMesh.publish("set_usb", 1)#
-            pass
-        elif status == 0:#拨出usbs
-            EventMesh.publish("clear_usb_flag")
-            EventMesh.publish("set_usb", 2)#
-            EventMesh.debug_log("charge R_CHARGE_out")
+    def wifiScan_cb(args):
+            EventMesh.publish(constants.EVENT.WIFIINFO, args)
+            wifiScan.control(0)
 
+    class LocationManager(Abstract):
+
+        def __init__(self):
+            self.gps = None
+            #self.match = GPSMatch()
+            self.timer_read_GPS_info = osTimer()
+            self.wifi_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
+            self.start_agps = 0
+            read_data = EventMesh.publish("get_storage_config","isOpenGNSS")#获取是否打开GNSS
+            if read_data != None:
+                self.isOpenGNSS = read_data
+            else:#默认关闭GNSS
+                self.isOpenGNSS = "1"
+                EventMesh.publish("set_storage_config",["isOpenGNSS",self.isOpenGNSS])
+
+            self.isOpenGNSS = EventMesh.publish("get_storage_config","isOpenGNSS")
+            if self.isOpenGNSS == None:
+                self.isOpenGNSS = "1"
+            if self.isOpenGNSS == "1":
+                quecgnss.init()
+                quecgnss.gnssEnable(0)
+        @staticmethod
+        def get_date():
+            return "{:04d}-{:02d}-{:02d}".format(*utime.localtime()[0:3])
+
+        @staticmethod
+        def get_time():
+            return "{:02d}:{:02d}:{:02d}".format(*utime.localtime()[3:6])
+
+        def post_processor_after_instantiation(self):
+            # _gps_cfg = {
+            #     "UARTn": UART.UART1,
+            #     "buadrate": 115200,
+            #     "databits": 8,
+            #     "parity": 0,
+            #     "stopbits": 1,
+            #     "flowctl": 0,
+            #     "PowerPin": Pin.GPIO2,
+            #     "StandbyPin": Pin.GPIO3,
+            #     "BackupPin": None,
+            #     "gps_mode": 0x01,
+            # }
+            # self.gps = GPS(**_gps_cfg)
+            # self.gps.power_switch(0)#关闭GPS
+            EventMesh.subscribe(constants.EVENT.GPSOPEN, self.gps_open)
+            EventMesh.subscribe(constants.EVENT.GPSCLOSE, self.gps_close)
+            EventMesh.subscribe(constants.EVENT.START_LOCATION, self.start_location)
+            EventMesh.subscribe(constants.EVENT.START_LOCATION_TEST, self.start_location_test)
+            EventMesh.subscribe(constants.EVENT.WIFIINFO, self.WIFI_INFO)
+            EventMesh.subscribe(constants.EVENT.WIFISCANOPEN,self.WIFI_scan_open)
+            EventMesh.subscribe(constants.EVENT.CLOSE_LOCATION,self.close_location)
+            EventMesh.subscribe("get_location_flag",self.get_location_flag)
             
+            #EventMesh.subscribe(constants.EVENT.GPSCLOSE, self.gps_close)
+        def get_location_flag(self, event, msg):
+            return self.location_flag
+        def start_location(self, event, msg):
+            self.location_queue.put(msg)#测试类型入队
+            self.gps_data = {}
+            self.wifi_data = []
+            self.cell_data = []
+            self.location_timer_count = 0
+            self.GSV_sig_ok_count = 0
+            EventMesh.debug_log("start_location:{}".format(msg))
+            if( self.location_flag == 1):
+                return
+            _thread.stack_size((9+5)*1024)
+            self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
+            _thread.stack_size(8*1024)
             
+            self.location_flag = 1
+            self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+            #self.gps_open(event, msg)
 
-       
 
-    def get_usb_state(self):
-        state = self.usb.getStatus()
-        if state == -1:
-            state = 0
-        return state
+        def start_location_test(self, event, msg):
+            EventMesh.debug_log("start_location_test")
+            
+            self.location_type = 1
+            if( self.location_flag == 1):
+                return
+            _thread.stack_size((9+4)*1024)
+            self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
+            _thread.stack_size(8*1024)
+        
+            self.location_timer_count = 0
+            self.location_flag = 1
+            #self.gps_open(event, msg)
+            self.location_type = 1
+            self.timer_read_GPS_info.start(1000, 1, self.location_timer)
     
 
-def wifiScan_cb(args):
-        EventMesh.publish(constants.EVENT.WIFIINFO, args)
-        wifiScan.control(0)
-
-class LocationManager(Abstract):
-
-    def __init__(self):
-        self.gps = None
-        #self.match = GPSMatch()
-        self.timer_read_GPS_info = osTimer()
-        self.wifi_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
-        self.start_agps = 0
-        read_data = EventMesh.publish("get_storage_config","isOpenGNSS")#获取是否打开GNSS
-        if read_data != None:
-            self.isOpenGNSS = read_data
-        else:#默认关闭GNSS
-            self.isOpenGNSS = "1"
-            EventMesh.publish("set_storage_config",["isOpenGNSS",self.isOpenGNSS])
-
-        self.isOpenGNSS = EventMesh.publish("get_storage_config","isOpenGNSS")
-        if self.isOpenGNSS == None:
-            self.isOpenGNSS = "1"
-        if self.isOpenGNSS == "1":
-            quecgnss.init()
-            quecgnss.gnssEnable(0)
-    @staticmethod
-    def get_date():
-        return "{:04d}-{:02d}-{:02d}".format(*utime.localtime()[0:3])
-
-    @staticmethod
-    def get_time():
-        return "{:02d}:{:02d}:{:02d}".format(*utime.localtime()[3:6])
-
-    def post_processor_after_instantiation(self):
-        # _gps_cfg = {
-        #     "UARTn": UART.UART1,
-        #     "buadrate": 115200,
-        #     "databits": 8,
-        #     "parity": 0,
-        #     "stopbits": 1,
-        #     "flowctl": 0,
-        #     "PowerPin": Pin.GPIO2,
-        #     "StandbyPin": Pin.GPIO3,
-        #     "BackupPin": None,
-        #     "gps_mode": 0x01,
-        # }
-        # self.gps = GPS(**_gps_cfg)
-        # self.gps.power_switch(0)#关闭GPS
-        EventMesh.subscribe(constants.EVENT.GPSOPEN, self.gps_open)
-        EventMesh.subscribe(constants.EVENT.GPSCLOSE, self.gps_close)
-        EventMesh.subscribe(constants.EVENT.START_LOCATION, self.start_location)
-        EventMesh.subscribe(constants.EVENT.START_LOCATION_TEST, self.start_location_test)
-        EventMesh.subscribe(constants.EVENT.WIFIINFO, self.WIFI_INFO)
-        EventMesh.subscribe(constants.EVENT.WIFISCANOPEN,self.WIFI_scan_open)
-        EventMesh.subscribe(constants.EVENT.CLOSE_LOCATION,self.close_location)
-        EventMesh.subscribe("get_location_flag",self.get_location_flag)
-        
-        #EventMesh.subscribe(constants.EVENT.GPSCLOSE, self.gps_close)
-    def get_location_flag(self, event, msg):
-        return self.location_flag
-    def start_location(self, event, msg):
-        self.location_queue.put(msg)#测试类型入队
-        self.gps_data = {}
-        self.wifi_data = []
-        self.cell_data = []
-        self.location_timer_count = 0
-        self.GSV_sig_ok_count = 0
-        EventMesh.debug_log("start_location:{}".format(msg))
-        if( self.location_flag == 1):
-            return
-        _thread.stack_size((9+5)*1024)
-        self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
-        _thread.stack_size(8*1024)
-        
-        self.location_flag = 1
-        self.timer_read_GPS_info.start(1000, 1, self.location_timer)
-        #self.gps_open(event, msg)
+        def close_location(self, event, msg):
+            self.location_flag = 0
+            self.location_type = 0
+            self.timer_read_GPS_info.stop()
 
+            
 
-    def start_location_test(self, event, msg):
-        EventMesh.debug_log("start_location_test")
-        
-        self.location_type = 1
-        if( self.location_flag == 1):
-            return
-        _thread.stack_size((9+4)*1024)
-        self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
-        _thread.stack_size(8*1024)
-       
-        self.location_timer_count = 0
-        self.location_flag = 1
-        #self.gps_open(event, msg)
-        self.location_type = 1
-        self.timer_read_GPS_info.start(1000, 1, self.location_timer)
- 
-
-    def close_location(self, event, msg):
-        self.location_flag = 0
-        self.location_type = 0
-        self.timer_read_GPS_info.stop()
+        def WIFI_INFO(self, event, msg):
+            self.wifi_data = msg
+            # EventMesh.debug_log("WIFI_INFO:")
+            # EventMesh.debug_log([msg[0],msg])
 
-        
+        def WIFI_scan_open(self, event, msg):
+            #EventMesh.debug_log("WIFI_scan_open")
+            
 
-    def WIFI_INFO(self, event, msg):
-        self.wifi_data = msg
-        # EventMesh.debug_log("WIFI_INFO:")
-        # EventMesh.debug_log([msg[0],msg])
+            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()
+                #EventMesh.debug_log("wifiScan.asyncStart")
+            else :
+                EventMesh.debug_log("WIFI_scan_open:error1") 
+        def gps_open(self, event, msg):
+            if self.isOpenGNSS == "1":
+                #EventMesh.debug_log("publish:gps_open")
+                #quecgnss.init()
+                quecgnss.gnssEnable(2)
+                #self.gps.__gps_nmea_data_clean()
+        def gps_close(self, event, msg):
+            if self.isOpenGNSS == "1":
+                quecgnss.gnssEnable(0)
+        def location_timer(self, *args, **kwargs):
+            
+            self.location_timer_count = self.location_timer_count +1
+            self.location_check_data_timer_count = self.location_check_data_timer_count+1
 
-    def WIFI_scan_open(self, event, msg):
-        #EventMesh.debug_log("WIFI_scan_open")
-        
+        def Location_send(self, msg) :
+            EventMesh.debug_log("Location_send1")
+            if self.location_queue.empty() == True:
+                return
+            EventMesh.debug_log("Location_send2")
+            while True:
+                if self.location_queue.empty() == False:
+                    TYPE = self.location_queue.get()
+                    date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
+                    date = date[2:]
+                    #date = "180916,025723"
+                    GPS_type = "V"
+                    latitude = "0.000000,N"
+                    longitude = "0.000000,E"
+                    speed = "0.00"
+                    direction = "0.0"
+                    high = "100.0"
+                    number = "0"
+                    precision = "24"
+                    if msg[0] :#有GPS数据
+                        GPS_type = "A"
+                        # 纬度
+                        latitude = msg[0]["latitude"]
+                        # 经度
+                        longitude = msg[0]["longitude"]
+                        # 速度
+                        speed = msg[0]["speed"]
+                        # 方向
+                        direction = "0"
+                        if msg[0]["direction"] :
+                            direction = msg[0]["direction"]
+                        # 高度
+                        high = msg[0]["high"]
+                        high_tmp = high.split(".")
+                        if len(high_tmp) >= 2 :
+                            high = "%s"%(high_tmp[0])
+                        # 讯号质量:搜索到的卫星数目
+                        number = msg[0]["number"]
+                        precision = msg[0]["precision"]
+                        #date = msg[0]["date"]
+                    
+                    #gsm 信号强度
+                    gsm_sig =  str((100//31)*EventMesh.publish("screen_get_sig"))
+                    # 电池电量百分比 
+                    bat_tmp = EventMesh.publish("screen_get_battery")
+                    battery_caption =  str(bat_tmp[1])
+                    #步数
+                    old_step = 0
+                    step = 0
+                    step = EventMesh.publish("get_old_step_value")
+                    if step != 0:
+                        tmp_data  = EventMesh.publish("get_storage_config","old_step_new")
+                        if tmp_data != None:
+                            old_step = tmp_data
+                        if old_step !=  step:
+                            EventMesh.publish("set_storage_config",["old_step",step])
+                            EventMesh.publish("set_storage_config",["old_step_new",step])
+                            
+                    old_step = step
+                    # step = str(EventMesh.publish(constants.EVENT.GET_STEP)[0])
+                    #翻转次数
+                    turn_count = "0"
+                    #终端状态
+                    state = "%08X"%(EventMesh.publish("get_dev_state"))
+                    #EventMesh.debug_log("TYPE:{}".format(TYPE))
+                    if type(TYPE) == list:#队列里的数据有终端状态,则用队里的终端状态
+                        if len(TYPE)>= 2 :
+                            state = "%08X"%(TYPE[1])
+                    
+                    EventMesh.debug_log("state:{}".format(state))
+                    #基站数据
+                    CELL_num = len(msg[2])
+                    CELL_data = "1," #时延
+                    if msg[2] != []:
+                        for CELL in msg[2] :
+                            if CELL[0] == 0 :
+                                CELL_data += "%X,"%(int(CELL[2])) #MCC
+                                CELL_data += str(CELL[3]) +","#MNC
+                                CELL_data += str(CELL[5]) +","#tac,区域码
+                                CELL_data += str(CELL[1]) +","#基站编号 CID
+                                CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
+                            else :
+                                CELL_data += str(CELL[5]) +","#tac,区域码
+                                CELL_data += str(CELL[1]) +","#基站编号 CID
+                                CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
+                        CELL_data = CELL_data[:(len(CELL_data)-1)]
+                    #WIFI数据
+                    WIFI_num = 0 
+                    WIFI_data = ""
+                    if msg[1] :
+                        WIFI_num = msg[1][0]
+                        i = 0
+                        for MAC in msg[1][1] :
+                            WIFI_data += "wifi%d,%s,%d,"%(i,str(MAC[0]),MAC[1])
+                            i += 1
+                        WIFI_data = WIFI_data[:(len(WIFI_data)-1)]
+                    WIFI_data = WIFI_data.lower()
+                    #send_data = "UD ,%s ,%s     ,%s       ,%s       ,%s   ,%s       ,%s  ,%s    ,%s     ,%s             ,%s  ,%s        ,%s   ,%d     ,%s       ,%d      ,%s"\
+                    #              %(date,GPS_type,latitude,longitude,speed,direction,high,number,gsm_sig,battery_caption,step,turn_count,state,CELL_num,CELL_data,WIFI_num,WIFI_data)
+                    #定位数据
+                    send_data = "%s,%s,%s"%(date,GPS_type,latitude)
+                    send_data += ",%s,%s,%s"%(longitude,speed,direction)
+                    send_data += ",%s,%s,%s"%(high,number,gsm_sig,)
+                    send_data += ",%s,%s,%s"%(battery_caption,step,turn_count)
+                    send_data += ",%s,%d,%s"%(state,CELL_num,CELL_data)
+                    send_data += ",%d,%s"%(WIFI_num,WIFI_data)
+                    send_data+=",%s"%(precision)
+                    #EventMesh.debug_log("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
+            
+                
+                    #EventMesh.debug_log("Location_send3:{}:{}".format(TYPE,send_data))
+                    if type(TYPE) == list:
+                        EventMesh.publish(TYPE[0],send_data)
+                    else:
+                        EventMesh.publish(TYPE,send_data)
+                else :
+                    break
 
-        if wifiScan.getState() == False :
+        def GxGGA_latitude(self, gga_data):
+            """Parse latitude from GGA"""
+            if gga_data:
+                latitude_re = ure.search(r",[0-9]+\.[0-9]+,[NS],", gga_data)
+                if latitude_re:
+                    latitude = latitude_re.group(0)[1:-3]
+                    return str(float(latitude[:2]) + float(latitude[2:]) / 60)
+            return ""
+        def GxGGA_longitude(self, gga_data):
+            """Parse longitude from GGA"""
+            if gga_data:
+                longitude_re = ure.search(r",[0-9]+\.[0-9]+,[EW],", gga_data)
+                if longitude_re:
+                    longitude = longitude_re.group(0)[1:-3]
+                    return str(float(longitude[:3]) + float(longitude[3:]) / 60)
+            return ""
+
+        def GxGGA_altitude(self, gga_data):
+            """Parse altitude from GGA"""
+            if gga_data:
+                altitude_re = ure.search(r",-*[0-9]+\.[0-9]+,M,", gga_data)
+                if altitude_re:
+                    return altitude_re.group(0)[1:-3]
+            return ""
+        def location_thread(self):
+            
             self.wifi_data = []
-            wifiScan.control(1)
-            wifiScan.setCfgParam(6, 2, 5,  0)  #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
-            wifiScan.setCallback(wifiScan_cb) #注册回调函数
-            wifiScan.asyncStart()
-            #EventMesh.debug_log("wifiScan.asyncStart")
-        else :
-            EventMesh.debug_log("WIFI_scan_open:error1") 
-    def gps_open(self, event, msg):
-        if self.isOpenGNSS == "1":
-            #EventMesh.debug_log("publish:gps_open")
-            #quecgnss.init()
-            quecgnss.gnssEnable(2)
-            #self.gps.__gps_nmea_data_clean()
-    def gps_close(self, event, msg):
-        if self.isOpenGNSS == "1":
-            quecgnss.gnssEnable(0)
-    def location_timer(self, *args, **kwargs):
-        
-        self.location_timer_count = self.location_timer_count +1
-        self.location_check_data_timer_count = self.location_check_data_timer_count+1
+            self.gps_data = {}
+            self.cell_data = []
+            gnss_r_data = []
+            self.GSV_sig_ok_count = 0
+            self.GSV_sig_very_ok_count = 0
+            self.GGA_count = 0
+            self.RMC_A_count = 0
+            # if self.start_agps == 1: #开启agps
+            #     self.start_agps = 0
+            #     quecgnss.configSet(2,1)
+            if self.lpm_fd == None:
+                self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
+            pm.wakelock_lock(self.lpm_fd)
+            EventMesh.debug_log("location_thread:1")
+            EventMesh.publish(constants.EVENT.GPSOPEN)
+            EventMesh.debug_log("location_thread:2")
+            #self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+            EventMesh.debug_log("location_thread:3")
+            #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)
+            GSV_dict= {}
+            while self.location_flag == 1:
+                try :   
+                    
+                    match_gga_data = []
+                    #match_gsv_data = []
+                    gnss_r_data = []
+                    # if self.location_check_data_timer_count >= 3:
+                    #     pm.autosleep(0)#唤醒
+                    #     pm.sclkEx_set(0, 1, 5)
+                    if self.location_check_data_timer_count >= 1 :#3秒查一次基站数据和wifi数据
+                        self.location_check_data_timer_count = 0
+                        #EventMesh.debug_log(self.location_timer_count)
+                        GSV_dict= {}
+                        if self.isOpenGNSS == "1":                    
+                            #检查GNSS数据
+                            if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
 
-    def Location_send(self, msg) :
-        EventMesh.debug_log("Location_send1")
-        if self.location_queue.empty() == True:
-            return
-        EventMesh.debug_log("Location_send2")
-        while True:
-            if self.location_queue.empty() == False:
-                TYPE = self.location_queue.get()
-                date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
-                date = date[2:]
-                #date = "180916,025723"
-                GPS_type = "V"
-                latitude = "0.000000,N"
-                longitude = "0.000000,E"
-                speed = "0.00"
-                direction = "0.0"
-                high = "100.0"
-                number = "0"
-                precision = "24"
-                if msg[0] :#有GPS数据
-                    GPS_type = "A"
-                    # 纬度
-                    latitude = msg[0]["latitude"]
-                    # 经度
-                    longitude = msg[0]["longitude"]
-                    # 速度
-                    speed = msg[0]["speed"]
-                    # 方向
-                    direction = "0"
-                    if msg[0]["direction"] :
-                        direction = msg[0]["direction"]
-                    # 高度
-                    high = msg[0]["high"]
-                    high_tmp = high.split(".")
-                    if len(high_tmp) >= 2 :
-                        high = "%s"%(high_tmp[0])
-                    # 讯号质量:搜索到的卫星数目
-                    number = msg[0]["number"]
-                    precision = msg[0]["precision"]
-                    #date = msg[0]["date"]
-                
-                #gsm 信号强度
-                gsm_sig =  str((100//31)*EventMesh.publish("screen_get_sig"))
-                # 电池电量百分比 
-                bat_tmp = EventMesh.publish("screen_get_battery")
-                battery_caption =  str(bat_tmp[1])
-                #步数
-                old_step = 0
-                step = 0
-                step = EventMesh.publish("get_old_step_value")
-                if step != 0:
-                    tmp_data  = EventMesh.publish("get_storage_config","old_step_new")
-                    if tmp_data != None:
-                        old_step = tmp_data
-                    if old_step !=  step:
-                        EventMesh.publish("set_storage_config",["old_step",step])
-                        EventMesh.publish("set_storage_config",["old_step_new",step])
-                        
-                old_step = step
-                # step = str(EventMesh.publish(constants.EVENT.GET_STEP)[0])
-                #翻转次数
-                turn_count = "0"
-                #终端状态
-                state = "%08X"%(EventMesh.publish("get_dev_state"))
-                #EventMesh.debug_log("TYPE:{}".format(TYPE))
-                if type(TYPE) == list:#队列里的数据有终端状态,则用队里的终端状态
-                    if len(TYPE)>= 2 :
-                        state = "%08X"%(TYPE[1])
-                
-                EventMesh.debug_log("state:{}".format(state))
-                #基站数据
-                CELL_num = len(msg[2])
-                CELL_data = "1," #时延
-                if msg[2] != []:
-                    for CELL in msg[2] :
-                        if CELL[0] == 0 :
-                            CELL_data += "%X,"%(int(CELL[2])) #MCC
-                            CELL_data += str(CELL[3]) +","#MNC
-                            CELL_data += str(CELL[5]) +","#tac,区域码
-                            CELL_data += str(CELL[1]) +","#基站编号 CID
-                            CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
-                        else :
-                            CELL_data += str(CELL[5]) +","#tac,区域码
-                            CELL_data += str(CELL[1]) +","#基站编号 CID
-                            CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
-                    CELL_data = CELL_data[:(len(CELL_data)-1)]
-                #WIFI数据
-                WIFI_num = 0 
-                WIFI_data = ""
-                if msg[1] :
-                    WIFI_num = msg[1][0]
-                    i = 0
-                    for MAC in msg[1][1] :
-                        WIFI_data += "wifi%d,%s,%d,"%(i,str(MAC[0]),MAC[1])
-                        i += 1
-                    WIFI_data = WIFI_data[:(len(WIFI_data)-1)]
-                WIFI_data = WIFI_data.lower()
-                #send_data = "UD ,%s ,%s     ,%s       ,%s       ,%s   ,%s       ,%s  ,%s    ,%s     ,%s             ,%s  ,%s        ,%s   ,%d     ,%s       ,%d      ,%s"\
-                #              %(date,GPS_type,latitude,longitude,speed,direction,high,number,gsm_sig,battery_caption,step,turn_count,state,CELL_num,CELL_data,WIFI_num,WIFI_data)
-                #定位数据
-                send_data = "%s,%s,%s"%(date,GPS_type,latitude)
-                send_data += ",%s,%s,%s"%(longitude,speed,direction)
-                send_data += ",%s,%s,%s"%(high,number,gsm_sig,)
-                send_data += ",%s,%s,%s"%(battery_caption,step,turn_count)
-                send_data += ",%s,%d,%s"%(state,CELL_num,CELL_data)
-                send_data += ",%d,%s"%(WIFI_num,WIFI_data)
-                send_data+=",%s"%(precision)
-                #EventMesh.debug_log("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
-        
-            
-                #EventMesh.debug_log("Location_send3:{}:{}".format(TYPE,send_data))
-                if type(TYPE) == list:
-                    EventMesh.publish(TYPE[0],send_data)
-                else:
-                    EventMesh.publish(TYPE,send_data)
-            else :
-                break
-
-    def GxGGA_latitude(self, gga_data):
-        """Parse latitude from GGA"""
-        if gga_data:
-            latitude_re = ure.search(r",[0-9]+\.[0-9]+,[NS],", gga_data)
-            if latitude_re:
-                latitude = latitude_re.group(0)[1:-3]
-                return str(float(latitude[:2]) + float(latitude[2:]) / 60)
-        return ""
-    def GxGGA_longitude(self, gga_data):
-        """Parse longitude from GGA"""
-        if gga_data:
-            longitude_re = ure.search(r",[0-9]+\.[0-9]+,[EW],", gga_data)
-            if longitude_re:
-                longitude = longitude_re.group(0)[1:-3]
-                return str(float(longitude[:3]) + float(longitude[3:]) / 60)
-        return ""
-
-    def GxGGA_altitude(self, gga_data):
-        """Parse altitude from GGA"""
-        if gga_data:
-            altitude_re = ure.search(r",-*[0-9]+\.[0-9]+,M,", gga_data)
-            if altitude_re:
-                return altitude_re.group(0)[1:-3]
-        return ""
-    def location_thread(self):
-        
-        self.wifi_data = []
-        self.gps_data = {}
-        self.cell_data = []
-        gnss_r_data = []
-        self.GSV_sig_ok_count = 0
-        self.GSV_sig_very_ok_count = 0
-        self.GGA_count = 0
-        self.RMC_A_count = 0
-        # if self.start_agps == 1: #开启agps
-        #     self.start_agps = 0
-        #     quecgnss.configSet(2,1)
-        if self.lpm_fd == None:
-            self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
-        pm.wakelock_lock(self.lpm_fd)
-        EventMesh.debug_log("location_thread:1")
-        EventMesh.publish(constants.EVENT.GPSOPEN)
-        EventMesh.debug_log("location_thread:2")
-        #self.timer_read_GPS_info.start(1000, 1, self.location_timer)
-        EventMesh.debug_log("location_thread:3")
-        #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)
-        GSV_dict= {}
-        while self.location_flag == 1:
-            try :   
-                
-                match_gga_data = []
-                #match_gsv_data = []
-                gnss_r_data = []
-                # if self.location_check_data_timer_count >= 3:
-                #     pm.autosleep(0)#唤醒
-                #     pm.sclkEx_set(0, 1, 5)
-                if self.location_check_data_timer_count >= 1 :#3秒查一次基站数据和wifi数据
-                    self.location_check_data_timer_count = 0
-                    #EventMesh.debug_log(self.location_timer_count)
-                    GSV_dict= {}
-                    if self.isOpenGNSS == "1":                    
-                        #检查GNSS数据
-                        if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
-
-                            pass
-                            tmp_ok_count = 0
-                            tmp_very_ok_count = 0
-                            gsv_data = quecgnss.get_gsv()
-                            rmc_data = quecgnss.get_rmc()
-                            gga_data = quecgnss.get_gga()
-                            vtg_data = quecgnss.get_vtg()
-                            # EventMesh.debug_log("gsv:{}".format(quecgnss.get_gsv()))
-                            # EventMesh.debug_log("gga:{}".format(quecgnss.get_gga()))
-                            # EventMesh.debug_log("rmc:{}".format(quecgnss.get_rmc()))
-                            # EventMesh.debug_log("vtg:{}".format(quecgnss.get_vtg())) 
-                            for i in range(len(gsv_data)) :
-                                
-                                if i % 2 == 0:
-                                    if i+1 >= len(gsv_data) :
-                                        # EventMesh.debug_log("gsv_data num error!!")
-                                        break
-                                    GSV_dict[gsv_data[i]] = gsv_data[i+1]
-                                    #EventMesh.debug_log("type:gsv_data{}".format(type(gsv_data[i+1])))
-                                    try:
-                                        #EventMesh.debug_log("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
-                                        if gsv_data[i+1] :
-                                            if (gsv_data[i+1])>=20:
-                                                tmp_ok_count +=1   
-                                            if (gsv_data[i+1])>=30:
-                                                tmp_very_ok_count +=1  
-                                                
-                                    except Exception as e:
-                                        usys.print_exception(e)
+                                pass
+                                tmp_ok_count = 0
+                                tmp_very_ok_count = 0
+                                gsv_data = quecgnss.get_gsv()
+                                rmc_data = quecgnss.get_rmc()
+                                gga_data = quecgnss.get_gga()
+                                vtg_data = quecgnss.get_vtg()
+                                # EventMesh.debug_log("gsv:{}".format(quecgnss.get_gsv()))
+                                # EventMesh.debug_log("gga:{}".format(quecgnss.get_gga()))
+                                # EventMesh.debug_log("rmc:{}".format(quecgnss.get_rmc()))
+                                # EventMesh.debug_log("vtg:{}".format(quecgnss.get_vtg())) 
+                                for i in range(len(gsv_data)) :
                                     
-                            if(tmp_ok_count > self.GSV_sig_ok_count ):
-                                self.GSV_sig_ok_count = tmp_ok_count
-                            if(tmp_very_ok_count > self.GSV_sig_very_ok_count ):
-                                self.GSV_sig_very_ok_count = tmp_very_ok_count
-                            match_rmc_data = rmc_data.split(",")
-                            if len (match_rmc_data)>3: #有rmc数据
-                                    if match_rmc_data[2] == 'A':    
-                                        match_gga_data = gga_data.split(",")
-                                        if len(match_gga_data) >4: #数据全
-                                            match_vtg_data = vtg_data.split(",")
-                                            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(self.GxGGA_latitude(gga_data)).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(self.GxGGA_longitude(gga_data)).split(".")
-                                            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])
-                                            
-                                            high = "0"#高度
-                                            high = str(self.GxGGA_altitude(gga_data))
-                                            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": direction,
-                                                "speed": speed,
-                                                "number": number, 
-                                                "date":  gps_date,
-                                                "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
+                                    if i % 2 == 0:
+                                        if i+1 >= len(gsv_data) :
+                                            # EventMesh.debug_log("gsv_data num error!!")
+                                            break
+                                        GSV_dict[gsv_data[i]] = gsv_data[i+1]
+                                        #EventMesh.debug_log("type:gsv_data{}".format(type(gsv_data[i+1])))
+                                        try:
+                                            #EventMesh.debug_log("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
+                                            if gsv_data[i+1] :
+                                                if (gsv_data[i+1])>=20:
+                                                    tmp_ok_count +=1   
+                                                if (gsv_data[i+1])>=30:
+                                                    tmp_very_ok_count +=1  
+                                                    
+                                        except Exception as e:
+                                            usys.print_exception(e)
+                                        
+                                if(tmp_ok_count > self.GSV_sig_ok_count ):
+                                    self.GSV_sig_ok_count = tmp_ok_count
+                                if(tmp_very_ok_count > self.GSV_sig_very_ok_count ):
+                                    self.GSV_sig_very_ok_count = tmp_very_ok_count
+                                match_rmc_data = rmc_data.split(",")
+                                if len (match_rmc_data)>3: #有rmc数据
+                                        if match_rmc_data[2] == 'A':    
+                                            match_gga_data = gga_data.split(",")
+                                            if len(match_gga_data) >4: #数据全
+                                                match_vtg_data = vtg_data.split(",")
+                                                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(self.GxGGA_latitude(gga_data)).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(self.GxGGA_longitude(gga_data)).split(".")
+                                                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])
+                                                
+                                                high = "0"#高度
+                                                high = str(self.GxGGA_altitude(gga_data))
+                                                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": direction,
+                                                    "speed": speed,
+                                                    "number": number, 
+                                                    "date":  gps_date,
+                                                    "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
 
-                if self.location_type == 1: #测试模式
-                    self.location_timer_count = 0
-                    
-                    EventMesh.publish("PUSH_LOCATION_DATA", [[self.gps_data,GSV_dict],self.wifi_data,self.cell_data]) 
-                    if self.gps_data  != {} : #发送数据 
-                        EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
-                        self.location_queue.put(constants.PROTOCOL.UD_SEND)
-                        self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                    if self.location_type == 1: #测试模式
+                        self.location_timer_count = 0
                         
+                        EventMesh.publish("PUSH_LOCATION_DATA", [[self.gps_data,GSV_dict],self.wifi_data,self.cell_data]) 
+                        if self.gps_data  != {} : #发送数据 
+                            EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+                            self.location_queue.put(constants.PROTOCOL.UD_SEND)
+                            self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                            
 
-                elif self.location_type == 0: #正常模式     
-                    if self.gps_data  != {} or self.location_timer_count > 100: #or( self.wifi_data != [] and self.cell_data != []): 
-                        if self.location_queue.empty() == False:#有定位队列
-                            pass
-                            #EventMesh.txt_log("LOCATION timer:{} ok:{} very_ok:{}".format(self.location_timer_count,self.GSV_sig_ok_count))   
-                            #EventMesh.txt_log("LOCATION:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
-                        if self.gps_data  == {}: #定位超时,且信噪比多个大于30,下次启动agps
-                            if self.GSV_sig_very_ok_count > 3:#3个超30以上
-                                self.start_agps = 1
-                                #EventMesh.txt_log("open agps:{}".format(GSV_dict))
-                        #upload_time = EventMesh.publish("get_upload_data")    
-                        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
+                    elif self.location_type == 0: #正常模式     
+                        if self.gps_data  != {} or self.location_timer_count > 100: #or( self.wifi_data != [] and self.cell_data != []): 
+                            if self.location_queue.empty() == False:#有定位队列
+                                pass
+                                #EventMesh.txt_log("LOCATION timer:{} ok:{} very_ok:{}".format(self.location_timer_count,self.GSV_sig_ok_count))   
+                                #EventMesh.txt_log("LOCATION:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
+                            if self.gps_data  == {}: #定位超时,且信噪比多个大于30,下次启动agps
+                                if self.GSV_sig_very_ok_count > 3:#3个超30以上
+                                    self.start_agps = 1
+                                    #EventMesh.txt_log("open agps:{}".format(GSV_dict))
+                            #upload_time = EventMesh.publish("get_upload_data")    
+                            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.isOpenGNSS != "1" or (self.GSV_sig_ok_count <= 1 and self.location_timer_count > 20)) and self.wifi_data != [] and self.cell_data != [] : #超过40秒且信号大于30的不足3个
-                        EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
-                        EventMesh.debug_log("Location_send:CLOSE_LOCATION")  
-                        #EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
-                        self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                            
+                        if (self.isOpenGNSS != "1" or (self.GSV_sig_ok_count <= 1 and self.location_timer_count > 20)) and self.wifi_data != [] and self.cell_data != [] : #超过40秒且信号大于30的不足3个
+                            EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
+                            EventMesh.debug_log("Location_send:CLOSE_LOCATION")  
+                            #EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
+                            self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
 
-             
                 
-            except Exception as e:
-                usys.print_exception(e)
-                EventMesh.txt_log("location_thread:ERROR:".format(e))
-                #EventMesh.debug_log("location_thread:ERROR:{}".format(usys.print_exception(e)))
-                EventMesh.debug_log("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(500)
-
-        #self.timer_read_GPS_info.stop()
-        #self.gps.power_switch(0)
-        wifiScan.control(0)
-        EventMesh.publish(constants.EVENT.GPSCLOSE)
-        # 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)
-        EventMesh.debug_log("CLOSE_LOCATION")
-        #EventMesh.txt_log("CLOSE_LOCATION")
+                    
+                except Exception as e:
+                    usys.print_exception(e)
+                    EventMesh.txt_log("location_thread:ERROR:".format(e))
+                    #EventMesh.debug_log("location_thread:ERROR:{}".format(usys.print_exception(e)))
+                    EventMesh.debug_log("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(500)
+
+            #self.timer_read_GPS_info.stop()
+            #self.gps.power_switch(0)
+            wifiScan.control(0)
+            EventMesh.publish(constants.EVENT.GPSCLOSE)
+            # 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)
+            EventMesh.debug_log("CLOSE_LOCATION")
+            #EventMesh.txt_log("CLOSE_LOCATION")
 
-                
+                    
 
-class AddrBookManager(Abstract):
-    # 通讯录
-    def __init__(self):
-        self.read_phonebook = {}
-        self.check_json = 0
-        self.check_json = ql_fs.path_exists("/usr/static/storage_file/phonebook.json")
-
-        if self.check_json == True:
-            with open("/usr/static/storage_file/phonebook.json","r",encoding="utf-8") as fd:
-                self.read_phonebook = ujson.load(fd)
-                EventMesh.debug_log("读取电话本")
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("get_phonebook_list", self.get)
-        EventMesh.subscribe("set_phonebook_list", self.set)
-        EventMesh.subscribe("call_phonebook_one_call", self.call_phonebook_one_call)
-        EventMesh.subscribe("call_phonebook_two_call", self.call_phonebook_two_call)
-        EventMesh.subscribe("call_phonebook_three_call", self.call_phonebook_three_call)
-
-        EventMesh.subscribe("call_phonebook_num", self.call_phonebook_num)
-
-    def get(self, event, msg):
-        self.check_json = ql_fs.path_exists("/usr/static/storage_file/phonebook.json")
-        return [self.check_json,self.read_phonebook]
-    
-    def call_phonebook_num(self, event, msg):
-        name = ''
-        key_tmp = ''
-        phone_num = int(msg)
-        if self.read_phonebook != {}:
-            if len(self.read_phonebook) >= phone_num:
-                phonebook_keys = sorted(self.read_phonebook.keys())
-                name = self.read_phonebook[phonebook_keys[phone_num-1]]
-                key_tmp = phonebook_keys[phone_num-1]
-                if len(name) != 0:
-                    EventMesh.publish("save_phonename",str(name))
-                    EventMesh.publish("save_phonenum",str(name))
-                    EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+    class AddrBookManager(Abstract):
+        # 通讯录
+        def __init__(self):
+            self.read_phonebook = {}
+            self.check_json = 0
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/phonebook.json")
+
+            if self.check_json == True:
+                with open("/usr/static/storage_file/phonebook.json","r",encoding="utf-8") as fd:
+                    self.read_phonebook = ujson.load(fd)
+                    EventMesh.debug_log("读取电话本")
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_phonebook_list", self.get)
+            EventMesh.subscribe("set_phonebook_list", self.set)
+            EventMesh.subscribe("call_phonebook_one_call", self.call_phonebook_one_call)
+            EventMesh.subscribe("call_phonebook_two_call", self.call_phonebook_two_call)
+            EventMesh.subscribe("call_phonebook_three_call", self.call_phonebook_three_call)
+
+            EventMesh.subscribe("call_phonebook_num", self.call_phonebook_num)
+
+        def get(self, event, msg):
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/phonebook.json")
+            return [self.check_json,self.read_phonebook]
+        
+        def call_phonebook_num(self, event, msg):
+            name = ''
+            key_tmp = ''
+            phone_num = int(msg)
+            if self.read_phonebook != {}:
+                if len(self.read_phonebook) >= phone_num:
+                    phonebook_keys = sorted(self.read_phonebook.keys())
+                    name = self.read_phonebook[phonebook_keys[phone_num-1]]
+                    key_tmp = phonebook_keys[phone_num-1]
+                    if len(name) != 0:
+                        EventMesh.publish("save_phonename",str(name))
+                        EventMesh.publish("save_phonenum",str(name))
+                        EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                    else:
+                        EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
                 else:
                     EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
             else:
                 EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-        else:
-            EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-        EventMesh.debug_log("call_phonebook_call name:{} msg:{}".format(len(self.read_phonebook),msg))
-
-    def call_phonebook_one_call(self, event, msg):
-        name = ''
-        key_tmp = ''
-        if self.read_phonebook != {}:
-            if len(self.read_phonebook) >= 1:
-                phonebook_keys = sorted(self.read_phonebook.keys())
-                name = self.read_phonebook[phonebook_keys[0]]
-                key_tmp = phonebook_keys[0]
-                if len(name) != 0:
-                    EventMesh.publish("save_phonename",str(name))
-                    EventMesh.publish("save_phonenum",str(name))
-                    EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+            EventMesh.debug_log("call_phonebook_call name:{} msg:{}".format(len(self.read_phonebook),msg))
+
+        def call_phonebook_one_call(self, event, msg):
+            name = ''
+            key_tmp = ''
+            if self.read_phonebook != {}:
+                if len(self.read_phonebook) >= 1:
+                    phonebook_keys = sorted(self.read_phonebook.keys())
+                    name = self.read_phonebook[phonebook_keys[0]]
+                    key_tmp = phonebook_keys[0]
+                    if len(name) != 0:
+                        EventMesh.publish("save_phonename",str(name))
+                        EventMesh.publish("save_phonenum",str(name))
+                        EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                    else:
+                        EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
                 else:
                     EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
             else:
                 EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-        else:
-            EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-        EventMesh.debug_log("call_phonebook_one_call name:{} key_tmp:{} len:{}".format(name,key_tmp,len(self.read_phonebook)))
-
-    def call_phonebook_two_call(self, event, msg):
-        name = ''
-        key_tmp = ''
-        if self.read_phonebook != {}:
-            if len(self.read_phonebook) >= 2:
-                phonebook_keys = sorted(self.read_phonebook.keys())
-                name = self.read_phonebook[phonebook_keys[1]]
-                key_tmp = phonebook_keys[1]
-                if len(name) != 0:
-                    #voiceCall.callStart(str(name))
-                    EventMesh.publish("save_phonename",str(name))
-                    EventMesh.publish("save_phonenum",str(name))
-                    EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+            EventMesh.debug_log("call_phonebook_one_call name:{} key_tmp:{} len:{}".format(name,key_tmp,len(self.read_phonebook)))
+
+        def call_phonebook_two_call(self, event, msg):
+            name = ''
+            key_tmp = ''
+            if self.read_phonebook != {}:
+                if len(self.read_phonebook) >= 2:
+                    phonebook_keys = sorted(self.read_phonebook.keys())
+                    name = self.read_phonebook[phonebook_keys[1]]
+                    key_tmp = phonebook_keys[1]
+                    if len(name) != 0:
+                        #voiceCall.callStart(str(name))
+                        EventMesh.publish("save_phonename",str(name))
+                        EventMesh.publish("save_phonenum",str(name))
+                        EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                    else:
+                        EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+                    
                 else:
                     EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-                
             else:
                 EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-        else:
-            EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-            EventMesh.debug_log("call_phonebook_two_call name:{} key_tmp:{}".format(name,key_tmp))
-    
-    def call_phonebook_three_call(self, event, msg):
-        name = ''
-        key_tmp = ''
-        if self.read_phonebook != {}:
-            if len(self.read_phonebook) >= 3:
-                phonebook_keys = sorted(self.read_phonebook.keys())
-                name = self.read_phonebook[phonebook_keys[2]]
-                key_tmp = phonebook_keys[2]
-                if len(name) != 0:
-                    #voiceCall.callStart(str(name))
-                    EventMesh.publish("save_phonename",str(name))
-                    EventMesh.publish("save_phonenum",str(name))
-                    EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                EventMesh.debug_log("call_phonebook_two_call name:{} key_tmp:{}".format(name,key_tmp))
+        
+        def call_phonebook_three_call(self, event, msg):
+            name = ''
+            key_tmp = ''
+            if self.read_phonebook != {}:
+                if len(self.read_phonebook) >= 3:
+                    phonebook_keys = sorted(self.read_phonebook.keys())
+                    name = self.read_phonebook[phonebook_keys[2]]
+                    key_tmp = phonebook_keys[2]
+                    if len(name) != 0:
+                        #voiceCall.callStart(str(name))
+                        EventMesh.publish("save_phonename",str(name))
+                        EventMesh.publish("save_phonenum",str(name))
+                        EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                    else:
+                        EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+                    
                 else:
                     EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-                
             else:
                 EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-        else:
-            EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
-        EventMesh.debug_log("call_phonebook_three_call name:{} key_tmp:{}".format(name,key_tmp))
+            EventMesh.debug_log("call_phonebook_three_call name:{} key_tmp:{}".format(name,key_tmp))
 
-    def set(self, event, msg):
-        self.check_json = msg[0]
-        self.read_phonebook = msg[1]
+        def set(self, event, msg):
+            self.check_json = msg[0]
+            self.read_phonebook = msg[1]
 
-import sms
-class MsgManager(Abstract):
-    # 短信
-    def __init__(self):
-        self.msg_nums = 0
-        self.msg_detail = ""
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("get_msg_nums", self.get_msg_nums)
-        # 可通过此push_addr_book_list主动推送
-        EventMesh.subscribe("get_msg_detail", self.get_msg_detail)
-
-    def get_msg_nums(self, event, msg):
-
-        self.msg_nums = sms.getMsgNums() 
-        EventMesh.debug_log("self.msg_nums {}:".format(self.msg_nums))
-        return self.msg_nums
-    
-    def get_msg_detail(self, event, msg):
+    import sms
+    class MsgManager(Abstract):
+        # 短信
+        def __init__(self):
+            self.msg_nums = 0
+            self.msg_detail = ""
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_msg_nums", self.get_msg_nums)
+            # 可通过此push_addr_book_list主动推送
+            EventMesh.subscribe("get_msg_detail", self.get_msg_detail)
+
+        def get_msg_nums(self, event, msg):
+
+            self.msg_nums = sms.getMsgNums() 
+            EventMesh.debug_log("self.msg_nums {}:".format(self.msg_nums))
+            return self.msg_nums
         
-        # self.msg_detail = sms.searchTextMsg(self.msg_nums)
-        # EventMesh.debug_log("self.msg_detai {}:".format(self.msg_detai))
-        return{
-            "小明":"有内鬼,停止交易",
-            "小红":"今晚十点一起吃饭"
-        }
-
-class MsgdetailManager(Abstract):
-    def __init__(self):
-        self.level = 0
-        self.msg_name = ""
-        self.msg_content = ""
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("save_msg_name", self.save_msg_name)
-        EventMesh.subscribe("save_msg_content", self.save_msg_content)
-        EventMesh.subscribe("get_msg_name", self.get_msg_name)
-        EventMesh.subscribe("get_msg_content", self.get_msg_content)
-
-    def save_msg_name(self, event, msg): 
-        self.msg_name = str(msg)
-        EventMesh.debug_log("save_msg_name:msg".format(msg))
-    
-    def save_msg_content(self, event, msg):
-        self.msg_content = str(msg)
-        EventMesh.debug_log("save_msg_content:msg".format(msg))
-    
-    def get_msg_content(self, event, msg):
-        return self.msg_content
-
-    def get_msg_name(self, event, msg):
-        return self.msg_name
-
-class CallLogManager(Abstract):
-    # 通话记录
-    def __init__(self):
-        self.read_call_log = {}
-        self.check_json = ql_fs.path_exists("/usr/static/storage_file/Call_log.json")
-
-        if self.check_json == True:
-            with open("/usr/static/storage_file/Call_log.json","r",encoding="utf-8") as fd:
-                self.read_call_log = ujson.load(fd)
-                EventMesh.debug_log("读取通话记录")
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("get_call_log_list", self.get)
-        EventMesh.subscribe("set_call_log_list", self.set)
-
-    def get(self, event, msg):
-        self.check_json = ql_fs.path_exists("/usr/static/storage_file/Call_log.json")
-        return [self.check_json,self.read_call_log]
-
-    def set(self, event, msg):
-        return
-        self.check_json = msg[0]
-        self.read_call_log = msg[1]
-        with open("/usr/static/storage_file/Call_log.json","w+",encoding="utf-8") as fd:
-            ujson.dump(self.read_call_log,fd)
-    # def call_usr(self,event,msg):
-    #     content = self.log[msg]
-    #     # 参数1 姓名  参数2  电话   参数3 1/主动呼叫  0别人呼叫
-    #     EventMesh.publish("call_in", [content[2], content[0], 1])
-
-
-
-class PhoneCallingManager(Abstract):
-    def __init__(self):
-        self.phonenum = ""
-        self.phonename = ""
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("save_phonenum", self.save_phonenum)
-        EventMesh.subscribe("get_phonenum", self.get_phonenum)
-        EventMesh.subscribe("get_phonename", self.get_phonename)
-        EventMesh.subscribe("save_phonename", self.save_phonename)
-
-    def get_phonename(self, event, msg): 
-        return self.phonename
-
-    def save_phonename(self, event, msg): 
-        self.phonename = str(msg)
-
-    def save_phonenum(self, event, msg): 
-        self.phonenum = str(msg)
-    
-    def get_phonenum(self, event, msg):
-        return self.phonenum
-
-#获取心率 血氧 步数历史数据
-class gethistoryDataManager(Abstract):
-    def __init__(self):
-        self.oldHr = 0
-        self.oldspo2 = 0
-        self.oldstep = 0
-        self.old_step = 0
-        self.read_histroy_hr_data = []
-        self.read_histroy_temp_data = []
-        self.read_histroy_spo2_data = []
-
-        oldHr  = EventMesh.publish("get_storage_config","old_hr")
-        if oldHr != None:
-            self.oldHr = oldHr  
-        old_spo2  = EventMesh.publish("get_storage_config","old_spo2")
-        if old_spo2 != None:
-            self.oldspo2 = old_spo2 
-        old_step  = EventMesh.publish("get_storage_config","old_step")    
-        if old_step != None:
-            self.oldstep = old_step
-
-
-        check_hr= ql_fs.path_exists("/usr/static/storage_file/history_hr.json")
-        if check_hr == True :
-            with open("/usr/static/storage_file/history_hr.json","r") as fd:#音频文件编号
-                self.read_histroy_hr_data = ujson.load(fd)
+        def get_msg_detail(self, event, msg):
+            
+            # self.msg_detail = sms.searchTextMsg(self.msg_nums)
+            # EventMesh.debug_log("self.msg_detai {}:".format(self.msg_detai))
+            return{
+                "小明":"有内鬼,停止交易",
+                "小红":"今晚十点一起吃饭"
+            }
+
+    class MsgdetailManager(Abstract):
+        def __init__(self):
+            self.level = 0
+            self.msg_name = ""
+            self.msg_content = ""
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("save_msg_name", self.save_msg_name)
+            EventMesh.subscribe("save_msg_content", self.save_msg_content)
+            EventMesh.subscribe("get_msg_name", self.get_msg_name)
+            EventMesh.subscribe("get_msg_content", self.get_msg_content)
+
+        def save_msg_name(self, event, msg): 
+            self.msg_name = str(msg)
+            EventMesh.debug_log("save_msg_name:msg".format(msg))
         
-        check_temp= ql_fs.path_exists("/usr/static/storage_file/history_temp.json")
-        if check_temp == True :
-            with open("/usr/static/storage_file/history_temp.json","r") as fd:#音频文件编号
-                self.read_histroy_temp_data = ujson.load(fd)
-
-        check_spo2= ql_fs.path_exists("/usr/static/storage_file/history_spo2.json")
-        if check_spo2 == True :
-            with open("/usr/static/storage_file/history_spo2.json","r") as fd:#音频文件编号
-                self.read_histroy_spo2_data = ujson.load(fd)
-        self.temp_value = 0
+        def save_msg_content(self, event, msg):
+            self.msg_content = str(msg)
+            EventMesh.debug_log("save_msg_content:msg".format(msg))
         
-        # self.read_histroy_hr_data=[{"timeSec":16789890,"value":90},{"timeSec":16789888,"value":78},{"timeSec":16789688,"value":68},{"timeSec":16789898,"value":58},\
-        #                              {"timeSec":16789897,"value":88},{"timeSec":16789867,"value":77},{"timeSec":16789895,"value":70}]
+        def get_msg_content(self, event, msg):
+            return self.msg_content
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_old_hr_data", self.save_hr_value)
-        EventMesh.subscribe("get_old_hr_data", self.get_hr_value)
-        EventMesh.subscribe("set_old_spo2_data", self.save_spo2_value)
-        EventMesh.subscribe("get_old_spo2_data", self.get_spo2_value)
+        def get_msg_name(self, event, msg):
+            return self.msg_name
 
-        EventMesh.subscribe("get_old_step_value", self.get_old_step_value)
-        EventMesh.subscribe("set_old_step_value", self.set_old_step_value)
+    class CallLogManager(Abstract):
+        # 通话记录
+        def __init__(self):
+            self.read_call_log = {}
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/Call_log.json")
 
+            if self.check_json == True:
+                with open("/usr/static/storage_file/Call_log.json","r",encoding="utf-8") as fd:
+                    self.read_call_log = ujson.load(fd)
+                    EventMesh.debug_log("读取通话记录")
 
-        EventMesh.subscribe("get_history_hr_value", self.get_history_hr_value)
-        EventMesh.subscribe("set_history_hr_value", self.set_history_hr_value)
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_call_log_list", self.get)
+            EventMesh.subscribe("set_call_log_list", self.set)
 
-        EventMesh.subscribe("get_history_temp_value", self.get_history_temp_value)
-        EventMesh.subscribe("set_history_temp_value", self.set_history_temp_value)
+        def get(self, event, msg):
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/Call_log.json")
+            return [self.check_json,self.read_call_log]
 
-        EventMesh.subscribe("get_history_spo2_value", self.get_history_spo2_value)
-        EventMesh.subscribe("set_history_spo2_value", self.set_history_spo2_value)
+        def set(self, event, msg):
+            return
+            self.check_json = msg[0]
+            self.read_call_log = msg[1]
+            with open("/usr/static/storage_file/Call_log.json","w+",encoding="utf-8") as fd:
+                ujson.dump(self.read_call_log,fd)
+        # def call_usr(self,event,msg):
+        #     content = self.log[msg]
+        #     # 参数1 姓名  参数2  电话   参数3 1/主动呼叫  0别人呼叫
+        #     EventMesh.publish("call_in", [content[2], content[0], 1])
 
-       
 
-    def get_history_spo2_value(self, event, msg): #近7次血氧历史数据统计显示
-        return self.read_histroy_spo2_data
 
-    def set_history_spo2_value(self, event, msg): 
-        pass
+    class PhoneCallingManager(Abstract):
+        def __init__(self):
+            self.phonenum = ""
+            self.phonename = ""
 
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("save_phonenum", self.save_phonenum)
+            EventMesh.subscribe("get_phonenum", self.get_phonenum)
+            EventMesh.subscribe("get_phonename", self.get_phonename)
+            EventMesh.subscribe("save_phonename", self.save_phonename)
 
+        def get_phonename(self, event, msg): 
+            return self.phonename
 
-    def get_history_temp_value(self, event, msg): #近7次体温历史数据统计显示
-        return self.read_histroy_temp_data
+        def save_phonename(self, event, msg): 
+            self.phonename = str(msg)
 
-    def set_history_temp_value(self, event, msg): 
-        self.temp_value = msg
-        if self.temp_value > 0:
-            # date_tmp = utime.localtime()
-            # time_tmp = utime.mktime(date_tmp)
-            # if len(self.read_histroy_temp_data) >= 7:
-            #     sort_new = {}
-            #     sort_new = sorted(self.read_histroy_temp_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
-            #     EventMesh.debug_log(sort_new)
-            #     for i in range(len(self.read_histroy_temp_data)-1):
-            #         sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
-            #         self.read_histroy_temp_data[i] = sort_new[i]
-            #         pass
-            #     self.read_histroy_temp_data[6] = {"timeSec": time_tmp, "temp": self.temp_value}
-            # else:
-            #     self.read_histroy_temp_data.append({"timeSec": time_tmp, "temp": self.temp_value}) 
+        def save_phonenum(self, event, msg): 
+            self.phonenum = str(msg)
+        
+        def get_phonenum(self, event, msg):
+            return self.phonenum
+
+    #获取心率 血氧 步数历史数据
+    class gethistoryDataManager(Abstract):
+        def __init__(self):
+            self.oldHr = 0
+            self.oldspo2 = 0
+            self.oldstep = 0
+            self.old_step = 0
+            self.read_histroy_hr_data = []
+            self.read_histroy_temp_data = []
+            self.read_histroy_spo2_data = []
+
+            oldHr  = EventMesh.publish("get_storage_config","old_hr")
+            if oldHr != None:
+                self.oldHr = oldHr  
+            old_spo2  = EventMesh.publish("get_storage_config","old_spo2")
+            if old_spo2 != None:
+                self.oldspo2 = old_spo2 
+            old_step  = EventMesh.publish("get_storage_config","old_step")    
+            if old_step != None:
+                self.oldstep = old_step
+
+
+            check_hr= ql_fs.path_exists("/usr/static/storage_file/history_hr.json")
+            if check_hr == True :
+                with open("/usr/static/storage_file/history_hr.json","r") as fd:#音频文件编号
+                    self.read_histroy_hr_data = ujson.load(fd)
+            
+            check_temp= ql_fs.path_exists("/usr/static/storage_file/history_temp.json")
+            if check_temp == True :
+                with open("/usr/static/storage_file/history_temp.json","r") as fd:#音频文件编号
+                    self.read_histroy_temp_data = ujson.load(fd)
+
+            check_spo2= ql_fs.path_exists("/usr/static/storage_file/history_spo2.json")
+            if check_spo2 == True :
+                with open("/usr/static/storage_file/history_spo2.json","r") as fd:#音频文件编号
+                    self.read_histroy_spo2_data = ujson.load(fd)
+            self.temp_value = 0
+            
+            # self.read_histroy_hr_data=[{"timeSec":16789890,"value":90},{"timeSec":16789888,"value":78},{"timeSec":16789688,"value":68},{"timeSec":16789898,"value":58},\
+            #                              {"timeSec":16789897,"value":88},{"timeSec":16789867,"value":77},{"timeSec":16789895,"value":70}]
 
-            # with open("/usr/static/storage_file/history_temp.json","w",encoding="utf-8") as fd:
-            #     ujson.dump(self.read_histroy_temp_data,fd)
-            #EventMesh.debug_log(self.read_histroy_temp_data)
-            pass
-        else:
-            pass
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_old_hr_data", self.save_hr_value)
+            EventMesh.subscribe("get_old_hr_data", self.get_hr_value)
+            EventMesh.subscribe("set_old_spo2_data", self.save_spo2_value)
+            EventMesh.subscribe("get_old_spo2_data", self.get_spo2_value)
 
-    def get_history_hr_value(self, event, msg): #近7次心率历史数据统计显示
-        return self.read_histroy_hr_data
+            EventMesh.subscribe("get_old_step_value", self.get_old_step_value)
+            EventMesh.subscribe("set_old_step_value", self.set_old_step_value)
 
-    def set_history_hr_value(self, event, msg): 
-        pass
-            
-           
 
-    def save_hr_value(self, event, msg): 
-        if msg >= 50:
-            EventMesh.publish("set_storage_config",["old_hr",msg])
-            self.oldHr = msg
-            
+            EventMesh.subscribe("get_history_hr_value", self.get_history_hr_value)
+            EventMesh.subscribe("set_history_hr_value", self.set_history_hr_value)
 
-            date_tmp = utime.localtime()
-            time_tmp = utime.mktime(date_tmp)
-            if len(self.read_histroy_hr_data) >= 7:
-                sort_new = {}
-                sort_new = sorted(self.read_histroy_hr_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
-                EventMesh.debug_log(sort_new)
-                for i in range(len(self.read_histroy_hr_data)-1):
-                    sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
-                    self.read_histroy_hr_data[i] = sort_new[i]
-                    pass
-                self.read_histroy_hr_data[6] = {"timeSec": time_tmp, "hr": self.oldHr}
-            else:
-                self.read_histroy_hr_data.append({"timeSec": time_tmp, "hr": self.oldHr}) 
+            EventMesh.subscribe("get_history_temp_value", self.get_history_temp_value)
+            EventMesh.subscribe("set_history_temp_value", self.set_history_temp_value)
+
+            EventMesh.subscribe("get_history_spo2_value", self.get_history_spo2_value)
+            EventMesh.subscribe("set_history_spo2_value", self.set_history_spo2_value)
+
+        
 
+        def get_history_spo2_value(self, event, msg): #近7次血氧历史数据统计显示
+            return self.read_histroy_spo2_data
 
-            with open("/usr/static/storage_file/history_hr.json","w",encoding="utf-8") as fd:
-                ujson.dump(self.read_histroy_hr_data,fd)
+        def set_history_spo2_value(self, event, msg): 
             pass
-        else:
-            EventMesh.publish("set_storage_config",["old_hr",msg])
+
+
+
+        def get_history_temp_value(self, event, msg): #近7次体温历史数据统计显示
+            return self.read_histroy_temp_data
+
+        def set_history_temp_value(self, event, msg): 
+            self.temp_value = msg
+            if self.temp_value > 0:
+                # date_tmp = utime.localtime()
+                # time_tmp = utime.mktime(date_tmp)
+                # if len(self.read_histroy_temp_data) >= 7:
+                #     sort_new = {}
+                #     sort_new = sorted(self.read_histroy_temp_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
+                #     EventMesh.debug_log(sort_new)
+                #     for i in range(len(self.read_histroy_temp_data)-1):
+                #         sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
+                #         self.read_histroy_temp_data[i] = sort_new[i]
+                #         pass
+                #     self.read_histroy_temp_data[6] = {"timeSec": time_tmp, "temp": self.temp_value}
+                # else:
+                #     self.read_histroy_temp_data.append({"timeSec": time_tmp, "temp": self.temp_value}) 
+
+                # with open("/usr/static/storage_file/history_temp.json","w",encoding="utf-8") as fd:
+                #     ujson.dump(self.read_histroy_temp_data,fd)
+                #EventMesh.debug_log(self.read_histroy_temp_data)
+                pass
+            else:
+                pass
+
+        def get_history_hr_value(self, event, msg): #近7次心率历史数据统计显示
+            return self.read_histroy_hr_data
+
+        def set_history_hr_value(self, event, msg): 
             pass
+                
+            
 
+        def save_hr_value(self, event, msg): 
+            if msg >= 50:
+                EventMesh.publish("set_storage_config",["old_hr",msg])
+                self.oldHr = msg
+                
 
-    def get_hr_value(self, event, msg): 
-        return self.oldHr
+                date_tmp = utime.localtime()
+                time_tmp = utime.mktime(date_tmp)
+                if len(self.read_histroy_hr_data) >= 7:
+                    sort_new = {}
+                    sort_new = sorted(self.read_histroy_hr_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
+                    EventMesh.debug_log(sort_new)
+                    for i in range(len(self.read_histroy_hr_data)-1):
+                        sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
+                        self.read_histroy_hr_data[i] = sort_new[i]
+                        pass
+                    self.read_histroy_hr_data[6] = {"timeSec": time_tmp, "hr": self.oldHr}
+                else:
+                    self.read_histroy_hr_data.append({"timeSec": time_tmp, "hr": self.oldHr}) 
 
-    def save_spo2_value(self, event, msg): 
-        if msg >= 85:
-            # EventMesh.publish("set_storage_config",["old_spo2",msg])
-            # self.oldspo2 = msg
 
+                with open("/usr/static/storage_file/history_hr.json","w",encoding="utf-8") as fd:
+                    ujson.dump(self.read_histroy_hr_data,fd)
+                pass
+            else:
+                EventMesh.publish("set_storage_config",["old_hr",msg])
+                pass
 
-            # date_tmp = utime.localtime()
-            # time_tmp = utime.mktime(date_tmp)
-            # if len(self.read_histroy_spo2_data) >= 7:
-            #     sort_new = {}
-            #     sort_new = sorted(self.read_histroy_spo2_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
-            #     EventMesh.debug_log(sort_new)
-            #     for i in range(len(self.read_histroy_spo2_data)-1):
-            #         sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
-            #         self.read_histroy_spo2_data[i] = sort_new[i]
-            #         pass
-            #     self.read_histroy_spo2_data[6] = {"timeSec": time_tmp, "spo2": self.oldspo2}
-            # else:
-            #     self.read_histroy_spo2_data.append({"timeSec": time_tmp, "spo2": self.oldspo2}) 
 
-            # with open("/usr/static/storage_file/history_spo2.json","w",encoding="utf-8") as fd:
-            #     ujson.dump(self.read_histroy_spo2_data,fd)
-            # #EventMesh.debug_log(self.read_histroy_spo2_data)
-            #播放语音
-            # EventMesh.publish("set_hr_blood_led",2)#测量成功
-            pass
-        else:
-            pass
-            pass
+        def get_hr_value(self, event, msg): 
+            return self.oldHr
+
+        def save_spo2_value(self, event, msg): 
+            if msg >= 85:
+                # EventMesh.publish("set_storage_config",["old_spo2",msg])
+                # self.oldspo2 = msg
+
+
+                # date_tmp = utime.localtime()
+                # time_tmp = utime.mktime(date_tmp)
+                # if len(self.read_histroy_spo2_data) >= 7:
+                #     sort_new = {}
+                #     sort_new = sorted(self.read_histroy_spo2_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
+                #     EventMesh.debug_log(sort_new)
+                #     for i in range(len(self.read_histroy_spo2_data)-1):
+                #         sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
+                #         self.read_histroy_spo2_data[i] = sort_new[i]
+                #         pass
+                #     self.read_histroy_spo2_data[6] = {"timeSec": time_tmp, "spo2": self.oldspo2}
+                # else:
+                #     self.read_histroy_spo2_data.append({"timeSec": time_tmp, "spo2": self.oldspo2}) 
+
+                # with open("/usr/static/storage_file/history_spo2.json","w",encoding="utf-8") as fd:
+                #     ujson.dump(self.read_histroy_spo2_data,fd)
+                # #EventMesh.debug_log(self.read_histroy_spo2_data)
+                #播放语音
+                # EventMesh.publish("set_hr_blood_led",2)#测量成功
+                pass
+            else:
+                pass
+                pass
 
-    def get_spo2_value(self, event, msg): 
-        return self.oldspo2
-    
-    def set_old_step_value(self, event, msg): 
-        self.oldstep = msg
-        EventMesh.publish("set_storage_config",["old_step",msg])
-        
+        def get_spo2_value(self, event, msg): 
+            return self.oldspo2
         
-    def get_old_step_value(self, event, msg): 
-        step = EventMesh.publish(constants.EVENT.GET_STEP)
-        self.old_step = self.oldstep + step[0]
-        return self.old_step
-#获取旧的时间戳
-class getOldTimeManager(Abstract):
-    # 获取天气数据
-    def __init__(self):
-        self.time_sec = 0
-        self.time_step = 0
-        self.step_second = 0
-        tmp_data = EventMesh.publish("get_storage_config","old_time")
-        if tmp_data !=None :
-            self.time_sec = tmp_data
-        tmp_data = EventMesh.publish("get_storage_config","clear_state")
-        if tmp_data !=None :
-            self.time_step = tmp_data[0]
-            self.step_second = tmp_data[1]
+        def set_old_step_value(self, event, msg): 
+            self.oldstep = msg
+            EventMesh.publish("set_storage_config",["old_step",msg])
+            
+            
+        def get_old_step_value(self, event, msg): 
+            step = EventMesh.publish(constants.EVENT.GET_STEP)
+            self.old_step = self.oldstep + step[0]
+            return self.old_step
+    #获取旧的时间戳
+    class getOldTimeManager(Abstract):
+        # 获取天气数据
+        def __init__(self):
+            self.time_sec = 0
+            self.time_step = 0
+            self.step_second = 0
+            tmp_data = EventMesh.publish("get_storage_config","old_time")
+            if tmp_data !=None :
+                self.time_sec = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","clear_state")
+            if tmp_data !=None :
+                self.time_step = tmp_data[0]
+                self.step_second = tmp_data[1]
 
-        
-          
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("get_old_time_data", self.get_old_time_data)
-        EventMesh.subscribe("set_old_time_data", self.set_old_time_data)
+            
+            
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_old_time_data", self.get_old_time_data)
+            EventMesh.subscribe("set_old_time_data", self.set_old_time_data)
 
-        EventMesh.subscribe("get_old_step_data", self.get_old_step_data)
-        EventMesh.subscribe("set_old_step_data", self.set_old_step_data)
+            EventMesh.subscribe("get_old_step_data", self.get_old_step_data)
+            EventMesh.subscribe("set_old_step_data", self.set_old_step_data)
 
-        EventMesh.subscribe("set_test_data1", self.set_test_data1)
+            EventMesh.subscribe("set_test_data1", self.set_test_data1)
 
-        EventMesh.subscribe("set_test_data2", self.set_test_data2)
+            EventMesh.subscribe("set_test_data2", self.set_test_data2)
 
-        EventMesh.subscribe("set_test_data3", self.set_test_data3)
+            EventMesh.subscribe("set_test_data3", self.set_test_data3)
 
-        EventMesh.subscribe("set_test_data4", self.set_test_data4)
+            EventMesh.subscribe("set_test_data4", self.set_test_data4)
 
-        EventMesh.subscribe("set_test_data5", self.set_test_data5)
+            EventMesh.subscribe("set_test_data5", self.set_test_data5)
 
-        EventMesh.subscribe("set_test_data6", self.set_test_data6)
+            EventMesh.subscribe("set_test_data6", self.set_test_data6)
 
-        EventMesh.subscribe("set_test_data7", self.set_test_data7)
+            EventMesh.subscribe("set_test_data7", self.set_test_data7)
 
-        EventMesh.subscribe("set_test_data8", self.set_test_data8)
-       
+            EventMesh.subscribe("set_test_data8", self.set_test_data8)
+        
 
-    def set_test_data1(self, event, msg):
-        EventMesh.publish("set_storage_config",["clear_state1",msg])
+        def set_test_data1(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state1",msg])
 
-    
-    def set_test_data2(self, event, msg):
         
-        EventMesh.publish("set_storage_config",["clear_state2",msg])
+        def set_test_data2(self, event, msg):
+            
+            EventMesh.publish("set_storage_config",["clear_state2",msg])
 
 
-    def set_test_data3(self, event, msg):
-        EventMesh.publish("set_storage_config",["clear_state3",msg])
+        def set_test_data3(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state3",msg])
 
-    def set_test_data4(self, event, msg):
-        EventMesh.publish("set_storage_config",["clear_state4",msg])
+        def set_test_data4(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state4",msg])
 
-    def set_test_data5(self, event, msg):
-        EventMesh.publish("set_storage_config",["clear_state5",msg])
+        def set_test_data5(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state5",msg])
 
-    def set_test_data6(self, event, msg):
-        EventMesh.publish("set_storage_config",["clear_state6",msg])
+        def set_test_data6(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state6",msg])
 
-    def set_test_data7(self, event, msg):
-        EventMesh.publish("set_storage_config",["clear_state7",msg])
+        def set_test_data7(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state7",msg])
 
-    def set_test_data8(self, event, msg):
-        EventMesh.publish("set_storage_config",["clear_state8",msg])
+        def set_test_data8(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state8",msg])
 
-    # f = open("/usr/static/storage_file/config.json",'r',encoding="utf-8")
-    # print(f.read())
+        # f = open("/usr/static/storage_file/config.json",'r',encoding="utf-8")
+        # print(f.read())
 
-    def get_old_step_data(self, event, msg):
-        return [self.time_step,self.step_second]
+        def get_old_step_data(self, event, msg):
+            return [self.time_step,self.step_second]
 
-    def get_old_time_data(self, event, msg):
-        return self.time_sec
-    
-    
+        def get_old_time_data(self, event, msg):
+            return self.time_sec
+        
+        
 
-    def set_old_time_data(self, event, msg):
-        self.time_sec = msg
-        EventMesh.publish("set_storage_config",["old_time",msg])
+        def set_old_time_data(self, event, msg):
+            self.time_sec = msg
+            EventMesh.publish("set_storage_config",["old_time",msg])
 
-    def set_old_step_data(self, event, msg):
-        self.time_step = msg[0]
-        self.step_second = msg[1]
-        EventMesh.publish("set_storage_config",["clear_state",msg])
+        def set_old_step_data(self, event, msg):
+            self.time_step = msg[0]
+            self.step_second = msg[1]
+            EventMesh.publish("set_storage_config",["clear_state",msg])
 
-    def get_old_step_data(self, event, msg):
-        return [self.time_step,self.step_second]
+        def get_old_step_data(self, event, msg):
+            return [self.time_step,self.step_second]
 
 
+            
         
-    
 
-class getWeatherDataManager(Abstract):
-    # 获取天气数据
-    def __init__(self):
-        self.date = {} #日期23-04-07
-        self.time = {} #14:41:41
-        self.content = {} #天气描述 
-        self.type = None #天气类型
-        self.temp = None #当前温度
-        self.min_temp = None #最低温度
-        self.max_temp = None #最高温度
-        self.city = {} #城市
-        self.no_data = 0#0沒有数据 1有数据
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("get_weather_data", self.get)
-        EventMesh.subscribe("set_weather_data", self.set)
-
-    def get(self, event, msg):
-        return [self.date,self.time,self.content,self.type,self.temp,self.min_temp,self.max_temp,self.city,self.no_data]
-
-    def set(self, event, msg):
-        self.date = msg[0]
-        self.time = msg[1]
-        self.content = msg[2]
-        self.type = msg[3]
-        self.temp = msg[4]
-        self.min_temp = msg[5]
-        self.max_temp = msg[6]
-        self.city = msg[7]
-        self.no_data = msg[8]
-
-
-class getHrTimeManager(Abstract):
-    def __init__(self):
-        self.set_time = 0
-        self.set_hr = 0 #0关闭 1手动 2 自动测量按照时间间隔测试心率
-        self.set_spo2 = 0
-        self.open_btn = 0
-        self.set_bgautotime = 0
-        self.bgauto_btn = 0
-        read_data = EventMesh.publish("get_storage_config","measure_time")
-        if read_data != None:
-            self.set_time = read_data  
-        read_data = EventMesh.publish("get_storage_config","open_hr_btn")
-                
-        if read_data != None:
-            self.open_btn = read_data   
+    class getWeatherDataManager(Abstract):
+        # 获取天气数据
+        def __init__(self):
+            self.date = {} #日期23-04-07
+            self.time = {} #14:41:41
+            self.content = {} #天气描述 
+            self.type = None #天气类型
+            self.temp = None #当前温度
+            self.min_temp = None #最低温度
+            self.max_temp = None #最高温度
+            self.city = {} #城市
+            self.no_data = 0#0沒有数据 1有数据
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_weather_data", self.get)
+            EventMesh.subscribe("set_weather_data", self.set)
+
+        def get(self, event, msg):
+            return [self.date,self.time,self.content,self.type,self.temp,self.min_temp,self.max_temp,self.city,self.no_data]
+
+        def set(self, event, msg):
+            self.date = msg[0]
+            self.time = msg[1]
+            self.content = msg[2]
+            self.type = msg[3]
+            self.temp = msg[4]
+            self.min_temp = msg[5]
+            self.max_temp = msg[6]
+            self.city = msg[7]
+            self.no_data = msg[8]
+
+
+    class getHrTimeManager(Abstract):
+        def __init__(self):
+            self.set_time = 0
+            self.set_hr = 0 #0关闭 1手动 2 自动测量按照时间间隔测试心率
+            self.set_spo2 = 0
+            self.open_btn = 0
+            self.set_bgautotime = 0
+            self.bgauto_btn = 0
+            read_data = EventMesh.publish("get_storage_config","measure_time")
+            if read_data != None:
+                self.set_time = read_data  
+            read_data = EventMesh.publish("get_storage_config","open_hr_btn")
+                    
+            if read_data != None:
+                self.open_btn = read_data   
 
-        read_data = EventMesh.publish("get_storage_config","bgauto_time")
-        if read_data != None:
-            self.set_bgautotime = read_data  
-        read_data = EventMesh.publish("get_storage_config","bgauto_btn")
-                
-        if read_data != None:
-            self.bgauto_btn = read_data   
+            read_data = EventMesh.publish("get_storage_config","bgauto_time")
+            if read_data != None:
+                self.set_bgautotime = read_data  
+            read_data = EventMesh.publish("get_storage_config","bgauto_btn")
+                    
+            if read_data != None:
+                self.bgauto_btn = read_data   
+
+
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_time_hr", self.set_time_hr)
+            EventMesh.subscribe("get_time_hr", self.get_time_hr)
+            EventMesh.subscribe("set_hr_state", self.set_hr_state)
+            EventMesh.subscribe("get_hr_state", self.get_hr_state)
+            EventMesh.subscribe("set_spo2_state", self.set_spo2_state)
+            EventMesh.subscribe("get_spo2_state", self.get_spo2_state)
+
+            EventMesh.subscribe("set_bgauto_time", self.set_bgauto_time)
+            EventMesh.subscribe("get_bgauto_time", self.get_bgauto_time)
+
+        def set_bgauto_time(self, event, msg): 
+            self.bgauto_btn = msg[0]
+            self.set_bgautotime = msg[1]
+            EventMesh.publish("set_storage_config",["bgauto_btn",self.bgauto_btn])
+            EventMesh.publish("set_storage_config",["bgauto_time",self.set_bgautotime])
+
+        def get_bgauto_time(self, event, msg): 
+            if self.bgauto_btn == None:
+                self.bgauto_btn = 0
+            if self.set_bgautotime == None:
+                self.set_bgautotime = 0
+            return [self.bgauto_btn,self.set_bgautotime]
+        
 
+        def set_time_hr(self, event, msg): 
+            self.open_btn = msg[0]
+            self.set_time = msg[1]
+            EventMesh.publish("set_storage_config",["measure_time",self.set_time])
+            EventMesh.publish("set_storage_config",["open_hr_btn",self.open_btn])
+
+        def get_time_hr(self, event, msg): 
+            return [self.open_btn,self.set_time]
+
+        def set_hr_state(self, event, msg): 
+            # if msg != 0:
+            #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
+            self.set_hr = msg
+            if self.set_hr == 0:
+                EventMesh.publish("clear_health_state")
+            
 
+        def get_hr_state(self, event, msg): 
+            return self.set_hr
+        
+        def set_spo2_state(self, event, msg): 
+            # if msg != 0:
+            #     EventMesh.publish("set_hr_blood_led",1)##红绿灯交替闪烁
+            self.set_spo2 = msg
+            if self.set_spo2 == 0:
+                EventMesh.publish("clear_health_state")
+            
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_time_hr", self.set_time_hr)
-        EventMesh.subscribe("get_time_hr", self.get_time_hr)
-        EventMesh.subscribe("set_hr_state", self.set_hr_state)
-        EventMesh.subscribe("get_hr_state", self.get_hr_state)
-        EventMesh.subscribe("set_spo2_state", self.set_spo2_state)
-        EventMesh.subscribe("get_spo2_state", self.get_spo2_state)
+        def get_spo2_state(self, event, msg): 
+            return self.set_spo2
+        
+    #体温
+    class getTempTimeManager(Abstract):
+        def __init__(self):
+            self.set_time = 0
+            self.get_temp = 0
+            read_data = EventMesh.publish("get_storage_config","temp_time")
 
-        EventMesh.subscribe("set_bgauto_time", self.set_bgauto_time)
-        EventMesh.subscribe("get_bgauto_time", self.get_bgauto_time)
+            if read_data != None:
+                self.set_time = read_data
 
-    def set_bgauto_time(self, event, msg): 
-        self.bgauto_btn = msg[0]
-        self.set_bgautotime = msg[1]
-        EventMesh.publish("set_storage_config",["bgauto_btn",self.bgauto_btn])
-        EventMesh.publish("set_storage_config",["bgauto_time",self.set_bgautotime])
+            self.get_bgstate = 0
+            self.get_bpstate = 0
 
-    def get_bgauto_time(self, event, msg): 
-        if self.bgauto_btn == None:
-            self.bgauto_btn = 0
-        if self.set_bgautotime == None:
-            self.set_bgautotime = 0
-        return [self.bgauto_btn,self.set_bgautotime]
-    
+            self.bptime_on = 0
+            self.bptime_time = 0
+            read_data=EventMesh.publish("get_storage_config","bpauto_btn")
+            if read_data != None:
+                self.bptime_on = read_data
 
-    def set_time_hr(self, event, msg): 
-        self.open_btn = msg[0]
-        self.set_time = msg[1]
-        EventMesh.publish("set_storage_config",["measure_time",self.set_time])
-        EventMesh.publish("set_storage_config",["open_hr_btn",self.open_btn])
-
-    def get_time_hr(self, event, msg): 
-        return [self.open_btn,self.set_time]
-
-    def set_hr_state(self, event, msg): 
-        # if msg != 0:
-        #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
-        self.set_hr = msg
-        if self.set_hr == 0:
-            EventMesh.publish("clear_health_state")
-        
+            EventMesh.publish("get_storage_config","bpauto_time")
+            if read_data != None:
+                self.bptime_time = read_data
 
-    def get_hr_state(self, event, msg): 
-        return self.set_hr
-    
-    def set_spo2_state(self, event, msg): 
-        # if msg != 0:
-        #     EventMesh.publish("set_hr_blood_led",1)##红绿灯交替闪烁
-        self.set_spo2 = msg
-        if self.set_spo2 == 0:
-            EventMesh.publish("clear_health_state")
-        
+            self.spo2time_on = 0
+            self.spo2time_time = 0
+            read_data = EventMesh.publish("get_storage_config","spo2auto_btn")
+            if read_data != None:
+                self.spo2time_on = read_data
 
-    def get_spo2_state(self, event, msg): 
-        return self.set_spo2
-    
-#体温
-class getTempTimeManager(Abstract):
-    def __init__(self):
-        self.set_time = 0
-        self.get_temp = 0
-        read_data = EventMesh.publish("get_storage_config","temp_time")
+            read_data = EventMesh.publish("get_storage_config","spo2auto_time")
+            if read_data != None:
+                self.spo2time_time = read_data
 
-        if read_data != None:
-            self.set_time = read_data
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_temp_time", self.set_temp_time)
+            EventMesh.subscribe("get_temp_time", self.get_temp_time)
 
-        self.get_bgstate = 0
-        self.get_bpstate = 0
+            EventMesh.subscribe("set_temp_state", self.set_temp_state)
+            EventMesh.subscribe("get_temp_state", self.get_temp_state)
 
-        self.bptime_on = 0
-        self.bptime_time = 0
-        read_data=EventMesh.publish("get_storage_config","bpauto_btn")
-        if read_data != None:
-            self.bptime_on = read_data
+            EventMesh.subscribe("set_bp_time", self.set_bp_time)
+            EventMesh.subscribe("get_bp_time", self.get_bp_time)
 
-        EventMesh.publish("get_storage_config","bpauto_time")
-        if read_data != None:
-            self.bptime_time = read_data
+            EventMesh.subscribe("set_bp_state", self.set_bp_state)
+            EventMesh.subscribe("get_bp_state", self.get_bp_state)
 
-        self.spo2time_on = 0
-        self.spo2time_time = 0
-        read_data = EventMesh.publish("get_storage_config","spo2auto_btn")
-        if read_data != None:
-            self.spo2time_on = read_data
 
-        read_data = EventMesh.publish("get_storage_config","spo2auto_time")
-        if read_data != None:
-            self.spo2time_time = read_data
+            EventMesh.subscribe("set_bg_state", self.set_bg_state)
+            EventMesh.subscribe("get_bg_state", self.get_bg_state)
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_temp_time", self.set_temp_time)
-        EventMesh.subscribe("get_temp_time", self.get_temp_time)
+            EventMesh.subscribe("set_spo2_time", self.set_spo2_time)
+            EventMesh.subscribe("get_spo2_time", self.get_spo2_time)
 
-        EventMesh.subscribe("set_temp_state", self.set_temp_state)
-        EventMesh.subscribe("get_temp_state", self.get_temp_state)
+            
+        def set_bg_state(self, event, msg): 
+            self.get_bgstate = msg
+            if self.get_bgstate == 0:
+                EventMesh.publish("clear_health_state")
+            # if msg != 0:
+            #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
+
+        def get_bg_state(self, event, msg): 
+            if self.get_bgstate:
+                return self.get_bgstate
+            else :
+                return 0
 
-        EventMesh.subscribe("set_bp_time", self.set_bp_time)
-        EventMesh.subscribe("get_bp_time", self.get_bp_time)
+        def set_spo2_time(self, event, msg): 
+            self.spo2time_on = msg[0]
+            self.spo2time_time = msg[1]
+            EventMesh.publish("set_storage_config",["spo2auto_btn",self.spo2time_on])
+            EventMesh.publish("set_storage_config",["spo2auto_time",self.spo2time_time])
 
-        EventMesh.subscribe("set_bp_state", self.set_bp_state)
-        EventMesh.subscribe("get_bp_state", self.get_bp_state)
 
+        def get_spo2_time(self, event, msg): 
+            
+            return [self.spo2time_on,self.spo2time_time]
 
-        EventMesh.subscribe("set_bg_state", self.set_bg_state)
-        EventMesh.subscribe("get_bg_state", self.get_bg_state)
 
-        EventMesh.subscribe("set_spo2_time", self.set_spo2_time)
-        EventMesh.subscribe("get_spo2_time", self.get_spo2_time)
+        def set_bp_time(self, event, msg): 
+            self.bptime_on = msg[0]
+            self.bptime_time = msg[1]
+            EventMesh.publish("set_storage_config",["bpauto_btn",self.bptime_on])
+            EventMesh.publish("set_storage_config",["bpauto_time",self.bptime_time])
 
+        def get_bp_time(self, event, msg): 
+            if self.bptime_on == None:
+                self.bptime_on = 0
+            if self.bptime_time == None:
+                self.bptime_time = 0
+            return [self.bptime_on,self.bptime_time]
         
-    def set_bg_state(self, event, msg): 
-        self.get_bgstate = msg
-        if self.get_bgstate == 0:
-            EventMesh.publish("clear_health_state")
-        # if msg != 0:
-        #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
-
-    def get_bg_state(self, event, msg): 
-        if self.get_bgstate:
-            return self.get_bgstate
-        else :
-            return 0
-
-    def set_spo2_time(self, event, msg): 
-        self.spo2time_on = msg[0]
-        self.spo2time_time = msg[1]
-        EventMesh.publish("set_storage_config",["spo2auto_btn",self.spo2time_on])
-        EventMesh.publish("set_storage_config",["spo2auto_time",self.spo2time_time])
-
-
-    def get_spo2_time(self, event, msg): 
-        
-        return [self.spo2time_on,self.spo2time_time]
+            
+        def set_bp_state(self, event, msg): 
+            self.get_bpstate = msg
+            if self.get_bpstate == 0:
+                EventMesh.publish("clear_health_state")
+            # if msg != 0:
+                # EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
+
+        def get_bp_state(self, event, msg): 
+            if self.get_bpstate:
+                return self.get_bpstate
+            else :
+                return 0
 
 
-    def set_bp_time(self, event, msg): 
-        self.bptime_on = msg[0]
-        self.bptime_time = msg[1]
-        EventMesh.publish("set_storage_config",["bpauto_btn",self.bptime_on])
-        EventMesh.publish("set_storage_config",["bpauto_time",self.bptime_time])
+        def set_temp_time(self, event, msg): 
+            self.set_time = msg
+            EventMesh.publish("set_storage_config",["temp_time",self.set_time])
 
-    def get_bp_time(self, event, msg): 
-        if self.bptime_on == None:
-            self.bptime_on = 0
-        if self.bptime_time == None:
-            self.bptime_time = 0
-        return [self.bptime_on,self.bptime_time]
-    
+        def get_temp_time(self, event, msg): 
+            return self.set_time
+        
+        def set_temp_state(self, event, msg): 
+            self.get_temp = msg
+            if self.get_temp == 0:
+                EventMesh.publish("clear_temp_state")
+            # if msg != 0:
+            #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
+
+        def get_temp_state(self, event, msg): 
+            return self.get_temp
+            
+    class getBrightnessManager(Abstract):#获取亮度级别
+        def __init__(self):
+            self.level = 6#默认值6
+            # self.read_data = {}
+            self.time = 5
+            self.PWM_backlight  = None
+
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_brightness_level", self.get_brightness_level)
+            EventMesh.subscribe("push_add_brightness_level", self.add)
+            EventMesh.subscribe("push_reduce_brightness_level", self.reduce)
+            EventMesh.subscribe("set_brightness_level", self.set_brightness_level)
+
+            EventMesh.subscribe("set_brightness_time", self.set_brightness_time)
+            EventMesh.subscribe("get_brightness_time", self.get_brightness_time)
+
+        def set_brightness_level(self, event, msg): 
+            self.level = msg
+            EventMesh.publish("set_storage_config", ["brightness_level",self.level])
+
+        def get_brightness_level(self, event, msg): 
+            tmp = EventMesh.publish("get_storage_config","brightness_level")
+            if tmp != None:
+                self.level = tmp
+            return self.level
+        
+        def set_brightness_time(self, event, msg): 
+            self.time = msg
+            EventMesh.publish("set_storage_config", ["brightness_time",self.time])
+        
+        def get_brightness_time(self, event, msg): 
+            tmp = EventMesh.publish("get_storage_config","brightness_time")
+            if tmp != None:
+                self.time = tmp
+            return self.time
         
-    def set_bp_state(self, event, msg): 
-        self.get_bpstate = msg
-        if self.get_bpstate == 0:
-            EventMesh.publish("clear_health_state")
-        # if msg != 0:
-            # EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
-
-    def get_bp_state(self, event, msg): 
-        if self.get_bpstate:
-            return self.get_bpstate
-        else :
-            return 0
-
-
-    def set_temp_time(self, event, msg): 
-        self.set_time = msg
-        EventMesh.publish("set_storage_config",["temp_time",self.set_time])
-
-    def get_temp_time(self, event, msg): 
-        return self.set_time
-    
-    def set_temp_state(self, event, msg): 
-        self.get_temp = msg
-        if self.get_temp == 0:
-            EventMesh.publish("clear_temp_state")
-        # if msg != 0:
-        #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
-
-    def get_temp_state(self, event, msg): 
-        return self.get_temp
-           
-class getBrightnessManager(Abstract):#获取亮度级别
-    def __init__(self):
-        self.level = 6#默认值6
-        # self.read_data = {}
-        self.time = 5
-        self.PWM_backlight  = None
-
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("get_brightness_level", self.get_brightness_level)
-        EventMesh.subscribe("push_add_brightness_level", self.add)
-        EventMesh.subscribe("push_reduce_brightness_level", self.reduce)
-        EventMesh.subscribe("set_brightness_level", self.set_brightness_level)
-
-        EventMesh.subscribe("set_brightness_time", self.set_brightness_time)
-        EventMesh.subscribe("get_brightness_time", self.get_brightness_time)
-
-    def set_brightness_level(self, event, msg): 
-        self.level = msg
-        EventMesh.publish("set_storage_config", ["brightness_level",self.level])
-
-    def get_brightness_level(self, event, msg): 
-        tmp = EventMesh.publish("get_storage_config","brightness_level")
-        if tmp != None:
-            self.level = tmp
-        return self.level
-    
-    def set_brightness_time(self, event, msg): 
-        self.time = msg
-        EventMesh.publish("set_storage_config", ["brightness_time",self.time])
-    
-    def get_brightness_time(self, event, msg): 
-        tmp = EventMesh.publish("get_storage_config","brightness_time")
-        if tmp != None:
-            self.time = tmp
-        return self.time
-    
 
 
-    def add(self, event, msg):
-        if self.level < 10:
-            self.level = self.level + 2
-        self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, self.level, 10)
-        self.PWM_backlight.open()
-        EventMesh.publish("set_storage_config", ["brightness_level",self.level])
+        def add(self, event, msg):
+            if self.level < 10:
+                self.level = self.level + 2
+            # self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, self.level, 10)
+            # self.PWM_backlight.open()
+            EventMesh.publish("set_storage_config", ["brightness_level",self.level])
 
 
-    def reduce(self, event, msg):
-        if self.level > 0:
-            self.level = self.level - 2
-        if self.level <= 0:
-            self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, 1, 10)
-        else:
-            self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS,self.level, 10)
+        def reduce(self, event, msg):
+            # if self.level > 0:
+            #     self.level = self.level - 2
+            # if self.level <= 0:
+            #     self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, 1, 10)
+            # else:
+            #     self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS,self.level, 10)
 
-        self.PWM_backlight.open()
-        EventMesh.publish("set_storage_config", ["brightness_level",self.level])
-       
-    
-class getStorageDataManager(Abstract):#获取内存数据
-    def __init__(self):
-        self.config_data = {}
-        check = ql_fs.path_exists("/usr/static/storage_file/config.json")
-        if check == True:
-            with open("/usr/static/storage_file/config.json","r") as fd:
-                self.config_data = ujson.load(fd)
-        else :
-            self.config_data = {'old_time': 0, 'flip_sw': 0}
-            pass
+            # self.PWM_backlight.open()
+            EventMesh.publish("set_storage_config", ["brightness_level",self.level])
+        
+        
+    class getStorageDataManager(Abstract):#获取内存数据
+        def __init__(self):
+            self.config_data = {}
+            check = ql_fs.path_exists("/usr/static/storage_file/config.json")
+            if check == True:
+                with open("/usr/static/storage_file/config.json","r") as fd:
+                    self.config_data = ujson.load(fd)
+            else :
+                self.config_data = {'old_time': 0, 'flip_sw': 0}
+                pass
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_storage_data", self.set_storage_data)
-        EventMesh.subscribe("set_storage_config", self.set_storage_config)
-        EventMesh.subscribe("get_storage_data", self.get_storage_data)
-        EventMesh.subscribe("get_storage_config", self.get_storage_config)
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_storage_data", self.set_storage_data)
+            EventMesh.subscribe("set_storage_config", self.set_storage_config)
+            EventMesh.subscribe("get_storage_data", self.get_storage_data)
+            EventMesh.subscribe("get_storage_config", self.get_storage_config)
+
+        def set_storage_data(self, event, msg): 
+            # EventMesh.debug_log("set_storage_data:{}".format(msg))
+            if msg != None:
+                self.config_data = msg
+                with open("/usr/static/storage_file/config.json",'w+',encoding="utf-8") as fd:
+                    ujson.dump(self.config_data,fd)
+        
 
-    def set_storage_data(self, event, msg): 
-        # EventMesh.debug_log("set_storage_data:{}".format(msg))
-        if msg != None:
-            self.config_data = msg
+        def set_storage_config(self,event,msg): 
+            # EventMesh.debug_log("set_storage_key_data1:{}".format(msg))
+            if len(msg) >= 2:
+                self.config_data[msg[0]]=msg[1]
+                # EventMesh.debug_log("set_storage_key_data2:{}".format(self.config_data[msg[0]]))
+                EventMesh.publish("publish_message_event_ui",{"func":self.set_storage_save,"data":0})
+        def set_storage_save(self, data): 
             with open("/usr/static/storage_file/config.json",'w+',encoding="utf-8") as fd:
                 ujson.dump(self.config_data,fd)
-    
-
-    def set_storage_config(self,event,msg): 
-        # EventMesh.debug_log("set_storage_key_data1:{}".format(msg))
-        if len(msg) >= 2:
-            self.config_data[msg[0]]=msg[1]
-            # EventMesh.debug_log("set_storage_key_data2:{}".format(self.config_data[msg[0]]))
-            EventMesh.publish("publish_message_event_ui",{"func":self.set_storage_save,"data":0})
-    def set_storage_save(self, data): 
-        with open("/usr/static/storage_file/config.json",'w+',encoding="utf-8") as fd:
-            ujson.dump(self.config_data,fd)
-    def get_storage_data(self, event, msg): 
-        # EventMesh.debug_log("get_storage_data:{}".format(self.config_data))
-        return self.config_data 
-    def get_storage_config(self,event,msg):
-        # EventMesh.debug_log("get_storage_key_data1:{}".format(msg))
-        b = msg in self.config_data.keys()
-        if b == True:
-            # EventMesh.debug_log("get_storage_key_data2:{}".format(self.config_data[msg]))
-            return self.config_data[msg]
-        else :
-            return None
-        # try:
-        #     return self.config_data[msg]
-        # except:
-        #     EventMesh.debug_log("get_storage_key_data:none key:{}",msg)
-        #     return None
-#定位频率
-class getUpLoadDataManager(Abstract):#
-    def __init__(self):
-        self.upload_time = 2*60*60
-        read_data = EventMesh.publish("get_storage_config","upload_time")
-        if read_data != None:
-            self.upload_time = read_data 
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_upload_data", self.set_upload_data)
-        EventMesh.subscribe("get_upload_data", self.get_upload_data)
-
-    def set_upload_data(self, event, msg): 
-        self.upload_time = msg
-
-    def get_upload_data(self, event, msg): 
-        if self.upload_time == None:
+        def get_storage_data(self, event, msg): 
+            # EventMesh.debug_log("get_storage_data:{}".format(self.config_data))
+            return self.config_data 
+        def get_storage_config(self,event,msg):
+            # EventMesh.debug_log("get_storage_key_data1:{}".format(msg))
+            b = msg in self.config_data.keys()
+            if b == True:
+                # EventMesh.debug_log("get_storage_key_data2:{}".format(self.config_data[msg]))
+                return self.config_data[msg]
+            else :
+                return None
+            # try:
+            #     return self.config_data[msg]
+            # except:
+            #     EventMesh.debug_log("get_storage_key_data:none key:{}",msg)
+            #     return None
+    #定位频率
+    class getUpLoadDataManager(Abstract):#
+        def __init__(self):
             self.upload_time = 2*60*60
-        return self.upload_time 
+            read_data = EventMesh.publish("get_storage_config","upload_time")
+            if read_data != None:
+                self.upload_time = read_data 
 
-class getplayAudiodStateManager(Abstract):#获取设置播放音频状态
-    def __init__(self):
-        self.play = 0
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_upload_data", self.set_upload_data)
+            EventMesh.subscribe("get_upload_data", self.get_upload_data)
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_audio_state", self.set_audio_state)
-        EventMesh.subscribe("get_audio_state", self.get_audio_state)
+        def set_upload_data(self, event, msg): 
+            self.upload_time = msg
 
-    def set_audio_state(self, event, msg): 
-        self.play = msg
+        def get_upload_data(self, event, msg): 
+            if self.upload_time == None:
+                self.upload_time = 2*60*60
+            return self.upload_time 
 
-    def get_audio_state(self, event, msg): 
-        return self.play
-    
-class getVolumSizeManager(Abstract):#设置或获取音量大小数据
-    def __init__(self):
-        self.volume_size = 8
-        read_data = EventMesh.publish("get_storage_config","volum")
-        if read_data != None:
-            self.volume_size = read_data
-    
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_volum_size", self.set_volum_size)
-        EventMesh.subscribe("get_volum_size", self.get_volum_size)
+    class getplayAudiodStateManager(Abstract):#获取设置播放音频状态
+        def __init__(self):
+            self.play = 0
 
-    def set_volum_size(self, event, msg): 
-        self.volume_size = msg
-        EventMesh.publish("set_storage_config", ["volum",self.volume_size])
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_audio_state", self.set_audio_state)
+            EventMesh.subscribe("get_audio_state", self.get_audio_state)
 
-    def get_volum_size(self, event, msg): 
-        return self.volume_size
+        def set_audio_state(self, event, msg): 
+            self.play = msg
 
-class getSosFlagManager(Abstract):#设置sos
-    def __init__(self):
-        self.aud = audio.Audio(0)
-        self.sos_flag = 0
-        self.sos_num = 0
-        self.hangup_mode = 0
-        self.call_timer = osTimer()
-        self.sos_numer1 = []
-        self.callnumer =""
-        SOS_NUMBER1 = EventMesh.publish("get_storage_config","SOS_NUMBER1")
-        if SOS_NUMBER1 != None:
-            self.sos_numer1 = SOS_NUMBER1
-        SOS_NUMBER2 = EventMesh.publish("get_storage_config","SOS_NUMBER2")
-        if SOS_NUMBER1 != None:        
-            self.sos_numer1 = [SOS_NUMBER1, SOS_NUMBER2]
+        def get_audio_state(self, event, msg): 
+            return self.play
+        
+    class getVolumSizeManager(Abstract):#设置或获取音量大小数据
+        def __init__(self):
+            self.volume_size = 8
+            read_data = EventMesh.publish("get_storage_config","volum")
+            if read_data != None:
+                self.volume_size = read_data
+        
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_volum_size", self.set_volum_size)
+            EventMesh.subscribe("get_volum_size", self.get_volum_size)
 
-        SOS_NUMBER3 = EventMesh.publish("get_storage_config","SOS_NUMBER3")
-        if SOS_NUMBER3 != None:        
-            self.sos_numer1 = [SOS_NUMBER1, SOS_NUMBER2,SOS_NUMBER3]
+        def set_volum_size(self, event, msg): 
+            self.volume_size = msg
+            EventMesh.publish("set_storage_config", ["volum",self.volume_size])
 
+        def get_volum_size(self, event, msg): 
+            return self.volume_size
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_sos_flag", self.set_sos_flag)#设置sos拨打标识
-        EventMesh.subscribe("get_sos_flag", self.get_sos_flag)
+    class getSosFlagManager(Abstract):#设置sos
+        def __init__(self):
+            self.aud = audio.Audio(0)
+            self.sos_flag = 0
+            self.sos_num = 0
+            self.hangup_mode = 0
+            self.call_timer = osTimer()
+            self.sos_numer1 = []
+            self.callnumer =""
+            SOS_NUMBER1 = EventMesh.publish("get_storage_config","SOS_NUMBER1")
+            if SOS_NUMBER1 != None:
+                self.sos_numer1 = SOS_NUMBER1
+            SOS_NUMBER2 = EventMesh.publish("get_storage_config","SOS_NUMBER2")
+            if SOS_NUMBER1 != None:        
+                self.sos_numer1 = [SOS_NUMBER1, SOS_NUMBER2]
 
-        EventMesh.subscribe("set_sos_num", self.set_sos_num)#设置拨打循环次数
-        EventMesh.subscribe("get_sos_num", self.get_sos_num)
+            SOS_NUMBER3 = EventMesh.publish("get_storage_config","SOS_NUMBER3")
+            if SOS_NUMBER3 != None:        
+                self.sos_numer1 = [SOS_NUMBER1, SOS_NUMBER2,SOS_NUMBER3]
 
-        EventMesh.subscribe("set_dial_sos_number", self.set_dial_sos_number)
-        EventMesh.subscribe("get_dial_sos_number", self.get_dial_sos_number)#设置家庭号码三个
 
-        EventMesh.subscribe("set_callnumer_cb", self.set_callnumer_cb)#延时回调
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_sos_flag", self.set_sos_flag)#设置sos拨打标识
+            EventMesh.subscribe("get_sos_flag", self.get_sos_flag)
 
-        EventMesh.subscribe("close_call_time",self.close_call_time)
+            EventMesh.subscribe("set_sos_num", self.set_sos_num)#设置拨打循环次数
+            EventMesh.subscribe("get_sos_num", self.get_sos_num)
 
-        EventMesh.subscribe("set_hangup_mode", self.set_hangup_mode)
-        EventMesh.subscribe("get_hangup_mode", self.get_hangup_mode)#获取挂断方式 是对方挂断 还是手表按键主动挂断
+            EventMesh.subscribe("set_dial_sos_number", self.set_dial_sos_number)
+            EventMesh.subscribe("get_dial_sos_number", self.get_dial_sos_number)#设置家庭号码三个
 
-    def get_hangup_mode(self, event, msg): # 1是设备端手表主动挂断 0是手机端
-        return self.hangup_mode
-    
-    def set_hangup_mode(self, event, msg): 
-        self.hangup_mode = msg
-
-    def set_sos_flag(self, event, msg): 
-        self.sos_flag = msg
-       
-        if self.sos_flag == 1:
-            number = EventMesh.publish("get_dial_sos_number")
-           
-            if number != None:
-                if len(number) > 0:
-                    self.call_timer.stop()
-                    EventMesh.publish("save_phonename",number[0])
-                    EventMesh.publish("save_phonenum",number[0])
-                    EventMesh.publish("set_sos_num",0)
-                    phone_num = EventMesh.publish("get_phonenum")  
-                    EventMesh.publish("sos_out_call_center_cb",phone_num)#电话拨出去
-                else:
-                    EventMesh.publish("sos_out_call_center_cb",None)#电话拨出去
-
-    def set_callnumer_cb(self, event, msg):
-        if self.sos_flag == 1:
-            self.callnumer = msg
-            self.call_timer.start(5000, 0, self.call_timer_cb)#延迟10S 继续拨打
-
-    def call_timer_cb(self, *args, **kwargs):
-        if self.sos_flag == 1:
-            EventMesh.publish("save_phonename",str(self.callnumer))
-            EventMesh.publish("save_phonenum",str(self.callnumer))
-            phone_num = EventMesh.publish("get_phonenum")  
-            EventMesh.publish("sos_out_call_center_cb",phone_num)#电话拨出去
-       
-    def close_call_time(self, event, msg): 
-        self.call_timer.stop()
-
-    def get_sos_flag(self, event, msg): 
-        return self.sos_flag
-    
-    def set_sos_num(self, event, msg): 
-        self.sos_num = msg
+            EventMesh.subscribe("set_callnumer_cb", self.set_callnumer_cb)#延时回调
 
-    def get_sos_num(self, event, msg): 
-        return self.sos_num
-    
-    def set_dial_sos_number(self, event, msg): 
-        self.sos_numer1 = msg
+            EventMesh.subscribe("close_call_time",self.close_call_time)
+
+            EventMesh.subscribe("set_hangup_mode", self.set_hangup_mode)
+            EventMesh.subscribe("get_hangup_mode", self.get_hangup_mode)#获取挂断方式 是对方挂断 还是手表按键主动挂断
+
+        def get_hangup_mode(self, event, msg): # 1是设备端手表主动挂断 0是手机端
+            return self.hangup_mode
         
+        def set_hangup_mode(self, event, msg): 
+            self.hangup_mode = msg
 
-    def get_dial_sos_number(self, event, msg): 
-        return self.sos_numer1
-class getLowBatManager(Abstract):#低电提醒
-    def __init__(self):
+        def set_sos_flag(self, event, msg): 
+            self.sos_flag = msg
+        
+            if self.sos_flag == 1:
+                number = EventMesh.publish("get_dial_sos_number")
+            
+                if number != None:
+                    if len(number) > 0:
+                        self.call_timer.stop()
+                        EventMesh.publish("save_phonename",number[0])
+                        EventMesh.publish("save_phonenum",number[0])
+                        EventMesh.publish("set_sos_num",0)
+                        phone_num = EventMesh.publish("get_phonenum")  
+                        EventMesh.publish("sos_out_call_center_cb",phone_num)#电话拨出去
+                    else:
+                        EventMesh.publish("sos_out_call_center_cb",None)#电话拨出去
+
+        def set_callnumer_cb(self, event, msg):
+            if self.sos_flag == 1:
+                self.callnumer = msg
+                self.call_timer.start(5000, 0, self.call_timer_cb)#延迟10S 继续拨打
+
+        def call_timer_cb(self, *args, **kwargs):
+            if self.sos_flag == 1:
+                EventMesh.publish("save_phonename",str(self.callnumer))
+                EventMesh.publish("save_phonenum",str(self.callnumer))
+                phone_num = EventMesh.publish("get_phonenum")  
+                EventMesh.publish("sos_out_call_center_cb",phone_num)#电话拨出去
+        
+        def close_call_time(self, event, msg): 
+            self.call_timer.stop()
 
-        self.low_btn = 0
-        read_data = EventMesh.publish("get_storage_config","low_on")
-        if read_data != None:
-            self.low_btn = read_data
+        def get_sos_flag(self, event, msg): 
+            return self.sos_flag
+        
+        def set_sos_num(self, event, msg): 
+            self.sos_num = msg
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_low_bat_btn", self.set_low_bat_btn)#
-        EventMesh.subscribe("get_low_bat_btn", self.get_low_bat_btn)
+        def get_sos_num(self, event, msg): 
+            return self.sos_num
+        
+        def set_dial_sos_number(self, event, msg): 
+            self.sos_numer1 = msg
+            
 
-    def set_low_bat_btn(self, event, msg): 
-        self.low_btn = msg
-        EventMesh.publish("set_storage_config",["low_on",self.low_btn])
+        def get_dial_sos_number(self, event, msg): 
+            return self.sos_numer1
+    class getLowBatManager(Abstract):#低电提醒
+        def __init__(self):
 
-    def get_low_bat_btn(self, event, msg): 
-        return self.low_btn
-    
+            self.low_btn = 0
+            read_data = EventMesh.publish("get_storage_config","low_on")
+            if read_data != None:
+                self.low_btn = read_data
 
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_low_bat_btn", self.set_low_bat_btn)#
+            EventMesh.subscribe("get_low_bat_btn", self.get_low_bat_btn)
 
-class playPowerAudioManager(Abstract):#播放开关机音频文件
-    def __init__(self):
-        self.aud = audio.Audio(0)
+        def set_low_bat_btn(self, event, msg): 
+            self.low_btn = msg
+            EventMesh.publish("set_storage_config",["low_on",self.low_btn])
 
-    def post_processor_after_instantiation(self):
+        def get_low_bat_btn(self, event, msg): 
+            return self.low_btn
         
-        EventMesh.subscribe("play_poewr_on_event", self.play_poewr_on_event)#
-        EventMesh.subscribe("play_poewr_off_event", self.play_poewr_off_event)
 
-    def play_poewr_on_event(self, event, msg): 
-        self.aud.play(1, 1, 'U:/static/R_POWER_1.mp3')  #播放播放开机铃声
 
-    def play_poewr_off_event(self, event, msg): 
-        self.aud.setVolume(11)
-        self.aud.play(1, 1, 'U:/static/R_POWER_OFF_1.mp3')  #播放关机铃声
-    
-class getBootOffManager(Abstract):#开关机时间
-    def __init__(self):
-        self.poweroff_time = []
-        read_data = EventMesh.publish("get_storage_config","poweroff_alarm")
-        if read_data != None:
-            self.poweroff_time = read_data
-        else:
-            self.poweroff_time = [{"poweroff_on":0,"start_hour":6,"start_min":0,"end_hour":0,"end_min":0}]
-        
+    class playPowerAudioManager(Abstract):#播放开关机音频文件
+        def __init__(self):
+            self.aud = audio.Audio(0)
+
+        def post_processor_after_instantiation(self):
+            
+            EventMesh.subscribe("play_poewr_on_event", self.play_poewr_on_event)#
+            EventMesh.subscribe("play_poewr_off_event", self.play_poewr_off_event)
 
+        def play_poewr_on_event(self, event, msg): 
+            self.aud.play(1, 1, 'U:/static/R_POWER_1.mp3')  #播放播放开机铃声
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_boot_off_time", self.set_boot_off_time)#设置关机时间
-        EventMesh.subscribe("get_boot_off_time", self.get_boot_off_time)
+        def play_poewr_off_event(self, event, msg): 
+            self.aud.setVolume(11)
+            self.aud.play(1, 1, 'U:/static/R_POWER_OFF_1.mp3')  #播放关机铃声
+        
+    class getBootOffManager(Abstract):#开关机时间
+        def __init__(self):
+            self.poweroff_time = []
+            read_data = EventMesh.publish("get_storage_config","poweroff_alarm")
+            if read_data != None:
+                self.poweroff_time = read_data
+            else:
+                self.poweroff_time = [{"poweroff_on":0,"start_hour":6,"start_min":0,"end_hour":0,"end_min":0}]
+            
 
-    def set_boot_off_time(self, event, msg): 
-        EventMesh.debug_log("set_boot_off_time",msg)
 
-        EventMesh.publish("set_storage_config",["poweroff_alarm",msg])
-        self.poweroff_time = msg
-        EventMesh.publish("set_rtc_alarm")
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_boot_off_time", self.set_boot_off_time)#设置关机时间
+            EventMesh.subscribe("get_boot_off_time", self.get_boot_off_time)
 
+        def set_boot_off_time(self, event, msg): 
+            EventMesh.debug_log("set_boot_off_time",msg)
 
-    def get_boot_off_time(self, event, msg):
-        return self.poweroff_time
-class setSmsIndexManager(Abstract):#
-    def __init__(self):
-        self.index = -1
+            EventMesh.publish("set_storage_config",["poweroff_alarm",msg])
+            self.poweroff_time = msg
+            EventMesh.publish("set_rtc_alarm")
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_sms_index", self.set_sms_index)#设置关机时间
-        EventMesh.subscribe("get_sms_index", self.get_sms_index)
 
-    def set_sms_index(self, event, msg): 
-        self.index = msg
-        
+        def get_boot_off_time(self, event, msg):
+            return self.poweroff_time
+    class setSmsIndexManager(Abstract):#
+        def __init__(self):
+            self.index = -1
 
-    def get_sms_index(self, event, msg):
-        
-        return self.index
-import protocol 
-class testSmsSetIPManager(Abstract):#
-    def __init__(self):
-        self.timer = osTimer()
-        #大锤
-        severdata = protocol.server_init()
-
-        self.newip = severdata[0]
-        self.newcom = severdata[1]
-        self.new_key = severdata[2]
-        self.new_pid = severdata[3]
-        
-        EventMesh.debug_log("testSmsSetIPManager:{}\n".format(severdata))
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_sms_index", self.set_sms_index)#设置关机时间
+            EventMesh.subscribe("get_sms_index", self.get_sms_index)
 
-        self.server_sate = 0
+        def set_sms_index(self, event, msg): 
+            self.index = msg
+            
 
+        def get_sms_index(self, event, msg):
+            
+            return self.index
+    import protocol 
+    class testSmsSetIPManager(Abstract):#
+        def __init__(self):
+            self.timer = osTimer()
+            #大锤
+            severdata = protocol.server_init()
+
+            self.newip = severdata[0]
+            self.newcom = severdata[1]
+            self.new_key = severdata[2]
+            self.new_pid = severdata[3]
+            
+            EventMesh.debug_log("testSmsSetIPManager:{}\n".format(severdata))
 
+            self.server_sate = 0
 
-        tmp_data = EventMesh.publish("get_storage_config","set_new_ip_addr")
-        if tmp_data != None:
-            self.newip = tmp_data
-        tmp_data = EventMesh.publish("get_storage_config","set_new_com")
-        if tmp_data != None:
-            self.newcom = tmp_data
-        tmp_data = EventMesh.publish("get_storage_config","set_new_md5")
-        if tmp_data != None:
-            self.newmd5 = tmp_data    
 
-        tmp_data = EventMesh.publish("get_storage_config","set_new_key")
-        if tmp_data != None:
-            self.new_key = tmp_data 
 
-        tmp_data = EventMesh.publish("get_storage_config","set_new_pid")
-        if tmp_data != None:
-            self.new_pid = tmp_data 
+            tmp_data = EventMesh.publish("get_storage_config","set_new_ip_addr")
+            if tmp_data != None:
+                self.newip = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","set_new_com")
+            if tmp_data != None:
+                self.newcom = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","set_new_md5")
+            if tmp_data != None:
+                self.newmd5 = tmp_data    
 
-        tmp_data = EventMesh.publish("get_storage_config","get_server_sate")
-        if tmp_data != None:
-            self.server_sate = tmp_data 
-        
-        
+            tmp_data = EventMesh.publish("get_storage_config","set_new_key")
+            if tmp_data != None:
+                self.new_key = tmp_data 
 
+            tmp_data = EventMesh.publish("get_storage_config","set_new_pid")
+            if tmp_data != None:
+                self.new_pid = tmp_data 
 
+            tmp_data = EventMesh.publish("get_storage_config","get_server_sate")
+            if tmp_data != None:
+                self.server_sate = tmp_data 
+            
+            
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_new_ip_com", self.set_new_ip_com)#设置关机时间
-        EventMesh.subscribe("get_new_ip_com", self.get_new_ip_com)
 
-        EventMesh.subscribe("set_ip", self.set_ip)#设置关机时间
-        EventMesh.subscribe("get_ip", self.get_ip)
 
-        EventMesh.subscribe("set_com", self.set_com)#设置关机时间
-        EventMesh.subscribe("get_com", self.get_com)
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_new_ip_com", self.set_new_ip_com)#设置关机时间
+            EventMesh.subscribe("get_new_ip_com", self.get_new_ip_com)
 
-        EventMesh.subscribe("get_new_key", self.get_new_key_cb)#获取key
-        EventMesh.subscribe("set_new_key", self.set_new_key_cb)#获取key
+            EventMesh.subscribe("set_ip", self.set_ip)#设置关机时间
+            EventMesh.subscribe("get_ip", self.get_ip)
 
-        EventMesh.subscribe("set_new_pid", self.set_new_pid_cb)#获取pid
-        EventMesh.subscribe("get_new_pid", self.get_new_pid_cb)#获取pid
+            EventMesh.subscribe("set_com", self.set_com)#设置关机时间
+            EventMesh.subscribe("get_com", self.get_com)
 
-        EventMesh.subscribe("set_server_state", self.set_server_state)#
-        EventMesh.subscribe("get_server_state", self.get_server_state)#
+            EventMesh.subscribe("get_new_key", self.get_new_key_cb)#获取key
+            EventMesh.subscribe("set_new_key", self.set_new_key_cb)#获取key
 
-        EventMesh.subscribe("get_new_key_pid", self.get_new_key_pid)#
+            EventMesh.subscribe("set_new_pid", self.set_new_pid_cb)#获取pid
+            EventMesh.subscribe("get_new_pid", self.get_new_pid_cb)#获取pid
 
+            EventMesh.subscribe("set_server_state", self.set_server_state)#
+            EventMesh.subscribe("get_server_state", self.get_server_state)#
 
+            EventMesh.subscribe("get_new_key_pid", self.get_new_key_pid)#
 
-    def set_new_key_cb(self, event, msg): 
-        self.new_key = msg
-        # print("set_new_key_cb",msg,self.new_key)
-        EventMesh.publish("set_storage_config",["set_new_key",self.new_key])
 
-    def get_new_key_cb(self, event, msg):
-        # print("get_new_key_cb",self.new_key)
-        return self.new_key
-    
-    def set_new_pid_cb(self, event, msg): 
-        self.new_pid = msg
-        # print("set_new_pid_cb",msg,self.new_pid)
-        EventMesh.publish("set_storage_config",["set_new_pid",self.new_pid])
 
-    def get_new_pid_cb(self, event, msg):
-        # print("get_new_pid_cb",self.new_pid)
-        return self.new_pid
+        def set_new_key_cb(self, event, msg): 
+            self.new_key = msg
+            # print("set_new_key_cb",msg,self.new_key)
+            EventMesh.publish("set_storage_config",["set_new_key",self.new_key])
 
-    def set_new_ip_com(self, event, msg): 
-        self.newip = str(msg[0])
-        self.newcom = int(msg[1])
-        # self.newmd5 = str(msg[2])
-        #短信格式:SETIP:api.xcloudtech.com:9000:bZld0ALsZTt15tKEZhOlLPgbsO75BLTP 以冒号分隔 SETIP:ip地址:ip端口号:ip密钥key
+        def get_new_key_cb(self, event, msg):
+            # print("get_new_key_cb",self.new_key)
+            return self.new_key
+        
+        def set_new_pid_cb(self, event, msg): 
+            self.new_pid = msg
+            # print("set_new_pid_cb",msg,self.new_pid)
+            EventMesh.publish("set_storage_config",["set_new_pid",self.new_pid])
+
+        def get_new_pid_cb(self, event, msg):
+            # print("get_new_pid_cb",self.new_pid)
+            return self.new_pid
+
+        def set_new_ip_com(self, event, msg): 
+            self.newip = str(msg[0])
+            self.newcom = int(msg[1])
+            # self.newmd5 = str(msg[2])
+            #短信格式:SETIP:api.xcloudtech.com:9000:bZld0ALsZTt15tKEZhOlLPgbsO75BLTP 以冒号分隔 SETIP:ip地址:ip端口号:ip密钥key
+
+            # self.read_data["set_new_md5"] = self.newmd5  #通过短信设置ip的key密钥
+        
 
-        # self.read_data["set_new_md5"] = self.newmd5  #通过短信设置ip的key密钥
-       
+            EventMesh.publish("set_storage_config",["set_new_ip_addr",self.newip])
+            EventMesh.publish("set_storage_config",["set_new_com",self.newcom])
 
-        EventMesh.publish("set_storage_config",["set_new_ip_addr",self.newip])
-        EventMesh.publish("set_storage_config",["set_new_com",self.newcom])
 
+            number = str(msg[2])
+            sms.sendPduMsg(number, 'set ok', 'UCS2')
+            self.timer.start(10*1000,0,self.fun)
+            
+        def fun(self,*argc):
+            Power.powerRestart()
+
+        def get_new_ip_com(self, event, msg):
+            tmp_addr = EventMesh.publish("get_storage_config","set_new_ip_addr")
+            tmp_com = EventMesh.publish("get_storage_config","set_new_com")
+            if tmp_addr != None:
+                self.newip = tmp_addr
+            if tmp_com != None:
+                self.newcom = tmp_com
+            return [self.newip,self.newcom]
+        
+        def set_ip(self, event, msg): 
+            self.newip = msg
+            EventMesh.publish("set_storage_config",["set_new_ip_addr",self.newip])
 
-        number = str(msg[2])
-        sms.sendPduMsg(number, 'set ok', 'UCS2')
-        self.timer.start(10*1000,0,self.fun)
+        def get_ip(self, event, msg):
+            # print("get_ip",self.newip)
+            return self.newip
         
-    def fun(self,*argc):
-        Power.powerRestart()
-
-    def get_new_ip_com(self, event, msg):
-        tmp_addr = EventMesh.publish("get_storage_config","set_new_ip_addr")
-        tmp_com = EventMesh.publish("get_storage_config","set_new_com")
-        if tmp_addr != None:
-            self.newip = tmp_addr
-        if tmp_com != None:
-            self.newcom = tmp_com
-        return [self.newip,self.newcom]
-    
-    def set_ip(self, event, msg): 
-        self.newip = msg
-        EventMesh.publish("set_storage_config",["set_new_ip_addr",self.newip])
+        def set_com(self, event, msg): 
+            self.newcom = msg
+            EventMesh.publish("set_storage_config",["set_new_com",self.newcom])
 
-    def get_ip(self, event, msg):
-        # print("get_ip",self.newip)
-        return self.newip
-    
-    def set_com(self, event, msg): 
-        self.newcom = msg
-        EventMesh.publish("set_storage_config",["set_new_com",self.newcom])
+        def get_com(self, event, msg):
+            # print("get_com",self.newcom)
+            return self.newcom
 
-    def get_com(self, event, msg):
-        # print("get_com",self.newcom)
-        return self.newcom
+        def get_new_key_pid(self, event, msg):
+            return [self.new_key,self.new_pid]
+        
+        def set_server_state(self, event, msg):
+            EventMesh.publish("set_storage_config",["get_server_sate",msg])
+            self.server_sate = msg
 
-    def get_new_key_pid(self, event, msg):
-        return [self.new_key,self.new_pid]
-    
-    def set_server_state(self, event, msg):
-        EventMesh.publish("set_storage_config",["get_server_sate",msg])
-        self.server_sate = msg
+        def get_server_state(self, event, msg):
+            return self.server_sate
+            
 
-    def get_server_state(self, event, msg):
-        return self.server_sate
-        
+    # MMI Version:UIX8910_C55_DS_D12G_PRO18_FZD_V1.0_Release
+    # Build:07-07-2022 16:12:58
+    # IMEI:861218001025267
+    # IP:api.xcloudtech.com
+    # PORT:9000
+    # UPLOAD:300
+    # Battery:3948, 64
+    # Udebug: 0
+    # ConnectTime: 7
+    import protocol
+
+    class sendDevinfoManager(Abstract):#发送设备信息
+        def __init__(self):
+            self.timer = osTimer()
+            pass
 
-# MMI Version:UIX8910_C55_DS_D12G_PRO18_FZD_V1.0_Release
-# Build:07-07-2022 16:12:58
-# IMEI:861218001025267
-# IP:api.xcloudtech.com
-# PORT:9000
-# UPLOAD:300
-# Battery:3948, 64
-# Udebug: 0
-# ConnectTime: 7
-import protocol
-
-class sendDevinfoManager(Abstract):#发送设备信息
-    def __init__(self):
-        self.timer = osTimer()
-        pass
-
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("send_devinfo_event", self.send_devinfo_event)#删除短信
-
-    def send_devinfo_event(self, event, msg): 
-        number = str(msg)
-        versions = EventMesh.softversion
-        Build = EventMesh.builTime
-        IMEI = EventMesh.publish(constants.EVENT.GET_IMEI)
-        IP = ""
-        new_ip = EventMesh.publish("get_storage_config","set_new_ip_addr")
-        new_com = EventMesh.publish("get_storage_config","set_new_com")
-        server_data = protocol.server_init()
-       
-        if new_ip != None:
-            if len(new_ip) != 0:
-                IP = new_ip
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("send_devinfo_event", self.send_devinfo_event)#删除短信
+
+        def send_devinfo_event(self, event, msg): 
+            number = str(msg)
+            versions = EventMesh.softversion
+            Build = EventMesh.builTime
+            IMEI = EventMesh.publish(constants.EVENT.GET_IMEI)
+            IP = ""
+            new_ip = EventMesh.publish("get_storage_config","set_new_ip_addr")
+            new_com = EventMesh.publish("get_storage_config","set_new_com")
+            server_data = protocol.server_init()
+        
+            if new_ip != None:
+                if len(new_ip) != 0:
+                    IP = new_ip
+                else:
+                    IP = server_data[0]
             else:
                 IP = server_data[0]
-        else:
-            IP = server_data[0]
-        
-        PORT = ''
-        if new_com != None:
-            if len(new_com) != 0:
-                PORT = new_com
+            
+            PORT = ''
+            if new_com != None:
+                if len(new_com) != 0:
+                    PORT = new_com
+                else:
+                    PORT = server_data[1]
             else:
                 PORT = server_data[1]
-        else:
-            PORT = server_data[1]
-        
-        UPLOAD = EventMesh.publish("get_upload_data")
+            
+            UPLOAD = EventMesh.publish("get_upload_data")
 
-        level = EventMesh.publish("get_curr_battery_level")
-        if level == None:
-            level = 4200
-        bat = EventMesh.publish("screen_get_battery")[1]
-        if bat == None:
-            bat = 100
-        Battery = str(level) +',' +  str(bat)
+            level = EventMesh.publish("get_curr_battery_level")
+            if level == None:
+                level = 4200
+            bat = EventMesh.publish("screen_get_battery")[1]
+            if bat == None:
+                bat = 100
+            Battery = str(level) +',' +  str(bat)
 
-        ConnectTime = heartbeat_time//60
-        data1 = "Version:{}\nBuild:{}".format(versions,Build)
+            ConnectTime = heartbeat_time//60
+            data1 = "Version:{}\nBuild:{}".format(versions,Build)
 
-        data2 = "IMEI:{}\nIP:{}\nPORT:{}".format(IMEI,IP,PORT)
-        
-        data3 = "UPLOAD:{}\nBattery:{}\nConnectTime:{}".format(UPLOAD,Battery,ConnectTime)
+            data2 = "IMEI:{}\nIP:{}\nPORT:{}".format(IMEI,IP,PORT)
+            
+            data3 = "UPLOAD:{}\nBattery:{}\nConnectTime:{}".format(UPLOAD,Battery,ConnectTime)
 
-        send_state1 = -1
-        send_state2 = -1
-        # print("data",data1,data2,data3)
-        send_state1 = sms.sendPduMsg(number, data1, 'UCS2')
+            send_state1 = -1
+            send_state2 = -1
+            # print("data",data1,data2,data3)
+            send_state1 = sms.sendPduMsg(number, data1, 'UCS2')
 
-        if send_state1 == 0:
-            send_state2 = sms.sendPduMsg(number, data2, 'UCS2')
+            if send_state1 == 0:
+                send_state2 = sms.sendPduMsg(number, data2, 'UCS2')
 
-        if send_state2 == 0:
-            sms.sendPduMsg(number, data3, 'UCS2')
-        
+            if send_state2 == 0:
+                sms.sendPduMsg(number, data3, 'UCS2')
+            
 
-class deleteSmsManager(Abstract):#删除信息
-    def __init__(self):
-        self.timer = osTimer()
-        pass
+    class deleteSmsManager(Abstract):#删除信息
+        def __init__(self):
+            self.timer = osTimer()
+            pass
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("delete_sms_event", self.delete_sms_event)#删除短信
-        EventMesh.subscribe("remove_all_sms_cb", self.remove_all_sms_cb)#
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("delete_sms_event", self.delete_sms_event)#删除短信
+            EventMesh.subscribe("remove_all_sms_cb", self.remove_all_sms_cb)#
 
-    def delete_sms_event(self, event, msg): 
-        self.timer.start(4*1000,0,self.fun)
+        def delete_sms_event(self, event, msg): 
+            self.timer.start(4*1000,0,self.fun)
+            
+        def fun(self, *argc): 
+            EventMesh.publish_async("remove_all_sms_cb","",1*1024)
+
+        def remove_all_sms_cb(self, event, msg):
+            sms.deleteMsg(1,4)
+
+    #闹钟信息
+    alarm_list = [{'hour': 6, 'repeart': 10, 'idx': 0, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0},
+                {'hour': 0, 'repeart': 10, 'idx': 1, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0}]
+    #用于显示闹钟列表不包含开关机信息
+
+    class ClockManager(Abstract):
+        def __init__(self):
+            super().__init__()
+            self.rtc = RTC()
+            self.days = 0
+            self.idx = 0
+
+            IFEXIST = ql_fs.path_exists("/usr/static/storage_file/alarm_msg.json") 
+            self.check_alarm_list = []     
+            if IFEXIST == True:
+                with open("/usr/static/storage_file/alarm_msg.json","r",encoding='utf-8') as fd:
+                    self.check_alarm_list = ujson.load(fd)
+            
+            EventMesh.subscribe("push_clock_info", self.set)
+            EventMesh.subscribe("read_alarminjson", self.read_alarminjson)
+            EventMesh.subscribe("add_alarm", self.add_alarm)
+            EventMesh.subscribe("remove_alarm", self.remove_alarm)
+            EventMesh.subscribe("set_rtc_alarm", self.set_rtc_alarm)
+            EventMesh.subscribe("get_alarm_indx", self.get_alarm_indx)
+            EventMesh.subscribe("get_check_alarm_list", self.get_check_alarm_list)
+            EventMesh.subscribe("push_update_alarm_show", self.update_show_info)
+
+        def post_processor_after_instantiation(self):
         
-    def fun(self, *argc): 
-        EventMesh.publish_async("remove_all_sms_cb","",1*1024)
-
-    def remove_all_sms_cb(self, event, msg):
-        sms.deleteMsg(1,4)
-
-#闹钟信息
-alarm_list = [{'hour': 6, 'repeart': 10, 'idx': 0, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0},
-               {'hour': 0, 'repeart': 10, 'idx': 1, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0}]
-#用于显示闹钟列表不包含开关机信息
-
-class ClockManager(Abstract):
-    def __init__(self):
-        super().__init__()
-        self.rtc = RTC()
-        self.days = 0
-        self.idx = 0
-
-        IFEXIST = ql_fs.path_exists("/usr/static/storage_file/alarm_msg.json") 
-        self.check_alarm_list = []     
-        if IFEXIST == True:
-            with open("/usr/static/storage_file/alarm_msg.json","r",encoding='utf-8') as fd:
-                self.check_alarm_list = ujson.load(fd)
+            EventMesh.publish("read_alarminjson")
+            # EventMesh.publish("set_rtc_alarm")
         
-        EventMesh.subscribe("push_clock_info", self.set)
-        EventMesh.subscribe("read_alarminjson", self.read_alarminjson)
-        EventMesh.subscribe("add_alarm", self.add_alarm)
-        EventMesh.subscribe("remove_alarm", self.remove_alarm)
-        EventMesh.subscribe("set_rtc_alarm", self.set_rtc_alarm)
-        EventMesh.subscribe("get_alarm_indx", self.get_alarm_indx)
-        EventMesh.subscribe("get_check_alarm_list", self.get_check_alarm_list)
-        EventMesh.subscribe("push_update_alarm_show", self.update_show_info)
-
-    def post_processor_after_instantiation(self):
-    
-        EventMesh.publish("read_alarminjson")
-        # EventMesh.publish("set_rtc_alarm")
-       
-    def update_show_info(self,event,msg):
-        EventMesh.publish("read_alarminjson")
-        # EventMesh.publish("set_rtc_alarm")
-
-    def get_check_alarm_list(self, event, msg):
-        alarm_len = 0
-        global alarm_list
-        EventMesh.publish("read_alarminjson")
-        alarm_len = len(alarm_list)
-        return alarm_len
-
-
-    def set(self, event, msg):
-        global alarm_list
-        EventMesh.debug_log("msg = {}".format(msg))
-        idx = msg.get("idx")
-        EventMesh.debug_log("修改第{}个闹钟信息{}".format(idx,alarm_list[idx]))
-        alarm_list[idx]["hour"] = msg["hour"]
-        alarm_list[idx]["minute"] = msg["minute"]
-        alarm_list[idx]["days"] = msg["days"]
-        alarm_list[idx]["enabled"] = msg["enabled"]
-        alarm_list[idx]["repeart"] = msg["repeart"]
-        with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
-            ujson.dump(alarm_list,fd)
-
-    def read_alarminjson(self, event, msg):
-        IFEXIST = ql_fs.path_exists("/usr/static/storage_file/alarm_msg.json") 
-        global alarm_list     
-        EventMesh.debug_log("IFEXIST:{}".format(IFEXIST))
-        if IFEXIST == True:
-            with open("/usr/static/storage_file/alarm_msg.json","r",encoding='utf-8') as fd:
-                alarm_list = ujson.load(fd)
+        def update_show_info(self,event,msg):
+            EventMesh.publish("read_alarminjson")
+            # EventMesh.publish("set_rtc_alarm")
+
+        def get_check_alarm_list(self, event, msg):
+            alarm_len = 0
+            global alarm_list
+            EventMesh.publish("read_alarminjson")
+            alarm_len = len(alarm_list)
+            return alarm_len
+
+
+        def set(self, event, msg):
+            global alarm_list
+            EventMesh.debug_log("msg = {}".format(msg))
+            idx = msg.get("idx")
+            EventMesh.debug_log("修改第{}个闹钟信息{}".format(idx,alarm_list[idx]))
+            alarm_list[idx]["hour"] = msg["hour"]
+            alarm_list[idx]["minute"] = msg["minute"]
+            alarm_list[idx]["days"] = msg["days"]
+            alarm_list[idx]["enabled"] = msg["enabled"]
+            alarm_list[idx]["repeart"] = msg["repeart"]
+            with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
+                ujson.dump(alarm_list,fd)
+
+        def read_alarminjson(self, event, msg):
+            IFEXIST = ql_fs.path_exists("/usr/static/storage_file/alarm_msg.json") 
+            global alarm_list     
+            EventMesh.debug_log("IFEXIST:{}".format(IFEXIST))
+            if IFEXIST == True:
+                with open("/usr/static/storage_file/alarm_msg.json","r",encoding='utf-8') as fd:
+                    alarm_list = ujson.load(fd)
 
-        
-        # read_data = EventMesh.publish("get_storage_config","off_on")
+            
+            # read_data = EventMesh.publish("get_storage_config","off_on")
 
-        hour1 = str(alarm_list[0]["hour"])+':'+str(alarm_list[0]["minute"])
-        # min1 = str(alarm_list[0]["minute"])
+            hour1 = str(alarm_list[0]["hour"])+':'+str(alarm_list[0]["minute"])
+            # min1 = str(alarm_list[0]["minute"])
 
-        hour2 = str(alarm_list[1]["hour"])+':'+str(alarm_list[1]["minute"])
-        # min2 = str(alarm_list[1]["minute"]) 
-        # EventMesh.publish("set_boot_off_time",[1,hour1,hour2])
+            hour2 = str(alarm_list[1]["hour"])+':'+str(alarm_list[1]["minute"])
+            # min2 = str(alarm_list[1]["minute"]) 
+            # EventMesh.publish("set_boot_off_time",[1,hour1,hour2])
 
-        EventMesh.debug_log("hour1:{}-{}".format(hour1,hour2))
+            EventMesh.debug_log("hour1:{}-{}".format(hour1,hour2))
 
-        
-        return alarm_list
+            
+            return alarm_list
 
-    def add_alarm(self, event, msg):
+        def add_alarm(self, event, msg):
 
-        global alarm_list
-        EventMesh.publish("read_alarminjson")
-        EventMesh.debug_log("msg:{}".format(msg))
-        for i in range(0,2):#开关机固定是 idx 0 1
-            off_msg1 = msg[i+1]
-            msg_tmp1 = off_msg1.split(':')
-            start_hour = int(msg_tmp1[0])
-            start_min = int(msg_tmp1[1])
-            enable = int(msg[0])
-            EventMesh.debug_log("start_hour:{} start_min:{} enable:{}",start_hour,start_min,enable)
-            # EventMesh.publish("set_boot_off_time",[msg[0],msg[1],msg[2]])
+            global alarm_list
+            EventMesh.publish("read_alarminjson")
+            EventMesh.debug_log("msg:{}".format(msg))
+            for i in range(0,2):#开关机固定是 idx 0 1
+                off_msg1 = msg[i+1]
+                msg_tmp1 = off_msg1.split(':')
+                start_hour = int(msg_tmp1[0])
+                start_min = int(msg_tmp1[1])
+                enable = int(msg[0])
+                EventMesh.debug_log("start_hour:{} start_min:{} enable:{}",start_hour,start_min,enable)
+                # EventMesh.publish("set_boot_off_time",[msg[0],msg[1],msg[2]])
 
-            alarm_list[i]["idx"]=i
-            alarm_list[i]["hour"]=start_hour
-            alarm_list[i]["minute"]=start_min
-            alarm_list[i]["days"]=[0,1,2,3,4,5,6]
-            alarm_list[i]["enabled"]=enable
-            alarm_list[i]["repeart"]=10
+                alarm_list[i]["idx"]=i
+                alarm_list[i]["hour"]=start_hour
+                alarm_list[i]["minute"]=start_min
+                alarm_list[i]["days"]=[0,1,2,3,4,5,6]
+                alarm_list[i]["enabled"]=enable
+                alarm_list[i]["repeart"]=10
 
 
-            # alarm_list.append({"idx": i, "hour": start_hour, "minute": start_min, "days":[0,1,2,3,4,5,6], "enabled": enable,"repeart":10})
+                # alarm_list.append({"idx": i, "hour": start_hour, "minute": start_min, "days":[0,1,2,3,4,5,6], "enabled": enable,"repeart":10})
 
-        
-        # EventMesh.debug_log("alarm_list----len- :{} alarm_list:{}".format(len(alarm_list),alarm_list))
-        with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
-            ujson.dump(alarm_list,fd)
-        EventMesh.publish("push_update_alarm_show")
-        
-       
+            
+            # EventMesh.debug_log("alarm_list----len- :{} alarm_list:{}".format(len(alarm_list),alarm_list))
+            with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
+                ujson.dump(alarm_list,fd)
+            EventMesh.publish("push_update_alarm_show")
             
         
+                
+            
 
 
-    def remove_alarm(self, event, msg):
-        global alarm_list
-        EventMesh.debug_log("ddddddddddddddddddd:",msg)
-        idx = msg.get("idx")
-        EventMesh.debug_log("delete_here1-----{},{}:".format(idx,msg))
-
-        for i, alarm in enumerate(alarm_list):
-            EventMesh.debug_log("delete_here2-----{},{}:".format(i,alarm))
-
-            if alarm["idx"] == idx:
-                del alarm_list[i]
-                EventMesh.debug_log("delete_here3-----",alarm_list)
-
-                #删除闹钟后,对idx重新排序
-                if alarm_list:
-                    for j in range(i,len(alarm_list)):
-                        alarm_list[j]["idx"] -= 1
-                        EventMesh.debug_log("delete_here4-----",alarm_list)
-
-        with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
-            ujson.dump(alarm_list,fd)
-
-
-    def get_alarm_indx(self,event,msg):
-        return self.idx
-
-    def _rtc_callback(self,args):
-        #设置下一个闹钟,定时开关机功能
-        msg_data = EventMesh.publish("get_boot_off_time")
-        if msg_data != None:
-            power_offdata = msg_data[0]
-            start_hour = int(power_offdata["start_hour"])
-            start_min = int(power_offdata["start_min"])
-            end_hour = int(power_offdata["end_hour"])
-            end_min = int(power_offdata["end_min"])
-            off_on = int(power_offdata["poweroff_on"])
-
-            rtc_now_time = self.rtc.datetime()
-            current_minute = rtc_now_time[4]*60 + rtc_now_time[5]
-            end_min_total = end_hour*60+end_min
-            next_minute = start_hour*60+start_min #10:11
-            EventMesh.debug_log("off_on:{} {} {}".format(off_on,current_minute,next_minute))
-            if off_on != None:
-                if off_on == 1:
-                    if end_min_total == current_minute:#结束的时间分钟等于关机时间分钟数则关机
-                        ubs_state = EventMesh.publish("get_usb")#'
-                        
-                        if ubs_state == 2 or ubs_state == 0:
+        def remove_alarm(self, event, msg):
+            global alarm_list
+            EventMesh.debug_log("ddddddddddddddddddd:",msg)
+            idx = msg.get("idx")
+            EventMesh.debug_log("delete_here1-----{},{}:".format(idx,msg))
 
-                            if next_minute > current_minute:#开机时间大于当前时间 9:00 > = 8:00 
-                                interval_minute = next_minute - current_minute
-                                
-                                EventMesh.debug_log("开机距离下一次响铃的的分钟数:", interval_minute,next_minute)
-                            else:#8:00 9:00
-                                #7*60*24 7天一个周期 7*60*24 - 
-                                interval_minute = next_minute + (24*60-current_minute)
-                                EventMesh.debug_log("开机08888距离下一次响铃的的分钟数:", interval_minute,next_minute)
-
-                            #反向获取时间戳
-                            time = utime.localtime()
-                            EventMesh.debug_log("开机9获取utime的时间戳:", time)
-                            rtc_mktime = utime.mktime(time)-time[5]
-                            EventMesh.debug_log("开机10反向获取utime的mktime:", rtc_mktime)
-
-                            #加上下一次响铃需要的时间
-                            next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳
-                            EventMesh.debug_log("开机11下一次响铃的mktime:", next_alarm_mktime)
-
-                            #格式化时间戳,得到下一次闹钟的时间
-                            next_alarm_time = utime.localtime(next_alarm_mktime)
-                            EventMesh.debug_log("开机12下一次响铃的准确时间:", next_alarm_time)
-                            #将时间转换为rtc的格式
-                            data_l = [2021, 7, 9, 5, 12, 30, 0, 0]
-                            #给rtc时间赋值
-                            data_l[0] = next_alarm_time[0] #year
-                            data_l[1] = next_alarm_time[1] #month                    
-                            data_l[2] = next_alarm_time[2] #day                     
-                            data_l[4] = next_alarm_time[3] #hour               
-                            data_l[5] = next_alarm_time[4] #minute   
-                            data_e=tuple(data_l)
-                            EventMesh.debug_log("开机13将该时间转换为RTC元组:", data_e)
-                            
-                            self.rtc.register_callback(self._rtc_callback)
+            for i, alarm in enumerate(alarm_list):
+                EventMesh.debug_log("delete_here2-----{},{}:".format(i,alarm))
 
-                            FLAG = self.rtc.set_alarm(data_e)
-                            if FLAG == 0:
-                                EventMesh.debug_log("开机11成功设置rtc的到期时间:", data_e)
-                            else:
-                                EventMesh.debug_log("开机时设置rtc的到期时间失败:", data_e)
-                            self.rtc.enable_alarm(1)
-                            
-                            EventMesh.debug_log("结束时设置rtc的到期时间失败:", data_e)
-                            EventMesh.publish("open_power_on", 5)#静音关机
-                            return
-                        else:
-                            EventMesh.publish("set_rtc_alarm")
-                            #self.rtc.datetime([2023, 12, 1, 5, 5, 59, 30, 0])
-                            return
-            
-        EventMesh.publish("set_rtc_alarm")
-
-
-    def set_rtc_alarm(self,event,msg):
-        msg_data = EventMesh.publish("get_boot_off_time")
-        if msg_data != None:
-            power_offdata = msg_data[0]
-            start_hour = int(power_offdata["start_hour"])
-            start_min = int(power_offdata["start_min"])
-            end_hour = int(power_offdata["end_hour"])
-            end_min = int(power_offdata["end_min"])
-            off_on = int(power_offdata["poweroff_on"])
-            if off_on == 1:
-                next_minute = start_hour*60+start_min #10:11
+                if alarm["idx"] == idx:
+                    del alarm_list[i]
+                    EventMesh.debug_log("delete_here3-----",alarm_list)
+
+                    #删除闹钟后,对idx重新排序
+                    if alarm_list:
+                        for j in range(i,len(alarm_list)):
+                            alarm_list[j]["idx"] -= 1
+                            EventMesh.debug_log("delete_here4-----",alarm_list)
+
+            with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
+                ujson.dump(alarm_list,fd)
+
+
+        def get_alarm_indx(self,event,msg):
+            return self.idx
+
+        def _rtc_callback(self,args):
+            #设置下一个闹钟,定时开关机功能
+            msg_data = EventMesh.publish("get_boot_off_time")
+            if msg_data != None:
+                power_offdata = msg_data[0]
+                start_hour = int(power_offdata["start_hour"])
+                start_min = int(power_offdata["start_min"])
+                end_hour = int(power_offdata["end_hour"])
+                end_min = int(power_offdata["end_min"])
+                off_on = int(power_offdata["poweroff_on"])
 
-                start_total = start_hour*60+start_min #10:11
-                end_total = end_hour*60+end_min #10:11
                 rtc_now_time = self.rtc.datetime()
-                current_minute = rtc_now_time[4]*60 + rtc_now_time[5]#当前时间
-
-
-                minute_list = []
-                if start_total != current_minute:
-                    minute_list.append(start_total)#23*60=
-                if end_total != current_minute:
-                    minute_list.append(end_total)
-                minute_list.append(current_minute)#[927,927,930]
-                minute_list = sorted(minute_list)
-                current_index = minute_list.index(current_minute)
-                print("minute_list",minute_list,start_total,end_total,current_index,power_offdata)
-                
-                
-                next_index = current_index + 1
-                if next_index >= len(minute_list):
-                    next_minute = minute_list[0]
-                    print("07下一个闹钟的分钟数:", next_minute)
-                else:
-                    next_minute = minute_list[next_index]
-                    print("08下一个闹钟的分钟数:", next_minute)
+                current_minute = rtc_now_time[4]*60 + rtc_now_time[5]
+                end_min_total = end_hour*60+end_min
+                next_minute = start_hour*60+start_min #10:11
+                EventMesh.debug_log("off_on:{} {} {}".format(off_on,current_minute,next_minute))
+                if off_on != None:
+                    if off_on == 1:
+                        if end_min_total == current_minute:#结束的时间分钟等于关机时间分钟数则关机
+                            ubs_state = EventMesh.publish("get_usb")#'
+                            
+                            if ubs_state == 2 or ubs_state == 0:
 
-                print("minute_list1",minute_list,current_index,next_minute)
-                if next_minute > current_minute:
-                    interval_minute = next_minute - current_minute
-                    print("09距离下一次响铃的的分钟数:", interval_minute)#14 31 14 29 14 31 24*60-
-                else:
-                    interval_minute = (24*60 - current_minute) + next_minute
-                    print("10距离下一次响铃的的分钟数:", interval_minute)
-
-
-                #反向获取时间戳
-                time = utime.localtime()
-                EventMesh.debug_log("关机09获取utime的时间戳:", time)
-                time
-                rtc_mktime = utime.mktime(time)-time[5]
-                EventMesh.debug_log("关机10反向获取utime的mktime:", rtc_mktime)
-
-                #加上下一次响铃需要的时间
-                next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳
-                EventMesh.debug_log("关机11下一次响铃的mktime:", next_alarm_mktime)
-
-                #格式化时间戳,得到下一次闹钟的时间
-                next_alarm_time = utime.localtime(next_alarm_mktime)
-                EventMesh.debug_log("关机12下一次响铃的准确时间:", next_alarm_time)
-                #将时间转换为rtc的格式
-                data_l = [2021, 7, 9, 5, 12, 30, 0, 0]
-                #给rtc时间赋值
-                data_l[0] = next_alarm_time[0] #year
-                data_l[1] = next_alarm_time[1] #month                    
-                data_l[2] = next_alarm_time[2] #day                     
-                data_l[4] = next_alarm_time[3] #hour               
-                data_l[5] = next_alarm_time[4] #minute   
-                data_e=tuple(data_l)
-                EventMesh.debug_log("关机13将该时间转换为RTC元组:", data_e)
+                                if next_minute > current_minute:#开机时间大于当前时间 9:00 > = 8:00 
+                                    interval_minute = next_minute - current_minute
+                                    
+                                    EventMesh.debug_log("开机距离下一次响铃的的分钟数:", interval_minute,next_minute)
+                                else:#8:00 9:00
+                                    #7*60*24 7天一个周期 7*60*24 - 
+                                    interval_minute = next_minute + (24*60-current_minute)
+                                    EventMesh.debug_log("开机08888距离下一次响铃的的分钟数:", interval_minute,next_minute)
+
+                                #反向获取时间戳
+                                time = utime.localtime()
+                                EventMesh.debug_log("开机9获取utime的时间戳:", time)
+                                rtc_mktime = utime.mktime(time)-time[5]
+                                EventMesh.debug_log("开机10反向获取utime的mktime:", rtc_mktime)
+
+                                #加上下一次响铃需要的时间
+                                next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳
+                                EventMesh.debug_log("开机11下一次响铃的mktime:", next_alarm_mktime)
+
+                                #格式化时间戳,得到下一次闹钟的时间
+                                next_alarm_time = utime.localtime(next_alarm_mktime)
+                                EventMesh.debug_log("开机12下一次响铃的准确时间:", next_alarm_time)
+                                #将时间转换为rtc的格式
+                                data_l = [2021, 7, 9, 5, 12, 30, 0, 0]
+                                #给rtc时间赋值
+                                data_l[0] = next_alarm_time[0] #year
+                                data_l[1] = next_alarm_time[1] #month                    
+                                data_l[2] = next_alarm_time[2] #day                     
+                                data_l[4] = next_alarm_time[3] #hour               
+                                data_l[5] = next_alarm_time[4] #minute   
+                                data_e=tuple(data_l)
+                                EventMesh.debug_log("开机13将该时间转换为RTC元组:", data_e)
+                                
+                                self.rtc.register_callback(self._rtc_callback)
+
+                                FLAG = self.rtc.set_alarm(data_e)
+                                if FLAG == 0:
+                                    EventMesh.debug_log("开机11成功设置rtc的到期时间:", data_e)
+                                else:
+                                    EventMesh.debug_log("开机时设置rtc的到期时间失败:", data_e)
+                                self.rtc.enable_alarm(1)
+                                
+                                EventMesh.debug_log("结束时设置rtc的到期时间失败:", data_e)
+                                EventMesh.publish("open_power_on", 5)#静音关机
+                                return
+                            else:
+                                EventMesh.publish("set_rtc_alarm")
+                                #self.rtc.datetime([2023, 12, 1, 5, 5, 59, 30, 0])
+                                return
                 
-                self.rtc.register_callback(self._rtc_callback)
+            EventMesh.publish("set_rtc_alarm")
+
+
+        def set_rtc_alarm(self,event,msg):
+            msg_data = EventMesh.publish("get_boot_off_time")
+            if msg_data != None:
+                power_offdata = msg_data[0]
+                start_hour = int(power_offdata["start_hour"])
+                start_min = int(power_offdata["start_min"])
+                end_hour = int(power_offdata["end_hour"])
+                end_min = int(power_offdata["end_min"])
+                off_on = int(power_offdata["poweroff_on"])
+                if off_on == 1:
+                    next_minute = start_hour*60+start_min #10:11
+
+                    start_total = start_hour*60+start_min #10:11
+                    end_total = end_hour*60+end_min #10:11
+                    rtc_now_time = self.rtc.datetime()
+                    current_minute = rtc_now_time[4]*60 + rtc_now_time[5]#当前时间
+
+
+                    minute_list = []
+                    if start_total != current_minute:
+                        minute_list.append(start_total)#23*60=
+                    if end_total != current_minute:
+                        minute_list.append(end_total)
+                    minute_list.append(current_minute)#[927,927,930]
+                    minute_list = sorted(minute_list)
+                    current_index = minute_list.index(current_minute)
+                    print("minute_list",minute_list,start_total,end_total,current_index,power_offdata)
+                    
+                    
+                    next_index = current_index + 1
+                    if next_index >= len(minute_list):
+                        next_minute = minute_list[0]
+                        print("07下一个闹钟的分钟数:", next_minute)
+                    else:
+                        next_minute = minute_list[next_index]
+                        print("08下一个闹钟的分钟数:", next_minute)
 
-                FLAG = self.rtc.set_alarm(data_e)
-                if FLAG == 0:
-                    EventMesh.debug_log("关机11成功设置rtc的到期时间:", data_e)
+                    print("minute_list1",minute_list,current_index,next_minute)
+                    if next_minute > current_minute:
+                        interval_minute = next_minute - current_minute
+                        print("09距离下一次响铃的的分钟数:", interval_minute)#14 31 14 29 14 31 24*60-
+                    else:
+                        interval_minute = (24*60 - current_minute) + next_minute
+                        print("10距离下一次响铃的的分钟数:", interval_minute)
+
+
+                    #反向获取时间戳
+                    time = utime.localtime()
+                    EventMesh.debug_log("关机09获取utime的时间戳:", time)
+                    time
+                    rtc_mktime = utime.mktime(time)-time[5]
+                    EventMesh.debug_log("关机10反向获取utime的mktime:", rtc_mktime)
+
+                    #加上下一次响铃需要的时间
+                    next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳
+                    EventMesh.debug_log("关机11下一次响铃的mktime:", next_alarm_mktime)
+
+                    #格式化时间戳,得到下一次闹钟的时间
+                    next_alarm_time = utime.localtime(next_alarm_mktime)
+                    EventMesh.debug_log("关机12下一次响铃的准确时间:", next_alarm_time)
+                    #将时间转换为rtc的格式
+                    data_l = [2021, 7, 9, 5, 12, 30, 0, 0]
+                    #给rtc时间赋值
+                    data_l[0] = next_alarm_time[0] #year
+                    data_l[1] = next_alarm_time[1] #month                    
+                    data_l[2] = next_alarm_time[2] #day                     
+                    data_l[4] = next_alarm_time[3] #hour               
+                    data_l[5] = next_alarm_time[4] #minute   
+                    data_e=tuple(data_l)
+                    EventMesh.debug_log("关机13将该时间转换为RTC元组:", data_e)
+                    
+                    self.rtc.register_callback(self._rtc_callback)
+
+                    FLAG = self.rtc.set_alarm(data_e)
+                    if FLAG == 0:
+                        EventMesh.debug_log("关机11成功设置rtc的到期时间:", data_e)
+                    else:
+                        EventMesh.debug_log("关机时设置rtc的到期时间失败:", data_e)
+                    self.rtc.enable_alarm(1)
                 else:
-                    EventMesh.debug_log("关机时设置rtc的到期时间失败:", data_e)
-                self.rtc.enable_alarm(1)
-            else:
-                self.rtc.enable_alarm(0)
-                   
-
-class schoolclassManager(Abstract):#
-    def __init__(self):
-        # ['火星情报局', '一年级二班', '柠檬茶']
-        self.school_name = ''
-        self.class_name = ''
-        self.full_name = ''
-        tmp_data = EventMesh.publish("get_storage_config","school_name")
-        if tmp_data != None:
-            self.school_name = tmp_data
-        tmp_data = EventMesh.publish("get_storage_config","class_name")
-        if tmp_data != None:
-            self.class_name = tmp_data
-        tmp_data = EventMesh.publish("get_storage_config","full_name")
-        if tmp_data != None:
-            self.full_name = tmp_data    
+                    self.rtc.enable_alarm(0)
+                    
 
-        
+    class schoolclassManager(Abstract):#
+        def __init__(self):
+            # ['火星情报局', '一年级二班', '柠檬茶']
+            self.school_name = ''
+            self.class_name = ''
+            self.full_name = ''
+            tmp_data = EventMesh.publish("get_storage_config","school_name")
+            if tmp_data != None:
+                self.school_name = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","class_name")
+            if tmp_data != None:
+                self.class_name = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","full_name")
+            if tmp_data != None:
+                self.full_name = tmp_data    
 
-    def post_processor_after_instantiation(self):
-        EventMesh.subscribe("set_schoolname", self.set_school_name)#
-        EventMesh.subscribe("get_schoolname", self.get_school_name)
+            
 
-        EventMesh.subscribe("set_classname", self.set_classname)#
-        EventMesh.subscribe("get_classname", self.get_classname)
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_schoolname", self.set_school_name)#
+            EventMesh.subscribe("get_schoolname", self.get_school_name)
 
-        EventMesh.subscribe("set_fullname", self.set_full_name)#
-        EventMesh.subscribe("get_fullname", self.get_full_name)
+            EventMesh.subscribe("set_classname", self.set_classname)#
+            EventMesh.subscribe("get_classname", self.get_classname)
 
-    def set_school_name(self, event, msg): 
-        if msg != None:
-            if len(msg) != 0:
-                self.school_name = str(msg)
-                EventMesh.publish("set_storage_config",["school_name",str(msg)])
-        
+            EventMesh.subscribe("set_fullname", self.set_full_name)#
+            EventMesh.subscribe("get_fullname", self.get_full_name)
 
-    def get_school_name(self, event, msg):
-        if self.school_name:
-            return self.school_name
-        else:
-            return None
-    
-    def set_classname(self, event, msg): 
-        if msg != None:
-            if len(msg) != 0:
-                self.class_name = str(msg)
-                EventMesh.publish("set_storage_config",["class_name",str(msg)])
+        def set_school_name(self, event, msg): 
+            if msg != None:
+                if len(msg) != 0:
+                    self.school_name = str(msg)
+                    EventMesh.publish("set_storage_config",["school_name",str(msg)])
             
+
+        def get_school_name(self, event, msg):
+            if self.school_name:
+                return self.school_name
+            else:
+                return None
         
-    def get_classname(self, event, msg):
-        if self.class_name:
-            return self.class_name
-        else:
-            return None
-    def set_full_name(self, event, msg): 
-        if msg != None:
-            if len(msg) != 0:
-                self.full_name = str(msg)
-                EventMesh.publish("set_storage_config",["full_name",str(msg)])
-
-    def get_full_name(self, event, msg):
-        if self.full_name:
-            return self.full_name
-        else:
-            return None
\ No newline at end of file
+        def set_classname(self, event, msg): 
+            if msg != None:
+                if len(msg) != 0:
+                    self.class_name = str(msg)
+                    EventMesh.publish("set_storage_config",["class_name",str(msg)])
+                
+            
+        def get_classname(self, event, msg):
+            if self.class_name:
+                return self.class_name
+            else:
+                return None
+        def set_full_name(self, event, msg): 
+            if msg != None:
+                if len(msg) != 0:
+                    self.full_name = str(msg)
+                    EventMesh.publish("set_storage_config",["full_name",str(msg)])
+
+        def get_full_name(self, event, msg):
+            if self.full_name:
+                return self.full_name
+            else:
+                return None
\ No newline at end of file
diff --git a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr_d15.py b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr_d15.py
new file mode 100644 (file)
index 0000000..3eeb0c5
--- /dev/null
@@ -0,0 +1,6045 @@
+from common import Abstract, LogAdapter
+import EventMesh
+import usocket
+import ql_fs
+import ujson
+import _thread
+import modem
+import utime
+import sim
+import net
+import dataCall
+import checkNet
+import osTimer
+import constants
+import sms
+from common import Lock, Abstract, LogAdapter
+#from location import GPS, GPSMatch,CellLocator
+from misc import USB, Power, ADC
+from machine import ExtInt, Pin,Timer,RTC,UART
+import EventMesh
+import usys
+import audio
+from machine import I2C
+from Gsensor import SC7A20
+import pm
+import ure
+import urandom
+try :
+    from Hsensor import GH3018
+except Exception as e:
+    EventMesh.debug_log("Hsensor none GH3018:{}".format(e))   
+#
+try :
+    from Hsensor import HX3918
+except Exception as e:
+    EventMesh.debug_log("Hsensor none HX3918:{}".format(e))    
+from machine import RTC
+import quecgnss
+import wifiScan
+import math
+import voiceCall
+from misc import PWM
+from queue import Queue
+if EventMesh.model == "D15":
+    from led_d15 import led_mode,open_led_green,close_led_green,open_led_red,close_led_red,close_led_white
+    heartbeat_time = 7*60 #心跳时间
+
+    def get_autoblood_value():#血压值
+        data = RTC().datetime()
+        hour = int(data[4])
+        blood_Maxvalue = 0
+        blood_Minvalue = 0
+        if hour >= 6 and hour <= 10:
+            random_numMax = urandom.randint(0, 30)
+            random_numMin = urandom.randint(0, 20)
+            blood_Maxvalue = 120+random_numMax
+            blood_Minvalue = 75+random_numMin
+
+            print("get_autoblood_value 6 -10",blood_Maxvalue,blood_Minvalue)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        elif hour > 10 and hour <= 14:#10-14(10,14]
+            random_numMax = urandom.randint(0, 20)
+            random_numMin = urandom.randint(0, 25)
+            blood_Maxvalue = 115+random_numMax
+            blood_Minvalue = 60+random_numMin
+            print("get_autoblood_value 10 -14",blood_Maxvalue,blood_Minvalue)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        elif hour > 14 and hour <= 18:#14-18
+            random_numMax = urandom.randint(0, 25)
+            random_numMin = urandom.randint(0, 15)
+            blood_Maxvalue = 115+random_numMax
+            blood_Minvalue = 70+random_numMin
+
+            print("get_autoblood_value 14 -18",blood_Maxvalue,blood_Minvalue)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        elif hour > 2 and hour < 6:#2-6
+            random_numMax = urandom.randint(0, 30)
+            random_numMin = urandom.randint(0, 20)
+            blood_Maxvalu = 105+random_numMax
+            blood_Minvalue = 65+random_numMin
+
+            
+            print("get_autoblood_value 2 -6",blood_Maxvalue,blood_Minvalue)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        else:#18-2 19 20 21 22 23 1 2
+            random_numMax = urandom.randint(0, 30)
+            random_numMin = urandom.randint(0, 20)
+            blood_Maxvalue = 100+random_numMax
+            blood_Minvalue = 60+random_numMin
+            print("get_autoblood_value 18 -2",blood_Maxvalue,blood_Minvalue)
+        return [blood_Maxvalue,blood_Minvalue]
+
+    def get_blood_sugar_value():#血糖值
+        data = RTC().datetime()
+        hour = int(data[4])
+        blood_sugar = 0
+        if (hour >= 6 and hour <= 8) or (hour >= 12 and hour <= 13) or (hour >= 18 and hour <= 19):#6-8 12-13 18-19 
+            random_value = urandom.randint(39, 61)
+            blood_sugar = random_value/10
+            print("get_blood_sugar_value 6 -10",blood_sugar)
+            # return [self.blood_Maxvalue,self.blood_Minvalue]
+        elif (hour > 8 and hour <= 9) or (hour >= 14 and hour <= 15) or (hour >= 20 and hour <= 21):#8-9 14-15 20-21
+            random_value = urandom.randint(67, 90)
+            blood_sugar = random_value/10
+            print("get_blood_sugar_value 10 -14",blood_sugar)
+        else:#18-2 19 20 21 22 23 1 2 10-11 16-17 21-22
+            random_value = urandom.randint(39, 78)
+            blood_sugar = random_value/10
+            print("get_blood_sugar_value 18 -2",blood_sugar)
+        return blood_sugar
+
+
+
+
+    class PhoneVolumeLevelManager(Abstract):
+        def __init__(self):
+            self.level = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("push_add_phonering_level", self.add)
+            EventMesh.subscribe("push_reduce_phonering_level", self.reduce)
+            EventMesh.subscribe("get_phonering_level", self.get)
+
+        def add(self, event, msg):
+            if self.level < 7:
+                self.level = self.level + 1
+
+        def reduce(self, event, msg):
+            if self.level > 0:
+                self.level = self.level - 1
+
+        def get(self, event=None, msg=None):
+            return self.level
+
+    class MsgVolumeLevelManager(Abstract):
+        def __init__(self):
+            self.level = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("push_add_msgvolume_level", self.add)
+            EventMesh.subscribe("push_reduce_msgvolume_level", self.reduce)
+            EventMesh.subscribe("get_msgvolume_level", self.get)
+
+        def add(self, event, msg):
+            if self.level < 7:
+                self.level = self.level + 1
+
+        def reduce(self, event, msg):
+            if self.level > 0:
+                self.level = self.level - 1
+
+        def get(self, event=None, msg=None):
+            return self.level
+
+    class AlarmVolumeLevelManager(Abstract):
+        def __init__(self):
+            self.level = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("push_add_alarmvolume_level", self.add)
+            EventMesh.subscribe("push_reduce_alarmvolume_level", self.reduce)
+            EventMesh.subscribe("get_alarmvolume_level", self.get)
+
+        def add(self, event, msg):
+            if self.level < 7:
+                self.level = self.level + 1
+
+        def reduce(self, event, msg):
+            if self.level > 0:
+                self.level = self.level - 1
+
+        def get(self, event=None, msg=None):
+            return self.level
+            
+    class StopwatchManager(Abstract):
+        def __init__(self):
+            self.level = 0
+            self.ms_value = 0
+            self.sec_value = 0
+            self.min_value = 0
+            self.timer = Timer(Timer.Timer1)
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("stopwatch_start", self.start)
+            EventMesh.subscribe("stopwatch_stop", self.paused)
+            EventMesh.subscribe("stopwatch_reset", self.reset)
+            EventMesh.subscribe("get_stopwatch_ms", self.get_ms)
+            EventMesh.subscribe("get_stopwatch_sec", self.get_sec)
+            EventMesh.subscribe("get_stopwatch_min", self.get_min)
+
+        def start(self, event, msg):        
+            self.timer.start(period=100, mode=self.timer.PERIODIC, callback=self.fun)
+        
+        def paused(self, event, msg):        
+            self.timer.stop()
+        
+        def reset(self, event, msg):
+            self.timer.stop()
+
+            self.sec_value = 0
+            self.min_value = 0
+            self.ms_value = 0
+
+        def fun(self):
+            self.ms_value += 1
+            if self.ms_value > 9:
+                self.ms_value = 0   
+                self.sec_value += 1
+            if self.sec_value > 60:
+                self.sec_value = 0
+                self.min_value += 1
+            if self.min_value > 60:
+                self.timer.stop()
+
+        def get_ms(self, event=None, msg=None):
+            return self.ms_value
+
+        def get_min(self, event=None, msg=None):
+            return self.min_value
+
+        def get_sec(self, event=None, msg=None):
+            return self.sec_value
+
+    class CountdownManager(Abstract):
+        def __init__(self):
+            self.sec = 0
+            self.min = 0
+            self.hour = 0
+            self.timer = osTimer()
+            self.total = 0
+            self.time_cb = 0
+            self.time_play = 0
+            self.total_sec = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("add_countdown_sec", self.add_sec)
+            EventMesh.subscribe("reduce_countdown_sec", self.reduce_sec)
+            EventMesh.subscribe("add_countdown_min", self.add_min)
+            EventMesh.subscribe("reduce_countdown_min", self.reduce_min)
+            EventMesh.subscribe("add_countdown_hour", self.add_hour)
+            EventMesh.subscribe("reduce_countdown_hour", self.reduce_hour)
+            EventMesh.subscribe("get_countdown_sec", self.get_sec)
+            EventMesh.subscribe("get_countdown_min", self.get_min)
+            EventMesh.subscribe("get_countdown_hour", self.get_hour)
+
+            EventMesh.subscribe("set_countdown_off_state", self.set_countdown_off_state)
+            EventMesh.subscribe("get_countdown_off_state", self.get_countdown_off_state)
+
+
+            EventMesh.subscribe("set_countdown_all_time", self.set_countdown_all_time)
+            EventMesh.subscribe("get_countdown_all_time", self.get_countdown_all_time)
+
+            EventMesh.subscribe("countdown_end_cb", self.countdown_end_cb)
+
+            EventMesh.subscribe("reset_time_countdown",self.reset)
+
+        def set_countdown_all_time(self, event, msg):
+            self.total = msg[0]
+            self.total_sec = msg[1]
+            # EventMesh.debug_log("self.total:{} self.total_sec:{}".format(self.total,self.total_sec))
+
+
+        def get_countdown_all_time(self, event, msg):
+            return self.total
+        
+        def set_countdown_off_state(self, event, msg):
+
+            self.time_cb = msg[0]
+            self.time_play = msg[1]
+            # EventMesh.debug_log("self.time_cb:{} self.total_sec:{}".format(self.time_cb,self.time_play))
+
+
+        def get_countdown_off_state(self, event, msg):
+            return [self.time_cb,self.time_play]
+        
+        def countdown_end_cb(self, event, msg):
+            
+            if self.time_cb == 1 and self.time_play == 1:
+                date_tmp = utime.localtime()
+                time_tmp = utime.mktime(date_tmp) 
+                reduce = time_tmp- self.total_sec
+                EventMesh.debug_log("self.time_cb:{} self.time_play:{} self.total:{} self.total_sec:{}".format(self.time_cb,self.time_play, self.total,self.total_sec))
+                self.total = self.total - reduce
+                if self.total <= 0:
+                    self.total = 0
+                    self.time_cb = 0
+                    self.time_play = 0
+                    self.sec = 0
+                    self.min = 0
+                    self.hour = 0
+                    
+                    EventMesh.publish("load_screen", {"screen": "countdown_end"})
+                    return
+                self.total_sec = time_tmp
+
+
+        def add_sec(self, event, msg):
+            if self.sec < 59:
+                self.sec = self.sec + 1
+
+        def reduce_sec(self, event, msg):
+            if self.sec > 0:
+                self.sec = self.sec - 1
+
+        def add_min(self, event, msg):
+            if self.min < 59:
+                self.min = self.min + 1
+
+        def reduce_min(self, event, msg):
+            if self.min > 0:
+                self.min = self.min - 1
+
+        def add_hour(self, event, msg):
+            if self.hour < 99:
+                self.hour = self.hour + 1
+
+        def reduce_hour(self, event, msg):
+            if self.hour > 0:
+                self.hour = self.hour - 1
+
+        def get_sec(self, event=None, msg=None):
+            return self.sec
+
+        def get_min(self, event=None, msg=None):
+            return self.min
+
+        def get_hour(self, event=None, msg=None):
+            return self.hour
+        
+
+        
+        def reset(self, event=None, msg=None):
+            self.hour = 0
+            self.min = 0
+            self.sec = 0
+        
+        
+
+    BATTERY_OCV_TABLE = {
+        "nix_coy_mnzo2": {
+            55: {
+                4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
+                3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
+            },
+            20: {
+                4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
+                3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
+            },
+            0: {
+                4290: 100, 4237: 95, 4179: 90, 4123: 85, 4070: 80, 4020: 75, 3963: 70, 3919: 65, 3882: 60, 3847: 55,
+                3818: 50, 3794: 45, 3772: 40, 3752: 35, 3733: 30, 3716: 25, 3699: 20, 3677: 15, 3652: 10, 3629: 5, 3400: 0,
+            },
+        },
+    }
+
+
+
+    class Battery(object):
+        """This class is for battery info.
+
+        This class can get battery voltage and energy.
+        if adc_args is not None, use cbc to read battery
+
+        adc_args: (adc_num, adc_period, factor)
+
+            adc_num: ADC channel num
+            adc_period: Cyclic read ADC cycle period
+            factor: calculation coefficient
+        """
+
+        def __init__(self, adc_args=None, chrg_gpion=None, stdby_gpion=None):
+            self.__energy = 100
+            self.__temp = 55
+
+            # ADC params
+            self.__adc = None
+            if adc_args:
+                self.__adc_num, self.__adc_period, self.__factor = adc_args
+                if not isinstance(self.__adc_num, int):
+                    raise TypeError("adc_args adc_num is not int number.")
+                if not isinstance(self.__adc_period, int):
+                    raise TypeError("adc_args adc_period is not int number.")
+                if not isinstance(self.__factor, float):
+                    raise TypeError("adc_args factor is not int float.")
+                self.__adc = ADC()
+
+            # Charge params
+            self.__charge_callback = None
+            self.__charge_status = None
+            self.__chrg_gpion = chrg_gpion
+            self.__stdby_gpion = stdby_gpion
+            self.__chrg_gpio = None
+            self.__stdby_gpio = None
+            self.__chrg_exint = None
+            self.__stdby_exint = None
+            if self.__chrg_gpion is not None and self.__stdby_gpion is not None:
+                self.__init_charge()
+
+        def __chrg_callback(self, args):
+            self.__update_charge_status()
+            if self.__charge_callback is not None:
+                self.__charge_callback(self.__charge_status)
+
+        def __stdby_callback(self, args):
+            self.__update_charge_status()
+            if self.__charge_callback is not None:
+                self.__charge_callback(self.__charge_status)
+
+        def __update_charge_status(self):
+            if self.__chrg_gpio.read() == 1 and self.__stdby_gpio.read() == 1:
+                self.__charge_status = 0
+            elif self.__chrg_gpio.read() == 0 and self.__stdby_gpio.read() == 1:
+                self.__charge_status = 1
+            elif self.__chrg_gpio.read() == 1 and self.__stdby_gpio.read() == 0:
+                self.__charge_status = 2
+            else:
+                raise TypeError("CHRG and STDBY cannot be 0 at the same time!")
+
+        def __init_charge(self):
+            self.__chrg_gpio = Pin(self.__chrg_gpion, Pin.IN, Pin.PULL_DISABLE)
+            self.__stdby_gpio = Pin(self.__stdby_gpion, Pin.IN, Pin.PULL_DISABLE)
+            self.__chrg_exint = ExtInt(self.__chrg_gpion, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.__chrg_callback)
+            self.__stdby_exint = ExtInt(self.__stdby_gpion, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU,
+                                        self.__stdby_callback)
+            self.__chrg_exint.enable()
+            self.__stdby_exint.enable()
+            self.__update_charge_status()
+
+        def __get_soc_from_dict(self, key, volt_arg):
+            """Get battery energy from map"""
+            if key in BATTERY_OCV_TABLE["nix_coy_mnzo2"]:
+                volts = sorted(BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].keys(), reverse=True)
+                pre_volt = 0
+                volt_not_under = 0  # Determine whether the voltage is lower than the minimum voltage value of soc.
+                for volt in volts:
+                    if volt_arg > volt:
+                        volt_not_under = 1
+                        soc1 = BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].get(volt, 0)
+                        soc2 = BATTERY_OCV_TABLE["nix_coy_mnzo2"][key].get(pre_volt, 0)
+                        break
+                    else:
+                        pre_volt = volt
+                # EventMesh.debug_log("__get_soc_from_dict:{}".format(soc2 - (soc2 - soc1) * (pre_volt - volt_arg) // (pre_volt - volt)))
+                if pre_volt == 0:  # Input Voltarg > Highest Voltarg
+                    return soc1
+                elif volt_not_under == 0:
+                    return 0
+                else:
+                    return soc2 - (soc2 - soc1) * (pre_volt - volt_arg) // (pre_volt - volt)
+
+        def __get_soc(self, temp, volt_arg, bat_type="nix_coy_mnzo2"):
+            """Get battery energy by temperature and voltage"""
+            if bat_type == "nix_coy_mnzo2":
+                if temp > 30:
+                    return self.__get_soc_from_dict(55, volt_arg)
+                elif temp < 10:
+                    return self.__get_soc_from_dict(0, volt_arg)
+                else:
+                    return self.__get_soc_from_dict(20, volt_arg)
+
+        def __get_power_vbatt(self):
+            return int(sum([Power.getVbatt() for i in range(100)]) / 100)
+
+        def __get_adc_vbatt(self):
+            self.__adc.open()
+            utime.sleep_ms(self.__adc_period)
+            adc_list = list()
+            for i in range(self.__adc_period):
+                adc_list.append(self.__adc.read(self.__adc_num))
+                utime.sleep_ms(self.__adc_period)
+            adc_list.remove(min(adc_list))
+            adc_list.remove(max(adc_list))
+            adc_value = int(sum(adc_list) / len(adc_list))
+            self.__adc.close()
+            vbatt_value = adc_value * (self.__factor + 1)
+            return vbatt_value
+
+        def set_temp(self, temp):
+            """Set now temperature."""
+            if isinstance(temp, int) or isinstance(temp, float):
+                self.__temp = temp
+                return True
+            return False
+
+        def get_voltage(self):
+            """Get battery voltage"""
+            if self.__adc is None:
+                return self.__get_power_vbatt()
+            else:
+                return self.__get_adc_vbatt()
+
+        def get_energy(self,volt_arg ):
+            """Get battery energy"""
+            if( volt_arg == None) :
+                volt_arg = self.get_voltage()
+            self.__energy = self.__get_soc(self.__temp, volt_arg)
+            # EventMesh.debug_log("get_energy:volt_arg {} __energy{}".format(volt_arg,self.__energy))
+            return self.__energy
+
+        def set_charge_callback(self, charge_callback):
+            if self.__chrg_gpion is not None and self.__stdby_gpion is not None:
+                if callable(charge_callback):
+                    self.__charge_callback = charge_callback
+                    return True
+            return False
+
+        def get_charge_status(self):
+            return self.__charge_status
+
+    class BatteryManager(Abstract):
+        def __init__(self):
+            """电池管理器"""
+            self.battery = Battery()
+            self.low_battery = False
+
+        def post_processor_after_instantiation(self):
+            """订阅此类所有的事件到 EventMesh中"""
+            EventMesh.subscribe("get_battery", self.get_battery)
+
+        def get_battery(self, event=None, msg=None):
+            battery = self.battery.get_energy(msg)
+            return battery
+
+        def get_voltage(self, event=None, msg=None):
+            voltage = self.battery.get_voltage()
+            return voltage
+
+    class ConfigStoreManager(Abstract):
+        """
+        持久化落盘存储
+        """
+
+        def __init__(self):
+            self.file_name = "/usr/conf_store.json"
+            self.lock = Lock()
+            self.map = dict()
+
+        def post_processor_after_instantiation(self):
+            if ql_fs.path_exists(self.file_name):
+                self.map = ql_fs.read_json(self.file_name)
+            else:
+                self.__store()
+            EventMesh.subscribe("persistent_config_get", self.__read)
+            EventMesh.subscribe("persistent_config_store", self.__store)
+
+        def __read(self, event, msg):
+            with self.lock:
+                return self.map.get(msg)
+
+        def __store(self, event=None, msg=None):
+            if msg is None:
+                msg = dict()
+            with self.lock:
+                self.map.update(msg)
+                ql_fs.touch(self.file_name, self.map)
+            
+    class sosInfoCallManager(Abstract):
+        # 通讯录
+        def __init__(self):
+            pass
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_sos_info_call", self.set_sos_info_call)
+
+        def set_sos_info_call(self, event, msg):
+            hangup_mode = EventMesh.publish("get_hangup_mode")
+            if hangup_mode == 1:
+                EventMesh.publish("set_sos_flag",0)
+                EventMesh.publish("set_sos_num",0)
+                EventMesh.publish("set_hangup_mode",0)
+            EventMesh.debug_log('hangup_mode disconnect',hangup_mode)
+            sos_flag = EventMesh.publish("get_sos_flag")
+            EventMesh.debug_log('voicecall sos_flag',sos_flag)
+            if sos_flag == 0 :
+                EventMesh.publish("set_sos_num",0)
+            else:
+                num = EventMesh.publish("get_sos_num")
+                number = EventMesh.publish("get_dial_sos_number")
+                if number != None:
+                    if len(number) > 0:
+                        if num == None:
+                            num = 0
+                        num+=1
+                        num_len = 0
+
+                        if len(number) == 1:
+                            num_len = len(number)
+                        elif len(number) == 2:
+                            num_len = len(number)+1
+                        elif len(number) == 3:
+                            num_len = len(number)+2  
+                        # EventMesh.debug_log("number:{} number_len :{} num:{} num_len:{}".format(number,len(number),num,num_len))
+                        if num > num_len :
+                            if len(number) == 1:
+                                number1 = str(number[0])
+                                sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+                            elif len(number) == 2:
+                                number1 = str(number[0])
+                                sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+
+                                number2 = str(number[1])
+                                sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
+                            elif len(number) == 3:
+                                number1 = str(number[0])
+                                sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+                                number2 = str(number[1])
+                                sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
+                                number3 = str(number[2])
+                                sms.sendPduMsg(number3, '我需要你的帮助', 'UCS2')
+                            EventMesh.publish("set_sos_flag",0)
+                            EventMesh.publish("set_sos_num",0)
+                        else:
+                        # EventMesh.debug_log("number:{} number_len :{}".format(number,len(number)))
+                            EventMesh.publish("set_sos_num",num)
+                            if len(number) == 1:
+                                if len(number[0]) != 0:
+                                    EventMesh.publish("set_callnumer_cb",number[0])
+                                    EventMesh.debug_log("phone 1")
+                            elif len(number) == 2:
+                                if num == 1 or num == 3:
+                                    if len(number[1]) != 0:
+                                        EventMesh.debug_log("phone 2")
+                                        EventMesh.publish("set_callnumer_cb",number[1])
+                                elif num == 2:
+                                    if len(number[0]) != 0:
+                                        EventMesh.debug_log("phone 3")
+                                        EventMesh.publish("set_callnumer_cb",number[0])
+                            elif len(number) == 3:
+                                if num == 1 or num == 4:
+                                    if len(number[1]) != 0:
+                                        EventMesh.publish("set_callnumer_cb",number[1])
+                                        EventMesh.debug_log("phone 4")
+                                elif num == 2 or num == 5:
+                                    if len(number[2]) != 0:
+                                        EventMesh.debug_log("phone 5")
+                                        EventMesh.publish("set_callnumer_cb",number[2])
+                                elif num == 3:
+                                    if len(number[0]) != 0:
+                                        EventMesh.debug_log("phone 6")
+                                        EventMesh.publish("set_callnumer_cb",number[0])   
+    WL_timer = osTimer()   
+    def WL_timer_cb(*args):   
+        get_call = EventMesh.publish("get_call_state") 
+        if get_call == 2:#只有拨进来才给接听
+            EventMesh.publish("answer_call_event")#接听电话
+    def voice_callback(args):
+        EventMesh.debug_log('voicecall iinfo:{}'.format(args))
+        if args[0] == 10:
+                get_UI_high_priority = EventMesh.publish("get_UI_high_priority")#如果在拨出去或者通话中屏蔽来电
+                if get_UI_high_priority == 1:
+                    EventMesh.publish("set_interrup_incall",1)
+                    return
+                EventMesh.debug_log('voicecall incoming call, PhoneNO.: ', args[6])
+                size_len = len(str(args[6]))
+                tmp = []
+                tmp = args[6]
+                find_num = tmp[0]
+                b = tmp[0].isdigit()#判断是否不是数字开头 暂时不用 因为截取了+判断不了 判断号码是否大于11位数,如果大于11位数 并且第一个字符是数字就按照最后11位做存储
+
+                if b == True and size_len > 11:
+                    tmp = tmp[size_len-11:]
+                WLKEY = EventMesh.publish("get_storage_config","WLKEY") 
+                if WLKEY == "1" or WLKEY == "2":#开启了白名单
+                    on_list_flag = 0
+                    phonebook = EventMesh.publish("get_phonebook_list")
+                    phonebook_list = phonebook[1]
+                    EventMesh.debug_log("voice_callback:phonebook_list{}".format(phonebook_list))
+                    try:
+                        for value in phonebook_list.values():
+                            if value == args[6]:
+                                on_list_flag = 1
+                                break
+                    except Exception as e:
+                        usys.print_exception(e)
+                    EventMesh.debug_log("voice_callback:on_list_flag{}".format(on_list_flag))
+                    if on_list_flag == 1:#在白名单里
+                        if WLKEY == "2":
+                            WL_timer.start(30000, 0, WL_timer_cb)
+                    else:
+                        EventMesh.debug_log("voice_callback:不在白名单中,挂断")
+                        voiceCall.callEnd()
+                        return 
+                viode_state = EventMesh.publish("get_video_state")
+                fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
+                if viode_state != 0 or fall_down != 0:
+                    voiceCall.callEnd()
+                    return
+
+                EventMesh.publish("set_call_state",2) 
+                EventMesh.publish("dialin_call_event")#电话拨进响铃
+                # EventMesh.publish("load_screen", {"screen": "incoming_call","meta":str(tmp)})
+
+        elif args[0] == 11:
+                EventMesh.publish("set_UI_high_priority",0)
+                sos_flag = EventMesh.publish("get_sos_flag")
+                if sos_flag == 1:
+                    sos_flag = 0
+                    EventMesh.publish("set_sos_flag",0)
+
+                EventMesh.debug_log('voicecall connected, PhoneNO.: ', args[6])
+                size_len = len(str(args[6]))
+                tmp = []
+                tmp = args[6]
+                find_num = tmp[0]
+                b = tmp[0].isdigit()#判断是否不是数字开头 暂时不用 因为截取了+判断不了
+                if b == True and size_len > 11:
+                    tmp = tmp[size_len-11:]
+                EventMesh.publish("set_call_state",3) 
+                # EventMesh.publish("load_screen", {"screen": "on_call","meta":str(tmp)})
+
+        elif args[0] == 12:
+                set_interrup_call = EventMesh.publish("get_interrup_incall")#打断这次不需要来电的ui事件 以免通话中退出当前界面进不去了
+                if set_interrup_call == 1:
+                    EventMesh.publish("set_interrup_incall",0)
+                    return
+
+                EventMesh.publish("set_interrup_incall",0)
+                EventMesh.publish("set_UI_high_priority",0)
+                
+
+                
+                
+                EventMesh.publish("set_sos_info_call")  
+                flag = EventMesh.publish("get_call_state") 
+                if flag == 2:
+                    EventMesh.publish("stop_led_timer")#设置参数
+                    EventMesh.publish("close_timer_all")#
+                EventMesh.publish("set_call_state",0) 
+                EventMesh.debug_log('voicecall disconnect end')
+                
+
+        elif args[0] == 13:
+                EventMesh.debug_log('voicecall is waiting, PhoneNO.: ', args[6])
+        elif args[0] == 14:
+
+                EventMesh.debug_log('voicecall dialing, PhoneNO.: ', args[6])
+                EventMesh.publish("set_UI_high_priority",0)
+                EventMesh.publish("set_call_state",1) 
+                # EventMesh.publish("load_screen", {"screen": "dialing"})
+
+                
+        elif args[0] == 15:
+                EventMesh.debug_log('voicecall alerting, PhoneNO.: ', args[6])
+                EventMesh.publish("set_call_state",1) 
+                
+        elif args[0] == 16:
+                EventMesh.debug_log('voicecall holding, PhoneNO.: ', args[6])
+
+    class DeviceInfoManager(Abstract):
+        
+        """
+            设备信息管理
+        """
+
+        def __init__(self):
+
+            self.DeviceInfo_queue = Queue()
+            _thread.stack_size((9+6)*1024)
+            _thread.start_new_thread(self.DeviceInfo_queue_thread, ())
+            _thread.stack_size(8*1024)
+            self.boot_time_count = 0
+            EventMesh.subscribe("publish_message_event_DeviceInfo",self.publish_message_event_DeviceInfo)
+            self.key = ""
+            self.imei = ""
+            self.cid = "ETEST20221014010"
+            self.imsi = ""
+            self.password = "000000"
+            #self.__city = None
+            #self.__location = None
+            self.timer_push_schedule = osTimer()
+            self.timer_pusht_test = osTimer()
+            
+            #self.battery_push_schedule = osTimer()
+            self.check_battery_list = []
+            
+            self.step = [0,0,0,0]
+            self.timer_push=0
+            self.timer_push_tmp=60
+            self.PING = "0" #绑定状态
+            self.connect = 0 #服务器连接状态
+            self.KA_time = 0
+            self.HR_time = 0
+            self.SENSOR_time = 0
+            self.HR_state = 0
+            self.HR_Onestate = 0
+            self.get_hr_state = 0
+            self.get_spo2_state = 0
+            self.set_hsenor_crt = 0
+            self.HR_OneTime = 0
+            self.Hr_Need_Open = 0
+            self.Spo2_Need_Open = 0
+            self.bat_time = 0
+            self.vbat_full_flag = 0
+            self.clear_step = 0
+            self.test = 0
+            self.old_time = 0
+            self.UD_time = 0
+            self.upload_time = 0
+            self.UD_timeout = 7*60
+
+            self.temp_time = 0
+            self.temp_state = 0
+            self.temp_one_state = 0
+            self.temp_warning = 0
+
+            self.bg_times = 0
+
+            self.bp_timeSecond = 0
+            self.bpauto_state = 0
+
+            self.spo2_timeSecond = 0
+            self.spo2auto_state = 0
+
+            self.vbat_count = 0
+
+            self.vbat_buf=[]
+
+            self.curr_battery_level = 4200
+            self.bat_count = 0
+
+            self.mearsure_btn = 0
+            self.mearsure_timer = 0
+
+            self.old_hr_time = 0
+            self.old_spo2_time = 0
+
+            self.no_smi_count = 0
+            self.no_smi_state = 0
+
+            self.old_bp_time = 0
+
+            self.medicine_count = 0
+            self.medicine_flag  = 0
+            self.medicine_oldtotalmin = 0
+            
+            self.wakeup_flag = 0
+            self.wakeup_count = 0
+            self.wakeup_oldtotalmin = 0
+
+            self.sleep_flag = 0
+            self.sleep_count = 0
+            self.sleep_oldtotalmin = 0
+
+            self.reset_flag = 0
+            self.reset_count = 0
+            self.reset_oldtotalmin = 0
+
+            self.home_flag = 0
+            self.home_count = 0
+            self.home_oldtotalmin = 0
+
+            self.normal_flag = 0
+            self.normal_count = 0
+            self.normal_oldtotalmin = 0
+            
+            self.charge_full_count = 0
+            self.GPS_step_t = 0#记录步数
+            self.usb = USB()
+            self.usb.setCallback(self.usb_event_cb)
+            self.log = LogAdapter(self.__class__.__name__)
+            self.rtc = RTC()
+            self.aud = audio.Audio(0)
+            EventMesh.debug_log("DeviceInfoManager:1")
+            self.gsensor = SC7A20()
+            EventMesh.debug_log("DeviceInfoManager:1.0")
+            self.gsensor.activate()
+            EventMesh.debug_log("DeviceInfoManager:1.1")
+            self.gsensor.init()
+            EventMesh.debug_log("DeviceInfoManager:2")
+            self.gsensor.set_callback(self.gsensor_cb)
+            try :
+                self.hsensor = HX3918()
+                
+            except Exception as e:
+                EventMesh.debug_log("Hsensor none HX3918:{}".format(e))   
+            try :
+                self.hsensor = GH3018()
+            except Exception as e:
+                EventMesh.debug_log("Hsensor none GH3018:{}".format(e))   
+            #
+            self.hsensor.activate()
+            self.hsensor.init()
+            self.hsensor.close()
+            try :
+                self.hsensor.set_sar(1)
+            except Exception as e:
+                EventMesh.debug_log("Hsensor none set_sar:{}".format(e)) 
+            self.old_temp_time = 0
+            # #EventMesh.debug_log("hsensor.open_heart:%d\r\n"%(self.hsensor.open_heart()))
+            EventMesh.debug_log("DeviceInfoManager:3")
+            self.i2c0 = I2C(I2C.I2C0, I2C.FAST_MODE)
+            self.stop_temp( None, None)
+            self.dev_state = 0
+            self.wear = 1
+            self.BG_state = 0
+            self.old_bg_time = 0
+
+            self.pull_time = 0
+
+            self.drink_time = 0
+
+            self.alarm_count = 0
+            self.alarm_flag = 0
+
+            self.time_count = 0
+            
+            self.auto_spo2_count = 0
+
+            self.auto_hr_count = 0
+
+            self.auto_temp_count = 0
+
+        
+
+        def post_processor_after_instantiation(self):
+            EventMesh.debug_log("post_processor_after_instantiation:1")
+            """订阅此类所有的事件到 EventMesh中"""
+            voiceCall.setCallback(voice_callback)
+            EventMesh.subscribe("screen_get_ope", self.get_device_ope)
+            EventMesh.subscribe("screen_get_sig", self.get_signal)
+            EventMesh.subscribe("screen_get_time", self.get_time)
+            EventMesh.subscribe("about_get_imei", self.get_imei)
+            EventMesh.subscribe("about_get_iccid", self.get_ic_cid)
+            EventMesh.subscribe("get_sim_Status", self.get_sim_Status)
+            EventMesh.subscribe("about_get_phonenum", self.get_phone_num)
+            EventMesh.subscribe("screen_get_battery", self.get_battery)
+            EventMesh.subscribe("set_curr_battery_level", self.set_curr_battery_level)
+            EventMesh.subscribe("get_curr_battery_level", self.get_curr_battery_level)
+            EventMesh.subscribe("get_fw_version", self.get_device_fw_version)
+            EventMesh.subscribe("get_standby_time", self.get_standby_time)
+            EventMesh.subscribe(constants.EVENT.GET_STEP, self.get_step_count)
+            EventMesh.subscribe("sim_slot_get", self.sim_slot_get)
+            EventMesh.subscribe("sim_slot_switch", self.sim_slot_switch)
+            EventMesh.subscribe(constants.EVENT.GET_KEY, self.get_key)
+            EventMesh.subscribe(constants.EVENT.SET_KEY, self.set_key)
+            EventMesh.subscribe(constants.EVENT.GET_IMEI, self.get_imei)
+            EventMesh.subscribe(constants.EVENT.GET_CID, self.get_cid)
+            EventMesh.subscribe(constants.EVENT.SET_CID, self.set_cid)
+            EventMesh.subscribe(constants.EVENT.GET_IMSI, self.get_imsi)
+            EventMesh.subscribe(constants.EVENT.GET_PASSWORD, self.get_password)
+            EventMesh.subscribe(constants.EVENT.SET_PASSWORD, self.set_password)     
+            EventMesh.subscribe(constants.EVENT.SET_PING, self.set_ping)
+            EventMesh.subscribe(constants.EVENT.GET_PING, self.get_ping)
+            EventMesh.subscribe(constants.EVENT.SET_CONNECT, self.set_connect)
+            EventMesh.subscribe(constants.EVENT.GET_CONNECT, self.get_connect)
+
+            
+            EventMesh.subscribe(constants.EVENT.START_BLOOD_OXYGEN, self.start_blood_oxygen)
+            EventMesh.subscribe(constants.EVENT.START_HEART, self.start_heart)
+            EventMesh.subscribe(constants.EVENT.STOP_BLOOD_OXYGEN, self.stop_blood_oxygen)
+            EventMesh.subscribe(constants.EVENT.STOP_HEART, self.stop_heart)
+            EventMesh.subscribe(constants.EVENT.GET_BLOOD_OXYGEN, self.get_blood_oxygen)
+            EventMesh.subscribe(constants.EVENT.GET_HEART, self.get_heart)
+            EventMesh.subscribe(constants.EVENT.GET_WEAR, self.get_wear)
+            EventMesh.subscribe("get_Hsensor", self.get_Hsensor)
+            EventMesh.subscribe("Hsensor_set_sleep", self.Hsensor_set_sleep)
+
+            EventMesh.subscribe(constants.EVENT.START_TEMP, self.start_temp)
+            EventMesh.subscribe(constants.EVENT.STOP_TEMP, self.stop_temp)
+            EventMesh.subscribe(constants.EVENT.GET_TEMP, self.get_temp)
+            EventMesh.subscribe("get_boot_time_count", self.get_boot_time_count)
+            EventMesh.subscribe("get_dev_state", self.get_dev_state)
+            EventMesh.subscribe("set_dev_state", self.set_dev_state)
+
+            EventMesh.subscribe("clear_health_state", self.clear_health_state)
+
+            EventMesh.subscribe("clear_home_alarm", self.clear_home_alarm)
+            EventMesh.subscribe("clear_medicine_alarm", self.clear_medicine_alarm)
+            EventMesh.subscribe("clear_wakeup_alarm", self.clear_wakeup_alarm)
+            EventMesh.subscribe("clear_sleep_alarm", self.clear_sleep_alarm)
+            EventMesh.subscribe("clear_normal_alarm", self.clear_normal_alarm)
+
+            EventMesh.subscribe("clear_manual_hr_flag", self.clear_manual_hr_flag)
+            EventMesh.subscribe("clear_manual_temp_flag", self.clear_manual_temp_flag)
+
+
+            EventMesh.subscribe("clear_usb_flag", self.clear_usb_flag)
+            
+            EventMesh.debug_log("post_processor_after_instantiation:2")
+            self.timer_push_schedule.start(10000, 1, self.publish_event_cb)
+            # self.timer_pusht_test.start(2000, 1, self.publish_test)
+            # self.battery_push_schedule.start(3000, 1, self.__check_battery)
+            self.log.debug("post_processor_after_instantiation finished")
+            #EventMesh.publish(constants.EVENT.START_HEART)
+            # 设备开机立刻更新一次参数
+            self.publish_event_cb()
+            
+            EventMesh.debug_log("post_processor_after_instantiation:3")
+
+        def clear_manual_hr_flag(self,event,msg):
+            self.auto_hr_count = 0
+        
+        def clear_manual_temp_flag(self,event,msg):
+            self.auto_temp_count = 0
+
+        def publish_message_event_DeviceInfo(self,event,msg):
+            self.DeviceInfo_queue.put(msg)
+
+        #DeviceInfo的消息队列处理,防止卡顿
+        def DeviceInfo_queue_thread(self):
+            while True:
+                data = self.DeviceInfo_queue.get()
+                #EventMesh.debug_log("DeviceInfo_queue_thread:data = {}".format(data))
+                if data != None:
+                    try:
+                        data["func"](data["data"])
+                    except Exception as e:
+                        EventMesh.debug_log("DeviceInfo_queue_thread:ERROR:{}".format(e))
+                        usys.print_exception(e)
+
+
+        def gsensor_cb(self, para):
+            EventMesh.debug_log("gsensor_cb:{}".format(para))
+            flip_sw = EventMesh.publish("get_storage_config","flip_sw")
+            fall_sw = EventMesh.publish("get_storage_config","fall_sw")
+            if para == 0: #跌倒报警
+                pass
+                if fall_sw == "1":
+                    EventMesh.publish("falldown_alarm_event")
+                    dev_state =  EventMesh.publish("get_dev_state")
+
+                    tmp = 1 << 21
+                    dev_state = dev_state|tmp #第21位=1
+                    EventMesh.publish("set_dev_state",dev_state)
+                    EventMesh.publish(constants.EVENT.START_LOCATION,[constants.PROTOCOL.AL_SEND,dev_state]) #开始AL定位
+                    pass
+                #EventMesh.publish("load_screen", {"screen": "FIND"})
+            elif para == 1: #抬腕
+                
+                if flip_sw == 1:
+                    EventMesh.publish(constants.EVENT.SYSTEM_UP)
+                
+            elif para == 2: #放手
+                pass
+                # if flip_sw == 1:
+                #     EventMesh.publish(constants.EVENT.SYSTEM_SLEEP)
+        def get_boot_time_count(self, event, msg):
+            return self.boot_time_count
+        
+        def get_dev_state(self, event, msg):
+            return self.dev_state
+        def set_dev_state(self, event, msg):
+            self.dev_state = msg
+        
+        def publish_event_cb(self, *args, **kwargs):
+            if self.boot_time_count < 50000000:
+                self.boot_time_count += 10
+                #EventMesh.debug_log("boot_time_count:{}".format(self.boot_time_count))
+            EventMesh.publish("publish_message_event_DeviceInfo",{"func":self.publish_event,"data":0})  
+        def optimize_temp(self,temp):
+            temp += 0.5
+            get_temp_time  = EventMesh.publish("get_temp_time")
+            EventMesh.debug_log("temp:{}".format(temp))
+            if temp < 36 :#or temp > 37.5:
+                temp = 36+urandom.random()
+            if temp > 37.5:
+                
+                self.temp_warning += 1
+                EventMesh.debug_log("temp_warning:{} get_temp_time{}".format(self.temp_warning,get_temp_time))
+                
+                if self.temp_warning < 5:#高温没连续超过3次,和谐成37.5度以下
+                    temp = 37+(urandom.randint(1, 4)/10)
+                else:
+                    self.temp_warning = 0
+            else:
+                if self.temp_warning>=1:
+                    self.temp_warning -= 1
+            if temp >= 40:
+                temp = 40
+            return temp
+        def clear_health_state(self,event,msg):
+            print("clear_health_state")
+            self.old_bp_time = 0#关闭心率 血压 血氧 体温清除标志
+            self.old_time = 0
+            self.HR_Onestate = 0
+            self.HR_OneTime = 0
+            self.HR_state = 0
+            self.set_hsenor_crt = 0
+            self.old_bg_time = 0
+            self.old_hr_time = 0
+            self.old_spo2_time = 0
+            self.BG_state = 0
+            self.bpauto_state = 0
+            self.spo2auto_state = 0
+            pass
+
+        def clear_temp_state(self,event,msg):
+            print("clear_temp_state")
+            self.temp_state = 0
+            self.temp_one_state = 0
+            self.old_temp_time = 0
+            pass
+
+        def publish_event(self,data):
+            """
+            定时事件处理
+            :param args:
+            :param kwargs:
+            :return:
+            """
+
+            date_tmp = utime.localtime()
+            time_tmp = utime.mktime(date_tmp)
+            # EventMesh.debug_log("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
+            
+
+            EventMesh.publish("countdown_end_cb")
+            """定时检查是否关闭gps失败"""
+            # gnss_state = quecgnss.get_state()
+            # get_location_flag = EventMesh.publish("get_location_flag")
+            # if get_location_flag != None:
+            #     # if gnss_state == 2 and get_location_flag == 0:
+            #     #     EventMesh.publish(constants.EVENT.GPSCLOSE)
+            #     if(get_location_flag == 0):
+            #         EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
+
+            """7分钟一次心跳"""
+            if  math.fabs(time_tmp - self.KA_time) > heartbeat_time: #7分钟一次心跳
+                self.KA_time = time_tmp
+                EventMesh.publish(constants.PROTOCOL.KA_SEND)
+
+            """定时定位"""
+            #EventMesh.publish("set_upload_data",3*60)
+            self.upload_time = EventMesh.publish("get_upload_data")
+            #EventMesh.debug_log("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")
+                        EventMesh.debug_log("NO status")
+                        EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
+            
+            EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
+
+            """电池平均值"""
+            temp = Power.getVbatt()
+            if self.bat_count < 10:
+                self.vbat_buf.append(temp)
+                self.bat_count += 1
+            else:
+                for i in range(9):
+                    self.vbat_buf[i] = self.vbat_buf[i+1]
+                self.vbat_buf[9] = temp
+            curr_count = len(self.vbat_buf)
+            bat_total_value = 0
+            for i in range(curr_count):
+                bat_total_value += self.vbat_buf[i]
+            bat_total_value = bat_total_value//curr_count#一分钟更新一次电量 10个平均值
+            EventMesh.publish("set_curr_battery_level",bat_total_value)
+            # EventMesh.debug_log("self.vbat_buf:{} curr_count :{} bat_total_value:{} temp:{}".format(self.vbat_buf,curr_count,bat_total_value,temp))
+            bat_tmp = EventMesh.publish("screen_get_battery")
+            self.vbat_count+=10
+            if self.vbat_count >= 60:
+                self.vbat_count = 0
+                if bat_tmp != None:
+                    bat_value = bat_tmp[1]
+                    if bat_value <= 0:
+                        pass
+                        # EventMesh.publish("load_screen", {"screen": "LOW_ONE_POWER"})
+            
+            
+            """"隔天清步数"""
+
+            data = RTC().datetime()
+
+            hour = int(data[4])
+            min = int(data[5])
+
+
+
+            cur_month = int(data[1])
+            cur_day = int(data[2])
+            cur_year = int(data[0])
+
+            old_Timesec = EventMesh.publish("get_old_time_data")
+            # EventMesh.debug_log("hour:{} {} cur_month:{} {} next_alarm_time:{} old_Timesec:{}".format(hour,min,cur_month,cur_day,next_alarm_time,old_Timesec))
+            # EventMesh.debug_log("old_Timesec",old_Timesec)
+            if old_Timesec != None:
+                next_alarm_time = utime.localtime(int(old_Timesec))
+                month = int(next_alarm_time[1]) #00:00 18
+                day = int(next_alarm_time[2])
+                year = int(next_alarm_time[0])
+                if month != cur_month or day != cur_day or year != cur_year:#年 月 日只要其中一个都不一样就清零
+                    EventMesh.publish("set_old_time_data",time_tmp)
+                    self.gsensor.reset_step()
+
+                    EventMesh.publish("set_old_step_value",0)
+                    
+                    hr = EventMesh.publish("get_old_hr_data")
+                    if hr != 0:
+                        EventMesh.publish("set_old_hr_data", 0)
+                    
+                    spo2 = EventMesh.publish("get_old_spo2_data")
+                    if spo2 != 0:
+                        EventMesh.publish("set_old_spo2_data", 0)
+                    EventMesh.debug_log("clear step1111")
+                else:
+                    pass
+                    
+                    
+            if hour == 23:#清步数23:59
+                if min == 59:#58 59
+                    # if self.clear_step == 0:
+                    #     self.clear_step = 1
+                    EventMesh.publish("set_old_time_data",time_tmp)
+                    self.gsensor.reset_step()
+                    EventMesh.publish("set_old_step_value",0)
+
+                    hr = EventMesh.publish("get_old_hr_data")
+                    if hr != 0:
+                        EventMesh.publish("set_old_hr_data", 0)
+                    
+                    spo2 = EventMesh.publish("get_old_spo2_data")
+                    if spo2 != 0:
+                        EventMesh.publish("set_old_spo2_data", 0)
+                    EventMesh.debug_log("clear step2222")
+
+                else:
+                    self.clear_step = 0
+            else:
+                self.clear_step = 0
+            
+            """电量小于0% 关机"""
+            get_low_btn = EventMesh.publish("get_low_bat_btn")#
+            battery = EventMesh.publish("screen_get_battery")
+            if battery[0] != '1':
+                if battery[1] == 0:
+                    EventMesh.publish("open_power_on",2)#  #未检测到sim卡15分钟后关机
+            
+            """未联网提示关机"""
+            ble=EventMesh.publish(constants.EVENT.GET_CONNECT)
+            # EventMesh.debug_log("ble",ble)
+            if ble == 0:#未联网提示关机
+                if battery[0] != '1':
+                    self.no_smi_count+=10
+                    # EventMesh.debug_log("self.no_smi_count",self.no_smi_count)
+                    if self.no_smi_count >= (15*60):#(15*60)
+                        self.no_smi_count = 0
+                        EventMesh.publish("open_power_on",2)#  #未检测到sim卡15分钟后关机
+                    
+            else:
+                self.no_smi_count = 0
+
+            msg_nums = sms.getMsgNums() #获取短信条数
+            # EventMesh.debug_log("msg_nums",msg_nums)
+            if(msg_nums != -1):
+                sms_data = sms.getSaveLoc()
+                sms_max = sms_data[0][2]
+                if msg_nums >= sms_max-1:
+                    EventMesh.publish("delete_sms_event")#
+
+            #佩戴检测
+            WEAR = EventMesh.publish(constants.EVENT.GET_WEAR)#佩戴数据
+            if self.wear != WEAR:
+                remove_sw = EventMesh.publish("get_storage_config","remove_sw")
+                if remove_sw == "1":#开启了佩戴检测的开关
+                    dev_state =  EventMesh.publish("get_dev_state")
+                    
+                    if WEAR != 1:
+                        tmp = 1 << 3
+                        tmp = ~tmp
+                        tmp = 1 << 20
+                        dev_state = dev_state|tmp #第20位=1
+                    # else :     
+                    #     pass              
+                        
+                    #     tmp = 1 << 20
+                    #     dev_state = dev_state|tmp #第20位=1
+                    #     tmp = 1 << 3
+                    #     dev_state = dev_state|tmp #第三位=1
+                        EventMesh.debug_log("佩戴检测:{}".format(dev_state))    
+                        EventMesh.publish("set_dev_state",dev_state)
+                        EventMesh.publish(constants.EVENT.START_LOCATION,[constants.PROTOCOL.AL_SEND,dev_state]) #开始AL定位,发送报警
+                        #EventMesh.publish(constants.PROTOCOL.HELP_SEND,65)
+            self.wear = WEAR
+            """定时测量心率,血氧,体温"""
+            self.get_hr_state = EventMesh.publish("get_hr_state")
+            self.get_spo2_state = EventMesh.publish("get_spo2_state")
+            get_temp_time  = EventMesh.publish("get_temp_time")
+            get_temp_state  = EventMesh.publish("get_temp_state")
+            get_bp_state  = EventMesh.publish("get_bp_state")
+            get_bg_state  = EventMesh.publish("get_bg_state")
+            if get_bg_state == None:
+                get_bg_state = 0
+            if get_bp_state == None:
+                get_bp_state = 0
+
+            if get_temp_state == None:
+                get_temp_state = 0
+
+            if self.get_hr_state == None:
+                self.get_hr_state = 0
+            if self.get_spo2_state == None:
+                self.get_spo2_state = 0 
+
+            video_state = EventMesh.publish("get_video_state")#获取
+            if video_state == None:
+                video_state = 0
+                
+            call_state = EventMesh.publish("get_call_state")
+            if call_state == None:
+                call_state = 0
+            if EventMesh.model == "D15":
+                video_state = EventMesh.publish("get_video_state")
+                if video_state != None:
+                    if battery[0] != "1":
+                        if get_temp_state != None and call_state != None and video_state != None: #突然脱腕
+
+                            if get_temp_state > 1  and (WEAR != 1 or call_state != 0 or video_state != 0):
+                                EventMesh.publish(constants.EVENT.STOP_TEMP)
+                                EventMesh.publish("set_temp_state",0)       
+                                EventMesh.txt_log("auto stop_temp:22")
+
+                            if (self.get_hr_state > 1 or self.get_spo2_state > 1 or get_bp_state > 1 or get_bg_state > 1) and (WEAR != 1 or call_state != 0 or video_state != 0):
+                                # print("wear faile")
+                                if self.get_hr_state > 1 :
+                                    EventMesh.txt_log("auto stop_hr:22")
+                                    EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
+                                    EventMesh.publish(constants.EVENT.STOP_HEART) 
+                                    if WEAR == 1:
+                                        heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                        if heart_value > 50 and heart_value != None:
+                                            EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                    
+                                if self.get_spo2_state > 1:
+                                    EventMesh.txt_log("auto stop_spo2:22")
+                                    EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+
+                                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                    spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                    if WEAR == 1:
+                                        if spo2_value > 85 and spo2_value != None:
+                                            EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                    
+                                if get_bp_state > 1:
+
+                                    EventMesh.txt_log("auto stop_bp:22")
+                                    EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    if WEAR == 1:
+                                        blood_data = get_autoblood_value()
+                                        if blood_data == None:
+                                            blood_data[0] = 0
+                                            blood_data[1] = 0
+
+                                        max_value = blood_data[0]
+                                        min_value = blood_data[1]
+                                        if max_value != 0 and min_value != 0:
+                                            EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                    
+                                if get_bg_state > 1:
+                                    EventMesh.txt_log("auto stop_bg:22")
+                                    
+                                    EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    if WEAR == 1:
+                                        bg_data = get_blood_sugar_value()
+                                        if bg_data == None:
+                                            bg_data = 0
+                                        if bg_data != 0:
+                                            # EventMesh.publish("play_sugar_value", bg_data)#播放血糖数值
+                                            EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bg_data)   
+            else:
+                if battery[0] != "1":
+                    if get_temp_state != None and call_state != None: #突然脱腕
+
+                        if get_temp_state > 1  and (WEAR != 1 or call_state != 0):
+                            EventMesh.publish(constants.EVENT.STOP_TEMP)
+                            EventMesh.publish("set_temp_state",0)       
+                            EventMesh.txt_log("auto stop_temp:22")
+
+                        if (self.get_hr_state > 1 or self.get_spo2_state > 1 or get_bp_state > 1 or get_bg_state > 1) and (WEAR != 1 or call_state != 0):
+                            # print("wear faile")
+                            if self.get_hr_state > 1 :
+                                EventMesh.txt_log("auto stop_hr:22")
+                                EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
+                                EventMesh.publish(constants.EVENT.STOP_HEART) 
+                                if WEAR == 1:
+                                    heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                    if heart_value > 50 and heart_value != None:
+                                        EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                
+                            if self.get_spo2_state > 1:
+                                EventMesh.txt_log("auto stop_spo2:22")
+                                EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+
+                                EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                if WEAR == 1:
+                                    if spo2_value > 85 and spo2_value != None:
+                                        EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                
+                            if get_bp_state > 1:
+
+                                EventMesh.txt_log("auto stop_bp:22")
+                                EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                EventMesh.publish(constants.EVENT.STOP_HEART)
+                                if WEAR == 1:
+                                    blood_data = get_autoblood_value()
+                                    if blood_data == None:
+                                        blood_data[0] = 0
+                                        blood_data[1] = 0
+
+                                    max_value = blood_data[0]
+                                    min_value = blood_data[1]
+                                    if max_value != 0 and min_value != 0:
+                                        EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                
+                            if get_bg_state > 1:
+                                EventMesh.txt_log("auto stop_bg:22")
+                                
+                                EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                EventMesh.publish(constants.EVENT.STOP_HEART)
+                                if WEAR == 1:
+                                    bg_data = get_blood_sugar_value()
+                                    if bg_data == None:
+                                        bg_data = 0
+                                    if bg_data != 0:
+                                        # EventMesh.publish("play_sugar_value", bg_data)#播放血糖数值
+                                        EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bg_data)
+                                
+            if self.pull_time == 0:
+                self.pull_time = time_tmp
+            if EventMesh.model == "D15":
+                # if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#已联网 并且不在充电 佩戴正常 不在通话就给测试心率
+                if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and battery[0] != "1" and WEAR == 1 and call_state == 0 and video_state == 0:
+                    if time_tmp - self.pull_time >= 30:
+                        # EventMesh.debug_log("shifens:")  
+
+                        get_hr_state = EventMesh.publish("get_hr_state")
+                        get_spo2_state = EventMesh.publish("get_spo2_state")
+                        get_bp_state  = EventMesh.publish("get_bp_state")
+                        get_bg_state  = EventMesh.publish("get_bg_state")
+                        get_temp_state  = EventMesh.publish("get_temp_state")
+                        if get_hr_state == None:
+                            get_hr_state = 0
+                            self.old_hr_time = 0
+
+                        if get_spo2_state == None:
+                            get_spo2_state = 0
+                            self.old_spo2_time = 0
+
+                        if get_temp_state == None:
+                            get_temp_state = 0
+                            self.temp_one_state = 0
+
+                        if get_bp_state == None:
+                            get_bp_state = 0
+                            self.old_bp_time = 0
+                        
+                        if get_bg_state == None:
+                            get_bg_state = 0
+                            self.old_bg_time = 0
+                        
+                        # print("bp get_bp_state ",get_bp_state,self.old_bp_time)
+
+                        
+                        if get_hr_state != None:
+                            if get_hr_state == 3:
+                                self.old_hr_time+=1
+                                if self.old_hr_time == 1:
+                                    EventMesh.publish("set_hr_state",3)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_HEART)
+                                    EventMesh.txt_log("auto start_hr:333")
+                                elif self.old_hr_time > 6:
+                                    self.old_hr_time = 0
+                                    EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                    EventMesh.txt_log("auto stop_hr:333")
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                    EventMesh.debug_log("heart_value:{}".format(heart_value))
+                                    if heart_value > 50 and heart_value != None:
+                                        EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                    EventMesh.debug_log("STOP_HEART:3")
+                            else:
+                                self.old_hr_time = 0
+                        else:
+                            self.old_hr_time = 0
+
+
+                        if get_spo2_state != None:
+                            if get_spo2_state == 3:
+                                self.old_spo2_time+=1
+                                if self.old_spo2_time == 1:
+                                    EventMesh.publish("set_spo2_state",3)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
+                                    EventMesh.txt_log("auto start_spo2:333")
+                                elif self.old_spo2_time > 6:
+                                    self.old_spo2_time = 0
+                                    EventMesh.txt_log("auto stop_spo2:333")
+                                    EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                    spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                    if spo2_value > 85 and spo2_value != None:
+                                        EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                        
+                            else:
+                                self.old_spo2_time = 0
+                        else:
+                            self.old_spo2_time = 0
+
+
+                        if get_bp_state != None:
+                            if get_bp_state == 3:
+                                self.old_bp_time+=1
+                                if self.old_bp_time == 1:
+                                    EventMesh.publish("set_bp_state",3)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_HEART)
+                                    EventMesh.txt_log("auto start_bp:333")
+                                elif self.old_bp_time > 6:
+                                    self.old_bp_time = 0
+                                    
+                                    EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    blood_data = get_autoblood_value()
+                                    if blood_data == None:
+                                        blood_data[0] = 0
+                                        blood_data[1] = 0
+
+                                    max_value = blood_data[0]
+                                    min_value = blood_data[1]
+                                    if max_value != 0 and min_value != 0:
+                                        EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    EventMesh.txt_log("auto stop_bp:333")
+                            else:
+                                self.old_bp_time = 0
+                        else:
+                            self.old_bp_time = 0
+
+                        if get_bg_state != None:
+                            if get_bg_state == 3:
+                                self.old_bg_time+=1
+                                if self.old_bg_time == 1:
+                                    EventMesh.publish("set_bg_state",3)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_HEART)
+                                    EventMesh.txt_log("auto start_bg:333")
+                                elif self.old_bg_time > 6:
+                                    self.old_bg_time = 0
+                                    EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    bg_data = get_blood_sugar_value()
+                                    if bg_data == None:
+                                        bg_data = 0
+                                    if bg_data != 0:
+                                        EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bg_data)
+
+                                    EventMesh.txt_log("auto stop_bp:333")
+                            else:
+                                self.old_bg_time = 0
+                        else:
+                            self.old_bg_time = 0
+
+                        
+                        if get_temp_state != None:
+                            if get_temp_state == 3:#单次测量
+                                self.temp_one_state+=1
+                                if self.temp_one_state == 1:
+                                    EventMesh.txt_log("auto start_temp:333")
+                                    EventMesh.debug_log("AUTO one temp:2") 
+                                    EventMesh.publish("set_temp_state",3)
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_TEMP)   
+                                elif self.temp_one_state > 3:
+                                    self.temp_one_state = 0
+                                    temp = EventMesh.publish(constants.EVENT.GET_TEMP) 
+                                    temp = self.optimize_temp(temp)
+                                    
+                                    EventMesh.publish("set_temp_state",0)
+                                    tmp_f_tmp = 0
+                                    tmp_d_tmp = 0
+                                    if str(temp).find(".") != -1:
+                                        tmp_f = str(temp).split('.')[0] 
+                                        tmp_f_tmp = int(tmp_f)
+                                        
+                                        tmp_d = str(temp).split('.')[1][:1]
+                                        tmp_d_tmp = int(tmp_d)
+                                    else:
+                                        tmp_f_tmp = temp
+                                        
+                                    if temp != None:
+                                        if temp != 0:
+                                            EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                                    EventMesh.publish(constants.EVENT.STOP_TEMP)
+                                    EventMesh.txt_log("auto start_temp:333")
+
+
+            
+                        
+                        # EventMesh.debug_log("get_temp_time:{} self.temp_one_state:{}".format(get_temp_time,self.temp_one_state))
+                        if get_temp_time != None:#定时测量体温
+                            if get_temp_time > 0:
+                                if get_temp_state != None:
+                                    get_temp_state  = EventMesh.publish("get_temp_state")
+                                    if get_temp_state == 0 or get_temp_state == 2:
+                                        if (time_tmp-self.temp_time) >= get_temp_time:#大于一个周期的时间,重新赋值
+                                            self.temp_state = 0
+                                            self.temp_time = time_tmp
+
+                                        if self.old_temp_time != get_temp_time:#重复修改测量间隔时间
+                                            self.temp_time = time_tmp#防止改变时间的时候正在开启测量突然10s就停止测量 
+                                            self.temp_state = 0
+                                        self.old_temp_time = get_temp_time
+
+                                        if (time_tmp-self.temp_time) == 0 and self.temp_state == 0:#一开始就测量 测量一分钟停止测量体温
+                                            self.temp_state = 1
+                                            EventMesh.publish("set_temp_state",2)
+                                            # EventMesh.publish("set_hr_blood_led",1)
+                                            EventMesh.debug_log("AUTO temp:") 
+                                            EventMesh.txt_log("auto START_temp:1")
+                                            EventMesh.publish(constants.EVENT.START_TEMP)
+
+                                        elif (time_tmp-self.temp_time) >= 30 and self.temp_state == 1:
+                                            self.temp_state = 0
+                                            EventMesh.txt_log("auto stop_temp:1")
+                                            EventMesh.publish("set_temp_state",0)
+                                            temp = EventMesh.publish(constants.EVENT.GET_TEMP) 
+                                            temp = self.optimize_temp(temp)
+                                            
+                                            tmp_f_tmp = 0
+                                            tmp_d_tmp = 0
+                                            if str(temp).find(".") != -1:
+                                                tmp_f = str(temp).split('.')[0] 
+                                                tmp_f_tmp = int(tmp_f)
+                                                
+                                                tmp_d = str(temp).split('.')[1][:1]
+                                                tmp_d_tmp = int(tmp_d)
+                                            else:
+                                                tmp_f_tmp = temp
+                                                
+                                            if temp != None:
+                                                if temp != 0:
+                                                    EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                                            EventMesh.publish(constants.EVENT.STOP_TEMP)
+
+                                    else:
+                                        self.temp_state = 0
+                                        self.old_temp_time = 0
+                            else:
+                                temp_state  = EventMesh.publish("get_temp_state") 
+                                if temp_state == 2:
+                                    EventMesh.publish("set_temp_state",0)#2代表后台进入测试
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    EventMesh.txt_log("auto wear stop_temp:2 ")
+                                    EventMesh.publish(constants.EVENT.STOP_TEMP)
+                                self.temp_state = 0
+                                self.temp_time = 0
+                                self.old_temp_time = 0
+
+
+
+                        hr_time = {}
+                        hr_time = EventMesh.publish("get_time_hr")#获取时间是否大于0
+
+                        if hr_time[0] !=  None:
+                            self.mearsure_btn = int(hr_time[0])
+                            self.mearsure_timer = int(hr_time[1])
+
+                            if self.mearsure_btn != None and self.mearsure_timer != None:
+                                
+                                if self.mearsure_btn >= 1 and self.mearsure_timer > 0:#开关打开并且时间大于0就可以测试血糖
+                                    get_hr_state = EventMesh.publish("get_hr_state")#心率
+                                    get_spo2_state = EventMesh.publish("get_spo2_state")#血氧
+                                    get_bp_state  = EventMesh.publish("get_bp_state")#血压
+                                    get_bg_state  = EventMesh.publish("get_bg_state")#血糖
+                                    # print("state hr",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                    if (get_bg_state == 0 and get_spo2_state == 0 and get_bp_state == 0) and  (get_hr_state == 2 or get_hr_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                        if (time_tmp-self.SENSOR_time) >= self.mearsure_timer:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                            self.SENSOR_time = time_tmp
+                                            self.HR_Onestate = 0
+                                        # print("time_tmp hr",time_tmp,self.SENSOR_time,time_tmp-self.SENSOR_time,self.mearsure_timer,self.HR_Onestate)
+                                        if (time_tmp - self.SENSOR_time) == 0 and self.HR_Onestate == 0:
+                                            self.HR_Onestate = 1
+                                            EventMesh.txt_log("auto START_hr:1")
+                                            EventMesh.publish("set_hr_state",2)#2代表后台进入测试
+                                            # EventMesh.publish("set_hr_blood_led",1)
+                                            EventMesh.publish(constants.EVENT.START_HEART)
+                                            
+                                        elif (time_tmp - self.SENSOR_time) >= 60 and self.HR_Onestate == 1:
+                                            self.HR_Onestate = 0
+                                            EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                            EventMesh.debug_log("stop debug3")
+                                            EventMesh.txt_log("auto stop_hr:1")
+                                            EventMesh.publish(constants.EVENT.STOP_HEART)
+                                            heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                            EventMesh.debug_log("heart_value:{}".format(heart_value))
+                                            # heart_value = 60+urandom.randint(0,10)
+                                            if heart_value > 50 and heart_value != None:
+                                                EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                            #获取心率数据上传数据app
+                                            EventMesh.debug_log("STOP_HEART:")
+                                            
+                                    else:
+                                        self.HR_Onestate = 0
+                                else:
+                                    self.SENSOR_time = 0
+                                    self.HR_Onestate = 0
+                                    hr_state = EventMesh.publish("get_hr_state")#心率
+                                    if hr_state == 2:
+                                        EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                        EventMesh.debug_log("33stop debug3")
+                                        # EventMesh.publish("stop_led_timer")#设置参数
+                                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                                        EventMesh.txt_log("auto wear stop_hr:2 ")
+
+                        get_spo2time = EventMesh.publish("get_spo2_time")#血压自动测试
+                        # print("get_spo2time",get_spo2time)
+                        if get_spo2time != None:#血压时间不为0
+                            spo2_on = int(get_spo2time[0])
+                            spo2_time = int(get_spo2time[1])
+                            if spo2_on != 0 and spo2_time != 0:
+                                get_hr_state = EventMesh.publish("get_hr_state")
+                                get_spo2_state = EventMesh.publish("get_spo2_state")
+                                get_bp_state  = EventMesh.publish("get_bp_state")
+                                get_bg_state  = EventMesh.publish("get_bg_state")
+                                # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                if (get_hr_state == 0 and get_bp_state == 0 and get_bg_state == 0) and (get_spo2_state == 2 or get_spo2_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                    if (time_tmp-self.spo2_timeSecond) >= spo2_time:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                        self.spo2_timeSecond = time_tmp
+                                        self.spo2auto_state = 0
+                                    # print("time_tmp spo2",time_tmp,self.spo2_timeSecond,time_tmp-self.spo2_timeSecond,self.bg_timer,self.bpauto_state)
+                                    if (time_tmp - self.spo2_timeSecond) == 0 and self.spo2auto_state == 0:
+                                        self.spo2auto_state = 1
+                                        EventMesh.debug_log("START_spo2:auto")
+                                        EventMesh.txt_log("auto START_spo2:1")
+                                        EventMesh.publish("set_spo2_state",2)#2代表后台进入测试
+                                        EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
+                                        
+                                    elif (time_tmp - self.spo2_timeSecond) >= 60 and self.spo2auto_state == 1:
+                                        EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                                        self.spo2auto_state = 0
+                                        EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                        spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                        if spo2_value > 85 and spo2_value != None:
+                                            EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                        EventMesh.txt_log("auto stop_spo2:1")
+                                    
+                                else:
+                                    self.spo2auto_state = 0
+                            else:
+                                self.spo2_timeSecond = 0
+                                self.spo2auto_state = 0
+                                spo2_state = EventMesh.publish("get_spo2_state")#心率
+                                if spo2_state == 2:
+                                    EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                                    EventMesh.debug_log("spo2 stop debug3")
+                                    EventMesh.txt_log("auto wear stop_spo2:2 ")
+                                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+
+
+                        get_bptime = EventMesh.publish("get_bp_time")#血压自动测试
+                        # print("get_bptime",get_bptime)
+                        if get_bptime != None:#血压时间不为0
+                            bp_on = int(get_bptime[0])
+                            bp_time = int(get_bptime[1])
+                            if bp_on != 0 and bp_time != 0:
+                                get_hr_state = EventMesh.publish("get_hr_state")
+                                get_spo2_state = EventMesh.publish("get_spo2_state")
+                                get_bp_state  = EventMesh.publish("get_bp_state")
+                                get_bg_state  = EventMesh.publish("get_bg_state")
+                                # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                
+                                if (get_hr_state == 0 and get_spo2_state == 0 and get_bg_state == 0) and (get_bp_state == 2 or get_bp_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                    if (time_tmp-self.bp_timeSecond) >= bp_time:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                        self.bp_timeSecond = time_tmp
+                                        self.bpauto_state = 0
+                                    # print("time_tmp bp",time_tmp,self.bp_timeSecond,time_tmp-self.bp_timeSecond,self.bg_timer,self.bpauto_state)
+                                    if (time_tmp - self.bp_timeSecond) == 0 and self.bpauto_state == 0:
+                                        self.bpauto_state = 1
+                                        EventMesh.debug_log("START_bp:auto")
+                                        EventMesh.txt_log("auto START_bp:1")
+                                        EventMesh.publish("set_bp_state",2)#2代表后台进入测试
+                                        # EventMesh.publish("set_hr_blood_led",1)
+                                        EventMesh.publish(constants.EVENT.START_HEART)
+                                        
+                                    elif (time_tmp - self.bp_timeSecond) >= 60 and self.bpauto_state == 1:
+                                        self.bpauto_state = 0
+                                        EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                        blood_data = get_autoblood_value()
+                                        if blood_data == None:
+                                            blood_data[0] = 0
+                                            blood_data[1] = 0
+
+                                        max_value = blood_data[0]
+                                        min_value = blood_data[1]
+                                        if max_value != 0 and min_value != 0:
+                                            EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                                        EventMesh.txt_log("auto stop_bp:1")
+                                        
+                                else:
+                                    self.bpauto_state = 0
+                            else:
+                                self.bp_timeSecond = 0
+                                self.bpauto_state = 0
+                                bp_state = EventMesh.publish("get_bp_state")#心率
+                                if bp_state == 2:
+                                    EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                    EventMesh.debug_log("bp stop debug3")
+                                    EventMesh.txt_log("auto wear stop_bp:2 ")
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+
+
+
+                        bg_time = {}
+                        bg_time = EventMesh.publish("get_bgauto_time")
+                        if bg_time[0] != None:
+                        
+                            bg_btn = int(bg_time[0])
+                            bg_timer = int(bg_time[1]) 
+                            # print("state bg2",self.bg_btn,self.bg_timer)
+                            if bg_btn >= 1 and bg_timer > 0:#开关打开并且时间大于0就可以测试血糖
+                                get_hr_state = EventMesh.publish("get_hr_state")
+                                get_spo2_state = EventMesh.publish("get_spo2_state")
+                                get_bp_state  = EventMesh.publish("get_bp_state")
+                                get_bg_state  = EventMesh.publish("get_bg_state")
+                                # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                
+                                if (get_hr_state == 0 and get_spo2_state == 0 and get_bp_state == 0) and (get_bg_state == 2 or get_bg_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                    if (time_tmp-self.bg_times) >= bg_timer:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                        self.bg_times = time_tmp #1780 
+                                        self.BG_state = 0
+                                    # print("time_tmp bg",time_tmp,self.bg_times,time_tmp-self.bg_times,bg_timer,self.BG_state)
+                                    if (time_tmp - self.bg_times) == 0 and self.BG_state == 0:
+                                        EventMesh.debug_log("START_bg:1")
+                                        EventMesh.txt_log("auto START_bg:1")
+                                        EventMesh.publish("set_bg_state",2)#2代表后台进入测试
+                                        # EventMesh.publish("set_hr_blood_led",1)
+                                        EventMesh.publish(constants.EVENT.START_HEART)
+                                        self.BG_state = 1
+                                    elif (time_tmp - self.bg_times) >= 60 and self.BG_state == 1:
+                                        self.BG_state = 0
+                                        EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                        # EventMesh.publish("stop_led_timer")#设置参数
+                                        EventMesh.txt_log("auto stop_bg:1")
+                                        EventMesh.debug_log("stop bgdebug3")
+                                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                                        bgdata = get_blood_sugar_value()
+                                        if bgdata == None:
+                                            bgdata = 0
+                                        if bgdata != 0:
+                                            EventMesh.debug_log("bgdata",bgdata)
+                                            EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bgdata)#上传心率数据
+                                        
+                                else:
+                                    
+                                    self.BG_state = 0
+                            else:
+                                bg_state  = EventMesh.publish("get_bg_state") 
+                                if bg_state == 2:
+                                    EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    EventMesh.debug_log("bg stop bgdebug3")
+                                    EventMesh.txt_log("auto wear stop_bg:2 ")
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                self.bg_times = 0
+                                self.BG_state = 0
+                        
+                    else:
+                        self.old_temp_time = 0
+                        self.old_time = 0
+                        # self.SENSOR_time = time_tmp
+                        self.HR_Onestate = 0
+                        self.HR_OneTime = 0
+                        self.HR_state = 0
+                        self.old_time = 0    
+                        self.old_bp_time = 0
+                        self.old_hr_time = 0
+                        self.old_spo2_time = 0
+                        self.set_hsenor_crt = 0
+                        self.old_bg_time = 0
+                        # self.bg_times = time_tmp
+                        self.BG_state = 0
+                        # self.temp_time = time_tmp
+
+                        # self.bp_timeSecond = time_tmp
+                        self.bpauto_state = 0
+
+                        # self.spo2_timeSecond = time_tmp
+                        self.spo2auto_state = 0
+
+                        self.temp_state = 0
+                        self.temp_one_state = 0
+
+
+                else:
+                    self.old_temp_time = 0
+                    self.old_time = 0
+                    # self.SENSOR_time = time_tmp
+                    self.HR_Onestate = 0
+                    self.HR_OneTime = 0
+                    self.HR_state = 0
+                    self.old_time = 0    
+                    self.old_bp_time = 0
+                    self.old_hr_time = 0
+                    self.old_spo2_time = 0
+                    self.set_hsenor_crt = 0
+                    self.old_bg_time = 0
+                    # self.bg_times = time_tmp
+
+                    self.BG_state = 0
+                    # self.temp_time = time_tmp
+
+                    # self.bp_timeSecond = time_tmp
+                    self.bpauto_state = 0
+
+                    # self.spo2_timeSecond = time_tmp
+                    self.spo2auto_state = 0
+
+                    self.temp_state = 0
+                    self.temp_one_state = 0
+
+                    get_hr_state = EventMesh.publish("get_hr_state")
+                    get_spo2_state = EventMesh.publish("get_spo2_state")
+                    get_bp_state  = EventMesh.publish("get_bp_state")
+                    get_bg_state  = EventMesh.publish("get_bg_state")
+                    if get_hr_state != None and get_spo2_state != None and get_bp_state != None and get_bg_state != None:
+                        if get_hr_state > 1:
+                            EventMesh.txt_log("auto stop_hr:44")
+                            EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
+                            # if get_hr_state == 3:
+                            #     EventMesh.publish("stop_led_timer")#设置参数
+                            EventMesh.debug_log("stop debug8")
+                            if WEAR == 1:
+                                heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                if heart_value > 50 and heart_value != None:
+                                    EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                            EventMesh.publish(constants.EVENT.STOP_HEART) 
+                        elif get_spo2_state > 1:
+                            EventMesh.txt_log("auto stop_spo2:44")
+                            EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                            # if get_spo2_state == 3:
+                            #     EventMesh.publish("stop_led_timer")#设置参数
+                            if WEAR == 1:
+                                spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                if spo2_value > 85 and spo2_value != None:
+                                    EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                            EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                            EventMesh.debug_log("stop debug13")
+                        elif get_bp_state > 1:
+                            EventMesh.txt_log("auto stop_bp:44")
+                            EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                            # if get_bp_state == 3:
+                            #     EventMesh.publish("stop_led_timer")#设置参数
+                            if WEAR == 1:
+                                blood_data = get_autoblood_value()
+                                if blood_data == None:
+                                    blood_data[0] = 0
+                                    blood_data[1] = 0
+
+                                max_value = blood_data[0]
+                                min_value = blood_data[1]
+                                if max_value != 0 and min_value != 0:
+                                    EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                            EventMesh.publish(constants.EVENT.STOP_HEART)
+                            EventMesh.debug_log("stop debug14")
+                        elif get_bg_state > 1:
+                            EventMesh.txt_log("auto stop_bg:44")
+                            EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                            # if get_bg_state == 3:
+                            #     EventMesh.publish("stop_led_timer")#设置参数
+                            EventMesh.publish(constants.EVENT.STOP_HEART)
+                            if WEAR == 1:
+                                bgdata = get_blood_sugar_value()
+                                if bgdata == None:
+                                    bgdata = 0
+                                if bgdata != 0:
+                                    EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bgdata)#上传心率数据
+                            EventMesh.debug_log("stop debug15")
+
+                    if get_temp_time != None:
+                        get_temp_state  = EventMesh.publish("get_temp_state")
+                        if get_temp_state > 1:
+                            self.temp_one_state = 0
+                            self.temp_state = 0
+                            temp = EventMesh.publish(constants.EVENT.GET_TEMP)       
+                            temp = self.optimize_temp(temp)
+                            EventMesh.txt_log("auto stop_temp:44")
+                            EventMesh.publish("set_temp_state",0)
+                            if WEAR == 1:
+                                tmp_f_tmp = 0
+                                tmp_d_tmp = 0
+                                if str(temp).find(".") != -1:
+                                    tmp_f = str(temp).split('.')[0] 
+                                    tmp_f_tmp = int(tmp_f)
+                                    
+                                    tmp_d = str(temp).split('.')[1][:1]
+                                    tmp_d_tmp = int(tmp_d)
+                                else:
+                                    tmp_f_tmp = temp
+                                    
+                                if temp != None:
+                                    if temp != 0:
+                                        EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                            EventMesh.publish(constants.EVENT.STOP_TEMP)
+                
+                
+            else:
+                # if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#已联网 并且不在充电 佩戴正常 不在通话就给测试心率
+                if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and battery[0] != "1" and WEAR == 1 and call_state == 0:
+                    if time_tmp - self.pull_time >= 30:
+                        # EventMesh.debug_log("shifens:")  
+
+                        get_hr_state = EventMesh.publish("get_hr_state")
+                        get_spo2_state = EventMesh.publish("get_spo2_state")
+                        get_bp_state  = EventMesh.publish("get_bp_state")
+                        get_bg_state  = EventMesh.publish("get_bg_state")
+                        get_temp_state  = EventMesh.publish("get_temp_state")
+                        if get_hr_state == None:
+                            get_hr_state = 0
+                            self.old_hr_time = 0
+
+                        if get_spo2_state == None:
+                            get_spo2_state = 0
+                            self.old_spo2_time = 0
+
+                        if get_temp_state == None:
+                            get_temp_state = 0
+                            self.temp_one_state = 0
+
+                        if get_bp_state == None:
+                            get_bp_state = 0
+                            self.old_bp_time = 0
+                        
+                        if get_bg_state == None:
+                            get_bg_state = 0
+                            self.old_bg_time = 0
+                        
+                        # print("bp get_bp_state ",get_bp_state,self.old_bp_time)
+
+                        
+                        if get_hr_state != None:
+                            if get_hr_state == 3:
+                                self.old_hr_time+=1
+                                if self.old_hr_time == 1:
+                                    EventMesh.publish("set_hr_state",3)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_HEART)
+                                    EventMesh.txt_log("auto start_hr:333")
+                                elif self.old_hr_time > 6:
+                                    self.old_hr_time = 0
+                                    EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                    EventMesh.txt_log("auto stop_hr:333")
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                    EventMesh.debug_log("heart_value:{}".format(heart_value))
+                                    if heart_value > 50 and heart_value != None:
+                                        EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                    EventMesh.debug_log("STOP_HEART:3")
+                            else:
+                                self.old_hr_time = 0
+                        else:
+                            self.old_hr_time = 0
+
+
+                        if get_spo2_state != None:
+                            if get_spo2_state == 3:
+                                self.old_spo2_time+=1
+                                if self.old_spo2_time == 1:
+                                    EventMesh.publish("set_spo2_state",3)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
+                                    EventMesh.txt_log("auto start_spo2:333")
+                                elif self.old_spo2_time > 6:
+                                    self.old_spo2_time = 0
+                                    EventMesh.txt_log("auto stop_spo2:333")
+                                    EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                    spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                    if spo2_value > 85 and spo2_value != None:
+                                        EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                        
+                            else:
+                                self.old_spo2_time = 0
+                        else:
+                            self.old_spo2_time = 0
+
+
+                        if get_bp_state != None:
+                            if get_bp_state == 3:
+                                self.old_bp_time+=1
+                                if self.old_bp_time == 1:
+                                    EventMesh.publish("set_bp_state",3)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_HEART)
+                                    EventMesh.txt_log("auto start_bp:333")
+                                elif self.old_bp_time > 6:
+                                    self.old_bp_time = 0
+                                    
+                                    EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    blood_data = get_autoblood_value()
+                                    if blood_data == None:
+                                        blood_data[0] = 0
+                                        blood_data[1] = 0
+
+                                    max_value = blood_data[0]
+                                    min_value = blood_data[1]
+                                    if max_value != 0 and min_value != 0:
+                                        EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    EventMesh.txt_log("auto stop_bp:333")
+                            else:
+                                self.old_bp_time = 0
+                        else:
+                            self.old_bp_time = 0
+
+                        if get_bg_state != None:
+                            if get_bg_state == 3:
+                                self.old_bg_time+=1
+                                if self.old_bg_time == 1:
+                                    EventMesh.publish("set_bg_state",3)#2代表后台进入测试
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_HEART)
+                                    EventMesh.txt_log("auto start_bg:333")
+                                elif self.old_bg_time > 6:
+                                    self.old_bg_time = 0
+                                    EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    bg_data = get_blood_sugar_value()
+                                    if bg_data == None:
+                                        bg_data = 0
+                                    if bg_data != 0:
+                                        EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bg_data)
+
+                                    EventMesh.txt_log("auto stop_bp:333")
+                            else:
+                                self.old_bg_time = 0
+                        else:
+                            self.old_bg_time = 0
+
+                        
+                        if get_temp_state != None:
+                            if get_temp_state == 3:#单次测量
+                                self.temp_one_state+=1
+                                if self.temp_one_state == 1:
+                                    EventMesh.txt_log("auto start_temp:333")
+                                    EventMesh.debug_log("AUTO one temp:2") 
+                                    EventMesh.publish("set_temp_state",3)
+                                    # EventMesh.publish("set_hr_blood_led",1)
+                                    EventMesh.publish(constants.EVENT.START_TEMP)   
+                                elif self.temp_one_state > 3:
+                                    self.temp_one_state = 0
+                                    temp = EventMesh.publish(constants.EVENT.GET_TEMP) 
+                                    temp = self.optimize_temp(temp)
+                                    
+                                    EventMesh.publish("set_temp_state",0)
+                                    tmp_f_tmp = 0
+                                    tmp_d_tmp = 0
+                                    if str(temp).find(".") != -1:
+                                        tmp_f = str(temp).split('.')[0] 
+                                        tmp_f_tmp = int(tmp_f)
+                                        
+                                        tmp_d = str(temp).split('.')[1][:1]
+                                        tmp_d_tmp = int(tmp_d)
+                                    else:
+                                        tmp_f_tmp = temp
+                                        
+                                    if temp != None:
+                                        if temp != 0:
+                                            EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                                    EventMesh.publish(constants.EVENT.STOP_TEMP)
+                                    EventMesh.txt_log("auto start_temp:333")
+
+
+            
+                        
+                        # EventMesh.debug_log("get_temp_time:{} self.temp_one_state:{}".format(get_temp_time,self.temp_one_state))
+                        if get_temp_time != None:#定时测量体温
+                            if get_temp_time > 0:
+                                if get_temp_state != None:
+                                    get_temp_state  = EventMesh.publish("get_temp_state")
+                                    if get_temp_state == 0 or get_temp_state == 2:
+                                        if (time_tmp-self.temp_time) >= get_temp_time:#大于一个周期的时间,重新赋值
+                                            self.temp_state = 0
+                                            self.temp_time = time_tmp
+
+                                        if self.old_temp_time != get_temp_time:#重复修改测量间隔时间
+                                            self.temp_time = time_tmp#防止改变时间的时候正在开启测量突然10s就停止测量 
+                                            self.temp_state = 0
+                                        self.old_temp_time = get_temp_time
+
+                                        if (time_tmp-self.temp_time) == 0 and self.temp_state == 0:#一开始就测量 测量一分钟停止测量体温
+                                            self.temp_state = 1
+                                            EventMesh.publish("set_temp_state",2)
+                                            # EventMesh.publish("set_hr_blood_led",1)
+                                            EventMesh.debug_log("AUTO temp:") 
+                                            EventMesh.txt_log("auto START_temp:1")
+                                            EventMesh.publish(constants.EVENT.START_TEMP)
+
+                                        elif (time_tmp-self.temp_time) >= 30 and self.temp_state == 1:
+                                            self.temp_state = 0
+                                            EventMesh.txt_log("auto stop_temp:1")
+                                            EventMesh.publish("set_temp_state",0)
+                                            temp = EventMesh.publish(constants.EVENT.GET_TEMP) 
+                                            temp = self.optimize_temp(temp)
+                                            
+                                            tmp_f_tmp = 0
+                                            tmp_d_tmp = 0
+                                            if str(temp).find(".") != -1:
+                                                tmp_f = str(temp).split('.')[0] 
+                                                tmp_f_tmp = int(tmp_f)
+                                                
+                                                tmp_d = str(temp).split('.')[1][:1]
+                                                tmp_d_tmp = int(tmp_d)
+                                            else:
+                                                tmp_f_tmp = temp
+                                                
+                                            if temp != None:
+                                                if temp != 0:
+                                                    EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                                            EventMesh.publish(constants.EVENT.STOP_TEMP)
+
+                                    else:
+                                        self.temp_state = 0
+                                        self.old_temp_time = 0
+                            else:
+                                temp_state  = EventMesh.publish("get_temp_state") 
+                                if temp_state == 2:
+                                    EventMesh.publish("set_temp_state",0)#2代表后台进入测试
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    EventMesh.txt_log("auto wear stop_temp:2 ")
+                                    EventMesh.publish(constants.EVENT.STOP_TEMP)
+                                self.temp_state = 0
+                                self.temp_time = 0
+                                self.old_temp_time = 0
+
+
+
+                        hr_time = {}
+                        hr_time = EventMesh.publish("get_time_hr")#获取时间是否大于0
+
+                        if hr_time[0] !=  None:
+                            self.mearsure_btn = int(hr_time[0])
+                            self.mearsure_timer = int(hr_time[1])
+
+                            if self.mearsure_btn != None and self.mearsure_timer != None:
+                                
+                                if self.mearsure_btn >= 1 and self.mearsure_timer > 0:#开关打开并且时间大于0就可以测试血糖
+                                    get_hr_state = EventMesh.publish("get_hr_state")#心率
+                                    get_spo2_state = EventMesh.publish("get_spo2_state")#血氧
+                                    get_bp_state  = EventMesh.publish("get_bp_state")#血压
+                                    get_bg_state  = EventMesh.publish("get_bg_state")#血糖
+                                    # print("state hr",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                    if (get_bg_state == 0 and get_spo2_state == 0 and get_bp_state == 0) and  (get_hr_state == 2 or get_hr_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                        if (time_tmp-self.SENSOR_time) >= self.mearsure_timer:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                            self.SENSOR_time = time_tmp
+                                            self.HR_Onestate = 0
+                                        # print("time_tmp hr",time_tmp,self.SENSOR_time,time_tmp-self.SENSOR_time,self.mearsure_timer,self.HR_Onestate)
+                                        if (time_tmp - self.SENSOR_time) == 0 and self.HR_Onestate == 0:
+                                            self.HR_Onestate = 1
+                                            EventMesh.txt_log("auto START_hr:1")
+                                            EventMesh.publish("set_hr_state",2)#2代表后台进入测试
+                                            # EventMesh.publish("set_hr_blood_led",1)
+                                            EventMesh.publish(constants.EVENT.START_HEART)
+                                            
+                                        elif (time_tmp - self.SENSOR_time) >= 60 and self.HR_Onestate == 1:
+                                            self.HR_Onestate = 0
+                                            EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                            EventMesh.debug_log("stop debug3")
+                                            EventMesh.txt_log("auto stop_hr:1")
+                                            EventMesh.publish(constants.EVENT.STOP_HEART)
+                                            heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                            EventMesh.debug_log("heart_value:{}".format(heart_value))
+                                            # heart_value = 60+urandom.randint(0,10)
+                                            if heart_value > 50 and heart_value != None:
+                                                EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                                            #获取心率数据上传数据app
+                                            EventMesh.debug_log("STOP_HEART:")
+                                            
+                                    else:
+                                        self.HR_Onestate = 0
+                                else:
+                                    self.SENSOR_time = 0
+                                    self.HR_Onestate = 0
+                                    hr_state = EventMesh.publish("get_hr_state")#心率
+                                    if hr_state == 2:
+                                        EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+                                        EventMesh.debug_log("33stop debug3")
+                                        # EventMesh.publish("stop_led_timer")#设置参数
+                                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                                        EventMesh.txt_log("auto wear stop_hr:2 ")
+
+                        get_spo2time = EventMesh.publish("get_spo2_time")#血压自动测试
+                        # print("get_spo2time",get_spo2time)
+                        if get_spo2time != None:#血压时间不为0
+                            spo2_on = int(get_spo2time[0])
+                            spo2_time = int(get_spo2time[1])
+                            if spo2_on != 0 and spo2_time != 0:
+                                get_hr_state = EventMesh.publish("get_hr_state")
+                                get_spo2_state = EventMesh.publish("get_spo2_state")
+                                get_bp_state  = EventMesh.publish("get_bp_state")
+                                get_bg_state  = EventMesh.publish("get_bg_state")
+                                # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                if (get_hr_state == 0 and get_bp_state == 0 and get_bg_state == 0) and (get_spo2_state == 2 or get_spo2_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                    if (time_tmp-self.spo2_timeSecond) >= spo2_time:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                        self.spo2_timeSecond = time_tmp
+                                        self.spo2auto_state = 0
+                                    # print("time_tmp spo2",time_tmp,self.spo2_timeSecond,time_tmp-self.spo2_timeSecond,self.bg_timer,self.bpauto_state)
+                                    if (time_tmp - self.spo2_timeSecond) == 0 and self.spo2auto_state == 0:
+                                        self.spo2auto_state = 1
+                                        EventMesh.debug_log("START_spo2:auto")
+                                        EventMesh.txt_log("auto START_spo2:1")
+                                        EventMesh.publish("set_spo2_state",2)#2代表后台进入测试
+                                        EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
+                                        
+                                    elif (time_tmp - self.spo2_timeSecond) >= 60 and self.spo2auto_state == 1:
+                                        EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                                        self.spo2auto_state = 0
+                                        EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                        spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                        if spo2_value > 85 and spo2_value != None:
+                                            EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                        EventMesh.txt_log("auto stop_spo2:1")
+                                    
+                                else:
+                                    self.spo2auto_state = 0
+                            else:
+                                self.spo2_timeSecond = 0
+                                self.spo2auto_state = 0
+                                spo2_state = EventMesh.publish("get_spo2_state")#心率
+                                if spo2_state == 2:
+                                    EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                                    EventMesh.debug_log("spo2 stop debug3")
+                                    EventMesh.txt_log("auto wear stop_spo2:2 ")
+                                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+
+
+                        get_bptime = EventMesh.publish("get_bp_time")#血压自动测试
+                        # print("get_bptime",get_bptime)
+                        if get_bptime != None:#血压时间不为0
+                            bp_on = int(get_bptime[0])
+                            bp_time = int(get_bptime[1])
+                            if bp_on != 0 and bp_time != 0:
+                                get_hr_state = EventMesh.publish("get_hr_state")
+                                get_spo2_state = EventMesh.publish("get_spo2_state")
+                                get_bp_state  = EventMesh.publish("get_bp_state")
+                                get_bg_state  = EventMesh.publish("get_bg_state")
+                                # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                
+                                if (get_hr_state == 0 and get_spo2_state == 0 and get_bg_state == 0) and (get_bp_state == 2 or get_bp_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                    if (time_tmp-self.bp_timeSecond) >= bp_time:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                        self.bp_timeSecond = time_tmp
+                                        self.bpauto_state = 0
+                                    # print("time_tmp bp",time_tmp,self.bp_timeSecond,time_tmp-self.bp_timeSecond,self.bg_timer,self.bpauto_state)
+                                    if (time_tmp - self.bp_timeSecond) == 0 and self.bpauto_state == 0:
+                                        self.bpauto_state = 1
+                                        EventMesh.debug_log("START_bp:auto")
+                                        EventMesh.txt_log("auto START_bp:1")
+                                        EventMesh.publish("set_bp_state",2)#2代表后台进入测试
+                                        # EventMesh.publish("set_hr_blood_led",1)
+                                        EventMesh.publish(constants.EVENT.START_HEART)
+                                        
+                                    elif (time_tmp - self.bp_timeSecond) >= 60 and self.bpauto_state == 1:
+                                        self.bpauto_state = 0
+                                        EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                        blood_data = get_autoblood_value()
+                                        if blood_data == None:
+                                            blood_data[0] = 0
+                                            blood_data[1] = 0
+
+                                        max_value = blood_data[0]
+                                        min_value = blood_data[1]
+                                        if max_value != 0 and min_value != 0:
+                                            EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                                        EventMesh.txt_log("auto stop_bp:1")
+                                        
+                                else:
+                                    self.bpauto_state = 0
+                            else:
+                                self.bp_timeSecond = 0
+                                self.bpauto_state = 0
+                                bp_state = EventMesh.publish("get_bp_state")#心率
+                                if bp_state == 2:
+                                    EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                                    EventMesh.debug_log("bp stop debug3")
+                                    EventMesh.txt_log("auto wear stop_bp:2 ")
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+
+
+
+                        bg_time = {}
+                        bg_time = EventMesh.publish("get_bgauto_time")
+                        if bg_time[0] != None:
+                        
+                            bg_btn = int(bg_time[0])
+                            bg_timer = int(bg_time[1]) 
+                            # print("state bg2",self.bg_btn,self.bg_timer)
+                            if bg_btn >= 1 and bg_timer > 0:#开关打开并且时间大于0就可以测试血糖
+                                get_hr_state = EventMesh.publish("get_hr_state")
+                                get_spo2_state = EventMesh.publish("get_spo2_state")
+                                get_bp_state  = EventMesh.publish("get_bp_state")
+                                get_bg_state  = EventMesh.publish("get_bg_state")
+                                # print("state bg2",get_hr_state,get_spo2_state,get_bp_state,get_bg_state)
+                                
+                                if (get_hr_state == 0 and get_spo2_state == 0 and get_bp_state == 0) and (get_bg_state == 2 or get_bg_state == 0):#心率血压血氧不在测试就测试血糖自动测量
+                                    if (time_tmp-self.bg_times) >= bg_timer:#大于一个周期的时间,保存的时间戳时间 1678 0 1678 30 1678 
+                                        self.bg_times = time_tmp #1780 
+                                        self.BG_state = 0
+                                    # print("time_tmp bg",time_tmp,self.bg_times,time_tmp-self.bg_times,bg_timer,self.BG_state)
+                                    if (time_tmp - self.bg_times) == 0 and self.BG_state == 0:
+                                        EventMesh.debug_log("START_bg:1")
+                                        EventMesh.txt_log("auto START_bg:1")
+                                        EventMesh.publish("set_bg_state",2)#2代表后台进入测试
+                                        # EventMesh.publish("set_hr_blood_led",1)
+                                        EventMesh.publish(constants.EVENT.START_HEART)
+                                        self.BG_state = 1
+                                    elif (time_tmp - self.bg_times) >= 60 and self.BG_state == 1:
+                                        self.BG_state = 0
+                                        EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                        # EventMesh.publish("stop_led_timer")#设置参数
+                                        EventMesh.txt_log("auto stop_bg:1")
+                                        EventMesh.debug_log("stop bgdebug3")
+                                        EventMesh.publish(constants.EVENT.STOP_HEART)
+                                        bgdata = get_blood_sugar_value()
+                                        if bgdata == None:
+                                            bgdata = 0
+                                        if bgdata != 0:
+                                            EventMesh.debug_log("bgdata",bgdata)
+                                            EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bgdata)#上传心率数据
+                                        
+                                else:
+                                    
+                                    self.BG_state = 0
+                            else:
+                                bg_state  = EventMesh.publish("get_bg_state") 
+                                if bg_state == 2:
+                                    EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                                    # EventMesh.publish("stop_led_timer")#设置参数
+                                    EventMesh.debug_log("bg stop bgdebug3")
+                                    EventMesh.txt_log("auto wear stop_bg:2 ")
+                                    EventMesh.publish(constants.EVENT.STOP_HEART)
+                                self.bg_times = 0
+                                self.BG_state = 0
+                        
+                    else:
+                        self.old_temp_time = 0
+                        self.old_time = 0
+                        # self.SENSOR_time = time_tmp
+                        self.HR_Onestate = 0
+                        self.HR_OneTime = 0
+                        self.HR_state = 0
+                        self.old_time = 0    
+                        self.old_bp_time = 0
+                        self.old_hr_time = 0
+                        self.old_spo2_time = 0
+                        self.set_hsenor_crt = 0
+                        self.old_bg_time = 0
+                        # self.bg_times = time_tmp
+                        self.BG_state = 0
+                        # self.temp_time = time_tmp
+
+                        # self.bp_timeSecond = time_tmp
+                        self.bpauto_state = 0
+
+                        # self.spo2_timeSecond = time_tmp
+                        self.spo2auto_state = 0
+
+                        self.temp_state = 0
+                        self.temp_one_state = 0
+
+                else:
+                    self.old_temp_time = 0
+                    self.old_time = 0
+                    # self.SENSOR_time = time_tmp
+                    self.HR_Onestate = 0
+                    self.HR_OneTime = 0
+                    self.HR_state = 0
+                    self.old_time = 0    
+                    self.old_bp_time = 0
+                    self.old_hr_time = 0
+                    self.old_spo2_time = 0
+                    self.set_hsenor_crt = 0
+                    self.old_bg_time = 0
+                    # self.bg_times = time_tmp
+
+                    self.BG_state = 0
+                    # self.temp_time = time_tmp
+
+                    # self.bp_timeSecond = time_tmp
+                    self.bpauto_state = 0
+
+                    # self.spo2_timeSecond = time_tmp
+                    self.spo2auto_state = 0
+
+                    self.temp_state = 0
+                    self.temp_one_state = 0
+
+                    get_hr_state = EventMesh.publish("get_hr_state")
+                    get_spo2_state = EventMesh.publish("get_spo2_state")
+                    get_bp_state  = EventMesh.publish("get_bp_state")
+                    get_bg_state  = EventMesh.publish("get_bg_state")
+                    if get_hr_state != None and get_spo2_state != None and get_bp_state != None and get_bg_state != None:
+                        if get_hr_state > 1:
+                            EventMesh.txt_log("auto stop_hr:44")
+                            EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 
+                            # if get_hr_state == 3:
+                            #     EventMesh.publish("stop_led_timer")#设置参数
+                            EventMesh.debug_log("stop debug8")
+                            if WEAR == 1:
+                                heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                                if heart_value > 50 and heart_value != None:
+                                    EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+                            EventMesh.publish(constants.EVENT.STOP_HEART) 
+                        elif get_spo2_state > 1:
+                            EventMesh.txt_log("auto stop_spo2:44")
+                            EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
+                            # if get_spo2_state == 3:
+                            #     EventMesh.publish("stop_led_timer")#设置参数
+                            if WEAR == 1:
+                                spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                if spo2_value > 85 and spo2_value != None:
+                                    EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                            EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                            EventMesh.debug_log("stop debug13")
+                        elif get_bp_state > 1:
+                            EventMesh.txt_log("auto stop_bp:44")
+                            EventMesh.publish("set_bp_state",0)#2代表后台进入测试
+                            # if get_bp_state == 3:
+                            #     EventMesh.publish("stop_led_timer")#设置参数
+                            if WEAR == 1:
+                                blood_data = get_autoblood_value()
+                                if blood_data == None:
+                                    blood_data[0] = 0
+                                    blood_data[1] = 0
+
+                                max_value = blood_data[0]
+                                min_value = blood_data[1]
+                                if max_value != 0 and min_value != 0:
+                                    EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                            EventMesh.publish(constants.EVENT.STOP_HEART)
+                            EventMesh.debug_log("stop debug14")
+                        elif get_bg_state > 1:
+                            EventMesh.txt_log("auto stop_bg:44")
+                            EventMesh.publish("set_bg_state",0)#2代表后台进入测试
+                            # if get_bg_state == 3:
+                            #     EventMesh.publish("stop_led_timer")#设置参数
+                            EventMesh.publish(constants.EVENT.STOP_HEART)
+                            if WEAR == 1:
+                                bgdata = get_blood_sugar_value()
+                                if bgdata == None:
+                                    bgdata = 0
+                                if bgdata != 0:
+                                    EventMesh.publish(constants.PROTOCOL.BLOODGLUSOCE_SEND,bgdata)#上传心率数据
+                            EventMesh.debug_log("stop debug15")
+
+                    if get_temp_time != None:
+                        get_temp_state  = EventMesh.publish("get_temp_state")
+                        if get_temp_state > 1:
+                            self.temp_one_state = 0
+                            self.temp_state = 0
+                            temp = EventMesh.publish(constants.EVENT.GET_TEMP)       
+                            temp = self.optimize_temp(temp)
+                            EventMesh.txt_log("auto stop_temp:44")
+                            EventMesh.publish("set_temp_state",0)
+                            if WEAR == 1:
+                                tmp_f_tmp = 0
+                                tmp_d_tmp = 0
+                                if str(temp).find(".") != -1:
+                                    tmp_f = str(temp).split('.')[0] 
+                                    tmp_f_tmp = int(tmp_f)
+                                    
+                                    tmp_d = str(temp).split('.')[1][:1]
+                                    tmp_d_tmp = int(tmp_d)
+                                else:
+                                    tmp_f_tmp = temp
+                                    
+                                if temp != None:
+                                    if temp != 0:
+                                        EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                            EventMesh.publish(constants.EVENT.STOP_TEMP)
+
+                
+
+
+            hr_state = EventMesh.publish("get_hr_state")
+            spo2_state = EventMesh.publish("get_spo2_state")
+            temp_state  = EventMesh.publish("get_temp_state")
+            if hr_state != None or spo2_state != None or temp_state != None:#手动测试
+                auto_hr = EventMesh.publish("get_start_measure_time")#设置开始测量的时间戳时间
+                if auto_hr == None:
+                    auto_hr = 0
+                if hr_state == 1:
+                    if auto_hr != 0:
+                        self.auto_hr_count+=1
+                        if  self.auto_hr_count > 6:
+                            self.auto_hr_count = 0
+                            EventMesh.publish("set_hr_state",0)#0代表g关闭测试
+                            EventMesh.debug_log("stop debug7")
+                            EventMesh.publish(constants.EVENT.STOP_HEART)
+                            heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
+                            if heart_value > 50 and heart_value != None:
+                                EventMesh.publish("play_hr_value",heart_value)
+                                # EventMesh.publish("set_history_hr_value",heart_value)
+                                EventMesh.publish(constants.PROTOCOL.HEART_SEND,heart_value)#上传心率数据
+
+                                if EventMesh.model == "D15" :#D15型号
+                                    blood_data = get_autoblood_value()
+                                    if blood_data == None:
+                                        blood_data[0] = 0
+                                        blood_data[1] = 0
+
+                                    max_value = blood_data[0]
+                                    min_value = blood_data[1]
+                                    if max_value != 0 and min_value != 0:
+                                        EventMesh.publish(constants.PROTOCOL.BLOOD_SEND,[max_value,min_value])
+                                    pass
+
+                            else:
+                                EventMesh.publish("play_hr_value",0) 
+                        else :
+                            if WEAR != 1:
+                                EventMesh.publish("set_hr_state",0)#0代表g关闭测试
+                                EventMesh.debug_log("stop debug7")
+                                EventMesh.publish(constants.EVENT.STOP_HEART)                               
+                                EventMesh.publish("play_hr_value",0) 
+                                
+                else:
+                    self.auto_hr_count = 0
+                    
+
+                auto_spo2 = EventMesh.publish("get_start_measure_time")#设置开始测量的时间戳时间
+                if auto_spo2 == None:
+                    auto_spo2 = 0
+                if spo2_state == 1:#手动测试血氧
+                    if auto_spo2 != None:
+                        if auto_spo2 != 0:
+                            self.auto_spo2_count+=1
+                            if self.auto_spo2_count > 6:
+                                self.auto_spo2_count = 0
+                                EventMesh.publish("set_spo2_state",0)#0代表g关闭测试
+                                EventMesh.debug_log("stop spo2 debug7")
+                                EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+                                spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
+                                if spo2_value > 85 and spo2_value != None:
+                                    EventMesh.publish("play_spo2_value",spo2_value)
+                                    EventMesh.publish("set_old_spo2_data",spo2_value)
+                                    EventMesh.publish(constants.PROTOCOL.OXYGEN_SEND,spo2_value)
+                                else:
+                                    EventMesh.publish("play_spo2_value",0)
+                            
+                            else:
+                                if WEAR != 1:
+                                    EventMesh.publish("set_spo2_state",0)#0代表g关闭测试
+                                    EventMesh.debug_log("stop debug8")
+                                    EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)                               
+                                    EventMesh.publish("play_spo2_value",0) 
+                                    
+                else:
+                    self.auto_spo2_count = 0
+
+                if temp_state == 1:#手动测试体温
+                    auto_temp = EventMesh.publish("get_start_temp_measure_time")#设置开始测量的时间戳时间
+                    if auto_temp == None:
+                        auto_temp = 0
+                    if auto_temp != None:
+                        if auto_temp != 0:
+                            self.auto_temp_count += 1
+                            if self.auto_temp_count > 6:
+                                self.auto_temp_count = 0
+                                EventMesh.debug_log("体温测量结束")
+                                temp = EventMesh.publish(constants.EVENT.GET_TEMP)       
+                                temp = self.optimize_temp(temp)
+                                EventMesh.debug_log("temp",temp)
+                                EventMesh.publish("set_temp_state",0)
+                                tmp_f_tmp = 0
+                                tmp_d_tmp = 0
+                                if str(temp).find(".") != -1:
+                                    tmp_f = str(temp).split('.')[0] 
+                                    tmp_f_tmp = int(tmp_f)
+                                    
+                                    tmp_d = str(temp).split('.')[1][:1]
+                                    tmp_d_tmp = int(tmp_d)
+                                else:
+                                    tmp_f_tmp = temp
+                                    
+                                if temp != None:
+                                    if temp != 0:
+                                        # EventMesh.publish("set_history_temp_value",temp)
+                                        EventMesh.publish("play_temp_value",temp)#播放体温数值
+                                        EventMesh.publish(constants.PROTOCOL.TEMP_SEND,[tmp_f_tmp,tmp_d_tmp])
+                                    else:
+                                        # EventMesh.publish("set_history_temp_value",0)
+                                        EventMesh.publish("play_temp_value",0)#播放体温数值
+                                
+                                EventMesh.publish(constants.EVENT.STOP_TEMP)
+
+                            else :
+                                if WEAR  != 1:
+                                    EventMesh.publish("set_temp_state",0)#0代表g关闭测试
+                                    EventMesh.debug_log("stop debug9")
+                                    EventMesh.publish(constants.EVENT.STOP_TEMP)                               
+                                    EventMesh.publish("play_temp_value",0) 
+                                    
+                else:
+                    self.auto_temp_count = 0
+
+            EventMesh.publish("play_unread_wechat_infor")#每10s检测是否有未读语音数据
+
+            usb_state = EventMesh.publish("get_usb")#
+            
+            # EventMesh.publish("set_led_time_arg",[1,2,20*11,led_mode.FLASH_LIGHT_RED,20,10,led_mode.OTHER_MEASURE_MODE])#測量成功
+            if battery[0] == '1':
+                # EventMesh.debug_log("battery[1]",battery[1])
+                if self.vbat_full_flag <= 120:
+                    self.vbat_full_flag+=10
+                    if self.vbat_full_flag == 60:#开机检测一次如果是充电标识为1就不再提示
+                        if usb_state != 1:
+                            EventMesh.publish("set_usb",1)#
+                else:
+                    if battery[1] >= 100:
+                        if self.charge_full_count == 0:#充电已满
+                            EventMesh.publish("set_usb",3)#
+                            EventMesh.debug_log("charge R_CHARGE_full")
+                            self.charge_full_count = 1
+                    
+            else:
+                self.charge_full_count = 0
+                low_power = battery[1]
+                if low_power <= 5:#小于5%红色灯慢闪
+                    EventMesh.publish("set_led_time_arg",[1,2,20*11,led_mode.FLASH_LIGHT_RED,20,10,led_mode.OTHER_MEASURE_MODE])#測量成功
+                    # EventMesh.publish("set_led_time_arg",[1000,400,52,led_mode.FLASH_LIGHT_RED,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#開始測量
+
+            
+            self.normal_alarm()
+            #喝水提醒
+            self.drink_alarm()
+            #该吃药了
+            self.medicine_alarm()
+            #该起床了
+            self.wakeup_alarm()
+            #该睡觉了
+            self.sleep_alarm()
+            #该回家了
+            self.home_alarm()
+            #该休息了
+            self.reset_alarm()
+
+
+            if self.alarm_flag == 0:
+                self.alarm_flag = 1
+                EventMesh.publish("set_rtc_alarm")
+
+            if EventMesh.model == "D15":#只有D15才有这个功能
+                EventMesh.publish("video_no_network")
+
+        def clear_usb_flag(self,event,msg):
+            self.charge_full_count = 0
+        #普通闹钟
+        def normal_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.normal_oldtotalmin",self.normal_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.normal_oldtotalmin == 0:
+                self.normal_oldtotalmin = cur_total_min #549
+            if self.normal_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.normal_flag == 1:
+                    self.normal_flag = 0
+                    self.normal_count = 0
+            normal_alarm = []
+            normal_alarm = EventMesh.publish("get_storage_config","normal_alarm")
+            # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
+            if self.normal_flag == 1:#表示闹钟响过清除标志
+                self.normal_count+=1
+                if self.normal_count > 6:
+                    self.normal_count = 0
+                    self.normal_flag = 0
+            if normal_alarm != None:
+                if len(normal_alarm) != 0 and normal_alarm != []:
+                    j = 0
+                    for i in range(len(normal_alarm)):
+                        # EventMesh.debug_log("normal_alarm normal_alarm 33",normal_alarm,j)
+                        normalalarm_hour = normal_alarm[j]["hour"]
+                        normalalarm_min = normal_alarm[j]["min"]
+                        normalalarm_day = normal_alarm[j]["day"]
+                        normalalarm_enale = normal_alarm[j]["enable"]
+                        normalalarm_totalmin = int(normalalarm_hour)*60+int(normalalarm_min)
+                        # EventMesh.debug_log("wake alarm",normalalarm_hour,sleep_min,sleep_day,sleep_enale,sleep_totalmin,week)
+                        if normalalarm_day == []:#单次闹钟只响一次
+                            if normalalarm_enale != 0:
+                                if cur_total_min > normalalarm_totalmin:
+                                    normal_alarm.pop(j)
+                                    self.normal_count = 0
+                                    self.normal_flag  = 0 
+                                    j=0
+                                    # EventMesh.debug_log("wakeup wakeup dayu",sleep,j)
+                                    EventMesh.publish("set_storage_config",["normal_alarm",normal_alarm])#删除之后重新保存
+                                    # sleep = EventMesh.publish("get_storage_config","sleep_alarm")#删除之后重新保存
+                                    continue
+                                else:
+                                    if normalalarm_totalmin == cur_total_min and self.normal_flag == 0:#14:00
+                                        self.normal_count = 0
+                                        self.normal_flag  = 0    
+                                        normal_alarm.pop(j)
+                                        # EventMesh.debug_log("wakeup wakeup1",sleep,j)
+                                        EventMesh.publish("set_storage_config",["normal_alarm",normal_alarm])#删除之后重新保存
+                                        EventMesh.publish("OPEN_ALARM_RING")                                                                                                                                            
+                                        break
+                        else:
+                            if normalalarm_enale != 0 and (week in normalalarm_day):#记录响过的时间分钟数
+                                if normalalarm_totalmin == cur_total_min and self.normal_flag == 0:#14:00
+                                    self.normal_flag  = 1
+                                    self.normal_count = 0
+                                    self.normal_oldtotalmin = normalalarm_totalmin
+                                    EventMesh.publish("OPEN_ALARM_RING")#                                                                                                                                                  
+                                    break
+                        j+=1
+
+
+        #喝水提醒
+        def drink_alarm(self):
+            date_tmp = utime.localtime()
+            time_tmp = utime.mktime(date_tmp)
+        
+            if self.drink_time == 0:
+                self.drink_time = time_tmp
+            
+            on = EventMesh.publish("get_storage_config","drink_on")
+            time = EventMesh.publish("get_storage_config","drink_time")
+            # print("drink info2",on,time)
+            if on != None and time != None:
+                if on != 0 and time != 0:
+                    if (time_tmp - self.drink_time) >= (time*60*60):#需要转换成小时3600
+                        self.drink_time = time_tmp 
+                        EventMesh.publish("drink_alarm_event")#该喝水了
+                        #该喝水了
+                else:
+                    self.drink_time = 0
+            else:
+                self.drink_time = 0
+
+        #吃药提醒
+        def medicine_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # print("self.medicine_oldtotalmin",self.medicine_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.medicine_oldtotalmin == 0:
+                self.medicine_oldtotalmin = cur_total_min #549
+            if self.medicine_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.medicine_flag == 1:
+                    self.medicine_flag = 0
+                    self.medicine_count = 0
+            medicine = EventMesh.publish("get_storage_config","medicine")
+            # print("medicine info2",medicine,cur_total_min)
+            if self.medicine_flag == 1:#表示闹钟响过清除标志
+                self.medicine_count+=1
+                if self.medicine_count > 6:
+                    self.medicine_count = 0
+                    self.medicine_flag = 0
+            if medicine != None:
+                if len(medicine) != 0 and medicine != []:
+                    for i in range(len(medicine)):
+                        medicine_hour = medicine[i]["hour"]
+                        medicine_min = medicine[i]["min"]
+                        medicine_day = medicine[i]["day"]
+                        medicine_enale = medicine[i]["enable"]
+                        medicine_totalmin = int(medicine_hour)*60+int(medicine_min)
+                        # print("medicine alarm",medicine_hour,medicine_min,medicine_day,medicine_enale,medicine_totalmin,week)
+                        if medicine_day == []:
+                            if medicine_enale != 0:
+                                if medicine_totalmin == cur_total_min and self.medicine_flag == 0:#14:00
+                                    self.medicine_count = 0
+                                    self.medicine_flag  = 1    
+                                    self.medicine_oldtotalmin = medicine_totalmin#记录响过的时间分钟数
+                                    # print("medicine alarm1")
+                                    EventMesh.publish("medicine_alarm_event")#该吃药了                                                                                                                                              
+                                    break
+                        else:
+                            if medicine_enale != 0 and (week in medicine_day):#记录响过的时间分钟数
+                                if medicine_totalmin == cur_total_min and self.medicine_flag == 0:#14:00
+                                    self.medicine_flag  = 1
+                                    self.medicine_count = 0
+                                    self.medicine_oldtotalmin = medicine_totalmin
+                                    # print("medicine alarm2",)
+                                    EventMesh.publish("medicine_alarm_event")#该吃药了                                                                                                                                                   
+                                    break
+        #该起床了
+        def wakeup_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.wakeup_oldtotalmin",self.wakeup_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.wakeup_oldtotalmin == 0:
+                self.wakeup_oldtotalmin = cur_total_min #549
+            if self.wakeup_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.wakeup_flag == 1:
+                    self.wakeup_flag = 0
+                    self.wakeup_count = 0
+            wakeup = []
+            wakeup = EventMesh.publish("get_storage_config","wakeup_alarm")
+            # EventMesh.debug_log("wakeup info2",wakeup,cur_total_min)
+            if self.wakeup_flag == 1:#表示闹钟响过清除标志
+                self.wakeup_count+=1
+                if self.wakeup_count > 6:
+                    self.wakeup_count = 0
+                    self.wakeup_flag = 0
+            if wakeup != None:
+                if len(wakeup) != 0 and wakeup != []:
+                    j = 0
+                    for i in range(len(wakeup)):
+                        wakeup_hour = wakeup[j]["hour"]
+                        wakeup_min = wakeup[j]["min"]
+                        wakeup_day = wakeup[j]["day"]
+                        wakeup_enale = wakeup[j]["enable"]
+                        wakeup_totalmin = int(wakeup_hour)*60+int(wakeup_min)
+                        # EventMesh.debug_log("wake alarm",wakeup_hour,wakeup_min,wakeup_day,wakeup_enale,wakeup_totalmin,week)
+                        if wakeup_day == []:#单次闹钟只响一次
+                            if wakeup_enale != 0:
+                                if cur_total_min > wakeup_totalmin:
+                                    self.wakeup_count = 0
+                                    self.wakeup_flag  = 0    
+                                    wakeup.pop(j)
+                                    j=0#每次删除都从0开始遍历
+                                    # EventMesh.debug_log("wakeup wakeup1 dayu",wakeup,j)
+                                    EventMesh.publish("set_storage_config",["wakeup_alarm",wakeup])
+                                    continue
+                                else:
+                                    if wakeup_totalmin == cur_total_min and self.wakeup_flag == 0:#14:00
+                                        self.wakeup_count = 0
+                                        self.wakeup_flag  = 0    
+                                        wakeup.pop(j)
+                                        EventMesh.debug_log("wakeup wakeup1",wakeup,j)
+                                        EventMesh.publish("set_storage_config",["wakeup_alarm",wakeup])
+                                        EventMesh.publish("wakeup_alarm_event")#该吃药了                                                                                                                                              
+                                        break
+                        else:
+                            if wakeup_enale != 0 and (week in wakeup_day):#记录响过的时间分钟数
+                                if wakeup_totalmin == cur_total_min and self.wakeup_flag == 0:#14:00
+                                    self.wakeup_flag  = 1
+                                    self.wakeup_count = 0
+                                    self.wakeup_oldtotalmin = wakeup_totalmin
+                                    EventMesh.publish("wakeup_alarm_event")#该吃药了                                                                                                                                                   
+                                    break
+                        j+=1
+
+
+        #该睡觉了
+        def sleep_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.sleep_oldtotalmin",self.sleep_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.sleep_oldtotalmin == 0:
+                self.sleep_oldtotalmin = cur_total_min #549
+            if self.sleep_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.sleep_flag == 1:
+                    self.sleep_flag = 0
+                    self.sleep_count = 0
+            sleep = []
+            sleep = EventMesh.publish("get_storage_config","sleep_alarm")
+            # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
+            if self.sleep_flag == 1:#表示闹钟响过清除标志
+                self.sleep_count+=1
+                if self.sleep_count > 6:
+                    self.sleep_count = 0
+                    self.sleep_flag = 0
+            if sleep != None:
+                if len(sleep) != 0 and sleep != []:
+                    j = 0
+                    count = int(len(sleep))
+                    for i in range(len(sleep)):
+                        # EventMesh.debug_log("wakeup wakeup 33",sleep,j)
+                        sleep_hour = sleep[j]["hour"]
+                        sleep_min = sleep[j]["min"]
+                        sleep_day = sleep[j]["day"]
+                        sleep_enale = sleep[j]["enable"]
+                        sleep_totalmin = int(sleep_hour)*60+int(sleep_min)
+                        # EventMesh.debug_log("wake alarm",sleep_hour,sleep_min,sleep_day,sleep_enale,sleep_totalmin,week)
+                        if sleep_day == []:#单次闹钟只响一次
+                            if sleep_enale != 0:
+                                if cur_total_min > sleep_totalmin:
+                                    sleep.pop(j)
+                                    self.sleep_count = 0
+                                    self.sleep_flag  = 0 
+                                    j=0
+                                    # EventMesh.debug_log("wakeup wakeup dayu",sleep,j)
+                                    EventMesh.publish("set_storage_config",["sleep_alarm",sleep])#删除之后重新保存
+                                    # sleep = EventMesh.publish("get_storage_config","sleep_alarm")#删除之后重新保存
+                                    continue
+                                else:
+                                    if sleep_totalmin == cur_total_min and self.sleep_flag == 0:#14:00
+                                        self.sleep_count = 0
+                                        self.sleep_flag  = 0    
+                                        sleep.pop(j)
+                                        # EventMesh.debug_log("wakeup wakeup1",sleep,j)
+                                        EventMesh.publish("set_storage_config",["sleep_alarm",sleep])#删除之后重新保存
+                                        EventMesh.publish("sleep_alarm_event")#该吃药了                                                                                                                                              
+                                        break
+                        else:
+                            if sleep_enale != 0 and (week in sleep_day):#记录响过的时间分钟数
+                                if sleep_totalmin == cur_total_min and self.sleep_flag == 0:#14:00
+                                    self.sleep_flag  = 1
+                                    self.sleep_count = 0
+                                    self.sleep_oldtotalmin = sleep_totalmin
+                                    EventMesh.publish("sleep_alarm_event")#该吃药了                                                                                                                                                   
+                                    break
+                        j+=1
+
+
+        #该回家了
+        def home_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.home_oldtotalmin",self.home_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.home_oldtotalmin == 0:
+                self.home_oldtotalmin = cur_total_min #549
+            if self.home_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.home_flag == 1:
+                    self.home_flag = 0
+                    self.home_count = 0
+            home = ''
+            home = EventMesh.publish("get_storage_config","home_alarm")
+            # EventMesh.debug_log("sleep info2",sleep,cur_total_min)
+            if self.home_flag == 1:#表示闹钟响过清除标志
+                self.home_count+=1
+                if self.home_count > 6:
+                    self.home_count = 0
+                    self.home_flag = 0
+            if home != None:
+                if len(str(home)) != 0 and str(home) != '':
+                    # EventMesh.debug_log("home home 33",home)
+                    home_hour = int(str(home).split(":")[0])
+                    home_min = int(str(home).split(":")[1])
+                    
+                    home_totalmin = int(home_hour)*60+int(home_min)
+                    if home_totalmin == cur_total_min and self.home_flag == 0:#14:00
+                        self.home_flag  = 1
+                        self.home_count = 0
+                        self.home_oldtotalmin = home_totalmin
+                        EventMesh.publish("home_alarm_event")#该回家了                                                                                                                                                   
+
+
+        
+        #该休息了
+        def reset_alarm(self):
+            data = RTC().datetime()
+            hour = data[4]
+            min = data[5]
+
+            week = int(data[3])
+
+            date1 = data[1]
+            date2 = data[2]
+            cur_total_min = int(hour)*60+int(min)
+            # EventMesh.debug_log("self.reset_oldtotalmin",self.reset_oldtotalmin,cur_total_min,self.alarm_flag)
+            if self.reset_oldtotalmin == 0:
+                self.reset_oldtotalmin = cur_total_min #549
+            if self.reset_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃
+                if self.reset_flag == 1:
+                    self.reset_flag = 0
+                    self.reset_count = 0
+            reset_alarm = []
+            reset_alarm = EventMesh.publish("get_storage_config","reset_alarm")
+            # EventMesh.debug_log("reset_alarm info2",len(reset_alarm),cur_total_min)
+            if self.reset_flag == 1:#表示闹钟响过清除标志
+                self.reset_count+=1
+                if self.reset_count > 6:
+                    self.reset_count = 0
+                    self.reset_flag = 0
+            if reset_alarm != None:
+                if len(str(reset_alarm)) != 0 and str(reset_alarm) != []:
+                    for i in range(len(reset_alarm)):
+                        # print("i",i)
+                        start_hour = int(reset_alarm[i]["start_hour"])
+                        start_min = int(reset_alarm[i]["start_min"])
+
+                        end_hour = int(reset_alarm[i]["end_hour"])
+                        end_min = int(reset_alarm[i]["end_min"])
+
+                        # EventMesh.debug_log("reset_alarm home 33",reset_alarm)
+                        
+                        start_totalmin = int(start_hour)*60+int(start_min)
+                        end_totalmin = int(end_hour)*60+int(end_min)
+
+                        if start_totalmin == cur_total_min and self.reset_flag == 0:#14:00
+                            self.reset_flag  = 1
+                            self.reset_count = 0
+                            self.reset_oldtotalmin = start_totalmin
+                            EventMesh.publish("reset_alarm_event")#该休息了     
+                            break
+
+                        if end_totalmin == cur_total_min and self.reset_flag == 0:
+                            self.reset_flag  = 1
+                            self.reset_count = 0
+                            self.reset_oldtotalmin = end_totalmin
+                            EventMesh.publish("reset_end_alarm_event")#休息结束了     
+                            break
+                                                                                                                                                                    
+
+        def clear_normal_alarm(self,event,msg):#普通闹钟清除标志
+            self.normal_flag = 0
+            self.normal_count = 0
+            self.normal_oldtotalmin = 0
+
+        def clear_reset_alarm(self,event,msg):#休息清除标志
+            self.reset_flag = 0
+            self.reset_count = 0
+            self.reset_oldtotalmin = 0
+
+        def clear_home_alarm(self,event,msg):#回家清除标志
+            self.home_flag = 0
+            self.home_count = 0
+            self.home_oldtotalmin = 0
+
+
+        def clear_medicine_alarm(self,event,msg):#吃药清除标志
+            self.medicine_count = 0
+            self.medicine_flag  = 0
+            self.medicine_oldtotalmin = 0
+        
+
+        def clear_wakeup_alarm(self,event,msg):#起床标识
+            self.wakeup_flag = 0
+            self.wakeup_count = 0
+            self.wakeup_oldtotalmin = 0
+
+        def clear_sleep_alarm(self,event,msg):#睡觉标识
+
+            self.sleep_flag = 0
+            self.sleep_count = 0
+            self.sleep_oldtotalmin = 0
+
+            
+
+
+        def get_sim_Status(self, event, msg):
+            return sim.getStatus()
+        def get_device_ope(self, event, msg):
+            """
+            获取设备运营商信息
+            :param event:
+            :param msg:
+            :return: 运营商
+            """
+            net_ope_map = {
+                "UNICOM": "中国联通HD",
+                "CMCC": "中国移动HD",
+                "CT": "中国电信HD"
+            }
+            """获取运营商"""
+            try:
+                short_eons = net.operatorName()[1]
+            except Exception:
+                return "无"
+            return net_ope_map.get(short_eons, None)
+
+        def get_signal(self, event=None, msg=None):
+            """
+            获取信号事件
+            :param event:
+            :param msg:
+            :return: int 类型
+            """
+            return net.csqQueryPoll()
+
+        def get_time_bucket(self, time):
+            if time < 12:
+                return '上午'
+            else:
+                return '下午'
+
+        def get_week(self, week):
+            if week == 1:
+                return '一'
+            elif week == 2:
+                return '二'
+            elif week == 3:
+                return '三'
+            elif week == 4:
+                return '四'
+            elif week == 5:
+                return '五'
+            elif week == 6:
+                return '六'
+            elif week == 7 or week == 0:
+                return '日'
+
+        def get_time(self, event=None, msg=None):
+            """
+            获取时间事件
+            :param event:
+            :param msg:
+            :return: HH:MM 格式
+            """
+            rtc_time = self.rtc.datetime()
+            
+            date = ("%d月%d日" % (rtc_time[1], rtc_time[2]))
+            year = ("%04d年" % (rtc_time[0]))
+            week = ("星期%s"%(self.get_week(rtc_time[3])))
+            week_data = rtc_time[3]
+            time = [rtc_time[4], rtc_time[5]]
+            time_quantum = ("%s" % (self.get_time_bucket(rtc_time[4])))
+            
+            result = [time, time_quantum, date , week,year,week_data]
+            #时分,上午下午,日期,星期,年 星期
+            return result
+
+        def get_step_count(self, event=None, msg=None):
+            """
+            获取步数
+            """
+            # print("11111:{}".format(EventMesh.publish("get_storage_config","clear_state3")))
+            XYZ = self.gsensor.get_x_y_z()
+            tmp = 0
+            step =[0,0,0,0]
+            tmp =  self.gsensor.get_step() 
+            # EventMesh.debug_log("x:%d,y:%d,z:%d tmp %d",XYZ[0],XYZ[1],XYZ[2],tmp)
+            step[0]= tmp 
+            step[1] = XYZ[0]
+            step[2] = XYZ[1]
+            step[3] = XYZ[2]
+            # print("1222:{}".format(EventMesh.publish("get_storage_config","clear_state3")))
+            return step
+
+        def get_ic_cid(self, event, msg):
+            """
+            获取ic cid事件
+            :param event:
+            :param msg:
+            :return: str ic cid
+            """
+            return sim.getIccid()
+
+        def get_phone_num(self, event, msg):
+            """
+            获取电话号码事件
+            :param event:
+            :param msg:
+            :return: str number
+            """
+            return sim.getPhoneNumber()
+
+        def get_battery(self, event=None, msg=None):
+            """
+            获取电池事件,暂时没支持
+            :param event:
+            :param msg:
+            :return:
+            """
+
+            charge_state = '0'
+            if self.get_usb_state() == 1:
+                charge_state = '1'
+            else:
+                charge_state = '0'
+
+            #temp = Power.getVbatt()
+            temp = EventMesh.publish("get_curr_battery_level")
+            vbat = EventMesh.publish("get_battery",temp)
+            if vbat == None:
+                vbat = 100
+            # EventMesh.debug_log("vbat",vbat)
+            # if temp != None :
+            #     if temp <= 3505:
+            #         vbat = 0 
+            #     elif temp <= 3699:
+            #         vbat = 20 #"E:/vbat_20.jpg"
+            #     elif temp <= 3772:
+            #         vbat = 40 #"E:/vbat_40.jpg"
+            #     elif temp <= 3882:
+            #         vbat = 60 #"E:/vbat_60.jpg"
+            #     elif temp <= 4070:
+            #         vbat = 80 #"E:/vbat_80.jpg"
+            #     elif temp <= 4200:
+            #         vbat = 90 #
+            #     else:
+            #         vbat = 100 #"E:/vbat_100.jpg"
+            # else:
+            #     vbat = 100
+
+            result = [charge_state, vbat]
+
+            return result
+        #Set the current average battery level
+        def set_curr_battery_level(self, event=None, msg=None):
+            self.curr_battery_level = msg
+        
+        def get_curr_battery_level(self, event=None, msg=None):
+            return self.curr_battery_level
+
+        def get_device_fw_version(self, *args):
+            '''
+            获取设备固件版本号
+            '''
+            fw_version = modem.getDevFwVersion()
+            if isinstance(fw_version, str):
+                return fw_version
+            return "--"
+
+        def get_standby_time(self, *args):
+            '''
+            获取设备单次开机待机时间
+            '''
+            time_msg = utime.time()
+            d = int(
+                time_msg / 86400)  # The int call removes the decimals.  Conveniently, it always rounds down.  int(2.9) returns 2 instead of 3, for example.
+            time_msg -= (
+                    d * 86400)  # This updates the value of x to show that the already counted seconds won't be double counted or anything.
+            h = int(time_msg / 3600)
+            time_msg -= (h * 3600)
+            m = int(time_msg / 60)
+            time_msg -= (m * 60)
+            s = time_msg
+            result = "{}天{}小时{}分".format(d, h, m)
+            return result
+
+        def set_key(self, topic, msg):
+            self.key = msg["value"]
+        def get_key(self, topic, msg):
+            return self.key
+
+        def get_imei(self, topic, msg):
+            if not self.imei:
+                self.imei = modem.getDevImei()
+            self.imei = "876226002021444"#视频通话测试账号
+            # self.imei = "860132060128634" #860132060128634
+            return self.imei
+
+        def get_cid(self, topic, msg):
+            return self.cid
+
+        def set_cid(self, topic, msg):
+            self.cid = msg["value"]
+
+        def get_imsi(self, topic, msg):
+            if not self.imei:
+                self.imei = sim.getImsi()
+            return self.imsi
+
+        def get_password(self, topic, msg):
+            return self.password
+
+        def set_password(self, topic, msg):
+            self.password = msg["value"]
+
+        def set_ping(self, topic, msg):
+            self.PING = msg
+        def get_ping(self, topic, msg):
+            return self.PING
+
+        def set_connect(self, topic, msg):
+            #EventMesh.debug_log("set_connect:{}".format(msg))
+            self.connect = msg
+        def get_connect(self, topic, msg):
+            return self.connect
+
+        def start_blood_oxygen(self, topic, msg):
+            EventMesh.debug_log("start_blood_oxygen!!!")
+            self.hsensor.open_blood_oxygen()
+
+        def start_heart(self, topic, msg):
+            EventMesh.debug_log("start_heart!!!")
+            self.hsensor.open_heart()
+
+        def stop_blood_oxygen(self, topic, msg):
+            EventMesh.debug_log("stop_blood_oxygen!!!")
+            self.hsensor.close()
+
+        def stop_heart(self, topic, msg):
+            EventMesh.debug_log("stop_heart!!!")
+            self.hsensor.close()
+
+        def get_blood_oxygen(self, topic, msg):
+            data = self.hsensor.get_all_data()
+            return data[1]
+
+        def get_heart(self, topic, msg):
+            data = self.hsensor.get_all_data()
+            return data[0]
+        
+        def get_wear(self, topic, msg):
+            return self.hsensor.get_wear()
+        
+        def get_Hsensor(self, topic, msg):
+            return self.hsensor
+        
+        def Hsensor_set_sleep(self, topic, msg):
+            self.hsensor.set_sleep()
+
+        def start_temp(self, topic, msg):
+            EventMesh.debug_log("start_temp!!!!!!!")
+            WHO_AM_I = bytearray([0x01, 0])
+            I2C_SLAVE_ADDR = 0x49
+            #I2C_SLAVE_ADDR = 0x48
+            r_data = bytearray(2)
+            data = bytearray([0x61A0, 0])   # 唤醒
+            return self.i2c0.write(I2C_SLAVE_ADDR, WHO_AM_I, 1, data, 2)
+        def stop_temp(self, topic, msg):
+            EventMesh.debug_log("stop_temp!!!!!!!")
+            WHO_AM_I = bytearray([0x01, 0])
+            I2C_SLAVE_ADDR = 0x49
+            #I2C_SLAVE_ADDR = 0x48
+            r_data = bytearray(2)
+            data = bytearray([0x60A0, 0])   #休眠
+            return self.i2c0.write(I2C_SLAVE_ADDR, WHO_AM_I, 1, data, 2)
+            
+        def get_temp(self, topic, msg):
+            WHO_AM_I = bytearray([0x00, 0])
+            I2C_SLAVE_ADDR = 0x49
+            #I2C_SLAVE_ADDR = 0x48
+            r_data = bytearray(2)
+            self.i2c0.read(I2C_SLAVE_ADDR, WHO_AM_I, 1, r_data, 2, 0)
+            #EventMesh.debug_log("temp_data:{}".format(r_data))
+            temp_s = ((r_data[0]<<8) | (r_data[1]))>>4
+            #EventMesh.debug_log("temp_s:{}".format(temp_s))
+            temp_data = temp_s * 0.0625
+            EventMesh.debug_log("temp_data:{}".format(temp_data))
+            return temp_data
+    
+                
+
+        def sim_slot_get(self, topic=None, msg=None):
+            return sim.getCurSimid()
+
+        def sim_slot_switch(self, topic=None, slot=None):
+            """
+            sim 卡槽切换
+            :param topic:
+            :param slot:
+            :return: 切换sim卡卡槽  0 切换成功, 1 无需切换, -1 切换失败
+            """
+            if self.sim_slot_get() == slot:
+                return 1
+            else:
+                return sim.switchCard(slot)
+
+        def usb_event_cb(self, state):
+            status = state
+
+            if status == 1:#插入USB
+                EventMesh.debug_log("charge R_CHARGE_in")
+                EventMesh.publish("clear_usb_flag")
+                EventMesh.publish("set_usb", 1)#
+                pass
+            elif status == 0:#拨出usbs
+                EventMesh.publish("clear_usb_flag")
+                EventMesh.publish("set_usb", 2)#
+                EventMesh.debug_log("charge R_CHARGE_out")
+
+                
+                
+
+        
+
+        def get_usb_state(self):
+            state = self.usb.getStatus()
+            if state == -1:
+                state = 0
+            return state
+        
+
+    def wifiScan_cb(args):
+            EventMesh.publish(constants.EVENT.WIFIINFO, args)
+            wifiScan.control(0)
+
+    class LocationManager(Abstract):
+
+        def __init__(self):
+            self.gps = None
+            #self.match = GPSMatch()
+            self.timer_read_GPS_info = osTimer()
+            self.wifi_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
+            self.start_agps = 0
+            read_data = EventMesh.publish("get_storage_config","isOpenGNSS")#获取是否打开GNSS
+            if read_data != None:
+                self.isOpenGNSS = read_data
+            else:#默认关闭GNSS
+                self.isOpenGNSS = "1"
+                EventMesh.publish("set_storage_config",["isOpenGNSS",self.isOpenGNSS])
+
+            self.isOpenGNSS = EventMesh.publish("get_storage_config","isOpenGNSS")
+            if self.isOpenGNSS == None:
+                self.isOpenGNSS = "1"
+            if self.isOpenGNSS == "1":
+                quecgnss.init()
+                quecgnss.gnssEnable(0)
+        @staticmethod
+        def get_date():
+            return "{:04d}-{:02d}-{:02d}".format(*utime.localtime()[0:3])
+
+        @staticmethod
+        def get_time():
+            return "{:02d}:{:02d}:{:02d}".format(*utime.localtime()[3:6])
+
+        def post_processor_after_instantiation(self):
+            # _gps_cfg = {
+            #     "UARTn": UART.UART1,
+            #     "buadrate": 115200,
+            #     "databits": 8,
+            #     "parity": 0,
+            #     "stopbits": 1,
+            #     "flowctl": 0,
+            #     "PowerPin": Pin.GPIO2,
+            #     "StandbyPin": Pin.GPIO3,
+            #     "BackupPin": None,
+            #     "gps_mode": 0x01,
+            # }
+            # self.gps = GPS(**_gps_cfg)
+            # self.gps.power_switch(0)#关闭GPS
+            EventMesh.subscribe(constants.EVENT.GPSOPEN, self.gps_open)
+            EventMesh.subscribe(constants.EVENT.GPSCLOSE, self.gps_close)
+            EventMesh.subscribe(constants.EVENT.START_LOCATION, self.start_location)
+            EventMesh.subscribe(constants.EVENT.START_LOCATION_TEST, self.start_location_test)
+            EventMesh.subscribe(constants.EVENT.WIFIINFO, self.WIFI_INFO)
+            EventMesh.subscribe(constants.EVENT.WIFISCANOPEN,self.WIFI_scan_open)
+            EventMesh.subscribe(constants.EVENT.CLOSE_LOCATION,self.close_location)
+            EventMesh.subscribe("get_location_flag",self.get_location_flag)
+            
+            #EventMesh.subscribe(constants.EVENT.GPSCLOSE, self.gps_close)
+        def get_location_flag(self, event, msg):
+            return self.location_flag
+        def start_location(self, event, msg):
+            self.location_queue.put(msg)#测试类型入队
+            self.gps_data = {}
+            self.wifi_data = []
+            self.cell_data = []
+            self.location_timer_count = 0
+            self.GSV_sig_ok_count = 0
+            EventMesh.debug_log("start_location:{}".format(msg))
+            if( self.location_flag == 1):
+                return
+            _thread.stack_size((9+5)*1024)
+            self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
+            _thread.stack_size(8*1024)
+            
+            self.location_flag = 1
+            self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+            #self.gps_open(event, msg)
+
+
+        def start_location_test(self, event, msg):
+            EventMesh.debug_log("start_location_test")
+            
+            self.location_type = 1
+            if( self.location_flag == 1):
+                return
+            _thread.stack_size((9+4)*1024)
+            self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
+            _thread.stack_size(8*1024)
+        
+            self.location_timer_count = 0
+            self.location_flag = 1
+            #self.gps_open(event, msg)
+            self.location_type = 1
+            self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+    
+
+        def close_location(self, event, msg):
+            self.location_flag = 0
+            self.location_type = 0
+            self.timer_read_GPS_info.stop()
+
+            
+
+        def WIFI_INFO(self, event, msg):
+            self.wifi_data = msg
+            # EventMesh.debug_log("WIFI_INFO:")
+            # EventMesh.debug_log([msg[0],msg])
+
+        def WIFI_scan_open(self, event, msg):
+            #EventMesh.debug_log("WIFI_scan_open")
+            
+
+            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()
+                #EventMesh.debug_log("wifiScan.asyncStart")
+            else :
+                EventMesh.debug_log("WIFI_scan_open:error1") 
+        def gps_open(self, event, msg):
+            if self.isOpenGNSS == "1":
+                #EventMesh.debug_log("publish:gps_open")
+                #quecgnss.init()
+                quecgnss.gnssEnable(2)
+                #self.gps.__gps_nmea_data_clean()
+        def gps_close(self, event, msg):
+            if self.isOpenGNSS == "1":
+                quecgnss.gnssEnable(0)
+        def location_timer(self, *args, **kwargs):
+            
+            self.location_timer_count = self.location_timer_count +1
+            self.location_check_data_timer_count = self.location_check_data_timer_count+1
+
+        def Location_send(self, msg) :
+            EventMesh.debug_log("Location_send1")
+            if self.location_queue.empty() == True:
+                return
+            EventMesh.debug_log("Location_send2")
+            while True:
+                if self.location_queue.empty() == False:
+                    TYPE = self.location_queue.get()
+                    date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
+                    date = date[2:]
+                    #date = "180916,025723"
+                    GPS_type = "V"
+                    latitude = "0.000000,N"
+                    longitude = "0.000000,E"
+                    speed = "0.00"
+                    direction = "0.0"
+                    high = "100.0"
+                    number = "0"
+                    precision = "24"
+                    if msg[0] :#有GPS数据
+                        GPS_type = "A"
+                        # 纬度
+                        latitude = msg[0]["latitude"]
+                        # 经度
+                        longitude = msg[0]["longitude"]
+                        # 速度
+                        speed = msg[0]["speed"]
+                        # 方向
+                        direction = "0"
+                        if msg[0]["direction"] :
+                            direction = msg[0]["direction"]
+                        # 高度
+                        high = msg[0]["high"]
+                        high_tmp = high.split(".")
+                        if len(high_tmp) >= 2 :
+                            high = "%s"%(high_tmp[0])
+                        # 讯号质量:搜索到的卫星数目
+                        number = msg[0]["number"]
+                        precision = msg[0]["precision"]
+                        #date = msg[0]["date"]
+                    
+                    #gsm 信号强度
+                    gsm_sig =  str((100//31)*EventMesh.publish("screen_get_sig"))
+                    # 电池电量百分比 
+                    bat_tmp = EventMesh.publish("screen_get_battery")
+                    battery_caption =  str(bat_tmp[1])
+                    #步数
+                    old_step = 0
+                    step = 0
+                    step = EventMesh.publish("get_old_step_value")
+                    if step != 0:
+                        tmp_data  = EventMesh.publish("get_storage_config","old_step_new")
+                        if tmp_data != None:
+                            old_step = tmp_data
+                        if old_step !=  step:
+                            EventMesh.publish("set_storage_config",["old_step",step])
+                            EventMesh.publish("set_storage_config",["old_step_new",step])
+                            
+                    old_step = step
+                    # step = str(EventMesh.publish(constants.EVENT.GET_STEP)[0])
+                    #翻转次数
+                    turn_count = "0"
+                    #终端状态
+                    state = "%08X"%(EventMesh.publish("get_dev_state"))
+                    #EventMesh.debug_log("TYPE:{}".format(TYPE))
+                    if type(TYPE) == list:#队列里的数据有终端状态,则用队里的终端状态
+                        if len(TYPE)>= 2 :
+                            state = "%08X"%(TYPE[1])
+                    
+                    EventMesh.debug_log("state:{}".format(state))
+                    #基站数据
+                    CELL_num = len(msg[2])
+                    CELL_data = "1," #时延
+                    if msg[2] != []:
+                        for CELL in msg[2] :
+                            if CELL[0] == 0 :
+                                CELL_data += "%X,"%(int(CELL[2])) #MCC
+                                CELL_data += str(CELL[3]) +","#MNC
+                                CELL_data += str(CELL[5]) +","#tac,区域码
+                                CELL_data += str(CELL[1]) +","#基站编号 CID
+                                CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
+                            else :
+                                CELL_data += str(CELL[5]) +","#tac,区域码
+                                CELL_data += str(CELL[1]) +","#基站编号 CID
+                                CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
+                        CELL_data = CELL_data[:(len(CELL_data)-1)]
+                    #WIFI数据
+                    WIFI_num = 0 
+                    WIFI_data = ""
+                    if msg[1] :
+                        WIFI_num = msg[1][0]
+                        i = 0
+                        for MAC in msg[1][1] :
+                            WIFI_data += "wifi%d,%s,%d,"%(i,str(MAC[0]),MAC[1])
+                            i += 1
+                        WIFI_data = WIFI_data[:(len(WIFI_data)-1)]
+                    WIFI_data = WIFI_data.lower()
+                    #send_data = "UD ,%s ,%s     ,%s       ,%s       ,%s   ,%s       ,%s  ,%s    ,%s     ,%s             ,%s  ,%s        ,%s   ,%d     ,%s       ,%d      ,%s"\
+                    #              %(date,GPS_type,latitude,longitude,speed,direction,high,number,gsm_sig,battery_caption,step,turn_count,state,CELL_num,CELL_data,WIFI_num,WIFI_data)
+                    #定位数据
+                    send_data = "%s,%s,%s"%(date,GPS_type,latitude)
+                    send_data += ",%s,%s,%s"%(longitude,speed,direction)
+                    send_data += ",%s,%s,%s"%(high,number,gsm_sig,)
+                    send_data += ",%s,%s,%s"%(battery_caption,step,turn_count)
+                    send_data += ",%s,%d,%s"%(state,CELL_num,CELL_data)
+                    send_data += ",%d,%s"%(WIFI_num,WIFI_data)
+                    send_data+=",%s"%(precision)
+                    #EventMesh.debug_log("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
+            
+                
+                    EventMesh.debug_log("Location_send3:{}:{}".format(TYPE,send_data))
+                    if type(TYPE) == list:
+                        EventMesh.publish(TYPE[0],send_data)
+                    else:
+                        EventMesh.publish(TYPE,send_data)
+                else :
+                    break
+
+        def GxGGA_latitude(self, gga_data):
+            """Parse latitude from GGA"""
+            if gga_data:
+                latitude_re = ure.search(r",[0-9]+\.[0-9]+,[NS],", gga_data)
+                if latitude_re:
+                    latitude = latitude_re.group(0)[1:-3]
+                    return str(float(latitude[:2]) + float(latitude[2:]) / 60)
+            return ""
+        def GxGGA_longitude(self, gga_data):
+            """Parse longitude from GGA"""
+            if gga_data:
+                longitude_re = ure.search(r",[0-9]+\.[0-9]+,[EW],", gga_data)
+                if longitude_re:
+                    longitude = longitude_re.group(0)[1:-3]
+                    return str(float(longitude[:3]) + float(longitude[3:]) / 60)
+            return ""
+
+        def GxGGA_altitude(self, gga_data):
+            """Parse altitude from GGA"""
+            if gga_data:
+                altitude_re = ure.search(r",-*[0-9]+\.[0-9]+,M,", gga_data)
+                if altitude_re:
+                    return altitude_re.group(0)[1:-3]
+            return ""
+        def location_thread(self):
+            
+            self.wifi_data = []
+            self.gps_data = {}
+            self.cell_data = []
+            gnss_r_data = []
+            self.GSV_sig_ok_count = 0
+            self.GSV_sig_very_ok_count = 0
+            self.GGA_count = 0
+            self.RMC_A_count = 0
+            # if self.start_agps == 1: #开启agps
+            #     self.start_agps = 0
+            #     quecgnss.configSet(2,1)
+            if self.lpm_fd == None:
+                self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
+            pm.wakelock_lock(self.lpm_fd)
+            EventMesh.debug_log("location_thread:1")
+            EventMesh.publish(constants.EVENT.GPSOPEN)
+            EventMesh.debug_log("location_thread:2")
+            #self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+            EventMesh.debug_log("location_thread:3")
+            #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)
+            GSV_dict= {}
+            while self.location_flag == 1:
+                try :   
+                    
+                    match_gga_data = []
+                    #match_gsv_data = []
+                    gnss_r_data = []
+                    # if self.location_check_data_timer_count >= 3:
+                    #     pm.autosleep(0)#唤醒
+                    #     pm.sclkEx_set(0, 1, 5)
+                    if self.location_check_data_timer_count >= 1 :#3秒查一次基站数据和wifi数据
+                        self.location_check_data_timer_count = 0
+                        #EventMesh.debug_log(self.location_timer_count)
+                        GSV_dict= {}
+                        if self.isOpenGNSS == "1":                    
+                            #检查GNSS数据
+                            if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
+
+                                pass
+                                tmp_ok_count = 0
+                                tmp_very_ok_count = 0
+                                gsv_data = quecgnss.get_gsv()
+                                rmc_data = quecgnss.get_rmc()
+                                gga_data = quecgnss.get_gga()
+                                vtg_data = quecgnss.get_vtg()
+                                # EventMesh.debug_log("gsv:{}".format(quecgnss.get_gsv()))
+                                # EventMesh.debug_log("gga:{}".format(quecgnss.get_gga()))
+                                # EventMesh.debug_log("rmc:{}".format(quecgnss.get_rmc()))
+                                # EventMesh.debug_log("vtg:{}".format(quecgnss.get_vtg())) 
+                                for i in range(len(gsv_data)) :
+                                    
+                                    if i % 2 == 0:
+                                        if i+1 >= len(gsv_data) :
+                                            # EventMesh.debug_log("gsv_data num error!!")
+                                            break
+                                        GSV_dict[gsv_data[i]] = gsv_data[i+1]
+                                        #EventMesh.debug_log("type:gsv_data{}".format(type(gsv_data[i+1])))
+                                        try:
+                                            #EventMesh.debug_log("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
+                                            if gsv_data[i+1] :
+                                                if (gsv_data[i+1])>=20:
+                                                    tmp_ok_count +=1   
+                                                if (gsv_data[i+1])>=30:
+                                                    tmp_very_ok_count +=1  
+                                                    
+                                        except Exception as e:
+                                            usys.print_exception(e)
+                                        
+                                if(tmp_ok_count > self.GSV_sig_ok_count ):
+                                    self.GSV_sig_ok_count = tmp_ok_count
+                                if(tmp_very_ok_count > self.GSV_sig_very_ok_count ):
+                                    self.GSV_sig_very_ok_count = tmp_very_ok_count
+                                match_rmc_data = rmc_data.split(",")
+                                if len (match_rmc_data)>3: #有rmc数据
+                                        if match_rmc_data[2] == 'A':    
+                                            match_gga_data = gga_data.split(",")
+                                            if len(match_gga_data) >4: #数据全
+                                                match_vtg_data = vtg_data.split(",")
+                                                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(self.GxGGA_latitude(gga_data)).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(self.GxGGA_longitude(gga_data)).split(".")
+                                                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])
+                                                
+                                                high = "0"#高度
+                                                high = str(self.GxGGA_altitude(gga_data))
+                                                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": direction,
+                                                    "speed": speed,
+                                                    "number": number, 
+                                                    "date":  gps_date,
+                                                    "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
+
+                    if self.location_type == 1: #测试模式
+                        self.location_timer_count = 0
+                        
+                        EventMesh.publish("PUSH_LOCATION_DATA", [[self.gps_data,GSV_dict],self.wifi_data,self.cell_data]) 
+                        if self.gps_data  != {} : #发送数据 
+                            EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+                            self.location_queue.put(constants.PROTOCOL.UD_SEND)
+                            self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                            
+
+                    elif self.location_type == 0: #正常模式     
+                        if self.gps_data  != {} or self.location_timer_count > 100: #or( self.wifi_data != [] and self.cell_data != []): 
+                            if self.location_queue.empty() == False:#有定位队列
+                                pass
+                                #EventMesh.txt_log("LOCATION timer:{} ok:{} very_ok:{}".format(self.location_timer_count,self.GSV_sig_ok_count))   
+                                #EventMesh.txt_log("LOCATION:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
+                            if self.gps_data  == {}: #定位超时,且信噪比多个大于30,下次启动agps
+                                if self.GSV_sig_very_ok_count > 3:#3个超30以上
+                                    self.start_agps = 1
+                                    #EventMesh.txt_log("open agps:{}".format(GSV_dict))
+                            #upload_time = EventMesh.publish("get_upload_data")    
+                            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.isOpenGNSS != "1" or (self.GSV_sig_ok_count <= 1 and self.location_timer_count > 20)) and self.wifi_data != [] and self.cell_data != [] : #超过40秒且信号大于30的不足3个
+                            EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
+                            EventMesh.debug_log("Location_send:CLOSE_LOCATION")  
+                            #EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
+                            self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+
+                
+                    
+                except Exception as e:
+                    usys.print_exception(e)
+                    EventMesh.txt_log("location_thread:ERROR:".format(e))
+                    #EventMesh.debug_log("location_thread:ERROR:{}".format(usys.print_exception(e)))
+                    EventMesh.debug_log("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(500)
+
+            #self.timer_read_GPS_info.stop()
+            #self.gps.power_switch(0)
+            wifiScan.control(0)
+            EventMesh.publish(constants.EVENT.GPSCLOSE)
+            # 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)
+            EventMesh.debug_log("CLOSE_LOCATION")
+            #EventMesh.txt_log("CLOSE_LOCATION")
+
+                    
+
+    class AddrBookManager(Abstract):
+        # 通讯录
+        def __init__(self):
+            self.read_phonebook = {}
+            self.check_json = 0
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/phonebook.json")
+
+            if self.check_json == True:
+                with open("/usr/static/storage_file/phonebook.json","r",encoding="utf-8") as fd:
+                    self.read_phonebook = ujson.load(fd)
+                    EventMesh.debug_log("读取电话本")
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_phonebook_list", self.get)
+            EventMesh.subscribe("set_phonebook_list", self.set)
+            EventMesh.subscribe("call_phonebook_one_call", self.call_phonebook_one_call)
+            EventMesh.subscribe("call_phonebook_two_call", self.call_phonebook_two_call)
+            EventMesh.subscribe("call_phonebook_three_call", self.call_phonebook_three_call)
+
+            EventMesh.subscribe("call_phonebook_num", self.call_phonebook_num)
+
+        def get(self, event, msg):
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/phonebook.json")
+            return [self.check_json,self.read_phonebook]
+        
+        def call_phonebook_num(self, event, msg):
+            name = ''
+            key_tmp = ''
+            phone_num = int(msg)
+            if self.read_phonebook != {}:
+                if len(self.read_phonebook) >= phone_num:
+                    phonebook_keys = sorted(self.read_phonebook.keys())
+                    name = self.read_phonebook[phonebook_keys[phone_num-1]]
+                    key_tmp = phonebook_keys[phone_num-1]
+                    if len(name) != 0:
+                        EventMesh.publish("save_phonename",str(name))
+                        EventMesh.publish("save_phonenum",str(name))
+                        EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                    else:
+                        EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+                else:
+                    EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+            else:
+                EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+            EventMesh.debug_log("call_phonebook_call name:{} msg:{}".format(len(self.read_phonebook),msg))
+
+        def call_phonebook_one_call(self, event, msg):
+            name = ''
+            key_tmp = ''
+            if self.read_phonebook != {}:
+                if len(self.read_phonebook) >= 1:
+                    phonebook_keys = sorted(self.read_phonebook.keys())
+                    name = self.read_phonebook[phonebook_keys[0]]
+                    key_tmp = phonebook_keys[0]
+                    if len(name) != 0:
+                        EventMesh.publish("save_phonename",str(name))
+                        EventMesh.publish("save_phonenum",str(name))
+                        EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                    else:
+                        EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+                else:
+                    EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+            else:
+                EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+            EventMesh.debug_log("call_phonebook_one_call name:{} key_tmp:{} len:{}".format(name,key_tmp,len(self.read_phonebook)))
+
+        def call_phonebook_two_call(self, event, msg):
+            name = ''
+            key_tmp = ''
+            if self.read_phonebook != {}:
+                if len(self.read_phonebook) >= 2:
+                    phonebook_keys = sorted(self.read_phonebook.keys())
+                    name = self.read_phonebook[phonebook_keys[1]]
+                    key_tmp = phonebook_keys[1]
+                    if len(name) != 0:
+                        #voiceCall.callStart(str(name))
+                        EventMesh.publish("save_phonename",str(name))
+                        EventMesh.publish("save_phonenum",str(name))
+                        EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                    else:
+                        EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+                    
+                else:
+                    EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+            else:
+                EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+                EventMesh.debug_log("call_phonebook_two_call name:{} key_tmp:{}".format(name,key_tmp))
+        
+        def call_phonebook_three_call(self, event, msg):
+            name = ''
+            key_tmp = ''
+            if self.read_phonebook != {}:
+                if len(self.read_phonebook) >= 3:
+                    phonebook_keys = sorted(self.read_phonebook.keys())
+                    name = self.read_phonebook[phonebook_keys[2]]
+                    key_tmp = phonebook_keys[2]
+                    if len(name) != 0:
+                        #voiceCall.callStart(str(name))
+                        EventMesh.publish("save_phonename",str(name))
+                        EventMesh.publish("save_phonenum",str(name))
+                        EventMesh.publish("dial_out_call_center_cb",str(name))#电话拨出去
+                    else:
+                        EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+                    
+                else:
+                    EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+            else:
+                EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
+            EventMesh.debug_log("call_phonebook_three_call name:{} key_tmp:{}".format(name,key_tmp))
+
+        def set(self, event, msg):
+            self.check_json = msg[0]
+            self.read_phonebook = msg[1]
+
+    import sms
+    class MsgManager(Abstract):
+        # 短信
+        def __init__(self):
+            self.msg_nums = 0
+            self.msg_detail = ""
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_msg_nums", self.get_msg_nums)
+            # 可通过此push_addr_book_list主动推送
+            EventMesh.subscribe("get_msg_detail", self.get_msg_detail)
+
+        def get_msg_nums(self, event, msg):
+
+            self.msg_nums = sms.getMsgNums() 
+            EventMesh.debug_log("self.msg_nums {}:".format(self.msg_nums))
+            return self.msg_nums
+        
+        def get_msg_detail(self, event, msg):
+            
+            # self.msg_detail = sms.searchTextMsg(self.msg_nums)
+            # EventMesh.debug_log("self.msg_detai {}:".format(self.msg_detai))
+            return{
+                "小明":"有内鬼,停止交易",
+                "小红":"今晚十点一起吃饭"
+            }
+
+    class MsgdetailManager(Abstract):
+        def __init__(self):
+            self.level = 0
+            self.msg_name = ""
+            self.msg_content = ""
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("save_msg_name", self.save_msg_name)
+            EventMesh.subscribe("save_msg_content", self.save_msg_content)
+            EventMesh.subscribe("get_msg_name", self.get_msg_name)
+            EventMesh.subscribe("get_msg_content", self.get_msg_content)
+
+        def save_msg_name(self, event, msg): 
+            self.msg_name = str(msg)
+            EventMesh.debug_log("save_msg_name:msg".format(msg))
+        
+        def save_msg_content(self, event, msg):
+            self.msg_content = str(msg)
+            EventMesh.debug_log("save_msg_content:msg".format(msg))
+        
+        def get_msg_content(self, event, msg):
+            return self.msg_content
+
+        def get_msg_name(self, event, msg):
+            return self.msg_name
+
+    class CallLogManager(Abstract):
+        # 通话记录
+        def __init__(self):
+            self.read_call_log = {}
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/Call_log.json")
+
+            if self.check_json == True:
+                with open("/usr/static/storage_file/Call_log.json","r",encoding="utf-8") as fd:
+                    self.read_call_log = ujson.load(fd)
+                    EventMesh.debug_log("读取通话记录")
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_call_log_list", self.get)
+            EventMesh.subscribe("set_call_log_list", self.set)
+
+        def get(self, event, msg):
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/Call_log.json")
+            return [self.check_json,self.read_call_log]
+
+        def set(self, event, msg):
+            return
+            self.check_json = msg[0]
+            self.read_call_log = msg[1]
+            with open("/usr/static/storage_file/Call_log.json","w+",encoding="utf-8") as fd:
+                ujson.dump(self.read_call_log,fd)
+        # def call_usr(self,event,msg):
+        #     content = self.log[msg]
+        #     # 参数1 姓名  参数2  电话   参数3 1/主动呼叫  0别人呼叫
+        #     EventMesh.publish("call_in", [content[2], content[0], 1])
+
+
+
+    class PhoneCallingManager(Abstract):
+        def __init__(self):
+            self.phonenum = ""
+            self.phonename = ""
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("save_phonenum", self.save_phonenum)
+            EventMesh.subscribe("get_phonenum", self.get_phonenum)
+            EventMesh.subscribe("get_phonename", self.get_phonename)
+            EventMesh.subscribe("save_phonename", self.save_phonename)
+
+        def get_phonename(self, event, msg): 
+            return self.phonename
+
+        def save_phonename(self, event, msg): 
+            self.phonename = str(msg)
+
+        def save_phonenum(self, event, msg): 
+            self.phonenum = str(msg)
+        
+        def get_phonenum(self, event, msg):
+            return self.phonenum
+
+    #获取心率 血氧 步数历史数据
+    class gethistoryDataManager(Abstract):
+        def __init__(self):
+            self.oldHr = 0
+            self.oldspo2 = 0
+            self.oldstep = 0
+            self.old_step = 0
+            self.read_histroy_hr_data = []
+            self.read_histroy_temp_data = []
+            self.read_histroy_spo2_data = []
+
+            oldHr  = EventMesh.publish("get_storage_config","old_hr")
+            if oldHr != None:
+                self.oldHr = oldHr  
+            old_spo2  = EventMesh.publish("get_storage_config","old_spo2")
+            if old_spo2 != None:
+                self.oldspo2 = old_spo2 
+            old_step  = EventMesh.publish("get_storage_config","old_step")    
+            if old_step != None:
+                self.oldstep = old_step
+
+
+            check_hr= ql_fs.path_exists("/usr/static/storage_file/history_hr.json")
+            if check_hr == True :
+                with open("/usr/static/storage_file/history_hr.json","r") as fd:#音频文件编号
+                    self.read_histroy_hr_data = ujson.load(fd)
+            
+            check_temp= ql_fs.path_exists("/usr/static/storage_file/history_temp.json")
+            if check_temp == True :
+                with open("/usr/static/storage_file/history_temp.json","r") as fd:#音频文件编号
+                    self.read_histroy_temp_data = ujson.load(fd)
+
+            check_spo2= ql_fs.path_exists("/usr/static/storage_file/history_spo2.json")
+            if check_spo2 == True :
+                with open("/usr/static/storage_file/history_spo2.json","r") as fd:#音频文件编号
+                    self.read_histroy_spo2_data = ujson.load(fd)
+            self.temp_value = 0
+            
+            # self.read_histroy_hr_data=[{"timeSec":16789890,"value":90},{"timeSec":16789888,"value":78},{"timeSec":16789688,"value":68},{"timeSec":16789898,"value":58},\
+            #                              {"timeSec":16789897,"value":88},{"timeSec":16789867,"value":77},{"timeSec":16789895,"value":70}]
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_old_hr_data", self.save_hr_value)
+            EventMesh.subscribe("get_old_hr_data", self.get_hr_value)
+            EventMesh.subscribe("set_old_spo2_data", self.save_spo2_value)
+            EventMesh.subscribe("get_old_spo2_data", self.get_spo2_value)
+
+            EventMesh.subscribe("get_old_step_value", self.get_old_step_value)
+            EventMesh.subscribe("set_old_step_value", self.set_old_step_value)
+
+
+            EventMesh.subscribe("get_history_hr_value", self.get_history_hr_value)
+            EventMesh.subscribe("set_history_hr_value", self.set_history_hr_value)
+
+            EventMesh.subscribe("get_history_temp_value", self.get_history_temp_value)
+            EventMesh.subscribe("set_history_temp_value", self.set_history_temp_value)
+
+            EventMesh.subscribe("get_history_spo2_value", self.get_history_spo2_value)
+            EventMesh.subscribe("set_history_spo2_value", self.set_history_spo2_value)
+
+        
+
+        def get_history_spo2_value(self, event, msg): #近7次血氧历史数据统计显示
+            return self.read_histroy_spo2_data
+
+        def set_history_spo2_value(self, event, msg): 
+            pass
+
+
+
+        def get_history_temp_value(self, event, msg): #近7次体温历史数据统计显示
+            return self.read_histroy_temp_data
+
+        def set_history_temp_value(self, event, msg): 
+            self.temp_value = msg
+            if self.temp_value > 0:
+                # date_tmp = utime.localtime()
+                # time_tmp = utime.mktime(date_tmp)
+                # if len(self.read_histroy_temp_data) >= 7:
+                #     sort_new = {}
+                #     sort_new = sorted(self.read_histroy_temp_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
+                #     EventMesh.debug_log(sort_new)
+                #     for i in range(len(self.read_histroy_temp_data)-1):
+                #         sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
+                #         self.read_histroy_temp_data[i] = sort_new[i]
+                #         pass
+                #     self.read_histroy_temp_data[6] = {"timeSec": time_tmp, "temp": self.temp_value}
+                # else:
+                #     self.read_histroy_temp_data.append({"timeSec": time_tmp, "temp": self.temp_value}) 
+
+                # with open("/usr/static/storage_file/history_temp.json","w",encoding="utf-8") as fd:
+                #     ujson.dump(self.read_histroy_temp_data,fd)
+                #EventMesh.debug_log(self.read_histroy_temp_data)
+                pass
+            else:
+                pass
+
+        def get_history_hr_value(self, event, msg): #近7次心率历史数据统计显示
+            return self.read_histroy_hr_data
+
+        def set_history_hr_value(self, event, msg): 
+            pass
+                
+            
+
+        def save_hr_value(self, event, msg): 
+            if msg >= 50:
+                EventMesh.publish("set_storage_config",["old_hr",msg])
+                self.oldHr = msg
+                
+
+                date_tmp = utime.localtime()
+                time_tmp = utime.mktime(date_tmp)
+                if len(self.read_histroy_hr_data) >= 7:
+                    sort_new = {}
+                    sort_new = sorted(self.read_histroy_hr_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
+                    EventMesh.debug_log(sort_new)
+                    for i in range(len(self.read_histroy_hr_data)-1):
+                        sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
+                        self.read_histroy_hr_data[i] = sort_new[i]
+                        pass
+                    self.read_histroy_hr_data[6] = {"timeSec": time_tmp, "hr": self.oldHr}
+                else:
+                    self.read_histroy_hr_data.append({"timeSec": time_tmp, "hr": self.oldHr}) 
+
+
+                with open("/usr/static/storage_file/history_hr.json","w",encoding="utf-8") as fd:
+                    ujson.dump(self.read_histroy_hr_data,fd)
+                pass
+            else:
+                EventMesh.publish("set_storage_config",["old_hr",msg])
+                pass
+
+
+        def get_hr_value(self, event, msg): 
+            return self.oldHr
+
+        def save_spo2_value(self, event, msg): 
+            if msg >= 85:
+                # EventMesh.publish("set_storage_config",["old_spo2",msg])
+                # self.oldspo2 = msg
+
+
+                # date_tmp = utime.localtime()
+                # time_tmp = utime.mktime(date_tmp)
+                # if len(self.read_histroy_spo2_data) >= 7:
+                #     sort_new = {}
+                #     sort_new = sorted(self.read_histroy_spo2_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
+                #     EventMesh.debug_log(sort_new)
+                #     for i in range(len(self.read_histroy_spo2_data)-1):
+                #         sort_new[i] = sort_new[i+1]#0==1 1== 2 2== 3 3==4 4==5 5==6 6==7
+                #         self.read_histroy_spo2_data[i] = sort_new[i]
+                #         pass
+                #     self.read_histroy_spo2_data[6] = {"timeSec": time_tmp, "spo2": self.oldspo2}
+                # else:
+                #     self.read_histroy_spo2_data.append({"timeSec": time_tmp, "spo2": self.oldspo2}) 
+
+                # with open("/usr/static/storage_file/history_spo2.json","w",encoding="utf-8") as fd:
+                #     ujson.dump(self.read_histroy_spo2_data,fd)
+                # #EventMesh.debug_log(self.read_histroy_spo2_data)
+                #播放语音
+                # EventMesh.publish("set_hr_blood_led",2)#测量成功
+                pass
+            else:
+                pass
+                pass
+
+        def get_spo2_value(self, event, msg): 
+            return self.oldspo2
+        
+        def set_old_step_value(self, event, msg): 
+            self.oldstep = msg
+            EventMesh.publish("set_storage_config",["old_step",msg])
+            
+            
+        def get_old_step_value(self, event, msg): 
+            step = EventMesh.publish(constants.EVENT.GET_STEP)
+            self.old_step = self.oldstep + step[0]
+            return self.old_step
+    #获取旧的时间戳
+    class getOldTimeManager(Abstract):
+        # 获取天气数据
+        def __init__(self):
+            self.time_sec = 0
+            self.time_step = 0
+            self.step_second = 0
+            tmp_data = EventMesh.publish("get_storage_config","old_time")
+            if tmp_data !=None :
+                self.time_sec = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","clear_state")
+            if tmp_data !=None :
+                self.time_step = tmp_data[0]
+                self.step_second = tmp_data[1]
+
+            
+            
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_old_time_data", self.get_old_time_data)
+            EventMesh.subscribe("set_old_time_data", self.set_old_time_data)
+
+            EventMesh.subscribe("get_old_step_data", self.get_old_step_data)
+            EventMesh.subscribe("set_old_step_data", self.set_old_step_data)
+
+            EventMesh.subscribe("set_test_data1", self.set_test_data1)
+
+            EventMesh.subscribe("set_test_data2", self.set_test_data2)
+
+            EventMesh.subscribe("set_test_data3", self.set_test_data3)
+
+            EventMesh.subscribe("set_test_data4", self.set_test_data4)
+
+            EventMesh.subscribe("set_test_data5", self.set_test_data5)
+
+            EventMesh.subscribe("set_test_data6", self.set_test_data6)
+
+            EventMesh.subscribe("set_test_data7", self.set_test_data7)
+
+            EventMesh.subscribe("set_test_data8", self.set_test_data8)
+        
+
+        def set_test_data1(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state1",msg])
+
+        
+        def set_test_data2(self, event, msg):
+            
+            EventMesh.publish("set_storage_config",["clear_state2",msg])
+
+
+        def set_test_data3(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state3",msg])
+
+        def set_test_data4(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state4",msg])
+
+        def set_test_data5(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state5",msg])
+
+        def set_test_data6(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state6",msg])
+
+        def set_test_data7(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state7",msg])
+
+        def set_test_data8(self, event, msg):
+            EventMesh.publish("set_storage_config",["clear_state8",msg])
+
+        # f = open("/usr/static/storage_file/config.json",'r',encoding="utf-8")
+        # print(f.read())
+
+        def get_old_step_data(self, event, msg):
+            return [self.time_step,self.step_second]
+
+        def get_old_time_data(self, event, msg):
+            return self.time_sec
+        
+        
+
+        def set_old_time_data(self, event, msg):
+            self.time_sec = msg
+            EventMesh.publish("set_storage_config",["old_time",msg])
+
+        def set_old_step_data(self, event, msg):
+            self.time_step = msg[0]
+            self.step_second = msg[1]
+            EventMesh.publish("set_storage_config",["clear_state",msg])
+
+        def get_old_step_data(self, event, msg):
+            return [self.time_step,self.step_second]
+
+
+            
+        
+
+    class getWeatherDataManager(Abstract):
+        # 获取天气数据
+        def __init__(self):
+            self.date = {} #日期23-04-07
+            self.time = {} #14:41:41
+            self.content = {} #天气描述 
+            self.type = None #天气类型
+            self.temp = None #当前温度
+            self.min_temp = None #最低温度
+            self.max_temp = None #最高温度
+            self.city = {} #城市
+            self.no_data = 0#0沒有数据 1有数据
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_weather_data", self.get)
+            EventMesh.subscribe("set_weather_data", self.set)
+
+        def get(self, event, msg):
+            return [self.date,self.time,self.content,self.type,self.temp,self.min_temp,self.max_temp,self.city,self.no_data]
+
+        def set(self, event, msg):
+            self.date = msg[0]
+            self.time = msg[1]
+            self.content = msg[2]
+            self.type = msg[3]
+            self.temp = msg[4]
+            self.min_temp = msg[5]
+            self.max_temp = msg[6]
+            self.city = msg[7]
+            self.no_data = msg[8]
+
+
+    class getHrTimeManager(Abstract):
+        def __init__(self):
+            self.set_time = 0
+            self.set_hr = 0 #0关闭 1手动 2 自动测量按照时间间隔测试心率
+            self.set_spo2 = 0
+            self.open_btn = 0
+            self.set_bgautotime = 0
+            self.bgauto_btn = 0
+            read_data = EventMesh.publish("get_storage_config","measure_time")
+            if read_data != None:
+                self.set_time = read_data  
+            read_data = EventMesh.publish("get_storage_config","open_hr_btn")
+                    
+            if read_data != None:
+                self.open_btn = read_data   
+
+            read_data = EventMesh.publish("get_storage_config","bgauto_time")
+            if read_data != None:
+                self.set_bgautotime = read_data  
+            read_data = EventMesh.publish("get_storage_config","bgauto_btn")
+                    
+            if read_data != None:
+                self.bgauto_btn = read_data   
+
+
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_time_hr", self.set_time_hr)
+            EventMesh.subscribe("get_time_hr", self.get_time_hr)
+            EventMesh.subscribe("set_hr_state", self.set_hr_state)
+            EventMesh.subscribe("get_hr_state", self.get_hr_state)
+            EventMesh.subscribe("set_spo2_state", self.set_spo2_state)
+            EventMesh.subscribe("get_spo2_state", self.get_spo2_state)
+
+            EventMesh.subscribe("set_bgauto_time", self.set_bgauto_time)
+            EventMesh.subscribe("get_bgauto_time", self.get_bgauto_time)
+
+        def set_bgauto_time(self, event, msg): 
+            self.bgauto_btn = msg[0]
+            self.set_bgautotime = msg[1]
+            EventMesh.publish("set_storage_config",["bgauto_btn",self.bgauto_btn])
+            EventMesh.publish("set_storage_config",["bgauto_time",self.set_bgautotime])
+
+        def get_bgauto_time(self, event, msg): 
+            if self.bgauto_btn == None:
+                self.bgauto_btn = 0
+            if self.set_bgautotime == None:
+                self.set_bgautotime = 0
+            return [self.bgauto_btn,self.set_bgautotime]
+        
+
+        def set_time_hr(self, event, msg): 
+            self.open_btn = msg[0]
+            self.set_time = msg[1]
+            EventMesh.publish("set_storage_config",["measure_time",self.set_time])
+            EventMesh.publish("set_storage_config",["open_hr_btn",self.open_btn])
+
+        def get_time_hr(self, event, msg): 
+            return [self.open_btn,self.set_time]
+
+        def set_hr_state(self, event, msg): 
+            # if msg != 0:
+            #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
+            self.set_hr = msg
+            if self.set_hr == 0:
+                EventMesh.publish("clear_health_state")
+            
+
+        def get_hr_state(self, event, msg): 
+            return self.set_hr
+        
+        def set_spo2_state(self, event, msg): 
+            # if msg != 0:
+            #     EventMesh.publish("set_hr_blood_led",1)##红绿灯交替闪烁
+            self.set_spo2 = msg
+            if self.set_spo2 == 0:
+                EventMesh.publish("clear_health_state")
+            
+
+        def get_spo2_state(self, event, msg): 
+            return self.set_spo2
+        
+    #体温
+    class getTempTimeManager(Abstract):
+        def __init__(self):
+            self.set_time = 0
+            self.get_temp = 0
+            read_data = EventMesh.publish("get_storage_config","temp_time")
+
+            if read_data != None:
+                self.set_time = read_data
+
+            self.get_bgstate = 0
+            self.get_bpstate = 0
+
+            self.bptime_on = 0
+            self.bptime_time = 0
+            read_data=EventMesh.publish("get_storage_config","bpauto_btn")
+            if read_data != None:
+                self.bptime_on = read_data
+
+            EventMesh.publish("get_storage_config","bpauto_time")
+            if read_data != None:
+                self.bptime_time = read_data
+
+            self.spo2time_on = 0
+            self.spo2time_time = 0
+            read_data = EventMesh.publish("get_storage_config","spo2auto_btn")
+            if read_data != None:
+                self.spo2time_on = read_data
+
+            read_data = EventMesh.publish("get_storage_config","spo2auto_time")
+            if read_data != None:
+                self.spo2time_time = read_data
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_temp_time", self.set_temp_time)
+            EventMesh.subscribe("get_temp_time", self.get_temp_time)
+
+            EventMesh.subscribe("set_temp_state", self.set_temp_state)
+            EventMesh.subscribe("get_temp_state", self.get_temp_state)
+
+            EventMesh.subscribe("set_bp_time", self.set_bp_time)
+            EventMesh.subscribe("get_bp_time", self.get_bp_time)
+
+            EventMesh.subscribe("set_bp_state", self.set_bp_state)
+            EventMesh.subscribe("get_bp_state", self.get_bp_state)
+
+
+            EventMesh.subscribe("set_bg_state", self.set_bg_state)
+            EventMesh.subscribe("get_bg_state", self.get_bg_state)
+
+            EventMesh.subscribe("set_spo2_time", self.set_spo2_time)
+            EventMesh.subscribe("get_spo2_time", self.get_spo2_time)
+
+            
+        def set_bg_state(self, event, msg): 
+            self.get_bgstate = msg
+            if self.get_bgstate == 0:
+                EventMesh.publish("clear_health_state")
+            # if msg != 0:
+            #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
+
+        def get_bg_state(self, event, msg): 
+            if self.get_bgstate:
+                return self.get_bgstate
+            else :
+                return 0
+
+        def set_spo2_time(self, event, msg): 
+            self.spo2time_on = msg[0]
+            self.spo2time_time = msg[1]
+            EventMesh.publish("set_storage_config",["spo2auto_btn",self.spo2time_on])
+            EventMesh.publish("set_storage_config",["spo2auto_time",self.spo2time_time])
+
+
+        def get_spo2_time(self, event, msg): 
+            
+            return [self.spo2time_on,self.spo2time_time]
+
+
+        def set_bp_time(self, event, msg): 
+            self.bptime_on = msg[0]
+            self.bptime_time = msg[1]
+            EventMesh.publish("set_storage_config",["bpauto_btn",self.bptime_on])
+            EventMesh.publish("set_storage_config",["bpauto_time",self.bptime_time])
+
+        def get_bp_time(self, event, msg): 
+            if self.bptime_on == None:
+                self.bptime_on = 0
+            if self.bptime_time == None:
+                self.bptime_time = 0
+            return [self.bptime_on,self.bptime_time]
+        
+            
+        def set_bp_state(self, event, msg): 
+            self.get_bpstate = msg
+            if self.get_bpstate == 0:
+                EventMesh.publish("clear_health_state")
+            # if msg != 0:
+                # EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
+
+        def get_bp_state(self, event, msg): 
+            if self.get_bpstate:
+                return self.get_bpstate
+            else :
+                return 0
+
+
+        def set_temp_time(self, event, msg): 
+            self.set_time = msg
+            EventMesh.publish("set_storage_config",["temp_time",self.set_time])
+
+        def get_temp_time(self, event, msg): 
+            return self.set_time
+        
+        def set_temp_state(self, event, msg): 
+            self.get_temp = msg
+            if self.get_temp == 0:
+                EventMesh.publish("clear_temp_state")
+            # if msg != 0:
+            #     EventMesh.publish("set_hr_blood_led",1)#红绿灯交替闪烁
+
+        def get_temp_state(self, event, msg): 
+            return self.get_temp
+            
+    class getBrightnessManager(Abstract):#获取亮度级别
+        def __init__(self):
+            self.level = 6#默认值6
+            # self.read_data = {}
+            self.time = 5
+            self.PWM_backlight  = None
+
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("get_brightness_level", self.get_brightness_level)
+            EventMesh.subscribe("push_add_brightness_level", self.add)
+            EventMesh.subscribe("push_reduce_brightness_level", self.reduce)
+            EventMesh.subscribe("set_brightness_level", self.set_brightness_level)
+
+            EventMesh.subscribe("set_brightness_time", self.set_brightness_time)
+            EventMesh.subscribe("get_brightness_time", self.get_brightness_time)
+
+        def set_brightness_level(self, event, msg): 
+            self.level = msg
+            EventMesh.publish("set_storage_config", ["brightness_level",self.level])
+
+        def get_brightness_level(self, event, msg): 
+            tmp = EventMesh.publish("get_storage_config","brightness_level")
+            if tmp != None:
+                self.level = tmp
+            return self.level
+        
+        def set_brightness_time(self, event, msg): 
+            self.time = msg
+            EventMesh.publish("set_storage_config", ["brightness_time",self.time])
+        
+        def get_brightness_time(self, event, msg): 
+            tmp = EventMesh.publish("get_storage_config","brightness_time")
+            if tmp != None:
+                self.time = tmp
+            return self.time
+        
+
+
+        def add(self, event, msg):
+            if self.level < 10:
+                self.level = self.level + 2
+            # self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, self.level, 10)
+            # self.PWM_backlight.open()
+            EventMesh.publish("set_storage_config", ["brightness_level",self.level])
+
+
+        def reduce(self, event, msg):
+            # if self.level > 0:
+            #     self.level = self.level - 2
+            # if self.level <= 0:
+            #     self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, 1, 10)
+            # else:
+            #     self.PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS,self.level, 10)
+
+            # self.PWM_backlight.open()
+            EventMesh.publish("set_storage_config", ["brightness_level",self.level])
+        
+        
+    class getStorageDataManager(Abstract):#获取内存数据
+        def __init__(self):
+            self.config_data = {}
+            check = ql_fs.path_exists("/usr/static/storage_file/config.json")
+            if check == True:
+                with open("/usr/static/storage_file/config.json","r") as fd:
+                    self.config_data = ujson.load(fd)
+            else :
+                self.config_data = {'old_time': 0, 'flip_sw': 0}
+                pass
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_storage_data", self.set_storage_data)
+            EventMesh.subscribe("set_storage_config", self.set_storage_config)
+            EventMesh.subscribe("get_storage_data", self.get_storage_data)
+            EventMesh.subscribe("get_storage_config", self.get_storage_config)
+
+        def set_storage_data(self, event, msg): 
+            # EventMesh.debug_log("set_storage_data:{}".format(msg))
+            if msg != None:
+                self.config_data = msg
+                with open("/usr/static/storage_file/config.json",'w+',encoding="utf-8") as fd:
+                    ujson.dump(self.config_data,fd)
+        
+
+        def set_storage_config(self,event,msg): 
+            # EventMesh.debug_log("set_storage_key_data1:{}".format(msg))
+            if len(msg) >= 2:
+                self.config_data[msg[0]]=msg[1]
+                # EventMesh.debug_log("set_storage_key_data2:{}".format(self.config_data[msg[0]]))
+                EventMesh.publish("publish_message_event_ui",{"func":self.set_storage_save,"data":0})
+        def set_storage_save(self, data): 
+            with open("/usr/static/storage_file/config.json",'w+',encoding="utf-8") as fd:
+                ujson.dump(self.config_data,fd)
+        def get_storage_data(self, event, msg): 
+            # EventMesh.debug_log("get_storage_data:{}".format(self.config_data))
+            return self.config_data 
+        def get_storage_config(self,event,msg):
+            # EventMesh.debug_log("get_storage_key_data1:{}".format(msg))
+            b = msg in self.config_data.keys()
+            if b == True:
+                # EventMesh.debug_log("get_storage_key_data2:{}".format(self.config_data[msg]))
+                return self.config_data[msg]
+            else :
+                return None
+            # try:
+            #     return self.config_data[msg]
+            # except:
+            #     EventMesh.debug_log("get_storage_key_data:none key:{}",msg)
+            #     return None
+    #定位频率
+    class getUpLoadDataManager(Abstract):#
+        def __init__(self):
+            self.upload_time = 2*60*60
+            read_data = EventMesh.publish("get_storage_config","upload_time")
+            if read_data != None:
+                self.upload_time = read_data 
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_upload_data", self.set_upload_data)
+            EventMesh.subscribe("get_upload_data", self.get_upload_data)
+
+        def set_upload_data(self, event, msg): 
+            self.upload_time = msg
+
+        def get_upload_data(self, event, msg): 
+            if self.upload_time == None:
+                self.upload_time = 2*60*60
+            return self.upload_time 
+
+    class getplayAudiodStateManager(Abstract):#获取设置播放音频状态
+        def __init__(self):
+            self.play = 0
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_audio_state", self.set_audio_state)
+            EventMesh.subscribe("get_audio_state", self.get_audio_state)
+
+        def set_audio_state(self, event, msg): 
+            self.play = msg
+
+        def get_audio_state(self, event, msg): 
+            return self.play
+        
+    class getVolumSizeManager(Abstract):#设置或获取音量大小数据
+        def __init__(self):
+            self.volume_size = 8
+            read_data = EventMesh.publish("get_storage_config","volum")
+            if read_data != None:
+                self.volume_size = read_data
+        
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_volum_size", self.set_volum_size)
+            EventMesh.subscribe("get_volum_size", self.get_volum_size)
+
+        def set_volum_size(self, event, msg): 
+            self.volume_size = msg
+            EventMesh.publish("set_storage_config", ["volum",self.volume_size])
+
+        def get_volum_size(self, event, msg): 
+            return self.volume_size
+
+    class getSosFlagManager(Abstract):#设置sos
+        def __init__(self):
+            self.aud = audio.Audio(0)
+            self.sos_flag = 0
+            self.sos_num = 0
+            self.hangup_mode = 0
+            self.call_timer = osTimer()
+            self.sos_numer1 = []
+            self.callnumer =""
+            SOS_NUMBER1 = EventMesh.publish("get_storage_config","SOS_NUMBER1")
+            if SOS_NUMBER1 != None:
+                self.sos_numer1 = SOS_NUMBER1
+            SOS_NUMBER2 = EventMesh.publish("get_storage_config","SOS_NUMBER2")
+            if SOS_NUMBER1 != None:        
+                self.sos_numer1 = [SOS_NUMBER1, SOS_NUMBER2]
+
+            SOS_NUMBER3 = EventMesh.publish("get_storage_config","SOS_NUMBER3")
+            if SOS_NUMBER3 != None:        
+                self.sos_numer1 = [SOS_NUMBER1, SOS_NUMBER2,SOS_NUMBER3]
+
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_sos_flag", self.set_sos_flag)#设置sos拨打标识
+            EventMesh.subscribe("get_sos_flag", self.get_sos_flag)
+
+            EventMesh.subscribe("set_sos_num", self.set_sos_num)#设置拨打循环次数
+            EventMesh.subscribe("get_sos_num", self.get_sos_num)
+
+            EventMesh.subscribe("set_dial_sos_number", self.set_dial_sos_number)
+            EventMesh.subscribe("get_dial_sos_number", self.get_dial_sos_number)#设置家庭号码三个
+
+            EventMesh.subscribe("set_callnumer_cb", self.set_callnumer_cb)#延时回调
+
+            EventMesh.subscribe("close_call_time",self.close_call_time)
+
+            EventMesh.subscribe("set_hangup_mode", self.set_hangup_mode)
+            EventMesh.subscribe("get_hangup_mode", self.get_hangup_mode)#获取挂断方式 是对方挂断 还是手表按键主动挂断
+
+        def get_hangup_mode(self, event, msg): # 1是设备端手表主动挂断 0是手机端
+            return self.hangup_mode
+        
+        def set_hangup_mode(self, event, msg): 
+            self.hangup_mode = msg
+
+        def set_sos_flag(self, event, msg): 
+            self.sos_flag = msg
+        
+            if self.sos_flag == 1:
+                number = EventMesh.publish("get_dial_sos_number")
+            
+                if number != None:
+                    if len(number) > 0:
+                        self.call_timer.stop()
+                        EventMesh.publish("save_phonename",number[0])
+                        EventMesh.publish("save_phonenum",number[0])
+                        EventMesh.publish("set_sos_num",0)
+                        phone_num = EventMesh.publish("get_phonenum")  
+                        EventMesh.publish("sos_out_call_center_cb",phone_num)#电话拨出去
+                    else:
+                        EventMesh.publish("sos_out_call_center_cb",None)#电话拨出去
+
+        def set_callnumer_cb(self, event, msg):
+            if self.sos_flag == 1:
+                self.callnumer = msg
+                self.call_timer.start(5000, 0, self.call_timer_cb)#延迟10S 继续拨打
+
+        def call_timer_cb(self, *args, **kwargs):
+            if self.sos_flag == 1:
+                EventMesh.publish("save_phonename",str(self.callnumer))
+                EventMesh.publish("save_phonenum",str(self.callnumer))
+                phone_num = EventMesh.publish("get_phonenum")  
+                EventMesh.publish("sos_out_call_center_cb",phone_num)#电话拨出去
+        
+        def close_call_time(self, event, msg): 
+            self.call_timer.stop()
+
+        def get_sos_flag(self, event, msg): 
+            return self.sos_flag
+        
+        def set_sos_num(self, event, msg): 
+            self.sos_num = msg
+
+        def get_sos_num(self, event, msg): 
+            return self.sos_num
+        
+        def set_dial_sos_number(self, event, msg): 
+            self.sos_numer1 = msg
+            
+
+        def get_dial_sos_number(self, event, msg): 
+            return self.sos_numer1
+    class getLowBatManager(Abstract):#低电提醒
+        def __init__(self):
+
+            self.low_btn = 0
+            read_data = EventMesh.publish("get_storage_config","low_on")
+            if read_data != None:
+                self.low_btn = read_data
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_low_bat_btn", self.set_low_bat_btn)#
+            EventMesh.subscribe("get_low_bat_btn", self.get_low_bat_btn)
+
+        def set_low_bat_btn(self, event, msg): 
+            self.low_btn = msg
+            EventMesh.publish("set_storage_config",["low_on",self.low_btn])
+
+        def get_low_bat_btn(self, event, msg): 
+            return self.low_btn
+        
+
+
+    class playPowerAudioManager(Abstract):#播放开关机音频文件
+        def __init__(self):
+            self.aud = audio.Audio(0)
+
+        def post_processor_after_instantiation(self):
+            
+            EventMesh.subscribe("play_poewr_on_event", self.play_poewr_on_event)#
+            EventMesh.subscribe("play_poewr_off_event", self.play_poewr_off_event)
+
+        def play_poewr_on_event(self, event, msg): 
+            self.aud.play(1, 1, 'U:/static/R_POWER_1.mp3')  #播放播放开机铃声
+
+        def play_poewr_off_event(self, event, msg): 
+            self.aud.setVolume(11)
+            self.aud.play(1, 1, 'U:/static/R_POWER_OFF_1.mp3')  #播放关机铃声
+        
+    class getBootOffManager(Abstract):#开关机时间
+        def __init__(self):
+            self.poweroff_time = []
+            read_data = EventMesh.publish("get_storage_config","poweroff_alarm")
+            if read_data != None:
+                self.poweroff_time = read_data
+            else:
+                self.poweroff_time = [{"poweroff_on":0,"start_hour":6,"start_min":0,"end_hour":0,"end_min":0}]
+            
+
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_boot_off_time", self.set_boot_off_time)#设置关机时间
+            EventMesh.subscribe("get_boot_off_time", self.get_boot_off_time)
+
+        def set_boot_off_time(self, event, msg): 
+            EventMesh.debug_log("set_boot_off_time",msg)
+
+            EventMesh.publish("set_storage_config",["poweroff_alarm",msg])
+            self.poweroff_time = msg
+            EventMesh.publish("set_rtc_alarm")
+
+
+        def get_boot_off_time(self, event, msg):
+            return self.poweroff_time
+    class setSmsIndexManager(Abstract):#
+        def __init__(self):
+            self.index = -1
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_sms_index", self.set_sms_index)#设置关机时间
+            EventMesh.subscribe("get_sms_index", self.get_sms_index)
+
+        def set_sms_index(self, event, msg): 
+            self.index = msg
+            
+
+        def get_sms_index(self, event, msg):
+            
+            return self.index
+    import protocol 
+    class testSmsSetIPManager(Abstract):#
+        def __init__(self):
+            self.timer = osTimer()
+            #大锤
+            severdata = protocol.server_init()
+
+            self.newip = severdata[0]
+            self.newcom = severdata[1]
+            self.new_key = severdata[2]
+            self.new_pid = severdata[3]
+            
+            EventMesh.debug_log("testSmsSetIPManager:{}\n".format(severdata))
+
+            self.server_sate = 0
+
+
+
+            tmp_data = EventMesh.publish("get_storage_config","set_new_ip_addr")
+            if tmp_data != None:
+                self.newip = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","set_new_com")
+            if tmp_data != None:
+                self.newcom = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","set_new_md5")
+            if tmp_data != None:
+                self.newmd5 = tmp_data    
+
+            tmp_data = EventMesh.publish("get_storage_config","set_new_key")
+            if tmp_data != None:
+                self.new_key = tmp_data 
+
+            tmp_data = EventMesh.publish("get_storage_config","set_new_pid")
+            if tmp_data != None:
+                self.new_pid = tmp_data 
+
+            tmp_data = EventMesh.publish("get_storage_config","get_server_sate")
+            if tmp_data != None:
+                self.server_sate = tmp_data 
+            
+            
+
+
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_new_ip_com", self.set_new_ip_com)#设置关机时间
+            EventMesh.subscribe("get_new_ip_com", self.get_new_ip_com)
+
+            EventMesh.subscribe("set_ip", self.set_ip)#设置关机时间
+            EventMesh.subscribe("get_ip", self.get_ip)
+
+            EventMesh.subscribe("set_com", self.set_com)#设置关机时间
+            EventMesh.subscribe("get_com", self.get_com)
+
+            EventMesh.subscribe("get_new_key", self.get_new_key_cb)#获取key
+            EventMesh.subscribe("set_new_key", self.set_new_key_cb)#获取key
+
+            EventMesh.subscribe("set_new_pid", self.set_new_pid_cb)#获取pid
+            EventMesh.subscribe("get_new_pid", self.get_new_pid_cb)#获取pid
+
+            EventMesh.subscribe("set_server_state", self.set_server_state)#
+            EventMesh.subscribe("get_server_state", self.get_server_state)#
+
+            EventMesh.subscribe("get_new_key_pid", self.get_new_key_pid)#
+
+
+
+        def set_new_key_cb(self, event, msg): 
+            self.new_key = msg
+            # print("set_new_key_cb",msg,self.new_key)
+            EventMesh.publish("set_storage_config",["set_new_key",self.new_key])
+
+        def get_new_key_cb(self, event, msg):
+            # print("get_new_key_cb",self.new_key)
+            return self.new_key
+        
+        def set_new_pid_cb(self, event, msg): 
+            self.new_pid = msg
+            # print("set_new_pid_cb",msg,self.new_pid)
+            EventMesh.publish("set_storage_config",["set_new_pid",self.new_pid])
+
+        def get_new_pid_cb(self, event, msg):
+            # print("get_new_pid_cb",self.new_pid)
+            return self.new_pid
+
+        def set_new_ip_com(self, event, msg): 
+            self.newip = str(msg[0])
+            self.newcom = int(msg[1])
+            # self.newmd5 = str(msg[2])
+            #短信格式:SETIP:api.xcloudtech.com:9000:bZld0ALsZTt15tKEZhOlLPgbsO75BLTP 以冒号分隔 SETIP:ip地址:ip端口号:ip密钥key
+
+            # self.read_data["set_new_md5"] = self.newmd5  #通过短信设置ip的key密钥
+        
+
+            EventMesh.publish("set_storage_config",["set_new_ip_addr",self.newip])
+            EventMesh.publish("set_storage_config",["set_new_com",self.newcom])
+
+
+            number = str(msg[2])
+            sms.sendPduMsg(number, 'set ok', 'UCS2')
+            self.timer.start(10*1000,0,self.fun)
+            
+        def fun(self,*argc):
+            Power.powerRestart()
+
+        def get_new_ip_com(self, event, msg):
+            tmp_addr = EventMesh.publish("get_storage_config","set_new_ip_addr")
+            tmp_com = EventMesh.publish("get_storage_config","set_new_com")
+            if tmp_addr != None:
+                self.newip = tmp_addr
+            if tmp_com != None:
+                self.newcom = tmp_com
+            return [self.newip,self.newcom]
+        
+        def set_ip(self, event, msg): 
+            self.newip = msg
+            EventMesh.publish("set_storage_config",["set_new_ip_addr",self.newip])
+
+        def get_ip(self, event, msg):
+            # print("get_ip",self.newip)
+            return self.newip
+        
+        def set_com(self, event, msg): 
+            self.newcom = msg
+            EventMesh.publish("set_storage_config",["set_new_com",self.newcom])
+
+        def get_com(self, event, msg):
+            # print("get_com",self.newcom)
+            return self.newcom
+
+        def get_new_key_pid(self, event, msg):
+            return [self.new_key,self.new_pid]
+        
+        def set_server_state(self, event, msg):
+            EventMesh.publish("set_storage_config",["get_server_sate",msg])
+            self.server_sate = msg
+
+        def get_server_state(self, event, msg):
+            return self.server_sate
+            
+
+    # MMI Version:UIX8910_C55_DS_D12G_PRO18_FZD_V1.0_Release
+    # Build:07-07-2022 16:12:58
+    # IMEI:861218001025267
+    # IP:api.xcloudtech.com
+    # PORT:9000
+    # UPLOAD:300
+    # Battery:3948, 64
+    # Udebug: 0
+    # ConnectTime: 7
+    import protocol
+
+    class sendDevinfoManager(Abstract):#发送设备信息
+        def __init__(self):
+            self.timer = osTimer()
+            pass
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("send_devinfo_event", self.send_devinfo_event)#删除短信
+
+        def send_devinfo_event(self, event, msg): 
+            number = str(msg)
+            versions = EventMesh.softversion
+            Build = EventMesh.builTime
+            IMEI = EventMesh.publish(constants.EVENT.GET_IMEI)
+            IP = ""
+            new_ip = EventMesh.publish("get_storage_config","set_new_ip_addr")
+            new_com = EventMesh.publish("get_storage_config","set_new_com")
+            server_data = protocol.server_init()
+        
+            if new_ip != None:
+                if len(new_ip) != 0:
+                    IP = new_ip
+                else:
+                    IP = server_data[0]
+            else:
+                IP = server_data[0]
+            
+            PORT = ''
+            if new_com != None:
+                if len(new_com) != 0:
+                    PORT = new_com
+                else:
+                    PORT = server_data[1]
+            else:
+                PORT = server_data[1]
+            
+            UPLOAD = EventMesh.publish("get_upload_data")
+
+            level = EventMesh.publish("get_curr_battery_level")
+            if level == None:
+                level = 4200
+            bat = EventMesh.publish("screen_get_battery")[1]
+            if bat == None:
+                bat = 100
+            Battery = str(level) +',' +  str(bat)
+
+            ConnectTime = heartbeat_time//60
+            data1 = "Version:{}\nBuild:{}".format(versions,Build)
+
+            data2 = "IMEI:{}\nIP:{}\nPORT:{}".format(IMEI,IP,PORT)
+            
+            data3 = "UPLOAD:{}\nBattery:{}\nConnectTime:{}".format(UPLOAD,Battery,ConnectTime)
+
+            send_state1 = -1
+            send_state2 = -1
+            # print("data",data1,data2,data3)
+            send_state1 = sms.sendPduMsg(number, data1, 'UCS2')
+
+            if send_state1 == 0:
+                send_state2 = sms.sendPduMsg(number, data2, 'UCS2')
+
+            if send_state2 == 0:
+                sms.sendPduMsg(number, data3, 'UCS2')
+            
+
+    class deleteSmsManager(Abstract):#删除信息
+        def __init__(self):
+            self.timer = osTimer()
+            pass
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("delete_sms_event", self.delete_sms_event)#删除短信
+            EventMesh.subscribe("remove_all_sms_cb", self.remove_all_sms_cb)#
+
+        def delete_sms_event(self, event, msg): 
+            self.timer.start(4*1000,0,self.fun)
+            
+        def fun(self, *argc): 
+            EventMesh.publish_async("remove_all_sms_cb","",1*1024)
+
+        def remove_all_sms_cb(self, event, msg):
+            sms.deleteMsg(1,4)
+
+    #闹钟信息
+    alarm_list = [{'hour': 6, 'repeart': 10, 'idx': 0, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0},
+                {'hour': 0, 'repeart': 10, 'idx': 1, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0}]
+    #用于显示闹钟列表不包含开关机信息
+
+    class ClockManager(Abstract):
+        def __init__(self):
+            super().__init__()
+            self.rtc = RTC()
+            self.days = 0
+            self.idx = 0
+
+            IFEXIST = ql_fs.path_exists("/usr/static/storage_file/alarm_msg.json") 
+            self.check_alarm_list = []     
+            if IFEXIST == True:
+                with open("/usr/static/storage_file/alarm_msg.json","r",encoding='utf-8') as fd:
+                    self.check_alarm_list = ujson.load(fd)
+            
+            EventMesh.subscribe("push_clock_info", self.set)
+            EventMesh.subscribe("read_alarminjson", self.read_alarminjson)
+            EventMesh.subscribe("add_alarm", self.add_alarm)
+            EventMesh.subscribe("remove_alarm", self.remove_alarm)
+            EventMesh.subscribe("set_rtc_alarm", self.set_rtc_alarm)
+            EventMesh.subscribe("get_alarm_indx", self.get_alarm_indx)
+            EventMesh.subscribe("get_check_alarm_list", self.get_check_alarm_list)
+            EventMesh.subscribe("push_update_alarm_show", self.update_show_info)
+
+        def post_processor_after_instantiation(self):
+        
+            EventMesh.publish("read_alarminjson")
+            # EventMesh.publish("set_rtc_alarm")
+        
+        def update_show_info(self,event,msg):
+            EventMesh.publish("read_alarminjson")
+            # EventMesh.publish("set_rtc_alarm")
+
+        def get_check_alarm_list(self, event, msg):
+            alarm_len = 0
+            global alarm_list
+            EventMesh.publish("read_alarminjson")
+            alarm_len = len(alarm_list)
+            return alarm_len
+
+
+        def set(self, event, msg):
+            global alarm_list
+            EventMesh.debug_log("msg = {}".format(msg))
+            idx = msg.get("idx")
+            EventMesh.debug_log("修改第{}个闹钟信息{}".format(idx,alarm_list[idx]))
+            alarm_list[idx]["hour"] = msg["hour"]
+            alarm_list[idx]["minute"] = msg["minute"]
+            alarm_list[idx]["days"] = msg["days"]
+            alarm_list[idx]["enabled"] = msg["enabled"]
+            alarm_list[idx]["repeart"] = msg["repeart"]
+            with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
+                ujson.dump(alarm_list,fd)
+
+        def read_alarminjson(self, event, msg):
+            IFEXIST = ql_fs.path_exists("/usr/static/storage_file/alarm_msg.json") 
+            global alarm_list     
+            EventMesh.debug_log("IFEXIST:{}".format(IFEXIST))
+            if IFEXIST == True:
+                with open("/usr/static/storage_file/alarm_msg.json","r",encoding='utf-8') as fd:
+                    alarm_list = ujson.load(fd)
+
+            
+            # read_data = EventMesh.publish("get_storage_config","off_on")
+
+            hour1 = str(alarm_list[0]["hour"])+':'+str(alarm_list[0]["minute"])
+            # min1 = str(alarm_list[0]["minute"])
+
+            hour2 = str(alarm_list[1]["hour"])+':'+str(alarm_list[1]["minute"])
+            # min2 = str(alarm_list[1]["minute"]) 
+            # EventMesh.publish("set_boot_off_time",[1,hour1,hour2])
+
+            EventMesh.debug_log("hour1:{}-{}".format(hour1,hour2))
+
+            
+            return alarm_list
+
+        def add_alarm(self, event, msg):
+
+            global alarm_list
+            EventMesh.publish("read_alarminjson")
+            EventMesh.debug_log("msg:{}".format(msg))
+            for i in range(0,2):#开关机固定是 idx 0 1
+                off_msg1 = msg[i+1]
+                msg_tmp1 = off_msg1.split(':')
+                start_hour = int(msg_tmp1[0])
+                start_min = int(msg_tmp1[1])
+                enable = int(msg[0])
+                EventMesh.debug_log("start_hour:{} start_min:{} enable:{}",start_hour,start_min,enable)
+                # EventMesh.publish("set_boot_off_time",[msg[0],msg[1],msg[2]])
+
+                alarm_list[i]["idx"]=i
+                alarm_list[i]["hour"]=start_hour
+                alarm_list[i]["minute"]=start_min
+                alarm_list[i]["days"]=[0,1,2,3,4,5,6]
+                alarm_list[i]["enabled"]=enable
+                alarm_list[i]["repeart"]=10
+
+
+                # alarm_list.append({"idx": i, "hour": start_hour, "minute": start_min, "days":[0,1,2,3,4,5,6], "enabled": enable,"repeart":10})
+
+            
+            # EventMesh.debug_log("alarm_list----len- :{} alarm_list:{}".format(len(alarm_list),alarm_list))
+            with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
+                ujson.dump(alarm_list,fd)
+            EventMesh.publish("push_update_alarm_show")
+            
+        
+                
+            
+
+
+        def remove_alarm(self, event, msg):
+            global alarm_list
+            EventMesh.debug_log("ddddddddddddddddddd:",msg)
+            idx = msg.get("idx")
+            EventMesh.debug_log("delete_here1-----{},{}:".format(idx,msg))
+
+            for i, alarm in enumerate(alarm_list):
+                EventMesh.debug_log("delete_here2-----{},{}:".format(i,alarm))
+
+                if alarm["idx"] == idx:
+                    del alarm_list[i]
+                    EventMesh.debug_log("delete_here3-----",alarm_list)
+
+                    #删除闹钟后,对idx重新排序
+                    if alarm_list:
+                        for j in range(i,len(alarm_list)):
+                            alarm_list[j]["idx"] -= 1
+                            EventMesh.debug_log("delete_here4-----",alarm_list)
+
+            with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
+                ujson.dump(alarm_list,fd)
+
+
+        def get_alarm_indx(self,event,msg):
+            return self.idx
+
+        def _rtc_callback(self,args):
+            #设置下一个闹钟,定时开关机功能
+            msg_data = EventMesh.publish("get_boot_off_time")
+            if msg_data != None:
+                power_offdata = msg_data[0]
+                start_hour = int(power_offdata["start_hour"])
+                start_min = int(power_offdata["start_min"])
+                end_hour = int(power_offdata["end_hour"])
+                end_min = int(power_offdata["end_min"])
+                off_on = int(power_offdata["poweroff_on"])
+
+                rtc_now_time = self.rtc.datetime()
+                current_minute = rtc_now_time[4]*60 + rtc_now_time[5]
+                end_min_total = end_hour*60+end_min
+                next_minute = start_hour*60+start_min #10:11
+                EventMesh.debug_log("off_on:{} {} {}".format(off_on,current_minute,next_minute))
+                if off_on != None:
+                    if off_on == 1:
+                        if end_min_total == current_minute:#结束的时间分钟等于关机时间分钟数则关机
+                            ubs_state = EventMesh.publish("get_usb")#'
+                            
+                            if ubs_state == 2 or ubs_state == 0:
+
+                                if next_minute > current_minute:#开机时间大于当前时间 9:00 > = 8:00 
+                                    interval_minute = next_minute - current_minute
+                                    
+                                    EventMesh.debug_log("开机距离下一次响铃的的分钟数:", interval_minute,next_minute)
+                                else:#8:00 9:00
+                                    #7*60*24 7天一个周期 7*60*24 - 
+                                    interval_minute = next_minute + (24*60-current_minute)
+                                    EventMesh.debug_log("开机08888距离下一次响铃的的分钟数:", interval_minute,next_minute)
+
+                                #反向获取时间戳
+                                time = utime.localtime()
+                                EventMesh.debug_log("开机9获取utime的时间戳:", time)
+                                rtc_mktime = utime.mktime(time)-time[5]
+                                EventMesh.debug_log("开机10反向获取utime的mktime:", rtc_mktime)
+
+                                #加上下一次响铃需要的时间
+                                next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳
+                                EventMesh.debug_log("开机11下一次响铃的mktime:", next_alarm_mktime)
+
+                                #格式化时间戳,得到下一次闹钟的时间
+                                next_alarm_time = utime.localtime(next_alarm_mktime)
+                                EventMesh.debug_log("开机12下一次响铃的准确时间:", next_alarm_time)
+                                #将时间转换为rtc的格式
+                                data_l = [2021, 7, 9, 5, 12, 30, 0, 0]
+                                #给rtc时间赋值
+                                data_l[0] = next_alarm_time[0] #year
+                                data_l[1] = next_alarm_time[1] #month                    
+                                data_l[2] = next_alarm_time[2] #day                     
+                                data_l[4] = next_alarm_time[3] #hour               
+                                data_l[5] = next_alarm_time[4] #minute   
+                                data_e=tuple(data_l)
+                                EventMesh.debug_log("开机13将该时间转换为RTC元组:", data_e)
+                                
+                                self.rtc.register_callback(self._rtc_callback)
+
+                                FLAG = self.rtc.set_alarm(data_e)
+                                if FLAG == 0:
+                                    EventMesh.debug_log("开机11成功设置rtc的到期时间:", data_e)
+                                else:
+                                    EventMesh.debug_log("开机时设置rtc的到期时间失败:", data_e)
+                                self.rtc.enable_alarm(1)
+                                
+                                EventMesh.debug_log("结束时设置rtc的到期时间失败:", data_e)
+                                EventMesh.publish("open_power_on", 5)#静音关机
+                                return
+                            else:
+                                EventMesh.publish("set_rtc_alarm")
+                                #self.rtc.datetime([2023, 12, 1, 5, 5, 59, 30, 0])
+                                return
+                
+            EventMesh.publish("set_rtc_alarm")
+
+
+        def set_rtc_alarm(self,event,msg):
+            msg_data = EventMesh.publish("get_boot_off_time")
+            if msg_data != None:
+                power_offdata = msg_data[0]
+                start_hour = int(power_offdata["start_hour"])
+                start_min = int(power_offdata["start_min"])
+                end_hour = int(power_offdata["end_hour"])
+                end_min = int(power_offdata["end_min"])
+                off_on = int(power_offdata["poweroff_on"])
+                if off_on == 1:
+                    next_minute = start_hour*60+start_min #10:11
+
+                    start_total = start_hour*60+start_min #10:11
+                    end_total = end_hour*60+end_min #10:11
+                    rtc_now_time = self.rtc.datetime()
+                    current_minute = rtc_now_time[4]*60 + rtc_now_time[5]#当前时间
+
+
+                    minute_list = []
+                    if start_total != current_minute:
+                        minute_list.append(start_total)#23*60=
+                    if end_total != current_minute:
+                        minute_list.append(end_total)
+                    minute_list.append(current_minute)#[927,927,930]
+                    minute_list = sorted(minute_list)
+                    current_index = minute_list.index(current_minute)
+                    print("minute_list",minute_list,start_total,end_total,current_index,power_offdata)
+                    
+                    
+                    next_index = current_index + 1
+                    if next_index >= len(minute_list):
+                        next_minute = minute_list[0]
+                        print("07下一个闹钟的分钟数:", next_minute)
+                    else:
+                        next_minute = minute_list[next_index]
+                        print("08下一个闹钟的分钟数:", next_minute)
+
+                    print("minute_list1",minute_list,current_index,next_minute)
+                    if next_minute > current_minute:
+                        interval_minute = next_minute - current_minute
+                        print("09距离下一次响铃的的分钟数:", interval_minute)#14 31 14 29 14 31 24*60-
+                    else:
+                        interval_minute = (24*60 - current_minute) + next_minute
+                        print("10距离下一次响铃的的分钟数:", interval_minute)
+
+
+                    #反向获取时间戳
+                    time = utime.localtime()
+                    EventMesh.debug_log("关机09获取utime的时间戳:", time)
+                    time
+                    rtc_mktime = utime.mktime(time)-time[5]
+                    EventMesh.debug_log("关机10反向获取utime的mktime:", rtc_mktime)
+
+                    #加上下一次响铃需要的时间
+                    next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳
+                    EventMesh.debug_log("关机11下一次响铃的mktime:", next_alarm_mktime)
+
+                    #格式化时间戳,得到下一次闹钟的时间
+                    next_alarm_time = utime.localtime(next_alarm_mktime)
+                    EventMesh.debug_log("关机12下一次响铃的准确时间:", next_alarm_time)
+                    #将时间转换为rtc的格式
+                    data_l = [2021, 7, 9, 5, 12, 30, 0, 0]
+                    #给rtc时间赋值
+                    data_l[0] = next_alarm_time[0] #year
+                    data_l[1] = next_alarm_time[1] #month                    
+                    data_l[2] = next_alarm_time[2] #day                     
+                    data_l[4] = next_alarm_time[3] #hour               
+                    data_l[5] = next_alarm_time[4] #minute   
+                    data_e=tuple(data_l)
+                    EventMesh.debug_log("关机13将该时间转换为RTC元组:", data_e)
+                    
+                    self.rtc.register_callback(self._rtc_callback)
+
+                    FLAG = self.rtc.set_alarm(data_e)
+                    if FLAG == 0:
+                        EventMesh.debug_log("关机11成功设置rtc的到期时间:", data_e)
+                    else:
+                        EventMesh.debug_log("关机时设置rtc的到期时间失败:", data_e)
+                    self.rtc.enable_alarm(1)
+                else:
+                    self.rtc.enable_alarm(0)
+                    
+
+    class schoolclassManager(Abstract):#
+        def __init__(self):
+            # ['火星情报局', '一年级二班', '柠檬茶']
+            self.school_name = ''
+            self.class_name = ''
+            self.full_name = ''
+            tmp_data = EventMesh.publish("get_storage_config","school_name")
+            if tmp_data != None:
+                self.school_name = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","class_name")
+            if tmp_data != None:
+                self.class_name = tmp_data
+            tmp_data = EventMesh.publish("get_storage_config","full_name")
+            if tmp_data != None:
+                self.full_name = tmp_data    
+
+            
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_schoolname", self.set_school_name)#
+            EventMesh.subscribe("get_schoolname", self.get_school_name)
+
+            EventMesh.subscribe("set_classname", self.set_classname)#
+            EventMesh.subscribe("get_classname", self.get_classname)
+
+            EventMesh.subscribe("set_fullname", self.set_full_name)#
+            EventMesh.subscribe("get_fullname", self.get_full_name)
+
+        def set_school_name(self, event, msg): 
+            if msg != None:
+                if len(msg) != 0:
+                    self.school_name = str(msg)
+                    EventMesh.publish("set_storage_config",["school_name",str(msg)])
+            
+
+        def get_school_name(self, event, msg):
+            if self.school_name:
+                return self.school_name
+            else:
+                return None
+        
+        def set_classname(self, event, msg): 
+            if msg != None:
+                if len(msg) != 0:
+                    self.class_name = str(msg)
+                    EventMesh.publish("set_storage_config",["class_name",str(msg)])
+                
+            
+        def get_classname(self, event, msg):
+            if self.class_name:
+                return self.class_name
+            else:
+                return None
+        def set_full_name(self, event, msg): 
+            if msg != None:
+                if len(msg) != 0:
+                    self.full_name = str(msg)
+                    EventMesh.publish("set_storage_config",["full_name",str(msg)])
+
+        def get_full_name(self, event, msg):
+            if self.full_name:
+                return self.full_name
+            else:
+                return None
+            
+    import jrtc     
+    class vedioInforManager(Abstract):#
+        def __init__(self):
+            self.call_id = ""
+            self.meet_id = ""#会议id
+            self.call_type = 0 #会议id
+            self.tokens_data= ""#tokens
+            self.timer = osTimer()
+            self.videobook = {}
+            self.check_json = 0
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/videobook.json")
+
+            if self.check_json == True:
+                with open("/usr/static/storage_file/videobook.json","r",encoding="utf-8") as fd:
+                    self.videobook = ujson.load(fd)
+                    print("读取视频通话账号列表")
+            
+            self.video_state = 0
+            self.video_count = 0
+            self.video_state_time = 0
+
+            self.video_dev_mode = 0
+
+            self.video_led_state = 0
+            self.video_answer = 0
+
+            self.video_timer = 0
+
+            self.videoInfo_queue = Queue()
+            _thread.stack_size(10*1024)
+            _thread.start_new_thread(self.videoInfo_queue_thread, ())
+            _thread.stack_size(8*1024)
+            EventMesh.subscribe("publish_message_event_videoInfo",self.publish_message_event_videoInfo)
+            pass
+
+        def videoInfo_queue_thread(self):
+            while True:
+                data = self.videoInfo_queue.get()
+                #EventMesh.debug_log("ledInfo_queue:data = {}".format(data))
+                if data != None:
+                    try:
+                        data["func"](data["data"])
+                    except Exception as e:
+                        EventMesh.debug_log("ledInfo_queue:ERROR:{}".format(e))
+                        usys.print_exception(e)
+        def publish_message_event_videoInfo(self,event,msg):
+            self.videoInfo_queue.put(msg)
+
+        def publish_led_event_cb(self, *args, **kwargs):
+            EventMesh.publish("publish_message_event_videoInfo",{"func":self.video_time_cb,"data":0})
+
+        def post_processor_after_instantiation(self):
+            EventMesh.subscribe("set_vedio_call_id", self.set_vedio_call_id)#
+            EventMesh.subscribe("set_vedio_meet_id", self.set_vedio_meet_id)#
+            EventMesh.subscribe("set_vedio_call_type", self.set_vedio_call_type)#
+            EventMesh.subscribe("set_vedio_tokens_data", self.set_vedio_tokens_data)#
+
+            EventMesh.subscribe("get_vedio_call_id", self.get_vedio_call_id)#
+            EventMesh.subscribe("get_vedio_meet_id", self.get_vedio_meet_id)#
+            EventMesh.subscribe("get_vedio_call_type", self.get_vedio_call_type)#
+            EventMesh.subscribe("get_vedio_tokens_data", self.get_vedio_tokens_data)#
+
+
+            EventMesh.subscribe("open_vedio_infor",self.open_vedio_infor)
+            EventMesh.subscribe("close_jrtc_event",self.close_jrtc_event)
+
+            EventMesh.subscribe("get_videobook_list", self.get_videobook_list)
+            EventMesh.subscribe("set_videobook_list", self.set_videobook_list)
+
+            EventMesh.subscribe("set_video_state", self.set_video_state)
+            EventMesh.subscribe("get_video_state", self.get_video_state)
+
+            EventMesh.subscribe("set_dev_app_mode", self.set_dev_app_mode)
+            EventMesh.subscribe("get_dev_app_mode", self.get_dev_app_mode)
+
+            EventMesh.subscribe("close_video_timer",self.close_video_timer)
+
+            EventMesh.subscribe("call_viode_book_num",self.call_viode_book_num)
+
+            EventMesh.subscribe("app_rtalk_cb",self.app_rtalk_cb)#app拒绝视频通话
+
+            EventMesh.subscribe("video_answer_cb",self.video_answer_cb)#手表端接听视频通话
+
+            EventMesh.subscribe("video_reject_cb",self.video_reject_cb)#手表端挂断视频通话
+
+            EventMesh.subscribe("video_no_network",self.video_no_network)#打着突然掉网或者未绑定设备 每10s检测一次
+
+            EventMesh.subscribe("video_anwer_led",self.video_anwer_led)
+
+            EventMesh.subscribe("clear_video_timer_state",self.clear_video_timer_state)
+
+            
+
+            EventMesh.subscribe("set_app_dev_end_state",self.set_app_dev_end_state)#设置是app 设备 还是主动信号不好的挂断当前的视频通话
+
+        def set_video_state(self, event, msg):#视频通话 1是刚播进去 2 是手机拨进去 3是正在加入中 5是已接通出现画面
+            self.video_state = msg
+
+        def get_video_state(self, event, msg):
+            return self.video_state
+        
+        def set_dev_app_mode(self, event, msg):#设置是手表拨 还是手机app拨视频通话 0未拨打 1是手表设备端  2 手机app拨打视频通话
+            self.video_dev_mode = msg
+
+        def get_dev_app_mode(self, event, msg):
+            return self.video_dev_mode
+        
+        def get_videobook_list(self, event, msg):
+            self.check_json = ql_fs.path_exists("/usr/static/storage_file/videobook.json")
+            return [self.check_json,self.videobook]
+        
+        def set_videobook_list(self, event, msg):
+            print("videolist",msg)
+            self.check_json = msg[0]
+            self.videobook = msg[1]
+
+        def call_viode_book_num(self, event, msg):#默认拨打视频通话列表第一个
+            self.video_led_state = 0
+            EventMesh.publish("clear_video_timer_state")
+            if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#未联网提示关机
+                if len(self.videobook) != 0:#已联网未添加账号
+                    phonebook_keys = sorted(self.videobook.keys())
+                    name = self.videobook[phonebook_keys[0]]
+                    key_tmp = phonebook_keys[0][4:]
+                    print("key_tmp list",key_tmp)
+                    print("calling",key_tmp)
+                    EventMesh.publish("set_vedio_call_id", key_tmp)#
+                    EventMesh.publish("set_vedio_call_type", 1)#
+                    EventMesh.publish("set_video_state", 1)#
+                    EventMesh.publish("set_dev_app_mode", 1)#
+                    EventMesh.publish("close_hr_sop2")##在测试心率血氧 血压体温是关闭测试
+                    EventMesh.publish("video_call_out_cb",1)#视频通话拨进中
+                    EventMesh.publish(constants.PROTOCOL.AGTALK_SEND,[1,key_tmp])
+                else:
+                    EventMesh.publish("video_call_out_cb",None)#视频通话拨进中
+                    print("no video list")
+                    pass
+            else:
+                EventMesh.publish("set_sim_mode")#
+                pass
+        
+
+            
+        def set_vedio_call_id(self, event, msg): 
+            self.call_id = msg
+
+        def set_vedio_meet_id(self, event, msg): 
+            self.meet_id = msg
+
+        def set_vedio_call_type(self, event, msg): 
+            self.call_type = msg
+
+        def set_vedio_tokens_data(self, event, msg): 
+            self.tokens_data= msg
+            
+
+        def get_vedio_call_id(self, event, msg): 
+            return self.call_id
+        
+        def get_vedio_meet_id(self, event, msg): 
+            return self.meet_id
+        
+        def get_vedio_call_type(self, event, msg): 
+            return self.call_type
+        
+        def get_vedio_tokens_data(self, event, msg): 
+            return self.tokens_data
+
+
+        def open_vedio_infor(self,event,msg):
+            call_id = EventMesh.publish("get_vedio_call_id")#对方的账号
+            meet_id = EventMesh.publish("get_vedio_meet_id")#共有的会议id
+            call_type = EventMesh.publish("get_vedio_call_type")#呼叫类型
+            tokens_data = EventMesh.publish("get_vedio_tokens_data")#tookens数据#云米平台不需要tokens
+        
+            uid = str(call_id)
+            ticket = str(meet_id)
+
+            # data = ['6951832', '876226002021444', '1', '01lqlyqzQ4Gozdz8OJv1Mij2Y3PBq2y3+rtIA26Ge+m2QHTc/Vk=gufkGNMBiYhPjbq1tLCwtLKysLKws7a2tg==']
+            jrtc.init()
+            # jrtc.config_server("119.3.54.56:1050")#测试服地址
+            tokens = str(tokens_data)
+            appkey = "efe9f8800a39d96244234097"#小见
+            uid_key = "25v9C652123QL3N8"
+
+            # appkey = "249e7d505516af0a7ed44097"
+            # uid_key = "qQI4gkB9FxH8J2cb"
+            imei = EventMesh.publish(constants.EVENT.GET_IMEI)
+            oneself_id = str(imei)#自己的账号默认是imei号
+            jrtc.config(appkey,oneself_id,uid_key,tokens)#只初始化一次发起通话
+           
+            
+            print("uid ",uid,ticket,oneself_id)
+            if call_type == 0:
+                jrtc.open(uid,ticket,[],[])
+                pass
+            else:
+                jrtc.open(uid,ticket,[15,129,240,240],[15,120,240,320])
+            EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
+            
+            jrtc.set_rotate(jrtc.CAM_ROTATE_90)
+            
+            self.video_count = 0
+            self.video_state_time = 0
+            self.video_led_state = 0
+            self.video_answer = 0
+            self.video_timer = 0
+            self.timer.start(1*1000,1,self.publish_led_event_cb)
+            
+
+        def video_time_cb(self,data):
+            EventMesh.publish("system_sleep_rest")#防止黑屏 
+            call_state = jrtc.get_state()
+            video_state = EventMesh.publish("get_video_state")
+            get_video_state = EventMesh.publish("get_video_in_out_state")
+            dev_mode = EventMesh.publish("get_dev_app_mode")
+            # print("call_state",call_state,video_state,get_video_state,dev_mode)
+            if video_state != 0:
+                if get_video_state == 0 and call_state != 0:#双方接通如果是信号不好就开始计算30 30s过后还没有出画面就挂断当前视频通话
+                    self.video_count+=1
+                    if self.video_count > 30:
+                        if call_state != 5:
+                            self.video_state = 0
+                            self.video_state_time = 0
+                            self.timer.stop()
+                            EventMesh.publish("video_reject_cb",5)#挂断视频通话
+                            return
+
+                if call_state == 5:#已经接通出画面了
+                    self.video_count = 0
+                    self.video_answer = 4
+                    EventMesh.publish("set_video_in_out_state",0)
+                    # self.timer.stop()
+                    if self.video_state_time == 0:
+                        self.video_state_time = 1
+                        EventMesh.publish("stop_led_timer")#设置参数
+                        EventMesh.publish("close_timer_all")#
+                        EventMesh.publish("video_answer_mode_timer_cb",2)#
+
+                    EventMesh.publish("set_video_state", 5)
+                else:
+                    self.video_state_time = 0 
+                    if call_state != 0:#信号不好的时候正在接听
+                        EventMesh.publish("set_video_state", call_state)
+
+                        if call_state == 4:
+                            EventMesh.publish("stop_led_timer")#设置参数
+                            EventMesh.publish("close_timer_all")#
+
+                        if dev_mode != 0:
+                            if get_video_state == 0 and call_state != 4 and self.video_answer == 0:
+                                EventMesh.publish("video_answer_mode_timer_cb",3)#
+                        
+                        
+                    if call_state == 0:
+                        # print("no call_state")
+                        self.timer.stop()
+                        EventMesh.publish("video_reject_cb",1)
+            else:
+                # if call_state == 0 or call_state == 1:
+                # print("no network1")
+                self.video_count = 0
+                self.video_state_time = 0
+                self.timer.stop()
+                EventMesh.publish("video_reject_cb",1)
+                # print("no network")
+
+        def video_waite_event_time_cb(self,*argc):#正在接听中,请稍候
+            EventMesh.publish("video_answer_mode_timer_cb",1)
+            pass
+
+        def video_answer_event_time_cb(self,*argc):#对方已接听可以正常视频通话了
+            EventMesh.publish("video_answer_mode_timer_cb",2)
+            pass
+        def video_no_network(self,event,msg):#视频通话无网络
+            if EventMesh.publish(constants.EVENT.GET_CONNECT) == 0:#
+                if EventMesh.publish("get_video_state") != 0:
+                    EventMesh.publish("video_reject_cb",None)
+                pass
+
+
+        def close_video_timer(self,event,msg):
+            self.timer.stop()
+            pass
+        def close_jrtc_event(self,event,msg):
+            jrtc.close(0)
+            pass
+
+
+        def video_answer_cb(self,event,msg):#手表端拒绝视频通话
+            EventMesh.publish("set_video_in_out_state",0)
+            EventMesh.publish("stop_led_timer")#设置参数
+            EventMesh.publish("close_timer_all")#
+            EventMesh.publish("open_vedio_infor")
+        
+        def clear_video_timer_state(self,event,msg):#清除标识
+            self.video_timer = 0
+
+        def video_reject_cb(self,event,msg):#手表端挂断视频通话
+            # print("close_jrtc_event start",msg)
+            if self.video_timer == 0:
+                self.video_timer = 1
+                EventMesh.publish("stop_led_timer")#设置参数
+                EventMesh.publish("close_timer_all")#
+                EventMesh.publish("close_video_timer")
+                # print("video_reject_cb set_video_state")
+                EventMesh.publish("set_video_state", 0)
+                EventMesh.publish("set_dev_app_mode", 0)
+                EventMesh.publish("set_video_in_out_state",0)
+                call_id = str(EventMesh.publish("get_vedio_call_id"))#
+                meet_id = str(EventMesh.publish("get_vedio_meet_id"))#
+                call_type = int(EventMesh.publish("get_vedio_call_type"))#
+                
+                # print("video_reject_cb1111",self.video_led_state,self.video_answer)
+
+                # EventMesh.publish("close_jrtc_event")
+                jrtc.close(0)
+                # print("close_jrtc_event ens")
+                if msg == 2:
+                    self.video_led_state = 1
+                else:
+                    self.video_led_state = 0
+                    EventMesh.publish("video_answer_mode_timer_cb",4)##提示对方已挂断
+                EventMesh.publish(constants.PROTOCOL.RCALLING_SEND,[call_id,meet_id,call_type])
+            
+        def set_app_dev_end_state(self,event,msg):#app拒绝视频通话
+            self.video_led_state = 0 #手表挂断不在进入
+
+        def app_rtalk_cb(self,event,msg):#app拒绝视频通话
+            
+            dev_mode = EventMesh.publish("get_dev_app_mode")#如果是app主动挂断需要提示音频文件
+            video_state = EventMesh.publish("get_video_state")#清除视频通话状态
+            # print("app_rtalk_cb return,",self.video_led_state,dev_mode,video_state)
+            # 1手表挂断 3 信号不好自动挂断 
+            if self.video_led_state == 1 or dev_mode == 0 or video_state == 0:#手表挂断不在进入
+                return
+            self.video_timer = 1
+            self.video_led_state = 0
+            EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
+            
+
+            video_in_out_state = EventMesh.publish("get_video_in_out_state")#设置参数
+            if video_in_out_state != 0:
+                EventMesh.publish("stop_led_timer")#设置参数
+                EventMesh.publish("close_timer_all")#
+                EventMesh.publish("set_video_in_out_state",0)#清除视频通话拨进还是拨出的状态
+
+            # print("app_rtalk_cb ",dev_mode,self.video_led_state,video_state)
+
+            EventMesh.publish("video_answer_mode_timer_cb",4)##提示对方已挂断
+
+            EventMesh.publish("set_dev_app_mode", 0)
+            EventMesh.publish("close_video_timer")
+            EventMesh.publish("set_video_state",0)#清除视频通话状态
+            EventMesh.publish("set_video_in_out_state",0)#清除视频通话拨进还是拨出的状态
+
+        def video_anwer_led(self,event,msg): #1绿灯 2白灯 3红灯
+            # print("video_anwer_led",msg)
+            if msg == 1:
+                # self.video_led_state = 0
+                # EventMesh.publish("set_led_time_arg",[1,2,8*1,led_mode.FLASH_LIGHT_GREEN,8,4,led_mode.VIDEO_MEASURE_MODE])#
+                pass
+            elif msg == 2:#网络不好或者正在接听中
+                # if self.video_led_state == 1:
+                #     self.video_led_state = 0
+                #     EventMesh.publish("set_led_time_arg",[1,2,8*1,led_mode.FLASH_LIGHT_WHITE,8,4,led_mode.VIDEO_MEASURE_MODE])#
+                # else:
+                #     self.video_led_state = 0
+                pass
+            else:#对方手机app挂断或者信号不好挂断
+                # EventMesh.publish("set_led_time_arg",[1,2,8*1,led_mode.FLASH_LIGHT_RED,8,4,led_mode.VIDEO_MEASURE_MODE])#
+                pass
+
+            
+
+    def jrtc_cb(close_sta):#注册回调
+        print("jrtc callback:", close_sta)
+        if close_sta == 0 or close_sta == 1:
+            EventMesh.publish("set_video_in_out_state",0)
+            EventMesh.publish("set_video_state",0)
+            jrtc.close(0)
+    jrtc.set_callback(jrtc_cb)
+
+
+
+
+
+
+
+
index 9bbe2eb..01514b2 100644 (file)
@@ -25,7 +25,7 @@ import request
 def server_init(server_type = None):
     #服务器选择1,防走丢,2大锤,3三基同创,4童信,5云米,6荣为 8:ds未知 dey.hinwatch. com:9968  9:183.62.239.121:31869 10:183.62.239.121:33461
     if server_type == None:
-        server_type = 1
+        server_type = 2
     #EventMesh.debug_log("server_init:server_type:{}".format(server_type))
    
     d_server_addr = "api.xcloudtech.com"
@@ -37,10 +37,17 @@ def server_init(server_type = None):
         
     elif server_type == 2:
         # test.iot.socket.thisiot.com:9999
-        d_server_addr = "test.iot.socket.thisiot.com"
+        # iot.socket .thisiot.com:9999
+        # d_server_addr = "test.iot.socket.thisiot.com"
+        # d_server_port = 9999
+        # d_md5_key = "3JyCjsw4ryXKzjzudayY"
+        # d_PID = "qAELPTKmFanR4RHe"
+
+        d_server_addr = "iot.socket.thisiot.com"
         d_server_port = 9999
-        d_md5_key = "3JyCjsw4ryXKzjzudayY"
-        d_PID = "qAELPTKmFanR4RHe"
+        d_md5_key = "SZYhyGhroQ3xFKFWZq1g"
+        d_PID = "oxLwDqcwJCtiPSRu"
+
     elif server_type == 3:
         d_server_addr = "tcp.zhihuixuexiao.com"
         d_server_port = 2346
@@ -240,12 +247,15 @@ class SockManager(Abstract):
                 # 转成十六进制表示
                 sign_data = ubinascii.hexlify(res)
                 sign_data = sign_data.decode('ascii')
-                print("sign_data:{} sonce_data:{}".format(md5_data,sign_data))
+                # print("sign_data:{} sonce_data:{}".format(md5_data,sign_data))
                 # sign_data = MD5_head
                 # http://8.134.110.49:31379/dev/device/check?imei=&bid=sonce=sign=
-                ip_addr = "test.iot.api.thisiot.com"
-                url = "http://{}/dev/device/check?imei={}&bid={}&sonce={}&sign={}".format(ip_addr,imei,pid_data,sonce_data,sign_data)
+                # ip_addr = "test.iot.api.thisiot.com"
+                # ip_addr = "app.api.thisiot.com"
+                # http://app.api.thisiot.com/
+                url = "http://app.api.thisiot.com/dev/device/check?imei={}&bid={}&sonce={}&sign={}".format(imei,pid_data,sonce_data,sign_data)
 
+                # print("url:{}".format(url))
                 response = request.get(url)
                 data_tmp ={}
                 # d_server_addr = "device.miwitracker.com"
@@ -261,7 +271,7 @@ class SockManager(Abstract):
                     # "api.xcloudtech.com"
                     # d_server_port = 9000
                     jsload_data =  ujson.loads(c)
-                    print("jsload_data-{}".format(jsload_data))
+                    # print("jsload_data-{}".format(jsload_data))
                     # jsload_data = {'data':'111','protocolType':'', 'host':'device.miwitracker.com', 'secretKey': 'bZld0ALsZTt15tKEZhOlLPgbsO75BLTP', 'port':8505, 'bid': '3G', 'extJsonStr': ''}
                     # ujson.loads(c)
                     
@@ -576,8 +586,11 @@ class LK_ProtoCol(ProtoCol):
         EventMesh.publish(constants.PROTOCOL.PING_SEND)
         EventMesh.publish(constants.PROTOCOL.KA_SEND)
         EventMesh.publish(constants.PROTOCOL.TIME_SEND)
+
         EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
         EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.WT_SEND) #开始WT定位
+        if EventMesh.model == 'D15':
+            EventMesh.publish(constants.PROTOCOL.MEMBERS_SEND)
 
 class PING_ProtoCol(ProtoCol):
     """获取绑定状态"""
@@ -600,8 +613,10 @@ class PING_ProtoCol(ProtoCol):
         """
         #EventMesh.debug_log("PING_ProtoCol:recv:%s"%(msg))   
         data_tmp =  msg.decode('ascii')   
-        data_tmp = data_tmp.split(']')[0] #去掉]    
+        data_tmp = data_tmp.split(']')[0] #去掉]   
         EventMesh.publish(constants.EVENT.SET_PING, data_tmp.split(',')[1])
+        if EventMesh.model == 'D15':
+            EventMesh.publish(constants.PROTOCOL.JPREG_SEND) 
 
 class KA_ProtoCol(ProtoCol):
     """心跳"""
@@ -2899,6 +2914,261 @@ class SCREEN_SHOWProtoCol(ProtoCol):
 
         EventMesh.publish(constants.PROTOCOL.SCREEN_SHOW_SEND)  
 
+# #小见平台视频通话
+# # [XT*YYYYYYYYYYYYYYY*LEN*JPREG]
+# # 实例:
+# # [XT*334588000000156*0004*JPREG]
+# # 平台回复:
+# # [XT*设备ID*LEN*JPREG,账号(整型)]
+# # 实例:[XT*334588000000156*0010*JPREG,1087654321]
+class JPREG_ProtoCol(ProtoCol):#登入注册
+    """"""
+    TYPE = "JPREG"
+    def send(self, event, msg):
+        
+        # [XT*334588000000156*0005*WLKEY]
+        send_data = EventMesh.publish("get_new_pid")+"*%s*0005*JPREG"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s]"%(str(MD5_SIGN),send_data)
+        # print("WLKEY:data:%s"%(data))
+        # print("WLKEY!!!!!!!!!!!!!")
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event:
+        @param msg: 接收到的下行数据
+        """
+        # b'[SZKW*867387060319166*000A*KEYBRD]'
+        print("JPREG!!!!!!!!!!!!!",msg,EventMesh.publish("get_new_pid"))
+        # EventMesh.publish(constants.PROTOCOL.JPREG_SEND)  
+
+# # (声网,佰锐的账号是整型)
+# # [XT*YYYYYYYYYYYYYYY*LEN*MEMBERS]
+# # 实例:[XT*334588000000156*0007*MEMBERS]
+# # 平台回复:[XT*设备ID*LEN*MEMBERS,账号1,昵称1,电话1,账号2,昵称2,电话2.....]
+# # 实例:
+# # [XT*334588000000156*003F*MEMBERS,d3e2f759f9d5af3858f3530,爸爸,13662313580,妈妈,555]
+# # 以上数据部分使用Unicode编码,最终上面示例传到服务端将是:
+
+class MEMBERS_ProtoCol(ProtoCol):#获取账号列表
+    """"""
+    TYPE = "MEMBERS"
+    def send(self, event, msg):
+        
+        # [XT*334588000000156*0005*WLKEY]
+        send_data = EventMesh.publish("get_new_pid")+"*%s*0007*MEMBERS"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s]"%(str(MD5_SIGN),send_data)
+        print("MEMBERS SEND:data:%s"%(data))
+        # print("WLKEY!!!!!!!!!!!!!")
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event:
+        @param msg: 接收到的下行数据
+        """
+        # b'[SZKW*876226002021444*0048*MEMBERS,0036003900350031003800330032002C563F563FD83CDF410020D83CDF42002C]'
+        print("MEMBERS!!!!!!!!!!!!!",msg,EventMesh.publish("get_new_pid"))
+        msg = msg[1:-1]
+        msg_tmp = msg.decode('ascii')
+        msg_tmp = msg_tmp.split(',')
+
+        videobook = {}
+        msg_tmp = msg_tmp[1:]
+        msg_tmp = msg_tmp[0]
+
+        j = 0
+        i = 0
+        videobook_old = {}
+        videobook_name_tmp = UnicodeHexStr_To_Utf8Str(msg_tmp)
+        lst = videobook_name_tmp.split(",")
+        
+        print("msg_tmp:{} phonebook_oldtmp:{} type:{}".format(msg_tmp,videobook_name_tmp,lst))
+        # 0 1 2 3
+        for vediobook_tmp in lst: 
+            
+            if (j % 3) == 0:#账号
+                videobook_old = vediobook_tmp
+            elif (j % 3) == 1:#名称
+                i+=1
+                videobook_name_cont= "{}:{}".format("%03d"%(i),videobook_old)                                      
+                videobook[videobook_name_cont] = vediobook_tmp
+            j+=1
+        print("videobook!!!:{}".format(str(videobook)))
+        # print("phonebook!!!:{}".format(str(phonebook)))
+        with open("/usr/static/storage_file/videobook.json","w",encoding="utf-8") as fd:
+            ujson.dump(videobook,fd)
+            print("创建视频通话账号")
+        
+        EventMesh.publish("set_videobook_list",[1,videobook])
+        # EventMesh.publish("video_updata_list_show")
+        # EventMesh.publish(constants.PROTOCOL.MEMBERS_SEND)  
+
+# # [X*Y*LEN*CALLING,呼叫者id,会议id,通话类型,Token]
+
+# # 设备回复
+# # [X*Y*LEN*CALLING,音视频状态]
+# # 音视频状态:为0表示正常可通讯状态,否则填上用音视频返回的状态码,比如200,如果未获取到返回状态码,则填1
+class CALLING_ProtoCol(ProtoCol):#app发起视频通话
+    """"""
+    TYPE = "CALLING"
+    def send(self, event, msg):
+        
+        # [XT*334588000000156*0005*WLKEY]
+        send_data = EventMesh.publish("get_new_pid")+"*%s*0007*CALLING"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s,%d]"%(str(MD5_SIGN),send_data,msg)
+        print("CALLING:send data:%s"%(data))
+        # print("WLKEY!!!!!!!!!!!!!")
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event:
+        @param msg: 接收到的下行数据
+        """
+        # b'[SZKW*867387060319166*000A*CALLING]'
+        print("CALLING!!!!!!!!!!!!!",msg)
+        if EventMesh.model == "D10":#D10没有视频通话
+            EventMesh.publish(constants.PROTOCOL.CALLING_SEND,1)
+            return
+        msg = msg[1:-1]
+        msg_tmp = msg.decode('ascii')
+        msg_tmp_d = msg_tmp.split(',')
+        call_id = msg_tmp_d[1]#id
+        meet_id = msg_tmp_d[2]#会议id
+        call_type = int(msg_tmp_d[3])#会议id# 0音频 1视频
+        tokens_data = msg_tmp_d[4]#tokens
+        EventMesh.publish("set_vedio_call_id", call_id)#
+        EventMesh.publish("set_vedio_meet_id", meet_id)#
+        EventMesh.publish("set_vedio_call_type", call_type)#
+        EventMesh.publish("set_vedio_tokens_data", tokens_data)#
+
+        flag = EventMesh.publish("get_call_state") 
+        fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识
+        usb_state = EventMesh.publish("get_usb")#
+        video_state = EventMesh.publish("get_video_state")
+        usb_state = 0
+        if flag != 0 or usb_state == 1 or usb_state == 3 or fall_down != 0 or video_state != 0: #电话在打入或者 在充电不允许视频通话
+            EventMesh.publish(constants.PROTOCOL.CALLING_SEND,1)
+            EventMesh.publish("set_video_in_out_state", 0)
+            EventMesh.publish("set_video_state", 0)
+            EventMesh.publish("set_dev_app_mode", 0)#
+        else:
+            EventMesh.publish(constants.PROTOCOL.CALLING_SEND,0)
+            EventMesh.publish("set_video_state", 6)
+            EventMesh.publish("set_dev_app_mode", 2)#
+            EventMesh.publish("close_hr_sop2")#
+            EventMesh.publish("video_call_in_event",call_type)
+
+# # [XT*YYYYYYYYYYYYYYY*LEN*RCALLING,呼叫者id,会议id/声网频道名(没有则留空,但位置保留),音频还是视频(0为音频,1为视频)]
+# # 实例:
+# # [XT*334588000000156*0007*RCALLING,d3e2f759f9d5af3858f3530b,,0]
+# # 终端回复:
+# # [XT*设备ID*LEN*RCALLING]
+# # 实例:[XT*334588000000156*0009*RCALLING]  
+# #   
+class RCALLING_ProtoCol(ProtoCol):#设备拒接接听
+    """"""
+    TYPE = "RCALLING"
+    def send(self, event, msg):
+        
+        # [XT*334588000000156*0005*WLKEY]
+        send_data = EventMesh.publish("get_new_pid")+"*%s*0008*RCALLING"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s,%s,%s,%d]"%(str(MD5_SIGN),send_data,msg[0],msg[1],msg[2])
+        print("RCALLING:send data:%s"%(data))
+        # print("WLKEY!!!!!!!!!!!!!")
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+        print("RCALLING:send data end:%s"%(data))
+
+    def recv(self, event, msg):
+        """
+        @param event:
+        @param msg: 接收到的下行数据
+        """
+        # b'[SZKW*867387060319166*000A*RCALLING]'
+        print("RCALLING!!!!!!!!!!!!!")
+
+class AGTALK_ProtoCol(ProtoCol):#设备发起视频通话与app接听视频通话
+    """"""
+    TYPE = "AGTALK"
+    def send(self, event, msg):
+        
+        # [XT*334588000000156*0005*WLKEY]
+        send_data = EventMesh.publish("get_new_pid")+"*%s*0006*AGTALK"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s,%d,%s]"%(str(MD5_SIGN),send_data,msg[0],msg[1])
+        print("AGTALK:send data:%s"%(data))
+        # print("WLKEY!!!!!!!!!!!!!")
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event:
+        @param msg: 接收到的下行数据
+        """
+        # b'[SZKW*876226002021444*007B*AGTALK,0,01lqlyqzzQHpfwv5g7jFVC2H6Ha2tHFpMlfSm5sd2uo7o55JEcc=OVxewje6MjP0NgEODwsLDwkJCwkLCA0NDQ==,8762260020214441701226895]'
+        
+        msg = msg[1:-1]
+        msg_tmp = msg.decode('ascii')
+        msg_tmp_d = msg_tmp.split(',')
+        call_state = int(msg_tmp_d[1])#返回是否可以视频通话
+        if call_state == 0:#可正常通话
+            tokens_data = msg_tmp_d[2]#会议id
+            meet_id = msg_tmp_d[3]#会议id
+            EventMesh.publish("set_vedio_meet_id", meet_id)#
+            EventMesh.publish("set_vedio_tokens_data", tokens_data)#
+            EventMesh.publish("open_vedio_infor")
+
+        else:
+            #不能视频通话
+            tokens_data = msg_tmp_d[2]#token数据
+            meet_id = msg_tmp_d[3]#会议id
+            EventMesh.publish("set_vedio_meet_id", meet_id)#
+            EventMesh.publish("set_vedio_tokens_data", tokens_data)#
+            EventMesh.publish("video_reject_cb",None)#挂断视频通话
+            print("AGTALK no!!!!!!!!!!!!!")
+
+        print("AGTALK!!!!!!!!!!!!!")
+
+
+class RTALK_ProtoCol(ProtoCol):#app拒接视频通话
+    """"""
+    TYPE = "RTALK"
+    def send(self, event, msg):
+        
+        # [XT*334588000000156*0005*WLKEY]
+        send_data = EventMesh.publish("get_new_pid")+"*%s*0005*RTALK"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s,%d,%s]"%(str(MD5_SIGN),send_data,msg[0],msg[1])
+        print("AGTALK:send data:%s"%(data))
+        # print("WLKEY!!!!!!!!!!!!!")
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event:
+        @param msg: 接收到的下行数据
+        """
+        # b'[SZKW*867387060319166*000A*RTALK]'
+        print("RTALK!!!!!!!!!!!!!")  
+        # [SZKW*876226002021444*003A*RTALK,3ef20e64f3abb84b27f7d764,8762260020214441701226522,1]'
+        msg = msg[1:-1]
+        msg_tmp = msg.decode('ascii')
+        msg_tmp_d = msg_tmp.split(',')
+        EventMesh.publish("app_rtalk_cb",1)
+
+        
+
 
 class ProtoColResolver(object):
     def __init__(self):
@@ -2911,7 +3181,7 @@ class ProtoColResolver(object):
     def handler(self, data):
         # 这里接收数据
         
-        # EventMesh.debug_log("handler -> {}".format(data))
+        EventMesh.debug_log("handler -> {}".format(data))
         # if data.startswith('Init;'):
         #     data = data[5:]
         #     EventMesh.publish(constants.EVENT.SET_KEY, {"value": ujson.loads(data)['KEY']})
index 354a47c..44b387b 100644 (file)
@@ -42,8 +42,8 @@ hsensor.activate()
 hsensor.init()
 hsensor.open_blood_oxygen()
 utime.sleep(5)
-PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, 0, 1)
-PWM_backlight.open()
+# PWM_backlight = PWM(PWM.PWM1, PWM.ABOVE_MS, 0, 1)
+# PWM_backlight.open()
 hsensor.close()
 #lcd_ctrl.write(0)
 lv.autoSleep(1)
index 32bf6e3..5fb5964 100644 (file)
@@ -4,7 +4,11 @@
  * Helios SDK Configuration
  *
  */
+
+
 #define PROJECT_NAME_G5_D10  1  //项目宏定义
+
+
 #define CONFIG_LVGL_SPAN 1
 #define CONFIG_LVGL_FS_HELIOS 1
 #define CONFIG_LVGL_GIF_DECODE 1
@@ -24,7 +28,7 @@
 // #define CONFIG_LVGL_MSGBOX 1
 // #define CONFIG_LVGL_ARC 1
 // #define CONFIG_LVGL_METER 1
-// #define CONFIG_LVGL_JPG_DECODE 1
+#define CONFIG_LVGL_JPG_DECODE 1
 // #define CONFIG_LVGL_PNG_DECODE 1
 // #define CONFIG_LVGL_IMGBTN 1
 //#define CONFIG_GH301x 1
@@ -38,3 +42,8 @@
 #define CONFIG_LVGL_QRCODE 1
 #define CONFIG_LVGL_TILEVIEW 1
 #define CONFIG_LVGL_HANDLER_TASK_PRIORITY 80
+#define CONFIG_CAMERA 1
+#define CONFIG_JPEG 1
+#define CONFIG_CAMERA_SAVEPHOTOS 1
+//菊风视频通话
+#define CONFIG_juphoon 1
index 6e03ed9..343bad7 100644 (file)
@@ -10,6 +10,6 @@ source "../services/microPython/config/config.in"
 source "../components/poc/poc_option.in"
 source "../components/GH301x/GH301x_option.in"
 source "../components/SC7A20/SC7A20_option.in"
-
+source "../components/juphoon/juphoon_option.in"
 endmenu
 
index 7f176d0..efc5de2 100644 (file)
@@ -18,7 +18,7 @@ CONFIG_LVGL=y
 #
 CONFIG_LVGL_PNG_DECODE=y
 # CONFIG_LVGL_GIF_DECODE is not set
-#CONFIG_LVGL_JPG_DECODE=y
+CONFIG_LVGL_JPG_DECODE=y
 #CONFIG_LVGL_FS_HELIOS=y
 # CONFIG_LVGL_FS_SD_HELIOS is not set
 CONFIG_LVGL_FS_EXTFLASH_HELIOS=y
@@ -46,11 +46,13 @@ CONFIG_LVGL_KEYBOARD=y
 CONFIG_LVGL_SPAN=y
 CONFIG_LVGL_HANDLER_TASK_PRIORITY=80
 # CONFIG_QRCODE is not set
-# CONFIG_CAMERA is not set
+CONFIG_CAMERA=y
+# CONFIG_CAMERA_DECODE is not set
+CONFIG_CAMERA_SAVEPHOTOS=y
 # CONFIG_QUECTHING is not set
 # CONFIG_SPINAND is not set
 # CONFIG_RTMP is not set
-# CONFIG_JPEG is not set
+CONFIG_JPEG=y
 # CONFIG_SPI_SDCARD is not set
 CONFIG_VIOCE_CALL=y
 # CONFIG_TTS is not set
@@ -60,3 +62,5 @@ CONFIG_LCD=y
 #CONFIG_GH301x=y
 CONFIG_HX3918=y
 CONFIG_SC7A20=y
+
+CONFIG_juphoon=y
index d97b83d..2fb5e24 100644 (file)
Binary files a/2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack.zip and b/2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack.zip differ
index 714d069..73c5340 100644 (file)
Binary files a/2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/libraries/libHeliosAPI.lib and b/2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/libraries/libHeliosAPI.lib differ
index c0f815c..f5bf2c8 100644 (file)
Binary files a/2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/libraries/ql_common_api.lib and b/2.sdk/project/D10/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/libraries/ql_common_api.lib differ
index 7ff1a31..e02e6af 100644 (file)
Binary files a/2.sdk/project/D10/usr/static/audio.bin and b/2.sdk/project/D10/usr/static/audio.bin differ
index cf51027..f437d10 100644 (file)
@@ -181,7 +181,7 @@ class WechatScreen(Screen):
         #         self.wechat_recode_list = ujson.load(fd)#读取每一个amr音频文件的时长ui_setting.py
 
         self.record_test = audio.Record()
-        self.record_test.gain(4,12)
+        self.record_test.gain_set(4,12)
         self.aud = audio.Audio(0)
         # self.aud.set_pa(Pin.GPIO29)
 
index 08792b5..23d8cef 100644 (file)
@@ -25,7 +25,7 @@ import usys
 def server_init(server_type = None):
     #服务器选择1,防走丢,2大锤,3三基同创,4童信 5云米
     if server_type == None:
-        server_type = 2
+        server_type = 1
     #print("server_init:server_type:{}".format(server_type))
     d_server_addr = "api.xcloudtech.com"
     d_server_port = 9000
@@ -2567,11 +2567,8 @@ class AGTALK_ProtoCol(ProtoCol):#设备发起视频通话与app接听视频通
             EventMesh.publish("set_vedio_meet_id", meet_id)#
             EventMesh.publish("set_vedio_tokens_data", tokens_data)#
             EventMesh.publish("open_vedio_infor")
-            # EventMesh.publish("set_UI_high_priority", 0)
-            # EventMesh.publish("load_screen", {"screen": "vedio_answer"})
-            # EventMesh.publish("set_vedio_infor",[call_id,meet_id,call_type,tokens_data])#
-        
-        
+        else:
+            EventMesh.publish("return_prev_screen")
 
         print("AGTALK!!!!!!!!!!!!!")
 
index 3310f6b..841ea82 100644 (file)
@@ -8411,9 +8411,10 @@ class VedioShowScreen(Screen):#正在视频通话中
         
         print("uid ",uid,ticket,oneself_id)
                #jrtc.set_rotate(0)
-        jrtc.open(uid,ticket,[15,120,240,320],[15,129,128,128])
-        
-        pass
+        if call_type == 0:
+            jrtc.open(uid,ticket,[],[])
+        else:
+            jrtc.open(uid,ticket,[15,129,128,128],[15,120,240,320])
 
     def close_jrtc_event(self,event,msg):
         call_state = jrtc.get_state()
@@ -8425,7 +8426,7 @@ class VedioShowScreen(Screen):#正在视频通话中
         pass
 
     def initialization(self):
-        jrtc.set_rotate(jrtc.CAM_ROTATE_180)
+        jrtc.set_rotate(jrtc.CAM_ROTATE_90)
         global camera_video_answer_screen,video_img_test,camera_video_answer_btn_label,camera_video_answer_label,camera_video_answer_second_label,camera_video_answer_btn,vcamera_video_answer_btn_label
         if camera_video_answer_screen == None:
             camera_video_answer_screen = lv.obj()
index 45d3d8d..f64d3d9 100644 (file)
Binary files a/2.sdk/project/K01/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack.zip and b/2.sdk/project/K01/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack.zip differ