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__)
|
||||
|
||||
# TODO: Use objec model code?
|
||||
|
||||
ALERTCODE = {
|
||||
30001: 'fault_alert',
|
||||
30002: 'low_power_alert',
|
||||
30003: 'over_speed_alert',
|
||||
30004: 'sim_out_alert',
|
||||
30005: 'disassemble_alert',
|
||||
# 30006: 'shock_alert', # TODO: NOT USED
|
||||
40000: 'drive_behavior_alert',
|
||||
50001: 'sos_alert',
|
||||
}
|
||||
|
||||
DRIVEBEHAVIORCODE = {
|
||||
1: 'quick_start',
|
||||
2: 'quick_stop',
|
||||
3: 'quick_turn_left',
|
||||
4: 'quick_turn_right',
|
||||
DRIVE_BEHAVIOR_CODE = {
|
||||
40001: 'quick_start',
|
||||
40002: 'quick_stop',
|
||||
40003: 'quick_turn_left',
|
||||
40004: 'quick_turn_right',
|
||||
}
|
||||
|
||||
|
||||
@ -38,9 +37,9 @@ def alert_process(argv):
|
||||
'''
|
||||
alert_signals_queue data format
|
||||
|
||||
(300001, {})
|
||||
(30001, {'local_time': 1646731286})
|
||||
|
||||
(400000, {40001: True})
|
||||
(40000, {'drive_behavior_code': 40001, 'local_time': 1646731286})
|
||||
'''
|
||||
self = argv
|
||||
while True:
|
||||
@ -58,7 +57,7 @@ def alert_process(argv):
|
||||
log.error('altercode (%s) is not exists. alert info: %s' % data)
|
||||
|
||||
|
||||
class AlertMonitor(object):
|
||||
class AlertMonitor(settings.Singleton):
|
||||
'''
|
||||
Recv alert signals and process them
|
||||
'''
|
||||
|
@ -43,7 +43,7 @@ def gps_data_retrieve_thread(argv):
|
||||
self.gps_data = self.uart_read(toRead).decode()
|
||||
|
||||
|
||||
class GPS(object):
|
||||
class GPS(settings.Singleton):
|
||||
def __init__(self, gps_cfg):
|
||||
global gps_data_retrieve_queue
|
||||
self.uart_obj = UART(
|
||||
@ -140,7 +140,7 @@ def loc_worker(argv):
|
||||
self.read_cb(data)
|
||||
|
||||
|
||||
class Location(object):
|
||||
class Location(settings.Singleton):
|
||||
gps = None
|
||||
cellLoc = None
|
||||
wifiLoc = None
|
||||
|
@ -206,7 +206,7 @@ def uplink_process(argv):
|
||||
continue
|
||||
|
||||
|
||||
class Remote(object):
|
||||
class Remote(settings.Singleton):
|
||||
_history = '/usr/tracker_data.hist'
|
||||
|
||||
def __init__(self):
|
||||
|
@ -37,6 +37,15 @@ class SettingsError(Exception):
|
||||
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):
|
||||
'''
|
||||
App default settings
|
||||
@ -206,7 +215,7 @@ class default_values_sys(object):
|
||||
return cloud_init_params
|
||||
|
||||
|
||||
class Settings(object):
|
||||
class Settings(Singleton):
|
||||
|
||||
def __init__(self):
|
||||
self.current_settings = {}
|
||||
@ -309,4 +318,5 @@ class Settings(object):
|
||||
def reset(self):
|
||||
uos.remove(tracker_settings_file)
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
Loading…
x
Reference in New Issue
Block a user