From 265760b9a94ede35348ca7010a664525c551099b Mon Sep 17 00:00:00 2001 From: JhosuaSparrow Date: Wed, 4 Dec 2024 16:15:23 +0800 Subject: [PATCH 1/3] add: PSM EG95M3 example. --- system/power-consumption/psm_EG95M3.py | 81 ++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 system/power-consumption/psm_EG95M3.py diff --git a/system/power-consumption/psm_EG95M3.py b/system/power-consumption/psm_EG95M3.py new file mode 100644 index 0000000..2a938ad --- /dev/null +++ b/system/power-consumption/psm_EG95M3.py @@ -0,0 +1,81 @@ +# 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 pm +import net +import utime +import osTimer +import checkNet +from misc import Power + + +def Business_code_example(run_time): + i = 0 + for i in range(run_time): + print("Business app running") + # usiness code here + utime.sleep(1) + + +def device_power_restart(args): + print("device_power_restart") + Power.powerRestart() + + +def psm_try_set(): + if pm.get_psm_time()[0] == 1: # 开机时获取psm是否设置,如果已经使能,则无需再次进行设置 + print("PSM has been enable, set pass") + return 0 + else: + return pm.set_psm_time(0, 1, 0, 15) # T3412=10min T3324=30s + + +def psm_failed_handle(delay_time, autosleep_timer): + autosleep_timer.start(600 * 1000, 0, device_power_restart) # 启动osTimer重启设备, 当psm生效后,该osTimer自动失效 + print("autosleep_timer start") + utime.sleep(delay_time) # 等待指定时长后,触发PSM失败的处理逻辑,即使用autosleep并等待osTimer重启设备 + + print("Device not into psm mode. Try to set autosleep.") + pm.autosleep(1) + print("Wait device into autosleep and wait device reset.") + + +if __name__ == '__main__': + pm.autosleep(0) + if pm.get_psm_time()[0] == 1: + if pm.set_psm_time(0) is True: + print("Disable psm successful.") + else: + print("Disable psm failed.") + + if net.getModemFun() != 1: + net.setModemFun(1) + print("Set CFUN1") + + psm_failed_delay_time = 60 + 30 # PSM的 T3324超时30S后,启用错误处理逻辑 + stage, state = checkNet.waitNetworkReady(30) + if stage == 3 and state == 1: + print('Network connection successful.') + else: + print('Network connection failed.') + psm_failed_delay_time = 1 # PSM依赖网络,无网络时应立即使用RTC代替之 + + Business_code_example(10) # 业务代码运行 + + if stage == 3 and state == 1: + res = psm_try_set() # 网络连接成功时尝试设置PSM,如果PSM设置已经生效,则不用再次设置 + print("psm_try_set res", res) + autosleep_timer = osTimer() + print("autosleep_timer init.") + psm_failed_handle(psm_failed_delay_time, autosleep_timer) # 运行错误处理,若模组能正常进入PSM,在sleep中就进入PSM了,该处实际的处理逻辑并不会运行 From 499c2d724a9a6dc5711f8d6e2ff9c82b59713061 Mon Sep 17 00:00:00 2001 From: JhosuaSparrow Date: Wed, 4 Dec 2024 19:08:15 +0800 Subject: [PATCH 2/3] update: rename psm example file name. --- system/power-consumption/{psm_EG95M3.py => psm_BG95M3.py} | 3 +++ 1 file changed, 3 insertions(+) rename system/power-consumption/{psm_EG95M3.py => psm_BG95M3.py} (91%) diff --git a/system/power-consumption/psm_EG95M3.py b/system/power-consumption/psm_BG95M3.py similarity index 91% rename from system/power-consumption/psm_EG95M3.py rename to system/power-consumption/psm_BG95M3.py index 2a938ad..06be716 100644 --- a/system/power-consumption/psm_EG95M3.py +++ b/system/power-consumption/psm_BG95M3.py @@ -52,6 +52,9 @@ def psm_failed_handle(delay_time, autosleep_timer): if __name__ == '__main__': + """ + 测试该脚本功能可将文件重命名为 main.py 烧录进模块中进行测试,模块 PSM 休眠唤醒后即可自动执行脚本中的功能。 + """ pm.autosleep(0) if pm.get_psm_time()[0] == 1: if pm.set_psm_time(0) is True: From 1f6ed291c41703eaf16061f994ce610bf319a323 Mon Sep 17 00:00:00 2001 From: JhosuaSparrow Date: Wed, 4 Dec 2024 19:16:51 +0800 Subject: [PATCH 3/3] update: psm BG95M3 example code note. --- system/power-consumption/psm_BG95M3.py | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/system/power-consumption/psm_BG95M3.py b/system/power-consumption/psm_BG95M3.py index 06be716..9cb2eb0 100644 --- a/system/power-consumption/psm_BG95M3.py +++ b/system/power-consumption/psm_BG95M3.py @@ -24,7 +24,7 @@ def Business_code_example(run_time): i = 0 for i in range(run_time): print("Business app running") - # usiness code here + # Business code here utime.sleep(1) @@ -34,7 +34,9 @@ def device_power_restart(args): def psm_try_set(): - if pm.get_psm_time()[0] == 1: # 开机时获取psm是否设置,如果已经使能,则无需再次进行设置 + # 开机时获取 psm 是否设置,如果已经使能,则无需再次进行设置 + # Get whether psm is set when booting. If it is already enabled, there is no need to set it again. + if pm.get_psm_time()[0] == 1: print("PSM has been enable, set pass") return 0 else: @@ -42,9 +44,13 @@ def psm_try_set(): def psm_failed_handle(delay_time, autosleep_timer): - autosleep_timer.start(600 * 1000, 0, device_power_restart) # 启动osTimer重启设备, 当psm生效后,该osTimer自动失效 + # 启动 osTimer 重启设备, 当 psm 生效后,该 osTimer 自动失效 + # Start osTimer and restart the device. When psm takes effect, the osTimer will automatically expire. + autosleep_timer.start(600 * 1000, 0, device_power_restart) print("autosleep_timer start") - utime.sleep(delay_time) # 等待指定时长后,触发PSM失败的处理逻辑,即使用autosleep并等待osTimer重启设备 + # 等待指定时长后,触发 psm 失败的处理逻辑,即使用 autosleep 并等待 osTimer 重启设备 + # After waiting for the specified time, trigger the processing logic of psm failure, that is, use autosleep and wait for osTimer to restart the device. + utime.sleep(delay_time) print("Device not into psm mode. Try to set autosleep.") pm.autosleep(1) @@ -54,6 +60,8 @@ def psm_failed_handle(delay_time, autosleep_timer): if __name__ == '__main__': """ 测试该脚本功能可将文件重命名为 main.py 烧录进模块中进行测试,模块 PSM 休眠唤醒后即可自动执行脚本中的功能。 + To test the script function, you can rename the file to main.py and burn it into the module for testing. + After the module PSM wakes up from sleep, it can automatically execute the functions in the script. """ pm.autosleep(0) if pm.get_psm_time()[0] == 1: @@ -66,19 +74,31 @@ def psm_failed_handle(delay_time, autosleep_timer): net.setModemFun(1) print("Set CFUN1") - psm_failed_delay_time = 60 + 30 # PSM的 T3324超时30S后,启用错误处理逻辑 + # PSM 的 T3324 超时 30s 后,启用错误处理逻辑 + # After PSM's T3324 times out 30s, error handling logic is enabled + psm_failed_delay_time = 60 + 30 stage, state = checkNet.waitNetworkReady(30) if stage == 3 and state == 1: print('Network connection successful.') else: print('Network connection failed.') - psm_failed_delay_time = 1 # PSM依赖网络,无网络时应立即使用RTC代替之 + # PSM 依赖网络,无网络时应立即使用 autosleep 代替之 + # PSM relies on the network. If there is no network, you should use autosleep immediately instead. + psm_failed_delay_time = 1 - Business_code_example(10) # 业务代码运行 + # 业务代码运行 + # Business code running + Business_code_example(10) if stage == 3 and state == 1: - res = psm_try_set() # 网络连接成功时尝试设置PSM,如果PSM设置已经生效,则不用再次设置 + # 网络连接成功时尝试设置PSM,如果PSM设置已经生效,则不用再次设置 + # Try to set up PSM when the network connection is successful. + # If the PSM setting has already taken effect, there is no need to set it up again. + res = psm_try_set() print("psm_try_set res", res) autosleep_timer = osTimer() print("autosleep_timer init.") - psm_failed_handle(psm_failed_delay_time, autosleep_timer) # 运行错误处理,若模组能正常进入PSM,在sleep中就进入PSM了,该处实际的处理逻辑并不会运行 + # 运行错误处理,若模组能正常进入PSM,在sleep中就进入PSM了,该处实际的处理逻辑并不会运行 + # Run error processing. If the module can enter PSM normally, it will enter PSM in sleep, + # and the actual processing logic there will not run. + psm_failed_handle(psm_failed_delay_time, autosleep_timer)