diff --git a/luci-app-modem/Makefile b/luci-app-modem/Makefile index da6e3a3..a5b8c81 100644 --- a/luci-app-modem/Makefile +++ b/luci-app-modem/Makefile @@ -6,12 +6,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-modem LUCI_TITLE:=LuCI support for Modem LUCI_PKGARCH:=all -PKG_VERSION:=1.2.0 +PKG_VERSION:=1.4.0 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 \ +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-serial-option +kmod-usb-wdm \ +kmod-usb2 +kmod-usb3 \ @@ -29,13 +29,6 @@ define Package/luci-app-modem/conffiles /etc/config/modem endef -define Package/$(PKG_NAME)/config -# shown in make menuconfig -help - $(LUCI_TITLE) - Version: $(PKG_VERSION) -endef - include $(TOPDIR)/feeds/luci/luci.mk # call BuildPackage - OpenWrt buildroot signature diff --git a/luci-app-modem/htdocs/luci-static/resources/icons/delsms.png b/luci-app-modem/htdocs/luci-static/resources/icons/sms.png similarity index 100% rename from luci-app-modem/htdocs/luci-static/resources/icons/delsms.png rename to luci-app-modem/htdocs/luci-static/resources/icons/sms.png diff --git a/luci-app-modem/htdocs/luci-static/resources/icons/delsms2.png b/luci-app-modem/htdocs/luci-static/resources/icons/sms2.png similarity index 100% rename from luci-app-modem/htdocs/luci-static/resources/icons/delsms2.png rename to luci-app-modem/htdocs/luci-static/resources/icons/sms2.png diff --git a/luci-app-modem/luasrc/controller/modem.lua b/luci-app-modem/luasrc/controller/modem.lua index 61f7b53..5338d21 100644 --- a/luci-app-modem/luasrc/controller/modem.lua +++ b/luci-app-modem/luasrc/controller/modem.lua @@ -5,6 +5,7 @@ local fs = require "nixio.fs" local json = require("luci.jsonc") uci = luci.model.uci.cursor() local script_path="/usr/share/modem/" +local run_path="/tmp/run/modem/" function index() if not nixio.fs.access("/etc/config/modem") then @@ -22,19 +23,25 @@ function index() entry({"admin", "network", "modem", "index"},cbi("modem/index"),translate("Dial Config"),20).leaf = true entry({"admin", "network", "modem", "config"}, cbi("modem/config")).leaf = true entry({"admin", "network", "modem", "get_modems"}, call("getModems"), nil).leaf = true + entry({"admin", "network", "modem", "get_dial_log_info"}, call("getDialLogInfo"), nil).leaf = true + entry({"admin", "network", "modem", "clean_dial_log"}, call("cleanDialLog"), nil).leaf = true entry({"admin", "network", "modem", "status"}, call("act_status")).leaf = true --模块调试 entry({"admin", "network", "modem", "modem_debug"},template("modem/modem_debug"),translate("Modem Debug"),30).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 - entry({"admin", "network", "modem", "get_modem_debug_info"}, call("getModemDebugInfo"), nil).leaf = true + entry({"admin", "network", "modem", "quick_commands_config"}, cbi("modem/quick_commands_config")).leaf = true entry({"admin", "network", "modem", "get_mode_info"}, call("getModeInfo"), nil).leaf = true 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_self_test_info"}, call("getSelfTestInfo"), nil).leaf = true - entry({"admin", "network", "modem", "quick_commands_config"}, cbi("modem/quick_commands_config")).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 + -- entry({"admin", "network", "modem", "get_modem_debug_info"}, call("getModemDebugInfo"), nil).leaf = true + + --插件信息 + entry({"admin", "network", "modem", "plugin_info"},template("modem/plugin_info"),translate("Plugin Info"),40).leaf = true + entry({"admin", "network", "modem", "get_plugin_info"}, call("getPluginInfo"), nil).leaf = true --AT命令旧界面 entry({"admin", "network", "modem", "at_command_old"},template("modem/at_command_old")).leaf = true @@ -50,6 +57,18 @@ function hasLetters(str) return string.find(str, pattern) ~= nil end +--[[ +@Description 执行Shell脚本 +@Params + command sh命令 +]] +function shell(command) + local odpall = io.popen(command) + local odp = odpall:read("*a") + odpall:close() + return odp +end + --[[ @Description 执行AT命令 @Params @@ -57,11 +76,29 @@ end at_command AT命令 ]] function at(at_port,at_command) - local odpall = io.popen("source "..script_path.."modem_debug.sh && at "..at_port.." "..at_command) - local odp = odpall:read("*a") - odpall:close() - odp=string.gsub(odp, "\r", "") - return odp + local command="source "..script_path.."modem_debug.sh && at "..at_port.." "..at_command + local result=shell(command) + result=string.gsub(result, "\r", "") + return result +end + +--[[ +@Description 获取制造商 +@Params + at_port AT串口 +]] +function getManufacturer(at_port) + + local manufacturer + uci:foreach("modem", "modem-device", function (modem_device) + --设置模组AT串口 + if at_port == modem_device["at_port"] then + manufacturer=modem_device["manufacturer"] + return true --跳出循环 + end + end) + + return manufacturer end --[[ @@ -75,15 +112,33 @@ function getMode(at_port,manufacturer,platform) local mode="unknown" if at_port and manufacturer~="unknown" then - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port.." "..platform) - opd = odpall:read("*a") - odpall:close() - mode = string.gsub(opd, "\n", "") + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port.." "..platform + local result=shell(command) + mode=string.gsub(result, "\n", "") end return mode end +--[[ +@Description 获取模组支持的拨号模式 +@Params + at_port AT串口 +]] +function getModes(at_port) + + local modes + uci:foreach("modem", "modem-device", function (modem_device) + --设置模组AT串口 + if at_port == modem_device["at_port"] then + modes=modem_device["modes"] + return true --跳出循环 + end + end) + + return modes +end + --[[ @Description 获取模组连接状态 @Params @@ -96,10 +151,9 @@ function getModemConnectStatus(at_port,manufacturer,define_connect) local connect_status="unknown" if at_port and manufacturer~="unknown" then - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_connect_status "..at_port.." "..define_connect) - opd = odpall:read("*a") - odpall:close() - connect_status = string.gsub(opd, "\n", "") + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_connect_status "..at_port.." "..define_connect + local result=shell(command) + connect_status=string.gsub(result, "\n", "") end return connect_status @@ -140,12 +194,11 @@ end function getModemMoreInfo(at_port,manufacturer,define_connect) --获取模组信息 - local odpall = io.popen("sh "..script_path.."modem_info.sh".." "..at_port.." "..manufacturer.." "..define_connect) - local opd = odpall:read("*a") - odpall:close() + local command="sh "..script_path.."modem_info.sh".." "..at_port.." "..manufacturer.." "..define_connect + local result=shell(command) --设置值 - local modem_more_info=json.parse(opd) + local modem_more_info=json.parse(result) return modem_more_info end @@ -309,6 +362,74 @@ function getModems() luci.http.write_json(data) end +--[[ +@Description 获取拨号日志信息 +]] +function getDialLogInfo() + + local command="find "..run_path.." -name \"modem*_dial.cache\"" + local result=shell(command) + + local log_paths=string.split(result, "\n") + table.sort(log_paths) + + local logs={} + local names={} + for key in pairs(log_paths) do + + local log_path=log_paths[key] + + if log_path ~= "" then + --获取模组 + local tmp=string.gsub(log_path, run_path, "") + local modem=string.gsub(tmp, "_dial.cache", "") + local modem_name=uci:get("modem", modem, "name") + + --获取日志内容 + local command="cat "..log_path + log=shell(command) + + --排序插入 + modem_log={} + modem_log[modem]=log + table.insert(logs, modem_log) + + names[modem]=modem_name + end + end + + -- 设置值 + local data={} + data["dial_log_info"]=logs + data["modem_name"]=names + data["translation"]=translation + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(data) +end + +--[[ +@Description 清空拨号日志 +]] +function cleanDialLog() + + -- 获取拨号日志路径 + local dial_log_path = http.formvalue("path") + + -- 清空拨号日志 + local command=": > "..dial_log_path + shell(command) + + -- 设置值 + local data={} + data["clean_result"]="clean dial log" + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(data) +end + --[[ @Description 模块列表状态函数 ]] @@ -380,6 +501,160 @@ function getATPort() luci.http.write_json(data) end +--[[ +@Description 获取拨号模式信息 +]] +function getModeInfo() + local at_port = http.formvalue("port") + + --获取值 + local mode_info={} + uci:foreach("modem", "modem-device", function (modem_device) + --设置模组AT串口 + if at_port == modem_device["at_port"] then + + --获取制造商 + local manufacturer=modem_device["manufacturer"] + if manufacturer=="unknown" then + return true --跳出循环 + end + + --获取支持的拨号模式 + local modes=modem_device["modes"] + + --获取模组拨号模式 + local mode=getMode(at_port,manufacturer,modem_device["platform"]) + + --设置模式信息 + mode_info["mode"]=mode + mode_info["modes"]=modes + + return true --跳出循环 + end + end) + + --设置值 + local modem_debug_info={} + modem_debug_info["mode_info"]=mode_info + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(modem_debug_info) +end + +--[[ +@Description 设置拨号模式 +]] +function setMode() + local at_port = http.formvalue("port") + local mode_config = http.formvalue("mode_config") + + --获取制造商 + local manufacturer=getManufacturer(at_port) + + --设置模组拨号模式 + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_mode "..at_port.." "..mode_config + shell(command) + + --获取设置好后的模组拨号模式 + local mode + if at_port and manufacturer and manufacturer~="unknown" then + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port + local result=shell(command) + mode=string.gsub(result, "\n", "") + end + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(mode) +end + +--[[ +@Description 获取网络偏好信息 +]] +function getNetworkPreferInfo() + local at_port = http.formvalue("port") + + --获取制造商 + local manufacturer=getManufacturer(at_port) + + --获取值 + local network_prefer_info + if manufacturer~="unknown" then + --获取模组网络偏好 + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port + local result=shell(command) + network_prefer_info=json.parse(result) + end + + --设置值 + local modem_debug_info={} + modem_debug_info["network_prefer_info"]=network_prefer_info + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(modem_debug_info) +end + +--[[ +@Description 设置网络偏好 +]] +function setNetworkPrefer() + local at_port = http.formvalue("port") + local network_prefer_config = json.stringify(http.formvalue("prefer_config")) + + --获取制造商 + local manufacturer=getManufacturer(at_port) + + --设置模组网络偏好 + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_set_network_prefer "..at_port.." "..network_prefer_config + shell(command) + + --获取设置好后的模组网络偏好 + local network_prefer={} + if at_port and manufacturer and manufacturer~="unknown" then + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port + local result=shell(command) + network_prefer=json.parse(result) + end + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(network_prefer) +end + +--[[ +@Description 获取自检信息 +]] +function getSelfTestInfo() + local at_port = http.formvalue("port") + + --获取制造商 + local manufacturer=getManufacturer(at_port) + + --获取值 + local self_test_info={} + if manufacturer~="unknown" then + --获取模组电压 + local command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_voltage "..at_port + local result=shell(command) + self_test_info["voltage"]=json.parse(result) + + --获取模组温度 + command="source "..script_path..manufacturer..".sh && "..manufacturer.."_get_temperature "..at_port + result=shell(command) + self_test_info["temperature"]=json.parse(result) + end + + --设置值 + local modem_debug_info={} + modem_debug_info["self_test_info"]=self_test_info + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(modem_debug_info) +end + --[[ @Description 获取快捷命令 ]] @@ -391,15 +666,7 @@ function getQuickCommands() local at_port = http.formvalue("port") --获取制造商 - local manufacturer - uci:foreach("modem", "modem-device", function (modem_device) - --设置模组AT串口 - if at_port == modem_device["at_port"] then - --获取制造商 - manufacturer=modem_device["manufacturer"] - return true --跳出循环 - end - end) + local manufacturer=getManufacturer(at_port) --未适配模组时,快捷命令选项为自定义 if manufacturer=="unknown" then @@ -410,11 +677,11 @@ function getQuickCommands() local commands={} if quick_option=="auto" then --获取模组AT命令 - -- local odpall = io.popen(source "..script_path.."modem_debug.sh && get_quick_commands "..quick_option.." "..manufacturer) - local odpall = io.popen("cat "..script_path..manufacturer.."_at_commands.json") - local opd = odpall:read("*a") - odpall:close() - quick_commands=json.parse(opd) + -- local command="source "..script_path.."modem_debug.sh && get_quick_commands "..quick_option.." "..manufacturer + local command="cat "..script_path..manufacturer.."_at_commands.json" + local result=shell(command) + quick_commands=json.parse(result) + else uci:foreach("modem", "custom-commands", function (custom_commands) local command={} @@ -447,207 +714,6 @@ function sendATCommand() luci.http.write_json(response) end ---[[ -@Description 设置网络偏好 -]] -function setNetworkPrefer() - local at_port = http.formvalue("port") - local network_prefer_config = json.stringify(http.formvalue("prefer_config")) - - --获取制造商 - local manufacturer - uci:foreach("modem", "modem-device", function (modem_device) - --设置模组AT串口 - if at_port == modem_device["at_port"] then - --获取制造商 - manufacturer=modem_device["manufacturer"] - return true --跳出循环 - end - end) - - --设置模组网络偏好 - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_set_network_prefer "..at_port.." "..network_prefer_config) - odpall:close() - - --获取设置好后的模组网络偏好 - local network_prefer={} - if at_port and manufacturer and manufacturer~="unknown" then - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port) - local opd = odpall:read("*a") - network_prefer=json.parse(opd) - odpall:close() - end - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(network_prefer) -end - ---[[ -@Description 设置拨号模式 -]] -function setMode() - local at_port = http.formvalue("port") - local mode_config = http.formvalue("mode_config") - - --获取制造商 - local manufacturer - uci:foreach("modem", "modem-device", function (modem_device) - --设置模组AT串口 - if at_port == modem_device["at_port"] then - --获取制造商 - manufacturer=modem_device["manufacturer"] - return true --跳出循环 - end - end) - - --设置模组拨号模式 - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_set_mode "..at_port.." "..mode_config) - odpall:close() - - --获取设置好后的模组拨号模式 - local mode - if at_port and manufacturer and manufacturer~="unknown" then - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port) - mode = odpall:read("*a") - mode=string.gsub(mode, "\n", "") - odpall:close() - end - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(mode) -end - ---[[ -@Description 获取拨号模式信息 -]] -function getModeInfo() - local at_port = http.formvalue("port") - - --获取制造商 - local manufacturer - uci:foreach("modem", "modem-device", function (modem_device) - --设置模组AT串口 - if at_port == modem_device["at_port"] then - --获取制造商 - manufacturer=modem_device["manufacturer"] - return true --跳出循环 - end - end) - - --获取值 - local mode_info={} - if manufacturer~="unknown" then - - --获取支持的拨号模式 - local modes - uci:foreach("modem", "modem-device", function (modem_device) - --设置模组AT串口 - if at_port == modem_device["at_port"] then - modes=modem_device["modes"] - return true --跳出循环 - end - end) - - --获取模组拨号模式 - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_mode "..at_port) - local opd = odpall:read("*a") - odpall:close() - local mode=string.gsub(opd, "\n", "") - - --设置模式信息 - mode_info["mode"]=mode - mode_info["modes"]=modes - end - - --设置值 - local modem_debug_info={} - modem_debug_info["mode_info"]=mode_info - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(modem_debug_info) -end - ---[[ -@Description 获取网络偏好信息 -]] -function getNetworkPreferInfo() - local at_port = http.formvalue("port") - - --获取制造商 - local manufacturer - uci:foreach("modem", "modem-device", function (modem_device) - --设置模组AT串口 - if at_port == modem_device["at_port"] then - --获取制造商 - manufacturer=modem_device["manufacturer"] - return true --跳出循环 - end - end) - - --获取值 - local network_prefer_info - if manufacturer~="unknown" then - --获取模组网络偏好 - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_network_prefer "..at_port) - local opd = odpall:read("*a") - odpall:close() - network_prefer_info=json.parse(opd) - end - - --设置值 - local modem_debug_info={} - modem_debug_info["network_prefer_info"]=network_prefer_info - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(modem_debug_info) -end - ---[[ -@Description 获取自检信息 -]] -function getSelfTestInfo() - local at_port = http.formvalue("port") - - --获取制造商 - local manufacturer - uci:foreach("modem", "modem-device", function (modem_device) - --设置模组AT串口 - if at_port == modem_device["at_port"] then - --获取制造商 - manufacturer=modem_device["manufacturer"] - return true --跳出循环 - end - end) - - --获取值 - local self_test_info={} - if manufacturer~="unknown" then - --获取模组电压 - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_voltage "..at_port) - local opd = odpall:read("*a") - odpall:close() - self_test_info["voltage"]=json.parse(opd) - - --获取模组温度 - local odpall = io.popen("source "..script_path..manufacturer..".sh && "..manufacturer.."_get_temperature "..at_port) - local opd = odpall:read("*a") - odpall:close() - self_test_info["temperature"]=json.parse(opd) - end - - --设置值 - local modem_debug_info={} - modem_debug_info["self_test_info"]=self_test_info - - -- 写入Web界面 - luci.http.prepare_content("application/json") - luci.http.write_json(modem_debug_info) -end - --[[ @Description 获取模组调试信息 ]] @@ -655,15 +721,7 @@ end -- local at_port = http.formvalue("port") -- --获取制造商 --- local manufacturer --- uci:foreach("modem", "modem-device", function (modem_device) --- --设置模组AT串口 --- if at_port == modem_device["at_port"] then --- --获取制造商 --- manufacturer=modem_device["manufacturer"] --- return true --跳出循环 --- end --- end) +-- local manufacturer=getManufacturer(at_port) -- --获取值 -- local mode_info={} @@ -675,7 +733,7 @@ end -- self_test_info=getSelfTestInfo(at_port,manufacturer) -- end --- --设置值 +-- -- 设置值 -- local modem_debug_info={} -- modem_debug_info["mode_info"]=mode_info -- modem_debug_info["network_prefer_info"]=network_prefer_info @@ -685,3 +743,125 @@ end -- luci.http.prepare_content("application/json") -- luci.http.write_json(modem_debug_info) -- end + +--[[ +@Description 设置插件版本信息 +@Params + info 信息 +]] +function setPluginVersionInfo(info) + + -- 正则表达式 + local version_regular_expression="[0-9]+.[0-9]+.[0-9]+" + + for key in pairs(info) do + + -- 获取插件版本 + local command="opkg list-installed | grep -oE '"..key.." - "..version_regular_expression.."' | awk -F' ' '{print $3}' | tr -d '\n'" + local plugin_version=shell(command) + + if plugin_version~="" then + info[key]=plugin_version + end + end + +end + +--[[ +@Description 获取内核模块状态 +@Params + result 命令返回值 +]] +function getModelStatus(result) + local model_status="Not loaded" + + if result~="" then + model_status="Loaded" + end + + return model_status +end + +--[[ +@Description 设置内核模块状态 +@Params + info 信息 +]] +function setModelStatus(info) + + for key in pairs(info) do + + -- 获取内核模块名 + local model_name=key:gsub(".ko","") + + local command="lsmod | grep -oE '"..model_name.." '" + local result=shell(command) + local model_status=getModelStatus(result) + + -- 修改信息表 + info[key]=model_status + end + +end + +--[[ +@Description 获取插件信息 +]] +function getPluginInfo() + + -- 设置翻译 + translation={} + translation["Unknown"]=luci.i18n.translate("Unknown") + translation["Loaded"]=luci.i18n.translate("Loaded") + translation["Not loaded"]=luci.i18n.translate("Not loaded") + + -- 获取插件信息 + local plugin_info={} + plugin_info["luci-app-modem"]="Unknown" + setPluginVersionInfo(plugin_info) + + -- 获取拨号工具信息 + local dial_tool_info={} + dial_tool_info["quectel-CM-5G"]="Unknown" + dial_tool_info["modemmanager"]="Unknown" + setPluginVersionInfo(dial_tool_info) + + -- 获取通用驱动信息 + local general_driver_info={} + general_driver_info["usbnet.ko"]="Not loaded" + general_driver_info["qcserial.ko"]="Not loaded" + setModelStatus(general_driver_info) + + -- 获取模组USB驱动信息 + local usb_driver_info={} + usb_driver_info["qmi_wwan.ko"]="Not loaded" + usb_driver_info["cdc_ether.ko"]="Not loaded" + usb_driver_info["cdc_mbim.ko"]="Not loaded" + usb_driver_info["rndis_host.ko"]="Not loaded" + usb_driver_info["cdc_ncm.ko"]="Not loaded" + setModelStatus(usb_driver_info) + + -- 获取模组PCIE驱动信息 + local pcie_driver_info={} + pcie_driver_info["mhi_net.ko"]="Not loaded" + pcie_driver_info["qrtr_mhi.ko"]="Not loaded" + pcie_driver_info["mhi_pci_generic.ko"]="Not loaded" + pcie_driver_info["mhi_wwan_mbim.ko"]="Not loaded" + pcie_driver_info["mhi_wwan_ctrl.ko"]="Not loaded" + pcie_driver_info["pcie_mhi.ko"]="Not loaded" + pcie_driver_info["mtk_pcie_wwan_m80.ko"]="Not loaded" + setModelStatus(pcie_driver_info) + + -- 设置值 + local data={} + data["translation"]=translation + data["plugin_info"]=plugin_info + data["dial_tool_info"]=dial_tool_info + data["general_driver_info"]=general_driver_info + data["usb_driver_info"]=usb_driver_info + data["pcie_driver_info"]=pcie_driver_info + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(data) +end diff --git a/luci-app-modem/luasrc/model/cbi/modem/index.lua b/luci-app-modem/luasrc/model/cbi/modem/index.lua index 9afb953..b6746ec 100644 --- a/luci-app-modem/luasrc/model/cbi/modem/index.lua +++ b/luci-app-modem/luasrc/model/cbi/modem/index.lua @@ -93,6 +93,9 @@ o.cfgvalue = function(t, n) return apn end +-- 添加模块拨号日志 +m:append(Template("modem/modem_dial_log")) + -- m:append(Template("modem/list_status")) return m diff --git a/luci-app-modem/luasrc/view/modem/modem_debug.htm b/luci-app-modem/luasrc/view/modem/modem_debug.htm index 926b989..75cd96c 100644 --- a/luci-app-modem/luasrc/view/modem/modem_debug.htm +++ b/luci-app-modem/luasrc/view/modem/modem_debug.htm @@ -15,8 +15,8 @@ get_modem_debug_info(debug_params); }); - //获取tab菜单 - var tab_menu = document.getElementsByClassName('cbi-tabmenu')[0]; + //获取标签菜单 + var tab_menu = document.getElementById("tab_menu"); set_tab_event(tab_menu); //获取快捷选项父元素 @@ -69,7 +69,7 @@ }); } - //设置tab菜单事件 + //设置标签菜单事件 function set_tab_event(parent_element) { //获取子元素 @@ -77,35 +77,36 @@ //获取需要禁用的元素 for (var i = 0; i < childElements.length; i++) { - // childElements[i].addEventListener('click', function(event) { - // var debug_params={first_cache:true}; - // get_modem_debug_info(debug_params); - // }); - - // 创建一个 MutationObserver 实例 - var observer = new MutationObserver(function(mutationsList) { - for (var mutation of mutationsList) { - if (mutation.type === 'attributes' && mutation.attributeName === 'class') { - //只处理当前变为禁用的tab - if (mutation.target.className=='cbi-tab') { - //获取模组调试信息 - var debug_params={first_cache:true}; - get_modem_debug_info(debug_params); - //只处理一次 - break; - } - } - } + childElements[i].addEventListener('click', function(event) { + tab_event(this); + var debug_params={first_cache:true}; + get_modem_debug_info(debug_params); }); - // 配置观察器选项 - var observerOptions = { - attributes: true, // 监听属性值变化 - attributeFilter: ['class'], // 要监听的属性名称 - }; + // // 创建一个 MutationObserver 实例 + // var observer = new MutationObserver(function(mutationsList) { + // for (var mutation of mutationsList) { + // if (mutation.type === 'attributes' && mutation.attributeName === 'class') { + // //只处理当前变为禁用的tab + // if (mutation.target.className=='cbi-tab') { + // //获取模组调试信息 + // var debug_params={first_cache:true}; + // get_modem_debug_info(debug_params); + // //只处理一次 + // break; + // } + // } + // } + // }); - // 开始观察目标元素 - observer.observe(childElements[i], observerOptions); + // // 配置观察器选项 + // var observerOptions = { + // attributes: true, // 监听属性值变化 + // attributeFilter: ['class'], // 要监听的属性名称 + // }; + + // // 开始观察目标元素 + // observer.observe(childElements[i], observerOptions); } } @@ -123,7 +124,8 @@ function(x, data) { responseElement=document.getElementById("response"); - if ("response" in data) { + if ("response" in data) + { //显示当前时间 responseElement.value+=data["time"]+" "; //显示返回值 @@ -233,7 +235,26 @@ return disenable_element; } - // 设置tab显示 + //获取需要禁用的元素 + function get_enable_element(parent_element) + { + var enable_element; + //获取子元素 + var childElements = parent_element.children; + //获取已启用的元素 + for (var i = 0; i < childElements.length; i++) + { + // 检查当前子元素的class属性是否为cbi-tab + if (childElements[i].classList.contains('cbi-tab')) + { + enable_element=childElements[i]; + break; + } + } + return enable_element; + } + + // 设置标签显示 function set_tab_view(disenable_element,enable_element) { //获取tab内容父元素 @@ -246,6 +267,7 @@ var data_tab_disenable = disenable_element.getAttribute('data-tab'); var tab_context_disenable_element = tab_context.querySelector('div[data-tab="'+data_tab_disenable+'"]'); tab_context_disenable_element.setAttribute('data-tab-active','false'); + tab_context_disenable_element.style.display="none"; //启用tab enable_element.classList.remove('cbi-tab-disabled'); @@ -254,13 +276,15 @@ var data_tab_enable = enable_element.getAttribute('data-tab'); var tab_context_enable_element = tab_context.querySelector('div[data-tab="'+data_tab_enable+'"]'); tab_context_enable_element.setAttribute('data-tab-active','true'); + tab_context_enable_element.style.display="block"; } - // tab事件处理(更新选中的tab及tab内容) + // 标签事件(更新选中的标签及标签内容) function tab_event(tab_element) { //获取需要禁用的tab元素 - var tab_menu = document.getElementsByClassName('cbi-tabmenu')[0]; + // var tab_menu = document.getElementsByClassName("cbi-tabmenu")[0]; + var tab_menu = document.getElementById("tab_menu"); var disenable_element=get_tab_enable_element(tab_menu); if (tab_element != disenable_element) { set_tab_view(disenable_element,tab_element); @@ -277,22 +301,11 @@ //隐藏模组选择界面 document.getElementById("cbi-modem").style.display="none"; //隐藏tab菜单界面 - document.getElementsByClassName("cbi-tabmenu")[0].style.display="none"; + document.getElementById("tab_menu").style.display="none"; //隐藏tab内容界面 document.getElementById("tab_context").style.display="none"; } - // 有模组界面 - function modems_view() - { - //显示模组选择界面 - document.getElementById("cbi-modem").style.display="block"; - //显示AT命令标题 - document.getElementById("at_command_title").style.display="block"; - //隐藏提示信息 - // document.getElementById("cbi-info").style.display="none"; - } - // 未适配模组界面 function not_adapted_modems_view() { @@ -300,26 +313,30 @@ document.getElementById("info_message").innerHTML="<%:Not adapted to this modem%>"; //显示提示信息 document.getElementById("cbi-info").style.display="block"; - //显示tab内容界面 + //显示模组选择界面 + document.getElementById("cbi-modem").style.display="block"; + //显示标签内容界面 document.getElementById("tab_context").style.display="block"; //显示AT命令标题 document.getElementById("at_command_title").style.display="block"; - //隐藏tab菜单界面 - document.getElementsByClassName("cbi-tabmenu")[0].style.display="none"; - //在tab菜单选中AT命令 + //隐藏标签菜单界面 + document.getElementById("tab_menu").style.display="none"; + //在标签菜单选中AT命令 var data_tab="at_command_tab" var at_command_tab_element = document.querySelector('li[data-tab="'+data_tab+'"]'); tab_event(at_command_tab_element); - //隐藏tab内容界面 - // document.getElementById("tab_context").style.display="none"; } // 全功能界面 function all_function_view() { - //显示tab菜单界面 - document.getElementsByClassName("cbi-tabmenu")[0].style.display="block"; - //显示tab内容界面 + //更新提示信息 + document.getElementById("info_message").innerHTML='<%:Loading%><%:Loading modem%>...'; + //显示模组选择界面 + document.getElementById("cbi-modem").style.display="block"; + //显示标签菜单界面 + document.getElementById("tab_menu").style.display="block"; + //显示标签内容界面 document.getElementById("tab_context").style.display="block"; //隐藏AT命令标题 document.getElementById("at_command_title").style.display="none"; @@ -390,9 +407,6 @@ var command_select = document.getElementById('command_select'); //更新选项 update_option(command_select,data["quick_commands"],true); - - //显示有模组界面 - modems_view(); } ); } @@ -462,6 +476,11 @@ { //获取当前拨号模式 var current_mode=mode_info["mode"]; + if (current_mode=="unknown") + { + return + } + //获取支持的拨号模式 var modes=mode_info["modes"]; @@ -489,7 +508,10 @@ document.getElementById('mode_option').innerHTML=mode_option_view; //设置拨号模式选项 - document.getElementById('mode_option_'+current_mode).checked=true; + element=document.getElementById('mode_option_'+current_mode).checked=true; + + //设置第一次获取数据标志 + first_cache=false; } } @@ -588,6 +610,9 @@ //启用偏好复选框 disabled_prefer_custom_config(false); } + + //设置第一次获取数据标志 + first_cache=false; } } @@ -602,7 +627,7 @@ //设置当前电压 document.getElementById('current_voltage').innerHTML=voltage/1000+" V"; //设置当前温度 - document.getElementById('current_temperature').innerHTML=temperature+" °C"; + document.getElementById('current_temperature').innerHTML=temperature*1+" °C"; //设置电压状态 var state = ''; @@ -719,7 +744,7 @@ var at_port = document.getElementById("modem_select").value; //获取当前启用的tab元素 - var tab_menu = document.getElementsByClassName('cbi-tabmenu')[0]; + var tab_menu = document.getElementById("tab_menu"); var tab_enable_element=get_tab_enable_element(tab_menu); //获取当前选中的tab元素 @@ -733,19 +758,11 @@ var mode_info=data["mode_info"]; if (Object.keys(mode_info).length==0) { - //显示未适配模组界面 - not_adapted_modems_view(); return false } //设置模式信息 set_mode_info(mode_info,debug_params.first_cache); - - //设置第一次获取数据标志 - debug_params.first_cache=false; - - //显示全功能界面 - all_function_view(); } ); } @@ -757,19 +774,11 @@ var network_prefer_info=data["network_prefer_info"]; if (Object.keys(network_prefer_info).length==0) { - //显示未适配模组界面 - not_adapted_modems_view(); return false } //设置网络偏好信息 set_network_prefer_info(network_prefer_info,debug_params.first_cache); - - //设置第一次获取数据标志 - debug_params.first_cache=false; - - //显示全功能界面 - all_function_view(); } ); } @@ -781,53 +790,14 @@ var self_test_info=data["self_test_info"]; if (Object.keys(self_test_info).length==0) { - //显示未适配模组界面 - not_adapted_modems_view(); return false } //设置模组自检信息 set_modem_self_test_info(self_test_info); - - //设置第一次获取数据标志 - // debug_params.first_cache=false; - - //显示全功能界面 - all_function_view(); } ); } - - //获取调试信息 - // XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_modem_debug_info")%>', {"port":at_port}, - // function(x, data) - // { - // var mode_info=data["mode_info"]; - // var network_prefer_info=data["network_prefer_info"]; - // var self_test_info=data["self_test_info"]; - // if (Object.keys(mode_info).length==0||Object.keys(network_prefer_info).length==0) { - // //显示未适配模组界面 - // not_adapted_modems_view(); - // return false - // } - - // //设置模式信息 - // set_mode_info(mode_info,debug_params.first_cache); - - // //设置网络偏好信息 - // set_network_prefer_info(network_prefer_info,debug_params.first_cache); - - // //设置模组自检信息 - // set_modem_self_test_info(self_test_info); - - // //设置第一次获取数据标志 - // debug_params.first_cache=false; - - // //显示全功能界面 - // all_function_view(); - // } - // ); - } // 定时触发更新AT串口 @@ -836,7 +806,7 @@ { //缓存当前选择的模组 var modem_select_cache=""; - var debug_params={first_cache:true}; + var debug_params={first_cache:true,view:0}; return function(x, data) { var at_ports=data["at_ports"]; @@ -848,8 +818,7 @@ //获取快捷命令 if (Object.keys(at_ports).length==0) { - //显示无模组界面 - no_modems_view(); + debug_params.view=0; } else { @@ -857,6 +826,15 @@ var modem_select_element = document.getElementById('modem_select'); var select_modem_name = modem_select_element.options[modem_select_element.selectedIndex].text; + if (select_modem_name.includes("ttyUSB")||select_modem_name.includes("at")||select_modem_name.includes("DUN")) + { + debug_params.view=2; + } + else + { + debug_params.view=1; + } + if (select_modem_name != modem_select_cache) { //获取快捷选项 @@ -864,6 +842,7 @@ if (quick_option=="auto") { get_quick_commands(); } + //缓存当前选中的模组 modem_select_cache=select_modem_name; //设置第一次获取数据标志 @@ -873,6 +852,20 @@ //获取模组调试信息 get_modem_debug_info(debug_params); } + + //设置界面 + if (debug_params.view==0) { + //显示无模组界面 + no_modems_view(); + } + else if (debug_params.view==1) { + //显示全功能界面 + all_function_view(); + } + else if (debug_params.view==2) { + //显示未适配模组界面 + not_adapted_modems_view(); + } }; })() ); @@ -913,7 +906,7 @@ display: none; } - /* 终端 */ + /* AT命令响应 */ textarea { background:#373737; border:none; @@ -975,16 +968,16 @@ - + -
+
-
+
@@ -1030,7 +1023,7 @@
-
+ -
+ -
+