From: dxy15521469561 <1731678236@qq.com> Date: Sat, 9 Dec 2023 09:37:52 +0000 (+0800) Subject: D10: X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=7b76a0cf3a1f11987ac87eca00940a3b4415fc79;p=mirrors%2FASR1603_G5.git D10: 需求增加 --- diff --git a/2.sdk/project/C06S/sdk/services/microPython/ports/quectel/core/ui_health.py b/2.sdk/project/C06S/sdk/services/microPython/ports/quectel/core/ui_health.py index b36730e2..ab4bfd70 100644 --- a/2.sdk/project/C06S/sdk/services/microPython/ports/quectel/core/ui_health.py +++ b/2.sdk/project/C06S/sdk/services/microPython/ports/quectel/core/ui_health.py @@ -422,10 +422,14 @@ class TemperatureScreen(Screen): sort_new = sorted(read_data, key = lambda i: i['timeSec'],reverse = False)#按照时间戳进行排序 去掉最旧的一次数据如果满了五 count = len(sort_new) if count != 0: + for i in range(count): - print(int(sort_new[i]["temp"])) - print("hr history read_data",read_data) + # print(int(sort_new[i]["temp"])) + # print("hr history read_data",read_data) value_float = sort_new[i]["temp"] + if value_float <= 0: + value_float = 0 + value = 0 value_dot = 0 line_value = 0 @@ -439,7 +443,8 @@ class TemperatureScreen(Screen): value_temp = int(value) print("value_float <",value_float,value,value_dot,value_temp) if value_float <= 30: - line_value = int(value_temp)*0.5+15 + print("value_float < 34") + line_value = int(value_temp*1) elif value_float <= 34: print("value_float < 34") line_value = int((value_temp-30)*4.25)+30 @@ -488,6 +493,7 @@ class TemperatureScreen(Screen): if line_value >= 100: line_value = 100 print("temp line_value",line_value) + line_value = int(line_value) temp_line_points = [{"x":0,"y":0},{"x":0,"y":line_value}] if i == 0: temp_line1.set_points(temp_line_points,2) diff --git a/2.sdk/project/D10/audio.bin b/2.sdk/project/D10/audio.bin index 65b68310..c28c3d9d 100644 Binary files a/2.sdk/project/D10/audio.bin and b/2.sdk/project/D10/audio.bin differ diff --git a/2.sdk/project/D10/audio/R_FALL_ALARM.mp3 b/2.sdk/project/D10/audio/R_FALL_ALARM.mp3 index 329f4e69..96381f61 100644 Binary files a/2.sdk/project/D10/audio/R_FALL_ALARM.mp3 and b/2.sdk/project/D10/audio/R_FALL_ALARM.mp3 differ diff --git a/2.sdk/project/D10/audio/R_HOME_ALARM.mp3 b/2.sdk/project/D10/audio/R_HOME_ALARM.mp3 new file mode 100644 index 00000000..38f676dd Binary files /dev/null and b/2.sdk/project/D10/audio/R_HOME_ALARM.mp3 differ diff --git a/2.sdk/project/D10/audio/R_RESET_ALARM.mp3 b/2.sdk/project/D10/audio/R_RESET_ALARM.mp3 new file mode 100644 index 00000000..fc44cba9 Binary files /dev/null and b/2.sdk/project/D10/audio/R_RESET_ALARM.mp3 differ diff --git a/2.sdk/project/D10/audio/R_RESET_END_ALARM.mp3 b/2.sdk/project/D10/audio/R_RESET_END_ALARM.mp3 new file mode 100644 index 00000000..afb29db4 Binary files /dev/null and b/2.sdk/project/D10/audio/R_RESET_END_ALARM.mp3 differ diff --git a/2.sdk/project/D10/audio/R_SLEEP_ALARM.mp3 b/2.sdk/project/D10/audio/R_SLEEP_ALARM.mp3 new file mode 100644 index 00000000..ed0019a5 Binary files /dev/null and b/2.sdk/project/D10/audio/R_SLEEP_ALARM.mp3 differ diff --git a/2.sdk/project/D10/audio/R_WAKEUP_ALARM.mp3 b/2.sdk/project/D10/audio/R_WAKEUP_ALARM.mp3 new file mode 100644 index 00000000..c30fe7ee Binary files /dev/null and b/2.sdk/project/D10/audio/R_WAKEUP_ALARM.mp3 differ diff --git a/2.sdk/project/D10/list.json b/2.sdk/project/D10/list.json index a314d60c..be59b774 100644 --- a/2.sdk/project/D10/list.json +++ b/2.sdk/project/D10/list.json @@ -1 +1 @@ -['audio_find_haixiu', 'R_ALARM_NEW', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_WECHAT_RECV'] \ No newline at end of file +['audio_find_haixiu', 'R_ALARM_NEW', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HOME_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_RESET_ALARM', 'R_RESET_END_ALARM', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SLEEP_ALARM', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_WAKEUP_ALARM', 'R_WECHAT_RECV'] \ No newline at end of file diff --git a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py index 288cb4a3..bafb0132 100644 --- a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py +++ b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/btn_device_ec800m.py @@ -26,9 +26,7 @@ def open_motor(): def close_motor(): motor_pin.write(0) -audio_buf = ['audio_find_haixiu', 'R_ALARM_NEW', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_WECHAT_RECV'] - - +audio_buf = ['audio_find_haixiu', 'R_ALARM_NEW', 'R_CALL_mp3', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_DRINK_ALARM', 'R_FALL_ALARM', 'R_HOME_ALARM', 'R_HSENSOR_RESULT_FAILE', 'R_HSENSOR_RESULT_HR_TITLE', 'R_HSENSOR_RESULT_OK', 'R_HSENSOR_SPO2_TITLE', 'R_HSENSOR_TEMP_TITLE', 'R_MEDICINE_ALARM', 'R_NO_SET_SOS_DIAL', 'R_NO_SIM', 'R_POWER_OFF_1', 'R_READ_STEP_0', 'R_READ_STEP_1', 'R_READ_STEP_2', 'R_READ_STEP_3', 'R_READ_STEP_4', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_MIN', 'R_READ_TIME_ZHENG', 'R_RESET_ALARM', 'R_RESET_END_ALARM', 'R_SIM_CONNECT', 'R_SIM_FAILE', 'R_SLEEP_ALARM', 'R_SOS_ALERT', 'R_TSENSOR_RESULT_VALUE_DOT', 'R_UNREAD_WECHAT', 'R_WAKEUP_ALARM', 'R_WECHAT_RECV'] class call: CALL_OUT = 1 CALL_IN = 2 @@ -42,8 +40,17 @@ class intervManager(Abstract): self.pwk_timer1 = osTimer() self.pwk_timer2 = osTimer() self.timer1 = osTimer() - self.timer1_sos = osTimer() + self.sos_timer2 = osTimer() self.sos_timer1 = osTimer() + + self.fall_timer1 = osTimer() + self.fall_timer2 = osTimer() + + self.alarm_timer1 = osTimer() + + self.find_timer1 = osTimer() + self.fall_flag = 0 + self.aud = audio.Audio(0) self.aud.set_pa(Pin.GPIO29) self.aud.setVolume(11) @@ -110,6 +117,7 @@ class intervManager(Abstract): self.sos_phone_num = '' self.msg_tmp = "" self.time_count = 0 + self.alarm_count = 0 self.audio_int = 0 check_txt = ql_fs.path_exists("/usr/static/storage_file/wechat_record.json") @@ -195,40 +203,376 @@ class intervManager(Abstract): EventMesh.subscribe("sos_short_press", self.sos_short_press)#sos短按事件 + EventMesh.subscribe("falldown_alarm_event", self.falldown_alarm_event)#休息结束了 + EventMesh.subscribe("drink_alarm_event", self.drink_alarm_event)#该喝水了 EventMesh.subscribe("medicine_alarm_event", self.medicine_alarm_event)#该吃药了 + EventMesh.subscribe("wakeup_alarm_event", self.wakeup_alarm_event)#该起床了 + + EventMesh.subscribe("home_alarm_event", self.home_alarm_event)#该回家了 + + EventMesh.subscribe("sleep_alarm_event", self.sleep_alarm_event)#该睡觉了 + + EventMesh.subscribe("reset_alarm_event", self.reset_alarm_event)#该休息了 + + EventMesh.subscribe("reset_end_alarm_event", self.reset_end_alarm_event)#休息结束了 + + EventMesh.subscribe("get_fall_down_state", self.get_fall_down_state)#跌倒报警标识 + + + def interInfo_queue_thread(self): + while True: + data = self.interInfo_queue.get() + #EventMesh.debug_log("interInfo_queue_thread:data = {}".format(data)) + if data != None: + try: + data["func"](data["data"]) + except Exception as e: + EventMesh.debug_log("interInfo_queue_thread:ERROR:{}".format(e)) + usys.print_exception(e) + + def publish_message_event_interInfo(self,event,msg): + self.interInfo_queue.put(msg) + + def publish_call_event_cb(self, *args, **kwargs):#拨打电话 + EventMesh.publish("publish_message_event_interInfo",{"func":self.call_timer_cb,"data":0}) + + def publish_resatrt_down_event_cb(self, *args, **kwargs):#重启设备 + EventMesh.publish("publish_message_event_interInfo",{"func":self.powe_resatrt_down_fun,"data":0}) + + def publish_power_down_event_cb(self, *args, **kwargs):#关机 + EventMesh.publish("publish_message_event_interInfo",{"func":self.power_down_fun,"data":0}) + + def publish_find_watch_event_cb(self, *args, **kwargs):#查找设备 + EventMesh.publish("publish_message_event_interInfo",{"func":self.FIND_timer_cb,"data":0}) + + def publish_alarm_ring_event_cb(self, *args, **kwargs):#闹钟响铃 + EventMesh.publish("publish_message_event_interInfo",{"func":self.Alarm_timer_cb,"data":0}) + + def publish_reset_alarm_ring_event_cb(self, *args, **kwargs):#休息响铃 + EventMesh.publish("publish_message_event_interInfo",{"func":self.reset_alarm_event_cb,"data":0}) + + def publish_reset_end_alarm_ring_event_cb(self, *args, **kwargs):#休息结束响铃 + EventMesh.publish("publish_message_event_interInfo",{"func":self.reset_end_alarm_event_cb,"data":0}) + def publish_sleep_alarm_ring_event_cb(self, *args, **kwargs):#睡觉响铃 + EventMesh.publish("publish_message_event_interInfo",{"func":self.sleep_alarm_event_cb,"data":0}) + + def publish_home_ring_event_cb(self, *args, **kwargs):#回家响铃 + EventMesh.publish("publish_message_event_interInfo",{"func":self.home_alarm_event_cb,"data":0}) + + def publish_wakeup_ring_event_cb(self, *args, **kwargs):#起床响铃 + EventMesh.publish("publish_message_event_interInfo",{"func":self.wakeup_alarm_event_cb,"data":0}) + + def publish_medicine_ring_event_cb(self, *args, **kwargs):#吃药响铃 + EventMesh.publish("publish_message_event_interInfo",{"func":self.medicine_alarm_event_cb,"data":0}) + + def publish_drink_ring_event_cb(self, *args, **kwargs):#喝水响铃 + EventMesh.publish("publish_message_event_interInfo",{"func":self.drink_alarm_event_cb,"data":0}) + + def publish_fall_done_ring_event_cb(self, *args, **kwargs):#跌倒提醒 + EventMesh.publish("publish_message_event_interInfo",{"func":self.falldown_alarm_cb,"data":0}) + + + def reset_alarm_event(self,args,msg):#该休息了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count = 0 + self.alarm_timer1.start(2000, 1, self.publish_reset_alarm_ring_event_cb) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_RESET_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + def reset_alarm_event_cb(self,args):#该休息了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count += 1 + if self.alarm_count >= 3: + self.alarm_count = 0 + self.alarm_timer1.stop() + return + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_RESET_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + else: + self.alarm_count = 0 + self.alarm_timer1.stop() + + def reset_end_alarm_event(self,args,msg):#休息结束了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count = 0 + self.alarm_timer1.start(2000, 1, self.reset_end_alarm_event_cb) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_RESET_END_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + + def reset_end_alarm_event_cb(self,args):#休息结束了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count += 1 + if self.alarm_count >= 3: + self.alarm_count = 0 + self.alarm_timer1.stop() + return + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_RESET_END_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + else: + self.alarm_count = 0 + self.alarm_timer1.stop() + + def sleep_alarm_event(self,args,msg):#该睡觉了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count = 0 + self.alarm_timer1.start(2000, 1, self.publish_sleep_alarm_ring_event_cb) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_SLEEP_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + def sleep_alarm_event_cb(self,args):#该睡觉了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count += 1 + if self.alarm_count >= 3: + self.alarm_count = 0 + self.alarm_timer1.stop() + return + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_SLEEP_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + else: + self.alarm_count = 0 + self.alarm_timer1.stop() + + + def home_alarm_event(self,args,msg):#该回家了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count = 0 + self.alarm_timer1.start(2000, 1, self.publish_home_ring_event_cb) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HOME_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + + def home_alarm_event_cb(self,args):#该回家了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count += 1 + if self.alarm_count >= 3: + self.alarm_count = 0 + self.alarm_timer1.stop() + return + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HOME_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + else: + self.alarm_count = 0 + self.alarm_timer1.stop() + + def wakeup_alarm_event(self,args,msg):#该起床了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count = 0 + self.alarm_timer1.start(2000, 1, self.publish_wakeup_ring_event_cb) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_WAKEUP_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + + def wakeup_alarm_event_cb(self,args):#该起床了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count += 1 + if self.alarm_count >= 3: + self.alarm_count = 0 + self.alarm_timer1.stop() + return + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_WAKEUP_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + else: + self.alarm_count = 0 + self.alarm_timer1.stop() + + def medicine_alarm_event(self,args,msg):#该吃药了 - - str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_MEDICINE_ALARM")) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count = 0 + self.alarm_timer1.start(2000, 1, self.publish_medicine_ring_event_cb) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_MEDICINE_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + + def medicine_alarm_event_cb(self,args):#该吃药了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count += 1 + if self.alarm_count >= 3: + self.alarm_count = 0 + self.alarm_timer1.stop() + return + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_MEDICINE_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + else: + self.alarm_count = 0 + self.alarm_timer1.stop() def drink_alarm_event(self,args,msg):#该喝水了 - - str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_DRINK_ALARM")) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count = 0 + self.alarm_timer1.start(2000, 1, self.publish_drink_ring_event_cb) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_DRINK_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 - def falldown_alarm_event(self,args,msg):#跌倒报警启动中提示 - - str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_FALL_ALARM")) - self.time_count = 0 - self.timer.start(500, 1, self.falldown_alarm_cb) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + + + def drink_alarm_event_cb(self,args):#该喝水了 + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0 and self.fall_flag == 0: + self.alarm_count += 1# 1 2 + if self.alarm_count >= 3: + self.alarm_count = 0 + self.alarm_timer1.stop() + return + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_DRINK_ALARM")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + else: + self.alarm_count = 0 + self.alarm_timer1.stop() + def falldown_alarm_event(self,args,msg):#跌倒报警启动中提示 + flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备 + wechat_state = EventMesh.publish("get_wechat_state") + if flag == 0 and wechat_state == 0: + EventMesh.publish("close_timer_all")# + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_FALL_ALARM")) + self.time_count = 0 + self.fall_flag = 0 + self.fall_timer1.stop() + self.fall_flag = 1 + self.fall_timer1.start(4000, 1, self.publish_fall_done_ring_event_cb) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 def falldown_alarm_cb(self,*args): - self.time_count+=1 - if self.time_count > 3: - self.time_count=0 - self.timer.stop() + wechat_state = EventMesh.publish("get_wechat_state") + if self.call_state == 0 and wechat_state == 0: + self.time_count+=1 + if self.time_count >= 5: + self.time_count = 0 + self.fall_timer1.stop() + EventMesh.publish_async("dial_sos_phone")#拨打sos号码 + return str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_FALL_ALARM")) EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 + else: + self.time_count = 0 + self.fall_timer1.stop() + + + + def send_find_watch(self, event, msg): #发送查找设备指令 + open_power = EventMesh.publish("get_power_on_state")#获取开机标识 + if open_power != None: + if open_power == 0: + return + power_off = EventMesh.publish("get_power_off_state")#获取开机标识 + if power_off != None: + if power_off == 1: + return + flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备 + wechat_state = EventMesh.publish("get_wechat_state") + if flag == 0 and wechat_state == 0 and self.fall_flag == 0: + EventMesh.publish("close_timer_all")# + self.find_state = 1 + self.FIND_timer_count = 0 + self.alarm_timer1.start(3000,1,self.publish_find_watch_event_cb) + EventMesh.publish("set_led_time_arg",[1,1,330,led_mode.LONG_LIGHT_GREEN,2,1,led_mode.OTHER_MEASURE_MODE])#測量成功 + # EventMesh.publish("set_led_time_arg",[1000,33000,1,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#设置参数 + str_data = 'mp3files={}.mp3'.format(audio_buf.index("audio_find_haixiu")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + + def stop_find_watch(self, event, msg): + if self.find_state == 1: + self.find_state = 0 + self.FIND_timer_count = 0 + # EventMesh.publish("stop_led_timer")#设置参数 + self.aud.stopPlayStream() #播放声音 + self.alarm_timer1.stop() + + def FIND_timer_cb(self, data): + flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备 + wechat_state = EventMesh.publish("get_wechat_state") + if flag == 0 and wechat_state == 0 and self.fall_flag == 0: + if self.find_state == 1: + # EventMesh.debug_log("self.FIND_timer_count:{}".format(self.FIND_timer_count)) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("audio_find_haixiu")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + self.FIND_timer_count += 1 + if self.FIND_timer_count > 10: #120秒30s + EventMesh.publish("STOP_FIND_WATCH") + else: + self.FIND_timer_count = 0 + self.alarm_timer1.stop() - + + def stop_FIND(self) : + self.alarm_timer1.stop() + + def send_alarm_ring(self, event, msg): #发送查找设备指令 + open_power = EventMesh.publish("get_power_on_state")#获取开机标识 + if open_power != None: + if open_power == 0: + return + power_off = EventMesh.publish("get_power_off_state")#获取开机标识 + if power_off != None: + if power_off == 1: + return + flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备 + wechat_state = EventMesh.publish("get_wechat_state") + if flag == 0 and wechat_state == 0 and self.fall_flag == 0: + EventMesh.publish("close_timer_all")# + self.alarm_state = 1 + self.alarm_timer_count = 0 + self.alarm_timer1.start(3000,1,self.publish_alarm_ring_event_cb) + # EventMesh.publish("set_led_time_arg",[1,1,330,led_mode.LONG_LIGHT_GREEN,2,1,led_mode.OTHER_MEASURE_MODE])#測量成功 + # EventMesh.publish("set_led_time_arg",[1000,33000,1,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#设置参数 + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_ALARM_NEW")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + + def stop_alarm_ring(self, event, msg): #停止闹钟响铃 + if self.alarm_state == 1: + self.alarm_state = 0 + self.alarm_timer_count = 0 + # EventMesh.publish("stop_led_timer")#设置参数 + self.aud.stopPlayStream() #停止播放 + self.alarm_timer1.stop() + + def Alarm_timer_cb(self, data): + flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备 + wechat_state = EventMesh.publish("get_wechat_state") + if flag == 0 and wechat_state == 0 and self.fall_flag == 0: + if self.alarm_state == 1: + # EventMesh.debug_log("self.alarm_timer_count:{}".format(self.alarm_timer_count)) + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_ALARM_NEW")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + self.alarm_timer_count += 1 + if self.alarm_timer_count > 15: #120秒30s + EventMesh.publish("STOP_ALARM_RING") + else: + self.alarm_timer_count = 0 + self.alarm_timer1.stop() + + def get_fall_down_state(self,event,msg): + return self.fall_flag def sos_short_press(self,args,msg): + self.fall_timer1.stop() + if self.fall_flag == 1:#跌倒标志 + self.fall_flag = 0 + self.sos_timer1.stop() + self.sos_timer2.stop() + if self.call_state != 0: + self.call_state = 0 + voiceCall.callEnd() + sos_flag = EventMesh.publish("get_sos_flag") + if sos_flag == 1: + self.call_state = 0 + EventMesh.publish("set_sos_flag",0) + EventMesh.publish("set_sos_num",0) + EventMesh.publish("set_hangup_mode",0) + EventMesh.publish("interup_call_event")#如果在电话中强制挂断电话 EventMesh.publish("close_audio_play")#强制关闭音频文件播放 EventMesh.publish("STOP_FIND_WATCH")#停止查找设备 @@ -237,7 +581,7 @@ class intervManager(Abstract): #播报当前时间 def recv_wechat_audio(self,event,str_data):#接收微聊语音播放 - if self.press_btn == 0: + if self.call_state == 0 and self.fall_flag == 0: str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_WECHAT_RECV")) EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 @@ -256,7 +600,7 @@ class intervManager(Abstract): def publish_message_event_audio(self,event,msg): self.audio_event_queue.put(msg) - def play_audio_file(self, *args, **kwargs):#拨打电话 + def play_audio_file(self, *args, **kwargs):#播放音频文件 # EventMesh.debug_log("args",args) EventMesh.publish("publish_message_event_audio",{"func":self.play_audio_file_do,"data":args[1]}) @@ -275,36 +619,9 @@ class intervManager(Abstract): - def interInfo_queue_thread(self): - while True: - data = self.interInfo_queue.get() - #EventMesh.debug_log("interInfo_queue_thread:data = {}".format(data)) - if data != None: - try: - data["func"](data["data"]) - except Exception as e: - EventMesh.debug_log("interInfo_queue_thread:ERROR:{}".format(e)) - usys.print_exception(e) - - def publish_message_event_interInfo(self,event,msg): - self.interInfo_queue.put(msg) - - def publish_call_event_cb(self, *args, **kwargs):#拨打电话 - EventMesh.publish("publish_message_event_interInfo",{"func":self.call_timer_cb,"data":0}) - - def publish_resatrt_down_event_cb(self, *args, **kwargs):#重启设备 - EventMesh.publish("publish_message_event_interInfo",{"func":self.powe_resatrt_down_fun,"data":0}) - - def publish_power_down_event_cb(self, *args, **kwargs):#关机 - EventMesh.publish("publish_message_event_interInfo",{"func":self.power_down_fun,"data":0}) - - def publish_find_watch_event_cb(self, *args, **kwargs):#查找设备 - EventMesh.publish("publish_message_event_interInfo",{"func":self.FIND_timer_cb,"data":0}) - def publish_alarm_ring_event_cb(self, *args, **kwargs):#闹钟响铃 - EventMesh.publish("publish_message_event_interInfo",{"func":self.Alarm_timer_cb,"data":0}) - def powe_resatrt_down_fun(self, *args): + def powe_resatrt_down_fun(self, *args):#重启设备 EventMesh.publish("close_led_pin") self.aud.stopPlayStream() Power.powerRestart() @@ -342,18 +659,28 @@ class intervManager(Abstract): self.aud.stopPlayStream() self.timer.stop() - + self.sos_timer2.stop() + self.sos_timer1.stop() + self.fall_timer1.stop() + self.fall_flag = 0 + self.alarm_timer1.stop() def answer_call_event(self, event, msg): # if self.call_state == 2: + sos_flag = EventMesh.publish("get_sos_flag") + if sos_flag == 1: + self.call_state = 0 + EventMesh.publish("set_sos_flag",0) + EventMesh.publish("set_sos_num",0) + EventMesh.publish("set_hangup_mode",0) EventMesh.publish("close_timer_all")# voiceCall.callAnswer() def set_call_state(self, event, msg): # self.call_state = msg - def dialin_call_event(self, event, msg): + def dialin_call_event(self, event, msg):#电话打进来 open_power = EventMesh.publish("get_power_on_state")#获取开机标识 if open_power != None: if open_power == 0: @@ -383,10 +710,6 @@ class intervManager(Abstract): return str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_CALL_mp3")) EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 - # EventMesh.publish("play_audio_file",str_data)#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - - - EventMesh.publish("get_phonebook_list") def dial_out_call_center_cb(self, event, msg):#电话拨出去 open_power = EventMesh.publish("get_power_on_state")#获取开机标识 @@ -406,7 +729,6 @@ class intervManager(Abstract): EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件 # EventMesh.publish("play_audio_file",str_data)#获取播放音频文件('U:/static/audio.bin',1,1,str_data) else: - self.phone_num = str(msg) self.timer1.start(2000, 0, self.time_out_phone) str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_SOS_ALERT")) @@ -427,6 +749,7 @@ class intervManager(Abstract): self.sos_phone_num = '' # EventMesh.debug_log("sos_out_call_center_cb",msg) if self.call_state == 0: + EventMesh.publish("close_timer_all")# if msg == None: str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_NO_SET_SOS_DIAL")) @@ -435,7 +758,7 @@ class intervManager(Abstract): else: self.sos_phone_num = msg self.sos_timer1.start(2000, 0, self.sos_call_out_phone) - self.timer1_sos.start(30000, 0, self.sos_time_out_phone) + self.sos_timer2.start(30000, 0, self.sos_time_out_phone) str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_SOS_ALERT")) EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件 @@ -458,18 +781,20 @@ class intervManager(Abstract): def interup_call_event(self, event, msg):#侧边金属按钮挂断来电 flag = EventMesh.publish("get_call_state") if flag == 2 or flag == 3:#电话通话中 或者呼叫中挂断中断 + self.call_state = 0 voiceCall.callEnd() def dialing_out_event(self, event, msg):#侧边金属按键挂断电话呼叫中 flag = EventMesh.publish("get_call_state") if flag == 1:#电话呼叫中 + self.call_state = 0 voiceCall.callEnd() def play_cur_step_event(self, event, msg): #msg 1 播放当前步数 flag = EventMesh.publish("get_call_state") - if flag != 2:#电话通话中 或者呼叫中挂断中断 + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 EventMesh.publish("close_timer_all")# step = EventMesh.publish("get_old_step_value") EventMesh.debug_log("step",step) @@ -748,7 +1073,7 @@ class intervManager(Abstract): self.usbState = msg str_buf = [1,1,10,led_mode.LONG_LIGHT_RED,4,2,led_mode.CHARGE_IN_MODE] EventMesh.publish("set_led_time_arg",str_buf)# - if flag == 3 or flag == 1 or flag == 0:#电话通话中 或者呼叫中挂断中断 + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 EventMesh.publish("close_timer_all")# self.aud.stop() self.aud.play(1,1,'U:/static/R_CHARGE_IN.mp3') @@ -763,7 +1088,7 @@ class intervManager(Abstract): # EventMesh.publish("set_led_time_arg",[0,1000,1,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.CHARGE_OUT_MODE])#測量成功 EventMesh.publish("set_led_time_arg",[1,1,0,led_mode.FLASH_LIGHT_GREEN,4,4,led_mode.CHARGE_OUT_MODE])#測量成功 EventMesh.debug_log("charge R_CHARGE_OUT") - if flag == 3 or flag == 1 or flag == 0:#电话通话中 或者呼叫中挂断中断 + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 EventMesh.publish("close_timer_all")# self.aud.stop() self.aud.play(1,1,'U:/static/R_CHARGE_OUT.mp3') @@ -777,7 +1102,7 @@ class intervManager(Abstract): EventMesh.debug_log("charge full") str_buf = [1,1,10,led_mode.LONG_LIGHT_GREEN,4,2,led_mode.CHARGE_FULL_MODE] EventMesh.publish("set_led_time_arg",str_buf)# - if flag == 3 or flag == 1 or flag == 0:#电话通话中 或者呼叫中挂断中断 + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 EventMesh.publish("close_timer_all")# str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_CHARGE_FULL")) EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) @@ -798,6 +1123,7 @@ class intervManager(Abstract): elif msg == 2: flag = EventMesh.publish("get_call_state") if flag != 0:#电话呼叫中 + self.call_state = 0 voiceCall.callEnd() step = EventMesh.publish("get_old_step_value") self.read_data = EventMesh.publish("get_storage_data") @@ -811,6 +1137,7 @@ class intervManager(Abstract): elif msg == 3: flag = EventMesh.publish("get_call_state") if flag != 0:#电话呼叫中 + self.call_state = 0 voiceCall.callEnd() self.aud.play(1,0,'U:/static/R_POWER_OFF_1.mp3') # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_POWER_OFF_1")) @@ -822,6 +1149,7 @@ class intervManager(Abstract): elif msg == 4: flag = EventMesh.publish("get_call_state") if flag != 0:#电话呼叫中 + self.call_state = 0 voiceCall.callEnd() EventMesh.publish("stop_led_timer")#设置参数 self.power_off = 1 @@ -837,6 +1165,7 @@ class intervManager(Abstract): elif msg == 5: flag = EventMesh.publish("get_call_state") if flag != 0:#电话呼叫中 + self.call_state = 0 voiceCall.callEnd() step = EventMesh.publish("get_old_step_value") self.read_data = EventMesh.publish("get_storage_data") @@ -849,8 +1178,8 @@ class intervManager(Abstract): self.pwk_timer1.start(3000,0,self.power_off_no_audio_cb)#不需要关机铃声 def fun(self,*argc): - self.aud.stopPlayStream() - Power.powerRestart() + self.aud.stopPlayStream() + Power.powerRestart() def power_on_cb(self, msg): #msg 开机标识 @@ -899,7 +1228,9 @@ class intervManager(Abstract): get_hr_state = EventMesh.publish("get_hr_state") get_spo2_state = EventMesh.publish("get_spo2_state") get_temp_state = EventMesh.publish("get_temp_state") - if get_hr_state != None or get_spo2_state != None or get_temp_state != None: + get_bg_state = EventMesh.publish("get_bg_state") + get_bp_state = EventMesh.publish("get_bp_state") + if get_hr_state != None and get_spo2_state != None and get_temp_state != None and get_bg_state != None and get_bp_state != None: if get_hr_state != 0: EventMesh.publish("set_hr_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 EventMesh.debug_log("sstop hr") @@ -912,6 +1243,15 @@ class intervManager(Abstract): EventMesh.debug_log("stop temp") EventMesh.publish("set_temp_state",0) EventMesh.publish(constants.EVENT.STOP_TEMP)#手动体温测试 + if get_bg_state != 0: + EventMesh.publish("set_bg_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 + EventMesh.debug_log("sstop bg") + EventMesh.publish(constants.EVENT.STOP_HEART) + + if get_bp_state != 0: + EventMesh.publish("set_bp_state",0)#2代表后台进入测试,定时测心率 1ui界面测试洗心率 + EventMesh.debug_log("sstop bp") + EventMesh.publish(constants.EVENT.STOP_HEART) def set_manual_measure_mode(self, event, msg): #手动测试 1心率 2 血氧 3 体温 get_hr_state = EventMesh.publish("get_hr_state") @@ -981,8 +1321,8 @@ class intervManager(Abstract): def play_temp_value(self, event, msg): #播放体温数值 flag = EventMesh.publish("get_call_state") if msg != None: - EventMesh.publish("close_timer_all")# - if flag == 0: + if flag == 0 and self.fall_flag == 0: + EventMesh.publish("close_timer_all")# if msg > 0: # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_OK")) # EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) @@ -994,6 +1334,9 @@ class intervManager(Abstract): str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_FAILE")) EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) EventMesh.publish("set_hr_blood_led",3)#测量异常 + else: + EventMesh.publish("set_hr_blood_led",3)#测量异常 + def play_temp_fun(self,argc): #播放体温数值 data = self.temp_value if data > 42: @@ -1041,8 +1384,8 @@ class intervManager(Abstract): def play_hr_value(self, event, msg): #播放心率数值 flag = EventMesh.publish("get_call_state") if msg != None: - EventMesh.publish("close_timer_all")# - if flag == 0: + if flag == 0 and self.fall_flag == 0: + EventMesh.publish("close_timer_all")# if msg >= 50: # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_OK")) # EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) @@ -1050,51 +1393,18 @@ class intervManager(Abstract): EventMesh.publish("set_hr_blood_led",2)#测量成功 # self.timer.start(2*1000,1,self.play_hr_fun) self.play_hr_fun(0) - else: - str_data ='mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_FAILE")) EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) EventMesh.publish("set_hr_blood_led",3)#测量异常 - - def play_spo2_value(self, event, msg): #播放血样数值 - flag = EventMesh.publish("get_call_state") - if msg != None: - EventMesh.publish("close_timer_all")# - if flag == 0: - if msg >= 85: - # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_OK")) - # EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - EventMesh.publish("set_hr_blood_led",2)#测量成功 - self.spo2_value = msg - # self.timer.start(2*1000,1,self.play_spo2_fun) - self.play_spo2_fun(0) - else: - str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_FAILE")) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - EventMesh.publish("set_hr_blood_led",3)#测量异常 - - def play_spo2_fun(self,argc):#播放血氧测试值 - flag = EventMesh.publish("get_call_state") - EventMesh.publish("close_timer_all")# - if flag == 0:#电话通话中 或者呼叫中挂断中断 - data = self.spo2_value - if data > 100: - data = 100 - if data == 100: - str_data = 'mp3files={}.mp3+{}.mp3+{}.mp3'.format(audio_buf.index("R_HSENSOR_SPO2_TITLE"),audio_buf.index("R_READ_TIME_{}".format(data//10)),\ - audio_buf.index("R_READ_STEP_2")) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) else: - str_data = 'mp3files={}.mp3+{}.mp3+{}.mp3+{}.mp3'.format(audio_buf.index("R_HSENSOR_SPO2_TITLE"),audio_buf.index("R_READ_TIME_{}".format(data//10)),\ - audio_buf.index("R_READ_STEP_3"),audio_buf.index("R_READ_TIME_{}".format(data%10))) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - + EventMesh.publish("set_hr_blood_led",3)#测量异常 def play_hr_fun(self,argc):#播放心率测试值 flag = EventMesh.publish("get_call_state") - EventMesh.publish("close_timer_all")# - if flag == 0:#电话通话中 或者呼叫中挂断中断 + + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 + EventMesh.publish("close_timer_all")# data = self.hr_value if data > 220: data = 220 @@ -1132,9 +1442,46 @@ class intervManager(Abstract): EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + def play_spo2_value(self, event, msg): #播放血样数值 + flag = EventMesh.publish("get_call_state") + if msg != None: + if flag == 0 and self.fall_flag == 0: + EventMesh.publish("close_timer_all")# + if msg >= 85: + # str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_OK")) + # EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + EventMesh.publish("set_hr_blood_led",2)#测量成功 + self.spo2_value = msg + # self.timer.start(2*1000,1,self.play_spo2_fun) + self.play_spo2_fun(0) + else: + str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_HSENSOR_RESULT_FAILE")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + EventMesh.publish("set_hr_blood_led",3)#测量异常 + else: + EventMesh.publish("set_hr_blood_led",3)#测量异常 + + def play_spo2_fun(self,argc):#播放血氧测试值 + flag = EventMesh.publish("get_call_state") + + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 + EventMesh.publish("close_timer_all")# + data = self.spo2_value + if data > 100: + data = 100 + if data == 100: + str_data = 'mp3files={}.mp3+{}.mp3+{}.mp3'.format(audio_buf.index("R_HSENSOR_SPO2_TITLE"),audio_buf.index("R_READ_TIME_{}".format(data//10)),\ + audio_buf.index("R_READ_STEP_2")) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + else: + str_data = 'mp3files={}.mp3+{}.mp3+{}.mp3+{}.mp3'.format(audio_buf.index("R_HSENSOR_SPO2_TITLE"),audio_buf.index("R_READ_TIME_{}".format(data//10)),\ + audio_buf.index("R_READ_STEP_3"),audio_buf.index("R_READ_TIME_{}".format(data%10))) + EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + + def set_sim_mode(self, event, msg): #mode 1 蓝灯闪烁 可识别卡 但未联网 2 可绑定appsim正常 3 手表不识别卡或者未插卡 flag = EventMesh.publish("get_call_state") - if flag != 2:#电话通话中 或者呼叫中挂断中断 + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 EventMesh.publish("close_timer_all")# # EventMesh.publish("stop_led_timer")#设置参数 mode = 0 @@ -1199,92 +1546,9 @@ class intervManager(Abstract): EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - - - - def send_find_watch(self, event, msg): #发送查找设备指令 - open_power = EventMesh.publish("get_power_on_state")#获取开机标识 - if open_power != None: - if open_power == 0: - return - power_off = EventMesh.publish("get_power_off_state")#获取开机标识 - if power_off != None: - if power_off == 1: - return - flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备 - wechat_state = EventMesh.publish("get_wechat_state") - if flag == 0 and wechat_state == 0: - EventMesh.publish("close_timer_all")# - self.find_state = 1 - self.FIND_timer_count = 0 - self.timer.start(3000,1,self.publish_find_watch_event_cb) - EventMesh.publish("set_led_time_arg",[1,1,330,led_mode.LONG_LIGHT_GREEN,2,1,led_mode.OTHER_MEASURE_MODE])#測量成功 - # EventMesh.publish("set_led_time_arg",[1000,33000,1,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#设置参数 - str_data = 'mp3files={}.mp3'.format(audio_buf.index("audio_find_haixiu")) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - - def stop_find_watch(self, event, msg): - if self.find_state == 1: - self.find_state = 0 - self.FIND_timer_count = 0 - # EventMesh.publish("stop_led_timer")#设置参数 - self.aud.stopPlayStream() #播放声音 - self.timer.stop() - - def FIND_timer_cb(self, data): - if self.find_state == 1: - # EventMesh.debug_log("self.FIND_timer_count:{}".format(self.FIND_timer_count)) - str_data = 'mp3files={}.mp3'.format(audio_buf.index("audio_find_haixiu")) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - self.FIND_timer_count += 1 - if self.FIND_timer_count > 10: #120秒30s - EventMesh.publish("STOP_FIND_WATCH") - - def stop_FIND(self) : - self.timer.stop() - - def send_alarm_ring(self, event, msg): #发送查找设备指令 - open_power = EventMesh.publish("get_power_on_state")#获取开机标识 - if open_power != None: - if open_power == 0: - return - power_off = EventMesh.publish("get_power_off_state")#获取开机标识 - if power_off != None: - if power_off == 1: - return - flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许寻找设备 - wechat_state = EventMesh.publish("get_wechat_state") - if flag == 0 and wechat_state == 0: - EventMesh.publish("close_timer_all")# - self.alarm_state = 1 - self.alarm_timer_count = 0 - self.timer.start(3000,1,self.publish_alarm_ring_event_cb) - # EventMesh.publish("set_led_time_arg",[1,1,330,led_mode.LONG_LIGHT_GREEN,2,1,led_mode.OTHER_MEASURE_MODE])#測量成功 - # EventMesh.publish("set_led_time_arg",[1000,33000,1,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#设置参数 - str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_ALARM_NEW")) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - - def stop_alarm_ring(self, event, msg): #停止闹钟响铃 - if self.alarm_state == 1: - self.alarm_state = 0 - self.alarm_timer_count = 0 - # EventMesh.publish("stop_led_timer")#设置参数 - self.aud.stopPlayStream() #停止播放 - self.timer.stop() - - def Alarm_timer_cb(self, data): - if self.alarm_state == 1: - # EventMesh.debug_log("self.alarm_timer_count:{}".format(self.alarm_timer_count)) - str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_ALARM_NEW")) - EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - self.alarm_timer_count += 1 - if self.alarm_timer_count > 15: #120秒30s - EventMesh.publish("STOP_ALARM_RING") - - def play_cur_time_event(self, event, msg): #播放当前时间 flag = EventMesh.publish("get_call_state") - if flag != 2:#电话通话中 或者呼叫中挂断中断 + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 EventMesh.publish("close_timer_all")# data = RTC().datetime() @@ -1468,7 +1732,7 @@ class intervManager(Abstract): def play_center_phone(self, event, msg): #msg flag = EventMesh.publish("get_call_state")#在通话或者电话拨进 或者拨出不允许设备再次拨出 - if flag == 0: + if flag == 0 and self.fall_flag == 0: EventMesh.publish("close_timer_all")# center_dial = EventMesh.publish("get_storage_config","center_dial") @@ -1477,16 +1741,21 @@ class intervManager(Abstract): voiceCall.callStart(str(center_dial)) str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_SOS_ALERT")) EventMesh.publish("play_audio_file",[str_data,0])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) + else:#未设置号码 # EventMesh.debug_log("play_center_phone") str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_NO_SET_SOS_DIAL")) EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) pass - + def center_phone_cb(self,*argc): #msg + pass + + + def play_imei_event(self, event, msg): #msg flag = EventMesh.publish("get_call_state") - if flag != 2:#电话通话中 或者呼叫中挂断中断 + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 EventMesh.publish("close_timer_all")# imei = EventMesh.publish(constants.EVENT.GET_IMEI) EventMesh.debug_log(imei) @@ -1525,11 +1794,10 @@ class intervManager(Abstract): def start_wechat_record(self, event, msg): #开始录音相关配置 if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#未联网不需要录音 - - if self.press_btn == 0: - self.press_btn = 1 - flag = EventMesh.publish("get_call_state") - if flag != 2:#电话通话中 或者呼叫中挂断中断 + flag = EventMesh.publish("get_call_state") + if flag == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 + if self.press_btn == 0: + self.press_btn = 1 EventMesh.publish("close_timer_all")# EventMesh.publish("set_led_time_arg",[1,1,160,led_mode.LONG_LIGHT_GREEN,4,2,led_mode.WECHAT_LED_MODE])#測量成功 # EventMesh.publish("set_led_time_arg",[1000,1000,1,led_mode.LONG_LIGHT_GREEN,led_mode.OPEN_LONG_LIGHT_MODE,led_mode.WECHAT_LED_MODE])#測量成功 @@ -1540,11 +1808,13 @@ class intervManager(Abstract): self.aud.setVolume(11)#设置音量最大 EventMesh.debug_log("talking1.0") - if self.wechat_num >= self.MXA_MSG: - self.wechat_num = 0 - self.wechat_num += 1 - self.wechat_show = self.wechat_num - self.record_test.start("/usr/static/storage_file/{}.amr".format(self.wechat_show),16) + # if self.wechat_num >= self.MXA_MSG: + # self.wechat_num = 0 + # self.wechat_num += 1 + # self.wechat_show = self.wechat_num + # self.record_test.start("/usr/static/storage_file/{}.amr".format(self.wechat_show),16) + self.record_test.start("/usr/static/storage_file/wechat.amr",16) + else: self.timeSecond = 0 self.press_btn = 0 @@ -1570,26 +1840,27 @@ class intervManager(Abstract): #录音时间太短 return else: - self.wechat_recode_list["%02d"%(self.wechat_show)] = "read:0" - self.wechat_recode_list["num"] = self.wechat_show + # self.wechat_recode_list["%02d"%(self.wechat_show)] = "read:0" + # self.wechat_recode_list["num"] = self.wechat_show EventMesh.debug_log("self.wechat_recode_list :{}".format(self.wechat_recode_list)) + # with open("/usr/static/storage_file/wechat_record.json","w+",encoding="utf-8") as fd: + # ujson.dump(self.wechat_recode_list,fd) + EventMesh.debug_log("send wechat data!!!!!!!!!!!!!!!!!!!!!") - - with open("/usr/static/storage_file/wechat_record.json","w+",encoding="utf-8") as fd: - ujson.dump(self.wechat_recode_list,fd) - # EventMesh.debug_log("send wechat data!!!!!!!!!!!!!!!!!!!!!") - - check_txt = ql_fs.path_exists("/usr/static/storage_file/{}.amr".format(self.wechat_show)) + check_txt = ql_fs.path_exists("/usr/static/storage_file/wechat.amr") if check_txt == True : - path = "/usr/static/storage_file/{}.amr".format(self.wechat_show) + path = "/usr/static/storage_file/wechat.amr" with open(path,"rb") as fd: buf = bytearray(ql_fs.path_getsize(path)) fd.readinto(buf) senddata = [self.countdown_old,buf] EventMesh.publish(constants.PROTOCOL.TKS_SEND,senddata) - - + + # with open("/usr/static/storage_file/wechat_record.json","w+",encoding="utf-8") as fd: + # ujson.dump(self.wechat_recode_list,fd) + # EventMesh.debug_log("send wechat data!!!!!!!!!!!!!!!!!!!!!") + # check_txt = ql_fs.path_exists("/usr/static/storage_file/{}.amr".format(self.wechat_show)) # if check_txt == True : # path = "/usr/static/storage_file/{}.amr".format(self.wechat_show) @@ -1602,13 +1873,8 @@ class intervManager(Abstract): def play_wechat_last_amr(self, event, msg):#播放微聊最后一条语音文件 flag = EventMesh.publish("get_call_state") - if flag != 2:#电话通话中 或者呼叫中挂断中断 + if flag == 0:#电话通话中 或者呼叫中挂断中断 EventMesh.publish("close_timer_all")# - - # check_amr = ql_fs.path_exists("/usr/static/storage_file/wechat.amr") - # if check_amr == True : - # self.aud.play(1, 1, '/usr/static/storage_file/wechat.amr') #文件名前面要加上路径 - # return if self.wechat_recode_list != None: num = 0 play_state = 0 @@ -1658,51 +1924,51 @@ class intervManager(Abstract): if check_amr == True: self.aud.play(1, 1, '/usr/static/storage_file/{}.amr'.format(num)) #文件名前面要加上路径 + def play_unread_wechat_infor(self,event,msg):#未读微聊语音 - if self.wechat_recode_list != None: - num = 0 - play_state = 0 - if len(self.wechat_recode_list) > 1: - num = int(self.wechat_recode_list["num"]) - if num != 0: - for i in range(len(self.wechat_recode_list)-1):#1 01 02 - key = "%02d"%(i+1) - if key in self.wechat_recode_list:# - str_tmp = self.wechat_recode_list[key] - read = int(str_tmp.split(":")[1]) - if read == 1:#未读是按一下播放下一条同时删除 - play_state = 1 + flag = EventMesh.publish("get_call_state") + if flag == 0 and self.press_btn == 0 and self.fall_flag == 0:#电话通话中 或者呼叫中挂断中断 + if self.wechat_recode_list != None: + num = 0 + play_state = 0 + if len(self.wechat_recode_list) > 1: + num = int(self.wechat_recode_list["num"]) + if num != 0: + for i in range(len(self.wechat_recode_list)-1):#1 01 02 + key = "%02d"%(i+1) + if key in self.wechat_recode_list:# + str_tmp = self.wechat_recode_list[key] + read = int(str_tmp.split(":")[1]) + if read == 1:#未读是按一下播放下一条同时删除 + play_state = 1 + else: + continue else: continue + if play_state == 1:#设置未读语音状态 + EventMesh.publish("set_unread_wechat_state",1) else: - continue - if play_state == 1:#设置未读语音状态 - EventMesh.publish("set_unread_wechat_state",1) - else: - EventMesh.publish("set_unread_wechat_state",0) - self.updateTime = 0 - + EventMesh.publish("set_unread_wechat_state",0) + self.updateTime = 0 - state = EventMesh.publish("get_unread_wechat_state")# - date_tmp = utime.localtime() - time_tmp = utime.mktime(date_tmp) - if state != None: - if state == 1: - EventMesh.publish("set_led_time_arg",[1,2,8,led_mode.FLASH_LIGHT_GREEN,8,4,led_mode.OTHER_MEASURE_MODE])#測量成功 - # EventMesh.publish("set_led_time_arg",[1000,400,1,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#设置参数 - if self.updateTime == 0: - self.updateTime = time_tmp - if self.updateTime != 0: - if time_tmp - self.updateTime >= 10*60: + state = EventMesh.publish("get_unread_wechat_state")# + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + if state != None: + if state == 1: + EventMesh.publish("set_led_time_arg",[1,2,8,led_mode.FLASH_LIGHT_GREEN,8,4,led_mode.OTHER_MEASURE_MODE])#測量成功 + # EventMesh.publish("set_led_time_arg",[1000,400,1,led_mode.FLASH_LIGHT_GREEN,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#设置参数 + if self.updateTime == 0: self.updateTime = time_tmp - #播放音频文件 - flag = EventMesh.publish("get_call_state") - if flag != 2 and self.press_btn == 0:#电话通话中 或者呼叫中挂断中断 + if self.updateTime != 0: + if time_tmp - self.updateTime >= 10*60: + self.updateTime = time_tmp + #播放音频文件 EventMesh.publish("close_timer_all") str_data = 'mp3files={}.mp3'.format(audio_buf.index("R_UNREAD_WECHAT")) EventMesh.publish("play_audio_file",[str_data,1])#获取播放音频文件('U:/static/audio.bin',1,1,str_data) - else: - self.updateTime = 0 + else: + self.updateTime = 0 @@ -1808,6 +2074,10 @@ class BtnDevice(Abstract): if power_off != None: if power_off == 1: return + fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识 + if fall_down != None: + if fall_down != 0: + return if self.sosKey_status != 0 and self.WeChatKey_status != 0: if self.GPIO26_status == 0:#按下 if self.pwkey_press == 0 : @@ -1999,15 +2269,13 @@ class BtnDevice(Abstract): EventMesh.publish("publish_message_event_btnInfo",{"func":self.sosKey_timeout_cb,"data":0}) def sosKey_timeout_cb(self, data):# # EventMesh.debug_log("sosKey_press_count!!!!!!!!!!!!!! ",self.sosKey_press_count) + + fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识 if self.sosKey_press_count == 10:# self.sosKey_press_count = 0 - # EventMesh.publish("reset_factor_setiing")# pass elif self.sosKey_press_count == 6:# self.sosKey_press_count = 0 - # EventMesh.publish("stop_led_timer")#设置参数 - # EventMesh.publish("set_manual_measure_mode",2)#测量血氧 - # EventMesh.publish("play_imei_event")#播報imei号 pass elif self.sosKey_press_count == 5:#功能暂时屏蔽 self.sosKey_press_count = 0 @@ -2023,8 +2291,9 @@ class BtnDevice(Abstract): pass elif self.sosKey_press_count == 4:#拨打app快捷号码 self.sosKey_press_count = 0 - EventMesh.publish("stop_led_timer")#设置参数 - EventMesh.publish("play_center_phone")#拨打快捷号码 + if fall_down == 0: + EventMesh.publish("stop_led_timer")#设置参数 + EventMesh.publish("play_center_phone")#拨打快捷号码 # EventMesh.publish("call_phonebook_three_call") pass elif self.sosKey_press_count == 3:#测试心率 @@ -2042,8 +2311,9 @@ class BtnDevice(Abstract): pass elif self.sosKey_press_count == 2:#播报当前步数 self.sosKey_press_count = 0 - EventMesh.publish("stop_led_timer")#设置参数 - EventMesh.publish("play_cur_step_event")# + if fall_down == 0: + EventMesh.publish("stop_led_timer")#设置参数 + EventMesh.publish("play_cur_step_event")# pass elif self.sosKey_press_count == 1:#挂断来电 短语音播报 self.sosKey_press_count = 0 @@ -2115,54 +2385,58 @@ class BtnDevice(Abstract): tmp = EventMesh.publish("get_wechat_time")#获取微聊时间戳 self.wechatKey_count += 1 if self.wechatKey_count >= 10: #长按1s进入微聊录音 - if self.WeChatKey_status == 0: - if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#未联网不需要录音 - if self.wechat_state == 1:#按下超过s开始录音 - EventMesh.publish("start_wechat_record")#开始录音 - self.wechat_state = 0 - else: - self.wechat_state = 0 - self.wechatKey_timer.stop() - self.wechatKey_count = 0 - self.wechatKey_press = 0 - self.wechatKey_press_count=0 - EventMesh.publish("set_sim_mode")#播報imei号 - return - - if self.WeChatKey_status == 0:#未松手超过15s啧停止录音 - if self.wechat_state == 0: - if tmp != None: - if tmp[0] != 0: - time_sec = tmp[1] - if time_tmp - time_sec >= 15: - wechat_time = time_tmp - time_sec - if wechat_time >= 15: - wechat_time = 15 - EventMesh.publish("send_wechat_record",wechat_time)#发送录音文件内容 + flag = EventMesh.publish("get_call_state") + fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识 + if flag != None: + if flag == 0 and fall_down == 0: + if self.WeChatKey_status == 0: + if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#未联网不需要录音 + if self.wechat_state == 1:#按下超过s开始录音 + EventMesh.publish("start_wechat_record")#开始录音 + self.wechat_state = 0 + else: + self.wechat_state = 0 + self.wechatKey_timer.stop() + self.wechatKey_count = 0 + self.wechatKey_press = 0 + self.wechatKey_press_count=0 + EventMesh.publish("set_sim_mode")#播報imei号 + return + + if self.WeChatKey_status == 0:#未松手超过15s啧停止录音 + if self.wechat_state == 0: + if tmp != None: + if tmp[0] != 0: + time_sec = tmp[1] + if time_tmp - time_sec >= 15: + wechat_time = time_tmp - time_sec + if wechat_time >= 15: + wechat_time = 15 + EventMesh.publish("send_wechat_record",wechat_time)#发送录音文件内容 + + self.wechatKey_timer.stop() + self.wechatKey_count = 0 + self.wechatKey_press = 0 + self.wechatKey_press_count=0 + return + else: + if self.WeChatKey_status == 1: + if self.wechat_state == 0:#如果按下时长超过1s且小于长按的时间也认为是录微聊 + if tmp != None: + if tmp[0] != 0: + time_sec = tmp[1] + wechat_time = time_tmp - time_sec + # EventMesh.debug_log("WECHAT TIEM",time_tmp,time_sec,wechat_time) + if wechat_time >= 15: + wechat_time = 15 + EventMesh.publish("send_wechat_record",wechat_time)#发送录音文件内容 self.wechatKey_timer.stop() + self.wechatKey_count = 0 self.wechatKey_press = 0 self.wechatKey_press_count=0 return - else: - if self.WeChatKey_status == 1: - if self.wechat_state == 0:#如果按下时长超过1s且小于长按的时间也认为是录微聊 - if tmp != None: - if tmp[0] != 0: - time_sec = tmp[1] - wechat_time = time_tmp - time_sec - # EventMesh.debug_log("WECHAT TIEM",time_tmp,time_sec,wechat_time) - if wechat_time >= 15: - wechat_time = 15 - - EventMesh.publish("send_wechat_record",wechat_time)#发送录音文件内容 - self.wechatKey_timer.stop() - - self.wechatKey_count = 0 - self.wechatKey_press = 0 - self.wechatKey_press_count=0 - return if self.WeChatKey_status == 1:#松开 if self.wechatKey_count >= 1: #防抖100ms @@ -2177,6 +2451,13 @@ class BtnDevice(Abstract): EventMesh.publish("publish_message_event_btnInfo",{"func":self.wechatKey_timeout_cb,"data":0}) def wechatKey_timeout_cb(self,data):#微聊键 + + if self.wechatKey_press_count > 1:#短按十次解绑app + fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识 + if fall_down != None: + if fall_down != 0: + self.wechatKey_press_count = 0 + return # EventMesh.debug_log("wechatKey_timeout_cb!!!!!!!!!!!!!! ",self.wechatKey_press_count) if self.wechatKey_press_count == 10:#短按十次解绑app self.wechatKey_press_count = 0 @@ -2208,10 +2489,17 @@ class BtnDevice(Abstract): self.wechatKey_press_count = 0 EventMesh.publish("stop_led_timer")#设置参数 call_state = EventMesh.publish("get_call_state") - if call_state == 2:#电话拨进需要接听 - EventMesh.publish("answer_call_event")#接听电话 + if call_state == 0: + fall_down = EventMesh.publish("get_fall_down_state")#跌倒报警标识 + if fall_down != None: + if fall_down != 0: + EventMesh.publish_async("dial_sos_phone")#拨打sos号码 + return else: - EventMesh.publish("play_wechat_last_amr") + if call_state == 2:#电话拨进需要接听 + EventMesh.publish("answer_call_event")#接听电话 + return + EventMesh.publish("play_wechat_last_amr") # pass self.wechatKey_press_count = 0 diff --git a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/constants.py b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/constants.py index 3983bbd3..88b2e6db 100644 --- a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/constants.py +++ b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/constants.py @@ -119,6 +119,18 @@ class PROTOCOL: REMIND_CH_MEDICINE2_SEND = "REMIND_CH_MEDICINE2_SEND" REMIND_CH_MEDICINE2_RECV = "REMIND_CH_MEDICINE2_RECV" + + REMIND_CH_HOME_SEND = "REMIND_CH_HOME_SEND" + REMIND_CH_HOME_RECV = "REMIND_CH_HOME_RECV" + + REMIND_CH_WAKEUP_SEND = "REMIND_CH_WAKEUP_SEND" + REMIND_CH_WAKEUP_RECV = "REMIND_CH_WAKEUP_RECV" + + REMIND_CH_SLEEP_SEND = "REMIND_CH_SLEEP_SEND" + REMIND_CH_SLEEP_RECV = "REMIND_CH_SLEEP_RECV" + + REMIND_CH_REST_SEND = "REMIND_CH_REST_SEND" + REMIND_CH_REST_RECV = "REMIND_CH_REST_RECV" class EVENT: diff --git a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/led.py b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/led.py index 08edae51..0f835bd4 100644 --- a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/led.py +++ b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/led.py @@ -271,7 +271,7 @@ class ledEventManager(Abstract):#灯事件 wechat_state = EventMesh.publish("get_wechat_state") temp_state = EventMesh.publish("get_temp_state") - bp_state = EventMesh.publish("get_bg_state") + bp_state = EventMesh.publish("get_bp_state") bg_state = EventMesh.publish("get_bg_state") EventMesh.debug_log("get_hr_state",get_hr_state,get_spo2_state,temp_state,wechat_state,self.working_led_mode) if wechat_state != None: #获取微聊状态 diff --git a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/main_init.py b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/main_init.py index bafb4056..50ee6317 100644 --- a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/main_init.py +++ b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/main_init.py @@ -188,6 +188,10 @@ def main_init(): pcr.add_support(protocol.bloodglucose_ProtoCol()) pcr.add_support(protocol.REMIND_CHDRINK_ProtoCol()) pcr.add_support(protocol.REMIND_CHMEDICINE2_ProtoCol()) + pcr.add_support(protocol.REMIND_CH_WAKEUP_ProtoCol()) + pcr.add_support(protocol.REMIND_CH_SLEEP_ProtoCol()) + pcr.add_support(protocol.REMIND_CH_HOME_ProtoCol()) + pcr.add_support(protocol.REMIND_CH_REST_ProtoCol()) sm = protocol.SockManager() sm.add_support_resolver(pcr) @@ -207,7 +211,7 @@ def main_init(): if timeSecond != 0: next_alarm_time = utime.localtime(timeSecond) machine.RTC().datetime((next_alarm_time[0],next_alarm_time[1],next_alarm_time[2],next_alarm_time[6],next_alarm_time[3],next_alarm_time[4],next_alarm_time[5],0)) - EventMesh.publish("set_rtc_alarm") + EventMesh.publish("open_power_on", 1)# # EventMesh.publish("load_screen", {"screen": "main_menu"}) diff --git a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr.py b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr.py index d0577c63..ccd555d5 100644 --- a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr.py +++ b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/mgr.py @@ -782,8 +782,29 @@ class DeviceInfoManager(Abstract): self.old_bp_time = 0 - self.alarm_count = 0 - self.alarm_flag = 0 + self.medicine_count = 0 + self.medicine_flag = 0 + self.medicine_oldtotalmin = 0 + + self.wakeup_flag = 0 + self.wakeup_count = 0 + self.wakeup_oldtotalmin = 0 + + self.sleep_flag = 0 + self.sleep_count = 0 + self.sleep_oldtotalmin = 0 + + self.reset_flag = 0 + self.reset_count = 0 + self.reset_oldtotalmin = 0 + + self.home_flag = 0 + self.home_count = 0 + self.home_oldtotalmin = 0 + + self.normal_flag = 0 + self.normal_count = 0 + self.normal_oldtotalmin = 0 self.charge_full_count = 0 self.GPS_step_t = 0#记录步数 @@ -831,6 +852,13 @@ class DeviceInfoManager(Abstract): self.drink_time = 0 + self.alarm_count = 0 + self.alarm_flag = 0 + + self.time_count = 0 + + + def post_processor_after_instantiation(self): EventMesh.debug_log("post_processor_after_instantiation:1") @@ -883,6 +911,12 @@ class DeviceInfoManager(Abstract): EventMesh.subscribe("set_dev_state", self.set_dev_state) EventMesh.subscribe("clear_health_state", self.clear_health_state) + + EventMesh.subscribe("clear_home_alarm", self.clear_home_alarm) + EventMesh.subscribe("clear_medicine_alarm", self.clear_medicine_alarm) + EventMesh.subscribe("clear_wakeup_alarm", self.clear_wakeup_alarm) + EventMesh.subscribe("clear_sleep_alarm", self.clear_sleep_alarm) + EventMesh.subscribe("clear_normal_alarm", self.clear_normal_alarm) EventMesh.debug_log("post_processor_after_instantiation:2") self.timer_push_schedule.start(10000, 1, self.publish_event_cb) @@ -1804,11 +1838,96 @@ class DeviceInfoManager(Abstract): EventMesh.publish("set_led_time_arg",[1,2,20*11,led_mode.FLASH_LIGHT_RED,20,10,led_mode.OTHER_MEASURE_MODE])#測量成功 # EventMesh.publish("set_led_time_arg",[1000,400,52,led_mode.FLASH_LIGHT_RED,led_mode.DEFAULT_LONG_LIGHT_MODE,led_mode.OTHER_MEASURE_MODE])#開始測量 + + self.normal_alarm() #喝水提醒 self.drink_alarm() #该吃药了 self.medicine_alarm() + #该起床了 + self.wakeup_alarm() + #该睡觉了 + self.sleep_alarm() + #该回家了 + self.home_alarm() + #该休息了 + self.reset_alarm() + + + if self.alarm_flag == 0: + self.alarm_flag = 1 + EventMesh.publish("set_rtc_alarm") + + + #普通闹钟 + def normal_alarm(self): + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + data = RTC().datetime() + hour = data[4] + min = data[5] + + week = int(data[3]) + + date1 = data[1] + date2 = data[2] + cur_total_min = int(hour)*60+int(min) + # EventMesh.debug_log("self.normal_oldtotalmin",self.normal_oldtotalmin,cur_total_min,self.alarm_flag) + if self.normal_oldtotalmin == 0: + self.normal_oldtotalmin = cur_total_min #549 + if self.normal_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃 + if self.normal_flag == 1: + self.normal_flag = 0 + self.normal_count = 0 + normal_alarm = [] + normal_alarm = EventMesh.publish("get_storage_config","normal_alarm") + # EventMesh.debug_log("sleep info2",sleep,cur_total_min) + if self.normal_flag == 1:#表示闹钟响过清除标志 + self.normal_count+=1 + if self.normal_count > 6: + self.normal_count = 0 + self.normal_flag = 0 + if normal_alarm != None: + if len(normal_alarm) != 0 and normal_alarm != []: + j = 0 + for i in range(len(normal_alarm)): + # EventMesh.debug_log("normal_alarm normal_alarm 33",normal_alarm,j) + normalalarm_hour = normal_alarm[j]["hour"] + normalalarm_min = normal_alarm[j]["min"] + normalalarm_day = normal_alarm[j]["day"] + normalalarm_enale = normal_alarm[j]["enable"] + normalalarm_totalmin = int(normalalarm_hour)*60+int(normalalarm_min) + # EventMesh.debug_log("wake alarm",normalalarm_hour,sleep_min,sleep_day,sleep_enale,sleep_totalmin,week) + if normalalarm_day == []:#单次闹钟只响一次 + if normalalarm_enale != 0: + if cur_total_min > normalalarm_totalmin: + normal_alarm.pop(j) + self.normal_count = 0 + self.normal_flag = 0 + j=0 + # EventMesh.debug_log("wakeup wakeup dayu",sleep,j) + EventMesh.publish("set_storage_config",["normal_alarm",normal_alarm])#删除之后重新保存 + # sleep = EventMesh.publish("get_storage_config","sleep_alarm")#删除之后重新保存 + continue + else: + if normalalarm_totalmin == cur_total_min and self.normal_flag == 0:#14:00 + self.normal_count = 0 + self.normal_flag = 0 + normal_alarm.pop(j) + # EventMesh.debug_log("wakeup wakeup1",sleep,j) + EventMesh.publish("set_storage_config",["normal_alarm",normal_alarm])#删除之后重新保存 + EventMesh.publish("OPEN_ALARM_RING") + break + else: + if normalalarm_enale != 0 and (week in normalalarm_day):#记录响过的时间分钟数 + if normalalarm_totalmin == cur_total_min and self.normal_flag == 0:#14:00 + self.normal_flag = 1 + self.normal_count = 0 + self.normal_oldtotalmin = normalalarm_totalmin + EventMesh.publish("OPEN_ALARM_RING")# + break + j+=1 #喝水提醒 @@ -1821,12 +1940,12 @@ class DeviceInfoManager(Abstract): on = EventMesh.publish("get_storage_config","drink_on") time = EventMesh.publish("get_storage_config","drink_time") - print("drink info2",on,time) + # print("drink info2",on,time) if on != None and time != None: if on != 0 and time != 0: if (time_tmp - self.drink_time) >= (time*60*60):#需要转换成小时3600 self.drink_time = time_tmp - EventMesh.publish("drink_alarm_event")#跌倒报警启动中 + EventMesh.publish("drink_alarm_event")#该喝水了 #该喝水了 else: self.drink_time = 0 @@ -1846,56 +1965,327 @@ class DeviceInfoManager(Abstract): date1 = data[1] date2 = data[2] cur_total_min = int(hour)*60+int(min) + # print("self.medicine_oldtotalmin",self.medicine_oldtotalmin,cur_total_min,self.alarm_flag) + if self.medicine_oldtotalmin == 0: + self.medicine_oldtotalmin = cur_total_min #549 + if self.medicine_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃 + if self.medicine_flag == 1: + self.medicine_flag = 0 + self.medicine_count = 0 medicine = EventMesh.publish("get_storage_config","medicine") - print("medicine info2",medicine,cur_total_min) - if self.alarm_flag == 1:#表示闹钟响过清除标志 - self.alarm_count+=1 - if self.alarm_count > 6: - self.alarm_count = 0 - self.alarm_flag = 0 + # print("medicine info2",medicine,cur_total_min) + if self.medicine_flag == 1:#表示闹钟响过清除标志 + self.medicine_count+=1 + if self.medicine_count > 6: + self.medicine_count = 0 + self.medicine_flag = 0 if medicine != None: if len(medicine) != 0 and medicine != []: for i in range(len(medicine)): - alarm_hour = medicine[i]["hour"] - alarm_min = medicine[i]["min"] - alarm_day = medicine[i]["day"] - alarm_enale = medicine[i]["enable"] - alarm_totalmin = int(alarm_hour)*60+int(alarm_min) - if alarm_day == []: - if alarm_enale != 0: - if alarm_totalmin >= cur_total_min and self.alarm_flag == 0:#14:00 - self.alarm_count = 0 - self.alarm_flag = 1 + medicine_hour = medicine[i]["hour"] + medicine_min = medicine[i]["min"] + medicine_day = medicine[i]["day"] + medicine_enale = medicine[i]["enable"] + medicine_totalmin = int(medicine_hour)*60+int(medicine_min) + # print("medicine alarm",medicine_hour,medicine_min,medicine_day,medicine_enale,medicine_totalmin,week) + if medicine_day == []: + if medicine_enale != 0: + if medicine_totalmin == cur_total_min and self.medicine_flag == 0:#14:00 + self.medicine_count = 0 + self.medicine_flag = 1 + self.medicine_oldtotalmin = medicine_totalmin#记录响过的时间分钟数 + # print("medicine alarm1") + EventMesh.publish("medicine_alarm_event")#该吃药了 break else: - if alarm_enale != 0: - if alarm_totalmin >= cur_total_min and self.alarm_flag == 0:#14:00 - self.alarm_count = 0 - self.alarm_flag = 1 + if medicine_enale != 0 and (week in medicine_day):#记录响过的时间分钟数 + if medicine_totalmin == cur_total_min and self.medicine_flag == 0:#14:00 + self.medicine_flag = 1 + self.medicine_count = 0 + self.medicine_oldtotalmin = medicine_totalmin + # print("medicine alarm2",) + EventMesh.publish("medicine_alarm_event")#该吃药了 break + #该起床了 + def wakeup_alarm(self): + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + data = RTC().datetime() + hour = data[4] + min = data[5] + + week = int(data[3]) + + date1 = data[1] + date2 = data[2] + cur_total_min = int(hour)*60+int(min) + # EventMesh.debug_log("self.wakeup_oldtotalmin",self.wakeup_oldtotalmin,cur_total_min,self.alarm_flag) + if self.wakeup_oldtotalmin == 0: + self.wakeup_oldtotalmin = cur_total_min #549 + if self.wakeup_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃 + if self.wakeup_flag == 1: + self.wakeup_flag = 0 + self.wakeup_count = 0 + wakeup = [] + wakeup = EventMesh.publish("get_storage_config","wakeup_alarm") + # EventMesh.debug_log("wakeup info2",wakeup,cur_total_min) + if self.wakeup_flag == 1:#表示闹钟响过清除标志 + self.wakeup_count+=1 + if self.wakeup_count > 6: + self.wakeup_count = 0 + self.wakeup_flag = 0 + if wakeup != None: + if len(wakeup) != 0 and wakeup != []: + j = 0 + for i in range(len(wakeup)): + wakeup_hour = wakeup[j]["hour"] + wakeup_min = wakeup[j]["min"] + wakeup_day = wakeup[j]["day"] + wakeup_enale = wakeup[j]["enable"] + wakeup_totalmin = int(wakeup_hour)*60+int(wakeup_min) + # EventMesh.debug_log("wake alarm",wakeup_hour,wakeup_min,wakeup_day,wakeup_enale,wakeup_totalmin,week) + if wakeup_day == []:#单次闹钟只响一次 + if wakeup_enale != 0: + if cur_total_min > wakeup_totalmin: + self.wakeup_count = 0 + self.wakeup_flag = 0 + wakeup.pop(j) + j=0#每次删除都从0开始遍历 + # EventMesh.debug_log("wakeup wakeup1 dayu",wakeup,j) + EventMesh.publish("set_storage_config",["wakeup_alarm",wakeup]) + continue + else: + if wakeup_totalmin == cur_total_min and self.wakeup_flag == 0:#14:00 + self.wakeup_count = 0 + self.wakeup_flag = 0 + wakeup.pop(j) + EventMesh.debug_log("wakeup wakeup1",wakeup,j) + EventMesh.publish("set_storage_config",["wakeup_alarm",wakeup]) + EventMesh.publish("wakeup_alarm_event")#该吃药了 + break + else: + if wakeup_enale != 0 and (week in wakeup_day):#记录响过的时间分钟数 + if wakeup_totalmin == cur_total_min and self.wakeup_flag == 0:#14:00 + self.wakeup_flag = 1 + self.wakeup_count = 0 + self.wakeup_oldtotalmin = wakeup_totalmin + EventMesh.publish("wakeup_alarm_event")#该吃药了 + break + j+=1 + + + #该睡觉了 + def sleep_alarm(self): + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + data = RTC().datetime() + hour = data[4] + min = data[5] + + week = int(data[3]) + + date1 = data[1] + date2 = data[2] + cur_total_min = int(hour)*60+int(min) + # EventMesh.debug_log("self.sleep_oldtotalmin",self.sleep_oldtotalmin,cur_total_min,self.alarm_flag) + if self.sleep_oldtotalmin == 0: + self.sleep_oldtotalmin = cur_total_min #549 + if self.sleep_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃 + if self.sleep_flag == 1: + self.sleep_flag = 0 + self.sleep_count = 0 + sleep = [] + sleep = EventMesh.publish("get_storage_config","sleep_alarm") + # EventMesh.debug_log("sleep info2",sleep,cur_total_min) + if self.sleep_flag == 1:#表示闹钟响过清除标志 + self.sleep_count+=1 + if self.sleep_count > 6: + self.sleep_count = 0 + self.sleep_flag = 0 + if sleep != None: + if len(sleep) != 0 and sleep != []: + j = 0 + count = int(len(sleep)) + for i in range(len(sleep)): + # EventMesh.debug_log("wakeup wakeup 33",sleep,j) + sleep_hour = sleep[j]["hour"] + sleep_min = sleep[j]["min"] + sleep_day = sleep[j]["day"] + sleep_enale = sleep[j]["enable"] + sleep_totalmin = int(sleep_hour)*60+int(sleep_min) + # EventMesh.debug_log("wake alarm",sleep_hour,sleep_min,sleep_day,sleep_enale,sleep_totalmin,week) + if sleep_day == []:#单次闹钟只响一次 + if sleep_enale != 0: + if cur_total_min > sleep_totalmin: + sleep.pop(j) + self.sleep_count = 0 + self.sleep_flag = 0 + j=0 + # EventMesh.debug_log("wakeup wakeup dayu",sleep,j) + EventMesh.publish("set_storage_config",["sleep_alarm",sleep])#删除之后重新保存 + # sleep = EventMesh.publish("get_storage_config","sleep_alarm")#删除之后重新保存 + continue + else: + if sleep_totalmin == cur_total_min and self.sleep_flag == 0:#14:00 + self.sleep_count = 0 + self.sleep_flag = 0 + sleep.pop(j) + # EventMesh.debug_log("wakeup wakeup1",sleep,j) + EventMesh.publish("set_storage_config",["sleep_alarm",sleep])#删除之后重新保存 + EventMesh.publish("sleep_alarm_event")#该吃药了 + break + else: + if sleep_enale != 0 and (week in sleep_day):#记录响过的时间分钟数 + if sleep_totalmin == cur_total_min and self.sleep_flag == 0:#14:00 + self.sleep_flag = 1 + self.sleep_count = 0 + self.sleep_oldtotalmin = sleep_totalmin + EventMesh.publish("sleep_alarm_event")#该吃药了 + break + j+=1 + + + + + + + #该回家了 + def home_alarm(self): + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + data = RTC().datetime() + hour = data[4] + min = data[5] + + week = int(data[3]) + + date1 = data[1] + date2 = data[2] + cur_total_min = int(hour)*60+int(min) + # EventMesh.debug_log("self.home_oldtotalmin",self.home_oldtotalmin,cur_total_min,self.alarm_flag) + if self.home_oldtotalmin == 0: + self.home_oldtotalmin = cur_total_min #549 + if self.home_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃 + if self.home_flag == 1: + self.home_flag = 0 + self.home_count = 0 + home = '' + home = EventMesh.publish("get_storage_config","home_alarm") + # EventMesh.debug_log("sleep info2",sleep,cur_total_min) + if self.home_flag == 1:#表示闹钟响过清除标志 + self.home_count+=1 + if self.home_count > 6: + self.home_count = 0 + self.home_flag = 0 + if home != None: + if len(str(home)) != 0 and str(home) != '': + # EventMesh.debug_log("home home 33",home) + home_hour = int(str(home).split(":")[0]) + home_min = int(str(home).split(":")[1]) + + home_totalmin = int(home_hour)*60+int(home_min) + if home_totalmin == cur_total_min and self.home_flag == 0:#14:00 + self.home_flag = 1 + self.home_count = 0 + self.home_oldtotalmin = home_totalmin + EventMesh.publish("home_alarm_event")#该回家了 + + + + #该休息了 + def reset_alarm(self): + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + data = RTC().datetime() + hour = data[4] + min = data[5] + + week = int(data[3]) + + date1 = data[1] + date2 = data[2] + cur_total_min = int(hour)*60+int(min) + # EventMesh.debug_log("self.reset_oldtotalmin",self.reset_oldtotalmin,cur_total_min,self.alarm_flag) + if self.reset_oldtotalmin == 0: + self.reset_oldtotalmin = cur_total_min #549 + if self.reset_oldtotalmin != cur_total_min: #上次响过的闹钟分钟数不等于当前的分钟数据需要清零否则下一个不会响铃 + if self.reset_flag == 1: + self.reset_flag = 0 + self.reset_count = 0 + reset_alarm = [] + reset_alarm = EventMesh.publish("get_storage_config","reset_alarm") + # EventMesh.debug_log("reset_alarm info2",len(reset_alarm),cur_total_min) + if self.reset_flag == 1:#表示闹钟响过清除标志 + self.reset_count+=1 + if self.reset_count > 6: + self.reset_count = 0 + self.reset_flag = 0 + if reset_alarm != None: + if len(str(reset_alarm)) != 0 and str(reset_alarm) != []: + for i in range(len(reset_alarm)): + # print("i",i) + start_hour = int(reset_alarm[i]["start_hour"]) + start_min = int(reset_alarm[i]["start_min"]) + + end_hour = int(reset_alarm[i]["end_hour"]) + end_min = int(reset_alarm[i]["end_min"]) + + # EventMesh.debug_log("reset_alarm home 33",reset_alarm) + + start_totalmin = int(start_hour)*60+int(start_min) + end_totalmin = int(end_hour)*60+int(end_min) + + if start_totalmin == cur_total_min and self.reset_flag == 0:#14:00 + self.reset_flag = 1 + self.reset_count = 0 + self.reset_oldtotalmin = start_totalmin + EventMesh.publish("reset_alarm_event")#该休息了 + break + + if end_totalmin == cur_total_min and self.reset_flag == 0: + self.reset_flag = 1 + self.reset_count = 0 + self.reset_oldtotalmin = end_totalmin + EventMesh.publish("reset_end_alarm_event")#休息结束了 + break + + + def clear_normal_alarm(self,event,msg):#普通闹钟清除标志 + self.normal_flag = 0 + self.normal_count = 0 + self.normal_oldtotalmin = 0 + + def clear_reset_alarm(self,event,msg):#休息清除标志 + self.reset_flag = 0 + self.reset_count = 0 + self.reset_oldtotalmin = 0 + + def clear_home_alarm(self,event,msg):#回家清除标志 + self.home_flag = 0 + self.home_count = 0 + self.home_oldtotalmin = 0 + + + def clear_medicine_alarm(self,event,msg):#吃药清除标志 + self.medicine_count = 0 + self.medicine_flag = 0 + self.medicine_oldtotalmin = 0 + + + def clear_wakeup_alarm(self,event,msg):#起床标识 + self.wakeup_flag = 0 + self.wakeup_count = 0 + self.wakeup_oldtotalmin = 0 + + def clear_sleep_alarm(self,event,msg):#睡觉标识 + + self.sleep_flag = 0 + self.sleep_count = 0 + self.sleep_oldtotalmin = 0 - - pass - # if self.medicine_time == 0: - # self.medicine_time = time_tmp - - # on = EventMesh.publish("get_storage_config","drink_on") - # time = EventMesh.publish("get_storage_config","drink_time") - # print("medicine_time info2",on,time) - # if on != None and time != None: - # if on != 0 and time != 0: - # if (time_tmp - self.medicine_time) >= (time*60*60):#需要转换成小时3600 - # self.medicine_time = time_tmp - # EventMesh.publish("drink_alarm_event")#跌倒报警启动中 - # #该吃药了 - # else: - # self.medicine_time = 0 - # else: - # self.medicine_time = 0 - def get_sim_Status(self, event, msg): return sim.getStatus() def get_device_ope(self, event, msg): @@ -3615,21 +4005,13 @@ class playPowerAudioManager(Abstract):#播放开关机音频文件 class getBootOffManager(Abstract):#开关机时间 def __init__(self): - self.off_msg = {} - self.off_flag = 0 - self.rtc = RTC() - self.off_on = 1 - self.off_start = "6:0" - self.off_end = "23:0" - read_data = EventMesh.publish("get_storage_config","off_on") - if read_data != None: - self.off_on = read_data - read_data = EventMesh.publish("get_storage_config","off_start") + self.poweroff_time = [] + read_data = EventMesh.publish("get_storage_config","poweroff_alarm") if read_data != None: - self.off_start= read_data - read_data = EventMesh.publish("get_storage_config","off_end") - if read_data != None: - self.off_end = read_data + self.poweroff_time = read_data + else: + self.poweroff_time = [{"poweroff_on":1,"start_hour":6,"start_min":0,"end_hour":0,"end_min":0}] + def post_processor_after_instantiation(self): @@ -3638,24 +4020,13 @@ class getBootOffManager(Abstract):#开关机时间 def set_boot_off_time(self, event, 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]]) - self.off_msg = msg + EventMesh.publish("set_storage_config",["poweroff_alarm",msg]) + self.poweroff_time = msg + EventMesh.publish("set_rtc_alarm") def get_boot_off_time(self, event, msg): - self.off_on = EventMesh.publish("get_storage_config","off_on") - self.off_start = EventMesh.publish("get_storage_config","off_start") - self.off_end = EventMesh.publish("get_storage_config","off_end") - if self.off_on == None: - self.off_on = 1 - if self.off_start == None: - self.off_start = "6:0" - - if self.off_end == None: - self.off_end = "23:0" - return [self.off_on,self.off_start,self.off_end] + return self.poweroff_time class setSmsIndexManager(Abstract):# def __init__(self): self.index = -1 @@ -3737,11 +4108,8 @@ class deleteSmsManager(Abstract):#删除信息 sms.deleteMsg(1,4) #闹钟信息 -alarm_list = [ {'hour': 6, 'repeart': 10, 'idx': 0, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0}, - {'hour': 10, 'repeart': 10, 'idx': 1, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 10}, - {'hour': 16, 'repeart': 10, 'idx': 2, 'enabled': 0, 'days': [], 'minute': 39}, - {'hour': 16, 'repeart': 10, 'idx': 3, 'enabled': 0, 'days': [], 'minute': 39}, - {'hour': 16, 'repeart': 10, 'idx': 4, 'enabled': 0, 'days': [], 'minute': 39}] +alarm_list = [{'hour': 6, 'repeart': 10, 'idx': 0, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0}, + {'hour': 0, 'repeart': 10, 'idx': 1, 'enabled': 1, 'days': [0,1,2,3,4,5,6], 'minute': 0}] #用于显示闹钟列表不包含开关机信息 class ClockManager(Abstract): @@ -3769,11 +4137,11 @@ class ClockManager(Abstract): def post_processor_after_instantiation(self): EventMesh.publish("read_alarminjson") - EventMesh.publish("set_rtc_alarm") + # EventMesh.publish("set_rtc_alarm") def update_show_info(self,event,msg): EventMesh.publish("read_alarminjson") - EventMesh.publish("set_rtc_alarm") + # EventMesh.publish("set_rtc_alarm") def get_check_alarm_list(self, event, msg): alarm_len = 0 @@ -3812,7 +4180,7 @@ class ClockManager(Abstract): hour2 = str(alarm_list[1]["hour"])+':'+str(alarm_list[1]["minute"]) # min2 = str(alarm_list[1]["minute"]) - EventMesh.publish("set_boot_off_time",[1,hour1,hour2]) + # EventMesh.publish("set_boot_off_time",[1,hour1,hour2]) EventMesh.debug_log("hour1:{}-{}".format(hour1,hour2)) @@ -3831,7 +4199,7 @@ class ClockManager(Abstract): start_min = int(msg_tmp1[1]) enable = int(msg[0]) EventMesh.debug_log("start_hour:{} start_min:{} enable:{}",start_hour,start_min,enable) - EventMesh.publish("set_boot_off_time",[msg[0],msg[1],msg[2]]) + # EventMesh.publish("set_boot_off_time",[msg[0],msg[1],msg[2]]) alarm_list[i]["idx"]=i alarm_list[i]["hour"]=start_hour @@ -3881,263 +4249,154 @@ class ClockManager(Abstract): return self.idx def _rtc_callback(self,args): - EventMesh.debug_log("---!!!!!!pfff neew alarm_ring!!!!!!!---,idx:",args) - global alarm_list - EventMesh.publish("read_alarminjson") - idx = self.idx - 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"] : - 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") - EventMesh.debug_log("msg_tmp:{}".format(msg_data)) - off_on = 1 - off_start = "6:0" - off_end = "23:0" - if msg_data[0] != None: - off_on = int(msg_data[0]) - if msg_data[1] != None: - off_start = msg_data[1]#开始时间 - - if msg_data[2] != None: - off_end = msg_data[2]#结束时间 - - off_time1 = int(off_start.split(":")[0]) - off_time2 = int(off_start.split(":")[1]) - - start_min = int(off_start.split(":")[0])*60+int(off_start.split(":")[1]) - end_min = int(off_end.split(":")[0])*60+int(off_end.split(":")[1]) - - rtc_now_time = self.rtc.datetime() - current = rtc_now_time[4]*60+rtc_now_time[5] - cur_day = rtc_now_time[3] - 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:#结束的时间分钟等于关机时间分钟数则关机 - ubs_state = EventMesh.publish("get_usb")#' - start_day = 0 # 周日 - end_minute = 60*24*7 - next_minute = off_time1*60+off_time2 #10:11 - current_minute = rtc_now_time[4]*60 + rtc_now_time[5] - - if next_minute >= current_minute:#开机时间大于当前时间 9:00 > = 8:00 - interval_minute = next_minute - current_minute + if msg_data != None: + power_offdata = msg_data[0] + start_hour = int(power_offdata["start_hour"]) + start_min = int(power_offdata["start_min"]) + end_hour = int(power_offdata["end_hour"]) + end_min = int(power_offdata["end_min"]) + off_on = int(power_offdata["poweroff_on"]) + + rtc_now_time = self.rtc.datetime() + current_minute = rtc_now_time[4]*60 + rtc_now_time[5] + end_min_total = end_hour*60+end_min + next_minute = start_hour*60+start_min #10:11 + EventMesh.debug_log("off_on:{} {} {}".format(off_on,current_minute,next_minute)) + if off_on != None: + if off_on == 1: + if end_min_total == current_minute:#结束的时间分钟等于关机时间分钟数则关机 + ubs_state = EventMesh.publish("get_usb")#' + - EventMesh.debug_log("关机距离下一次响铃的的分钟数:", interval_minute,next_minute) - else:#8:00 9:00 - #7*60*24 7天一个周期 7*60*24 - - interval_minute = next_minute + (24*60-current_minute) - EventMesh.debug_log("关机08888距离下一次响铃的的分钟数:", interval_minute,next_minute) - - #反向获取时间戳 - time = utime.localtime() - EventMesh.debug_log("关机09获取utime的时间戳:", time) - rtc_mktime = utime.mktime(time) - EventMesh.debug_log("关机10反向获取utime的mktime:", rtc_mktime) - - #加上下一次响铃需要的时间 - next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳 - EventMesh.debug_log("关机11下一次响铃的mktime:", next_alarm_mktime) - - #格式化时间戳,得到下一次闹钟的时间 - next_alarm_time = utime.localtime(next_alarm_mktime) - EventMesh.debug_log("关机12下一次响铃的准确时间:", next_alarm_time) - #将时间转换为rtc的格式 - data_l = [2021, 7, 9, 5, 12, 30, 0, 0] - #给rtc时间赋值 - data_l[0] = next_alarm_time[0] #year - data_l[1] = next_alarm_time[1] #month - data_l[2] = next_alarm_time[2] #day - data_l[4] = next_alarm_time[3] #hour - data_l[5] = next_alarm_time[4] #minute - data_e=tuple(data_l) - EventMesh.debug_log("关机13将该时间转换为RTC元组:", data_e) - - self.rtc.register_callback(self._rtc_callback) - FLAG = self.rtc.set_alarm(data_e) - if FLAG == 0: - EventMesh.debug_log("开机11成功设置rtc的到期时间:", data_e) - else: - EventMesh.debug_log("开机时设置rtc的到期时间失败:", data_e) - self.rtc.enable_alarm(1) - if ubs_state == 2 or ubs_state == 0: - EventMesh.debug_log("结束时设置rtc的到期时间失败:", data_e) - EventMesh.publish("open_power_on", 5)#静音关机 - return - else: - EventMesh.debug_log("充电关机失败:", data_e) - #self.rtc.datetime([2023, 12, 1, 5, 5, 59, 30, 0]) - return - - EventMesh.publish("set_rtc_alarm") - alarm_flag = 0 - day = [] - enable = 0 - total_min = 0 - if off_on != None: - if off_on == 1: - # 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"]) - day = alarm_list[idx]["days"] - enable = int(alarm_list[idx]["enabled"]) - repeart = int(alarm_list[idx]["repeart"]) - total_min = hour*60+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:#单次闹钟 - if total_min == start_min and enable == 1:#如果闹钟时间和开机时间一致啧响铃否则不响铃 - EventMesh.publish("OPEN_ALARM_RING")#闹钟到点响铃 - alarm_flag = 1# - break - else: - continue - else: - if (cur_day in day) and enable == 1: - if total_min == start_min and enable == 1:#如果闹钟时间和开机时间一致啧响铃否则不响铃 - # EventMesh.debug_log("alarm_ring22222") - EventMesh.publish("OPEN_ALARM_RING")#闹钟到点响铃 - alarm_flag = 1 - break - else: - continue + if next_minute >= current_minute:#开机时间大于当前时间 9:00 > = 8:00 + interval_minute = next_minute - current_minute + + EventMesh.debug_log("开机距离下一次响铃的的分钟数:", interval_minute,next_minute) + else:#8:00 9:00 + #7*60*24 7天一个周期 7*60*24 - + interval_minute = next_minute + (24*60-current_minute) + EventMesh.debug_log("开机08888距离下一次响铃的的分钟数:", interval_minute,next_minute) + + #反向获取时间戳 + time = utime.localtime() + EventMesh.debug_log("开机9获取utime的时间戳:", time) + rtc_mktime = utime.mktime(time)-time[5] + EventMesh.debug_log("开机10反向获取utime的mktime:", rtc_mktime) + + #加上下一次响铃需要的时间 + next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳 + EventMesh.debug_log("开机11下一次响铃的mktime:", next_alarm_mktime) + + #格式化时间戳,得到下一次闹钟的时间 + next_alarm_time = utime.localtime(next_alarm_mktime) + EventMesh.debug_log("开机12下一次响铃的准确时间:", next_alarm_time) + #将时间转换为rtc的格式 + data_l = [2021, 7, 9, 5, 12, 30, 0, 0] + #给rtc时间赋值 + data_l[0] = next_alarm_time[0] #year + data_l[1] = next_alarm_time[1] #month + data_l[2] = next_alarm_time[2] #day + data_l[4] = next_alarm_time[3] #hour + data_l[5] = next_alarm_time[4] #minute + data_e=tuple(data_l) + EventMesh.debug_log("开机13将该时间转换为RTC元组:", data_e) + + self.rtc.register_callback(self._rtc_callback) + + FLAG = self.rtc.set_alarm(data_e) + if FLAG == 0: + EventMesh.debug_log("开机11成功设置rtc的到期时间:", data_e) else: - continue - else: - alarm_flag = 0 - # 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.debug_log("开机时设置rtc的到期时间失败:", data_e) + self.rtc.enable_alarm(1) + if ubs_state == 2 or ubs_state == 0: + EventMesh.debug_log("结束时设置rtc的到期时间失败:", data_e) + EventMesh.publish("open_power_on", 5)#静音关机 + return + else: + EventMesh.debug_log("充电关机失败:", data_e) + #self.rtc.datetime([2023, 12, 1, 5, 5, 59, 30, 0]) + return + + EventMesh.publish("set_rtc_alarm") def set_rtc_alarm(self,event,msg): - global alarm_list - EventMesh.publish("read_alarminjson") - rtc_now_time = self.rtc.datetime() - - # 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']] - - 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: - EventMesh.debug_log("02当前并没有开启的闹钟,退出闹钟设置程序:{}".format(new_alarm_list)) - self.rtc.enable_alarm(0) - return - - for alarm in new_alarm_list: - hour, minute, days,idx = alarm - #如果没有选择day,则表示是单次闹钟 - if days: - for day in days: - minute_list.append(hour*60 + minute + (day-start_day)*24*60) - + msg_data = EventMesh.publish("get_boot_off_time") + if msg_data != None: + power_offdata = msg_data[0] + start_hour = power_offdata["start_hour"] + start_min = power_offdata["start_min"] + end_hour = power_offdata["end_hour"] + end_min = power_offdata["end_min"] + + next_minute = start_hour*60+start_min #10:11 + + start_total = start_hour*60+start_min #10:11 + end_total = end_hour*60+end_min #10:11 + rtc_now_time = self.rtc.datetime() + current_minute = rtc_now_time[4]*60 + rtc_now_time[5]#当前时间 + + minute_list = [] + minute_list.append(start_total)#23*60= + minute_list.append(end_total) + minute_list.append(current_minute)#[460,480,340] + minute_list = sorted(minute_list) + current_index = minute_list.index(current_minute) + # print("minute_list",minute_list,start_total,end_total,current_index,power_offdata) + + + next_index = current_index + 1 + if next_index >= len(minute_list): + next_minute = minute_list[0] + print("07下一个闹钟的分钟数:", next_minute) else: - #如果当前时间没超过闹钟设置时间,则设置为今天,否则设置为明天 - 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) - EventMesh.debug_log("设置单次闹钟:{}".format(new_alarm_list)) + next_minute = minute_list[next_index] + print("07下一个闹钟的分钟数:", next_minute) - else: - minute_list.append(hour*60 + minute + (rtc_now_time[3]-start_day+1)*24*60) - - total_minutes = sorted(minute_list) - 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() - - 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 - EventMesh.debug_log("04当前的rtc_total_minutes:{}".format(current_minute)) - - if current_minute in minute_list: - 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) - - 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] - EventMesh.debug_log("0744下一个闹钟的分钟数:", next_minute) - else: - next_minute = minute_list[next_index] - EventMesh.debug_log("0744下一个闹钟的分钟数:", next_minute) + if next_minute >= current_minute: + interval_minute = next_minute - current_minute + print("08距离下一次响铃的的分钟数:", interval_minute) + else: + interval_minute = (24*60 - current_minute) + next_minute + print("08距离下一次响铃的的分钟数:", interval_minute) + + + #反向获取时间戳 + time = utime.localtime() + EventMesh.debug_log("关机09获取utime的时间戳:", time) + time + rtc_mktime = utime.mktime(time)-time[5] + EventMesh.debug_log("关机10反向获取utime的mktime:", rtc_mktime) + + #加上下一次响铃需要的时间 + next_alarm_mktime = rtc_mktime + interval_minute*60 #转换成s单位 时间戳 + EventMesh.debug_log("关机11下一次响铃的mktime:", next_alarm_mktime) + + #格式化时间戳,得到下一次闹钟的时间 + next_alarm_time = utime.localtime(next_alarm_mktime) + EventMesh.debug_log("关机12下一次响铃的准确时间:", next_alarm_time) + #将时间转换为rtc的格式 + data_l = [2021, 7, 9, 5, 12, 30, 0, 0] + #给rtc时间赋值 + data_l[0] = next_alarm_time[0] #year + data_l[1] = next_alarm_time[1] #month + data_l[2] = next_alarm_time[2] #day + data_l[4] = next_alarm_time[3] #hour + data_l[5] = next_alarm_time[4] #minute + data_e=tuple(data_l) + EventMesh.debug_log("关机13将该时间转换为RTC元组:", data_e) + + self.rtc.register_callback(self._rtc_callback) - if next_minute >= current_minute: - interval_minute = next_minute - current_minute - EventMesh.debug_log("08666距离下一次响铃的的分钟数:", interval_minute) - else: - #7*60*24 7天一个周期 7*60*24 - - interval_minute = end_minute - current_minute + next_minute - EventMesh.debug_log("08888距离下一次响铃的的分钟数:", interval_minute) - - #反向获取时间戳 - time = utime.localtime() - EventMesh.debug_log("09获取utime的时间戳:", time) - rtc_mktime = utime.mktime(time) - EventMesh.debug_log("10反向获取utime的mktime:", rtc_mktime) - - #加上下一次响铃需要的时间 - next_alarm_mktime = rtc_mktime + interval_minute*60 - EventMesh.debug_log("11下一次响铃的mktime:", next_alarm_mktime) - - #格式化时间戳,得到下一次闹钟的时间 - next_alarm_time = utime.localtime(next_alarm_mktime) - EventMesh.debug_log("12下一次响铃的准确时间:", next_alarm_time) - #将时间转换为rtc的格式 - data_l = [2021, 7, 9, 5, 12, 30, 0, 0] - #给rtc时间赋值 - data_l[0] = next_alarm_time[0] #year - data_l[1] = next_alarm_time[1] #month - data_l[2] = next_alarm_time[2] #day - data_l[4] = next_alarm_time[3] #hour - data_l[5] = next_alarm_time[4] #minute - #转换为元组 - data_e=tuple(data_l) - EventMesh.debug_log("13将该时间转换为RTC元组:", data_e) - - for alarm in alarm_list: - if not alarm["days"] and alarm["enabled"]: - EventMesh.debug_log("关闭666:",alarm["idx"]) - if alarm["hour"] == data_l[4] and alarm["minute"]==data_l[5]: - self.idx = alarm["idx"] - #设置rtc闹钟时间 - self.rtc.register_callback(self._rtc_callback) - - FLAG = self.rtc.set_alarm(data_e) - if FLAG == 0: - EventMesh.debug_log("14成功设置rtc的到期时间:", data_e) - else: - EventMesh.debug_log("14设置rtc的到期时间失败:", data_e) - - self.rtc.enable_alarm(1) - + FLAG = self.rtc.set_alarm(data_e) + if FLAG == 0: + EventMesh.debug_log("关机11成功设置rtc的到期时间:", data_e) + else: + EventMesh.debug_log("关机时设置rtc的到期时间失败:", data_e) + self.rtc.enable_alarm(1) + diff --git a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/protocol.py b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/protocol.py index 33ea9ab6..74f120fa 100644 --- a/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/protocol.py +++ b/2.sdk/project/D10/sdk/services/microPython/ports/quectel/core/protocol.py @@ -816,137 +816,215 @@ class WT_ProtoCol(ProtoCol): EventMesh.publish("set_weather_data",[msg_date,msg_time,msg_weather_content,msg_type,msg_temp,msg_min_temp,msg_max_temp,msg_city,1]) EventMesh.publish("updata_weather_show") - - -class REMIND_ProtoCol(ProtoCol): - """闹钟数据""" +class REMIND_ProtoCol(ProtoCol):#普通闹钟 + """ + + 平台发送: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND,,时间1-开关,时间2-开关,周几] + 实例:[XT*334588000000156*0008*REMIND,,时间1-开关,时间2-开关,周几] + 终端回复: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND] + """ TYPE = "REMIND" - - + def send(self, event, msg): - # [SZKW*867387060319491*0008*REMIND] send_data = self.PID+"*%s*0006*REMIND"%(self.imei) MD5_SIGN = self.pack_MD5_head(send_data) data = "[%s%s]"%(str(MD5_SIGN),send_data) - # EventMesh.debug_log("REMIND_ProtoCol:send:%s"%(data)) + #Wechat_log("POWEROFF_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' - # EventMesh.debug_log("REMIND_ProtoCol RECV msg:%s"%(msg)) - alarm_new = [] - + # SZKW*860132060346475*0013*REMIND_CH_MEDICINE2,4-1 msg = msg[1:-1] msg_tmp = msg.decode('ascii') - msg_tmp = msg_tmp.split('REMIND,') - msg_tmp = msg_tmp[1] - - alarm_new = EventMesh.publish("read_alarminjson") - EventMesh.debug_log("alarm_new start:{}",alarm_new) - k=1 + msg_tmp_new = msg_tmp.split('REMIND,')[1] count = 0 - if len(msg_tmp) == 0: - for j in range(2,5):#0 1是开关机,234是闹钟#5-1 0 1 2 3 4 5-1 = 4 3 4 k = 1 1+2+j = - alarm_new[j+2]["idx"] = 2+j - alarm_new[j+2]["hour"] = 16 - alarm_new[j+2]["minute"] = 16 - alarm_new[j+2]["days"] = [] - alarm_new[j+2]["enabled"] = 0 - alarm_new[j+2]["repeart"] = 10 - else: - for i in range(len(str(msg_tmp))):#寻找有多少个,号 - if msg_tmp[i] == ',':#, , , - k+=1 - # if len(alarm_new) > 2: - # for i in range(0,len(alarm_new)-2): - # # EventMesh.debug_log("alarm_new_tmp",alarm_new) - # del alarm_new[2] - # EventMesh.debug_log("alarm_new:{}",alarm_new) - for j in range(2,2+k):#0 1是开关机,234是闹钟 - EventMesh.debug_log("j",j,j+2,2+k,k) - if j > 4: - break - alarm_day = [] - alarm_week = [] - alarm_total_data = [] - # EventMesh.debug_log("j!!!!!!!!!!",j) - if k == 1: - if len(msg_tmp) != 0: - alarm_data = msg_tmp.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: - alarm_week = alarm_data[3]#星期 - - if alarm_day_num == 2:#每一天 - alarm_day = [1,2,3,4,5,6,0] - elif alarm_day_num == 3:#自定义 + for i in str(msg_tmp_new): + # print("i",i) + if i == ",": + count+=1 + + if count != 0: + count+=1 + normal_alarm_save = [] + # # ("handler -> b'[SZKW*860132060346475*001C*REMIND,08:00-1-1,,]'",) + # b'[SZKW*860132060346475*001B*REMIND,08:00-1-1,,]'",) + # medicine_alarmday = str(msg_data[4]) + # alarmday=[] + alarm_day = [] + alarm_switch = 0 + + print("count",count,msg_tmp_new) + if count >= 3: + count = 3 + for i in range(0,count):#默认是三个时间多了也不保存 + alarm_day = [] + alarm_data = str(msg_tmp_new.split(',')[i]) + # print("i",i,sleep_data) + if len(alarm_data) != 0: + b = alarm_data.find('-') + if b != -1: + alarm_time = alarm_data.split('-')[0]#-作为分隔符 + alarm_switch = int(alarm_data.split('-')[1])#开关 + alarm_repeat = int(alarm_data.split('-')[2])#是单次还是每天 还是自定义 + + alarm_hour = int(alarm_time.split(":")[0])#时间 + alarm_min = int(alarm_time.split(":")[1])#冒号分隔时间 时 分 + + + if alarm_repeat == 2:#每一天 + alarm_day = [0,1,2,3,4,5,6] + elif alarm_repeat == 3:#自定义 + alarm_day_tmp = alarm_data.split('-')[3]#-作为分隔符 + if len(str(alarm_day_tmp)) != 0: for i in range(0,7): - if alarm_week[i] != '0': + if alarm_day_tmp[i] != '0': alarm_day.append(i) - alarm_new[j]["idx"] = j - alarm_new[j]["hour"] = alarm_time_hour - alarm_new[j]["minute"] = alarm_time_min - alarm_new[j]["days"] = alarm_day - alarm_new[j]["enabled"] = alarm_switch - alarm_new[j]["repeart"] = alarm_day_num - # alarm_new.append({"idx": j, "hour": alarm_time_hour, "minute": alarm_time_min, "days":alarm_day, "enabled": alarm_switch,"repeart":alarm_day_num}) - else: - if len(msg_tmp) != 0: - alarm_total_data = msg_tmp.split(',')[count] - count+=1 - if len(alarm_total_data) > 0: - b = alarm_total_data.find('-') - if b != -1: - alarm_data = 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: - alarm_week = alarm_data[3]#星期 - - if alarm_day_num == 2:#每一天 - alarm_day = [1,2,3,4,5,6,0] - elif alarm_day_num == 3:#自定义 - for i in range(0,7): - if alarm_week[i] != '0': - alarm_day.append(i) - EventMesh.debug_log("j+2",j+2) - alarm_new[j]["idx"] = j - alarm_new[j]["hour"] = alarm_time_hour - alarm_new[j]["minute"] = alarm_time_min - alarm_new[j]["days"] = alarm_day - alarm_new[j]["enabled"] = alarm_switch - alarm_new[j]["repeart"] = alarm_day_num - # alarm_new.append({"idx": j, "hour": alarm_time_hour, "minute": alarm_time_min, "days":alarm_day, "enabled": alarm_switch,"repeart":alarm_day_num}) + else:#单次 1 + alarm_day=[] + if alarm_switch != 0: + normal_alarm_save.append({"hour":alarm_hour,"min":alarm_min,"day":alarm_day,"enable":alarm_switch}) + + EventMesh.publish("set_storage_config",["normal_alarm",normal_alarm_save]) + normal_alarm = EventMesh.publish("get_storage_config","normal_alarm") + + EventMesh.debug_log("recv REMIND_SEND:{} normal_alarm ;{}".format(msg,normal_alarm)) + + EventMesh.publish(constants.PROTOCOL.REMIND_SEND) + EventMesh.publish("clear_normal_alarm") + + +# class REMIND_ProtoCol(ProtoCol): +# """闹钟数据""" +# TYPE = "REMIND" + + +# def send(self, event, msg): +# # [SZKW*867387060319491*0008*REMIND] +# send_data = self.PID+"*%s*0006*REMIND"%(self.imei) +# MD5_SIGN = self.pack_MD5_head(send_data) +# data = "[%s%s]"%(str(MD5_SIGN),send_data) +# # EventMesh.debug_log("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' +# # EventMesh.debug_log("REMIND_ProtoCol RECV msg:%s"%(msg)) +# alarm_new = [] + +# msg = msg[1:-1] +# msg_tmp = msg.decode('ascii') +# msg_tmp = msg_tmp.split('REMIND,') +# msg_tmp = msg_tmp[1] + +# alarm_new = EventMesh.publish("read_alarminjson") +# EventMesh.debug_log("alarm_new start:{}",alarm_new) +# k=1 +# count = 0 +# if len(msg_tmp) == 0: +# for j in range(2,5):#0 1是开关机,234是闹钟#5-1 0 1 2 3 4 5-1 = 4 3 4 k = 1 1+2+j = +# alarm_new[j+2]["idx"] = 2+j +# alarm_new[j+2]["hour"] = 16 +# alarm_new[j+2]["minute"] = 16 +# alarm_new[j+2]["days"] = [] +# alarm_new[j+2]["enabled"] = 0 +# alarm_new[j+2]["repeart"] = 10 +# else: +# for i in range(len(str(msg_tmp))):#寻找有多少个,号 +# if msg_tmp[i] == ',':#, , , +# k+=1 +# # if len(alarm_new) > 2: +# # for i in range(0,len(alarm_new)-2): +# # # EventMesh.debug_log("alarm_new_tmp",alarm_new) +# # del alarm_new[2] +# # EventMesh.debug_log("alarm_new:{}",alarm_new) +# for j in range(2,2+k):#0 1是开关机,234是闹钟 +# EventMesh.debug_log("j",j,j+2,2+k,k) +# if j > 4: +# break +# alarm_day = [] +# alarm_week = [] +# alarm_total_data = [] +# # EventMesh.debug_log("j!!!!!!!!!!",j) +# if k == 1: +# if len(msg_tmp) != 0: +# alarm_data = msg_tmp.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: +# alarm_week = alarm_data[3]#星期 + +# if alarm_day_num == 2:#每一天 +# alarm_day = [1,2,3,4,5,6,0] +# elif alarm_day_num == 3:#自定义 +# for i in range(0,7): +# if alarm_week[i] != '0': +# alarm_day.append(i) +# alarm_new[j]["idx"] = j +# alarm_new[j]["hour"] = alarm_time_hour +# alarm_new[j]["minute"] = alarm_time_min +# alarm_new[j]["days"] = alarm_day +# alarm_new[j]["enabled"] = alarm_switch +# alarm_new[j]["repeart"] = alarm_day_num +# # alarm_new.append({"idx": j, "hour": alarm_time_hour, "minute": alarm_time_min, "days":alarm_day, "enabled": alarm_switch,"repeart":alarm_day_num}) +# else: +# if len(msg_tmp) != 0: +# alarm_total_data = msg_tmp.split(',')[count] +# count+=1 +# if len(alarm_total_data) > 0: +# b = alarm_total_data.find('-') +# if b != -1: +# alarm_data = 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: +# alarm_week = alarm_data[3]#星期 + +# if alarm_day_num == 2:#每一天 +# alarm_day = [1,2,3,4,5,6,0] +# elif alarm_day_num == 3:#自定义 +# for i in range(0,7): +# if alarm_week[i] != '0': +# alarm_day.append(i) +# EventMesh.debug_log("j+2",j+2) +# alarm_new[j]["idx"] = j +# alarm_new[j]["hour"] = alarm_time_hour +# alarm_new[j]["minute"] = alarm_time_min +# alarm_new[j]["days"] = alarm_day +# alarm_new[j]["enabled"] = alarm_switch +# alarm_new[j]["repeart"] = alarm_day_num +# # alarm_new.append({"idx": j, "hour": alarm_time_hour, "minute": alarm_time_min, "days":alarm_day, "enabled": alarm_switch,"repeart":alarm_day_num}) - EventMesh.debug_log("alarm_new end:{}",alarm_new) - for j in range(2,5-k):#0 1是开关机,234是闹钟#5-1 0 1 2 3 4 5-1 = 4 3 4 k = 1 1+2+j = - alarm_new[j+k]["idx"] = k+j - alarm_new[j+k]["hour"] = 16 - alarm_new[j+k]["minute"] = 16 - alarm_new[j+k]["days"] = [] - alarm_new[j+k]["enabled"] = 0 - alarm_new[j+k]["repeart"] = 10 - - with open("/usr/static/storage_file/alarm_msg.json", 'w',encoding='utf-8') as fd: - ujson.dump(alarm_new,fd) - EventMesh.publish("push_update_alarm_show") +# EventMesh.debug_log("alarm_new end:{}",alarm_new) +# for j in range(2,5-k):#0 1是开关机,234是闹钟#5-1 0 1 2 3 4 5-1 = 4 3 4 k = 1 1+2+j = +# alarm_new[j+k]["idx"] = k+j +# alarm_new[j+k]["hour"] = 16 +# alarm_new[j+k]["minute"] = 16 +# alarm_new[j+k]["days"] = [] +# alarm_new[j+k]["enabled"] = 0 +# alarm_new[j+k]["repeart"] = 10 + +# with open("/usr/static/storage_file/alarm_msg.json", 'w',encoding='utf-8') as fd: +# ujson.dump(alarm_new,fd) +# EventMesh.publish("push_update_alarm_show") - # EventMesh.publish("add_alarm",[0,msg_tmp]) - EventMesh.publish(constants.PROTOCOL.REMIND_SEND) +# # EventMesh.publish("add_alarm",[0,msg_tmp]) +# EventMesh.publish(constants.PROTOCOL.REMIND_SEND) @@ -1491,12 +1569,19 @@ class bootoff_ProtoCol(ProtoCol): msg = msg[1:-1] msg_tmp = msg.decode('ascii') msg_tmp = msg_tmp.split(',') - on_bt = msg_tmp[1] - on_start = msg_tmp[2] - on_end = msg_tmp[3] - EventMesh.debug_log("BOOTOFF:send data:{} {} {}".format(on_bt,on_start,on_end)) + on_bt = int(msg_tmp[1]) + start_hour = int(str(msg_tmp[2]).split(":")[0]) + start_min = int(str(msg_tmp[2]).split(":")[1]) + + end_hour = int(str(msg_tmp[3]).split(":")[0]) + end_min = int(str(msg_tmp[3]).split(":")[1]) + + EventMesh.debug_log("BOOTOFF:send data:",on_bt,start_hour,start_min,end_hour,end_min) + poweroff = [] + poweroff.append({"poweroff_on":on_bt,"start_hour":start_hour,"start_min":start_min,"end_hour":end_hour,"end_min":end_min}) #b'[SZKW*860132060006970*0015*BOOTOFF,1,06:00,23:59]' - EventMesh.publish("add_alarm", [on_bt,on_start,on_end]) + EventMesh.publish("set_boot_off_time",poweroff)#设置关机时间 + EventMesh.publish(constants.PROTOCOL.BOOTOFF_SEND) @@ -1748,7 +1833,8 @@ class TK_ProtoCol(ProtoCol): read_AMR_flag = msg_tmp.find("#!AMR") #EventMesh.debug_log("TK recv:read_AMR_flag:{} ,{}".format(read_AMR_flag,EventMesh.publish("get_wechat_record_flag"))) - if EventMesh.publish("get_wechat_record_flag") != 1 and read_AMR_flag != -1: #是否是服务器下发音频数据 + # if EventMesh.publish("get_wechat_record_flag") != 1 and read_AMR_flag != -1: #是否是服务器下发音频数据 + if read_AMR_flag != -1: #是否是服务器下发音频数据 # Wechat_log("TK_ProtoCol:recv:datalen{}".format(len(msg))) arm_data = bytearray(str[1])#获取amr输出 get_wechat_data = EventMesh.publish("get_wechat_data") @@ -1872,7 +1958,8 @@ class TKS_ProtoCol(ProtoCol): str = msg_tmp.split('TKS,') # Wechat_log("TK_ProtoCol:recv:len:{} {} {}".format(len(msg),len(str),msg_tmp.find("#!AMR"))) read_AMR_flag = msg_tmp.find("#!AMR") - if EventMesh.publish("get_wechat_record_flag") != 1 and read_AMR_flag != -1: #是否是服务器下发音频数据 + # if EventMesh.publish("get_wechat_record_flag") != 1 and read_AMR_flag != -1: #是否是服务器下发音频数据 + if read_AMR_flag != -1: #是否是服务器下发音频数据 # Wechat_log("TK_ProtoCol:recv:datalen{}".format(len(msg))) arm_data = bytearray(str[1])#获取amr输出 get_wechat_data = EventMesh.publish("get_wechat_data") @@ -2146,12 +2233,12 @@ class REMIND_CHMEDICINE2_ProtoCol(ProtoCol):#吃药提醒 [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_MEDICINE2,,时间1-开关,时间2-开关,周几] 实例:[XT*334588000000156*0008*REMIND_CH_MEDICINE2,,时间1-开关,时间2-开关,周几] 终端回复: - [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_DRINK] + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_MEDICINE2] """ TYPE = "REMIND_CH_MEDICINE2" def send(self, event, msg): - send_data = self.PID+"*%s*00013*REMIND_CH_MEDICINE2"%(self.imei) + send_data = self.PID+"*%s*0013*REMIND_CH_MEDICINE2"%(self.imei) MD5_SIGN = self.pack_MD5_head(send_data) data = "[%s%s]"%(str(MD5_SIGN),send_data) #Wechat_log("POWEROFF_ProtoCol:send:%s"%(data)) @@ -2162,77 +2249,343 @@ class REMIND_CHMEDICINE2_ProtoCol(ProtoCol):#吃药提醒 # SZKW*860132060346475*0013*REMIND_CH_MEDICINE2,4-1 msg = msg[1:-1] msg_tmp = msg.decode('ascii') - msg_data = msg_tmp.split(',') + msg_data = msg_tmp.split('REMIND_CH_MEDICINE2,')[1] medicin_data = [] - - medicine_alarmday = str(msg_data[4]) alarmday=[] - - for i in range(1,4):#默认是三个时间多了也不保存 - print("i",i) - medicine_alarm = str(msg_data[i]) - on = int(medicine_alarm.split('-')[1]) - if on != 0: - alarmday = [] - data = str(medicine_alarm.split('-')[0]) - hour = int(data.split(":")[0]) - min = int(data.split(":")[1]) - for i in range(0,7): - print("medicine_alarmday",medicine_alarmday,medicine_alarmday[i]) - if medicine_alarmday[i] != '0': - alarmday.append(i) - enable = 1 - medicin_data.append({"hour":hour,"min":min,"day":alarmday,"enable":enable}) + count = 0 + for i in str(msg_data): + # print("i",i) + if i == ",": + count+=1 + if count >= 3: + count = 3 + medicine_alarmday = [] + for i in range(0,count):#默认是三个时间多了也不保存 + medicine_alarmday = str(msg_data.split(",")[count]) + # print("i",i) + medicine_alarm = str(msg_data.split(",")[i]) + if str(medicine_alarm).find("-") != -1: + on = int(medicine_alarm.split('-')[1]) + if on != 0: + alarmday = [] + data = str(medicine_alarm.split('-')[0]) + hour = int(data.split(":")[0]) + min = int(data.split(":")[1]) + for i in range(0,7): + # print("medicine_alarmday",medicine_alarmday,medicine_alarmday[i]) + if medicine_alarmday[i] != '0': + alarmday.append(i) + enable = 1 + medicin_data.append({"hour":hour,"min":min,"day":alarmday,"enable":enable}) EventMesh.publish("set_storage_config",["medicine",medicin_data]) - medicine = EventMesh.publish("get_storage_config","medicine") - print("get medicine",medicine,type(medicine)) - - # medicine_alarm1 = str(msg_data[1]) - # on1 = int(medicine_alarm1.split('-')[1]) - # if on1 != 0: - # data = str(medicine_alarm1.split('-')[0]) - # hour = int(data.split(":")[0]) - # min = int(data.split(":")[1]) - # for i in range(0,7): - # if medicine_alarmday[i] != '0': - # alarmday.append(i) - # enable = 1 - # medicin_data.append({"hour":hour,"min":min,"day":alarmday,"enable":enable}) - - # medicine_alarm2 = str(msg_data[2]) - # on2 = int(medicine_alarm2.split('-')[1]) - # if on2 != 0: - # alarmday = [] - # data = str(medicine_alarm2.split('-')[0]) - # hour = int(data.split(":")[0]) - # min = int(data.split(":")[1]) - # for i in range(0,7): - # if medicine_alarmday[i] != '0': - # alarmday.append(i) - # enable = 1#1是重复 0单次 - # medicin_data.append({"hour":hour,"min":min,"day":alarmday,"enable":enable}) - - # medicine_alarm3 = str(msg_data[3]) - # on3 = int(medicine_alarm3.split('-')[1]) - # if on3 != 0: - # alarmday = [] - # data = str(medicine_alarm3.split('-')[0]) - # hour = int(data.split(":")[0]) - # min = int(data.split(":")[1]) - # for i in range(0,7): - # if medicine_alarmday[i] != '0': - # alarmday.append(i) - # enable = 1#1是重复 0单次 - - # medicin_data.append({"hour":hour,"min":min,"day":alarmday,"enable":enable}) + EventMesh.debug_log("recv REMIND_CH_MEDICINE2:{} medicin_data ;{}".format(msg,medicin_data)) + + EventMesh.publish(constants.PROTOCOL.REMIND_CH_MEDICINE2_SEND) + EventMesh.publish("clear_medicine_alarm") + +# 回家闹钟设置指令 +# 可设置闹钟的提醒文字 +# 平台发送: +# [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_HOME,闹钟1,闹钟2,闹钟3] +# 实例: +# [XT*334588000000156*0018*REMIND_CH_HOME,08:10,12:10] +# 终端回复: +# [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_HOME] +# 实例:[XT*334588000000156*0006*REMIND_CH_HOME] +# 说明:闹钟为时间点; +class REMIND_CH_HOME_ProtoCol(ProtoCol):#回家提醒 + """ + + 平台发送: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_HOME,,时间1-开关,时间2-开关,周几] + 实例:[XT*334588000000156*0008*REMIND_CH_HOME,,时间1-开关,时间2-开关,周几] + 终端回复: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_HOME] + """ + TYPE = "REMIND_CH_HOME" + + def send(self, event, msg): + send_data = self.PID+"*%s*000E*REMIND_CH_HOME"%(self.imei) + MD5_SIGN = self.pack_MD5_head(send_data) + data = "[%s%s]"%(str(MD5_SIGN),send_data) + #Wechat_log("POWEROFF_ProtoCol:send:%s"%(data)) + # 通过socket发送到服务器端 + EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data) + + def recv(self, event, msg): + # SZKW*860132060346475*0013*REMIND_CH_MEDICINE2,4-1 + msg = msg[1:-1] + msg_tmp = msg.decode('ascii') + msg_data = msg_tmp.split(',') + + # [SZKW*860132060346475*0014*REMIND_CH_HOME,00:00',) + home_data = str(msg_data[1]) + + EventMesh.debug_log("recv REMIND_CH_HOME:{} medicin_data ;{}".format(msg,home_data)) + if len(home_data) != 0: + EventMesh.publish("set_storage_config",["home_alarm",home_data]) + EventMesh.publish("clear_home_alarm") + EventMesh.publish(constants.PROTOCOL.REMIND_CH_HOME_SEND) +# 起床闹钟设置指令 +# 平台发送: +# [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_WAKEUP,闹钟1,闹钟2] +# 实例: +# [XT*334588000000156*0026*REMIND_CH_WAKEUP,08:10-0-3-1000001,09:10-0-3-1000001] +# 闹钟格式为:时间-开关-频率(1:一次;2:每天;3:自定义) +# 08:10-1-1:闹钟时间8:10,打开,响铃一次 +# 08:10-1-2:闹钟时间8:10,打开,每天响铃 +# 08:10-1-3-0111110:闹钟时间8:10,打开,自定义周一至周五打开 +# 最左边是周日,最右边是周六,即0111110的顺序是:周日,周一,周二,周三,周四,周五,周六(1为打开,0为关闭),其中周一至周五打开闹钟 +# 终端回复: +# [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_WAKEUP] +# 实例:[XT*334588000000156*000E*REMIND_CH_WAKEUP] +# 说明:闹铃格式为:时间-开关-周几(周六到周日) +class REMIND_CH_WAKEUP_ProtoCol(ProtoCol):#该起床了 + """ + + 平台发送: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_WAKEUP,,时间1-开关,时间2-开关,周几] + 实例:[XT*334588000000156*0008*REMIND_CH_WAKEUP,,时间1-开关,时间2-开关,周几] + 终端回复: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_WAKEUP] + """ + TYPE = "REMIND_CH_WAKEUP" + + def send(self, event, msg): + send_data = self.PID+"*%s*0011*REMIND_CH_WAKEUP"%(self.imei) + MD5_SIGN = self.pack_MD5_head(send_data) + data = "[%s%s]"%(str(MD5_SIGN),send_data) + #Wechat_log("POWEROFF_ProtoCol:send:%s"%(data)) + # 通过socket发送到服务器端 + EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data) + + def recv(self, event, msg): + # SZKW*860132060346475*0013*REMIND_CH_MEDICINE2,4-1 + msg = msg[1:-1] + msg_tmp = msg.decode('ascii') + msg_tmp_new = msg_tmp.split('REMIND_CH_WAKEUP,')[1] + count = 0 + for i in str(msg_tmp_new): + # print("i",i) + if i == ",": + count+=1 + wakeup_data_save = [] + # # ("handler -> b'[SZKW*860132060346475*001C*REMIND_CH_WAKEUP,08:00-1-1,,]'",) + # medicine_alarmday = str(msg_data[4]) + # alarmday=[] + wakeup_day = [] + wakeup_switch = 0 + if count != 0: + count += 1 + + print("count",count) + if count >= 3: + count = 3 + for i in range(0,count):#默认是三个时间多了也不保存 + wakeup_day = [] + wakeup_data = str(msg_tmp_new.split(',')[i]) + # print("i",i,wakeup_data) + if len(wakeup_data) != 0: + b = wakeup_data.find('-') + if b != -1: + wakeup_time = wakeup_data.split('-')[0]#-作为分隔符 + wakeup_switch = int(wakeup_data.split('-')[1])#开关 + wakeup_repeat = int(wakeup_data.split('-')[2])#是单次还是每天 还是自定义 + + wakeup_hour = int(wakeup_time.split(":")[0])#时间 + wakeup_min = int(wakeup_time.split(":")[1])#冒号分隔时间 时 分 + + + if wakeup_repeat == 2:#每一天 + wakeup_day = [0,1,2,3,4,5,6] + elif wakeup_repeat == 3:#自定义 + wakeup_day_tmp = wakeup_data.split('-')[3]#-作为分隔符 + for i in range(0,7): + if wakeup_day_tmp[i] != '0': + wakeup_day.append(i) + else:#单次 1 + wakeup_day=[] + if wakeup_switch != 0: + wakeup_data_save.append({"hour":wakeup_hour,"min":wakeup_min,"day":wakeup_day,"enable":wakeup_switch}) + EventMesh.publish("set_storage_config",["wakeup_alarm",wakeup_data_save]) + wakeup = EventMesh.publish("get_storage_config","wakeup_alarm") + EventMesh.debug_log("recv REMIND_CH_WAKEUP:{} wakeup ;{}".format(msg,wakeup)) + + EventMesh.publish(constants.PROTOCOL.REMIND_CH_WAKEUP_SEND) + + EventMesh.publish("clear_wakeup_alarm") - EventMesh.debug_log("recv REMIND_CH_MEDICINE2:{} medicin_data ;{}".format(msg,medicin_data)) + + +# 睡觉闹钟设置指令 +# 平台发送: +# [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_SLEEP,闹钟1,闹钟2] +# 实例: +# [XT*334588000000156*0026*REMIND_CH_SLEEP,08:10-0-3-1000001,09:10-0-3-1000001] +# 闹钟格式为:时间-开关-频率(1:一次;2:每天;3:自定义) +# 08:10-1-1:闹钟时间8:10,打开,响铃一次 +# 08:10-1-2:闹钟时间8:10,打开,每天响铃 +# 08:10-1-3-0111110:闹钟时间8:10,打开,自定义周一至周五打开 +# 最左边是周日,最右边是周六,即0111110的顺序是:周日,周一,周二,周三,周四,周五,周六(1为打开,0为关闭),其中周一至周五打开闹钟 +# 终端回复: +# [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_SLEEP] +# 实例:[XT*334588000000156*000E*REMIND_CH_SLEEP] +# 说明:闹铃格式为:时间-开关-周几(周六到周日) +class REMIND_CH_SLEEP_ProtoCol(ProtoCol):#该睡觉了 + """ + + 平台发送: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_SLEEP,,时间1-开关,时间2-开关,周几] + 实例:[XT*334588000000156*0008*REMIND_CH_SLEEP,,时间1-开关,时间2-开关,周几] + 终端回复: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_SLEEP] + """ + TYPE = "REMIND_CH_SLEEP" + + def send(self, event, msg): + send_data = self.PID+"*%s*0011*REMIND_CH_SLEEP"%(self.imei) + MD5_SIGN = self.pack_MD5_head(send_data) + data = "[%s%s]"%(str(MD5_SIGN),send_data) + #Wechat_log("POWEROFF_ProtoCol:send:%s"%(data)) + # 通过socket发送到服务器端 + EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data) + + def recv(self, event, msg): + # SZKW*860132060346475*0013*REMIND_CH_MEDICINE2,4-1 + msg = msg[1:-1] + msg_tmp = msg.decode('ascii') + msg_tmp_new = msg_tmp.split('REMIND_CH_SLEEP,')[1] + count = 0 + for i in str(msg_tmp_new): + # print("i",i) + if i == ",": + count+=1 + + if count != 0: + count+=1 + sleep_data_save = [] + # # ("handler -> b'[SZKW*860132060346475*001C*REMIND_CH_SLEEP,08:00-1-1,,]'",) + # b'[SZKW*860132060346475*001B*REMIND_CH_SLEEP,08:00-1-1,,]'",) + # medicine_alarmday = str(msg_data[4]) + # alarmday=[] + sleep_day = [] + sleep_switch = 0 + + print("count",count) + if count >= 3: + count = 3 + for i in range(0,count):#默认是三个时间多了也不保存 + sleep_day = [] + sleep_data = str(msg_tmp_new.split(',')[i]) + # print("i",i,sleep_data) + if len(sleep_data) != 0: + b = sleep_data.find('-') + if b != -1: + sleep_time = sleep_data.split('-')[0]#-作为分隔符 + sleep_switch = int(sleep_data.split('-')[1])#开关 + sleep_repeat = int(sleep_data.split('-')[2])#是单次还是每天 还是自定义 + + sleep_hour = int(sleep_time.split(":")[0])#时间 + sleep_min = int(sleep_time.split(":")[1])#冒号分隔时间 时 分 + + + if sleep_repeat == 2:#每一天 + sleep_day = [0,1,2,3,4,5,6] + elif sleep_repeat == 3:#自定义 + sleep_day_tmp = sleep_data.split('-')[3]#-作为分隔符 + for i in range(0,7): + if sleep_day_tmp[i] != '0': + sleep_day.append(i) + else:#单次 1 + sleep_day=[] + if sleep_switch != 0: + sleep_data_save.append({"hour":sleep_hour,"min":sleep_min,"day":sleep_day,"enable":sleep_switch}) + + EventMesh.publish("set_storage_config",["sleep_alarm",sleep_data_save]) + sleep = EventMesh.publish("get_storage_config","sleep_alarm") + + EventMesh.debug_log("recv REMIND_CH_SLEEP_SEND:{} sleep ;{}".format(msg,sleep)) + + EventMesh.publish(constants.PROTOCOL.REMIND_CH_SLEEP_SEND) + EventMesh.publish("clear_sleep_alarm") + + +# 可设置闹钟的提醒文字 +# 平台发送: +# [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_REST,时间间隔1,时间间隔2,时间间隔3] +# 实例: +# [XT*334588000000156*0026*REMIND_CH_REST,08:10-10:00,12:10-15:00] +# 终端回复: +# [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_REST] +# 实例:[XT*334588000000156*000E*REMIND_CH_REST] +# 说明:时间间隔 【起始-结束】,起始为开始休息,结束为休息结束 + +class REMIND_CH_REST_ProtoCol(ProtoCol):#该休息了 + """ + + 平台发送: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_REST,,时间1-开关,时间2-开关,周几] + 实例:[XT*334588000000156*0008*REMIND_CH_REST,,时间1-开关,时间2-开关,周几] + 终端回复: + [XT*YYYYYYYYYYYYYYY*LEN*REMIND_CH_REST] + """ + TYPE = "REMIND_CH_REST" + + def send(self, event, msg): + send_data = self.PID+"*%s*000E*REMIND_CH_REST"%(self.imei) + MD5_SIGN = self.pack_MD5_head(send_data) + data = "[%s%s]"%(str(MD5_SIGN),send_data) + #Wechat_log("POWEROFF_ProtoCol:send:%s"%(data)) + # 通过socket发送到服务器端 + EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data) + + def recv(self, event, msg): + # SZKW*860132060346475*0013*REMIND_CH_REST,4-1 + msg = msg[1:-1] + msg_tmp = msg.decode('ascii') + msg_data = msg_tmp.split('REMIND_CH_REST,')[1] + print("REMIND_CH_REST",len(msg_data),msg_data) + + reset_data_save = [] + count = 0 + for i in str(msg_data): + # print("i",i) + if i == ",": + count+=1 + if count != 0: + count += 1 + + if count >= 2: + count = 2 + + for i in range(0,count):#默认是三个时间多了也不保存 + reset_data = str(msg_data.split(',')[i]) + print("i",i,reset_data) + if len(reset_data) != 0: + b = reset_data.find('-') + if b != -1: + start_time = reset_data.split('-')[0]#-作为分隔符 + end_time = reset_data.split('-')[1]#-作为分隔符 + + start_hour = int(start_time.split(":")[0]) + start_min = int(start_time.split(":")[1]) + + end_hour = int(end_time.split(":")[0]) + end_min = int(end_time.split(":")[1]) + + reset_data_save.append({"start_hour":start_hour,"start_min":start_min,"end_hour":end_hour,"end_min":end_min}) + + EventMesh.publish("set_storage_config",["reset_alarm",reset_data_save]) + reset = EventMesh.publish("get_storage_config","reset_alarm") + + EventMesh.debug_log("recv REMIND_CH_REST:{} reset ;{}".format(msg,reset)) - EventMesh.publish(constants.PROTOCOL.REMIND_CH_MEDICINE2_SEND) + EventMesh.publish(constants.PROTOCOL.REMIND_CH_REST_SEND) + EventMesh.publish("clear_reset_alarm") @@ -2248,7 +2601,7 @@ class ProtoColResolver(object): def handler(self, data): # 这里接收数据 - EventMesh.debug_log("handler -> {}".format(data)) + # EventMesh.debug_log("handler -> {}".format(data)) # if data.startswith('Init;'): # data = data[5:] # EventMesh.publish(constants.EVENT.SET_KEY, {"value": ujson.loads(data)['KEY']}) diff --git a/2.sdk/project/D10/usr/static/audio.bin b/2.sdk/project/D10/usr/static/audio.bin index 65b68310..c28c3d9d 100644 Binary files a/2.sdk/project/D10/usr/static/audio.bin and b/2.sdk/project/D10/usr/static/audio.bin differ