mirror of
https://gitee.com/qpy-solutions/tracker-v2.git
synced 2025-05-19 02:58:25 +08:00
update: 1. settings split two files; 2. speed check move to get_device_data; 3. cloud close; 4. delete log code.
This commit is contained in:
parent
1c7245f94d
commit
9f4f9fa1c2
@ -161,6 +161,9 @@ class AliYunIot(object):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cloud_close(self):
|
||||||
|
self.ali.disconnect()
|
||||||
|
|
||||||
def ali_subcribe_topic(self):
|
def ali_subcribe_topic(self):
|
||||||
if self.ali.subscribe(self.ica_topic_property_post, qos=0) == -1:
|
if self.ali.subscribe(self.ica_topic_property_post, qos=0) == -1:
|
||||||
log.error('Topic [%s] Subscribe Falied.' % self.ica_topic_property_post)
|
log.error('Topic [%s] Subscribe Falied.' % self.ica_topic_property_post)
|
||||||
|
@ -101,7 +101,6 @@ class GPS(Singleton):
|
|||||||
def first_gps_timer_callback(self, args):
|
def first_gps_timer_callback(self, args):
|
||||||
global gps_data_retrieve_queue
|
global gps_data_retrieve_queue
|
||||||
self.__first_break = 1
|
self.__first_break = 1
|
||||||
log.debug('self.__first_break: %s' % self.__first_break)
|
|
||||||
if gps_data_retrieve_queue is not None:
|
if gps_data_retrieve_queue is not None:
|
||||||
gps_data_retrieve_queue.put(0)
|
gps_data_retrieve_queue.put(0)
|
||||||
log.debug('gps_data_retrieve_queue.put(0)')
|
log.debug('gps_data_retrieve_queue.put(0)')
|
||||||
@ -118,15 +117,12 @@ class GPS(Singleton):
|
|||||||
global gps_data_retrieve_queue
|
global gps_data_retrieve_queue
|
||||||
|
|
||||||
while self.__first_break == 0:
|
while self.__first_break == 0:
|
||||||
log.debug('self.__first_break: %s' % self.__first_break)
|
self.__gps_timer.start(50, 0, self.first_gps_timer_callback)
|
||||||
timer_start_res = self.__gps_timer.start(50, 0, self.first_gps_timer_callback)
|
|
||||||
log.debug('timer_start_res: %s' % timer_start_res)
|
|
||||||
nread = gps_data_retrieve_queue.get()
|
nread = gps_data_retrieve_queue.get()
|
||||||
log.debug('__first_break nread: %s' % nread)
|
log.debug('__first_break nread: %s' % nread)
|
||||||
data = self.uart_obj.read(nread).decode()
|
data = self.uart_obj.read(nread).decode()
|
||||||
log.debug('__first_break data: %s' % data)
|
log.debug('__first_break data: %s' % data)
|
||||||
self.__gps_timer.stop()
|
self.__gps_timer.stop()
|
||||||
log.debug('self.__first_break: %s' % self.__first_break)
|
|
||||||
self.__first_break = 0
|
self.__first_break = 0
|
||||||
|
|
||||||
data = ''
|
data = ''
|
||||||
@ -134,7 +130,6 @@ class GPS(Singleton):
|
|||||||
gga_data = ''
|
gga_data = ''
|
||||||
vtg_data = ''
|
vtg_data = ''
|
||||||
while self.__second_break == 0:
|
while self.__second_break == 0:
|
||||||
log.debug('self.__second_break: %s' % self.__second_break)
|
|
||||||
self.__gps_timer.start(1500, 0, self.second_gps_timer_callback)
|
self.__gps_timer.start(1500, 0, self.second_gps_timer_callback)
|
||||||
nread = gps_data_retrieve_queue.get()
|
nread = gps_data_retrieve_queue.get()
|
||||||
log.debug('__second_break nread: %s' % nread)
|
log.debug('__second_break nread: %s' % nread)
|
||||||
@ -149,11 +144,9 @@ class GPS(Singleton):
|
|||||||
if rmc_data and gga_data and vtg_data:
|
if rmc_data and gga_data and vtg_data:
|
||||||
self.__second_break = 1
|
self.__second_break = 1
|
||||||
self.__gps_timer.stop()
|
self.__gps_timer.stop()
|
||||||
log.debug('self.__second_break: %s' % self.__second_break)
|
log.debug('__second_break(uart_read) data: %s' % data)
|
||||||
log.debug('__second_break data: %s' % data)
|
|
||||||
self.__second_break = 0
|
self.__second_break = 0
|
||||||
|
|
||||||
log.debug('uart_read data: %s' % data)
|
|
||||||
self.uart_close()
|
self.uart_close()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
@ -118,9 +118,8 @@ class PowerManage(Singleton):
|
|||||||
if self.lpm_fd is None:
|
if self.lpm_fd is None:
|
||||||
self.lpm_fd = pm.create_wakelock("lowenergy_lock", len("lowenergy_lock"))
|
self.lpm_fd = pm.create_wakelock("lowenergy_lock", len("lowenergy_lock"))
|
||||||
pm.autosleep(1)
|
pm.autosleep(1)
|
||||||
pm.wakelock_lock(self.lpm_fd)
|
wlk_res = pm.wakelock_lock(self.lpm_fd)
|
||||||
|
log.debug('pm.wakelock_lock %s.' % ('Success' if wlk_res == 0 else 'Falied'))
|
||||||
|
|
||||||
over_speed_check_res = self.tracker.get_over_speed_check()
|
self.tracker.device_data_report(msg=data)
|
||||||
log.debug('over_speed_check_res: %s' % str(over_speed_check_res))
|
|
||||||
self.tracker.device_data_report(event_data=over_speed_check_res, msg=data)
|
|
||||||
self.tracker.remote.check_ota()
|
self.tracker.remote.check_ota()
|
||||||
|
@ -162,6 +162,9 @@ class QuecThing(object):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def cloud_close(self):
|
||||||
|
quecIot.setConnmode(0)
|
||||||
|
|
||||||
def get_post_res(self):
|
def get_post_res(self):
|
||||||
self.quec_timer.start(5000, 0, self.quec_timer_cb)
|
self.quec_timer.start(5000, 0, self.quec_timer_cb)
|
||||||
res = self.post_result_wait_queue.get()
|
res = self.post_result_wait_queue.get()
|
||||||
|
323
code/settings.py
323
code/settings.py
@ -16,75 +16,22 @@ import uos
|
|||||||
import ure
|
import ure
|
||||||
import ql_fs
|
import ql_fs
|
||||||
import ujson
|
import ujson
|
||||||
import modem
|
|
||||||
import _thread
|
import _thread
|
||||||
from machine import UART
|
|
||||||
from usr.common import Singleton
|
from usr.common import Singleton
|
||||||
|
from usr.settings_app import default_values_app
|
||||||
|
from usr.settings_sys import default_values_sys
|
||||||
|
|
||||||
PROJECT_NAME = 'QuecPython-Tracker'
|
# For Other Module Import
|
||||||
|
from usr.settings_sys import SYSNAME
|
||||||
PROJECT_VERSION = '2.0.1'
|
from usr.settings_sys import PROJECT_NAME
|
||||||
|
from usr.settings_sys import PROJECT_VERSION
|
||||||
SYSNAME = uos.uname()[0].split('=')[1]
|
from usr.settings_sys import DEVICE_FIRMWARE_VERSION
|
||||||
|
from usr.settings_sys import DATA_NON_LOCA
|
||||||
DEVICE_FIRMWARE_VERSION = modem.getDevFwVersion()
|
from usr.settings_sys import DATA_LOCA_NON_GPS
|
||||||
|
from usr.settings_sys import DATA_LOCA_GPS
|
||||||
DATA_NON_LOCA = 0x0
|
from usr.settings_sys import ALERTCODE
|
||||||
DATA_LOCA_NON_GPS = 0x1
|
from usr.settings_sys import LOWENERGYMAP
|
||||||
DATA_LOCA_GPS = 0x2
|
|
||||||
|
|
||||||
ALERTCODE = {
|
|
||||||
20000: 'fault_alert',
|
|
||||||
30002: 'low_power_alert',
|
|
||||||
30003: 'over_speed_alert',
|
|
||||||
30004: 'sim_abnormal_alert',
|
|
||||||
30005: 'disassemble_alert',
|
|
||||||
40000: 'drive_behavior_alert',
|
|
||||||
50001: 'sos_alert',
|
|
||||||
}
|
|
||||||
|
|
||||||
DEVICE_MODULE_STATUS = {
|
|
||||||
'net': 1,
|
|
||||||
'location': 2,
|
|
||||||
'temp_sensor': 3,
|
|
||||||
'light_sensor': 4,
|
|
||||||
'move_sensor': 5,
|
|
||||||
'mike': 6,
|
|
||||||
}
|
|
||||||
|
|
||||||
OTA_STATUS = {
|
|
||||||
'sys_current_version': 1,
|
|
||||||
'sys_target_version': 2,
|
|
||||||
'app_current_version': 3,
|
|
||||||
'app_target_version': 4,
|
|
||||||
'upgrade_module': 5,
|
|
||||||
'upgrade_status': 6,
|
|
||||||
}
|
|
||||||
|
|
||||||
DRIVE_BEHAVIOR_CODE = {
|
|
||||||
0: 'none',
|
|
||||||
1: 'quick_start',
|
|
||||||
2: 'quick_stop',
|
|
||||||
3: 'quick_turn_left',
|
|
||||||
4: 'quick_turn_right',
|
|
||||||
}
|
|
||||||
|
|
||||||
LOWENERGYMAP = {
|
|
||||||
"EC200U": [
|
|
||||||
"POWERDOWN",
|
|
||||||
"PM",
|
|
||||||
],
|
|
||||||
"EC200U": [
|
|
||||||
"POWERDOWN",
|
|
||||||
"PM",
|
|
||||||
],
|
|
||||||
"EC600N": [
|
|
||||||
"PM",
|
|
||||||
],
|
|
||||||
"EC800G": [
|
|
||||||
"PM"
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
tracker_settings_file = '/usr/tracker_settings.json'
|
tracker_settings_file = '/usr/tracker_settings.json'
|
||||||
|
|
||||||
@ -108,250 +55,6 @@ class SettingsError(Exception):
|
|||||||
return repr(self.value)
|
return repr(self.value)
|
||||||
|
|
||||||
|
|
||||||
class default_values_app(object):
|
|
||||||
'''
|
|
||||||
App default settings
|
|
||||||
'''
|
|
||||||
|
|
||||||
class _loc_method(object):
|
|
||||||
none = 0x0
|
|
||||||
gps = 0x1
|
|
||||||
cell = 0x2
|
|
||||||
wifi = 0x4
|
|
||||||
all = 0x7
|
|
||||||
|
|
||||||
class _work_mode(object):
|
|
||||||
cycle = 0x1
|
|
||||||
intelligent = 0x2
|
|
||||||
|
|
||||||
class _drive_behavior(object):
|
|
||||||
suddenly_start = 0
|
|
||||||
suddenly_stop = 1
|
|
||||||
suddenly_turn_left = 2
|
|
||||||
suddenly_turn_right = 3
|
|
||||||
|
|
||||||
'''
|
|
||||||
variables of App default settings below MUST NOT start with '_'
|
|
||||||
'''
|
|
||||||
|
|
||||||
phone_num = ''
|
|
||||||
|
|
||||||
loc_method = _loc_method.all
|
|
||||||
|
|
||||||
work_mode = _work_mode.cycle
|
|
||||||
|
|
||||||
work_cycle_period = 30
|
|
||||||
|
|
||||||
low_power_alert_threshold = 20
|
|
||||||
|
|
||||||
low_power_shutdown_threshold = 5
|
|
||||||
|
|
||||||
over_speed_threshold = 50
|
|
||||||
|
|
||||||
sw_ota = True
|
|
||||||
|
|
||||||
sw_ota_auto_upgrade = True
|
|
||||||
|
|
||||||
sw_voice_listen = False
|
|
||||||
|
|
||||||
sw_voice_record = False
|
|
||||||
|
|
||||||
sw_fault_alert = True
|
|
||||||
|
|
||||||
sw_low_power_alert = True
|
|
||||||
|
|
||||||
sw_over_speed_alert = True
|
|
||||||
|
|
||||||
sw_sim_abnormal_alert = True
|
|
||||||
|
|
||||||
sw_disassemble_alert = True
|
|
||||||
|
|
||||||
sw_drive_behavior_alert = True
|
|
||||||
|
|
||||||
|
|
||||||
class default_values_sys(object):
|
|
||||||
'''
|
|
||||||
System default settings
|
|
||||||
'''
|
|
||||||
|
|
||||||
class _cloud(object):
|
|
||||||
none = 0x0
|
|
||||||
quecIot = 0x1
|
|
||||||
AliYun = 0x2
|
|
||||||
JTT808 = 0x4
|
|
||||||
customization = 0x8
|
|
||||||
|
|
||||||
class _gps_mode(object):
|
|
||||||
none = 0x0
|
|
||||||
internal = 0x1
|
|
||||||
external = 0x2
|
|
||||||
|
|
||||||
class _ota_upgrade_status(object):
|
|
||||||
none = 0
|
|
||||||
to_be_updated = 1
|
|
||||||
updating = 2
|
|
||||||
update_successed = 3
|
|
||||||
update_failed = 4
|
|
||||||
|
|
||||||
class _ota_upgrade_module(object):
|
|
||||||
none = 0
|
|
||||||
sys = 1
|
|
||||||
app = 2
|
|
||||||
|
|
||||||
class _ali_burning_method(object):
|
|
||||||
one_type_one_density = 0
|
|
||||||
one_machine_one_density = 1
|
|
||||||
|
|
||||||
'''
|
|
||||||
variables of system default settings below MUST NOT start with '_'
|
|
||||||
'''
|
|
||||||
sw_log = True
|
|
||||||
|
|
||||||
checknet_timeout = 60
|
|
||||||
|
|
||||||
profile_idx = 1
|
|
||||||
|
|
||||||
gps_mode = _gps_mode.external
|
|
||||||
|
|
||||||
ota_status = {}
|
|
||||||
|
|
||||||
drive_behavior_code = 0
|
|
||||||
|
|
||||||
cloud = _cloud.quecIot
|
|
||||||
|
|
||||||
cloud_life_time = 120
|
|
||||||
|
|
||||||
cloud_init_params = {}
|
|
||||||
|
|
||||||
work_mode_timeline = 3600
|
|
||||||
|
|
||||||
ali_burning_method = _ali_burning_method.one_machine_one_density
|
|
||||||
|
|
||||||
# trackdev0304 (PROENV)
|
|
||||||
_quecIot = {
|
|
||||||
'PK': 'p11275',
|
|
||||||
'PS': 'Q0ZQQndaN3pCUFd6',
|
|
||||||
'DK': 'trackdev0304',
|
|
||||||
'DS': '8eba9389af434974c3c846d1922d949f',
|
|
||||||
'SERVER': 'iot-south.quectel.com:2883',
|
|
||||||
}
|
|
||||||
|
|
||||||
# # trackerdemo0326 (PROENV)
|
|
||||||
# _quecIot = {
|
|
||||||
# 'PK': 'p11275',
|
|
||||||
# 'PS': 'Q0ZQQndaN3pCUFd6',
|
|
||||||
# 'DK': 'trackerdemo0326',
|
|
||||||
# 'DS': '32d540996e32f95c58dd98f18d473d52',
|
|
||||||
# 'SERVER': 'iot-south.quectel.com:2883',
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # IMEI (PROENV)
|
|
||||||
# _quecIot = {
|
|
||||||
# 'PK': 'p11275',
|
|
||||||
# 'PS': 'Q0ZQQndaN3pCUFd6',
|
|
||||||
# 'DK': '',
|
|
||||||
# 'DS': '',
|
|
||||||
# 'SERVER': 'iot-south.quectel.com:2883',
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # TrackerDevEC600NCNLC (TESTENV)
|
|
||||||
# _quecIot = {
|
|
||||||
# 'PK': 'p119v2',
|
|
||||||
# 'PS': 'TXRPdVVhdkY3bU5s',
|
|
||||||
# 'DK': 'TrackerDevEC600NCNLC',
|
|
||||||
# 'DS': '',
|
|
||||||
# 'SERVER': 'mqtt://220.180.239.212:8382',
|
|
||||||
# }
|
|
||||||
|
|
||||||
# # IMEI (TESTENV)
|
|
||||||
# _quecIot = {
|
|
||||||
# 'PK': 'p119v2',
|
|
||||||
# 'PS': 'TXRPdVVhdkY3bU5s',
|
|
||||||
# 'DK': '',
|
|
||||||
# 'DS': '',
|
|
||||||
# 'SERVER': 'mqtt://220.180.239.212:8382',
|
|
||||||
# }
|
|
||||||
|
|
||||||
# tracker_dev_jack
|
|
||||||
_AliYun = {
|
|
||||||
'PK': 'a1q1kmZPwU2',
|
|
||||||
'PS': 'HQraBqtV8WsfCEuy',
|
|
||||||
'DK': 'tracker_dev_jack',
|
|
||||||
'DS': 'bfdfcca5075715e8309eff8597663c4b',
|
|
||||||
"SERVER": '',
|
|
||||||
}
|
|
||||||
|
|
||||||
_JTT808 = {
|
|
||||||
'PK': '',
|
|
||||||
'PS': '',
|
|
||||||
'DK': '',
|
|
||||||
'DS': '',
|
|
||||||
"SERVER": '',
|
|
||||||
}
|
|
||||||
|
|
||||||
locator_init_params = {}
|
|
||||||
|
|
||||||
_gps_cfg = {
|
|
||||||
'UARTn': UART.UART1,
|
|
||||||
'buadrate': 115200,
|
|
||||||
'databits': 8,
|
|
||||||
'parity': 0,
|
|
||||||
'stopbits': 1,
|
|
||||||
'flowctl': 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
_cellLocator_cfg = {
|
|
||||||
'serverAddr': 'www.queclocator.com',
|
|
||||||
'port': 80,
|
|
||||||
'token': 'xGP77d2z0i91s67n',
|
|
||||||
'timeout': 3,
|
|
||||||
'profileIdx': profile_idx,
|
|
||||||
}
|
|
||||||
|
|
||||||
_wifiLocator_cfg = {
|
|
||||||
'token': 'xGP77d2z0i91s67n'
|
|
||||||
}
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _get_locator_init_params(loc_method):
|
|
||||||
locator_init_params = {}
|
|
||||||
|
|
||||||
if loc_method & default_values_app._loc_method.gps:
|
|
||||||
locator_init_params['gps_cfg'] = default_values_sys._gps_cfg
|
|
||||||
if loc_method & default_values_app._loc_method.cell:
|
|
||||||
locator_init_params['cellLocator_cfg'] = default_values_sys._cellLocator_cfg
|
|
||||||
if loc_method & default_values_app._loc_method.wifi:
|
|
||||||
locator_init_params['wifiLocator_cfg'] = default_values_sys._wifiLocator_cfg
|
|
||||||
|
|
||||||
return locator_init_params
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _get_cloud_init_params(cloud):
|
|
||||||
cloud_init_params = {}
|
|
||||||
|
|
||||||
if cloud & default_values_sys._cloud.quecIot:
|
|
||||||
cloud_init_params = default_values_sys._quecIot
|
|
||||||
if cloud & default_values_sys._cloud.AliYun:
|
|
||||||
cloud_init_params = default_values_sys._AliYun
|
|
||||||
if cloud & default_values_sys._cloud.JTT808:
|
|
||||||
cloud_init_params = default_values_sys._JTT808
|
|
||||||
|
|
||||||
return cloud_init_params
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _ota_status_init_params():
|
|
||||||
ota_status = {
|
|
||||||
'sys_current_version': SYSNAME,
|
|
||||||
'sys_target_version': '--',
|
|
||||||
'app_current_version': PROJECT_VERSION,
|
|
||||||
'app_target_version': '--',
|
|
||||||
'upgrade_module': default_values_sys._ota_upgrade_module.none,
|
|
||||||
'upgrade_status': default_values_sys._ota_upgrade_status.none,
|
|
||||||
}
|
|
||||||
|
|
||||||
return ota_status
|
|
||||||
|
|
||||||
|
|
||||||
class Settings(Singleton):
|
class Settings(Singleton):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
74
code/settings_app.py
Normal file
74
code/settings_app.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
class default_values_app(object):
|
||||||
|
'''
|
||||||
|
App default settings
|
||||||
|
'''
|
||||||
|
|
||||||
|
class _loc_method(object):
|
||||||
|
none = 0x0
|
||||||
|
gps = 0x1
|
||||||
|
cell = 0x2
|
||||||
|
wifi = 0x4
|
||||||
|
all = 0x7
|
||||||
|
|
||||||
|
class _work_mode(object):
|
||||||
|
cycle = 0x1
|
||||||
|
intelligent = 0x2
|
||||||
|
|
||||||
|
class _drive_behavior(object):
|
||||||
|
suddenly_start = 0x0
|
||||||
|
suddenly_stop = 0x1
|
||||||
|
suddenly_turn_left = 0x2
|
||||||
|
suddenly_turn_right = 0x3
|
||||||
|
|
||||||
|
'''
|
||||||
|
variables of App default settings below MUST NOT start with '_'
|
||||||
|
'''
|
||||||
|
|
||||||
|
phone_num = ''
|
||||||
|
|
||||||
|
loc_method = _loc_method.all
|
||||||
|
|
||||||
|
work_mode = _work_mode.cycle
|
||||||
|
|
||||||
|
work_cycle_period = 30
|
||||||
|
|
||||||
|
low_power_alert_threshold = 20
|
||||||
|
|
||||||
|
low_power_shutdown_threshold = 5
|
||||||
|
|
||||||
|
over_speed_threshold = 50
|
||||||
|
|
||||||
|
sw_ota = True
|
||||||
|
|
||||||
|
sw_ota_auto_upgrade = True
|
||||||
|
|
||||||
|
sw_voice_listen = False
|
||||||
|
|
||||||
|
sw_voice_record = False
|
||||||
|
|
||||||
|
sw_fault_alert = True
|
||||||
|
|
||||||
|
sw_low_power_alert = True
|
||||||
|
|
||||||
|
sw_over_speed_alert = True
|
||||||
|
|
||||||
|
sw_sim_abnormal_alert = True
|
||||||
|
|
||||||
|
sw_disassemble_alert = True
|
||||||
|
|
||||||
|
sw_drive_behavior_alert = True
|
249
code/settings_sys.py
Normal file
249
code/settings_sys.py
Normal file
@ -0,0 +1,249 @@
|
|||||||
|
# Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
import uos
|
||||||
|
import modem
|
||||||
|
|
||||||
|
from machine import UART
|
||||||
|
|
||||||
|
from usr.settings_app import default_values_app
|
||||||
|
|
||||||
|
PROJECT_NAME = 'QuecPython-Tracker'
|
||||||
|
|
||||||
|
PROJECT_VERSION = '2.0.1'
|
||||||
|
|
||||||
|
SYSNAME = uos.uname()[0].split('=')[1]
|
||||||
|
|
||||||
|
DEVICE_FIRMWARE_VERSION = modem.getDevFwVersion()
|
||||||
|
|
||||||
|
DATA_NON_LOCA = 0x0
|
||||||
|
DATA_LOCA_NON_GPS = 0x1
|
||||||
|
DATA_LOCA_GPS = 0x2
|
||||||
|
|
||||||
|
ALERTCODE = {
|
||||||
|
20000: 'fault_alert',
|
||||||
|
30002: 'low_power_alert',
|
||||||
|
30003: 'over_speed_alert',
|
||||||
|
30004: 'sim_abnormal_alert',
|
||||||
|
30005: 'disassemble_alert',
|
||||||
|
40000: 'drive_behavior_alert',
|
||||||
|
50001: 'sos_alert',
|
||||||
|
}
|
||||||
|
|
||||||
|
LOWENERGYMAP = {
|
||||||
|
"EC200U": [
|
||||||
|
"POWERDOWN",
|
||||||
|
"PM",
|
||||||
|
],
|
||||||
|
"EC200U": [
|
||||||
|
"POWERDOWN",
|
||||||
|
"PM",
|
||||||
|
],
|
||||||
|
"EC600N": [
|
||||||
|
"PM",
|
||||||
|
],
|
||||||
|
"EC800G": [
|
||||||
|
"PM"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class default_values_sys(object):
|
||||||
|
'''
|
||||||
|
System default settings
|
||||||
|
'''
|
||||||
|
|
||||||
|
class _cloud(object):
|
||||||
|
none = 0x0
|
||||||
|
quecIot = 0x1
|
||||||
|
AliYun = 0x2
|
||||||
|
JTT808 = 0x4
|
||||||
|
customization = 0x8
|
||||||
|
|
||||||
|
class _gps_mode(object):
|
||||||
|
none = 0x0
|
||||||
|
internal = 0x1
|
||||||
|
external = 0x2
|
||||||
|
|
||||||
|
class _drive_behavior_code(object):
|
||||||
|
none = 0x0
|
||||||
|
quick_start = 0x1
|
||||||
|
quick_stop = 0x2
|
||||||
|
quick_turn_left = 0x3
|
||||||
|
quick_turn_right = 0x4
|
||||||
|
|
||||||
|
class _ota_upgrade_status(object):
|
||||||
|
none = 0x0
|
||||||
|
to_be_updated = 0x1
|
||||||
|
updating = 0x2
|
||||||
|
update_successed = 0x3
|
||||||
|
update_failed = 0x4
|
||||||
|
|
||||||
|
class _ota_upgrade_module(object):
|
||||||
|
none = 0x0
|
||||||
|
sys = 0x1
|
||||||
|
app = 0x2
|
||||||
|
|
||||||
|
class _ali_burning_method(object):
|
||||||
|
one_type_one_density = 0x0
|
||||||
|
one_machine_one_density = 0x1
|
||||||
|
|
||||||
|
'''
|
||||||
|
variables of system default settings below MUST NOT start with '_'
|
||||||
|
'''
|
||||||
|
sw_log = True
|
||||||
|
|
||||||
|
checknet_timeout = 60
|
||||||
|
|
||||||
|
profile_idx = 1
|
||||||
|
|
||||||
|
gps_mode = _gps_mode.external
|
||||||
|
|
||||||
|
ota_status = {}
|
||||||
|
|
||||||
|
drive_behavior_code = _drive_behavior_code.none
|
||||||
|
|
||||||
|
cloud = _cloud.quecIot
|
||||||
|
|
||||||
|
cloud_life_time = 120
|
||||||
|
|
||||||
|
cloud_init_params = {}
|
||||||
|
|
||||||
|
work_mode_timeline = 3600
|
||||||
|
|
||||||
|
ali_burning_method = _ali_burning_method.one_machine_one_density
|
||||||
|
|
||||||
|
# trackdev0304 (PROENV)
|
||||||
|
_quecIot = {
|
||||||
|
'PK': 'p11275',
|
||||||
|
'PS': 'Q0ZQQndaN3pCUFd6',
|
||||||
|
'DK': 'trackdev0304',
|
||||||
|
'DS': '8eba9389af434974c3c846d1922d949f',
|
||||||
|
'SERVER': 'iot-south.quectel.com:2883',
|
||||||
|
}
|
||||||
|
|
||||||
|
# # trackerdemo0326 (PROENV)
|
||||||
|
# _quecIot = {
|
||||||
|
# 'PK': 'p11275',
|
||||||
|
# 'PS': 'Q0ZQQndaN3pCUFd6',
|
||||||
|
# 'DK': 'trackerdemo0326',
|
||||||
|
# 'DS': '32d540996e32f95c58dd98f18d473d52',
|
||||||
|
# 'SERVER': 'iot-south.quectel.com:2883',
|
||||||
|
# }
|
||||||
|
|
||||||
|
# # IMEI (PROENV)
|
||||||
|
# _quecIot = {
|
||||||
|
# 'PK': 'p11275',
|
||||||
|
# 'PS': 'Q0ZQQndaN3pCUFd6',
|
||||||
|
# 'DK': '',
|
||||||
|
# 'DS': '',
|
||||||
|
# 'SERVER': 'iot-south.quectel.com:2883',
|
||||||
|
# }
|
||||||
|
|
||||||
|
# # TrackerDevEC600NCNLC (TESTENV)
|
||||||
|
# _quecIot = {
|
||||||
|
# 'PK': 'p119v2',
|
||||||
|
# 'PS': 'TXRPdVVhdkY3bU5s',
|
||||||
|
# 'DK': 'TrackerDevEC600NCNLC',
|
||||||
|
# 'DS': '',
|
||||||
|
# 'SERVER': 'mqtt://220.180.239.212:8382',
|
||||||
|
# }
|
||||||
|
|
||||||
|
# # IMEI (TESTENV)
|
||||||
|
# _quecIot = {
|
||||||
|
# 'PK': 'p119v2',
|
||||||
|
# 'PS': 'TXRPdVVhdkY3bU5s',
|
||||||
|
# 'DK': '',
|
||||||
|
# 'DS': '',
|
||||||
|
# 'SERVER': 'mqtt://220.180.239.212:8382',
|
||||||
|
# }
|
||||||
|
|
||||||
|
# tracker_dev_jack
|
||||||
|
_AliYun = {
|
||||||
|
'PK': 'a1q1kmZPwU2',
|
||||||
|
'PS': 'HQraBqtV8WsfCEuy',
|
||||||
|
'DK': 'tracker_dev_jack',
|
||||||
|
'DS': 'bfdfcca5075715e8309eff8597663c4b',
|
||||||
|
"SERVER": '',
|
||||||
|
}
|
||||||
|
|
||||||
|
_JTT808 = {
|
||||||
|
'PK': '',
|
||||||
|
'PS': '',
|
||||||
|
'DK': '',
|
||||||
|
'DS': '',
|
||||||
|
"SERVER": '',
|
||||||
|
}
|
||||||
|
|
||||||
|
locator_init_params = {}
|
||||||
|
|
||||||
|
_gps_cfg = {
|
||||||
|
'UARTn': UART.UART1,
|
||||||
|
'buadrate': 115200,
|
||||||
|
'databits': 8,
|
||||||
|
'parity': 0,
|
||||||
|
'stopbits': 1,
|
||||||
|
'flowctl': 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
_cellLocator_cfg = {
|
||||||
|
'serverAddr': 'www.queclocator.com',
|
||||||
|
'port': 80,
|
||||||
|
'token': 'xGP77d2z0i91s67n',
|
||||||
|
'timeout': 3,
|
||||||
|
'profileIdx': profile_idx,
|
||||||
|
}
|
||||||
|
|
||||||
|
_wifiLocator_cfg = {
|
||||||
|
'token': 'xGP77d2z0i91s67n'
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_locator_init_params(loc_method):
|
||||||
|
locator_init_params = {}
|
||||||
|
|
||||||
|
if loc_method & default_values_app._loc_method.gps:
|
||||||
|
locator_init_params['gps_cfg'] = default_values_sys._gps_cfg
|
||||||
|
if loc_method & default_values_app._loc_method.cell:
|
||||||
|
locator_init_params['cellLocator_cfg'] = default_values_sys._cellLocator_cfg
|
||||||
|
if loc_method & default_values_app._loc_method.wifi:
|
||||||
|
locator_init_params['wifiLocator_cfg'] = default_values_sys._wifiLocator_cfg
|
||||||
|
|
||||||
|
return locator_init_params
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_cloud_init_params(cloud):
|
||||||
|
cloud_init_params = {}
|
||||||
|
|
||||||
|
if cloud & default_values_sys._cloud.quecIot:
|
||||||
|
cloud_init_params = default_values_sys._quecIot
|
||||||
|
if cloud & default_values_sys._cloud.AliYun:
|
||||||
|
cloud_init_params = default_values_sys._AliYun
|
||||||
|
if cloud & default_values_sys._cloud.JTT808:
|
||||||
|
cloud_init_params = default_values_sys._JTT808
|
||||||
|
|
||||||
|
return cloud_init_params
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _ota_status_init_params():
|
||||||
|
ota_status = {
|
||||||
|
'sys_current_version': SYSNAME,
|
||||||
|
'sys_target_version': '--',
|
||||||
|
'app_current_version': PROJECT_VERSION,
|
||||||
|
'app_target_version': '--',
|
||||||
|
'upgrade_module': default_values_sys._ota_upgrade_module.none,
|
||||||
|
'upgrade_status': default_values_sys._ota_upgrade_status.none,
|
||||||
|
}
|
||||||
|
|
||||||
|
return ota_status
|
@ -91,32 +91,49 @@ class Tracker(Singleton):
|
|||||||
return alert_data
|
return alert_data
|
||||||
|
|
||||||
def get_device_data(self, power_switch=True):
|
def get_device_data(self, power_switch=True):
|
||||||
device_data = {}
|
device_data = {
|
||||||
|
'power_switch': power_switch,
|
||||||
|
'local_time': self.get_local_time(),
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get Cloud Location Data
|
||||||
loc_info = self.locator.read()
|
loc_info = self.locator.read()
|
||||||
if loc_info:
|
if loc_info:
|
||||||
log.debug('loc_method: %s' % loc_info[0])
|
loc_method_dict = {1: 'GPS', 2: 'CELL', 4: 'WIFI'}
|
||||||
|
log.debug('Location Data loc_method: %s' % loc_method_dict.get(loc_info[0], loc_info[0]))
|
||||||
device_data.update(loc_info[1])
|
device_data.update(loc_info[1])
|
||||||
|
|
||||||
|
# Get GPS Speed
|
||||||
|
over_speed_check_res = self.get_over_speed_check()
|
||||||
|
log.debug('over_speed_check_res: %s' % str(over_speed_check_res))
|
||||||
|
device_data.update(over_speed_check_res)
|
||||||
|
|
||||||
current_settings = settings.settings.get()
|
current_settings = settings.settings.get()
|
||||||
|
|
||||||
|
# Get Battery Energy
|
||||||
energy = self.battery.energy()
|
energy = self.battery.energy()
|
||||||
|
device_data.update({
|
||||||
|
'energy': energy,
|
||||||
|
'voltage': self.battery.voltage(),
|
||||||
|
})
|
||||||
if energy <= current_settings['app']['low_power_alert_threshold']:
|
if energy <= current_settings['app']['low_power_alert_threshold']:
|
||||||
alert_data = self.get_alert_data(30002, {'local_time': self.get_local_time()})
|
alert_data = self.get_alert_data(30002, {'local_time': self.get_local_time()})
|
||||||
device_data.update(alert_data)
|
device_data.update(alert_data)
|
||||||
|
|
||||||
# TODO: Other Machine Info.
|
# Get OTA Status & Drive Behiver Code
|
||||||
device_data.update({
|
device_data.update({
|
||||||
'power_switch': power_switch,
|
|
||||||
'energy': energy,
|
|
||||||
'voltage': self.battery.voltage(),
|
|
||||||
'local_time': self.get_local_time(),
|
|
||||||
'ota_status': current_settings['sys']['ota_status'],
|
'ota_status': current_settings['sys']['ota_status'],
|
||||||
'drive_behavior_code': current_settings['sys']['drive_behavior_code'],
|
'drive_behavior_code': current_settings['sys']['drive_behavior_code'],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Get APP Settings Info
|
||||||
device_data.update(current_settings['app'])
|
device_data.update(current_settings['app'])
|
||||||
|
|
||||||
|
# Format Loc Method
|
||||||
device_data.update({'loc_method': self.format_loc_method(current_settings['app']['loc_method'])})
|
device_data.update({'loc_method': self.format_loc_method(current_settings['app']['loc_method'])})
|
||||||
|
|
||||||
|
# TODO: Add Other Machine Info.
|
||||||
|
|
||||||
return device_data
|
return device_data
|
||||||
|
|
||||||
def format_loc_method(self, data):
|
def format_loc_method(self, data):
|
||||||
@ -191,12 +208,14 @@ class Tracker(Singleton):
|
|||||||
sys_bus.unsubscribe(topic)
|
sys_bus.unsubscribe(topic)
|
||||||
|
|
||||||
if topic.endswith('/wakelock_unlock'):
|
if topic.endswith('/wakelock_unlock'):
|
||||||
pm.wakelock_unlock(self.power_manage.lpm_fd)
|
wulk_res = pm.wakelock_unlock(self.power_manage.lpm_fd)
|
||||||
|
log.debug('pm.wakelock_unlock %s.' % ('Success' if wulk_res == 0 else 'Falied'))
|
||||||
elif topic.endswith('/power_down'):
|
elif topic.endswith('/power_down'):
|
||||||
self.energy_led.period = None
|
self.energy_led.period = None
|
||||||
self.energy_led.switch(0)
|
self.energy_led.switch(0)
|
||||||
self.running_led.period = None
|
self.running_led.period = None
|
||||||
self.running_led.switch(0)
|
self.running_led.switch(0)
|
||||||
|
self.remote.cloud.cloud_close()
|
||||||
Power.powerDown()
|
Power.powerDown()
|
||||||
elif topic.endswith('/power_restart'):
|
elif topic.endswith('/power_restart'):
|
||||||
Power.powerRestart()
|
Power.powerRestart()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user