self.PING = "0" #绑定状态
self.connect = 0 #服务器连接状态
self.KA_time = 0
+ self.HR_time = 0
+ self.SENSOR_time = 0
+ self.HR_state = 0
+ self.spo2_state = 0
+ self.g_hr_spo2_priority = 0
+
self.UD_time = 0
self.UD_timeout = 7*60
print("DeviceInfoManager:1")
self.UD_time = time_tmp
EventMesh.publish(constants.EVENT.START_LOCATION) #开始定位
EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
- #self.timer_push_tmp = self.timer_push_tmp+1
+
+ hr_time = EventMesh.publish("get_hr_spo2_time")#获取时间是否大于0
+
+
+ get_hr_state = EventMesh.publish("get_hr_state")
+ get_spo2_state = EventMesh.publish("get_spo2_state")
+ if hr_time > 0:
+ if get_hr_state != 1 and get_spo2_state != 1:
+ print("time_tmp :{} self.SENSOR_time :{} self.HR_state:{}".format(time_tmp,self.SENSOR_time,self.HR_state))
+ if math.fabs(time_tmp - self.SENSOR_time) >= hr_time and self.HR_state == 0:
+ print("START_HEART:1")
+ EventMesh.publish("set_hr_state",2)#2代表后台进入测试
+ # EventMesh.publish(constants.EVENT.START_HEART)
+ self.HR_state = 1
+ elif math.fabs(time_tmp - self.SENSOR_time) >= (hr_time+60) and self.HR_state == 1:
+ EventMesh.publish("set_hr_state",0)#2代表后台进入测试
+ EventMesh.publish(constants.EVENT.STOP_HEART)
+ #获取心率数据上传数据app
+ print("STOP_HEART:")
+ EventMesh.publish("set_spo2_state",2)#2代表后台进入血氧测试
+ # EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
+ print("START_BLOOD_OXYGEN:")
+ self.HR_state = 2
+ elif math.fabs(time_tmp - self.SENSOR_time) >= (hr_time+120) and self.HR_state == 2:
+ print("STOP_BLOOD_OXYGEN:")
+ EventMesh.publish("set_spo2_state",0)#2代表后台进入血氧测试
+ # EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#停止血氧测试
+ self.HR_state = 0
+ self.SENSOR_time = time_tmp
+ else:
+ self.SENSOR_time = time_tmp
+ self.HR_state = 0
+ else:
+ self.SENSOR_time = time_tmp#进入最后一次的时间戳
+ if get_hr_state != 1 or get_spo2_state != 1:#
+ if get_hr_state == 2 and self.HR_state == 1:#自动检测的心率还在测量立马关了测试
+ # EventMesh.publish(constants.EVENT.STOP_HEART)
+ self.HR_state = 0
+ elif get_spo2_state ==2 and self.HR_state == 2:
+ self.HR_state = 0
+ # EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)
+ else:
+ self.HR_state = 0
+
+
+
+
+
+ # if hr_time > 0:
+ # if (time_tmp % 60) == 0:#每一分钟进入一次
+ # self.HR_time+=1
+ # get_hr_state = EventMesh.publish("get_hr_state")
+ # get_spo2_state = EventMesh.publish("get_spo2_state")
+ # if get_hr_state != 1 and get_spo2_state != 1:
+ # if self.HR_time >= 5 and self.HR_state == 0:
+ # if self.HR_state == 0:#先测试心率 后测试血氧数据
+ # EventMesh.publish(constants.EVENT.START_HEART)
+ # self.HR_state = 1
+ # elif self.HR_state == 1:#关闭心率测试血氧
+ # EventMesh.publish(constants.EVENT.STOP_HEART)
+ # #获取心率数据上传数据app
+ # if get_hr_state != 1 and get_spo2_state != 1:
+ # EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN)#K开血氧
+ # self.HR_state = 2
+ # elif self.HR_state == 2:
+ # EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN)#停止血氧测试
+ # self.HR_state = 0
+ # self.HR_time = 0
voiceCall.setCallback(voice_callback)
: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])))
def stop_heart(self, topic, msg):
print("stop_heart!!!")
self.hsensor.close()
+
def get_blood_oxygen(self, topic, msg):
data = self.hsensor.get_all_data()
from ext import constants
import osTimer
import utime
-
+from machine import RTC
#-------------------------------------weather-----------------#
# weather_screen = lv.obj()
# weather = lv.obj(weather_screen)
# def btn8_press(self):
# EventMesh.publish("load_screen", {"screen": "watchface"})
-class REMIND_ProtoCol(ProtoCol):
- """闹钟数据"""
- TYPE = "REMIND"
+
+
+
+
+# class REMIND_ProtoCol(ProtoCol):
+# """闹钟数据"""
+# TYPE = "REMIND"
+
+
+# def send(self, event, msg):
+# # [SZKW*867387060319491*0008*REMIND]
+# send_data = "SZKW*%s*003*REMIND"%(self.imei)
+# MD5_SIGN = self.pack_MD5_head(send_data)
+# data = "[%s%s]"%(str(MD5_SIGN),send_data)
+# # print("REMIND_ProtoCol:send:%s"%(data))
+# # 通过socket发送到服务器端
+# EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+
+# def recv(self, event, msg):
+# """
+# @param event: 闹钟数据下发
+# @param msg: 接收到的下行数据
+# """
+# # b'SZKW*860132060004322*0035*REMIND,23-04-06,14:41:06,b6e0d4c6,1,27,-1,40,6DF157335E02'
+# # print("REMIND_ProtoCol RECV msg:%s"%(msg))
+# self.alarm_list = []
+
+# msg = msg[1:-1]
+# msg_tmp = msg.decode('ascii')
+# msg_tmp = msg_tmp.split('REMIND,')
+# msg_tmp = msg_tmp[1]
+# num = 0
+# j=0
+# for j in range(0,3):
+# self.alarm_day = []
+# self.alarm_week = []
+# self.alarm_total_data = []
+# self.alarm_total_data = msg_tmp.split(',')[j]
+
+# b = self.alarm_total_data.find('-')
+# if b != -1:
+# alarm_data = self.alarm_total_data.split('-')#-作为分隔符
+# alarm_switch = int(alarm_data[1])#开关
+# alarm_day_num = int(alarm_data[2])#天
+# alarm_time = alarm_data[0]#时间
+# alarm_time_tmp = alarm_time.split(':')#冒号分隔时间 时 分
+# alarm_time_hour = int(alarm_time_tmp[0])
+# alarm_time_min = int(alarm_time_tmp[1])
+# if alarm_day_num == 3:
+# self.alarm_week = alarm_data[3]#星期
+
+# if alarm_day_num == 2:#每一天
+# self.alarm_day = [1,2,3,4,5,6,0]
+# elif alarm_day_num == 3:#自定义
+# for i in range(0,7):
+# if self.alarm_week[i] != '0':
+# self.alarm_day.append(i)
+# self.alarm_list.append({"idx": num, "hour": alarm_time_hour, "minute": alarm_time_min, "days": self.alarm_day, "enabled": alarm_switch})
+# with open("/ext/static/storage_file/alarm_msg.json", 'w',encoding='utf-8') as fd:
+# ujson.dump(self.alarm_list,fd)
+# num+=1
+# if num >= 2:
+# num = 2
+# EventMesh.publish("push_update_alarm_show")
+# EventMesh.publish(constants.PROTOCOL.REMIND_SEND)
+
+#心率定时测量
+class hrTimeHandlerManager(Abstract):
+ def __init__(self):
+ super().__init__()
+ self.rtc = RTC()
+ self.timer = osTimer()
+ self.second = 0
+
+ def post_processor_after_instantiation(self):
+
+ date_tmp = utime.localtime()
+ time_tmp = utime.mktime(date_tmp)
+ self.second = time_tmp
+ # self.timer.start(1*1000,1,self._min_callback)
+
+
+ def _min_callback(self,args):
+ self.second+=1
+ date_tmp = utime.localtime()
+ time_tmp = utime.mktime(date_tmp)
+ rtc_now_time = self.rtc.datetime()
+ if (self.second % 60) == 0:
+ rtc_now_time = self.rtc.datetime()
+ print("hrTimeHandlerManager 当前的rtc时间:{}".format(rtc_now_time))
+
+ print("---!self.second!!!!---:{} time_tmp:{} rtc_now_time:{}".format(self.second,time_tmp,rtc_now_time))
+
+class HRSTART_ProtoCol(ProtoCol):
+ """心率数据"""
+ TYPE = "hrtstart"
def send(self, event, msg):
- # [SZKW*867387060319491*0008*REMIND]
- send_data = "SZKW*%s*003*REMIND"%(self.imei)
+ # [SZKW*867387060319491*0008*hrtstart]
+ send_data = "SZKW*%s*008*hrtstart"%(self.imei)
MD5_SIGN = self.pack_MD5_head(send_data)
data = "[%s%s]"%(str(MD5_SIGN),send_data)
- # print("REMIND_ProtoCol:send:%s"%(data))
+ # print("HRSTART_ProtoCol:send:%s"%(data))
# 通过socket发送到服务器端
- EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+ EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
def recv(self, event, msg):
"""
- @param event: 闹钟数据下发
+ @param event: 心率数据下发
@param msg: 接收到的下行数据
"""
# b'SZKW*860132060004322*0035*REMIND,23-04-06,14:41:06,b6e0d4c6,1,27,-1,40,6DF157335E02'
# print("REMIND_ProtoCol RECV msg:%s"%(msg))
- self.alarm_list = []
-
+ # HRSTART_ProtoCol RECV msg:b'SZKW*860132060004322*000D*hrtstart,7200' msg_:7200
msg = msg[1:-1]
msg_tmp = msg.decode('ascii')
- msg_tmp = msg_tmp.split('REMIND,')
+ msg_tmp = msg_tmp.split(',')
msg_tmp = msg_tmp[1]
- num = 0
- j=0
- for j in range(0,3):
- self.alarm_day = []
- self.alarm_week = []
- self.alarm_total_data = []
- self.alarm_total_data = msg_tmp.split(',')[j]
-
- b = self.alarm_total_data.find('-')
- if b != -1:
- alarm_data = self.alarm_total_data.split('-')#-作为分隔符
- alarm_switch = int(alarm_data[1])#开关
- alarm_day_num = int(alarm_data[2])#天
- alarm_time = alarm_data[0]#时间
- alarm_time_tmp = alarm_time.split(':')#冒号分隔时间 时 分
- alarm_time_hour = int(alarm_time_tmp[0])
- alarm_time_min = int(alarm_time_tmp[1])
- if alarm_day_num == 3:
- self.alarm_week = alarm_data[3]#星期
-
- if alarm_day_num == 2:#每一天
- self.alarm_day = [1,2,3,4,5,6,0]
- elif alarm_day_num == 3:#自定义
- for i in range(0,7):
- if self.alarm_week[i] != '0':
- self.alarm_day.append(i)
- self.alarm_list.append({"idx": num, "hour": alarm_time_hour, "minute": alarm_time_min, "days": self.alarm_day, "enabled": alarm_switch})
- with open("/ext/static/storage_file/alarm_msg.json", 'w',encoding='utf-8') as fd:
- ujson.dump(self.alarm_list,fd)
- num+=1
- if num >= 2:
- num = 2
- EventMesh.publish("push_update_alarm_show")
- EventMesh.publish(constants.PROTOCOL.REMIND_SEND)
+ # print("HRSTART_ProtoCol RECV msg:{} msg_:{}".format(msg,msg_tmp))
+ hrTotal = int(msg_tmp)
+ if hrTotal < 300 and hrTotal > 0:
+ hrTotal = 300
+
+
+ with open("/ext/static/storage_file/setHrTime.txt","w") as fd:
+ fd.write(str(hrTotal))
+ EventMesh.publish("set_time_hr_spo2",hrTotal)
+ EventMesh.publish(constants.PROTOCOL.HRTSTART_SEND)
+
+#设置和获取心率上传频率时间
+class getHrTimeManager(Abstract):
+ def __init__(self):
+ self.set_time = 0
+ self.set_hr = 0 #0关闭 1手动 2 自动测量按照时间间隔测试心率
+ self.set_spo2 = 0
+
+ def post_processor_after_instantiation(self):
+ EventMesh.subscribe("set_time_hr_spo2", self.set_hr_spo2_time)
+ EventMesh.subscribe("get_time_hr_spo2", self.get_hr_spo2_time)
+ 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 set_hr_spo2_time(self, event, msg):
+ self.set_time = msg
+
+ def get_hr_spo2_time(self, event, msg):
+ return self.set_time
+
+ def set_hr_state(self, event, msg):
+ self.set_hr = msg
+
+ def get_hr_state(self, event, msg):
+ return self.set_hr
+
+ def set_spo2_state(self, event, msg):
+ self.set_spo2 = msg
+
+ def get_spo2_state(self, event, msg):
+ return self.set_spo2
+
+
+# class OXSTART_ProtoCol(ProtoCol):
+# """血氧数据"""
+# TYPE = "oxstart"
+
+# def send(self, event, msg):
+# # [SZKW*867387060319491*0008*hrtstart]
+# send_data = "SZKW*%s*007*oxstart"%(self.imei)
+# MD5_SIGN = self.pack_MD5_head(send_data)
+# data = "[%s%s]"%(str(MD5_SIGN),send_data)
+# print("OXSTART__ProtoCol:send:%s"%(data))
+# # 通过socket发送到服务器端
+# EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+# def recv(self, event, msg):
+# """
+# @param event: 血氧设置频率数据下发
+# @param msg: 接收到的下行数据
+# """
+# msg = msg[1:-1]
+# msg_tmp = msg.decode('ascii')
+# msg_tmp = msg_tmp.split(',')
+# msg_tmp = msg_tmp[1]
+# print("OXSTART__ProtoCol RECV msg:{} msg_:{}".format(msg,msg_tmp))
+# spo2Total = int(msg_tmp)
+# if spo2Total < 300 and spo2Total > 0:
+# spo2Total = 300
+
+# with open("/ext/static/storage_file/setSpo2Time.txt","w") as fd:
+# fd.write(str(spo2Total))
+
+# EventMesh.publish(constants.PROTOCOL.OXSTART_SEND)
+
+
\ No newline at end of file