import audio
from machine import I2C
from Gsensor import SC7A20
+import pm
try :
from Hsensor import GH3018
except Exception as e:
num_len = len(number)+2
# print("number:{} number_len :{} num:{} num_len:{}".format(number,len(number),num,num_len))
if num > num_len :
- if len(number) == 1:
- number1 = str(number[0])
- sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
- elif len(number) == 2:
- number1 = str(number[0])
- sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
-
- number2 = str(number[1])
- sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
- elif len(number) == 3:
- number1 = str(number[0])
- sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
- number2 = str(number[1])
- sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
- number3 = str(number[2])
- sms.sendPduMsg(number3, '我需要你的帮助', 'UCS2')
EventMesh.publish("set_sos_flag",0)
EventMesh.publish("set_sos_num",0)
else:
#self.battery_push_schedule = osTimer()
self.check_battery_list = []
-
+
self.step = [0,0,0,0]
self.timer_push=0
self.timer_push_tmp=60
:return:
"""
+ try :
+ self.timer_push = self.timer_push+1
- self.timer_push = self.timer_push+1
-
- #if self.timer_push > 10 :
- # EventMesh.publish("time", self.get_time())
- # EventMesh.publish("battery", self.get_battery())
- # EventMesh.publish("signal", self.get_signal())
-
- self.timer_push = 0
- date_tmp = utime.localtime()
- time_tmp = utime.mktime(date_tmp)
- # print("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
-
+ #if self.timer_push > 10 :
+ # EventMesh.publish("time", self.get_time())
+ # EventMesh.publish("battery", self.get_battery())
+ # EventMesh.publish("signal", self.get_signal())
+
+ self.timer_push = 0
+ date_tmp = utime.localtime()
+ time_tmp = utime.mktime(date_tmp)
+ # print("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
+
- EventMesh.publish("countdown_end_cb")
- """定时检查是否关闭gps失败"""
- gnss_state = quecgnss.get_state()
- get_location_flag = EventMesh.publish("get_location_flag")
- if get_location_flag != None:
- if gnss_state == 2 and get_location_flag == 0:
- EventMesh.publish(constants.EVENT.GPSCLOSE)
-
- """7分钟一次心跳"""
- if math.fabs(time_tmp - self.KA_time) > 7*60: #7分钟一次心跳
- self.KA_time = time_tmp
- EventMesh.publish(constants.PROTOCOL.KA_SEND)
-
- """定时定位"""
- self.upload_time = EventMesh.publish("get_upload_data")
- #print("self.upload_time:{} math.fabs(time_tmp - self.UD_time):{}".format(self.upload_time,math.fabs(time_tmp - self.UD_time)))
- if self.upload_time != None :
- if math.fabs(time_tmp - self.UD_time) > self.upload_time: #30分钟一次定位
- self.UD_time = time_tmp
- status_tmp = self.gsensor.get_status()#获取运动次数
- #EventMesh.txt_log("status_count:{}".format(status_tmp))
- if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and status_tmp > 3 :
- EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
- self.gsensor.clean_status()#清除运动次数
- EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
-
- """电池平均值"""
- temp = Power.getVbatt()
- if self.bat_count < 10:
- self.vbat_buf.append(temp)
- self.bat_count += 1
- else:
- for i in range(9):
- self.vbat_buf[i] = self.vbat_buf[i+1]
- self.vbat_buf[9] = temp
- curr_count = len(self.vbat_buf)
- bat_total_value = 0
- for i in range(curr_count):
- bat_total_value += self.vbat_buf[i]
- bat_total_value = bat_total_value//curr_count#一分钟更新一次电量 10个平均值
- EventMesh.publish("set_curr_battery_level",bat_total_value)
- # print("self.vbat_buf:{} curr_count :{} bat_total_value:{} temp:{}".format(self.vbat_buf,curr_count,bat_total_value,temp))
- bat_tmp = EventMesh.publish("screen_get_battery")
- self.vbat_count+=10
- if self.vbat_count >= 60:
- self.vbat_count = 0
- if bat_tmp != None:
- bat_value = bat_tmp[1]
- if bat_value <= 0:
- EventMesh.publish("load_screen", {"screen": "LOW_ONE_POWER"})
-
-
- """"隔天清步数"""
- hour = 0
- min = 0
- hour = date_tmp[3]
- min = date_tmp[4]
- old_Timesec = EventMesh.publish("get_old_time_data")
- if old_Timesec != None:
- data = RTC().datetime()
- hour = data[4]
- min = data[5]
- next_alarm_time = utime.localtime(old_Timesec)
- # print("data[5]:{} {} next_alarm_time:{} old_Timesec:{}".format(data[1],data[2],next_alarm_time,old_Timesec))
- month = next_alarm_time[1]
- day = next_alarm_time[2]
- if month != data[1] or day != data[2]:
- step = EventMesh.publish("get_old_step_value")
- if step > 0:
- self.gsensor.reset_step()
- EventMesh.publish("set_old_step_value",0)
-
- hr = EventMesh.publish("get_old_hr_data",)
- if hr != 0:
- EventMesh.publish("set_old_hr_data", 0)
-
- spo2 = EventMesh.publish("get_old_spo2_data")
- if spo2 != 0:
- EventMesh.publish("set_old_spo2_data", 0)
- EventMesh.publish("set_old_time_data",time_tmp)
- if hour == 0:#清步数
- if min <= 1:
- if self.clear_step == 0:
+ EventMesh.publish("countdown_end_cb")
+ """定时检查是否关闭gps失败"""
+ # gnss_state = quecgnss.get_state()
+ # get_location_flag = EventMesh.publish("get_location_flag")
+ # if get_location_flag != None:
+ # # if gnss_state == 2 and get_location_flag == 0:
+ # # EventMesh.publish(constants.EVENT.GPSCLOSE)
+ # if(get_location_flag == 0):
+ # EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
+
+ """7分钟一次心跳"""
+ if math.fabs(time_tmp - self.KA_time) > 7*60: #7分钟一次心跳
+ self.KA_time = time_tmp
+ EventMesh.publish(constants.PROTOCOL.KA_SEND)
+
+ """定时定位"""
+ #EventMesh.publish("set_upload_data",3*60)
+ self.upload_time = EventMesh.publish("get_upload_data")
+ #print("self.upload_time:{} math.fabs(time_tmp - self.UD_time):{}".format(self.upload_time,math.fabs(time_tmp - self.UD_time)))
+ if self.upload_time != None :
+ if math.fabs(time_tmp - self.UD_time) > self.upload_time: #30分钟一次定位
+ self.UD_time = time_tmp
+ status_tmp = self.gsensor.get_status()#获取运动次数
+ #status_tmp = 4
+ #EventMesh.txt_log("status_count:{}".format(status_tmp))
+ if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and status_tmp > 3 :
+ EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
+ self.gsensor.clean_status()#清除运动次数
+ else : #关闭定位
+ #EventMesh.txt_log("NO status")
+ print("NO status")
+ EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
+ except Exception as e:
+ usys.print_exception(e)
+ EventMesh.txt_log("publish_event1:".format(e))
+ try :
+ """电池平均值"""
+ temp = Power.getVbatt()
+ if self.bat_count < 10:
+ self.vbat_buf.append(temp)
+ self.bat_count += 1
+ else:
+ for i in range(9):
+ self.vbat_buf[i] = self.vbat_buf[i+1]
+ self.vbat_buf[9] = temp
+ curr_count = len(self.vbat_buf)
+ bat_total_value = 0
+ for i in range(curr_count):
+ bat_total_value += self.vbat_buf[i]
+ bat_total_value = bat_total_value//curr_count#一分钟更新一次电量 10个平均值
+ EventMesh.publish("set_curr_battery_level",bat_total_value)
+ # print("self.vbat_buf:{} curr_count :{} bat_total_value:{} temp:{}".format(self.vbat_buf,curr_count,bat_total_value,temp))
+ bat_tmp = EventMesh.publish("screen_get_battery")
+ self.vbat_count+=10
+ if self.vbat_count >= 60:
+ self.vbat_count = 0
+ if bat_tmp != None:
+ bat_value = bat_tmp[1]
+ if bat_value <= 0:
+ EventMesh.publish("load_screen", {"screen": "LOW_ONE_POWER"})
+ except Exception as e:
+ usys.print_exception(e)
+ EventMesh.txt_log("publish_event2:".format(e))
+ try :
+ """"隔天清步数"""
+ hour = 0
+ min = 0
+ hour = date_tmp[3]
+ min = date_tmp[4]
+ old_Timesec = EventMesh.publish("get_old_time_data")
+ if old_Timesec != None:
+ data = RTC().datetime()
+ hour = data[4]
+ min = data[5]
+ next_alarm_time = utime.localtime(old_Timesec)
+ # print("data[5]:{} {} next_alarm_time:{} old_Timesec:{}".format(data[1],data[2],next_alarm_time,old_Timesec))
+ month = next_alarm_time[1]
+ day = next_alarm_time[2]
+ if month != data[1] or day != data[2]:
step = EventMesh.publish("get_old_step_value")
- EventMesh.publish("set_old_time_data",time_tmp)
if step > 0:
- EventMesh.publish("set_old_step_value",0)
self.gsensor.reset_step()
- hr = EventMesh.publish("get_old_hr_data")
+ EventMesh.publish("set_old_step_value",0)
+
+ hr = EventMesh.publish("get_old_hr_data",)
if hr != 0:
EventMesh.publish("set_old_hr_data", 0)
spo2 = EventMesh.publish("get_old_spo2_data")
if spo2 != 0:
EventMesh.publish("set_old_spo2_data", 0)
- self.clear_step = 1
+ EventMesh.publish("set_old_time_data",time_tmp)
+ if hour == 0:#清步数
+ if min <= 1:
+ if self.clear_step == 0:
+ step = EventMesh.publish("get_old_step_value")
+ EventMesh.publish("set_old_time_data",time_tmp)
+ if step > 0:
+ EventMesh.publish("set_old_step_value",0)
+ self.gsensor.reset_step()
+ hr = EventMesh.publish("get_old_hr_data")
+ if hr != 0:
+ EventMesh.publish("set_old_hr_data", 0)
+
+ spo2 = EventMesh.publish("get_old_spo2_data")
+ if spo2 != 0:
+ EventMesh.publish("set_old_spo2_data", 0)
+ self.clear_step = 1
+ else:
+ if self.clear_step == 1:
+ self.clear_step = 0
else:
if self.clear_step == 1:
self.clear_step = 0
- else:
- if self.clear_step == 1:
- self.clear_step = 0
-
- """电量小于20% 5分钟提醒一次"""
- get_low_btn = EventMesh.publish("get_low_bat_btn")#
- battery = EventMesh.publish("screen_get_battery")
- # print("get_low_btn:{} self.bat_time:{}".format(get_low_btn,self.bat_time))
- if get_low_btn != None:#低电使能开关
- if get_low_btn == 1:
- self.bat_time+=10
- # print("date_tmp:{} self.bat_time:{}".format(date_tmp,self.bat_time))
-
- if self.bat_time > 5*60:
+
+ """电量小于20% 5分钟提醒一次"""
+ get_low_btn = EventMesh.publish("get_low_bat_btn")#
+ battery = EventMesh.publish("screen_get_battery")
+ # print("get_low_btn:{} self.bat_time:{}".format(get_low_btn,self.bat_time))
+ if get_low_btn != None:#低电使能开关
+ if get_low_btn == 1:
+ self.bat_time+=10
+ # print("date_tmp:{} self.bat_time:{}".format(date_tmp,self.bat_time))
+
+ if self.bat_time > 5*60:
+ self.bat_time = 0
+ if battery[1] <= 20 and battery[1] > 0:
+ EventMesh.publish("load_screen", {"screen": "LOW_POWER"})
+ else:
self.bat_time = 0
- if battery[1] <= 20 and battery[1] > 0:
- EventMesh.publish("load_screen", {"screen": "LOW_POWER"})
- else:
- self.bat_time = 0
-
- """未联网提示关机"""
- if EventMesh.publish(constants.EVENT.GET_CONNECT) == 0:#未联网提示关机
- if battery[0] == "0":
- self.no_smi_count+=10
- if self.no_smi_count > (15*60) and self.no_smi_state == 0:
+
+ """未联网提示关机"""
+ if EventMesh.publish(constants.EVENT.GET_CONNECT) == 0:#未联网提示关机
+ if battery[0] == "0":
+ self.no_smi_count+=10
+ if self.no_smi_count > (15*60) and self.no_smi_state == 0:
+ self.no_smi_count = 0
+ self.no_smi_state = 1
+ EventMesh.publish("load_screen", {"screen": "no_sim_auto_screen"})
+ else:
self.no_smi_count = 0
- self.no_smi_state = 1
- EventMesh.publish("load_screen", {"screen": "no_sim_auto_screen"})
+ self.no_smi_state = 0
else:
self.no_smi_count = 0
self.no_smi_state = 0
- else:
- self.no_smi_count = 0
- self.no_smi_state = 0
- if battery[0] == "1":
- if battery[1] >= 100:
- if self.charge_full_count > 60 and self.charge_full_count % (60*10) == 0:#每十分钟提醒一次
- EventMesh.publish("load_screen", {"screen": "charge_full"})
- self.charge_full_count+=10
- else:
- self.charge_full_count = 0
-
- """检测短信已满,提示是否清掉"""
- msg_nums = sms.getMsgNums() #获取短信条数
- if(msg_nums != -1):
- sms_data = sms.getSaveLoc()
- sms_max = sms_data[0][2]
- if msg_nums >= sms_max-1:
- self.sms_full_flag+=10
- if self.sms_full_flag >= 120:
- self.sms_full_flag=0
- EventMesh.publish("load_screen", {"screen": "message_full"})
+ if battery[0] == "1":
+ if battery[1] >= 100:
+ if self.charge_full_count > 60 and self.charge_full_count % (60*10) == 0:#每十分钟提醒一次
+ EventMesh.publish("load_screen", {"screen": "charge_full"})
+ self.charge_full_count+=10
else:
- self.sms_full_flag = 0
+ self.charge_full_count = 0
+
+ """检测短信已满,提示是否清掉"""
+ msg_nums = sms.getMsgNums() #获取短信条数
+ if(msg_nums != -1):
+ sms_data = sms.getSaveLoc()
+ sms_max = sms_data[0][2]
+ if msg_nums >= sms_max-1:
+ self.sms_full_flag+=10
+ if self.sms_full_flag >= 120:
+ self.sms_full_flag=0
+ EventMesh.publish("load_screen", {"screen": "message_full"})
+ else:
+ self.sms_full_flag = 0
+ except Exception as e:
+ usys.print_exception(e)
+ EventMesh.txt_log("publish_event3:".format(e))
+
"""定时测量心率,血氧,体温"""
WEAR = EventMesh.publish(constants.EVENT.GET_WEAR)#佩戴数据
self.get_hr_state = EventMesh.publish("get_hr_state")
self.old_time = 0
self.set_hsenor_crt = 0
- EventMesh.publish("get_class_in_time_page")
+
#quecgnss.gnssEnable(0)
def usb_event_cb(self, state):
status = state
- if status == 1:#
+ if status == 1:#拔出
screen_NAME = EventMesh.publish("get_screen_NAME")
if screen_NAME != None:
if screen_NAME == "poweron" or screen_NAME == "system_init":
if bat_tmp[0] == "1":
EventMesh.publish("load_screen", {"screen": "charge_in"})
pass
- elif status == 0:#
+ elif status == 0:#插入usb
screen_NAME = EventMesh.publish("get_screen_NAME")
if screen_NAME != None:
if screen_NAME == "poweron" or screen_NAME == "system_init":
def wifiScan_cb(args):
EventMesh.publish(constants.EVENT.WIFIINFO, args)
+ wifiScan.control(0)
class LocationManager(Abstract):
self.match = GPSMatch()
self.timer_read_GPS_info = osTimer()
self.wifi_data = []
- self.gps_data = []
+ self.gps_data = {}
self.cell_data = []
self.location_timer_count = 0
self.location_check_data_timer_count = 0
+ self.GGA_count = 0
+ self.RMC_A_count = 0
self.location_type = 0 #定位类型,0:正常定位,有gps数据或60秒关闭;1:测试模式,只有发CLOSE_LOCATION消息才关闭
self.location_flag = 0
self.start_location_flag = 0
- self.location_thread_id = 0
- self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
+ self.location_thread_id = 0
self.location_queue = Queue(100)
+ self.lpm_fd = None
#quecgnss.init()
#quecgnss.gnssEnable(0)
@staticmethod
return self.location_flag
def start_location(self, event, msg):
self.location_queue.put(msg)#测试类型入队
+ self.gps_data = {}
+ self.wifi_data = []
+ self.cell_data = []
+ self.location_timer_count = 0
+ self.GSV_sig_ok_count = 0
print("start_location:{}".format(msg))
- self.timer_read_GPS_info.start(1000, 1, self.location_timer)
if( self.location_flag == 1):
return
- self.location_timer_count = 0
+ self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
self.location_flag = 1
#self.gps_open(event, msg)
- self.start_location_flag = 1
def start_location_test(self, event, msg):
print("start_location_test")
- self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+
+ self.location_type = 1
if( self.location_flag == 1):
return
+ self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
self.location_timer_count = 0
self.location_flag = 1
#self.gps_open(event, msg)
self.location_type = 1
- self.start_location_flag = 1
+
def close_location(self, event, msg):
self.location_flag = 0
self.location_type = 0
- self.gps.power_switch(0)
- wifiScan.control(0)
- self.timer_read_GPS_info.stop()
+
def WIFI_INFO(self, event, msg):
self.wifi_data = msg
def WIFI_scan_open(self, event, msg):
#print("WIFI_scan_open")
- self.wifi_data = []
- if wifiScan.support():
- if wifiScan.getState() == False :
- wifiScan.control(1)
- wifiScan.setConfig(4, 2, 5, 6, 0) #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
+
+
+ if wifiScan.getState() == False :
+ self.wifi_data = []
+ wifiScan.control(1)
+ wifiScan.setCfgParam(6, 2, 5, 0) #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
wifiScan.setCallback(wifiScan_cb) #注册回调函数
wifiScan.asyncStart()
#print("wifiScan.asyncStart")
def Location_send(self, msg) :
#print("Location_send1")
+ if self.location_queue.empty() == True:
+ return
date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
date = date[2:]
+ #date = "180916,025723"
GPS_type = "V"
latitude = "0.000000,N"
longitude = "0.000000,E"
direction = "0.0"
high = "100.0"
number = "0"
- if msg[0] != [] :#有GPS数据
+ precision = "24"
+ if msg[0] :#有GPS数据
GPS_type = "A"
# 纬度
latitude = msg[0]["latitude"]
high = "%s"%(high_tmp[0])
# 讯号质量:搜索到的卫星数目
number = msg[0]["number"]
+ precision = msg[0]["precision"]
+ #date = msg[0]["date"]
+
#gsm 信号强度
gsm_sig = str((100//31)*EventMesh.publish("screen_get_sig"))
# 电池电量百分比
send_data += ",%s,%s,%s"%(battery_caption,step,turn_count)
send_data += ",%s,%d,%s"%(state,CELL_num,CELL_data)
send_data += ",%d,%s"%(WIFI_num,WIFI_data)
+ send_data+=",%s"%(precision)
#print("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
while True:
if self.location_queue.empty() == False:
def location_thread(self):
- gnss_r_data = ""
- while True:
+ self.wifi_data = []
+ self.gps_data = {}
+ self.cell_data = []
+ gnss_r_data = []
+ self.GSV_sig_ok_count = 0
+ self.GGA_count = 0
+ self.RMC_A_count = 0
+ if self.lpm_fd == None:
+ self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
+ pm.wakelock_lock(self.lpm_fd)
+ print("location_thread:1")
+ EventMesh.publish(constants.EVENT.GPSOPEN)
+ print("location_thread:2")
+ self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+
+ #utime.sleep_ms(1000)
+ self.location_timer_count = 0
+ #quecgnss.read(4096)#去掉第一次错误数据
+ #EventMesh.txt_log("START_LOCATION")
+ # pm.autosleep(0)#唤醒
+ # pm.sclkEx_set(0, 1, 5)
+ while self.location_flag == 1:
try :
- if self.location_flag == 1 :
+
+ match_gga_data = []
+ #match_gsv_data = []
+ gnss_r_data = []
+ # if self.location_check_data_timer_count >= 3:
+ # pm.autosleep(0)#唤醒
+ # pm.sclkEx_set(0, 1, 5)
+ if self.location_check_data_timer_count >= 5 :#5秒查一次基站数据和wifi数据
+ self.location_check_data_timer_count = 0
+ #print(self.location_timer_count)
+ #GSV_dict= {}
- if self.start_location_flag == 1 :
- self.start_location_flag = 0
- self.wifi_data = []
- self.gps_data = []
- self.cell_data = []
- gnss_r_data = []
- print("location_thread:1")
- EventMesh.publish(constants.EVENT.GPSOPEN)
- print("location_thread:2")
- EventMesh.publish(constants.EVENT.WIFISCANOPEN)
- print("location_thread:3")
- utime.sleep_ms(1000)
- self.location_timer_count
- #quecgnss.read(4096)#去掉第一次错误数据
- match_gga_data = []
- #match_gsv_data = []
- gnss_r_data = []
- if self.location_check_data_timer_count > 3 :#5秒查一次基站数据和wifi数据
- self.location_check_data_timer_count = 0
- #print(self.location_timer_count)
- GSV_dict= {}
- GSV_sig_ok_count = 0
- #检查GNSS数据
- if (self.gps_data == [] or self.location_type == 1) and quecgnss.get_state() == 2:
- self.gps.__gps_nmea_data_clean()
- #gnss_r_data = [0,1]
- gnss_r_data = quecgnss.read(4096)
- #print("location gnss_r_data:{}".format(gnss_r_data[1].decode()))
- print("gnss_r_data len:{}".format(gnss_r_data[0]))
- if gnss_r_data[0] > 0 : #有数据
- gsv_data = gnss_r_data[1].split("GSV")
- if len(gsv_data) >= 2 :
- gsv_data = gsv_data[1:]
- for i in range(len(gsv_data)) :
- gsv_data[i] = gsv_data[i].split("\r\n")[0]
- gsv_tmp = gsv_data[i].split(",")
- if len(gsv_tmp) < 7 :
- break
- gsv_tmp = gsv_tmp[4:]
- #print("gsv_tmp:{}".format(gsv_tmp))
- for i in range(len(gsv_tmp)) :
- if i % 4 == 0:
- GSV_dict[gsv_tmp[i]] = gsv_tmp[i+3]
- try:
- #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
- if gsv_tmp[i+3] != "" :
- if int(gsv_tmp[i+3])>=24:
- GSV_sig_ok_count+=1
- except Exception as e:
- usys.print_exception(e)
- #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
- if len(gsv_tmp)-i < 4:
- break
- #match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
- #match_gsv_data = self.match.GxGSV(gnss_r_data[1]).split(",")
- if self.gps.__check_gps_valid(gnss_r_data[1].decode()): #数据齐全
- match_gmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
- match_vtg_data = self.match.GxVTG(gnss_r_data[1]).split(",")
- match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
- gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
- latitude_tmp = str(gps_data_tmp[1]).split(".")
- if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
- latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
- latitude = "%s,%s"%(latitude,match_gmc_data[4] )
- longitude_tmp = str(gps_data_tmp[0]).split(".")
- if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
- longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
- longitude = "%s,%s"%(longitude,match_gmc_data[6] ) #match_gmc_data[6] + str(gnss_r_data[1])
- high = str(gps_data_tmp[2])
- self.gps_data = {
- "latitude": latitude,
- "longitude": longitude,
- "high": high,
- "direction": match_vtg_data[1],
- "speed": match_vtg_data[5],
- "number": match_gga_data[7],
- }
- #检查wifi数据
- if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
- EventMesh.publish(constants.EVENT.WIFISCANOPEN)
+ #检查GNSS数据
+ if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
- #检查基站数据
- if self.cell_data == []:
- data_tmp = net.getCellInfo()
- for cell in data_tmp:
- if cell and cell[0][0] == 0 and len(cell[0]) > 1:
- self.cell_data = cell
+ self.gps.__gps_nmea_data_clean()
+ #gnss_r_data = [0,1]
+ gnss_r_data = quecgnss.read(4096)
+ #EventMesh.txt_log("gps Datalen:{}".format(gnss_r_data[0]))
+ print("location gnss_r_data:len{}\n{}".format(gnss_r_data[0],gnss_r_data[1].decode()))
+ #print("gnss_r_data len:{}".format(gnss_r_data[0]))
+ if gnss_r_data[0] > 0 : #有数据
+ tmp_ok_count = 0
+ gsv_data = gnss_r_data[1].split("GSV")
+
+ if len(gsv_data) >= 2 :
+ gsv_data = gsv_data[1:]
+ for i in range(len(gsv_data)) :
+ gsv_data[i] = gsv_data[i].split("\r\n")[0]
+ gsv_tmp = gsv_data[i].split(",")
+ if len(gsv_tmp) < 7 :
break
- if self.location_timer_count >= 60*7 : #4分钟关闭
+
+ gsv_tmp = gsv_tmp[4:]
+ #print("gsv_tmp:{}".format(gsv_tmp))
+ for i in range(len(gsv_tmp)) :
+ if i % 4 == 0:
+ #GSV_dict[gsv_tmp[i]] = gsv_tmp[i+3]
+ try:
+ #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
+ if gsv_tmp[i+3] != "" :
+ if int(gsv_tmp[i+3])>=20:
+ tmp_ok_count +=1
+ except Exception as e:
+ usys.print_exception(e)
+ #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
+ if len(gsv_tmp)-i < 4:
+ break
+
+ if(tmp_ok_count > self.GSV_sig_ok_count ):
+ self.GSV_sig_ok_count = tmp_ok_count
+
+
+ # if len(match_gga_data) > 8:
+ # #print(match_gga_data)
+ # if(match_gga_data[7] ):
+ # gga_count_tmp = int(match_gga_data[7]) #可用卫星
+ # if(gga_count_tmp > self.GGA_count):
+ # self.GGA_count = gga_count_tmp
+ print("GGA_count:{} GSV_sig_ok_coun:{} ".format(self.GGA_count,self.GSV_sig_ok_count))
+
+ match_rmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
+
+ #print("match_rmc_data:\n{}".format(match_rmc_data))
+ if len (match_rmc_data)>3: #有rmc数据
+ if match_rmc_data[2] == 'A':
+
+ if self.gps.__check_gps_valid(gnss_r_data[1].decode()): #数据齐全 :
+
+ #print("hhhhhh:{}\n\n".format(self.gps.__gsv_data))
+ match_vtg_data = self.gps.__vtg_data.split(",")#self.match.GxVTG(gnss_r_data[1]).split(",")
+ match_gga_data = self.gps.__gga_data.split(",")#self.match.GxGGA(gnss_r_data[1]).split(",")
+ #match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
+
+ EventMesh.txt_log("GGA:{}".format(match_gga_data))
+ # EventMesh.txt_log("VTG:{}".format(match_vtg_data))
+ # EventMesh.txt_log("RMC:{}".format(match_rmc_data))
+ # EventMesh.txt_log("timer:{} ok_count:{} count:{}\n".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ print("LOCATION_ok :time:{}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n".format(self.location_timer_count))
+ gps_date = "%s,%s"%(match_rmc_data[9],match_rmc_data[1][:6])#日期
+ gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
+ latitude = "0,N" #纬度
+ latitude_tmp = str(gps_data_tmp[1]).split(".")
+ if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
+ latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
+ latitude = "%s,%s"%(latitude,match_rmc_data[4] )
+
+ longitude = "0,E"#经度
+ longitude_tmp = str(gps_data_tmp[0]).split(".")
+ if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
+ longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
+ longitude = "%s,%s"%(longitude,match_rmc_data[6] ) #match_rmc_data[6] + str(gnss_r_data[1])
+
+ high = "0"#高度
+ high = str(gps_data_tmp[2])
+ number = "0"#可用卫星
+ precision = "5.8"#精度
+ if len(match_gga_data)>5 :
+ if match_gga_data[7]:
+ number = match_gga_data[7]
+ if match_gga_data[8]:
+ precision = match_gga_data[8]
+ direction = "249.5" #方向
+ speed = '0.00' #速度
+ if(len(match_vtg_data)>5 ):
+ if match_vtg_data[1]:
+ direction = match_vtg_data[1]
+ if match_vtg_data[7]:
+ speed = match_vtg_data[7]
+ self.gps_data = {
+ "latitude": latitude,
+ "longitude": longitude,
+ "high": high,
+ "direction": direction,
+ "speed": speed,
+ "number": number,
+ "date": gps_date,
+ "precision": precision
+ }
+ else :
+ EventMesh.txt_log("gps数据不全")
+ else :
+ EventMesh.txt_log("gps 无数据")
+
+
+
+ #检查wifi数据
+ if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
+ EventMesh.publish(constants.EVENT.WIFISCANOPEN)
+
+ #检查基站数据
+ if self.cell_data == []:
+ data_tmp = net.getCellInfo()
+ if(len(data_tmp)>=2):
+ for cell in data_tmp:
+ if cell and cell[0][0] == 0 and len(cell[0]) > 1:
+ self.cell_data = cell
+ break
+
+ if self.location_type == 1: #测试模式
+ self.location_timer_count = 0
+ if len(gnss_r_data) >= 1:
+ if gnss_r_data[0] > 0:
+ EventMesh.publish("PUSH_LOCATION_DATA", [gnss_r_data,self.wifi_data,self.cell_data])
+ if self.gps_data != {} : #发送数据
+ EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ self.location_queue.put(constants.PROTOCOL.UD_SEND)
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+
+
+ elif self.location_type == 0: #正常模式
+ if self.gps_data != {} or self.location_timer_count > 100: #or( self.wifi_data != [] and self.cell_data != []):
+ if self.location_queue.empty() == False:#有定位队列
+ EventMesh.txt_log("LOCATION:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
+ upload_time = EventMesh.publish("get_upload_data")
+
+
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ #if upload_time > 200 :
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ # else: #定位间隔小于3分钟不关闭gps,不影响无信号判断
+ # self.location_timer_count = 0
+ # self.GSV_sig_ok_count = 0
+
+
+ # if (self.GGA_count < 3 and self.GSV_sig_ok_count < 2) and self.wifi_data and self.cell_data and self.location_timer_count > 30 and self.location_timer_count < 40: #超过20秒且有效卫星个数少于3
+ # EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ # EventMesh.txt_log("GGA_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ # self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+
+ if self.GSV_sig_ok_count <= 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过40秒且信号大于30的不足3个
+ EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
#break
- #EventMesh.txt_log("GSV_sig_ok_count :{}".format(GSV_sig_ok_count))
- if self.location_type == 1: #测试模式
- if len(gnss_r_data) >= 1:
- if gnss_r_data[0] > 0:
- EventMesh.publish("PUSH_LOCATION_DATA", [gnss_r_data,self.wifi_data,self.cell_data])
- elif self.location_type == 0: #正常模式
- if self.gps_data != [] or self.location_timer_count > 180: #or( self.wifi_data != [] and self.cell_data != []):
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("CLOSE_LOCATION:location_timer_count:{}".format(self.location_timer_count))
- #break
-
- if len(GSV_dict) < 2 and GSV_sig_ok_count < 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过20秒且卫星个数少于3
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("len(GSV_dict) < 2")
- if GSV_sig_ok_count < 3 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 40: #超过40秒且信号大于30的不足3个
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("GSV_sig_ok_count < 3")
- #break
- utime.sleep_ms(1000)
- #print("location_timer_count:{}".format(self.location_timer_count))
- else :
- utime.sleep_ms(2000)
+ # if self.location_type != 1 and self.location_timer_count >= 60*4 : #4分钟关闭
+ # EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ #break
+ #EventMesh.txt_log("self.GSV_sig_ok_count :{}".format(self.GSV_sig_ok_count))
+ #EventMesh.publish("set_old_step_value",self.location_timer_count)
+
+ #print("location_timer_count:{}".format(self.location_timer_count))
+
except Exception as e:
usys.print_exception(e)
- utime.sleep_ms(1000)
- print("location_thread:ERROR:{}\r\n{}".format(e,Exception))
+ EventMesh.txt_log("location_thread:ERROR:".format(e))
+ #print("location_thread:ERROR:{}".format(usys.print_exception(e)))
print("self.gps_data{},self.wifi_data{},self.cell_data{}".format(self.gps_data,self.wifi_data,self.cell_data))
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ #self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ utime.sleep_ms(500)
+ self.timer_read_GPS_info.stop()
+ self.gps.power_switch(0)
+ wifiScan.control(0)
+ # if EventMesh.publish("get_lcd_state" ) == 0:#休眠的时候,恢复休眠
+ # pm.autosleep(1)
+ # pm.sclkEx_set(1, 1, 5)
+ if self.lpm_fd != None:
+ pm.wakelock_unlock(self.lpm_fd)
+ #pm.delete_wakelock(lpm_fd)
+ print("CLOSE_LOCATION")
+ #EventMesh.txt_log("CLOSE_LOCATION")
def set(self, event, msg):
self.check_json = msg[0]
self.read_call_log = msg[1]
- with open("/ext/static/storage_file/Call_log.json","w+",encoding="utf-8") as fd:
+ with open("/usr/static/storage_file/Call_log.json","w+",encoding="utf-8") as fd:
ujson.dump(self.read_call_log,fd)
# def call_usr(self,event,msg):
# content = self.log[msg]
self.call_timer.start(10000, 0, self.call_timer_cb)#延迟10S 继续拨打
def call_timer_cb(self, *args, **kwargs):
- if self.sos_flag == 1:
- # print("call_timer_cb:{}".format(self.callnumer))
- EventMesh.publish("save_phonename",str(self.callnumer))
- EventMesh.publish("save_phonenum",str(self.callnumer))
- EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})
+ # print("call_timer_cb:{}".format(self.callnumer))
+ EventMesh.publish("save_phonename",str(self.callnumer))
+ EventMesh.publish("save_phonenum",str(self.callnumer))
+ EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})
def get_sos_flag(self, event, msg):
return self.sos_flag
# return [self.newip,self.newcom,self.newmd5]
if(tmp_data != None):
return [self.newip,self.newcom]
+
+
class setclassTimeManager(Abstract):#设置上课禁用时间
def __init__(self):
self.class_buf = {}
self.class_state = 0
- check_json = ql_fs.path_exists("/usr/static/storage_file/class_msg.json")
+ check_json = ql_fs.path_exists("/ext/static/storage_file/class_msg.json")
if check_json == True:
- with open("/usr/static/storage_file/class_msg.json","r",encoding="utf-8") as fd:
+ with open("/ext/static/storage_file/class_msg.json","r",encoding="utf-8") as fd:
self.class_buf = ujson.load(fd)
print("读取上课禁用时间段")
# print("self.class_buf:",self.class_buf)
week2_state = 0
week3_state = 0
week4_state = 0
- print("week4 ",cur_week,week1,week2,week3,week4,enable1,enable2,enable3,enable4)
# print("end_time1 ",start_time1,end_time1,start_time2,end_time2,start_time3,end_time3,start_time4,end_time4)
for i in range(0,7):
if ((cur_week in week1) and enable1 == 1):
if ((cur_week in week4) and enable4 == 1):
week4_state = 1
- # print("week4_state ",cur_week,week1_state,week2_state,week3_state,week4_state,cur_week)
- if week1 != [] or week2 != [] or week3 != [] or week4 != []:
- if ((cur_week in week1) and enable1 == 1 and week1 != []) or ((cur_week in week2) and enable2 == 1 and week2 != []) or\
- ((cur_week in week3) and enable3 == 1 and week3 != []) or ((cur_week in week4) and enable4 == 1 and week4 != []):
- if enable1 == 1 or enable2 == 1 or enable3 == 1 or enable4 == 1:
+
+ if ((cur_week in week1) and enable1 == 1) or ((cur_week in week2) and enable2 == 1) or\
+ ((cur_week in week3) and enable3 == 1) or ((cur_week in week4) and enable4 == 1):
+ if enable1 == 1 or enable2 == 1 or enable3 == 1 or enable4 == 1:
+ if week1 != [] or week2 != [] or week3 != [] or week4 != []:
if (end_time1 > start_time1 and enable1 == 1 and week1_state == 1) or (end_time2 > start_time2 and enable2 == 1 and week2_state == 1) or\
(end_time3 > start_time3 and enable3 == 1 and week3_state == 1) or (end_time4 > start_time4 and enable4 == 1 and week4_state == 1):
if (cur_total_min <= end_time1 and cur_total_min >= start_time1 and enable1 == 1) or (cur_total_min <= end_time2 and cur_total_min >= start_time2 and enable2 == 1) or\
- (cur_total_min <= end_time3 and cur_total_min >= start_time3 and enable3 == 1) or (cur_total_min <= end_time4 and cur_total_min >= start_time4 and enable4 == 1):
+ (cur_total_min <= end_time3 and cur_total_min >= start_time3 and enable3 == 1) or (cur_total_min <= end_time4 and cur_total_min >= start_time4 and enable3 == 1):
self.class_state = 1
print("class_in1")
break
+ else:#开始时间小于结束时间属于垮天 9:00 -7:00 7*60 6:00
+
+ # print("end_time1!!!!!!!!!",start_time1,end_time1,start_time2,end_time2,start_time3,end_time3,start_time4,end_time4)
+ if (((end_time1 >= cur_total_min or cur_total_min >= start_time1) and enable1 == 1 and week1_state == 1)or \
+ ((end_time2 >= cur_total_min or cur_total_min >= start_time2) and enable2 == 1 and week2_state == 1) or\
+ ((end_time3 >= cur_total_min or cur_total_min >= start_time3) and enable3 == 1 and week3_state == 1) or \
+ ((end_time4 >= cur_total_min or cur_total_min >= start_time4) and enable4 == 1 and week4_state == 1)):
+ self.class_state = 1
+ print("class_in2")
+ break
+
+
return self.class_state
def get_class_in_time_page(self, event, msg):
EventMesh.publish("load_screen", {"screen": "main_menu"})
pass
-
-
-
\ No newline at end of file
def wifiScan_cb(args):
EventMesh.publish(constants.EVENT.WIFIINFO, args)
+ wifiScan.control(0)
class LocationManager(Abstract):
self.match = GPSMatch()
self.timer_read_GPS_info = osTimer()
self.wifi_data = []
- self.gps_data = []
+ self.gps_data = {}
self.cell_data = []
self.location_timer_count = 0
self.location_check_data_timer_count = 0
+ self.GGA_count = 0
+ self.RMC_A_count = 0
self.location_type = 0 #定位类型,0:正常定位,有gps数据或60秒关闭;1:测试模式,只有发CLOSE_LOCATION消息才关闭
self.location_flag = 0
self.start_location_flag = 0
- self.location_thread_id = 0
- self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
+ self.location_thread_id = 0
self.location_queue = Queue(100)
+ self.lpm_fd = None
#quecgnss.init()
#quecgnss.gnssEnable(0)
@staticmethod
return self.location_flag
def start_location(self, event, msg):
self.location_queue.put(msg)#测试类型入队
+ self.gps_data = {}
+ self.wifi_data = []
+ self.cell_data = []
+ self.location_timer_count = 0
+ self.GSV_sig_ok_count = 0
print("start_location:{}".format(msg))
- self.timer_read_GPS_info.start(1000, 1, self.location_timer)
if( self.location_flag == 1):
return
- self.location_timer_count = 0
+ self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
self.location_flag = 1
#self.gps_open(event, msg)
- self.start_location_flag = 1
def start_location_test(self, event, msg):
print("start_location_test")
- self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+
+ self.location_type = 1
if( self.location_flag == 1):
return
+ self.location_thread_id = _thread.start_new_thread(self.location_thread, ())
self.location_timer_count = 0
self.location_flag = 1
#self.gps_open(event, msg)
self.location_type = 1
- self.start_location_flag = 1
+
def close_location(self, event, msg):
self.location_flag = 0
self.location_type = 0
- self.gps.power_switch(0)
- wifiScan.control(0)
- self.timer_read_GPS_info.stop()
+
def WIFI_INFO(self, event, msg):
self.wifi_data = msg
def WIFI_scan_open(self, event, msg):
#print("WIFI_scan_open")
- self.wifi_data = []
- if wifiScan.support():
- if wifiScan.getState() == False :
- wifiScan.control(1)
- wifiScan.setConfig(4, 2, 5, 6, 0) #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
+
+
+ if wifiScan.getState() == False :
+ self.wifi_data = []
+ wifiScan.control(1)
+ wifiScan.setCfgParam(6, 2, 5, 0) #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
wifiScan.setCallback(wifiScan_cb) #注册回调函数
wifiScan.asyncStart()
#print("wifiScan.asyncStart")
def Location_send(self, msg) :
#print("Location_send1")
+ if self.location_queue.empty() == True:
+ return
date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
date = date[2:]
+ #date = "180916,025723"
GPS_type = "V"
latitude = "0.000000,N"
longitude = "0.000000,E"
direction = "0.0"
high = "100.0"
number = "0"
- if msg[0] != [] :#有GPS数据
+ precision = "24"
+ if msg[0] :#有GPS数据
GPS_type = "A"
# 纬度
latitude = msg[0]["latitude"]
high = "%s"%(high_tmp[0])
# 讯号质量:搜索到的卫星数目
number = msg[0]["number"]
+ precision = msg[0]["precision"]
+ #date = msg[0]["date"]
+
#gsm 信号强度
gsm_sig = str((100//31)*EventMesh.publish("screen_get_sig"))
# 电池电量百分比
send_data += ",%s,%s,%s"%(battery_caption,step,turn_count)
send_data += ",%s,%d,%s"%(state,CELL_num,CELL_data)
send_data += ",%d,%s"%(WIFI_num,WIFI_data)
+ send_data+=",%s"%(precision)
#print("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
while True:
if self.location_queue.empty() == False:
def location_thread(self):
- gnss_r_data = ""
- while True:
+ self.wifi_data = []
+ self.gps_data = {}
+ self.cell_data = []
+ gnss_r_data = []
+ self.GSV_sig_ok_count = 0
+ self.GGA_count = 0
+ self.RMC_A_count = 0
+ if self.lpm_fd == None:
+ self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
+ pm.wakelock_lock(self.lpm_fd)
+ print("location_thread:1")
+ EventMesh.publish(constants.EVENT.GPSOPEN)
+ print("location_thread:2")
+ self.timer_read_GPS_info.start(1000, 1, self.location_timer)
+
+ #utime.sleep_ms(1000)
+ self.location_timer_count = 0
+ #quecgnss.read(4096)#去掉第一次错误数据
+ #EventMesh.txt_log("START_LOCATION")
+ # pm.autosleep(0)#唤醒
+ # pm.sclkEx_set(0, 1, 5)
+ while self.location_flag == 1:
try :
- if self.location_flag == 1 :
+
+ match_gga_data = []
+ #match_gsv_data = []
+ gnss_r_data = []
+ # if self.location_check_data_timer_count >= 3:
+ # pm.autosleep(0)#唤醒
+ # pm.sclkEx_set(0, 1, 5)
+ if self.location_check_data_timer_count >= 5 :#5秒查一次基站数据和wifi数据
+ self.location_check_data_timer_count = 0
+ #print(self.location_timer_count)
+ #GSV_dict= {}
- if self.start_location_flag == 1 :
- self.start_location_flag = 0
- self.wifi_data = []
- self.gps_data = []
- self.cell_data = []
- gnss_r_data = []
- print("location_thread:1")
- EventMesh.publish(constants.EVENT.GPSOPEN)
- print("location_thread:2")
- EventMesh.publish(constants.EVENT.WIFISCANOPEN)
- print("location_thread:3")
- utime.sleep_ms(1000)
- self.location_timer_count
- #quecgnss.read(4096)#去掉第一次错误数据
- match_gga_data = []
- #match_gsv_data = []
- gnss_r_data = []
- if self.location_check_data_timer_count > 3 :#5秒查一次基站数据和wifi数据
- self.location_check_data_timer_count = 0
- #print(self.location_timer_count)
- GSV_dict= {}
- GSV_sig_ok_count = 0
- #检查GNSS数据
- if (self.gps_data == [] or self.location_type == 1) and quecgnss.get_state() == 2:
- self.gps.__gps_nmea_data_clean()
- #gnss_r_data = [0,1]
- gnss_r_data = quecgnss.read(4096)
- #print("location gnss_r_data:{}".format(gnss_r_data[1].decode()))
- print("gnss_r_data len:{}".format(gnss_r_data[0]))
- if gnss_r_data[0] > 0 : #有数据
- gsv_data = gnss_r_data[1].split("GSV")
- if len(gsv_data) >= 2 :
- gsv_data = gsv_data[1:]
- for i in range(len(gsv_data)) :
- gsv_data[i] = gsv_data[i].split("\r\n")[0]
- gsv_tmp = gsv_data[i].split(",")
- if len(gsv_tmp) < 7 :
- break
- gsv_tmp = gsv_tmp[4:]
- #print("gsv_tmp:{}".format(gsv_tmp))
- for i in range(len(gsv_tmp)) :
- if i % 4 == 0:
- GSV_dict[gsv_tmp[i]] = gsv_tmp[i+3]
- try:
- #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
- if gsv_tmp[i+3] != "" :
- if int(gsv_tmp[i+3])>=24:
- GSV_sig_ok_count+=1
- except Exception as e:
- usys.print_exception(e)
- #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
- if len(gsv_tmp)-i < 4:
- break
- #match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
- #match_gsv_data = self.match.GxGSV(gnss_r_data[1]).split(",")
- if self.gps.__check_gps_valid(gnss_r_data[1].decode()): #数据齐全
- match_gmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
- match_vtg_data = self.match.GxVTG(gnss_r_data[1]).split(",")
- match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
- gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
- latitude_tmp = str(gps_data_tmp[1]).split(".")
- if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
- latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
- latitude = "%s,%s"%(latitude,match_gmc_data[4] )
- longitude_tmp = str(gps_data_tmp[0]).split(".")
- if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
- longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
- longitude = "%s,%s"%(longitude,match_gmc_data[6] ) #match_gmc_data[6] + str(gnss_r_data[1])
- high = str(gps_data_tmp[2])
- self.gps_data = {
- "latitude": latitude,
- "longitude": longitude,
- "high": high,
- "direction": match_vtg_data[1],
- "speed": match_vtg_data[5],
- "number": match_gga_data[7],
- }
- #检查wifi数据
- if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
- EventMesh.publish(constants.EVENT.WIFISCANOPEN)
+ #检查GNSS数据
+ if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
- #检查基站数据
- if self.cell_data == []:
- data_tmp = net.getCellInfo()
- for cell in data_tmp:
- if cell and cell[0][0] == 0 and len(cell[0]) > 1:
- self.cell_data = cell
+ self.gps.__gps_nmea_data_clean()
+ #gnss_r_data = [0,1]
+ gnss_r_data = quecgnss.read(4096)
+ #EventMesh.txt_log("gps Datalen:{}".format(gnss_r_data[0]))
+ print("location gnss_r_data:len{}\n{}".format(gnss_r_data[0],gnss_r_data[1].decode()))
+ #print("gnss_r_data len:{}".format(gnss_r_data[0]))
+ if gnss_r_data[0] > 0 : #有数据
+ tmp_ok_count = 0
+ gsv_data = gnss_r_data[1].split("GSV")
+
+ if len(gsv_data) >= 2 :
+ gsv_data = gsv_data[1:]
+ for i in range(len(gsv_data)) :
+ gsv_data[i] = gsv_data[i].split("\r\n")[0]
+ gsv_tmp = gsv_data[i].split(",")
+ if len(gsv_tmp) < 7 :
break
- if self.location_timer_count >= 60*7 : #4分钟关闭
+
+ gsv_tmp = gsv_tmp[4:]
+ #print("gsv_tmp:{}".format(gsv_tmp))
+ for i in range(len(gsv_tmp)) :
+ if i % 4 == 0:
+ #GSV_dict[gsv_tmp[i]] = gsv_tmp[i+3]
+ try:
+ #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
+ if gsv_tmp[i+3] != "" :
+ if int(gsv_tmp[i+3])>=20:
+ tmp_ok_count +=1
+ except Exception as e:
+ usys.print_exception(e)
+ #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
+ if len(gsv_tmp)-i < 4:
+ break
+
+ if(tmp_ok_count > self.GSV_sig_ok_count ):
+ self.GSV_sig_ok_count = tmp_ok_count
+
+
+ # if len(match_gga_data) > 8:
+ # #print(match_gga_data)
+ # if(match_gga_data[7] ):
+ # gga_count_tmp = int(match_gga_data[7]) #可用卫星
+ # if(gga_count_tmp > self.GGA_count):
+ # self.GGA_count = gga_count_tmp
+ print("GGA_count:{} GSV_sig_ok_coun:{} ".format(self.GGA_count,self.GSV_sig_ok_count))
+
+ match_rmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
+
+ #print("match_rmc_data:\n{}".format(match_rmc_data))
+ if len (match_rmc_data)>3: #有rmc数据
+ if match_rmc_data[2] == 'A':
+
+ if self.gps.__check_gps_valid(gnss_r_data[1].decode()): #数据齐全 :
+
+ #print("hhhhhh:{}\n\n".format(self.gps.__gsv_data))
+ match_vtg_data = self.gps.__vtg_data.split(",")#self.match.GxVTG(gnss_r_data[1]).split(",")
+ match_gga_data = self.gps.__gga_data.split(",")#self.match.GxGGA(gnss_r_data[1]).split(",")
+ #match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
+
+ EventMesh.txt_log("GGA:{}".format(match_gga_data))
+ # EventMesh.txt_log("VTG:{}".format(match_vtg_data))
+ # EventMesh.txt_log("RMC:{}".format(match_rmc_data))
+ # EventMesh.txt_log("timer:{} ok_count:{} count:{}\n".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ print("LOCATION_ok :time:{}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n".format(self.location_timer_count))
+ gps_date = "%s,%s"%(match_rmc_data[9],match_rmc_data[1][:6])#日期
+ gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
+ latitude = "0,N" #纬度
+ latitude_tmp = str(gps_data_tmp[1]).split(".")
+ if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
+ latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
+ latitude = "%s,%s"%(latitude,match_rmc_data[4] )
+
+ longitude = "0,E"#经度
+ longitude_tmp = str(gps_data_tmp[0]).split(".")
+ if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
+ longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
+ longitude = "%s,%s"%(longitude,match_rmc_data[6] ) #match_rmc_data[6] + str(gnss_r_data[1])
+
+ high = "0"#高度
+ high = str(gps_data_tmp[2])
+ number = "0"#可用卫星
+ precision = "5.8"#精度
+ if len(match_gga_data)>5 :
+ if match_gga_data[7]:
+ number = match_gga_data[7]
+ if match_gga_data[8]:
+ precision = match_gga_data[8]
+ direction = "249.5" #方向
+ speed = '0.00' #速度
+ if(len(match_vtg_data)>5 ):
+ if match_vtg_data[1]:
+ direction = match_vtg_data[1]
+ if match_vtg_data[7]:
+ speed = match_vtg_data[7]
+ self.gps_data = {
+ "latitude": latitude,
+ "longitude": longitude,
+ "high": high,
+ "direction": direction,
+ "speed": speed,
+ "number": number,
+ "date": gps_date,
+ "precision": precision
+ }
+ else :
+ EventMesh.txt_log("gps数据不全")
+ else :
+ EventMesh.txt_log("gps 无数据")
+
+
+
+ #检查wifi数据
+ if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
+ EventMesh.publish(constants.EVENT.WIFISCANOPEN)
+
+ #检查基站数据
+ if self.cell_data == []:
+ data_tmp = net.getCellInfo()
+ if(len(data_tmp)>=2):
+ for cell in data_tmp:
+ if cell and cell[0][0] == 0 and len(cell[0]) > 1:
+ self.cell_data = cell
+ break
+
+ if self.location_type == 1: #测试模式
+ self.location_timer_count = 0
+ if len(gnss_r_data) >= 1:
+ if gnss_r_data[0] > 0:
+ EventMesh.publish("PUSH_LOCATION_DATA", [gnss_r_data,self.wifi_data,self.cell_data])
+ if self.gps_data != {} : #发送数据
+ EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ self.location_queue.put(constants.PROTOCOL.UD_SEND)
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+
+
+ elif self.location_type == 0: #正常模式
+ if self.gps_data != {} or self.location_timer_count > 100: #or( self.wifi_data != [] and self.cell_data != []):
+ if self.location_queue.empty() == False:#有定位队列
+ EventMesh.txt_log("LOCATION:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
+ upload_time = EventMesh.publish("get_upload_data")
+
+
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ #if upload_time > 200 :
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ # else: #定位间隔小于3分钟不关闭gps,不影响无信号判断
+ # self.location_timer_count = 0
+ # self.GSV_sig_ok_count = 0
+
+
+ # if (self.GGA_count < 3 and self.GSV_sig_ok_count < 2) and self.wifi_data and self.cell_data and self.location_timer_count > 30 and self.location_timer_count < 40: #超过20秒且有效卫星个数少于3
+ # EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ # EventMesh.txt_log("GGA_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ # self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+
+ if self.GSV_sig_ok_count <= 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过40秒且信号大于30的不足3个
+ EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
+ self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
#break
- #EventMesh.txt_log("GSV_sig_ok_count :{}".format(GSV_sig_ok_count))
- if self.location_type == 1: #测试模式
- if len(gnss_r_data) >= 1:
- if gnss_r_data[0] > 0:
- EventMesh.publish("PUSH_LOCATION_DATA", [gnss_r_data,self.wifi_data,self.cell_data])
- elif self.location_type == 0: #正常模式
- if self.gps_data != [] or self.location_timer_count > 180: #or( self.wifi_data != [] and self.cell_data != []):
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("CLOSE_LOCATION:location_timer_count:{}".format(self.location_timer_count))
- #break
-
- if len(GSV_dict) < 2 and GSV_sig_ok_count < 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过20秒且卫星个数少于3
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("len(GSV_dict) < 2")
- if GSV_sig_ok_count < 3 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 40: #超过40秒且信号大于30的不足3个
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
- EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
- EventMesh.txt_log("GSV_sig_ok_count < 3")
- #break
- utime.sleep_ms(1000)
- #print("location_timer_count:{}".format(self.location_timer_count))
- else :
- utime.sleep_ms(2000)
+ # if self.location_type != 1 and self.location_timer_count >= 60*4 : #4分钟关闭
+ # EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ #break
+ #EventMesh.txt_log("self.GSV_sig_ok_count :{}".format(self.GSV_sig_ok_count))
+ #EventMesh.publish("set_old_step_value",self.location_timer_count)
+
+ #print("location_timer_count:{}".format(self.location_timer_count))
+
except Exception as e:
usys.print_exception(e)
- utime.sleep_ms(1000)
- print("location_thread:ERROR:{}\r\n{}".format(e,Exception))
+ EventMesh.txt_log("location_thread:ERROR:".format(e))
+ #print("location_thread:ERROR:{}".format(usys.print_exception(e)))
print("self.gps_data{},self.wifi_data{},self.cell_data{}".format(self.gps_data,self.wifi_data,self.cell_data))
- self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+ #self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
+ utime.sleep_ms(500)
+ self.timer_read_GPS_info.stop()
+ self.gps.power_switch(0)
+ wifiScan.control(0)
+ # if EventMesh.publish("get_lcd_state" ) == 0:#休眠的时候,恢复休眠
+ # pm.autosleep(1)
+ # pm.sclkEx_set(1, 1, 5)
+ if self.lpm_fd != None:
+ pm.wakelock_unlock(self.lpm_fd)
+ #pm.delete_wakelock(lpm_fd)
+ print("CLOSE_LOCATION")
+ #EventMesh.txt_log("CLOSE_LOCATION")