update: loc_mode to work_mode; add: sim out alert;

This commit is contained in:
JackSun-qc 2022-03-21 19:40:33 +08:00
parent d2fce432f0
commit 520fed1345
7 changed files with 49 additions and 34 deletions

View File

@ -32,8 +32,8 @@ object_model = {
'energy',
'phone_num',
'loc_method',
'loc_mode',
'loc_cycle_period',
'work_mode',
'work_cycle_period',
'local_time',
'low_power_alert_threshold',
'low_power_shutdown_threshold',

View File

@ -18,8 +18,8 @@ object_model = [
(4, ('energy', 'r')),
(23, ('phone_num', 'rw')),
(24, ('loc_method', 'rw')),
(25, ('loc_mode', 'rw')),
(26, ('loc_cycle_period', 'rw')),
(25, ('work_mode', 'rw')),
(26, ('work_cycle_period', 'rw')),
(19, ('local_time', 'r')),
(15, ('low_power_alert_threshold', 'rw')),
(16, ('low_power_shutdown_threshold', 'rw')),

View File

@ -85,13 +85,12 @@ class default_values_app(object):
wifi = 0x4
all = 0x7
class _loc_mode(object):
class _work_mode(object):
none = 0x0
cycle = 0x1
onAlert = 0x2
onPhoneCall = 0x4
onVoiceRecord = 0x8
all = 0xF
intelligent = 0x2
lowenergy = 0x4
all = 0x7
class _drive_behavior(object):
suddenly_start = 0
@ -107,9 +106,9 @@ class default_values_app(object):
loc_method = _loc_method.gps
loc_mode = _loc_mode.cycle
work_mode = _work_mode.cycle
loc_cycle_period = 30
work_cycle_period = 30
low_power_alert_threshold = 20
@ -324,15 +323,15 @@ class Settings(Singleton):
self.current_settings['sys']['locator_init_params'] = default_values_sys._get_locator_init_params(val)
return True
elif opt == 'loc_mode':
elif opt == 'work_mode':
if not isinstance(val, int):
return False
if val > default_values_app._loc_mode.all:
if val > default_values_app._work_mode.all:
return False
self.current_settings['app'][opt] = val
return True
elif opt == 'loc_cycle_period':
elif opt == 'work_cycle_period':
if not isinstance(val, int):
return False
if val < 1:

View File

@ -34,9 +34,10 @@ class TrackerTimer(Singleton):
self.gnss_count += 1
self.quec_ota += 1
if (current_settings['app']['loc_mode'] & settings.default_values_app._loc_mode.cycle) \
and current_settings['app']['loc_cycle_period'] \
and self.loc_count >= current_settings['app']['loc_cycle_period']:
if (current_settings['app']['work_mode'] & settings.default_values_app._work_mode.cycle or
current_settings['app']['work_mode'] & settings.default_values_app._work_mode.intelligent) \
and current_settings['app']['work_cycle_period'] \
and self.loc_count >= current_settings['app']['work_cycle_period']:
self.loc_count = 0
self.loc_timer()
@ -57,6 +58,14 @@ class TrackerTimer(Singleton):
self.quecthing_ota_timer()
def loc_timer(self):
current_settings = settings.settings.get()
if current_settings['app']['work_mode'] & settings.default_values_app._work_mode.intelligent:
if not self.tracker.locator.gps:
if not self.tracker.locator.gps.read_location_GxVTG_speed():
return
else:
return
self.tracker.over_speed_check()
self.tracker.machine_info_report()

View File

@ -1,5 +1,6 @@
import utime
import checkNet
import dataCall
import usr.settings as settings
@ -44,6 +45,7 @@ class Tracker(Singleton):
if USB is not None:
self.usb = USB()
self.usb.setCallback(self.usb_callback)
dataCall.setCallback(self.nw_callback)
def loc_report(self):
data = self.locator.read()
@ -99,21 +101,21 @@ class Tracker(Singleton):
alert_code = 20000
fault_code = 0
if net_check_res and gps_check_res and sensor_check_res:
if net_check_res == (3, 1) and gps_check_res and sensor_check_res:
self.running_led.period = 2
else:
self.running_led.period = 0.5
if not net_check_res:
if net_check_res != (3, 1):
fault_code = 20001
alert_info = {'fault_code': fault_code, 'local_time': utime.mktime(utime.localtime())}
self.alert_report(alert_code, alert_info)
if not gps_check_res:
fault_code = 20002
alert_info = {'fault_code': fault_code, 'local_time': utime.mktime(utime.localtime())}
self.alert_report(alert_code, alert_info)
if not sensor_check_res:
# TODO: Need To Check What Sensor Error To Report.
pass
self.alert_report(alert_code, alert_info)
self.machine_info_report()
return fault_code
@ -158,6 +160,14 @@ class Tracker(Singleton):
else:
log.warn('Unknown USB Stauts:', status)
def nw_callback(self, args):
net_check_res = self.check.net_check()
if args[1] != 1:
if net_check_res[0] == 0 or (net_check_res[0] == 1 and net_check_res[1] == 0):
alert_code = 30004
alert_info = {'local_time': utime.mktime(utime.localtime())}
self.alert_report(alert_code, alert_info)
class SelfCheck(object):
@ -167,10 +177,7 @@ class SelfCheck(object):
checknet = checkNet.CheckNetwork(settings.PROJECT_NAME, settings.PROJECT_VERSION)
timeout = current_settings.get('sys', {}).get('checknet_timeout', 60)
check_res = checknet.wait_network_connected(timeout)
if check_res == (3, 1):
return True
else:
return False
return check_res
def gps_check(self):
# return True if OK

View File

@ -62,7 +62,7 @@
- 根据不同的应用场景,上报工作模式分别有:
1. 周期性模式 -- 周期性上报设备信息
2. 智能模式 -- 开启GPS定位时运动上报静止不上报可设置周期
3. 低功耗模式 -- 周期性开机后上报设备信息,上报完成后关机
3. 低功耗模式(开发中) -- 周期性开机后上报设备信息,上报完成后关机
- 上报工作模式与上报周期由云端或手机APP控制。
#### OTA升级(开发中)
@ -245,8 +245,8 @@ tracker.remote.post_data(data_type, data)
|电量|`energy`|`int`|取值范围0 ~ 100||只读|
|电话号码|`phone_num`|`text`|数据长度11||读写|
|定位方式|`loc_method`|`int`|取值范围0 ~ 7|0: 无;1: GPS;2: 基站;4: WIFI(暂不支持);7: 全部支持|读写|
|定位工作模式|`loc_mode`|`int`|取值范围0 ~ 15|0: 无;1: 循环;2: 报警时;4: 电话呼入;8: 开启录音时;15: 全部|读写|
|定位周期|`loc_cycle_period`|`int`|取值范围: ~|单位s|读写|
|工作模式|`work_mode`|`int`|取值范围0 ~ 15|0: 无;1: 周期性模式;2: 智能模式;4: 低功耗模式;7: 全部|读写|
|工作模式循环周期|`work_cycle_period`|`int`|取值范围: ~|单位s|读写|
|本地时间|`local_time`|`int`|取值范围: ~||只读|
|低电报警阈值|`low_power_alert_threshold`|`int`|取值范围5 ~ 30||读写|
|低电关机阈值|`low_power_shutdown_threshold`|`int`|取值范围5 ~ 30||读写|
@ -471,10 +471,10 @@ current_settings = settings.get()
```json
{
"app": {
"loc_cycle_period": 1,
"work_cycle_period": 30,
"phone_num": "",
"loc_method": 1,
"loc_mode": 0,
"work_mode": 0,
"low_power_alert_threshold": 20,
"low_power_shutdown_threshold": 5,
"sw_over_speed_alert": true,

View File

@ -79,7 +79,7 @@
"max":"15",
"step":"1"
},
"code":"loc_mode",
"code":"work_mode",
"dataType":"INT",
"name":"定位工作模式",
"subType":"RW",
@ -95,9 +95,9 @@
"max":"",
"step":""
},
"code":"loc_cycle_period",
"code":"work_cycle_period",
"dataType":"INT",
"name":"定位周期",
"name":"工作循环周期",
"subType":"RW",
"id":26,
"sort":5,
@ -609,4 +609,4 @@
"desc":""
}
]
}
}