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
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
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.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:
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
--- /dev/null
+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)
+
+
+
+
+
+
+
+