1
+ # Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ @file :_main.py
17
+ @author :Jack Sun (jack.sun@quectel.com)
18
+ @brief :Project start.
19
+ @version :2.2.0
20
+ @date :2022-10-31 14:42:25
21
+ @copyright :Copyright (c) 2022
22
+ """
23
+
24
+ import _thread
25
+ try :
26
+ from modules .battery import Battery
27
+ from modules .history import History
28
+ from modules .logging import getLogger
29
+ from modules .net_manage import NetManager
30
+ from modules .thingsboard import TBDeviceMQTTClient
31
+ from modules .power_manage import PowerManage
32
+ from modules .aliIot import AliIot , AliIotOTA
33
+ from modules .location import GNSS , CellLocator , WiFiLocator , CoordinateSystemConvert
34
+ from settings_user import UserConfig
35
+ from tracker_tb import Tracker as TBTracker
36
+ from tracker_ali import Tracker as AliTracker
37
+ from settings import Settings , PROJECT_NAME , PROJECT_VERSION , FIRMWARE_NAME , FIRMWARE_VERSION
38
+ except ImportError :
39
+ from usr .modules .battery import Battery
40
+ from usr .modules .history import History
41
+ from usr .modules .logging import getLogger
42
+ from usr .modules .net_manage import NetManager
43
+ from usr .modules .thingsboard import TBDeviceMQTTClient
44
+ from usr .modules .power_manage import PowerManage
45
+ from usr .modules .aliIot import AliIot , AliIotOTA
46
+ from usr .modules .location import GNSS , CellLocator , WiFiLocator , CoordinateSystemConvert
47
+ from usr .settings_user import UserConfig
48
+ from usr .tracker_tb import Tracker as TBTracker
49
+ from usr .tracker_ali import Tracker as AliTracker
50
+ from usr .settings import Settings , PROJECT_NAME , PROJECT_VERSION , FIRMWARE_NAME , FIRMWARE_VERSION
51
+
52
+ log = getLogger (__name__ )
53
+
54
+ def main ():
55
+ log .debug ("[x] Main start." )
56
+ log .info ("PROJECT_NAME: %s, PROJECT_VERSION: %s" % (PROJECT_NAME , PROJECT_VERSION ))
57
+ log .info ("DEVICE_FIRMWARE_NAME: %s, DEVICE_FIRMWARE_VERSION: %s" % (FIRMWARE_NAME , FIRMWARE_VERSION ))
58
+
59
+ # Init settings.
60
+ settings = Settings ()
61
+ # Init battery.
62
+ battery = Battery ()
63
+ # Init history
64
+ history = History ()
65
+ # Init power manage and set device low energy.
66
+ power_manage = PowerManage ()
67
+ power_manage .autosleep (1 )
68
+ # Init net modules and start net connect.
69
+ net_manager = NetManager ()
70
+ _thread .stack_size (0x1000 )
71
+ _thread .start_new_thread (net_manager .net_connect , ())
72
+ # Init GNSS modules and start reading and parsing gnss data.
73
+ loc_cfg = settings .read ("loc" )
74
+ gnss = GNSS (** loc_cfg ["gps_cfg" ])
75
+ gnss .set_trans (0 )
76
+ gnss .start ()
77
+ # Init cell and wifi location modules.
78
+ cell = CellLocator (** loc_cfg ["cell_cfg" ])
79
+ wifi = WiFiLocator (** loc_cfg ["wifi_cfg" ])
80
+ cyc = CoordinateSystemConvert ()
81
+ # Init tracker business modules.
82
+ user_cfg = settings .read ("user" )
83
+ server_cfg = settings .read ("server" )
84
+ # Init coordinate system convert modules.
85
+ if user_cfg ["server" ] == UserConfig ._server .AliIot :
86
+ server = AliIot (** server_cfg )
87
+ server_ota = AliIotOTA (PROJECT_NAME , FIRMWARE_NAME )
88
+ server_ota .set_server (server )
89
+ tracker = AliTracker ()
90
+ elif user_cfg ["server" ] == UserConfig ._server .ThingsBoard :
91
+ # Init server modules.
92
+ server = TBDeviceMQTTClient (** server_cfg )
93
+ tracker = TBTracker ()
94
+ else :
95
+ raise ValueError ("User config server is not compared." )
96
+ tracker .add_module (settings )
97
+ tracker .add_module (battery )
98
+ tracker .add_module (history )
99
+ tracker .add_module (net_manager )
100
+ tracker .add_module (server )
101
+ tracker .add_module (server_ota )
102
+ tracker .add_module (gnss )
103
+ tracker .add_module (cell )
104
+ tracker .add_module (wifi )
105
+ tracker .add_module (cyc )
106
+ server .add_event ("over_speed_alert" )
107
+ server .add_event ("sim_abnormal_alert" )
108
+ server .add_event ("low_power_alert" )
109
+ server .add_event ("fault_alert" )
110
+ # Set net modules callback.
111
+ net_manager .set_callback (tracker .net_callback )
112
+ # Set server modules callback.
113
+ server .set_callback (tracker .server_callback )
114
+ # Start tracker business.
115
+ tracker .running ()
116
+
117
+ log .debug ("[x] Main over." )
118
+
119
+ if __name__ == "__main__" :
120
+ main ()
0 commit comments