mirror of
https://gitee.com/qpy-solutions/tracker-v2.git
synced 2025-05-19 19:18:25 +08:00
Merge branch 'dev' into v2.1
This commit is contained in:
commit
6a45250de3
@ -1 +1 @@
|
||||
Subproject commit df9ca46f04a3fb5da163712cb7395c24c25cd15a
|
||||
Subproject commit db55b42e966a5e838c9c2862edef40aee39fe41a
|
@ -124,16 +124,16 @@ class Settings(Singleton):
|
||||
elif opt in ("sw_ota", "sw_ota_auto_upgrade", "sw_voice_listen", "sw_voice_record",
|
||||
"sw_fault_alert", "sw_low_power_alert", "sw_over_speed_alert",
|
||||
"sw_sim_abnormal_alert", "sw_disassemble_alert", "sw_drive_behavior_alert"):
|
||||
if not isinstance(val, bool):
|
||||
if not isinstance(val, bool) and val not in (0, 1):
|
||||
return False
|
||||
self.current_settings["user_cfg"][opt] = val
|
||||
self.current_settings["user_cfg"][opt] = bool(val)
|
||||
return True
|
||||
elif opt == "ota_status":
|
||||
if not isinstance(val, dict):
|
||||
return False
|
||||
self.current_settings["user_cfg"][opt] = val
|
||||
return True
|
||||
elif opt in ("user_ota_action", "drive_behavior_code"):
|
||||
elif opt in ("user_ota_action", "drive_behavior_code", "loc_gps_read_timeout", "work_mode_timeline"):
|
||||
if not isinstance(val, int):
|
||||
return False
|
||||
self.current_settings["sys"][opt] = val
|
||||
|
@ -189,7 +189,8 @@ def tracker():
|
||||
# LowEnergyManage initialization
|
||||
work_cycle_period = current_settings["user_cfg"]["work_cycle_period"]
|
||||
low_energy.set_period(work_cycle_period)
|
||||
low_energy.set_low_energy_method(collector.__init_low_energy_method(work_cycle_period))
|
||||
low_energy_method = collector.__init_low_energy_method(work_cycle_period)
|
||||
low_energy.set_low_energy_method(low_energy_method)
|
||||
low_energy.addObserver(collector)
|
||||
|
||||
# RemoteSubscribe initialization
|
||||
@ -200,6 +201,8 @@ def tracker():
|
||||
# Business start
|
||||
# Cloud start
|
||||
cloud.init()
|
||||
# Report history
|
||||
collector.report_history()
|
||||
# OTA status init
|
||||
collector.ota_status_init()
|
||||
# Device modules status check
|
||||
@ -213,3 +216,5 @@ def tracker():
|
||||
controller.low_energy_init()
|
||||
# Low energy start
|
||||
controller.low_energy_start()
|
||||
if low_energy.get_low_energy_method() == "POWERDOWN":
|
||||
controller.power_down()
|
||||
|
@ -24,7 +24,7 @@ from usr.modules.mpower import LowEnergyManage
|
||||
from usr.modules.common import Singleton, LOWENERGYMAP
|
||||
from usr.modules.location import Location, GPSMatch, GPSParse, _loc_method
|
||||
from usr.settings import PROJECT_NAME, PROJECT_VERSION, DEVICE_FIRMWARE_NAME, DEVICE_FIRMWARE_VERSION, \
|
||||
settings, UserConfig, SYSConfig, LocConfig
|
||||
settings, UserConfig, SYSConfig
|
||||
from usr.tracker_controller import Controller
|
||||
from usr.tracker_devicecheck import DeviceCheck
|
||||
|
||||
@ -54,6 +54,9 @@ class Collector(Singleton):
|
||||
self.__gps_match = GPSMatch()
|
||||
self.__gps_parse = GPSParse()
|
||||
|
||||
self.__net_status = False
|
||||
self.__loc_status = False
|
||||
|
||||
def __format_loc_method(self, data):
|
||||
"""Decimal to Binary for loc method
|
||||
The first is gps, second is cell, third is wifi from binary right.
|
||||
@ -186,13 +189,13 @@ class Collector(Singleton):
|
||||
def __locator_gps_hibernation_strategy(self, onoff):
|
||||
"""Set GPS sleep"""
|
||||
current_settings = settings.get()
|
||||
gps_sleep_mode = current_settings["LocConfig"]["gps_sleep_mode"]
|
||||
work_cycle_period = current_settings["user_cfg"]["work_cycle_period"]
|
||||
if self.__locator.gps:
|
||||
if gps_sleep_mode == LocConfig._gps_sleep_mode.pull_off:
|
||||
if work_cycle_period >= 3600:
|
||||
self.__locator.gps.power_switch(onoff)
|
||||
elif gps_sleep_mode == LocConfig._gps_sleep_mode.backup:
|
||||
elif 1800 <= work_cycle_period < 3600:
|
||||
self.__locator.gps.backup(onoff)
|
||||
elif gps_sleep_mode == LocConfig._gps_sleep_mode.standby:
|
||||
elif 0 < work_cycle_period < 1200:
|
||||
self.__locator.gps.standby(onoff)
|
||||
|
||||
def __read_cloud_location(self, loc_info):
|
||||
@ -349,6 +352,8 @@ class Collector(Singleton):
|
||||
|
||||
net_status = self.__devicecheck.net()
|
||||
location_status = self.__devicecheck.location()
|
||||
self.__net_status = True if net_status == (3, 1) else False
|
||||
self.__loc_status = location_status
|
||||
temp_status = self.__devicecheck.temp()
|
||||
light_status = self.__devicecheck.light()
|
||||
triaxial_status = self.__devicecheck.triaxial()
|
||||
@ -407,6 +412,7 @@ class Collector(Singleton):
|
||||
device_data = {
|
||||
"power_switch": power_switch,
|
||||
"local_time": self.__get_local_time(),
|
||||
"gps_mode": current_settings["LocConfig"]["gps_mode"],
|
||||
}
|
||||
|
||||
# Get ota status & drive behiver code
|
||||
@ -422,17 +428,18 @@ class Collector(Singleton):
|
||||
device_data.update({"loc_method": self.__format_loc_method(current_settings["user_cfg"]["loc_method"])})
|
||||
|
||||
# Get cloud location data
|
||||
loc_info = self.__read_location()
|
||||
cloud_loc = self.__read_cloud_location(loc_info)
|
||||
device_data.update(cloud_loc)
|
||||
gps_data = loc_info.get(_loc_method.gps)
|
||||
if gps_data:
|
||||
gga_satellite = self.__gps_parse.GxGGA_satellite_num(self.__gps_match.GxGGA(gps_data))
|
||||
log.debug("GxGGA Satellite Num %s" % gga_satellite)
|
||||
gsv_satellite = self.__gps_parse.GxGSV_satellite_num(self.__gps_match.GxGSV(gps_data))
|
||||
log.debug("GxGSV Satellite Num %s" % gsv_satellite)
|
||||
# Get gps speed
|
||||
device_data.update(self.__check_speed(gps_data))
|
||||
if self.__loc_status:
|
||||
loc_info = self.__read_location()
|
||||
cloud_loc = self.__read_cloud_location(loc_info)
|
||||
device_data.update(cloud_loc)
|
||||
gps_data = loc_info.get(_loc_method.gps)
|
||||
if gps_data:
|
||||
gga_satellite = self.__gps_parse.GxGGA_satellite_num(self.__gps_match.GxGGA(gps_data))
|
||||
log.debug("GxGGA Satellite Num %s" % gga_satellite)
|
||||
gsv_satellite = self.__gps_parse.GxGSV_satellite_num(self.__gps_match.GxGSV(gps_data))
|
||||
log.debug("GxGSV Satellite Num %s" % gsv_satellite)
|
||||
# Get gps speed
|
||||
device_data.update(self.__check_speed(gps_data))
|
||||
|
||||
# Get battery energy
|
||||
battery_data = self.__read_battery()
|
||||
@ -580,7 +587,9 @@ class Collector(Singleton):
|
||||
|
||||
def event_query(self, *args, **kwargs):
|
||||
"""Hanle quering object model downlink message from cloud."""
|
||||
return self.device_data_report()
|
||||
power_switch = kwargs.get("power_switch", 1)
|
||||
power_switch = bool(power_switch)
|
||||
return self.device_data_report(power_switch=power_switch)
|
||||
|
||||
def event_ota_plain(self, *args, **kwargs):
|
||||
"""Hanle OTA plain from cloud."""
|
||||
@ -649,11 +658,12 @@ class Collector(Singleton):
|
||||
log.debug("RRPC data: %s" % data)
|
||||
self.__controller.remote_rrpc_response(message_id, data)
|
||||
|
||||
def power_switch(self, onoff=None):
|
||||
def power_switch(self, onoff=1):
|
||||
"""Control device power"""
|
||||
if not self.__controller:
|
||||
raise TypeError("self.__controller is not registered.")
|
||||
|
||||
onoff = bool(onoff)
|
||||
self.event_query(power_switch=onoff)
|
||||
if onoff is False:
|
||||
self.__controller.power_down()
|
||||
@ -749,30 +759,36 @@ class Collector(Singleton):
|
||||
|
||||
def low_engery_option(self, low_energy_method):
|
||||
"""Business option after low energy waking up."""
|
||||
log.debug("start low_engery_option")
|
||||
if not self.__controller:
|
||||
raise TypeError("self.__controller is not registered.")
|
||||
|
||||
self.report_history()
|
||||
self.__controller.remote_device_report()
|
||||
self.__controller.remote_ota_check()
|
||||
report_flag = True
|
||||
current_settings = settings.get()
|
||||
if current_settings["user_cfg"]["work_mode"] == UserConfig._work_mode.intelligent:
|
||||
speed_info = self.__check_speed()
|
||||
if speed_info.get("current_speed") > 0:
|
||||
self.device_data_report()
|
||||
else:
|
||||
self.device_data_report()
|
||||
# TODO: Check speed by sensor
|
||||
if self.__loc_status:
|
||||
loc_info = self.__read_location()
|
||||
gps_data = loc_info.get(_loc_method.gps)
|
||||
speed_info = self.__check_speed(gps_data)
|
||||
if speed_info.get("current_speed") <= 0:
|
||||
report_flag = False
|
||||
|
||||
if report_flag is True:
|
||||
self.device_status_check()
|
||||
if self.__net_status:
|
||||
self.__controller.remote_device_report()
|
||||
self.__controller.remote_ota_check()
|
||||
|
||||
# Check battery low enery power down.
|
||||
self.__check_battery_low_energy_power_down()
|
||||
|
||||
self.__controller.low_energy_start()
|
||||
|
||||
if low_energy_method == "PSM":
|
||||
# TODO: PSM option.
|
||||
pass
|
||||
elif low_energy_method == "POWERDOWN":
|
||||
if low_energy_method == "POWERDOWN":
|
||||
self.__controller.power_down()
|
||||
log.debug("end low_engery_option")
|
||||
|
||||
def thing_services(self, data):
|
||||
log.debug("thing_services data: %s" % str(data))
|
||||
|
@ -57,6 +57,11 @@ class DeviceCheck(object):
|
||||
sleep_time = 1
|
||||
|
||||
while retry < 5:
|
||||
if retry > 0:
|
||||
retry += 1
|
||||
utime.sleep(sleep_time)
|
||||
sleep_time *= 2
|
||||
|
||||
if current_settings["user_cfg"].get("loc_method"):
|
||||
loc_method = current_settings["user_cfg"].get("loc_method")
|
||||
elif current_settings["sys"]["base_cfg"]["LocConfig"]:
|
||||
@ -64,13 +69,13 @@ class DeviceCheck(object):
|
||||
else:
|
||||
loc_method = 7
|
||||
|
||||
gps_data = self.__locator.read(loc_method)
|
||||
loc_info = self.__locator.read(loc_method)
|
||||
for k, v in loc_info.items():
|
||||
gps_data = v
|
||||
if gps_data:
|
||||
break
|
||||
if gps_data:
|
||||
break
|
||||
else:
|
||||
retry += 1
|
||||
utime.sleep(sleep_time)
|
||||
sleep_time *= 2
|
||||
|
||||
if gps_data:
|
||||
return True
|
||||
|
@ -617,7 +617,7 @@
|
||||
"dataType": {
|
||||
"type": "int",
|
||||
"specs": {
|
||||
"min": "0",
|
||||
"min": "3600",
|
||||
"max": "2147483647",
|
||||
"unit": "s",
|
||||
"unitName": "秒",
|
||||
@ -1203,7 +1203,7 @@
|
||||
"dataType": {
|
||||
"type": "int",
|
||||
"specs": {
|
||||
"min": "0",
|
||||
"min": "3600",
|
||||
"max": "2147483647",
|
||||
"unit": "s",
|
||||
"unitName": "秒",
|
||||
@ -1556,7 +1556,7 @@
|
||||
"dataType": {
|
||||
"type": "int",
|
||||
"specs": {
|
||||
"min": "0",
|
||||
"min": "3600",
|
||||
"max": "2147483647",
|
||||
"unit": "s",
|
||||
"unitName": "秒",
|
||||
@ -2173,7 +2173,7 @@
|
||||
"dataType": {
|
||||
"type": "int",
|
||||
"specs": {
|
||||
"min": "0",
|
||||
"min": "3600",
|
||||
"max": "2147483647",
|
||||
"unit": "s",
|
||||
"unitName": "秒",
|
||||
|
@ -2,7 +2,7 @@
|
||||
"profile":{
|
||||
"tslVersion":"1.1.0",
|
||||
"productKey":"p11275",
|
||||
"version":"20220428155940369"
|
||||
"version":"20220526133940091"
|
||||
},
|
||||
"properties":[
|
||||
{
|
||||
@ -808,22 +808,6 @@
|
||||
"type":"PROPERTY",
|
||||
"desc":""
|
||||
},
|
||||
{
|
||||
"specs":{
|
||||
"unit":"s",
|
||||
"min":"0",
|
||||
"max":"2147483647",
|
||||
"step":"1"
|
||||
},
|
||||
"code":"work_mode_timeline",
|
||||
"dataType":"INT",
|
||||
"name":"休眠策略参考时间",
|
||||
"subType":"RW",
|
||||
"id":44,
|
||||
"sort":35,
|
||||
"type":"PROPERTY",
|
||||
"desc":""
|
||||
},
|
||||
{
|
||||
"specs":{
|
||||
"unit":"s",
|
||||
@ -839,6 +823,22 @@
|
||||
"sort":36,
|
||||
"type":"PROPERTY",
|
||||
"desc":"-1:一直等待直到读取到数据才进行返回\n0:不等待,读取接口返回数据后立即返回\n>0: 等待超时时间,单位秒"
|
||||
},
|
||||
{
|
||||
"specs":{
|
||||
"unit":"s",
|
||||
"min":"3600",
|
||||
"max":"2147483647",
|
||||
"step":"1"
|
||||
},
|
||||
"code":"work_mode_timeline",
|
||||
"dataType":"INT",
|
||||
"name":"休眠策略参考时间",
|
||||
"subType":"RW",
|
||||
"id":1,
|
||||
"sort":37,
|
||||
"type":"PROPERTY",
|
||||
"desc":""
|
||||
}
|
||||
],
|
||||
"events":[
|
||||
|
Loading…
x
Reference in New Issue
Block a user