try :
from Hsensor import GH3018
except Exception as e:
- print("Hsensor none GH3018:{}".format(e))
+ EventMesh.debug_log("Hsensor none GH3018:{}".format(e))
#
try :
from Hsensor import HX3918
except Exception as e:
- print("Hsensor none HX3918:{}".format(e))
+ EventMesh.debug_log("Hsensor none HX3918:{}".format(e))
from machine import RTC
import quecgnss
import wifiScan
def set_countdown_all_time(self, event, msg):
self.total = msg[0]
self.total_sec = msg[1]
- # print("self.total:{} self.total_sec:{}".format(self.total,self.total_sec))
+ # EventMesh.debug_log("self.total:{} self.total_sec:{}".format(self.total,self.total_sec))
def get_countdown_all_time(self, event, msg):
self.time_cb = msg[0]
self.time_play = msg[1]
- # print("self.time_cb:{} self.total_sec:{}".format(self.time_cb,self.time_play))
+ # EventMesh.debug_log("self.time_cb:{} self.total_sec:{}".format(self.time_cb,self.time_play))
def get_countdown_off_state(self, event, msg):
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
reduce = time_tmp- self.total_sec
- print("self.time_cb:{} self.time_play:{} self.total:{} self.total_sec:{}".format(self.time_cb,self.time_play, self.total,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
break
else:
pre_volt = volt
- # print("__get_soc_from_dict:{}".format(soc2 - (soc2 - soc1) * (pre_volt - volt_arg) // (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:
if( volt_arg == None) :
volt_arg = self.get_voltage()
self.__energy = self.__get_soc(self.__temp, volt_arg)
- # print("get_energy:volt_arg {} __energy{}".format(volt_arg,self.__energy))
+ # EventMesh.debug_log("get_energy:volt_arg {} __energy{}".format(volt_arg,self.__energy))
return self.__energy
def set_charge_callback(self, charge_callback):
EventMesh.publish("set_sos_flag",0)
EventMesh.publish("set_sos_num",0)
EventMesh.publish("set_hangup_mode",0)
- print('hangup_mode disconnect',hangup_mode)
+ EventMesh.debug_log('hangup_mode disconnect',hangup_mode)
sos_flag = EventMesh.publish("get_sos_flag")
- print('voicecall sos_flag',sos_flag)
+ EventMesh.debug_log('voicecall sos_flag',sos_flag)
if sos_flag == 0 :
EventMesh.publish("set_sos_num",0)
else:
num_len = len(number)+1
elif len(number) == 3:
num_len = len(number)+2
- # print("number:{} number_len :{} num:{} num_len:{}".format(number,len(number),num,num_len))
+ # 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])
EventMesh.publish("set_sos_flag",0)
EventMesh.publish("set_sos_num",0)
else:
- # print("number:{} number_len :{}".format(number,len(number)))
+ # EventMesh.debug_log("number:{} number_len :{}".format(number,len(number)))
EventMesh.publish("set_sos_num",num)
if len(number) == 1:
EventMesh.publish("set_callnumer_cb",number[0])
- print("phone 1")
+ EventMesh.debug_log("phone 1")
elif len(number) == 2:
if num == 1 or num == 3:
- print("phone 2")
+ EventMesh.debug_log("phone 2")
EventMesh.publish("set_callnumer_cb",number[1])
elif num == 2:
- print("phone 3")
+ EventMesh.debug_log("phone 3")
EventMesh.publish("set_callnumer_cb",number[0])
elif len(number) == 3:
if num == 1 or num == 4:
EventMesh.publish("set_callnumer_cb",number[1])
- print("phone 4")
+ EventMesh.debug_log("phone 4")
elif num == 2 or num == 5:
- print("phone 5")
+ EventMesh.debug_log("phone 5")
EventMesh.publish("set_callnumer_cb",number[2])
elif num == 3:
- print("phone 6")
+ EventMesh.debug_log("phone 6")
EventMesh.publish("set_callnumer_cb",number[0])
def voice_callback(args):
- print('voicecall iinfo:{}'.format(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
- print('voicecall incoming call, PhoneNO.: ', args[6])
+ EventMesh.debug_log('voicecall incoming call, PhoneNO.: ', args[6])
size_len = len(str(args[6]))
tmp = []
tmp = args[6]
sos_flag = 0
EventMesh.publish("set_sos_flag",0)
- print('voicecall connected, PhoneNO.: ', args[6])
+ EventMesh.debug_log('voicecall connected, PhoneNO.: ', args[6])
size_len = len(str(args[6]))
tmp = []
tmp = args[6]
if flag == 2:
EventMesh.publish("close_timer_all")#
EventMesh.publish("set_call_state",0)
- print('voicecall disconnect end')
+ EventMesh.debug_log('voicecall disconnect end')
elif args[0] == 13:
- print('voicecall is waiting, PhoneNO.: ', args[6])
+ EventMesh.debug_log('voicecall is waiting, PhoneNO.: ', args[6])
elif args[0] == 14:
- print('voicecall dialing, PhoneNO.: ', args[6])
+ 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:
- print('voicecall alerting, PhoneNO.: ', args[6])
+ EventMesh.debug_log('voicecall alerting, PhoneNO.: ', args[6])
EventMesh.publish("set_call_state",1)
elif args[0] == 16:
- print('voicecall holding, PhoneNO.: ', args[6])
+ EventMesh.debug_log('voicecall holding, PhoneNO.: ', args[6])
class DeviceInfoManager(Abstract):
self.log = LogAdapter(self.__class__.__name__)
self.rtc = RTC()
self.aud = audio.Audio(0)
- print("DeviceInfoManager:1")
+ EventMesh.debug_log("DeviceInfoManager:1")
self.gsensor = SC7A20()
- print("DeviceInfoManager:1.0")
+ EventMesh.debug_log("DeviceInfoManager:1.0")
self.gsensor.activate()
- print("DeviceInfoManager:1.1")
+ EventMesh.debug_log("DeviceInfoManager:1.1")
self.gsensor.init()
- print("DeviceInfoManager:2")
+ EventMesh.debug_log("DeviceInfoManager:2")
self.gsensor.set_callback(self.gsensor_cb)
try :
self.hsensor = HX3918()
except Exception as e:
- print("Hsensor none HX3918:{}".format(e))
+ EventMesh.debug_log("Hsensor none HX3918:{}".format(e))
try :
self.hsensor = GH3018()
except Exception as e:
- print("Hsensor none GH3018:{}".format(e))
+ EventMesh.debug_log("Hsensor none GH3018:{}".format(e))
#
self.hsensor.activate()
self.hsensor.init()
try :
self.hsensor.set_sar(1)
except Exception as e:
- print("Hsensor none set_sar:{}".format(e))
+ EventMesh.debug_log("Hsensor none set_sar:{}".format(e))
self.old_temp_time = 0
- # #print("hsensor.open_heart:%d\r\n"%(self.hsensor.open_heart()))
- print("DeviceInfoManager:3")
+ # #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)
def post_processor_after_instantiation(self):
- print("post_processor_after_instantiation:1")
+ EventMesh.debug_log("post_processor_after_instantiation:1")
"""订阅此类所有的事件到 EventMesh中"""
voiceCall.setCallback(voice_callback)
EventMesh.subscribe("screen_get_ope", self.get_device_ope)
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)
- print("post_processor_after_instantiation:2")
+ 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.publish_event_cb()
- print("post_processor_after_instantiation:3")
+ EventMesh.debug_log("post_processor_after_instantiation:3")
def publish_message_event_DeviceInfo(self,event,msg):
self.DeviceInfo_queue.put(msg)
def DeviceInfo_queue_thread(self):
while True:
data = self.DeviceInfo_queue.get()
- #print("DeviceInfo_queue_thread:data = {}".format(data))
+ #EventMesh.debug_log("DeviceInfo_queue_thread:data = {}".format(data))
if data != None:
try:
data["func"](data["data"])
except Exception as e:
- print("DeviceInfo_queue_thread:ERROR:{}".format(e))
+ EventMesh.debug_log("DeviceInfo_queue_thread:ERROR:{}".format(e))
usys.print_exception(e)
def gsensor_cb(self, para):
- print("gsensor_cb:{}".format(para))
+ EventMesh.debug_log("gsensor_cb:{}".format(para))
flip_sw = EventMesh.publish("get_storage_config","flip_sw")
if para == 0: #跌倒报警
def publish_event_cb(self, *args, **kwargs):
if self.boot_time_count < 50000000:
self.boot_time_count += 10
- #print("boot_time_count:{}".format(self.boot_time_count))
+ #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")
- print("temp:{}".format(temp))
+ 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
- print("temp_warning:{} get_temp_time{}".format(self.temp_warning,get_temp_time))
+ EventMesh.debug_log("temp_warning:{} get_temp_time{}".format(self.temp_warning,get_temp_time))
if self.temp_warning*get_temp_time < 3:#高温没连续超过3次,和谐成37.5度以下
temp = 37+(urandom.randint(1, 4)/10)
self.timer_push = 0
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
- # print("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
+ # EventMesh.debug_log("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
EventMesh.publish("countdown_end_cb")
"""定时定位"""
#EventMesh.publish("set_upload_data",3*60)
self.upload_time = EventMesh.publish("get_upload_data")
- #print("self.upload_time:{} math.fabs(time_tmp - self.UD_time):{}".format(self.upload_time,math.fabs(time_tmp - self.UD_time)))
+ #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
self.gsensor.clean_status()#清除运动次数
else : #关闭定位
#EventMesh.txt_log("NO status")
- print("NO status")
+ EventMesh.debug_log("NO status")
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_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)
- # print("self.vbat_buf:{} curr_count :{} bat_total_value:{} temp:{}".format(self.vbat_buf,curr_count,bat_total_value,temp))
+ # 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:
hour = date_tmp[3]
min = date_tmp[4]
old_Timesec = EventMesh.publish("get_old_time_data")
- # print("old_Timesec",old_Timesec)
+ # EventMesh.debug_log("old_Timesec",old_Timesec)
if old_Timesec != None:
data = RTC().datetime()
hour = data[4]
min = data[5]
next_alarm_time = utime.localtime(int(old_Timesec))
- # print("data[5]:{} {} next_alarm_time:{} old_Timesec:{}".format(data[1],data[2],next_alarm_time,old_Timesec))
+ # EventMesh.debug_log("data[5]:{} {} next_alarm_time:{} old_Timesec:{}".format(data[1],data[2],next_alarm_time,old_Timesec))
month = next_alarm_time[1]
day = next_alarm_time[2]
if month != data[1] or day != data[2]:
"""电量小于20% 5分钟提醒一次"""
get_low_btn = EventMesh.publish("get_low_bat_btn")#
battery = EventMesh.publish("screen_get_battery")
- # print("get_low_btn:{} self.bat_time:{}".format(get_low_btn,self.bat_time))
+ # EventMesh.debug_log("get_low_btn:{} self.bat_time:{}".format(get_low_btn,self.bat_time))
if get_low_btn != None:#低电使能开关
if get_low_btn == 1:
self.bat_time+=10
- # print("date_tmp:{} self.bat_time:{}".format(date_tmp,self.bat_time))
+ # EventMesh.debug_log("date_tmp:{} self.bat_time:{}".format(date_tmp,self.bat_time))
if self.bat_time > 5*60:
self.bat_time = 0
if battery[1] <= 20 and battery[1] > 0:
"""未联网提示关机"""
ble=EventMesh.publish(constants.EVENT.GET_CONNECT)
- # print("ble",ble)
+ # EventMesh.debug_log("ble",ble)
if ble == 0:#未联网提示关机
if battery[0] != '1':
self.no_smi_count+=10
- # print("self.no_smi_count",self.no_smi_count)
+ # EventMesh.debug_log("self.no_smi_count",self.no_smi_count)
if self.no_smi_count >= (15*60):
self.no_smi_count = 0
EventMesh.publish("open_power_on", 2)# #未检测到sim卡15分钟后关机
self.no_smi_count = 0
msg_nums = sms.getMsgNums() #获取短信条数
- # print("msg_nums",msg_nums)
+ # EventMesh.debug_log("msg_nums",msg_nums)
if(msg_nums != -1):
sms_data = sms.getSaveLoc()
sms_max = sms_data[0][2]
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:
- # print("get_temp_time:{} self.temp_one_state:{}".format(get_temp_time,self.temp_one_state))
+ # 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:
self.temp_state = 1
self.temp_one_state = 0
EventMesh.publish("set_temp_state",2)
- print("AUTO temp:")
+ EventMesh.debug_log("AUTO temp:")
EventMesh.publish(constants.EVENT.START_TEMP)
elif (time_tmp-self.temp_time) >= 30 and self.temp_state == 1:
EventMesh.publish("set_history_temp_value",0)
# EventMesh.publish("play_temp_value",0)#播放体温数值
EventMesh.publish(constants.EVENT.STOP_TEMP)
- print("AUTO temp:{} tmp_f:{} tmp_f_tmp:{} tmp_d:{} tmp_d_tmp:{}".format(temp,tmp_f,tmp_f_tmp,tmp_d,tmp_d_tmp))
+ EventMesh.debug_log("AUTO temp:{} tmp_f:{} tmp_f_tmp:{} tmp_d:{} tmp_d_tmp:{}".format(temp,tmp_f,tmp_f_tmp,tmp_d,tmp_d_tmp))
self.temp_one_state+=1
if self.temp_one_state == 1:
EventMesh.publish("set_temp_state",3)
- print("AUTO one temp:1")
+ EventMesh.debug_log("AUTO one temp:1")
EventMesh.publish(constants.EVENT.START_TEMP)
elif self.temp_one_state > 3:
self.temp_one_state = 0
EventMesh.publish("set_history_temp_value",0)
# EventMesh.publish("play_temp_value",0)#播放体温数值
EventMesh.publish(constants.EVENT.STOP_TEMP)
- print("once temp:{} tmp_f:{} tmp_f_tmp:{} tmp_d:{} tmp_d_tmp:{}".format(temp,tmp_f,tmp_f_tmp,tmp_d,tmp_d_tmp))
+ EventMesh.debug_log("once temp:{} tmp_f:{} tmp_f_tmp:{} tmp_d:{} tmp_d_tmp:{}".format(temp,tmp_f,tmp_f_tmp,tmp_d,tmp_d_tmp))
else:
self.temp_one_state = 0
if get_temp_end_state == 3:#单次测量
self.temp_one_state+=1
if self.temp_one_state == 1:
- print("AUTO one temp:2")
+ EventMesh.debug_log("AUTO one temp:2")
EventMesh.publish("set_temp_state",3)
EventMesh.publish(constants.EVENT.START_TEMP)
elif self.temp_one_state > 3:
EventMesh.publish("set_history_temp_value",0)
# EventMesh.publish("play_temp_value",0)#播放体温数值
EventMesh.publish(constants.EVENT.STOP_TEMP)
- print("AUTO once temp:{} tmp_f:{} tmp_f_tmp:{} tmp_d:{} tmp_d_tmp:{}".format(temp,tmp_f,tmp_f_tmp,tmp_d,tmp_d_tmp))
+ EventMesh.debug_log("AUTO once temp:{} tmp_f:{} tmp_f_tmp:{} tmp_d:{} tmp_d_tmp:{}".format(temp,tmp_f,tmp_f_tmp,tmp_d,tmp_d_tmp))
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:
- # print("hr......01....{} {}\r\n".format(hr_time[0],hr_time[1]))
+ # EventMesh.debug_log("hr......01....{} {}\r\n".format(hr_time[0],hr_time[1]))
if self.mearsure_btn > 0:
if self.mearsure_timer > 0:
- #print("get_hr_state:{} get_spo2_state:{} self.old_time:{} mearsure_timer:{}".format(self.get_hr_state,self.get_spo2_state,self.old_time,mearsure_timer))
+ #EventMesh.debug_log("get_hr_state:{} get_spo2_state:{} self.old_time:{} mearsure_timer:{}".format(self.get_hr_state,self.get_spo2_state,self.old_time,mearsure_timer))
if self.get_hr_state != 1 and self.get_spo2_state != 1:
if self.get_hr_state == 0 and self.get_spo2_state == 0:
if self.HR_state == 0 or self.HR_state == 3:
else:
pass
# EventMesh.publish("play_hr_value",0)#测量失败
- print("stop debug1")
+ EventMesh.debug_log("stop debug1")
EventMesh.publish(constants.EVENT.STOP_HEART)
self.HR_state = 0
elif self.get_spo2_state == 2 and self.HR_state == 2:
if (time_tmp - self.SENSOR_time) >= self.mearsure_timer:
if self.get_spo2_state == 3 or self.get_hr_state == 3:#单次测量没有完毕优先测量间隔时间测量的
if self.get_hr_state == 3:
- print("stop debug2")
+ EventMesh.debug_log("stop debug2")
EventMesh.publish(constants.EVENT.STOP_HEART)
heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
if heart_value > 50 and heart_value != None:
self.SENSOR_time = time_tmp
self.HR_state = 0
- #print("time_tmp :{} self.SENSOR_time :{} time_tmp - self.SENSOR_time:{} self.HR_state:{}".format(time_tmp,self.SENSOR_time,time_tmp - self.SENSOR_time,self.HR_state))
+ #EventMesh.debug_log("time_tmp :{} self.SENSOR_time :{} time_tmp - self.SENSOR_time:{} self.HR_state:{}".format(time_tmp,self.SENSOR_time,time_tmp - self.SENSOR_time,self.HR_state))
if (time_tmp - self.SENSOR_time) == 0 and self.HR_state == 0:
- print("START_HEART:1")
+ EventMesh.debug_log("START_HEART:1")
EventMesh.publish("set_hr_state",2)#2代表后台进入测试
EventMesh.publish(constants.EVENT.START_HEART)
self.HR_state = 1
self.HR_OneTime = 0
elif (time_tmp - self.SENSOR_time) >= 60 and self.HR_state == 1:
EventMesh.publish("set_hr_state",0)#2代表后台进入测试
- print("stop debug3")
+ EventMesh.debug_log("stop debug3")
EventMesh.publish(constants.EVENT.STOP_HEART)
heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
- print("heart_value:{}".format(heart_value))
+ EventMesh.debug_log("heart_value:{}".format(heart_value))
if heart_value > 50 and heart_value != None:
# EventMesh.publish("play_hr_value",heart_value)
EventMesh.publish("set_history_hr_value",heart_value)
pass
# EventMesh.publish("play_hr_value",0)
#获取心率数据上传数据app
- print("STOP_HEART:")
+ EventMesh.debug_log("STOP_HEART:")
self.HR_state = 3
# EventMesh.publish("set_spo2_state",2)#2代表后台进入血氧测试
# EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
- # print("START_BLOOD_OXYGEN:")
+ # EventMesh.debug_log("START_BLOOD_OXYGEN:")
# elif (time_tmp - self.SENSOR_time) >= 120 and self.HR_state == 2:#有需要再打开
- # print("STOP_BLOOD_OXYGEN:")
+ # EventMesh.debug_log("STOP_BLOOD_OXYGEN:")
# EventMesh.publish("set_spo2_state",0)#2代表后台进入血氧测试
# EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#停止血氧测试
# spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
- # print("spo2_value:{}".format(spo2_value))
+ # EventMesh.debug_log("spo2_value:{}".format(spo2_value))
# if spo2_value > 85 and spo2_value != None:
# EventMesh.publish("set_old_spo2_data",spo2_value)
# EventMesh.publish("set_history_spo2_value",spo2_value)
self.HR_state = 0
self.HR_OneTime+=1
if self.HR_OneTime == 1 and self.HR_Onestate == 0:
- print("hr..........\r\n")
+ EventMesh.debug_log("hr..........\r\n")
if self.get_hr_state == 3:
self.Hr_Need_Open = 1
EventMesh.publish("set_hr_state",3)#2代表后台进入测试
else:
self.Spo2_Need_Open = 0
self.HR_Onestate = 1
- # print("self.HR_Onestate....3..:{} {} {} {} {}".format(self.HR_Onestate,self.get_hr_state,self.get_spo2_state,self.Hr_Need_Open,self.Spo2_Need_Open))
+ # EventMesh.debug_log("self.HR_Onestate....3..:{} {} {} {} {}".format(self.HR_Onestate,self.get_hr_state,self.get_spo2_state,self.Hr_Need_Open,self.Spo2_Need_Open))
elif self.HR_OneTime > 6 and self.HR_Onestate == 1:
- # print("self.HR_Onestate...4....:{} {} {} {} {}".format(self.HR_Onestate,self.get_hr_state,self.get_spo2_state,self.Hr_Need_Open,self.Spo2_Need_Open))
+ # EventMesh.debug_log("self.HR_Onestate...4....:{} {} {} {} {}".format(self.HR_Onestate,self.get_hr_state,self.get_spo2_state,self.Hr_Need_Open,self.Spo2_Need_Open))
if self.Hr_Need_Open == 1:#需要关闭心率测量
- print("stop debug4")
+ EventMesh.debug_log("stop debug4")
EventMesh.publish(constants.EVENT.STOP_HEART)
heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
if heart_value > 50 and heart_value != None:
elif self.HR_OneTime > 6+6 and self.HR_Onestate == 2:
- print("HR_OneTime:....05")
+ EventMesh.debug_log("HR_OneTime:....05")
if self.set_hsenor_crt == 2:
EventMesh.publish("set_spo2_state",0)#2代表后台进入血氧测试
EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#停止血氧测试
elif self.set_hsenor_crt == 1:
EventMesh.publish("set_hr_state",0)#0代表g关闭测试
- print("stop debug5")
+ EventMesh.debug_log("stop debug5")
EventMesh.publish(constants.EVENT.STOP_HEART)
heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
if heart_value > 50 and heart_value != None:
self.HR_OneTime = 0
self.set_hsenor_crt = 0
else:
- #print("hr......01....{} {} self.HR_Onestate {} {}".format(self.get_hr_state,self.get_spo2_state,self.HR_OneTime,self.HR_Onestate))
+ #EventMesh.debug_log("hr......01....{} {} self.HR_Onestate {} {}".format(self.get_hr_state,self.get_spo2_state,self.HR_OneTime,self.HR_Onestate))
self.SENSOR_time = time_tmp#进入最后一次的时间戳
self.old_time = 0
self.HR_Onestate = 1
elif self.HR_OneTime > 6 and self.HR_Onestate == 1:
- print("stop_heart Onec ")
+ EventMesh.debug_log("stop_heart Onec ")
if self.Hr_Need_Open == 1:#需要关闭心率测量
- print("stop debug6")
+ EventMesh.debug_log("stop debug6")
EventMesh.publish(constants.EVENT.STOP_HEART)
heart_value = EventMesh.publish(constants.EVENT.GET_HEART)
- print("stop_heart heart_value:{}".format(heart_value))
+ EventMesh.debug_log("stop_heart heart_value:{}".format(heart_value))
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("set_spo2_state",0)#2代表后台进入血氧测试
EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#K开血氧
spo2_value = EventMesh.publish(constants.EVENT.GET_BLOOD_OXYGEN)
- print("spo2_value:{}.......01..".format(spo2_value))
+ EventMesh.debug_log("spo2_value:{}.......01..".format(spo2_value))
if spo2_value > 85 and spo2_value != None:
# EventMesh.publish("play_spo2_value",spo2_value)
EventMesh.publish("set_history_spo2_value",spo2_value)
self.HR_Onestate = 0
self.HR_OneTime = 0
self.set_hsenor_crt = 2#血氧关闭
- print("STOP_BLOOD_OXYGEN:....06.....")
+ EventMesh.debug_log("STOP_BLOOD_OXYGEN:....06.....")
elif self.HR_OneTime > 6+6 and self.HR_Onestate == 2:
if self.set_hsenor_crt == 2:
# EventMesh.publish("play_spo2_value",0)
elif self.set_hsenor_crt == 1:
EventMesh.publish("set_hr_state",0)#0代表g关闭测试
- print("stop debug7")
+ 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:
if get_hr_state != None and get_spo2_state != None:
if get_hr_state == 2 or get_hr_state == 3:
EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率
- print("stop debug8")
+ EventMesh.debug_log("stop debug8")
EventMesh.publish(constants.EVENT.STOP_HEART)
elif get_spo2_state == 2 or get_spo2_state == 3:
EventMesh.publish("set_spo2_state",0)#2代表后台进入测试
if time_s != 0:
if (time_tmp - time_s) >= 60:#大于60s关闭测试
EventMesh.publish("set_hr_state",0)#0代表g关闭测试
- print("stop debug7")
+ 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:
else :
if WEAR != 1:
EventMesh.publish("set_hr_state",0)#0代表g关闭测试
- print("stop debug7")
+ EventMesh.debug_log("stop debug7")
EventMesh.publish(constants.EVENT.STOP_HEART)
EventMesh.publish("play_hr_value",0)
pass
if time_s != 0:
if (time_tmp - time_s) >= 60:#大于60s关闭测试
EventMesh.publish("set_spo2_state",0)#0代表g关闭测试
- print("stop spo2 debug7")
+ 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:
else :
if WEAR != 1:
EventMesh.publish("set_spo2_state",0)#0代表g关闭测试
- print("stop debug8")
+ EventMesh.debug_log("stop debug8")
EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
EventMesh.publish("play_spo2_value",0)
pass
if time_s != None:
if time_s != 0:
if (time_tmp - time_s) >= 30:#大于60s关闭测试
- print("体温测量结束")
+ EventMesh.debug_log("体温测量结束")
temp = EventMesh.publish(constants.EVENT.GET_TEMP)
temp = self.optimize_temp(temp)
- print("temp",temp)
+ EventMesh.debug_log("temp",temp)
EventMesh.publish("set_temp_state",0)
tmp_f_tmp = 0
tmp_d_tmp = 0
else :
if WEAR != 1:
EventMesh.publish("set_temp_state",0)#0代表g关闭测试
- print("stop debug9")
+ EventMesh.debug_log("stop debug9")
EventMesh.publish(constants.EVENT.STOP_TEMP)
EventMesh.publish("play_temp_value",0)
if battery[0] == '1':
- # print("battery[1]",battery[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 battery[1] >= 100:
if self.charge_full_count == 0:#充电已满
EventMesh.publish("set_usb",3)#
- print("charge R_CHARGE_full")
+ EventMesh.debug_log("charge R_CHARGE_full")
self.charge_full_count = 1
else:
tmp = 0
tmp = self.gsensor.get_step()
- # print("x:%d,y:%d,z:%d tmp %d",XYZ[0],XYZ[1],XYZ[2],tmp)
+ # EventMesh.debug_log("x:%d,y:%d,z:%d tmp %d",XYZ[0],XYZ[1],XYZ[2],tmp)
self.step[0]= tmp
self.step[1] = XYZ[0]
self.step[2] = XYZ[1]
vbat = EventMesh.publish("get_battery",temp)
if vbat == None:
vbat = 100
- # print("vbat",vbat)
+ # EventMesh.debug_log("vbat",vbat)
# if temp != None :
# if temp <= 3505:
# vbat = 0
return self.PING
def set_connect(self, topic, msg):
- #print("set_connect:{}".format(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):
- print("start_blood_oxygen!!!")
+ EventMesh.debug_log("start_blood_oxygen!!!")
self.hsensor.open_blood_oxygen()
def start_heart(self, topic, msg):
- print("start_heart!!!")
+ EventMesh.debug_log("start_heart!!!")
self.hsensor.open_heart()
def stop_blood_oxygen(self, topic, msg):
- print("stop_blood_oxygen!!!")
+ EventMesh.debug_log("stop_blood_oxygen!!!")
self.hsensor.close()
def stop_heart(self, topic, msg):
- print("stop_heart!!!")
+ EventMesh.debug_log("stop_heart!!!")
self.hsensor.close()
def get_blood_oxygen(self, topic, msg):
self.hsensor.set_sleep()
def start_temp(self, topic, msg):
- print("start_temp!!!!!!!")
+ EventMesh.debug_log("start_temp!!!!!!!")
WHO_AM_I = bytearray([0x01, 0])
I2C_SLAVE_ADDR = 0x49
#I2C_SLAVE_ADDR = 0x48
data = bytearray([0x61A0, 0]) # 唤醒
return self.i2c0.write(I2C_SLAVE_ADDR, WHO_AM_I, 1, data, 2)
def stop_temp(self, topic, msg):
- print("stop_temp!!!!!!!")
+ EventMesh.debug_log("stop_temp!!!!!!!")
WHO_AM_I = bytearray([0x01, 0])
I2C_SLAVE_ADDR = 0x49
#I2C_SLAVE_ADDR = 0x48
#I2C_SLAVE_ADDR = 0x48
r_data = bytearray(2)
self.i2c0.read(I2C_SLAVE_ADDR, WHO_AM_I, 1, r_data, 2, 0)
- #print("temp_data:{}".format(r_data))
+ #EventMesh.debug_log("temp_data:{}".format(r_data))
temp_s = ((r_data[0]<<8) | (r_data[1]))>>4
- #print("temp_s:{}".format(temp_s))
+ #EventMesh.debug_log("temp_s:{}".format(temp_s))
temp_data = temp_s * 0.0625
- print("temp_data:{}".format(temp_data))
+ EventMesh.debug_log("temp_data:{}".format(temp_data))
return temp_data
status = state
if status == 1:#插入USB
- print("charge R_CHARGE_in")
+ EventMesh.debug_log("charge R_CHARGE_in")
EventMesh.publish("set_usb", 1)#
pass
elif status == 0:#拨出usbs
EventMesh.publish("set_usb", 2)#
- print("charge R_CHARGE_out")
+ EventMesh.debug_log("charge R_CHARGE_out")
self.location_queue = Queue(100)
self.lpm_fd = None
self.start_agps = 0
- quecgnss.init()
- quecgnss.gnssEnable(0)
+ read_data = EventMesh.publish("get_storage_config","isOpenGNSS")#获取是否打开GNSS
+ if read_data != None:
+ self.isOpenGNSS = read_data
+ else:#默认关闭GNSS
+ self.isOpenGNSS = "0"
+ EventMesh.publish("set_storage_config",["isOpenGNSS",self.isOpenGNSS])
+ if self.isOpenGNSS == "1":
+ quecgnss.init()
+ quecgnss.gnssEnable(0)
@staticmethod
def get_date():
return "{:04d}-{:02d}-{:02d}".format(*utime.localtime()[0:3])
self.cell_data = []
self.location_timer_count = 0
self.GSV_sig_ok_count = 0
- print("start_location:{}".format(msg))
+ EventMesh.debug_log("start_location:{}".format(msg))
if( self.location_flag == 1):
return
_thread.stack_size((9+5)*1024)
def start_location_test(self, event, msg):
- print("start_location_test")
+ EventMesh.debug_log("start_location_test")
self.location_type = 1
if( self.location_flag == 1):
def WIFI_INFO(self, event, msg):
self.wifi_data = msg
- # print("WIFI_INFO:")
- # print([msg[0],msg])
+ # EventMesh.debug_log("WIFI_INFO:")
+ # EventMesh.debug_log([msg[0],msg])
def WIFI_scan_open(self, event, msg):
- #print("WIFI_scan_open")
+ #EventMesh.debug_log("WIFI_scan_open")
if wifiScan.getState() == False :
wifiScan.setCfgParam(6, 2, 5, 0) #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
wifiScan.setCallback(wifiScan_cb) #注册回调函数
wifiScan.asyncStart()
- #print("wifiScan.asyncStart")
+ #EventMesh.debug_log("wifiScan.asyncStart")
else :
- print("WIFI_scan_open:error1")
+ EventMesh.debug_log("WIFI_scan_open:error1")
def gps_open(self, event, msg):
- #print("publish:gps_open")
- #quecgnss.init()
- quecgnss.gnssEnable(2)
- #self.gps.__gps_nmea_data_clean()
+ 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):
- quecgnss.gnssEnable(0)
+ 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) :
- #print("Location_send1")
+ #EventMesh.debug_log("Location_send1")
if self.location_queue.empty() == True:
return
date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
send_data += ",%s,%d,%s"%(state,CELL_num,CELL_data)
send_data += ",%d,%s"%(WIFI_num,WIFI_data)
send_data+=",%s"%(precision)
- #print("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
+ #EventMesh.debug_log("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
while True:
if self.location_queue.empty() == False:
TYPE = self.location_queue.get()
- #print("Location_send3:{}".format(TYPE))
+ #EventMesh.debug_log("Location_send3:{}".format(TYPE))
EventMesh.publish(TYPE,send_data)
else :
break
if self.lpm_fd == None:
self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
pm.wakelock_lock(self.lpm_fd)
- print("location_thread:1")
+ EventMesh.debug_log("location_thread:1")
EventMesh.publish(constants.EVENT.GPSOPEN)
- print("location_thread:2")
+ EventMesh.debug_log("location_thread:2")
#self.timer_read_GPS_info.start(1000, 1, self.location_timer)
- print("location_thread:3")
+ EventMesh.debug_log("location_thread:3")
#utime.sleep_ms(1000)
self.location_timer_count = 0
#quecgnss.read(4096)#去掉第一次错误数据
# pm.sclkEx_set(0, 1, 5)
if self.location_check_data_timer_count >= 1 :#3秒查一次基站数据和wifi数据
self.location_check_data_timer_count = 0
- #print(self.location_timer_count)
+ #EventMesh.debug_log(self.location_timer_count)
GSV_dict= {}
-
- #检查GNSS数据
- if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
+ 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()
- # print("gsv:{}".format(quecgnss.get_gsv()))
- # print("gga:{}".format(quecgnss.get_gga()))
- # print("rmc:{}".format(quecgnss.get_rmc()))
- # print("vtg:{}".format(quecgnss.get_vtg()))
- for i in range(len(gsv_data)) :
-
- if i % 2 == 0:
- if i+1 >= len(gsv_data) :
- # print("gsv_data num error!!")
- break
- GSV_dict[gsv_data[i]] = gsv_data[i+1]
- #print("type:gsv_data{}".format(type(gsv_data[i+1])))
- try:
- #print("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
- }
+ 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
+ }
# ***********************************************************************************
# EventMesh.txt_log("GGA_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
# self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- if self.GSV_sig_ok_count <= 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过40秒且信号大于30的不足3个
+ if (self.isOpenGNSS == "1" or self.GSV_sig_ok_count <= 1) and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过40秒且信号大于30的不足3个
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
#EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
#EventMesh.txt_log("self.GSV_sig_ok_count :{}".format(self.GSV_sig_ok_count))
#EventMesh.publish("set_old_step_value",self.location_timer_count)
- #print("location_timer_count:{}".format(self.location_timer_count))
+ #EventMesh.debug_log("location_timer_count:{}".format(self.location_timer_count))
except Exception as e:
usys.print_exception(e)
EventMesh.txt_log("location_thread:ERROR:".format(e))
- #print("location_thread:ERROR:{}".format(usys.print_exception(e)))
- print("self.gps_data{},self.wifi_data{},self.cell_data{}".format(self.gps_data,self.wifi_data,self.cell_data))
+ #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)
if self.lpm_fd != None:
pm.wakelock_unlock(self.lpm_fd)
#pm.delete_wakelock(lpm_fd)
- print("CLOSE_LOCATION")
+ EventMesh.debug_log("CLOSE_LOCATION")
#EventMesh.txt_log("CLOSE_LOCATION")
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)
- print("读取电话本")
+ EventMesh.debug_log("读取电话本")
def post_processor_after_instantiation(self):
EventMesh.subscribe("get_phonebook_list", self.get)
EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
else:
EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
- print("call_phonebook_one_call name:{} key_tmp:{} len:{}".format(name,key_tmp,len(self.read_phonebook)))
+ 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 = ''
EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
else:
EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
- print("call_phonebook_two_call name:{} key_tmp:{}".format(name,key_tmp))
+ EventMesh.debug_log("call_phonebook_two_call name:{} key_tmp:{}".format(name,key_tmp))
def call_phonebook_three_call(self, event, msg):
name = ''
EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
else:
EventMesh.publish("dial_out_call_center_cb",None)#电话拨出去
- print("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]
def get_msg_nums(self, event, msg):
self.msg_nums = sms.getMsgNums()
- print("self.msg_nums {}:".format(self.msg_nums))
+ 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)
- # print("self.msg_detai {}:".format(self.msg_detai))
+ # EventMesh.debug_log("self.msg_detai {}:".format(self.msg_detai))
return{
"小明":"有内鬼,停止交易",
"小红":"今晚十点一起吃饭"
def save_msg_name(self, event, msg):
self.msg_name = str(msg)
- print("save_msg_name:msg".format(msg))
+ EventMesh.debug_log("save_msg_name:msg".format(msg))
def save_msg_content(self, event, msg):
self.msg_content = str(msg)
- print("save_msg_content:msg".format(msg))
+ EventMesh.debug_log("save_msg_content:msg".format(msg))
def get_msg_content(self, event, msg):
return self.msg_content
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)
- print("读取通话记录")
+ EventMesh.debug_log("读取通话记录")
def post_processor_after_instantiation(self):
EventMesh.subscribe("get_call_log_list", self.get)
# 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)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
- # print(sort_new)
+ # 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]
# with open("/usr/static/storage_file/history_temp.json","w",encoding="utf-8") as fd:
# ujson.dump(self.read_histroy_temp_data,fd)
- #print(self.read_histroy_temp_data)
+ #EventMesh.debug_log(self.read_histroy_temp_data)
pass
else:
pass
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)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
- print(sort_new)
+ 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]
# 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)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条
- # print(sort_new)
+ # 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]
# with open("/usr/static/storage_file/history_spo2.json","w",encoding="utf-8") as fd:
# ujson.dump(self.read_histroy_spo2_data,fd)
- # #print(self.read_histroy_spo2_data)
+ # #EventMesh.debug_log(self.read_histroy_spo2_data)
#播放语音
# EventMesh.publish("set_hr_blood_led",2)#测量成功
pass
EventMesh.subscribe("get_storage_config", self.get_storage_config)
def set_storage_data(self, event, msg):
- # print("set_storage_data:{}".format(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:
def set_storage_config(self,event,msg):
- # print("set_storage_key_data1:{}".format(msg))
+ # EventMesh.debug_log("set_storage_key_data1:{}".format(msg))
if len(msg) >= 2:
self.config_data[msg[0]]=msg[1]
- # print("set_storage_key_data2:{}".format(self.config_data[msg[0]]))
+ # 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):
- # print("get_storage_data:{}".format(self.config_data))
+ # EventMesh.debug_log("get_storage_data:{}".format(self.config_data))
return self.config_data
def get_storage_config(self,event,msg):
- # print("get_storage_key_data1:{}".format(msg))
+ # EventMesh.debug_log("get_storage_key_data1:{}".format(msg))
b = msg in self.config_data.keys()
if b == True:
- # print("get_storage_key_data2:{}".format(self.config_data[msg]))
+ # 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:
- # print("get_storage_key_data:none key:{}",msg)
+ # EventMesh.debug_log("get_storage_key_data:none key:{}",msg)
# return None
#定位频率
class getUpLoadDataManager(Abstract):#
EventMesh.subscribe("get_boot_off_time", self.get_boot_off_time)
def set_boot_off_time(self, event, msg):
- print("set_boot_off_time",msg)
+ EventMesh.debug_log("set_boot_off_time",msg)
EventMesh.publish("set_storage_config",["off_on",msg[0]])
EventMesh.publish("set_storage_config",["off_start",msg[1]])
EventMesh.publish("set_storage_config",["off_end",msg[2]])
def set(self, event, msg):
global alarm_list
- print("msg = {}".format(msg))
+ EventMesh.debug_log("msg = {}".format(msg))
idx = msg.get("idx")
- print("修改第{}个闹钟信息{}".format(idx,alarm_list[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"]
def read_alarminjson(self, event, msg):
IFEXIST = ql_fs.path_exists("/usr/static/storage_file/alarm_msg.json")
global alarm_list
- print("IFEXIST:{}".format(IFEXIST))
+ 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)
# min2 = str(alarm_list[1]["minute"])
EventMesh.publish("set_boot_off_time",[1,hour1,hour2])
- print("hour1:{}-{}".format(hour1,hour2))
+ EventMesh.debug_log("hour1:{}-{}".format(hour1,hour2))
return alarm_list
global alarm_list
EventMesh.publish("read_alarminjson")
- print("msg:{}".format(msg))
+ 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])
- print("start_hour:{} start_min:{} enable:{}",start_hour,start_min,enable)
+ 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.append({"idx": i, "hour": start_hour, "minute": start_min, "days":[0,1,2,3,4,5,6], "enabled": enable,"repeart":10})
- # print("alarm_list----len- :{} alarm_list:{}".format(len(alarm_list),alarm_list))
+ # 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
- print("ddddddddddddddddddd:",msg)
+ EventMesh.debug_log("ddddddddddddddddddd:",msg)
idx = msg.get("idx")
- print("delete_here1-----{},{}:".format(idx,msg))
+ EventMesh.debug_log("delete_here1-----{},{}:".format(idx,msg))
for i, alarm in enumerate(alarm_list):
- print("delete_here2-----{},{}:".format(i,alarm))
+ EventMesh.debug_log("delete_here2-----{},{}:".format(i,alarm))
if alarm["idx"] == idx:
del alarm_list[i]
- print("delete_here3-----",alarm_list)
+ EventMesh.debug_log("delete_here3-----",alarm_list)
#删除闹钟后,对idx重新排序
if alarm_list:
for j in range(i,len(alarm_list)):
alarm_list[j]["idx"] -= 1
- print("delete_here4-----",alarm_list)
+ 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)
return self.idx
def _rtc_callback(self,args):
- print("---!!!!!!pfff neew alarm_ring!!!!!!!---,idx:",args)
+ EventMesh.debug_log("---!!!!!!pfff neew alarm_ring!!!!!!!---,idx:",args)
global alarm_list
EventMesh.publish("read_alarminjson")
idx = self.idx
- print("单次闹钟关闭:{} alarm_list:{}".format(idx,alarm_list))
+ EventMesh.debug_log("单次闹钟关闭:{} alarm_list:{}".format(idx,alarm_list))
#判断是否是单次闹钟,如果是,则将开关状态设置为关闭
# for i in range(len(alarm_list)):
# if alarm_list[i]["idx"] == self.idx:
# idx = i
if not alarm_list[idx]["days"] :
- print("关闭1:",alarm_list[idx]["days"])
- print("关闭2:",alarm_list [idx]["days"])
+ EventMesh.debug_log("关闭1:",alarm_list[idx]["days"])
+ EventMesh.debug_log("关闭2:",alarm_list [idx]["days"])
alarm_list[idx]["enabled"] = False
with open("/usr/static/storage_file/alarm_msg.json", 'w+',encoding='utf-8') as fd:
ujson.dump(alarm_list,fd)
#设置下一个闹钟,定时开关机功能
msg_data = EventMesh.publish("get_boot_off_time")
- print("msg_tmp:{}".format(msg_data))
+ EventMesh.debug_log("msg_tmp:{}".format(msg_data))
off_on = 1
off_start = "6:0"
off_end = "23:0"
rtc_now_time = self.rtc.datetime()
current = rtc_now_time[4]*60+rtc_now_time[5]
cur_day = rtc_now_time[3]
- print("off_on:{} current:{} start_min:{} end_min:{}".format(off_on,current,start_min,end_min))
+ EventMesh.debug_log("off_on:{} current:{} start_min:{} end_min:{}".format(off_on,current,start_min,end_min))
if off_on != None:
if off_on == 1:
if end_min == current:#结束的时间分钟等于关机时间分钟数则关机
if next_minute >= current_minute:#开机时间大于当前时间 9:00 > = 8:00
interval_minute = next_minute - current_minute
- print("关机距离下一次响铃的的分钟数:", interval_minute,next_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
- print("关机08888距离下一次响铃的的分钟数:", interval_minute,next_minute)
+ EventMesh.debug_log("关机08888距离下一次响铃的的分钟数:", interval_minute,next_minute)
#反向获取时间戳
time = utime.localtime()
- print("关机09获取utime的时间戳:", time)
+ EventMesh.debug_log("关机09获取utime的时间戳:", time)
rtc_mktime = utime.mktime(time)
- print("关机10反向获取utime的mktime:", rtc_mktime)
+ EventMesh.debug_log("关机10反向获取utime的mktime:", rtc_mktime)
#加上下一次响铃需要的时间
next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳
- print("关机11下一次响铃的mktime:", next_alarm_mktime)
+ EventMesh.debug_log("关机11下一次响铃的mktime:", next_alarm_mktime)
#格式化时间戳,得到下一次闹钟的时间
next_alarm_time = utime.localtime(next_alarm_mktime)
- print("关机12下一次响铃的准确时间:", next_alarm_time)
+ EventMesh.debug_log("关机12下一次响铃的准确时间:", next_alarm_time)
#将时间转换为rtc的格式
data_l = [2021, 7, 9, 5, 12, 30, 0, 0]
#给rtc时间赋值
data_l[4] = next_alarm_time[3] #hour
data_l[5] = next_alarm_time[4] #minute
data_e=tuple(data_l)
- print("关机13将该时间转换为RTC元组:", data_e)
+ EventMesh.debug_log("关机13将该时间转换为RTC元组:", data_e)
self.rtc.register_callback(self._rtc_callback)
FLAG = self.rtc.set_alarm(data_e)
if FLAG == 0:
- print("开机11成功设置rtc的到期时间:", data_e)
+ EventMesh.debug_log("开机11成功设置rtc的到期时间:", data_e)
else:
- print("开机时设置rtc的到期时间失败:", data_e)
+ EventMesh.debug_log("开机时设置rtc的到期时间失败:", data_e)
self.rtc.enable_alarm(1)
if ubs_state == 2 or ubs_state == 0:
- print("结束时设置rtc的到期时间失败:", data_e)
+ EventMesh.debug_log("结束时设置rtc的到期时间失败:", data_e)
EventMesh.publish("open_power_on", 5)#静音关机
return
else:
- print("结束111开机时设置rtc的到期时间失败:", data_e)
+ EventMesh.debug_log("结束111开机时设置rtc的到期时间失败:", data_e)
return
EventMesh.publish("set_rtc_alarm")
total_min = 0
if off_on != None:
if off_on == 1:
- # print("alarm_list:{}".format(alarm_list))
+ # EventMesh.debug_log("alarm_list:{}".format(alarm_list))
for idx in range(0,len(alarm_list)):
hour = int(alarm_list[idx]["hour"])
min = int(alarm_list[idx]["minute"])
enable = int(alarm_list[idx]["enabled"])
repeart = int(alarm_list[idx]["repeart"])
total_min = hour*60+min
- # print("hour",hour,min,day,enable,repeart,total_min,start_min)
+ # EventMesh.debug_log("hour",hour,min,day,enable,repeart,total_min,start_min)
if enable == 1:
if repeart != 10:
if len(day) == 0 and enable == 1:#单次闹钟
else:
if (cur_day in day) and enable == 1:
if total_min == start_min and enable == 1:#如果闹钟时间和开机时间一致啧响铃否则不响铃
- # print("alarm_ring22222")
+ # EventMesh.debug_log("alarm_ring22222")
EventMesh.publish("OPEN_ALARM_RING")#闹钟到点响铃
alarm_flag = 1
break
continue
else:
alarm_flag = 0
- # print("start_min",start_min,current,alarm_flag)
+ # EventMesh.debug_log("start_min",start_min,current,alarm_flag)
if (start_min != current and alarm_flag == 0) or off_on == 0:
EventMesh.publish("OPEN_ALARM_RING")#闹钟到点响铃
EventMesh.publish("read_alarminjson")
rtc_now_time = self.rtc.datetime()
- # print("00获取所有闹钟信息:{}".format(alarm_list))
+ # EventMesh.debug_log("00获取所有闹钟信息:{}".format(alarm_list))
new_alarm_list = [(alarm['hour'], alarm['minute'], alarm['days'],alarm["idx"]) for alarm in alarm_list if alarm['enabled']]
- print("01获取开启的闹钟:{}".format(new_alarm_list))
+ EventMesh.debug_log("01获取开启的闹钟:{}".format(new_alarm_list))
start_day = 0 # 周日
start_minute = 0 # 0点
end_minute = 60*24*7
minute_list = []
if not new_alarm_list:
- print("02当前并没有开启的闹钟,退出闹钟设置程序:{}".format(new_alarm_list))
+ EventMesh.debug_log("02当前并没有开启的闹钟,退出闹钟设置程序:{}".format(new_alarm_list))
self.rtc.enable_alarm(0)
return
#如果当前时间没超过闹钟设置时间,则设置为今天,否则设置为明天
if (hour*60 + minute) > (rtc_now_time[4]*60 + rtc_now_time[5]):
minute_list.append(hour*60 + minute + (rtc_now_time[3]-start_day)*24*60)
- print("设置单次闹钟:{}".format(new_alarm_list))
+ EventMesh.debug_log("设置单次闹钟:{}".format(new_alarm_list))
else:
minute_list.append(hour*60 + minute + (rtc_now_time[3]-start_day+1)*24*60)
total_minutes = sorted(minute_list)
- print("02以周日00:00为起点,计算所有开启闹钟的total_min并排序:{}".format(total_minutes))
+ EventMesh.debug_log("02以周日00:00为起点,计算所有开启闹钟的total_min并排序:{}".format(total_minutes))
#获取当前时间 (2020, 9, 11, 5, 15, 43, 23, 0)
# rtc_now_time = (2020, 9, 11, 6, 11, 43, 23, 0)
# rtc_now_time = self.rtc.datetime()
- print("03当前的rtc时间:{}".format(rtc_now_time))
+ EventMesh.debug_log("03当前的rtc时间:{}".format(rtc_now_time))
current_minute = rtc_now_time[4]*60 + rtc_now_time[5] + (rtc_now_time[3]-start_day)*24*60
- print("04当前的rtc_total_minutes:{}".format(current_minute))
+ EventMesh.debug_log("04当前的rtc_total_minutes:{}".format(current_minute))
if current_minute in minute_list:
- print("当前时间和闹钟列表时间重复,删除重复的时间")
+ EventMesh.debug_log("当前时间和闹钟列表时间重复,删除重复的时间")
minute_list.remove(current_minute)
minute_list.append(current_minute)
minute_list = sorted(minute_list)
current_index = minute_list.index(current_minute)
- print("05将当前时间插入min_list后的min_list:{}".format(minute_list))
- print("06当前时间所在位置:{}".format(current_index))
+ EventMesh.debug_log("05将当前时间插入min_list后的min_list:{}".format(minute_list))
+ EventMesh.debug_log("06当前时间所在位置:{}".format(current_index))
next_index = current_index + 1
if next_index >= len(minute_list):
next_minute = minute_list[0]
- print("0744下一个闹钟的分钟数:", next_minute)
+ EventMesh.debug_log("0744下一个闹钟的分钟数:", next_minute)
else:
next_minute = minute_list[next_index]
- print("0744下一个闹钟的分钟数:", next_minute)
+ EventMesh.debug_log("0744下一个闹钟的分钟数:", next_minute)
if next_minute >= current_minute:
interval_minute = next_minute - current_minute
- print("08666距离下一次响铃的的分钟数:", interval_minute)
+ EventMesh.debug_log("08666距离下一次响铃的的分钟数:", interval_minute)
else:
#7*60*24 7天一个周期 7*60*24 -
interval_minute = end_minute - current_minute + next_minute
- print("08888距离下一次响铃的的分钟数:", interval_minute)
+ EventMesh.debug_log("08888距离下一次响铃的的分钟数:", interval_minute)
#反向获取时间戳
time = utime.localtime()
- print("09获取utime的时间戳:", time)
+ EventMesh.debug_log("09获取utime的时间戳:", time)
rtc_mktime = utime.mktime(time)
- print("10反向获取utime的mktime:", rtc_mktime)
+ EventMesh.debug_log("10反向获取utime的mktime:", rtc_mktime)
#加上下一次响铃需要的时间
next_alarm_mktime = rtc_mktime + interval_minute*60
- print("11下一次响铃的mktime:", next_alarm_mktime)
+ EventMesh.debug_log("11下一次响铃的mktime:", next_alarm_mktime)
#格式化时间戳,得到下一次闹钟的时间
next_alarm_time = utime.localtime(next_alarm_mktime)
- print("12下一次响铃的准确时间:", next_alarm_time)
+ EventMesh.debug_log("12下一次响铃的准确时间:", next_alarm_time)
#将时间转换为rtc的格式
data_l = [2021, 7, 9, 5, 12, 30, 0, 0]
#给rtc时间赋值
data_l[5] = next_alarm_time[4] #minute
#转换为元组
data_e=tuple(data_l)
- print("13将该时间转换为RTC元组:", data_e)
+ EventMesh.debug_log("13将该时间转换为RTC元组:", data_e)
for alarm in alarm_list:
if not alarm["days"] and alarm["enabled"]:
- print("关闭666:",alarm["idx"])
+ EventMesh.debug_log("关闭666:",alarm["idx"])
if alarm["hour"] == data_l[4] and alarm["minute"]==data_l[5]:
self.idx = alarm["idx"]
#设置rtc闹钟时间
FLAG = self.rtc.set_alarm(data_e)
if FLAG == 0:
- print("14成功设置rtc的到期时间:", data_e)
+ EventMesh.debug_log("14成功设置rtc的到期时间:", data_e)
else:
- print("14设置rtc的到期时间失败:", data_e)
+ EventMesh.debug_log("14设置rtc的到期时间失败:", data_e)
self.rtc.enable_alarm(1)