From c338e65c01a87d57c1a1e83b4610c016f9ecd2c8 Mon Sep 17 00:00:00 2001 From: fujr Date: Mon, 7 Apr 2025 19:26:40 +0800 Subject: [PATCH] Feature: Introduce a mechanism to add delays and execute commands post-init or pre-dial to address the issue raised in #32. --- .../luasrc/model/cbi/qmodem/modem_config.lua | 26 ++++++++++ .../luasrc/model/cbi/qmodem/settings.lua | 6 +-- luci/luci-app-qmodem/po/zh-cn/qmodem.po | 37 ++++++++++++++ luci/luci-app-qmodem/po/zh_Hans/qmodem.po | 37 ++++++++++++++ .../root/usr/share/qmodem/modem_dial.sh | 7 +++ .../root/usr/share/qmodem/modem_hook.sh | 51 +++++++++++++++++++ .../root/usr/share/qmodem/modem_scan.sh | 11 ++++ 7 files changed, 170 insertions(+), 5 deletions(-) create mode 100755 luci/luci-app-qmodem/root/usr/share/qmodem/modem_hook.sh diff --git a/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/modem_config.lua b/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/modem_config.lua index a2b123d..5a2f4b0 100644 --- a/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/modem_config.lua +++ b/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/modem_config.lua @@ -114,4 +114,30 @@ for _, band in ipairs(band_options) do end end +pre_dial_delay = s:option(Value, "pre_dial_delay", translate("Pre Dial Delay")..translate(" (beta)")) +pre_dial_delay.description = translate("Delay of executing AT command before dialing, in seconds."..translate("(still in beta))")) +pre_dial_delay.placeholder = translate("Enter delay in seconds") +pre_dial_delay.default = "0" +pre_dial_delay.datatype = "uinteger" +pre_dial_delay.rmempty = true + +pre_add_delay = s:option(Value, "post_init_delay", translate("Post Init Delay")..translate(" (beta)")) +pre_add_delay.description = translate("Delay of executing AT command after modem initialization, in seconds."..translate("(still in beta))")) +pre_add_delay.placeholder = translate("Enter delay in seconds") +pre_add_delay.default = "0" +pre_add_delay.datatype = "uinteger" +pre_add_delay.rmempty = true + +pre_add_at_cmds = s:option(DynamicList, "post_init_at_cmds", translate("Post Init AT Commands")..translate(" (beta)")) +pre_add_at_cmds.description = translate("AT commands to execute after modem initialization."..translate("(still in beta))")) +pre_add_at_cmds.placeholder = translate("Enter AT commands") +pre_add_at_cmds.datatype = "string" +pre_add_at_cmds.rmempty = true + +pre_dial_at_cmds = s:option(DynamicList, "pre_dial_at_cmds", translate("Pre Dial AT Commands")..translate(" (beta)")) +pre_dial_at_cmds.description = translate("AT commands to execute before dialing."..translate("(still in beta))")) +pre_dial_at_cmds.placeholder = translate("Enter AT commands") +pre_dial_at_cmds.datatype = "string" +pre_dial_at_cmds.rmempty = true + return m diff --git a/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/settings.lua b/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/settings.lua index 56212e4..c3e0eaa 100644 --- a/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/settings.lua +++ b/luci/luci-app-qmodem/luasrc/model/cbi/qmodem/settings.lua @@ -102,11 +102,7 @@ slot_type.cfgvalue = function(t, n) return name:upper() end -slot_path = s:option(DummyValue, "slot", translate("Slot Path")) -slot_path.cfgvalue = function(t, n) - local path = (Value.cfgvalue(t, n) or "-") - return path -end +path = s:option(DummyValue, "path", translate("Slot Path")) default_alias = s:option(DummyValue, "alias", translate("Alias")) default_alias.cfgvalue = function(t, n) diff --git a/luci/luci-app-qmodem/po/zh-cn/qmodem.po b/luci/luci-app-qmodem/po/zh-cn/qmodem.po index 1b6356a..1191856 100644 --- a/luci/luci-app-qmodem/po/zh-cn/qmodem.po +++ b/luci/luci-app-qmodem/po/zh-cn/qmodem.po @@ -771,3 +771,40 @@ msgstr "重启调制解调器" msgid "AT Debug" msgstr "AT调试" + +msgid "Post Init Delay" +msgstr "初始化延时" + +msgid "Delay of executing AT command after modem initialization, in seconds." +msgstr "模组初始化后执行AT命令的延迟时间,以秒为单位。" + +msgid "Enter delay in seconds" +msgstr "输入延时(秒)" + +msgid "Post Init AT Commands" +msgstr "初始化后AT命令" + +msgid "AT commands to execute after modem initialization." +msgstr "模组初始化后执行的AT命令。" + +msgid "Enter AT commands" +msgstr "输入AT命令" + +msgid "Pre Dial Delay" +msgstr "拨号前延时" + +msgid "Delay of executing AT command before dialing, in seconds." +msgstr "拨号前执行AT命令的延迟时间,以秒为单位。" + + +msgid "Pre Dial AT Commands" +msgstr "拨号前AT命令" + +msgid "AT commands to execute before dialing." +msgstr "拨号前执行的AT命令。" + +msgid "(still in beta)" +msgstr "(仍在测试中)" + +msgid “(beta)" +msgstr "(测试)" diff --git a/luci/luci-app-qmodem/po/zh_Hans/qmodem.po b/luci/luci-app-qmodem/po/zh_Hans/qmodem.po index 1b6356a..1191856 100644 --- a/luci/luci-app-qmodem/po/zh_Hans/qmodem.po +++ b/luci/luci-app-qmodem/po/zh_Hans/qmodem.po @@ -771,3 +771,40 @@ msgstr "重启调制解调器" msgid "AT Debug" msgstr "AT调试" + +msgid "Post Init Delay" +msgstr "初始化延时" + +msgid "Delay of executing AT command after modem initialization, in seconds." +msgstr "模组初始化后执行AT命令的延迟时间,以秒为单位。" + +msgid "Enter delay in seconds" +msgstr "输入延时(秒)" + +msgid "Post Init AT Commands" +msgstr "初始化后AT命令" + +msgid "AT commands to execute after modem initialization." +msgstr "模组初始化后执行的AT命令。" + +msgid "Enter AT commands" +msgstr "输入AT命令" + +msgid "Pre Dial Delay" +msgstr "拨号前延时" + +msgid "Delay of executing AT command before dialing, in seconds." +msgstr "拨号前执行AT命令的延迟时间,以秒为单位。" + + +msgid "Pre Dial AT Commands" +msgstr "拨号前AT命令" + +msgid "AT commands to execute before dialing." +msgstr "拨号前执行的AT命令。" + +msgid "(still in beta)" +msgstr "(仍在测试中)" + +msgid “(beta)" +msgstr "(测试)" diff --git a/luci/luci-app-qmodem/root/usr/share/qmodem/modem_dial.sh b/luci/luci-app-qmodem/root/usr/share/qmodem/modem_dial.sh index 76f96b9..6115bce 100755 --- a/luci/luci-app-qmodem/root/usr/share/qmodem/modem_dial.sh +++ b/luci/luci-app-qmodem/root/usr/share/qmodem/modem_dial.sh @@ -11,6 +11,12 @@ debug_subject="modem_dial" source "${SCRIPT_DIR}/generic.sh" touch $log_file +exec_pre_dial() +{ + section=$1 + /usr/share/qmodem/modem_hook.sh $section pre_dial +} + get_led() { config_foreach get_led_by_slot modem-slot @@ -575,6 +581,7 @@ dial(){ done set_if m_debug "dialing $modem_path driver $driver" + exec_pre_dial $modem_config case $driver in "qmi") qmi_dial diff --git a/luci/luci-app-qmodem/root/usr/share/qmodem/modem_hook.sh b/luci/luci-app-qmodem/root/usr/share/qmodem/modem_hook.sh new file mode 100755 index 0000000..4036094 --- /dev/null +++ b/luci/luci-app-qmodem/root/usr/share/qmodem/modem_hook.sh @@ -0,0 +1,51 @@ +#!/bin/sh +. /lib/functions.sh + +config_name="qmodem" +config_section=$1 +init_type=$2 + +case $init_type in + post_init) + # pre-add at commands + cfg_prefix="post_init" + debug_subject="post_init" + ;; + pre_dial) + # pre-dial at commands + cfg_prefix="pre_dial" + debug_subject="pre_dial" + ;; + *) + m_debug "init_type error" + exit 1 + ;; +esac + +_execute_ats(){ + command=$1 + res=$(at $at_port $command) + m_debug "execute_ats $config_section: $command $at_port" + m_debug "execute_ats_result $config_section: $res" +} + +. /usr/share/qmodem/modem_util.sh +config_load ${config_name} + +config_get ${cfg_prefix}_delay $config_section delay + +config_get at_port $config_section at_port + +if [ -f "$at_port" ] || [ -z "$at_port" ]; then + m_debug "$config_section:at_port is not set or not a file" + m_debug "at_port $config_section: $at_port" + exit 1 +fi + +if [ -n "$delay" ]; then + sleep $delay +fi + + + +config_list_foreach $config_section ${cfg_prefix}_at_cmds _execute_ats diff --git a/luci/luci-app-qmodem/root/usr/share/qmodem/modem_scan.sh b/luci/luci-app-qmodem/root/usr/share/qmodem/modem_scan.sh index 423e4d8..3d2e484 100755 --- a/luci/luci-app-qmodem/root/usr/share/qmodem/modem_scan.sh +++ b/luci/luci-app-qmodem/root/usr/share/qmodem/modem_scan.sh @@ -8,6 +8,14 @@ debug_subject="modem_scan" source /lib/functions.sh source /usr/share/qmodem/modem_util.sh + + +exec_post_init() +{ + section_name=$1 + /usr/share/qmodem/modem_hook.sh $section_name post_init +} + get_associate_usb() { target_slot=$1 @@ -315,6 +323,7 @@ add() if [ "$is_fixed_device" == "1" ];then m_debug "modem $modem_name slot $slot slot_type $slot_type is fixed device, skip" lock -u /tmp/lock/modem_add_$slot + exec_post_init $section_name return fi case $slot_type in @@ -407,6 +416,8 @@ EOF uci commit qmodem mkdir -p /var/run/qmodem/${section_name}_dir lock -u /tmp/lock/modem_add_$slot +#增加预初始化脚本 + exec_post_init $section_name #判断是否重启网络 [ -n "$is_exist" ] && [ "$orig_network" == "$net_devices" ] && [ "$orig_at_port" == "/dev/$at_port" ] && [ "$orig_state" == "enabled" ] && [ "$orig_name" == "$modem_name" ] && return /etc/init.d/qmodem_network restart