self.HR_time = 0
self.SENSOR_time = 0
self.HR_state = 0
- self.spo2_state = 0
- self.g_hr_spo2_priority = 0
-
+ self.hr_time = 0
+ self.old_time = 0
self.UD_time = 0
self.UD_timeout = 7*60
print("DeviceInfoManager:1")
EventMesh.publish(constants.EVENT.START_LOCATION) #开始定位
EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
- hr_time = EventMesh.publish("get_hr_spo2_time")#获取时间是否大于0
-
-
+ hr_time = EventMesh.publish("get_time_hr_spo2")#获取时间是否大于0
+ print("hr_time:{}".format(hr_time))
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
+
+ if hr_time != None:
+ if hr_time > 0:
+ if get_hr_state != 1 and get_spo2_state != 1:
+ print("self.old_time:{} hr_time:{}".format(self.old_time,hr_time))
+ if self.old_time != hr_time:
+ self.SENSOR_time = time_tmp#防止改变时间的时候正在开启测量突然10s就停止测量
+ 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)
+ self.old_time = hr_time
+
+
+ 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))
+ 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
- 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)
+ self.old_time = 0
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
+ self.SENSOR_time = time_tmp#进入最后一次的时间戳
+ self.old_time = 0
+ 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
voiceCall.setCallback(voice_callback)
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(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
+ check = ql_fs.path_exists("/ext/static/storage_file/setHrTime.txt")
+ if check == True:
+ with open("/ext/static/storage_file/setHrTime.txt","r") as fd:
+ time = fd.read()
+ self.set_time = int(time)
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_time_hr_spo2", self.set_time_hr_spo2)
+ EventMesh.subscribe("get_time_hr_spo2", self.get_time_hr_spo2)
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):
+ def set_time_hr_spo2(self, event, msg):
self.set_time = msg
- def get_hr_spo2_time(self, event, msg):
+ def get_time_hr_spo2(self, event, msg):
+ print("self.set_time:".format(self.set_time))
return self.set_time
-
+
def set_hr_state(self, event, msg):
self.set_hr = msg
def get_hr_state(self, event, msg):
+ print("self.set_hr:".format(self.set_hr))
return self.set_hr
def set_spo2_state(self, event, msg):
self.set_spo2 = msg
def get_spo2_state(self, event, msg):
+ print("self.set_spo2:".format(self.set_spo2))
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