From: d15521469561 Date: Tue, 11 Apr 2023 01:18:42 +0000 (+0800) Subject: 增加心率上传频率协议对接 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=fbde4eb183929faef40944e6ad47e54d623a7763;p=mirrors%2FASR1603_G5.git 增加心率上传频率协议对接 --- diff --git a/3.code/1.watch/2.code/alarm.py b/3.code/1.watch/2.code/alarm.py index e413a979..85017968 100644 --- a/3.code/1.watch/2.code/alarm.py +++ b/3.code/1.watch/2.code/alarm.py @@ -409,6 +409,7 @@ class ClockManager(Abstract): EventMesh.subscribe("add_alarm", self.add_alarm) EventMesh.subscribe("remove_alarm", self.remove_alarm) EventMesh.subscribe("set_rtc_alarm", self.set_rtc_alarm) + print("ClockManager = ........") def set(self, event, msg): global alarm_list @@ -595,9 +596,13 @@ class ClkListScreen(Screen): def update_show_info(self,event,msg): EventMesh.publish("read_alarminjson") - self.timer.start(1*1000,0,self.alarm_draw_btn) + self.timer.start(1*1000,0,self.delay_update) + def delay_update(self,*agrs): + EventMesh.publish("set_rtc_alarm") + self.alarm_draw_btn() + - def alarm_draw_btn(self,*agrs): + def alarm_draw_btn(self): global alarm_list self.clock_list = alarm_list IFEXIST = ql_fs.path_exists("/ext/static/storage_file/alarm_msg.json") diff --git a/3.code/1.watch/2.code/constants.py b/3.code/1.watch/2.code/constants.py index 76082ce6..8131117e 100644 --- a/3.code/1.watch/2.code/constants.py +++ b/3.code/1.watch/2.code/constants.py @@ -35,6 +35,13 @@ class PROTOCOL: REMIND_SEND = "REMIND_SEND" REMIND_RECV = "REMIND_RECV" + HRTSTART_SEND = "hrtstart_SEND" + HRTSTART_RECV = "hrtstart_RECV" + + OXSTART_SEND = "oxstart_SEND" + OXSTART_RECV = "oxstart_RECV" + + class EVENT: CHANNEL_SOCKET_SEND = "CHANNEL_SOCKET_SEND" diff --git a/3.code/1.watch/2.code/lcd.py b/3.code/1.watch/2.code/lcd.py index 20f8c821..3108cd16 100644 --- a/3.code/1.watch/2.code/lcd.py +++ b/3.code/1.watch/2.code/lcd.py @@ -145,7 +145,7 @@ gpio_backlight.write(0) LCD_SIZE_W = 240 LCD_SIZE_H = 320 - +# pwm.close() # 初始化lvgl lv.init() @@ -224,6 +224,6 @@ power_on_label.align(lv.ALIGN.CENTER, 0, 0) power_on_label.add_style(style_font_youyuan_40, lv.PART.MAIN | lv.STATE.DEFAULT) print("power_on_screen init...") lv.scr_load(power_on_screen) -#utime.sleep_ms(2000) +utime.sleep_ms(1000) print("power_on_screen end...") gpio_backlight.write(1) diff --git a/3.code/1.watch/2.code/main.py b/3.code/1.watch/2.code/main.py index 2027e442..6bf13abb 100644 --- a/3.code/1.watch/2.code/main.py +++ b/3.code/1.watch/2.code/main.py @@ -59,7 +59,7 @@ if __name__ == '__main__': from ext.ui_main_menu import MainMenuScreen from ext.appWechat import WechatScreen,TK_ProtoCol,MESSAGE_ProtoCol import ext.ui_setting as _ui_setting - # from usr.test_sms import REMIND_ProtoCol + from usr.test_sms import hrTimeHandlerManager #from usr.ui_wechat import WechatScreen,TK_ProtoCol btn_device = BtnDevice(tp_cst816) @@ -146,6 +146,7 @@ if __name__ == '__main__': app.append_manager(PhoneCallingManager()) app.append_manager(ClockManager()) app.append_manager(getOldHrDataManager()) + app.append_manager(hrTimeHandlerManager()) pcr = ProtoColResolver() pcr.add_support(LK_ProtoCol()) diff --git a/3.code/1.watch/2.code/main_1.py b/3.code/1.watch/2.code/main_1.py index 2027e442..d10bc1e9 100644 --- a/3.code/1.watch/2.code/main_1.py +++ b/3.code/1.watch/2.code/main_1.py @@ -59,7 +59,7 @@ if __name__ == '__main__': from ext.ui_main_menu import MainMenuScreen from ext.appWechat import WechatScreen,TK_ProtoCol,MESSAGE_ProtoCol import ext.ui_setting as _ui_setting - # from usr.test_sms import REMIND_ProtoCol + from usr.test_sms import hrTimeHandlerManager,HRSTART_ProtoCol,getHrTimeManager #from usr.ui_wechat import WechatScreen,TK_ProtoCol btn_device = BtnDevice(tp_cst816) @@ -146,6 +146,8 @@ if __name__ == '__main__': app.append_manager(PhoneCallingManager()) app.append_manager(ClockManager()) app.append_manager(getOldHrDataManager()) + app.append_manager(hrTimeHandlerManager()) + app.append_manager(getHrTimeManager()) pcr = ProtoColResolver() pcr.add_support(LK_ProtoCol()) @@ -160,6 +162,8 @@ if __name__ == '__main__': pcr.add_support(MESSAGE_ProtoCol()) pcr.add_support(WT_ProtoCol()) pcr.add_support(REMIND_ProtoCol()) + pcr.add_support(HRSTART_ProtoCol()) + # pcr.add_support(OXSTART__ProtoCol()) sm = SockManager() sm.add_support_resolver(pcr) app.append_manager(sm) diff --git a/3.code/1.watch/2.code/mgr.py b/3.code/1.watch/2.code/mgr.py index b1742042..e0b349da 100644 --- a/3.code/1.watch/2.code/mgr.py +++ b/3.code/1.watch/2.code/mgr.py @@ -523,6 +523,12 @@ class DeviceInfoManager(Abstract): 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") @@ -614,7 +620,74 @@ class DeviceInfoManager(Abstract): 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) @@ -684,7 +757,7 @@ class DeviceInfoManager(Abstract): :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]))) @@ -840,6 +913,7 @@ class DeviceInfoManager(Abstract): 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() diff --git a/3.code/1.watch/2.code/protocol.py b/3.code/1.watch/2.code/protocol.py index 055746a8..d9682721 100644 --- a/3.code/1.watch/2.code/protocol.py +++ b/3.code/1.watch/2.code/protocol.py @@ -520,7 +520,7 @@ class REMIND_ProtoCol(ProtoCol): def send(self, event, msg): # [SZKW*867387060319491*0008*REMIND] - send_data = "SZKW*%s*003*REMIND"%(self.imei) + send_data = "SZKW*%s*006*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)) diff --git a/3.code/1.watch/2.code/test_sms.py b/3.code/1.watch/2.code/test_sms.py index 3af2f46e..bca30a2f 100644 --- a/3.code/1.watch/2.code/test_sms.py +++ b/3.code/1.watch/2.code/test_sms.py @@ -13,7 +13,7 @@ from ext.protocol import ProtoCol,UnicodeHexStr_To_Utf8Str from ext import constants import osTimer import utime - +from machine import RTC #-------------------------------------weather-----------------# # weather_screen = lv.obj() # weather = lv.obj(weather_screen) @@ -150,65 +150,201 @@ import utime # 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 diff --git a/3.code/1.watch/2.code/ui.py b/3.code/1.watch/2.code/ui.py index ffbc3e06..6f02b7aa 100644 --- a/3.code/1.watch/2.code/ui.py +++ b/3.code/1.watch/2.code/ui.py @@ -1740,6 +1740,7 @@ class HeartrateScreen(Screen): heartrate_done_label.set_text(" ") heartrate_bpm_label.set_text(" ") heartrate_start_label.set_text("正在测量中.") + EventMesh.publish("set_hr_state",1)#1代表手动进入测试界面 EventMesh.publish(constants.EVENT.START_HEART) @@ -1776,10 +1777,12 @@ class HeartrateScreen(Screen): self.timer.stop() self.point = 0 + EventMesh.publish("set_hr_state",0)#0代表关闭测试 EventMesh.publish(constants.EVENT.STOP_HEART) def Close(self): self.timer.stop() + EventMesh.publish("set_hr_state",0)#0代表关闭测试 EventMesh.publish(constants.EVENT.STOP_HEART) def done_return(self): @@ -2550,6 +2553,7 @@ class Spo2Screen(Screen): self.point = 0 self.spo2_value = 0 self.timer.start(1*1000, 1, self.start_measure) + EventMesh.publish("set_spo2_state",1)#2代表后台进入血氧测试 EventMesh.publish(constants.EVENT.START_BLOOD_OXYGEN) self.last_spo2_value = EventMesh.publish("get_old_spo2_data") spo2_label.set_text("--%") @@ -2597,11 +2601,13 @@ class Spo2Screen(Screen): self.timer.stop() self.point = 0 + EventMesh.publish("set_spo2_state",0)#0代表关闭测试 EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN) # spo2_last_time.set_text() def Close(self): self.timer.stop() + EventMesh.publish("set_spo2_state",0)#0代表关闭测试 EventMesh.publish(constants.EVENT.STOP_BLOOD_OXYGEN) def done_return(self):