From 8649a011a01c106f65f18a5c8c9c25f79ab3af5c Mon Sep 17 00:00:00 2001 From: JackSun-qc Date: Wed, 9 Mar 2022 10:51:39 +0800 Subject: [PATCH] =?UTF-8?q?update:=201.=20GPS=EF=BC=8CLocation=EF=BC=8CRem?= =?UTF-8?q?ote=EF=BC=8CSettings=20To=20Singleton;=202.=20alter=20code=20&?= =?UTF-8?q?=20drive=20behavior=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/alert.py | 19 +++++++++---------- code/location.py | 4 ++-- code/remote.py | 2 +- code/settings.py | 12 +++++++++++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/code/alert.py b/code/alert.py index ee3376e..4a4ea1f 100644 --- a/code/alert.py +++ b/code/alert.py @@ -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 ''' diff --git a/code/location.py b/code/location.py index 3a4070f..baeafbd 100644 --- a/code/location.py +++ b/code/location.py @@ -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 diff --git a/code/remote.py b/code/remote.py index 0133f6c..c83f21e 100644 --- a/code/remote.py +++ b/code/remote.py @@ -206,7 +206,7 @@ def uplink_process(argv): continue -class Remote(object): +class Remote(settings.Singleton): _history = '/usr/tracker_data.hist' def __init__(self): diff --git a/code/settings.py b/code/settings.py index 8860b61..64ed7dd 100644 --- a/code/settings.py +++ b/code/settings.py @@ -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()