mirror of
https://gitee.com/qpy-solutions/tracker-v2.git
synced 2025-05-18 18:48:25 +08:00
update: 1. GPS,Location,Remote,Settings To Singleton; 2. alter code & drive behavior code
This commit is contained in:
parent
54ee755183
commit
8649a011a0
@ -6,23 +6,22 @@ from usr.logging import getLogger
|
|||||||
|
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
|
|
||||||
# TODO: Use objec model code?
|
|
||||||
ALERTCODE = {
|
ALERTCODE = {
|
||||||
30001: 'fault_alert',
|
30001: 'fault_alert',
|
||||||
30002: 'low_power_alert',
|
30002: 'low_power_alert',
|
||||||
30003: 'over_speed_alert',
|
30003: 'over_speed_alert',
|
||||||
30004: 'sim_out_alert',
|
30004: 'sim_out_alert',
|
||||||
30005: 'disassemble_alert',
|
30005: 'disassemble_alert',
|
||||||
# 30006: 'shock_alert', # TODO: NOT USED
|
|
||||||
40000: 'drive_behavior_alert',
|
40000: 'drive_behavior_alert',
|
||||||
50001: 'sos_alert',
|
50001: 'sos_alert',
|
||||||
}
|
}
|
||||||
|
|
||||||
DRIVEBEHAVIORCODE = {
|
DRIVE_BEHAVIOR_CODE = {
|
||||||
1: 'quick_start',
|
40001: 'quick_start',
|
||||||
2: 'quick_stop',
|
40002: 'quick_stop',
|
||||||
3: 'quick_turn_left',
|
40003: 'quick_turn_left',
|
||||||
4: 'quick_turn_right',
|
40004: 'quick_turn_right',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -38,9 +37,9 @@ def alert_process(argv):
|
|||||||
'''
|
'''
|
||||||
alert_signals_queue data format
|
alert_signals_queue data format
|
||||||
|
|
||||||
(300001, {})
|
(30001, {'local_time': 1646731286})
|
||||||
|
|
||||||
(400000, {40001: True})
|
(40000, {'drive_behavior_code': 40001, 'local_time': 1646731286})
|
||||||
'''
|
'''
|
||||||
self = argv
|
self = argv
|
||||||
while True:
|
while True:
|
||||||
@ -58,7 +57,7 @@ def alert_process(argv):
|
|||||||
log.error('altercode (%s) is not exists. alert info: %s' % data)
|
log.error('altercode (%s) is not exists. alert info: %s' % data)
|
||||||
|
|
||||||
|
|
||||||
class AlertMonitor(object):
|
class AlertMonitor(settings.Singleton):
|
||||||
'''
|
'''
|
||||||
Recv alert signals and process them
|
Recv alert signals and process them
|
||||||
'''
|
'''
|
||||||
|
@ -43,7 +43,7 @@ def gps_data_retrieve_thread(argv):
|
|||||||
self.gps_data = self.uart_read(toRead).decode()
|
self.gps_data = self.uart_read(toRead).decode()
|
||||||
|
|
||||||
|
|
||||||
class GPS(object):
|
class GPS(settings.Singleton):
|
||||||
def __init__(self, gps_cfg):
|
def __init__(self, gps_cfg):
|
||||||
global gps_data_retrieve_queue
|
global gps_data_retrieve_queue
|
||||||
self.uart_obj = UART(
|
self.uart_obj = UART(
|
||||||
@ -140,7 +140,7 @@ def loc_worker(argv):
|
|||||||
self.read_cb(data)
|
self.read_cb(data)
|
||||||
|
|
||||||
|
|
||||||
class Location(object):
|
class Location(settings.Singleton):
|
||||||
gps = None
|
gps = None
|
||||||
cellLoc = None
|
cellLoc = None
|
||||||
wifiLoc = None
|
wifiLoc = None
|
||||||
|
@ -206,7 +206,7 @@ def uplink_process(argv):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
class Remote(object):
|
class Remote(settings.Singleton):
|
||||||
_history = '/usr/tracker_data.hist'
|
_history = '/usr/tracker_data.hist'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -37,6 +37,15 @@ class SettingsError(Exception):
|
|||||||
return repr(self.value)
|
return repr(self.value)
|
||||||
|
|
||||||
|
|
||||||
|
class Singleton(object):
|
||||||
|
_instance = None
|
||||||
|
|
||||||
|
def __new__(cls, *args, **kwargs):
|
||||||
|
if not cls._instance:
|
||||||
|
cls._instance = super().__new__(cls)
|
||||||
|
return cls._instance
|
||||||
|
|
||||||
|
|
||||||
class default_values_app(object):
|
class default_values_app(object):
|
||||||
'''
|
'''
|
||||||
App default settings
|
App default settings
|
||||||
@ -206,7 +215,7 @@ class default_values_sys(object):
|
|||||||
return cloud_init_params
|
return cloud_init_params
|
||||||
|
|
||||||
|
|
||||||
class Settings(object):
|
class Settings(Singleton):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.current_settings = {}
|
self.current_settings = {}
|
||||||
@ -309,4 +318,5 @@ class Settings(object):
|
|||||||
def reset(self):
|
def reset(self):
|
||||||
uos.remove(tracker_settings_file)
|
uos.remove(tracker_settings_file)
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user