From 98def800ca094abbc4ab029e6280a50c7020bb4c Mon Sep 17 00:00:00 2001 From: fujr Date: Sun, 28 Apr 2024 15:09:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=94=81=E9=A2=91=E3=80=81?= =?UTF-8?q?=E9=94=81=E5=B0=8F=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luci-app-modem/Makefile | 6 +- luci-app-modem/luasrc/controller/modem.lua | 91 +++++++ .../root/usr/share/modem/fibocom.sh | 237 +++++++++++++++++- 3 files changed, 329 insertions(+), 5 deletions(-) diff --git a/luci-app-modem/Makefile b/luci-app-modem/Makefile index 113f298..709939e 100644 --- a/luci-app-modem/Makefile +++ b/luci-app-modem/Makefile @@ -11,8 +11,8 @@ PKG_LICENSE:=GPLv3 PKG_LINCESE_FILES:=LICENSE PKF_MAINTAINER:=siriling LUCI_DEPENDS:=+luci-compat +kmod-usb-net +kmod-usb-net-cdc-ether +kmod-usb-acm \ - +kmod-usb-net-qmi-wwan +kmod-usb-net-rndis +kmod-usb-serial-qualcomm \ - +kmod-usb-net-sierrawireless +kmod-usb-ohci +kmod-usb-serial \ + +kmod-usb-net-rndis \ + +kmod-usb-net-sierrawireless +kmod-usb-ohci\ +kmod-usb-serial-option +kmod-usb-wdm \ +kmod-usb2 +kmod-usb3 \ +kmod-usb-net-cdc-mbim \ @@ -23,7 +23,7 @@ LUCI_DEPENDS:=+luci-compat +kmod-usb-net +kmod-usb-net-cdc-ether +kmod-usb-acm \ +modemmanager \ +luci-proto-modemmanager \ +sms-tool \ - +jq +grep\ + +jq +grep +bc\ define Package/luci-app-modem/conffiles /etc/config/modem diff --git a/luci-app-modem/luasrc/controller/modem.lua b/luci-app-modem/luasrc/controller/modem.lua index ed41a5d..76dca9d 100644 --- a/luci-app-modem/luasrc/controller/modem.lua +++ b/luci-app-modem/luasrc/controller/modem.lua @@ -34,6 +34,10 @@ function index() entry({"admin", "network", "modem", "set_mode"}, call("setMode"), nil).leaf = true entry({"admin", "network", "modem", "get_network_prefer_info"}, call("getNetworkPreferInfo"), nil).leaf = true entry({"admin", "network", "modem", "set_network_prefer"}, call("setNetworkPrefer"), nil).leaf = true + entry({"admin", "network", "modem", "get_lockband"}, call("getLockBand"), nil).leaf = true + entry({"admin", "network", "modem", "set_lockband"}, call("setLockBand"), nil).leaf = true + entry({"admin", "network", "modem", "get_neighbor_cellinfo"}, call("getNeighbor"), nil).leaf = true + entry({"admin", "network", "modem", "set_lock_cell"}, call("setLockCell"), nil).leaf = true entry({"admin", "network", "modem", "get_self_test_info"}, call("getSelfTestInfo"), nil).leaf = true entry({"admin", "network", "modem", "get_quick_commands"}, call("getQuickCommands"), nil).leaf = true entry({"admin", "network", "modem", "send_at_command"}, call("sendATCommand"), nil).leaf = true @@ -632,6 +636,93 @@ function setNetworkPrefer() luci.http.write_json(network_prefer) end +function getNeighbor() + local at_port = http.formvalue("port") + local manufacturer = getManufacturer(at_port) + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_neighborcell "..at_port + local result=shell(command) + local neighbor_cellinfo=json.parse(result) + luci.http.prepare_content("application/json") + luci.http.write_json(neighbor_cellinfo) +end + +function setLockCell() + local at_port = http.formvalue("port") + local manufacturer = getManufacturer(at_port) + local pci = http.formvalue("pci") + local arfcn = http.formvalue("arfcn") + local scs = http.formvalue("scs") --0:15KHz 1:30KHz 2:60KHz + local nrband = http.formvalue("nrband") + local celltype = http.formvalue("celltype") --0:LTE 1:NR + local lock = http.formvalue("lock") --0:unlock 1:lock_pci 2:lock_arfcn 3:lock_self + response={} + if (lock == "0") then + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_unlockcell "..at_port + local result=shell(command) + response["response"]=result + response["time"]=os.date("%Y-%m-%d %H:%M:%S") + response["lock"]=0 + elseif (lock == "1") then + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_lockpci "..at_port.." "..celltype.." "..arfcn.." "..pci.." "..scs.." "..nrband + local result=shell(command) + response["response"]=result + response["time"]=os.date("%Y-%m-%d %H:%M:%S") + response["lock"]="pci" + elseif (lock == "2") then + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_lockarfcn "..at_port.." "..celltype.." "..arfcn + local result=shell(command) + response["response"]=result + response["time"]=os.date("%Y-%m-%d %H:%M:%S") + response["lock"]="arfcn" + elseif (lock == "3") then + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_lockcurrent "..at_port + local result=shell(command) + response["response"]=result + response["time"]=os.date("%Y-%m-%d %H:%M:%S") + response["lock"]="self" + end + luci.http.prepare_content("application/json") + luci.http.write_json(response) +end + +function getLockBand() + local at_port = http.formvalue("port") + local manufacturer = getManufacturer(at_port) + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_lockband "..at_port + local result=shell(command) + --获取锁频配置 + local lock_band_config={} + if at_port and manufacturer and manufacturer~="unknown" then + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_lockband "..at_port + local result=shell(command) + lock_band_config=json.parse(result) + end + luci.http.prepare_content("application/json") + luci.http.write_json(lock_band_config) +end + + +function setLockBand() + local at_port = http.formvalue("port") + local lock_band_config = http.formvalue("lock_band_config") + + --获取制造商 + local manufacturer = getManufacturer(at_port) + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_lockband "..at_port.." "..lock_band_config + local result=shell(command) + --获取锁频配置 + local lock_band_config={} + if at_port and manufacturer and manufacturer~="unknown" then + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_lockband "..at_port + local result=shell(command) + lock_band_config=json.parse(result) + end + luci.http.prepare_content("application/json") + luci.http.write_json(lock_band_config) +end + + + --[[ @Description 获取自检信息 ]] diff --git a/luci-app-modem/root/usr/share/modem/fibocom.sh b/luci-app-modem/root/usr/share/modem/fibocom.sh index ab2671c..94664b8 100755 --- a/luci-app-modem/root/usr/share/modem/fibocom.sh +++ b/luci-app-modem/root/usr/share/modem/fibocom.sh @@ -3,7 +3,7 @@ #脚本目录 SCRIPT_DIR="/usr/share/modem" - +source /usr/share/libubox/jshn.sh #预设 fibocom_presets() { @@ -559,6 +559,239 @@ fibocom_network_info() rx_rate=$(echo $response | awk -F',' '{print $1}') } +#锁频信息 +fibocom_get_lockband() +{ + local at_port="$1" + debug "Fibocom get lockband info" + get_lockband_config_command="AT+GTACT?" + get_available_band_command="AT+GTACT=?" + get_lockband_config_res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_lockband_config_command) + get_available_band_res=$(sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_available_band_command) + json_init + json_add_object "available_band" + index=0 + for i in $(echo "$get_available_band_res"| sed 's/\r//g' | awk -F"[()]" '{for(j=8; j /tmp/neighborcell + while IFS= read -r line; do + #跳过空行 + line=$(echo $line | sed 's/\r//g') + if [ -z "$line" ]; then + continue + fi + case $line in + *"NR neighbor cell"*) + cell_type="NR" + continue + ;; + *"LTE neighbor cell"*) + cell_type="LTE" + continue + ;; + *"service cell"*|*"GTCELLINFO"*|*"OK"*) + cell_type="undefined" + continue + ;; + esac + case $cell_type in + "NR") + tac=$(echo "$line" | awk -F',' '{print $5}') + cellid=$(echo "$line" | awk -F',' '{print $6}') + arfcn=$(echo "$line" | awk -F',' '{print $7}') + pci=$(echo "$line" | awk -F',' '{print $8}') + ss_sinr=$(echo "$line" | awk -F',' '{print $9}') + rxlev=$(echo "$line" | awk -F',' '{print $10}') + ss_rsrp=$(echo "$line" | awk -F',' '{print $11}') + ss_rsrq=$(echo "$line" | awk -F',' '{print $12}') + arfcn=$(echo 'ibase=16;' "$arfcn" | bc) + pci=$(echo 'ibase=16;' "$pci" | bc) + json_select "NR" + json_add_object "" + json_add_string "tac" "$tac" + json_add_string "cellid" "$cellid" + json_add_string "arfcn" "$arfcn" + json_add_string "pci" "$pci" + json_add_string "ss_sinr" "$ss_sinr" + json_add_string "rxlev" "$rxlev" + json_add_string "ss_rsrp" "$ss_rsrp" + json_add_string "ss_rsrq" "$ss_rsrq" + json_close_object + json_select ".." + ;; + "LTE") + tac=$(echo "$line" | awk -F',' '{print $5}') + cellid=$(echo "$line" | awk -F',' '{print $6}') + arfcn=$(echo "$line" | awk -F',' '{print $7}') + pci=$(echo "$line" | awk -F',' '{print $8}') + bandwidth=$(echo "$line" | awk -F',' '{print $9}') + rxlev=$(echo "$line" | awk -F',' '{print $10}') + rsrp=$(echo "$line" | awk -F',' '{print $11}') + rsrq=$(echo "$line" | awk -F',' '{print $12}') + arfcn=$(echo 'ibase=16;' "$arfcn" | bc) + pci=$(echo 'ibase=16;' "$pci" | bc) + json_select "LTE" + json_add_object "" + json_add_string "tac" "$tac" + json_add_string "cellid" "$cellid" + json_add_string "arfcn" "$arfcn" + json_add_string "pci" "$pci" + json_add_string "bandwidth" "$bandwidth" + json_add_string "rxlev" "$rxlev" + json_add_string "rsrp" "$rsrp" + json_add_string "rsrq" "$rsrq" + json_close_object + json_select ".." + ;; + esac + done < "/tmp/neighborcell" + + result=`sh ${SCRIPT_DIR}/modem_at.sh $at_port $get_lockcell_command | grep "+GTCELLLOCK:" | sed 's/+GTCELLLOCK: //g' | sed 's/\r//g'` + #$1:lockcell_status $2:cell_type $3:lock_type $4:arfcn $5:pci $6:scs $7:nr_band + json_add_object "lockcell_status" + if [ -n "$result" ]; then + lockcell_status=$(echo "$result" | awk -F',' '{print $1}') + if [ "$lockcell_status" = "1" ]; then + lockcell_status="lock" + else + lockcell_status="unlock" + fi + cell_type=$(echo "$result" | awk -F',' '{print $2}') + if [ "$cell_type" = "1" ]; then + cell_type="NR" + elif [ "$cell_type" = "0" ]; then + cell_type="LTE" + fi + lock_type=$(echo "$result" | awk -F',' '{print $3}') + if [ "$lock_type" = "1" ]; then + lock_type="arfcn" + elif [ "$lock_type" = "0" ]; then + lock_type="pci" + fi + arfcn=$(echo "$result" | awk -F',' '{print $4}') + pci=$(echo "$result" | awk -F',' '{print $5}') + scs=$(echo "$result" | awk -F',' '{print $6}') + nr_band=$(echo "$result" | awk -F',' '{print $7}') + json_add_string "lockcell_status" "$lockcell_status" + json_add_string "cell_type" "$cell_type" + json_add_string "lock_type" "$lock_type" + json_add_string "arfcn" "$arfcn" + json_add_string "pci" "$pci" + json_add_string "scs" "$scs" + json_add_string "nr_band" "$nr_band" + fi + json_close_object + + json_dump +} + +fibocom_unlockcell() +{ + local at_port="$1" + local unlockcell_command="AT+GTCELLLOCK=0" + sh ${SCRIPT_DIR}/modem_at.sh $at_port $unlockcell_command +} + +fibocom_lockcurrent() +{ + local at_port="$1" + local unlockcell_command="AT+GTCELLLOCK=1" + sh ${SCRIPT_DIR}/modem_at.sh $at_port $unlockcell_command +} + +fibocom_lockpci() +{ + local at_port="$1" + local cell_type="$2" + local arfcn="$3" + local pci="$4" + local scs="$5" + local nrband="$6" + if [ "$cell_type" == 1 ]; then + local set_lockcell_command="AT+GTCELLLOCK=1,$cell_type,0,$arfcn,$pci,$scs,50$nrband" + else + local set_lockcell_command="AT+GTCELLLOCK=1,$cell_type,0,$arfcn,$pci" + fi + echo $set_lockcell_command + sh ${SCRIPT_DIR}/modem_at.sh $at_port $set_lockcell_command +} + +fibocom_lockarfcn() +{ + local at_port="$1" + local cell_type="$2" + local arfcn="$3" + local set_lockcell_command="AT+GTCELLLOCK=1,$cell_type,1,$arfcn" + echo $set_lockcell_command + sh ${SCRIPT_DIR}/modem_at.sh $at_port $set_lockcell_command +} #获取频段 # $1:网络类型 # $2:频段数字 @@ -1068,4 +1301,4 @@ get_fibocom_info() PCI="$PCI, "$(echo "$CASV" | cut -d, -f7) done fi -} \ No newline at end of file +}