This commit is contained in:
chenchi 2022-03-04 17:09:22 +08:00
commit fc3d66a248
5 changed files with 35 additions and 45 deletions

View File

@ -42,7 +42,7 @@ def gps_data_retrieve_thread(argv):
class GPS(UART):
def __init__(self, gps_cfg):
global gps_data_retrieve_queue
super(GPS, self).__init__(gps_cfg['UARTn'], gps_cfg['buadrate'], gps_cfg['databits'], gps_cfg['parity'], gps_cfg['stopbits'], gps_cfg['flowctl'])
super(UART, self).__init__(gps_cfg['UARTn'], gps_cfg['buadrate'], gps_cfg['databits'], gps_cfg['parity'], gps_cfg['stopbits'], gps_cfg['flowctl'])
self.set_callback(gps_data_retrieve_cb)
self.gps_data = ''
gps_data_retrieve_queue = Queue(maxsize=8)
@ -113,8 +113,7 @@ class Location(GPS, CellLocator, WiFiLocator):
wifiLoc_enabled = False
def __init__(self, read_cb, **kw):
current_settings, _ = settings.get()
# current_settings = settings.current_settings
current_settings = settings.current_settings
self.read_cb = read_cb

View File

@ -8,8 +8,6 @@ log = getLogger(__name__)
tracker = None
PROFILE_IDX = 0
def loc_read_cb(data):
if data:
@ -23,7 +21,7 @@ def loc_read_cb(data):
data_type = tracker.remote.DATA_LOCA_NON_GPS
tracker.remote.post_data(data_type, loc_data)
tracker = Tracker(loc_read_cb, **settings.locator_init_params)
tracker = Tracker(loc_read_cb, **settings.current_settings['sys']['locator_init_params'])
def loc_timer_cb(argv):
@ -32,9 +30,9 @@ def loc_timer_cb(argv):
if __name__ == '__main__':
settings.init()
# current_settings, locator_init_params = settings.get()
current_settings = settings.current_settings
if (settings.current_settings['app']['loc_mode'] & settings.default_values_app._loc_mode.cycle) \
and settings.current_settings['app']['loc_cycle_period']:
if (current_settings['app']['loc_mode'] & settings.default_values_app._loc_mode.cycle) \
and current_settings['app']['loc_cycle_period']:
loc_timer = osTimer()
loc_timer.start(settings.current_settings['app']['loc_cycle_period'] * 1000, 1, loc_timer_cb)
loc_timer.start(current_settings['app']['loc_cycle_period'] * 1000, 1, loc_timer_cb)

View File

@ -7,7 +7,6 @@ DATA_NON_LOCA = 0x0
DATA_LOCA_NON_GPS = 0x1
DATA_LOCA_GPS = 0x2
# log = getLogger('QuecThing')
log = getLogger(__name__)
object_model = [

View File

@ -1,5 +1,4 @@
# from logging import exception
import utime
import ql_fs
import ujson
@ -9,7 +8,7 @@ from queue import Queue
import usr.settings as settings
import usr.dev_info as dev_info
current_settings = settings.get()
current_settings = settings.current_settings
if current_settings['sys']['cloud'] == settings.default_values_sys._cloud.quecIot:
from usr.quecthing import QuecThing

View File

@ -7,6 +7,10 @@ from machine import UART
tracker_settings_file = '/usr/tracker_settings.json'
current_settings = {}
current_settings_app = {}
current_settings_sys = {}
class default_values_app(object):
'''
@ -88,48 +92,47 @@ class default_values_sys(object):
'''
variables of system default settings below MUST NOT start with '_'
'''
profile_idx = 0
cloud = _cloud.quecIot
locator_init_params = {}
default_settings_app = {k: v for k, v in default_values_app.__dict__.items() if not k.startswith('_')}
current_settings_app = {}
default_settings_sys = {k: v for k, v in default_values_sys.__dict__.items() if not k.startswith('_')}
current_settings_sys = {}
default_settings = {'app': default_settings_app, 'sys': default_settings_sys}
current_settings = {}
PROFILE_IDX = 0
locator_init_params = {}
all_locator_init_params = {
'gps_cfg': {
_gps_cfg = {
'UARTn': UART.UART0,
'buadrate': 115200,
'databits': 8,
'parity': 0,
'stopbits': 1,
'flowctl': 0
},
'cellLocator_cfg': {
'flowctl': 0,
}
_cellLocator_cfg = {
'serverAddr': 'www.queclocator.com',
'port': 80,
'token': 'xGP77d2z0i91s67n',
'timeout': 3,
'profileIdx': PROFILE_IDX
},
'wifiLocator_cfg': {
'profileIdx': profile_idx,
}
_wifiLocator_cfg = {
'token': 'xGP77d2z0i91s67n'
}
}
def init():
global current_settings
global locator_init_params
if default_values_app.loc_method & default_values_app._loc_method.gps:
default_values_sys.locator_init_params = default_values_sys._gps_cfg
elif default_values_app.loc_method & default_values_app._loc_method.cell:
default_values_sys.locator_init_params = default_values_sys._cellLocator_cfg
elif default_values_app.loc_method & default_values_app._loc_method.wifi:
default_values_sys.locator_init_params = default_values_sys._wifiLocator_cfg
default_settings_app = {k: v for k, v in default_values_app.__dict__.items() if not k.startswith('_')}
default_settings_sys = {k: v for k, v in default_values_sys.__dict__.items() if not k.startswith('_')}
default_settings = {'app': default_settings_app, 'sys': default_settings_sys}
if not ql_fs.path_exists(tracker_settings_file):
with open(tracker_settings_file, 'w') as f:
@ -139,18 +142,10 @@ def init():
with open(tracker_settings_file, 'r') as f:
current_settings = ujson.load(f)
if current_settings['app']['loc_method'] & default_values_app._loc_method.gps:
locator_init_params['gps_cfg'] = all_locator_init_params['gps_cfg']
elif current_settings['app']['loc_method'] & default_values_app._loc_method.cell:
locator_init_params['cellLocator_cfg'] = all_locator_init_params['cellLocator_cfg']
elif current_settings['app']['loc_method'] & default_values_app._loc_method.wifi:
locator_init_params['wifiLocator_cfg'] = all_locator_init_params['wifiLocator_cfg']
def get():
global current_settings
global locator_init_params
return current_settings, locator_init_params
return current_settings
def set(opt, val):