2022-03-24 16:01:12 +08:00
|
|
|
# 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.
|
|
|
|
|
2022-04-20 18:47:47 +08:00
|
|
|
import net
|
|
|
|
import utime
|
|
|
|
import dataCall
|
|
|
|
|
2022-04-17 16:49:25 +08:00
|
|
|
from usr.tracker import tracker
|
2022-04-18 13:55:36 +08:00
|
|
|
from usr.settings import Settings
|
2022-04-20 18:47:47 +08:00
|
|
|
from usr.modules.logging import getLogger
|
|
|
|
from usr.tracker_devicecheck import DeviceCheck
|
|
|
|
|
|
|
|
log = getLogger(__name__)
|
2022-03-09 16:51:21 +08:00
|
|
|
|
2022-03-11 17:18:18 +08:00
|
|
|
|
2022-04-12 09:13:20 +08:00
|
|
|
def test_settings():
|
|
|
|
res = {"all": 0, "success": 0, "failed": 0}
|
|
|
|
settings = Settings()
|
|
|
|
|
|
|
|
assert settings.init() is True, "[test_settings] FAILED: Settings.init()."
|
|
|
|
print("[test_settings] SUCCESS: Settings.init().")
|
|
|
|
res["success"] += 1
|
|
|
|
|
|
|
|
current_settings = settings.get()
|
|
|
|
assert current_settings and isinstance(current_settings, dict)
|
|
|
|
print("[test_settings] SUCCESS: Settings.get().")
|
|
|
|
res["success"] += 1
|
|
|
|
|
2022-04-14 15:20:22 +08:00
|
|
|
for key, val in current_settings.get("user_cfg", {}).items():
|
2022-04-12 09:13:20 +08:00
|
|
|
val = "18888888888" if key == "phone_num" else val
|
2022-04-14 15:20:22 +08:00
|
|
|
if key == "work_mode_timeline":
|
|
|
|
set_res = False
|
|
|
|
else:
|
|
|
|
set_res = True
|
|
|
|
assert settings.set(key, val) is set_res, "[test_settings] FAILED: APP Settings.set(%s, %s)." % (key, val)
|
2022-04-12 09:13:20 +08:00
|
|
|
print("[test_settings] SUCCESS: APP Settings.set(%s, %s)." % (key, val))
|
|
|
|
res["success"] += 1
|
2022-04-14 15:20:22 +08:00
|
|
|
|
|
|
|
cloud_params = current_settings["cloud"]
|
|
|
|
assert settings.set("cloud", cloud_params) is True, "[test_settings] FAILED: SYS Settings.set(%s, %s)." % ("cloud", str(cloud_params))
|
|
|
|
print("[test_settings] SUCCESS: SYS Settings.set(%s, %s)." % ("cloud", str(cloud_params)))
|
|
|
|
res["success"] += 1
|
2022-04-12 09:13:20 +08:00
|
|
|
|
|
|
|
assert settings.save() is True, "[test_settings] FAILED: Settings.save()."
|
|
|
|
print("[test_settings] SUCCESS: Settings.save().")
|
|
|
|
res["success"] += 1
|
|
|
|
|
|
|
|
assert settings.reset() is True, "[test_settings] FAILED: Settings.reset()."
|
|
|
|
print("[test_settings] SUCCESS: Settings.reset().")
|
|
|
|
res["success"] += 1
|
|
|
|
|
|
|
|
res["all"] = res["success"] + res["failed"]
|
|
|
|
print("[test_settings] ALL: %s SUCCESS: %s, FAILED: %s." % (res["all"], res["success"], res["failed"]))
|
|
|
|
|
|
|
|
|
2022-04-20 18:47:47 +08:00
|
|
|
def nw_callback(args):
|
|
|
|
log.debug("[nw_callback][args] %s" % str(args))
|
|
|
|
if args[1] != 1:
|
|
|
|
res = net.setModemFun(0)
|
|
|
|
log.debug("net.setModemFun(0): %s" % res)
|
|
|
|
DeviceCheck().net()
|
|
|
|
utime.sleep(3)
|
|
|
|
DeviceCheck().net()
|
|
|
|
res = net.setModemFun(1)
|
|
|
|
log.debug("net.setModemFun(1): %s" % res)
|
|
|
|
DeviceCheck().net()
|
|
|
|
utime.sleep(3)
|
|
|
|
DeviceCheck().net()
|
|
|
|
else:
|
|
|
|
DeviceCheck().net()
|
|
|
|
|
|
|
|
|
|
|
|
def test_net():
|
|
|
|
log.debug("[test_net] Start")
|
|
|
|
dataCall.setCallback(nw_callback)
|
|
|
|
res = net.setModemFun(0)
|
|
|
|
log.debug("net.setModemFun(0): %s" % res)
|
|
|
|
DeviceCheck().net()
|
|
|
|
utime.sleep(10)
|
|
|
|
log.debug("[test_net] End")
|
|
|
|
|
|
|
|
|
2022-04-12 09:13:20 +08:00
|
|
|
def test_tracker():
|
2022-04-14 15:20:22 +08:00
|
|
|
tracker()
|
2022-04-07 14:56:12 +08:00
|
|
|
|
|
|
|
|
2022-04-20 18:47:47 +08:00
|
|
|
def main(test_fun="test_net"):
|
|
|
|
test_funs = ["test_settings", "test_tracker", "test_net"]
|
|
|
|
if test_fun not in test_funs and callable(locals().get(test_fun)):
|
|
|
|
print("test_fun[%s] is not exists." % test_fun)
|
|
|
|
return
|
|
|
|
|
|
|
|
locals()[test_fun]()
|
2022-04-07 14:56:12 +08:00
|
|
|
|
|
|
|
|
2022-04-12 09:13:20 +08:00
|
|
|
if __name__ == "__main__":
|
2022-03-09 16:51:21 +08:00
|
|
|
main()
|