From 79248095114889895af000978fdf2034a1119635 Mon Sep 17 00:00:00 2001 From: ling <1042585959@qq.com> Date: Sat, 6 Jan 2024 00:46:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luci-app-modem/luasrc/controller/modem.lua | 37 ++++++------------- .../luasrc/view/modem/modem_status.htm | 2 +- .../root/usr/share/modem/fibocom.sh | 21 ++++++++++- .../root/usr/share/modem/modem_info.sh | 3 ++ .../root/usr/share/modem/quectel.sh | 18 +++++++++ 5 files changed, 53 insertions(+), 28 deletions(-) diff --git a/luci-app-modem/luasrc/controller/modem.lua b/luci-app-modem/luasrc/controller/modem.lua index 350d6e7..3659628 100644 --- a/luci-app-modem/luasrc/controller/modem.lua +++ b/luci-app-modem/luasrc/controller/modem.lua @@ -44,27 +44,18 @@ function at(at_port,at_command) end -- 获取模组连接状态 -function getModemConnectStatus(at_port) - local at_command="AT+CGDCONT?" - local response=at(at_port,at_command) +function getModemConnectStatus(at_port,manufacturer) - -- 第六个引号的索引 - local sixth_index=1 - for i = 1, 5 do - sixth_index=string.find(response,'"',sixth_index)+1 + local connect_status="unknown" + + if at_port and manufacturer then + local odpall = io.popen("cd /usr/share/modem && source $(dirname \"$0\")/"..manufacturer..".sh && get_connect_status "..at_port) + connect_status = odpall:read("*a") + connect_status=string.gsub(connect_status, "\n", "") + odpall:close() end - -- 第七个引号的索引 - local seven_index=string.find(response,'"',sixth_index+1) - -- 获取IPv4和IPv6 - local ip=string.sub(response,sixth_index,seven_index-1) - - local not_ip="0.0.0.0,0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" - if string.find(ip,not_ip) then - return "disconnect" - else - return "connect" - end + return connect_status end -- 获取模组基本信息 @@ -76,10 +67,7 @@ function getModemBaseInfo(at_port) --获取数据接口 local data_interface=modem_device["data_interface"]:upper() --获取连接状态 - local connect_status="unknown" - if modem_device["at_port"] then - connect_status=getModemConnectStatus(modem_device["at_port"]) - end + local connect_status=getModemConnectStatus(modem_device["at_port"],modem_device["manufacturer"]) --设置值 modem_base_info=modem_device @@ -166,10 +154,7 @@ function getModems() local translation={} uci:foreach("modem", "modem-device", function (modem_device) -- 获取连接状态 - local connect_status="unknown" - if modem_device["at_port"] then - connect_status=getModemConnectStatus(modem_device["at_port"]) - end + local connect_status=getModemConnectStatus(modem_device["at_port"],modem_device["manufacturer"]) -- 获取翻译 translation[connect_status]=luci.i18n.translate(connect_status) diff --git a/luci-app-modem/luasrc/view/modem/modem_status.htm b/luci-app-modem/luasrc/view/modem/modem_status.htm index 313ac3d..0990ca1 100644 --- a/luci-app-modem/luasrc/view/modem/modem_status.htm +++ b/luci-app-modem/luasrc/view/modem/modem_status.htm @@ -11,7 +11,7 @@ { var modems=data["modems"]; var translation=data["translation"]; - + var modems_div=document.getElementById('modem_status_view'); if (Object.keys(modems).length!=0) { diff --git a/luci-app-modem/root/usr/share/modem/fibocom.sh b/luci-app-modem/root/usr/share/modem/fibocom.sh index f82d4b7..88aed2e 100755 --- a/luci-app-modem/root/usr/share/modem/fibocom.sh +++ b/luci-app-modem/root/usr/share/modem/fibocom.sh @@ -27,6 +27,25 @@ get_fibocom_mode() echo "$mode" } +#获取连接状态 +# $1:AT串口 +get_connect_status() +{ + local at_port="$1" + local at_command="AT+CGDCONT?" + + local response=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $6}') + local not_ip="0.0.0.0,0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" + + if [ "$response" = "$not_ip" ]; then + connect_status="disconnect" + else + connect_status="connect" + fi + + echo "$connect_status" +} + #获取SIM卡状态 get_fibocom_sim_status() { @@ -148,7 +167,7 @@ get_band() case $1 in "WCDMA") band="B$2" ;; "LTE") band="B$(($2-100))" ;; - "NR") band="N$(($2-500))" ;; + "NR") band="$2" band="N${band#*50}" ;; esac echo "$band" } diff --git a/luci-app-modem/root/usr/share/modem/modem_info.sh b/luci-app-modem/root/usr/share/modem/modem_info.sh index 111cb06..625eab6 100755 --- a/luci-app-modem/root/usr/share/modem/modem_info.sh +++ b/luci-app-modem/root/usr/share/modem/modem_info.sh @@ -197,6 +197,7 @@ get_cell_info() {\"Physical Cell ID\":\"$endc_lte_physical_cell_id\", \"full_name\":\"Physical Cell ID\"}, {\"EARFCN\":\"$endc_lte_earfcn\", \"full_name\":\"E-UTRA Absolute Radio Frequency Channel Number\"}, {\"Freq band indicator\":\"$endc_lte_freq_band_ind\", \"full_name\":\"Freq band indicator\"}, + {\"Band\":\"$endc_lte_band\", \"full_name\":\"Band\"}, {\"UL Bandwidth\":\"$endc_lte_ul_bandwidth\", \"full_name\":\"UL Bandwidth\"}, {\"DL Bandwidth\":\"$endc_lte_dl_bandwidth\", \"full_name\":\"DL Bandwidth\"}, {\"TAC\":\"$endc_lte_tac\", \"full_name\":\"Tracking area code of cell servedby neighbor Enb\"}, @@ -236,6 +237,7 @@ get_cell_info() {\"Physical Cell ID\":\"$lte_physical_cell_id\", \"full_name\":\"Physical Cell ID\"}, {\"EARFCN\":\"$lte_earfcn\", \"full_name\":\"E-UTRA Absolute Radio Frequency Channel Number\"}, {\"Freq band indicator\":\"$lte_freq_band_ind\", \"full_name\":\"Freq band indicator\"}, + {\"Band\":\"$lte_band\", \"full_name\":\"Band\"}, {\"UL Bandwidth\":\"$lte_ul_bandwidth\", \"full_name\":\"UL Bandwidth\"}, {\"DL Bandwidth\":\"$lte_dl_bandwidth\", \"full_name\":\"DL Bandwidth\"}, {\"TAC\":\"$lte_tac\", \"full_name\":\"Tracking area code of cell servedby neighbor Enb\"}, @@ -259,6 +261,7 @@ get_cell_info() {\"UARFCN\":\"$wcdma_uarfcn\", \"full_name\":\"UTRA Absolute Radio Frequency Channel Number\"}, {\"PSC\":\"$wcdma_psc\", \"full_name\":\"Primary Scrambling Code\"}, {\"RAC\":\"$wcdma_rac\", \"full_name\":\"Routing Area Code\"}, + {\"Band\":\"$wcdma_band\", \"full_name\":\"Band\"}, {\"RSCP\":\"$wcdma_rscp\", \"full_name\":\"Received Signal Code Power\"}, {\"Ec/Io\":\"$wcdma_ecio\", \"full_name\":\"Ec/Io\"}, {\"Ec/No\":\"$wcdma_ecno\", \"full_name\":\"Ec/No\"}, diff --git a/luci-app-modem/root/usr/share/modem/quectel.sh b/luci-app-modem/root/usr/share/modem/quectel.sh index 224284c..3f89fe6 100755 --- a/luci-app-modem/root/usr/share/modem/quectel.sh +++ b/luci-app-modem/root/usr/share/modem/quectel.sh @@ -22,6 +22,24 @@ get_quectel_mode() echo "$mode" } +#获取连接状态 +# $1:AT串口 +get_connect_status() +{ + local at_port="$1" + local at_command="AT+QNWINFO" + + local response=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p') + + if [[ "$response" = *"No Service"* ]]; then + connect_status="disconnect" + else + connect_status="connect" + fi + + echo "$connect_status" +} + #获取SIM卡状态 get_quectel_sim_status() {