diff --git a/README.md b/README.md index 8bf9675..cd2b36d 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ ### 拨号 -- luci-app-modem(暂未完成) +- luci-app-modem(beta) - luci-app-hypermodem(新) - luci-app-usbmodem diff --git a/luci-app-modem/.gitignore b/luci-app-modem/.gitignore new file mode 100644 index 0000000..a06ac7b --- /dev/null +++ b/luci-app-modem/.gitignore @@ -0,0 +1,49 @@ +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/luci-app-modem/luasrc/controller/modem.lua b/luci-app-modem/luasrc/controller/modem.lua index da7a9db..d24a8b3 100644 --- a/luci-app-modem/luasrc/controller/modem.lua +++ b/luci-app-modem/luasrc/controller/modem.lua @@ -1,24 +1,152 @@ -- Copyright 2020 Lienol module("luci.controller.modem", package.seeall) +local http = require "luci.http" +local fs = require "nixio.fs" +local json = require("luci.jsonc") +uci = luci.model.uci.cursor() +local script_path="/usr/share/modem/" function index() if not nixio.fs.access("/etc/config/modem") then return end - entry({"admin", "network", "modem"}, alias("admin", "network", "modem", "index"), translate("Modem"), 100).dependent = true - entry({"admin", "network", "modem", "index"},cbi("modem/index"),translate("Modem Config"),10).leaf = true - entry({"admin", "network", "modem", "at_commands"},template("modem/at_commands"),translate("AT Commands"),20).leaf = true - entry({"admin", "network", "modem", "config"}, cbi("modem/config")).leaf = true - entry({"admin", "network", "modem", "modem_info"}, template("modem/modem_info"), translate("Modem Info"),30).leaf = true - + + entry({"admin", "network", "modem"}, alias("admin", "network", "modem", "modem_info"), translate("Modem"), 100).dependent = true + --模块状态 - entry({"admin", "network", "modem", "get_csq"}, call("action_get_csq")) + entry({"admin", "network", "modem", "modem_info"}, template("modem/modem_info"), translate("Modem Info"),10).leaf = true + entry({"admin", "network", "modem", "get_modem_info"}, call("getModemInfo")) + + --模块设置 + entry({"admin", "network", "modem", "index"},cbi("modem/index"),translate("Modem 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", "status"}, call("act_status")).leaf = true --AT命令 - entry({"admin", "network", "modem", "status"}, call("act_status")).leaf = true - entry({"admin", "network", "modem", "run_at"}, call("at"), nil).leaf = true - entry({"admin", "network", "modem", "user_atc"}, call("useratc"), nil).leaf = true - entry({"admin", "network", "modem", "at_port_select"}, call("modemSelect"), nil).leaf = true + -- local modem_number=uci:get('modem','@global[0]','modem_number') + -- if modem_number ~= "0" or modem_number == nil then + entry({"admin", "network", "modem", "at_commands"},template("modem/at_commands"),translate("AT Commands"),30).leaf = true + -- end + entry({"admin", "network", "modem", "mode_info"}, call("modeInfo"), nil).leaf = true + entry({"admin", "network", "modem", "send_at_command"}, call("sendATCommand"), nil).leaf = true + entry({"admin", "network", "modem", "user_at_command"}, call("userATCommand"), nil).leaf = true + entry({"admin", "network", "modem", "get_at_port"}, call("getATPort"), nil).leaf = true +end + +-- AT命令 +function at(at_port,at_command) + -- local odpall = io.popen("sh modem_at.sh "..at_port.." '"..at_command.."'") + local odpall = io.popen("sms_tool -d " .. at_port .. " at " ..at_command:gsub("[$]", "\\\$"):gsub("\"", "\\\"").." 2>&1") + local odp = odpall:read("*a") + odpall:close() + return odp +end + +-- 获取模组连接状态 +function getModemConnectStatus(at_port) + local at_command="AT+CGDCONT?" + local response=at(at_port,at_command) + + -- 第六个引号的索引 + local sixth_index=1 + for i = 1, 5 do + sixth_index=string.find(response,'"',sixth_index)+1 + 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 +end + +-- 获取模组基本信息 +function getModemBaseInfo(at_port) + local modem_base_info={} + + uci:foreach("modem", "modem-device", function (modem_device) + if at_port == modem_device["at_port"] then + --获取数据接口 + local data_interface=modem_device["data_interface"]:upper() + --获取连接状态 + local connect_status + if modem_device["at_port"] then + connect_status=getModemConnectStatus(modem_device["at_port"]) + end + + --设置值 + modem_base_info=modem_device + modem_base_info["data_interface"]=data_interface + modem_base_info["connect_status"]=connect_status + return true + end + end) + + return modem_base_info +end + +-- 获取模组更多信息 +function getModemMoreInfo(at_port,manufacturer) + local odpall = io.popen("sh "..script_path.."modem_info.sh".." "..at_port.." "..manufacturer) + local opd = odpall:read("*a") + odpall:close() + local modem_more_info=json.parse(opd) + return modem_more_info +end + +-- 模块状态获取 +function getModemInfo() + + --获取AT串口 + local at_port = http.formvalue("port") + + --获取值 + local modem_base_info + local modem_more_info + if at_port then + modem_base_info=getModemBaseInfo(at_port) + modem_more_info=getModemMoreInfo(at_port,modem_base_info["manufacturer"]) + end + + --设置值 + local modem_info={} + modem_info["base_info"]=modem_base_info + modem_info["more_info"]=modem_more_info + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(modem_info) +end + +-- 获取模组信息 +function getModems() + + local modems={} + + -- 获取所有模组 + uci:foreach("modem", "modem-device", function (modem_device) + --获取连接状态 + local connect_status + if modem_device["at_port"] then + connect_status=getModemConnectStatus(modem_device["at_port"]) + end + + --设置值 + local modem=modem_device + modem["connect_status"]=connect_status + modems[modem_device[".name"]]=modem + end) + + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(modems) end -- 模块列表状态函数 @@ -30,185 +158,102 @@ function act_status() luci.http.write_json(e) end --- 模块状态获取 -function action_get_csq() - local file - stat = "/tmp/modem_cell.file" - file = io.open(stat, "r") - local rv ={} +-- 模式信息 +function modeInfo() + -- 设置默认值 + local modes={"qmi","gobinet","ecm","mbim","rndis","ncm"} + -- 获取移动网络 + local network = http.formvalue("network") - -- echo 'RM520N-GL' - -- echo 'manufacturer' - -- echo '1e0e:9001' - -- echo $COPS #运营商 - -- echo '' #端口 - -- echo '' #温度 - -- echo '' #拨号模式 - rv["modem"] = file:read("*line") - rv["manufacturer"] = file:read("*line") - rv["modid"] = file:read("*line") - rv["cops"] = file:read("*line") - rv["port"] = file:read("*line") - rv["tempur"] = file:read("*line") - rv["proto"] = file:read("*line") - rv["mode"] = file:read("*line") - - - -- echo $IMEI #imei - -- echo $IMSI #imsi - -- echo $ICCID #iccid - -- echo $phone #phone - rv["imei"] = file:read("*line") - rv["imsi"] = file:read("*line") - rv["iccid"] =file:read("*line") - rv["phone"] = file:read("*line") - file:read("*line") - - - -- echo $net_type - -- echo $CSQ - -- echo $CSQ_PER - -- echo $CSQ_RSSI - -- echo '' #参考信号接收质量 RSRQ ecio - -- echo '' #参考信号接收质量 RSRQ ecio1 - -- echo '' #参考信号接收功率 RSRP rscp - -- echo '' #参考信号接收功率 RSRP rscp1 - -- echo '' #信噪比 SINR rv["sinr"] - -- echo '' #连接状态监控 rv["netmode"] - rv["net_type"] = file:read("*line") - rv["csq"] = file:read("*line") - rv["per"] = file:read("*line") - rv["rssi"] = file:read("*line") - rv["ecio"] = file:read("*line") - rv["ecio1"] = file:read("*line") - rv["rscp"] = file:read("*line") - rv["rscp1"] = file:read("*line") - rv["sinr"] = file:read("*line") - rv["netmode"] = file:read("*line") - file:read("*line") - - rssi = rv["rssi"] - ecio = rv["ecio"] - rscp = rv["rscp"] - ecio1 = rv["ecio1"] - rscp1 = rv["rscp1"] - if ecio == nil then - ecio = "-" + local modem_number=uci:get('modem','global','modem_number') + for i=0,modem_number-1 do + local modem_network = uci:get('modem','modem'..i,'network') + if network == modem_network then + -- 清空表 + modes={} + -- 把找到的模块存入表中 + local modes_arr = uci:get_list('modem','modem'..i,'modes') + for i in ipairs(modes_arr) do + modes[i]=modes_arr[i] + end + end end - if ecio1 == nil then - ecio1 = "-" - end - if rscp == nil then - rscp = "-" - end - if rscp1 == nil then - rscp1 = "-" - end - - if ecio ~= "-" then - rv["ecio"] = ecio .. " dB" - end - if rscp ~= "-" then - rv["rscp"] = rscp .. " dBm" - end - if ecio1 ~= " " then - rv["ecio1"] = " (" .. ecio1 .. " dB)" - end - if rscp1 ~= " " then - rv["rscp1"] = " (" .. rscp1 .. " dBm)" - end - - rv["mcc"] = file:read("*line") - rv["mnc"] = file:read("*line") - rv["rnc"] = file:read("*line") - rv["rncn"] = file:read("*line") - rv["lac"] = file:read("*line") - rv["lacn"] = file:read("*line") - rv["cid"] = file:read("*line") - rv["cidn"] = file:read("*line") - rv["lband"] = file:read("*line") - rv["channel"] = file:read("*line") - rv["pci"] = file:read("*line") - - rv["date"] = file:read("*line") - - -- rv["phonen"] = file:read("*line") - --rv["host"] = "0" - - -- rv["simerr"] = "0" - - -- rv["down"] = file:read("*line") - -- rv["up"] = file:read("*line") - - -- rv["cell"] = file:read("*line") - -- rv["modtype"] = file:read("*line") - - -- rv["lat"] = "-" - -- rv["long"] = "-" - - rv["crate"] = translate("快速(每10秒更新一次)") + -- 写入Web界面 luci.http.prepare_content("application/json") - luci.http.write_json(rv) + luci.http.write_json(modes) end --- at页面命令函数 -function at() - local devv = tostring(uci:get("modem", "general", "atport")) +-- 发送AT命令 +function sendATCommand() + local at_port = http.formvalue("port") + local at_command = http.formvalue("command") - local at_code = http.formvalue("code") - if at_code then - local odpall = io.popen("sms_tool -d " .. devv .. " at " ..at_code:gsub("[$]", "\\\$"):gsub("\"", "\\\"").." 2>&1") - local odp = odpall:read("*a") - odpall:close() - http.write(tostring(odp)) + local response + if at_port and at_command then + response=at(at_port,at_command) + http.write(tostring(response)) else http.write_json(http.formvalue()) end end --- AT界面模块选择 -function modemSelect() - - local at_ports={} - local at={} - local modem_number=uci:get('modem','global','modem_number') - for i=0,modem_number do - local at_port = uci:get('modem','modem'..i,'at_port') - at_ports[#at_ports+1]=at_port - -- table.insert(at_ports,at_port) +-- 用户AT命令 +function userATCommand() + local at_commands={} + -- 获取模块AT命令 + local command_file + if nixio.fs.access("/etc/config/modem_command.user") then + command_file=io.popen("cat /etc/config/modem_command.user") end - - -- 遍历查找AT串口 - -- uci:foreach("modem", "modem-device", function (modem_device) - -- at_port = modem_device["at_port"] - -- at_ports[#at_ports+1]=at_port - -- end) - luci.http.prepare_content("application/json") - luci.http.write_json(at_ports) -end - --- 用户AT命令读取 -function uat(rv) - local command_file = nixio.fs.access("/etc/config/atcmds.user") and - io.popen("cat /etc/config/atcmds.user") - if command_file then + local i=0 for line in command_file:lines() do - local i = line - if i then - rv[#rv + 1] = { - atu = i - } + if line then + -- 分割为{key,value} + local command_table=string.split(line, ";") + -- 整合为{0:{key:value},1:{key:value}} + local at_command={} + at_command[command_table[1]]=command_table[2] + at_commands[tostring(i)]=at_command + i=i+1 end end command_file:close() end + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(at_commands) end --- 用户AT命令写入函数 -function useratc() - local atu = { } - uat(atu) - luci.http.prepare_content("application/json") - luci.http.write_json(atu) +-- 获取模组的备注 +-- @Param network 移动网络 +function getModemRemarks(network) + local remarks="" + uci:foreach("modem", "config", function (config) + ---配置启用,且备注存在 + if network == config["network"] and config["enable"] == "1" then + if config["remarks"] then + remarks=" ("..config["remarks"]..")" --" (备注)" + return true --跳出循环 + end + end + end) + return remarks +end + +-- 获取AT串口 +function getATPort() + local at_ports={} + uci:foreach("modem", "modem-device", function (modem_device) + --获取模块的备注 + local network=modem_device["network"] + local remarks=getModemRemarks(network) + + local name=modem_device["name"]:upper()..remarks + local at_port = modem_device["at_port"] + at_ports[at_port]=name + end) + -- 写入Web界面 + luci.http.prepare_content("application/json") + luci.http.write_json(at_ports) end diff --git a/luci-app-modem/luasrc/model/cbi/modem/config.lua b/luci-app-modem/luasrc/model/cbi/modem/config.lua index 0bc42b8..5e6783d 100644 --- a/luci-app-modem/luasrc/model/cbi/modem/config.lua +++ b/luci-app-modem/luasrc/model/cbi/modem/config.lua @@ -1,8 +1,9 @@ local d = require "luci.dispatcher" local uci = require "luci.model.uci".cursor() +local http = require "luci.http" m = Map("modem", translate("Modem Config")) -m.redirect = d.build_url("admin", "network", "modem") +m.redirect = d.build_url("admin", "network", "modem","index") s = m:section(NamedSection, arg[1], "config", "") s.addremove = false @@ -17,59 +18,53 @@ enable = s:taboption("general", Flag, "enable", translate("Enable")) enable.default = "0" enable.rmempty = false +-- 配置ID +uci:set('modem',arg[1],'id',arg[1]) + -- 备注 remarks = s:taboption("general", Value, "remarks", translate("Remarks")) remarks.rmempty = true -- 移动网络 --- moblie_net = s:taboption("general", Value, "moblie_net", translate("Moblie Network")) -moblie_net = s:taboption("general", ListValue, "moblie_net", translate("Moblie Network")) --- moblie_net.default = "" -moblie_net.rmempty = false +-- network = s:taboption("general", Value, "network", translate("Moblie Network")) +network = s:taboption("general", ListValue, "network", translate("Moblie Network")) +-- network.default = "" +network.rmempty = false --- 拨号模式 --- mode = s:taboption("general", ListValue, "mode", translate("Mode")) --- mode.rmempty = false - --- 根据调制解调器节点获取模块名 --- function getDeviceName(device_node) --- local deviceName --- uci:foreach("modem", "modem-device", function (modem_device) --- if device_node == modem_device["device_node"] then --- deviceName = modem_device["name"] --- end --- end) --- return string.upper(deviceName) --- end - --- 显示设备通用信息(网络,拨号模式)(有bug) -function devicesGeneralInfo() +-- 获取移动网络,并显示设备名 +function getMoblieNetwork() local modem_number=uci:get('modem','global','modem_number') - for i=0,modem_number do + if modem_number == "0" then + network:value("",translate("Mobile network not found")) + end + + for i=0,modem_number-1 do --获取模块名 - local deviceName = uci:get('modem','modem'..i,'name') - if deviceName == nil then - deviceName = "unknown" + local modem_name = uci:get('modem','modem'..i,'name') + if modem_name == nil then + modem_name = "unknown" end --设置网络 - local net = uci:get('modem','modem'..i,'net') - if net ~= nil then - moblie_net:value(net,net.." ("..translate(deviceName:upper())..")") - - --设置拨号模式 - local mode = s:taboption("general", ListValue, "mode", translate("Mode")) - mode.rmempty = false - - local modes = uci:get_list('modem','modem'..tostring(i),'modes') - for i in ipairs(modes) do - mode:value(modes[i],string.upper(modes[i])) - end - mode:depends("moblie_net", net) + modem_network = uci:get('modem','modem'..i,'network') + if modem_network ~= nil then + network:value(modem_network,modem_network.." ("..translate(modem_name:upper())..")") end end end -devicesGeneralInfo() +getMoblieNetwork() + +-- 拨号模式 +-- mode = s:taboption("general", ListValue, "mode", translate("Mode")) +-- mode.rmempty = false +-- mode.description = translate("Only display the modes available for the adaptation modem") +-- local modes = {"qmi","gobinet","ecm","mbim","rndis","ncm"} +-- for i in ipairs(modes) do +-- mode:value(modes[i],string.upper(modes[i])) +-- end + +-- 添加获取拨号模式信息 +-- m:append(Template("modem/mode_info")) --------advanced-------- diff --git a/luci-app-modem/luasrc/model/cbi/modem/index.lua b/luci-app-modem/luasrc/model/cbi/modem/index.lua index a85a7de..55523fe 100644 --- a/luci-app-modem/luasrc/model/cbi/modem/index.lua +++ b/luci-app-modem/luasrc/model/cbi/modem/index.lua @@ -1,9 +1,9 @@ local d = require "luci.dispatcher" -local e = luci.model.uci.cursor() +local uci = luci.model.uci.cursor() m = Map("modem") m.title = translate("Modem Config") -m.description = translate("Configuration panel for Modem, Add and configure all modules on this page") +m.description = translate("Configuration panel for Modem, Add configuration to all modems on this page") s = m:section(NamedSection, "global", "global") s.anonymous = true @@ -11,23 +11,27 @@ s.addremove = false o = s:option(Flag, "enable", translate("Enable")) o.rmempty = false +o.description = translate("Check to enable all configurations") -s = m:section(TypedSection, "config", translate("Modem List")) +-- 添加模块状态 +m:append(Template("modem/modem_status")) + +s = m:section(TypedSection, "config", translate("Config List")) s.anonymous = true s.addremove = true s.template = "cbi/tblsection" s.extedit = d.build_url("admin", "network", "modem", "config", "%s") -function s.create(e, t) +function s.create(uci, t) local uuid = string.gsub(luci.sys.exec("echo -n $(cat /proc/sys/kernel/random/uuid)"), "-", "") t = uuid - TypedSection.create(e, t) - luci.http.redirect(e.extedit:format(t)) + TypedSection.create(uci, t) + luci.http.redirect(uci.extedit:format(t)) end -function s.remove(e, t) - e.map.proceed = true - e.map:del(t) - luci.http.redirect(d.build_url("admin", "network", "modem")) +function s.remove(uci, t) + uci.map.proceed = true + uci.map:del(t) + luci.http.redirect(d.build_url("admin", "network", "modem","index")) end o = s:option(Flag, "enable", translate("Enable")) @@ -40,24 +44,27 @@ o.rmempty = false o = s:option(DummyValue, "remarks", translate("Remarks")) -o = s:option(DummyValue, "moblie_net", translate("Moblie Network")) +o = s:option(DummyValue, "network", translate("Moblie Network")) o.cfgvalue = function(t, n) - -- 检测移动网络设备是否存在 - local moblie_net = (Value.cfgvalue(t, n) or "") - local odpall = io.popen("ls /sys/class/net/ | grep -w "..moblie_net.." | wc -l") - local odp = odpall:read("*a"):gsub("\n","") + -- 检测移动网络是否存在 + local network = (Value.cfgvalue(t, n) or "") + local odpall = io.popen("ls /sys/class/net/ | grep -w "..network.." | wc -l") + local odp = odpall:read("*a"):gsub("\n","") odpall:close() if odp ~= "0" then - return moblie_net + return network else return "The network device was not found" end end -o = s:option(DummyValue, "mode", translate("Mode")) +o = s:option(DummyValue, "dial_tool", translate("Dial Tool")) o.cfgvalue = function(t, n) - local mode = (Value.cfgvalue(t, n) or ""):upper() - return mode + local dial_tool = (Value.cfgvalue(t, n) or ""):upper() + if dial_tool == "" then + dial_tool=translate("Auto Choose") + end + return dial_tool end o = s:option(DummyValue, "pdp_type", translate("PDP Type")) @@ -66,6 +73,15 @@ o.cfgvalue = function(t, n) return pdp_type end +o = s:option(DummyValue, "apn", translate("APN")) +o.cfgvalue = function(t, n) + local apn = (Value.cfgvalue(t, n) or ""):gsub("_","/"):upper():gsub("V","v") + if apn == "" then + apn=translate("Auto Choose") + end + return apn +end + -- m:append(Template("modem/list_status")) return m diff --git a/luci-app-modem/luasrc/view/modem/at_commands.htm b/luci-app-modem/luasrc/view/modem/at_commands.htm index d7bf1d9..7d4663a 100644 --- a/luci-app-modem/luasrc/view/modem/at_commands.htm +++ b/luci-app-modem/luasrc/view/modem/at_commands.htm @@ -1,38 +1,69 @@ <%+header%> - +<% +local uci = luci.model.uci.cursor() +-- 获取模组的备注 +-- @Param network 移动网络 +function getModemRemarks(network) + local remarks="" + uci:foreach("modem", "config", function (config) + ---配置启用,且备注存在 + if network == config["network"] and config["enable"] == "1" then + if config["remarks"] then + remarks=" ("..config["remarks"]..")" --" (备注)" + return true --跳出循环 + end + end + end) + return remarks +end + +-- 获取AT串口 +function getATPort() + local at_ports={} + uci:foreach("modem", "modem-device", function (modem_device) + --获取模块的备注 + local network=modem_device["network"] + local remarks=getModemRemarks(network) + + local name=modem_device["name"]:upper()..remarks + local at_port = modem_device["at_port"] + at_ports[at_port]=name + end) + return at_ports +end +%>

<%:AT Commands%>

-
<%:Web UI for handling AT commands via sms_tool.%>
+
<%:Debugging Your Module with AT Command%>


<%:Modem Select%>:
-
- +
<%:User AT Commands%>:
-
- +
<%:Command to send%>:
- -
+
@@ -50,71 +81,83 @@ \ No newline at end of file diff --git a/luci-app-modem/luasrc/view/modem/modem_info.htm b/luci-app-modem/luasrc/view/modem/modem_info.htm index 3fb4665..cbc2233 100644 --- a/luci-app-modem/luasrc/view/modem/modem_info.htm +++ b/luci-app-modem/luasrc/view/modem/modem_info.htm @@ -1,6 +1,8 @@ <%+header%> <% local fs = require "nixio.fs" +local uci = luci.model.uci.cursor() + nosms = 1 if not fs.stat("/etc/nosim") then nosms = 0 @@ -9,148 +11,270 @@ havegps = 0 if fs.stat("/etc/havegps") then havegps = 1 end + +-- 获取模组的备注 +-- @Param network 移动网络 +function getModemRemarks(network) + local remarks="" + uci:foreach("modem", "config", function (config) + ---配置启用,且备注存在 + if network == config["network"] and config["enable"] == "1" then + if config["remarks"] then + remarks=" ("..config["remarks"]..")" --" (备注)" + return true --跳出循环 + end + end + end) + return remarks +end + +-- 获取AT串口 +function getATPort() + local at_ports={} + uci:foreach("modem", "modem-device", function (modem_device) + --获取模块的备注 + local network=modem_device["network"] + local remarks=getModemRemarks(network) + + local name=modem_device["name"]:upper()..remarks + local at_port = modem_device["at_port"] + at_ports[at_port]=name + end) + return at_ports +end %> - +//]]> +
-

<%:信号状态/模块信息%>

-
请注意该插件所有功能并无适配所有5G模块,不用妄想冷门模块插上就能用(有能力者自行适配) -
+

<%:Modem Info%>

+
<%:%>
+<% at_ports = getATPort() %> +<% if next(at_ports) == nil then %> -
- <%:综合信息%> - - - - - - -
<%:模块 :%>-
<%:制造商 :%>
<%:温度 : %>
<%:更新时间 : %>
-
+
+

<%:信息%>

+ + + + + + +
<%:No modems found%>
+
+ +<% else %> +
+

<%:基本信息%>

+ + + + + + + + + + +
<%:模组 :%> + +
<%:制造商 :%>
<%:固件版本 :%>
<%:数据接口 : %>
<%:拨号模式 : %>
<%:AT串口 : %>
<%:移动网络 : %>
<%:温度 : %>
<%:更新时间 : %>
+
+ + <% if nosms == 0 then %> + <% end %> + +
+

<%:SIM卡信息%>

+ + + + + + +
<%:运营商 : %>
<%:IMEI :%>
<%:IMSI : %>
<%:ICCID : %>
<%:SIM卡号码 : %>
+
+ +
+

<%:网络信息%>

+ + + + + + + + + + +
<%:网络类型 :%>
<%:CSQ : %>
<%:信号强度 : %>
<%:信号接收强度 RSSI : %>
<%:参考信号接收质量 RSRQ : %>
<%:参考信号接收功率 RSRP : %>
<%:信噪比 SINR : %>
<%:连接状态监控 : %>
+
+ +
+

<%:基站信息%>

+ + + + + + + + + + +
<%:MCC / MNC :%>
<%:eNB ID : %>
<%:TAC : %>
<%:Cell ID : %>
<%:频段 Band : %>
<%:频点 Channel : %>
<%:物理小区标识 PCI : %>
<%:最大Qos级别 Maximum Qos : %>
+
+ + <% if havegps == 1 then %> +
+

<%:GPS 定位%>

+ + + + + + + + + + + +
<%:纬度 :%>
     
    <%:经度 :%>
       
      +
      + <% end %> -<% if nosms == 0 then %> <% end %> -
      - <%:通信模块/SIM卡信息%> - - - - - - -
      <%:运营商 : %>
      <%:IMEI :%>
      <%:IMSI : %>
      <%:ICCID : %>
      <%:SIM卡号码 : %>
      -
      - - -
      - <%:信号状态%> - - - - - - - - - - -
      <%:蜂窝网络类型 :%>
      <%:CSQ : %>
      <%:信号强度 : %>
      <%:信号接收强度 RSSI : %>
      <%:参考信号接收质量 RSRQ : %>
      <%:参考信号接收功率 RSRP : %>
      <%:信噪比 SINR : %>
      <%:连接状态监控 : %>
      -
      - -
      - <%:基站信息%> - - - - - - - - - - -
      <%:MCC / MNC :%>
      <%:eNB ID : %>
      <%:TAC : %>
      <%:Cell ID : %>
      <%:频段 Band : %>
      <%:频点 Channel : %>
      <%:物理小区标识 PCI : %>
      <%:最大Qos级别 Maximum Qos : %>
      -
      - - -<% if havegps == 1 then %> -
      - <%:GPS 定位%> - - - - - - - - - - - -
      <%:纬度 :%>
         
        <%:经度 :%>
           
          -
          -<% end %> - -
          <%+footer%> diff --git a/luci-app-modem/luasrc/view/modem/modem_status.htm b/luci-app-modem/luasrc/view/modem/modem_status.htm new file mode 100644 index 0000000..a1fc965 --- /dev/null +++ b/luci-app-modem/luasrc/view/modem/modem_status.htm @@ -0,0 +1,95 @@ +<%# + Copyright 2014 Aedan Renner + Copyright 2018 Florian Eckert + Licensed to the public under the GNU General Public License v2. +-%> + + + + + +
          + +

          <%:Modem Status%>

          +
          + <%:Loading%> + <%:Loading modem status...%> +
          +
          diff --git a/luci-app-modem/note/OpenWRT软件开发.md b/luci-app-modem/note/OpenWRT软件开发.md deleted file mode 100644 index 6c94dcd..0000000 --- a/luci-app-modem/note/OpenWRT软件开发.md +++ /dev/null @@ -1,135 +0,0 @@ -# OpenWRT软件开发 - -# 一、相关文档 - -UCI系统:https://openwrt.org/docs/guide-user/base-system/uci - -OpenWRT命令解释器:https://openwrt.org/zh/docs/guide-user/base-system/user.beginner.cli - -热插拔:https://openwrt.org/zh/docs/guide-user/base-system/hotplug - -网络基础配置:https://openwrt.org/zh/docs/guide-user/base-system/basic-networking - -Web界面相关 - -- 自定义主题:https://github.com/openwrt/luci/wiki/HowTo:-Create-Themes -- 模块参考:https://github.com/openwrt/luci/wiki/Modules -- 模板参考:https://github.com/openwrt/luci/wiki/Templates -- 实例参考:https://blog.csdn.net/byb123/article/details/77921486/ - -# 二、网络配置 - -在任何网络配置更改(通过uci或其他方式)之后,你需要输入以下内容来重载网络配置: - -```shell -service network reload -``` - -如果您安装的版本没有提供`service`命令,则可以使用: - -```shell -/etc/init.d/network reload -``` - -# 三、拨号程序 - -拨号步骤 - -```shell -run_dial() -{ - local enabled - config_get_bool enabled $1 enabled - - if [ "$enabled" = "1" ]; then - local apn - local user - local password - local auth - local ipv6 - local device - - #获取配置 - config_get apn $1 apn - config_get user $1 user - config_get password $1 password - config_get auth $1 auth - config_get ipv6 $1 ipv6 - config_get device $1 device - - devname="$(basename "$device")" #获取调制解调器,/dev/cdc-wdm0->cdc-wdm0 - devicepath="$(find /sys/class/ -name $devname)" #找到设备快捷路径,/sys/class/net/cdc-wdm0 - devpath="$(readlink -f $devicepath/device/)" #找出连接的物理设备路径,/sys/devices/.../ - ifname="$( ls "$devpath"/net )" #获取设备名,/sys/devices/.../net->cdc-wdm0 - - procd_open_instance #打开一个示例? - procd_set_param command quectel-CM #设置参数? - if [ "$ipv6" = 1 ]; then - procd_append_param command -4 -6 - fi - if [ "$apn" != "" ];then - procd_append_param command -s $apn - fi - if [ "$user" != "" ]; then - procd_append_param command $user - fi - if [ "$password" != "" ]; then - procd_append_param command $password - fi - if [ "$auth" != "" ]; then - procd_append_param command $auth - fi - if [ "$device" != "" ]; then - procd_append_param command -i $ifname - fi - procd_set_param respawn - procd_close_instance - - if [ -d /sys/class/net/rmnet_mhi0 ]; then - pre_set rmnet_mhi0.1 - elif [ -d /sys/class/net/wwan0_1 ]; then - pre_set wwan0_1 - elif [ -d /sys/class/net/wwan0.1 ]; then - pre_set wwan0.1 - elif [ -d /sys/class/net/wwan0 ]; then - pre_set wwan0 - fi - fi - - sleep 15 -} -``` - -# 四、shell - -获取设备物理路径 - -device_bus_path.sh - -```shell -#!/bin/sh - -#获取物理设备地址 -local device_name="$(basename "$1")" -local device_path="$(find /sys/class/ -name $device_name)" -local device_physical_path="$(readlink -f $device_path/device/)" -local device_bus_path=$(dirname "$device_physical_path") -return $device_bus_path -``` - -设置配置 - -setConfig.sh - -```shell -#!/bin/sh - -#处理获取到的路径 -substr="${parentDir/\/sys\/devices\//}" -echo $substr - -#写入到配置中 -uci set modem.modem1.path="$substr" -uci commit modem2 -``` - diff --git a/luci-app-modem/po/zh-cn/modem.po b/luci-app-modem/po/zh-cn/modem.po index f46adcb..f1eff7f 100644 --- a/luci-app-modem/po/zh-cn/modem.po +++ b/luci-app-modem/po/zh-cn/modem.po @@ -7,18 +7,60 @@ msgstr "移动通信模组" msgid "Modem Config" msgstr "模组配置" -msgid "Modem List" -msgstr "模块列表" +msgid "Modem Status" +msgstr "模组状态" -msgid "Configuration panel for Modem, Add and configure all modules on this page" -msgstr "通信模组服务配置界面,在此页面添加和配置所有模块" +msgid "Modem Name" +msgstr "模组名称" + +msgid "Modem Select" +msgstr "选择模组" + +msgid "Check information about adapted modem on this page" +msgstr "在此页面查看已适配模组的信息" + +msgid "Loading modem status..." +msgstr "正在加载模组状态" + +msgid "Connect" +msgstr "已连接" + +msgid "Disconnect" +msgstr "未连接" + +msgid "Disabled" +msgstr "未启用" + +msgid "Data Interface" +msgstr "数据接口" + +msgid "Mode" +msgstr "模式" + +msgid "Connect Status" +msgstr "连接状态" + +msgid "Config List" +msgstr "配置列表" + +msgid "Configuration panel for Modem, Add configuration to all modems on this page" +msgstr "通信模组服务配置界面,在此页面给所有模组添加配置" msgid "AT Commands" msgstr "AT命令" +msgid "Debugging Your Module with AT Command" +msgstr "使用AT命令调试你的模组" + msgid "Modem Info" msgstr "模组信息" +msgid "No modems found" +msgstr "没有找到模组" + +msgid "Check to enable all configurations" +msgstr "勾选启用全部配置" + msgid "General Settings" msgstr "通用配置" @@ -34,11 +76,14 @@ msgstr "移动网络" msgid "UNKNOWN" msgstr "未知" -msgid "The network device was not found" -msgstr "移动网络" +msgid "Mobile network not found" +msgstr "未发现移动网络" -msgid "Mode" -msgstr "模式" +msgid "The network device was not found" +msgstr "找不到网络设备" + +msgid "Only display the modes available for the adaptation modem" +msgstr "仅显示适配模组可用的拨号模式" msgid "Dial Tool" msgstr "拨号工具" diff --git a/luci-app-modem/root/etc/config/modem b/luci-app-modem/root/etc/config/modem index 04e4f87..05474a3 100644 --- a/luci-app-modem/root/etc/config/modem +++ b/luci-app-modem/root/etc/config/modem @@ -1,3 +1,4 @@ config global 'global' - option enable '0' + option enable '1' + option modem_number '0' diff --git a/luci-app-modem/root/etc/config/modem_command.user b/luci-app-modem/root/etc/config/modem_command.user new file mode 100644 index 0000000..448379f --- /dev/null +++ b/luci-app-modem/root/etc/config/modem_command.user @@ -0,0 +1,51 @@ +****************通用****************;ATI +模组信息 > ATI;ATI +查询SIM卡状态 > AT+CPIN?;AT+CPIN? +查询此时信号强度 > AT+CSQ;AT+CSQ +查询网络信息 > AT+COPS?;AT+COPS? +查询PDP信息 > AT+CGDCONT?;AT+CGDCONT? +最小功能模式 > AT+CFUN=0;AT+CFUN=0 +全功能模式 > AT+CFUN=1;AT+CFUN=1 +****************移远****************;ATI +SIM卡状态上报 > AT+QSIMSTAT?;AT+QSIMSTAT? +设置当前使用的为卡1 > AT+QUIMSLOT=1;AT+QUIMSLOT=1 +设置当前使用的为卡2 > AT+QUIMSLOT=2;AT+QUIMSLOT=2 +查询网络信息 > AT+QNWINFO;AT+QNWINFO +查询载波聚合参数 > AT+QCAINFO;AT+QCAINFO +查询当前拨号模式 > AT+QCFG="usbnet";AT+QCFG="usbnet" +QMI/GobiNet拨号 > AT+QCFG="usbnet",0;AT+QCFG="usbnet",0 +ECM拨号 > AT+QCFG="usbnet",1;AT+QCFG="usbnet",1 +MBIM拨号 > AT+QCFG="usbnet",2;AT+QCFG="usbnet",2 +RNDIS拨号 > AT+QCFG="usbnet",3;AT+QCFG="usbnet",3 +NCM拨号 > AT+QCFG="usbnet",5;AT+QCFG="usbnet",5 +锁4G > AT+QNWPREFCFG="mode_pref",LTE;AT+QNWPREFCFG="mode_pref",LTE +锁5G > AT+QNWPREFCFG="mode_pref",NR5G;AT+QNWPREFCFG="mode_pref",NR5G +恢复自动搜索网络 > AT+QNWPREFCFG="mode_pref",AUTO;AT+QNWPREFCFG="mode_pref",AUTO +查询模组IMEI > AT+CGSN;AT+CGSN +查询模组IMEI > AT+GSN;AT+GSN +更改模组IMEI > AT+EGMR=1,7,"IMEI";AT+EGMR=1,7,"在此设置IMEI" +获取模组温度 > AT+QTEMP;AT+QTEMP +切换为USB通信端口 > AT+QCFG="data_interface",0,0;AT+QCFG="data_interface",0,0 +切换为PCIE通信端口 > AT+QCFG="data_interface",1,0;AT+QCFG="data_interface",1,0 +重置模组 > AT+CFUN=1,1;AT+CFUN=1,1 +****************广和通****************;ATI +设置当前使用的为卡1 > AT+GTDUALSIM=0;AT+GTDUALSIM=0 +设置当前使用的为卡2 > AT+GTDUALSIM=1;AT+GTDUALSIM=1 +ECM手动拨号 > AT+GTRNDIS=1,1;AT+GTRNDIS=1,1 +ECM拨号断开 > AT+GTRNDIS=0,1;AT+GTRNDIS=0,1 +查询当前端口模式 > AT+GTUSBMODE?;AT+GTUSBMODE? +QMI/GobiNet拨号 > AT+GTUSBMODE=32;AT+GTUSBMODE=32 +ECM拨号 > AT+GTUSBMODE=18;AT+GTUSBMODE=18 +MBIM拨号 > AT+GTUSBMODE=30;AT+GTUSBMODE=30 +RNDIS拨号 > AT+GTUSBMODE=24;AT+GTUSBMODE=24 +NCM拨号 > AT+GTUSBMODE=18;AT+GTUSBMODE=18 +锁4G > AT+GTACT=2;AT+GTACT=2 +锁5G > AT+GTACT=14;AT+GTACT=14 +恢复自动搜索网络 > AT+GTACT=20;AT+GTACT=20 +查询当前连接的网络类型 > AT+PSRAT?;AT+PSRAT? +查询模组IMEI > AT+CGSN?;AT+CGSN? +查询模组IMEI > AT+GSN?;AT+GSN? +更改模组IMEI > AT+GTSN=1,7,"IMEI";AT+GTSN=1,7,"在此设置IMEI" +报告一次当前BBIC的温度 > AT+MTSM=1,6;AT+MTSM=1,6 +报告一次当前射频的温度 > AT+MTSM=1,7;AT+MTSM=1,7 +重置模组 > AT+CFUN=15;AT+CFUN=15 \ No newline at end of file diff --git a/luci-app-modem/root/etc/init.d/modem b/luci-app-modem/root/etc/init.d/modem index f7e1eea..45db0bd 100644 --- a/luci-app-modem/root/etc/init.d/modem +++ b/luci-app-modem/root/etc/init.d/modem @@ -1,88 +1,93 @@ #!/bin/sh /etc/rc.common # Copyright (C) 2006-2014 OpenWrt.org -START=94 +START=21 STOP=13 USE_PROCD=1 #设置拨号模式 # $1:拨号模式 -set_mode() -{ - #获取AT串口、制造商、模块名 - local at_port=$(uci -q get modem.modem$modem_no.at_port) - local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) - local name=$(uci -q get modem.modem$modem_no.name) +# set_mode() +# { +# #获取AT串口、制造商、模块名 +# local at_port=$(uci -q get modem.modem$modem_no.at_port) +# local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) +# local name=$(uci -q get modem.modem$modem_no.name) - #分制造商设置不同的AT命令 - local command - if [ "$manufacturer" = "quectel" ]; then - local mode_num - case $1 in - "qmi") mode_num='0' ;; - "gobinet") mode_num='0' ;; - "ecm") mode_num='1' ;; - "mbim") mode_num='2' ;; - "rndis") mode_num='3' ;; - "ncm") mode_num='5' ;; - "*") mode_num='0' ;; - esac +# #分制造商设置不同的AT命令 +# local command +# if [ "$manufacturer" = "quectel" ]; then +# local mode_num +# case $1 in +# "qmi") mode_num='0' ;; +# "gobinet") mode_num='0' ;; +# "ecm") mode_num='1' ;; +# "mbim") mode_num='2' ;; +# "rndis") mode_num='3' ;; +# "ncm") mode_num='5' ;; +# "*") mode_num='0' ;; +# esac - #查询当前拨号模式 - command='AT+QCFG="usbnet"' - local at_result=$(sh /usr/share/modem/modem_at.sh $at_port $command) - if [[ "$at_result" != *"$mode_num"* ]]; then - #切换到指定的拨号模式 - case $1 in - "qmi") command='AT+QCFG="usbnet",0' ;; - "gobinet") command='AT+QCFG="usbnet",0' ;; - "ecm") command='AT+QCFG="usbnet",1' ;; - "mbim") command='AT+QCFG="usbnet",2' ;; - "rndis") command='AT+QCFG="usbnet",3' ;; - "ncm") command='AT+QCFG="usbnet",5' ;; - "*") command='AT+QCFG="usbnet",0' ;; - esac - sh /usr/share/modem/modem_at.sh $at_port $command - #移远切换模式后,还需要重启模块,待测试 - fi - elif [ "$manufacturer" = "fibocom" ]; then - if [ "$name" = "fm150-ae" ]; then - local mode_num - case $1 in - "qmi") mode_num='32' ;; - "gobinet") mode_num='32' ;; - "ecm") mode_num='23' ;; - "mbim") mode_num='29' ;; - "rndis") mode_num='24' ;; - "ncm") mode_num='23' ;; - "*") mode_num='32' ;; - esac +# #查询当前拨号模式 +# command='AT+QCFG="usbnet"' +# local at_result=$(sh /usr/share/modem/modem_at.sh $at_port $command) +# if [[ "$at_result" != *"$mode_num"* ]]; then + +# #切换到指定的拨号模式 +# case $1 in +# "qmi") command='AT+QCFG="usbnet",0' ;; +# "gobinet") command='AT+QCFG="usbnet",0' ;; +# "ecm") command='AT+QCFG="usbnet",1' ;; +# "mbim") command='AT+QCFG="usbnet",2' ;; +# "rndis") command='AT+QCFG="usbnet",3' ;; +# "ncm") command='AT+QCFG="usbnet",5' ;; +# "*") command='AT+QCFG="usbnet",0' ;; +# esac +# at_result=$(sh /usr/share/modem/modem_at.sh "$at_port" "$command") +# #移远切换模式后,还需要重启模块,待测试 +# sleep 5 +# modem_scan +# fi +# elif [ "$manufacturer" = "fibocom" ]; then +# if [ "$name" = "fm150-ae" ]; then +# local mode_num +# case $1 in +# "qmi") mode_num='32' ;; +# "gobinet") mode_num='32' ;; +# "ecm") mode_num='23' ;; +# "mbim") mode_num='29' ;; +# "rndis") mode_num='24' ;; +# "ncm") mode_num='23' ;; +# "*") mode_num='32' ;; +# esac - #查询当前拨号模式 - command='AT+GTUSBMODE?' - local at_result=$(sh /usr/share/modem/modem_at.sh $at_port $command) - if [[ "$at_result" != *"$mode_num"* ]]; then - #切换到指定的拨号模式 - case $1 in - "qmi") command='AT+GTUSBMODE=32' ;; - "gobinet") command='AT+GTUSBMODE=32' ;; - "ecm") command='AT+GTUSBMODE=23' ;; - "mbim") command='AT+GTUSBMODE=29' ;; - "rndis") command='AT+GTUSBMODE=24' ;; - "ncm") command='AT+GTUSBMODE=23' ;; - "*") command='AT+GTUSBMODE=32' ;; - esac - sh /usr/share/modem/modem_at.sh $at_port $command - fi - elif [ "$name" = "fm650" ]; then - #待处理 - echo "fm650" - fi - else - #没有匹配到制造商,需要手动切换模块的拨号模式 - echo "请手动切换模块的拨号模式" - fi -} +# #查询当前拨号模式 +# command='AT+GTUSBMODE?' +# local at_result=$(sh /usr/share/modem/modem_at.sh $at_port $command) +# if [[ "$at_result" != *"$mode_num"* ]]; then +# #切换到指定的拨号模式 +# case $1 in +# "qmi") command='AT+GTUSBMODE=32' ;; +# "gobinet") command='AT+GTUSBMODE=32' ;; +# "ecm") command='AT+GTUSBMODE=23' ;; +# "mbim") command='AT+GTUSBMODE=29' ;; +# "rndis") command='AT+GTUSBMODE=24' ;; +# "ncm") command='AT+GTUSBMODE=23' ;; +# "*") command='AT+GTUSBMODE=32' ;; +# esac +# at_result=$(sh /usr/share/modem/modem_at.sh "$at_port" "$command") +# sleep 5 +# modem_scan +# fi +# elif [ "$name" = "fm650" ]; then +# #待处理 +# echo "fm650" +# fi +# else +# #没有匹配到制造商,需要手动切换模块的拨号模式 +# echo "请手动切换模块的拨号模式" +# fi +# } #设置防火墙 set_firewall() @@ -100,10 +105,12 @@ set_firewall() # $2:网络接口 set_ipv4_interface() { - [ "$(uci -q get network.$1.ifname)" != "$2" ] && { + #配置中不存在这个网络接口配置,或这个网络接口配置的设备不同 + [ "$(uci -q get network.$1.device)" != "$2" ] && { uci set network.$1='interface' - uci set network.$1.ifname="$2" uci set network.$1.proto='dhcp' + uci set network.$1.device="$2" + uci set network.$1.ifname="$2" uci commit network #加入WAN防火墙 @@ -119,11 +126,12 @@ set_ipv4_interface() # $2:网络接口 set_ipv6_interface() { - if [ "$(uci -q get network.$1.ifname)" != "$2" ]; then + if [ "$(uci -q get network.$1.device)" != "$2" ]; then uci set network.$1='interface' - uci set network.$1.ifname="$2" uci set network.$1.proto='dhcpv6' uci set network.$1.extendprefix='1' + uci set network.$1.device="$2" + uci set network.$1.ifname="$2" uci commit network #加入WAN防火墙 @@ -146,24 +154,21 @@ set_interface() "ipv4") set_ipv4_interface wwan_5g_$1 $2 ;; "ipv6") set_ipv6_interface wwan6_5g_$1 $2 ;; "ipv4_ipv6") - set_ipv4_interface wwan_5g_$1 $2 - set_ipv6_interface wwan6_5g_$1 $2 + set_ipv4_interface "wwan_5g_$1" $2 + set_ipv6_interface "wwan6_5g_$1" $2 ;; "*") - set_ipv4_interface wwan_5g_$1 $2 - set_ipv6_interface wwan6_5g_$1 $2 + set_ipv4_interface "wwan_5g_$1" $2 + set_ipv6_interface "wwan6_5g_$1" $2 ;; esac } qmi() { - #设置拨号模式 - set_mode qmi - #设置网络接口 - local net_interface=$(uci -q get modem.modem$modem_no.net_interface) - set_interface $modem_no $net_interface + local network_interface=$(uci -q get modem.modem$modem_no.network_interface) + set_interface $modem_no $network_interface #拨号 procd_open_instance @@ -195,8 +200,8 @@ qmi() if [ "$auth" != "" ]; then procd_append_param command $auth fi - if [ "$moblie_net" != "" ]; then - procd_append_param command -i $moblie_net + if [ "$network" != "" ]; then + procd_append_param command -i $network fi procd_set_param respawn procd_set_param procd_pid /var/run/modem/modem$modem_no.pid @@ -205,29 +210,32 @@ qmi() gobinet() { - qmi + #获取网络接口、AT串口、制造商 + local network_interface=$(uci -q get modem.modem$modem_no.network_interface) + local at_port=$(uci -q get modem.modem$modem_no.at_port) + local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) + #设置网络接口 + set_interface $modem_no $network_interface + + #拨号 + procd_open_instance + procd_set_param command sh /usr/share/modem/modem_usb_network.sh $id $at_port $manufacturer "gobinet" + procd_set_param respawn + procd_close_instance } ecm() { - #设置拨号模式 - set_mode ecm - #获取网络接口、AT串口、制造商 - local net_interface=$(uci -q get modem.modem$modem_no.net_interface) + local network_interface=$(uci -q get modem.modem$modem_no.network_interface) local at_port=$(uci -q get modem.modem$modem_no.at_port) local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) #设置网络接口 - set_interface $modem_no $net_interface + set_interface $modem_no $network_interface #拨号 procd_open_instance - procd_set_param command sh /usr/share/modem/modem_at.sh $at_port - if [ "$manufacturer" = "quectel" ]; then - procd_append_param command 'ATI' - elif [ "$manufacturer" = "fibocom" ]; then - procd_append_param command 'AT+GTRNDIS=1,1' - fi + procd_set_param command sh /usr/share/modem/modem_usb_network.sh $id $at_port $manufacturer "ecm" procd_set_param respawn procd_close_instance } @@ -248,30 +256,166 @@ ncm() ecm } -#实例运行状态 -instance_status() +stop_qmi() { #获取modem的实例信息 local response=$(ubus call service list '{"name": "modem"}') local instance_number=$(echo "$response" | jq -r '.modem.instances | length') for i in $(seq 1 $((instance_number))); do - #获取运行状态和拨号命令 - local running_status=$(echo "$response" | jq -r '.modem.instances.$i.running') + #获取拨号命令 local command=$(echo "$response" | jq -r '.modem.instances.instance$i.command') - if [ "$running_status" = "$true" ] && [[ "$command" = *"$moblie_net"* ]]; then - return 1 + if [ "$command" = *"$network"* ]; then + local pid=$(echo "$response" | jq -r '.modem.instances.$i.pid') + kill $pid >/dev/null 2>&1 fi done } +stop_gobinet() +{ + #获取AT串口、制造商 + local at_port=$(uci -q get modem.modem$modem_no.at_port) + local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) + + #停止拨号 + local command="sh /usr/share/modem/modem_at.sh $at_port" + if [ "$manufacturer" = "quectel" ]; then + $command 'ATI' + elif [ "$manufacturer" = "fibocom" ]; then + $command 'AT$QCRMCALL=0,1' + else + $command 'ATI' + fi +} + +stop_ecm() +{ + #获取AT串口、制造商 + local at_port=$(uci -q get modem.modem$modem_no.at_port) + local manufacturer=$(uci -q get modem.modem$modem_no.manufacturer) + + #停止拨号 + local command="sh /usr/share/modem/modem_at.sh $at_port" + if [ "$manufacturer" = "quectel" ]; then + $command 'ATI' + elif [ "$manufacturer" = "fibocom" ]; then + $command 'AT+GTRNDIS=0,1' + else + $command 'ATI' + fi +} + +stop_mbim() +{ + stop_qmi +} + +stop_rndis() +{ + stop_ecm + #广和通的rndis和ecm不同,后续再测试 +} + +stop_ncm() +{ + stop_ecm +} + +#获取模块序号 +# $1:移动网络 +get_modem_no() +{ + local modem_number=$(uci -q get modem.@global[0].modem_number) + echo "modem_number:$modem_number" >> /root/a + local modem_network + for i in $(seq 0 $((modem_number-1))); do + modem_network=$(uci -q get modem.modem$i.network) + if [ "$modem_network" = "$1" ]; then + #模块序号 + modem_no=$i + break + fi + done + echo "modem_no:$modem_no" >> /root/a +} + +#获取实例运行状态(未使用) +# $1:配置ID +get_instance_status() +{ + #获取modem的实例信息 + local response=$(ubus call service list '{"name": "modem"}') + local instance_number=$(echo "$response" | jq -r ".modem.instances | length") + for i in $(seq 1 $((instance_number))); do + #获取运行状态和拨号命令 + local running_status=$(echo "$response" | jq -r ".modem.instances.instance$i.running") + local command=$(echo "$response" | jq -r ".modem.instances.instance$i.command") + if [ "$running_status" = "true" ] && [[ "$command" = *"$network"* ]]; then + #查看配置ID是否记录在已运行的文件里 + local run_config="/tmp/modem/run_config" + local run_config_id=$(grep -n "$network" "$run_config" | cut -d ';' -f 2) + if [ "$1" = "$run_config_id" ]; then + status=2 + break + else + status=1 + break + fi + fi + done +} + +#停止拨号 +# $1:配置ID +stop_dial() +{ + local id="$1" #配置ID + local network=$(uci -q get modem.$1.network) #移动网络 + + #把配置ID从临时列表中移除 + local run_config="/tmp/modem/run_config" + local row_no=$(grep -n "$id" "$run_config" | cut -d ':' -f 1) + if [ -z "$row_no" ]; then + return 0 + fi + #该配置ID在运行,需要删除记录 + sed -i "$row_no"d $run_config + + #获取模块序号 + get_modem_no $network + #获取模组的拨号模式 + local mode=$(uci -q get modem.modem$modem_no.mode) + + #根据不同的拨号模式停止拨号 + if [ "$mode" = "qmi" ]; then + stop_qmi + elif [ "$mode" = "gobinet" ]; then + stop_gobinet + elif [ "$mode" = "ecm" ]; then + stop_ecm + elif [ "$mode" = "mbim" ]; then + stop_mbim + elif [ "$mode" = "rndis" ]; then + stop_rndis + elif [ "$mode" = "ncm" ]; then + stop_ncm + fi +} + dial() { + local enable #启用 + local id #ID + config_get enable $1 enable - [ "$enable" = "0" ] && return 0 + config_get id $1 id + [ "$enable" = "0" ] && { + stop_dial "$id" + return 0 + } local remarks #备注 - local moblie_net #移动网络 - local mode #拨号模式 + local network #移动网络 local dial_tool #拨号工具 local pdp_type #网络类型 local apn @@ -280,8 +424,7 @@ dial() local auth config_get remarks $1 remarks - config_get moblie_net $1 moblie_net - config_get mode $1 mode + config_get network $1 network config_get dial_tool $1 dial_tool config_get pdp_type $1 pdp_type config_get apn $1 apn @@ -289,25 +432,34 @@ dial() config_get password $1 password config_get auth $1 auth - #查看移动网络是否已经有实例在运行 - instance_status - [ $? = "1" ] && return 0 - #获取模块序号 - local modem_number=$(uci -q get modem.@global[0].option.modem_number) - for i in $(seq 0 $((modem_number-1))); do - local net=$(uci -q get modem.modem$i.net) - if [ "$net" = "$moblie_net" ]; then - #模块序号 - modem_no=$i + get_modem_no $network + #获取模组的拨号模式 + [ -z "$modem_no" ] && return 0 + local mode=$(uci -q get modem.modem$modem_no.mode) + + #查看移动网络是否已经有配置在运行 + local run_path="/tmp/modem" + mkdir -p $run_path + local run_config="/tmp/modem/run_config" + local row_no=$(grep -n "$network" "$run_config" | cut -d ':' -f 1) #1:wwan0;abc->1 + if [ -z "$row_no" ]; then #未记录该移动网络 + #把已运行的配置ID加入到记录中 + echo "$network;$id" >> "$run_path/run_config" + else + local run_config_id=$(grep -n "$network" "$run_config" | cut -d ';' -f 2) + if [ "$id" != "$run_config_id" ]; then #该移动网络已存在,且已有其他配置运行 + uci set modem.$1.enable=0 + uci commit modem + return 0 fi - done + fi #根据不同的拨号模式拨号 if [ "$mode" = "qmi" ]; then qmi elif [ "$mode" = "gobinet" ]; then - gobinet #暂无,同qmi + gobinet elif [ "$mode" = "ecm" ]; then ecm elif [ "$mode" = "mbim" ]; then @@ -321,40 +473,14 @@ dial() # sleep 15 } -stop_dial() -{ - #停止所有拨号 - config_get enable $1 enable - [ "$enable" = "0" ] && { - killall quectel-CM >/dev/null 2>&1 - return 0 - } - - #停止单个拨号 - local moblie_net #移动网络 - config_get moblie_net $1 moblie_net - - #获取modem的实例信息 - local response=$(ubus call service list '{"name": "modem"}') - local instance_number=$(echo "$response" | jq -r '.modem.instances | length') - for i in $(seq 1 $((instance_number))); do - #获取拨号命令 - local command=$(echo "$response" | jq -r '.modem.instances.instance$i.command') - if [ "$command" = *"$moblie_net"* ]; then - local pid=$(echo "$response" | jq -r '.modem.instances.$i.pid') - kill $pid >/dev/null 2>&1 - fi - done -} - service_triggers() { procd_add_reload_trigger "modem" } start_service() { - enable=$(uci -q get modem.@global[0].enable) - if [ "$enable" = "0" ];then + local enable=$(uci -q get modem.@global[0].enable) + if [ "$enable" = "0" ]; then stop_service else config_load modem @@ -364,6 +490,14 @@ start_service() { stop_service() { - config_load modem - config_foreach stop_dial "config" + #删除记录文件 + rm -rf /tmp/modem + #停止qmi、mbim拨号 + killall quectel-CM >/dev/null 2>&1 + #停止ecm、rndis、ncm拨号 + local modem_number=$(uci -q get modem.@global[0].modem_number) + for i in $(seq 0 $((modem_number-1))); do + modem_no=$i + stop_ecm + done } diff --git a/luci-app-modem/root/etc/init.d/modeminit b/luci-app-modem/root/etc/init.d/modeminit index 38c3b65..bd5783a 100644 --- a/luci-app-modem/root/etc/init.d/modeminit +++ b/luci-app-modem/root/etc/init.d/modeminit @@ -1,8 +1,12 @@ #!/bin/sh /etc/rc.common -START=99 +START=16 +STOP=13 +USE_PROCD=1 -start() { - # /bin/sh /usr/share/cpe/rssi & - /bin/sh /usr/share/modem/modem_data & +start_service() { + procd_open_instance #启动实例 + procd_set_param command /bin/sh /usr/share/modem/modem_task.sh + procd_set_param respawn # 定义respawn参数,告知procd当task程序退出后尝试进行重启 + procd_close_instance #关闭实例 } \ No newline at end of file diff --git a/luci-app-modem/root/etc/uci-defaults/luci-app-modem b/luci-app-modem/root/etc/uci-defaults/luci-app-modem index 0e40535..4893d28 100644 --- a/luci-app-modem/root/etc/uci-defaults/luci-app-modem +++ b/luci-app-modem/root/etc/uci-defaults/luci-app-modem @@ -3,9 +3,11 @@ uci -q get modem.global >/dev/null || uci -q batch <<-EOF >/dev/null set modem.global=global set modem.global.enable=1 + set modem.global.modem_number=0 commit modem EOF +/etc/init.d/modeminit enable /etc/init.d/modem enable uci -q batch <<-EOF >/dev/null diff --git a/luci-app-modem/root/usr/share/modem/fibocom.sh b/luci-app-modem/root/usr/share/modem/fibocom.sh index bc0d288..0c55c8e 100644 --- a/luci-app-modem/root/usr/share/modem/fibocom.sh +++ b/luci-app-modem/root/usr/share/modem/fibocom.sh @@ -1,21 +1,123 @@ #!/bin/sh +current_dir="$(dirname "$0")" + +#获取拨号模式 +# $1:AT串口 +get_fibocom_mode() +{ + local at_port="$1" + local at_command="AT+GTUSBMODE?" + local mode_num=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/+GTUSBMODE: //g' | sed 's/\r//g') + + local mode + case "$mode_num" in + "17") mode="qmi" ;; #- + "31") mode="qmi" ;; #- + "32") mode="qmi" ;; + "32") mode="gobinet" ;; + "18") mode="ecm" ;; + "23") mode="ecm" ;; #- + "33") mode="ecm" ;; #- + "29") mode="mbim" ;; #- + "30") mode="mbim" ;; + "24") mode="rndis" ;; + "18") mode='ncm' ;; + "*") mode="$mode_num" ;; + esac + echo "$mode" +} + + +#基本信息 +fibocom_base_info() +{ + debug "Fibocom base info" + + local at_command="ATI" + local response=$(sh $current_dir/modem_at.sh $at_port $at_command) + + #名称 + name=$(echo "$response" | sed -n '3p' | sed 's/Model: //g' | sed 's/\r//g') + #制造商 + manufacturer=$(echo "$response" | sed -n '2p' | sed 's/Manufacturer: //g' | sed 's/\r//g') + #固件版本 + revision=$(echo "$response" | sed -n '4p' | sed 's/Revision: //g' | sed 's/\r//g') + + #拨号模式 + mode=$(get_fibocom_mode $at_port | tr 'a-z' 'A-Z') + + #温度 + at_command="AT+MTSM=1,6" + response=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/+MTSM: //g' | sed 's/\r//g') + if [ -n "$response" ]; then + temperature="$response$(printf "\xc2\xb0")C" + fi +} + +#SIM卡信息 +fibocom_sim_info() +{ + debug "Fibocom sim info" + + #ISP(互联网服务提供商) + local at_command="AT+COPS?" + isp=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') + if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then + isp="中国移动" + elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then + isp="中国联通" + elif [ "$isp" = "CHN-CT" ] || [ "$isp" = "CT" ] || [ "$isp" = "46011" ]; then + isp="中国电信" + fi + + #IMEI + at_command="AT+CGSN" + imei=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') + + #IMSI + at_command="AT+CIMI" + imsi=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') + + #ICCID + at_command="AT+ICCID" + iccid=$(sh $current_dir/modem_at.sh $at_port $at_command | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") + + #SIM卡号码(手机号) + at_command="AT+CNUM?" + phone=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') +} + +#网络信息 +fibocom_net_info() +{ + debug "Fibocom net info" + + #Network Type(网络类型) + local at_command="AT+PSRAT?" + net_type=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/+PSRAT: //g' | sed 's/\r//g') + + #CSQ + + #per(信号强度) + +} # fibocom获取基站信息 Fibocom_Cellinfo() { #baseinfo.gcom - OX=$( sh modem_at.sh $at_port "ATI") - OX=$( sh modem_at.sh $at_port "AT+CGEQNEG=1") + OX=$( sh $current_dir/modem_at.sh $at_port "ATI") + OX=$( sh $current_dir/modem_at.sh $at_port "AT+CGEQNEG=1") #cellinfo0.gcom - OX1=$( sh modem_at.sh $at_port "AT+COPS=3,0;+COPS?") - OX2=$( sh modem_at.sh $at_port "AT+COPS=3,2;+COPS?") + # OX1=$( sh $current_dir/modem_at.sh $at_port "AT+COPS=3,0;+COPS?") + # OX2=$( sh $current_dir/modem_at.sh $at_port "AT+COPS=3,2;+COPS?") OX=$OX1" "$OX2 #cellinfo.gcom - OY1=$( sh modem_at.sh $at_port "AT+CREG=2;+CREG?;+CREG=0") - OY2=$( sh modem_at.sh $at_port "AT+CEREG=2;+CEREG?;+CEREG=0") - OY3=$( sh modem_at.sh $at_port "AT+C5GREG=2;+C5GREG?;+C5GREG=0") + OY1=$( sh $current_dir/modem_at.sh $at_port "AT+CREG=2;+CREG?;+CREG=0") + OY2=$( sh $current_dir/modem_at.sh $at_port "AT+CEREG=2;+CEREG?;+CEREG=0") + OY3=$( sh $current_dir/modem_at.sh $at_port "AT+C5GREG=2;+C5GREG?;+C5GREG=0") OY=$OY1" "$OY2" "$OY3 @@ -131,42 +233,26 @@ Fibocom_Cellinfo() fi } -Fibocom_SIMINFO() -{ - debug "Fibocom_SIMINFO" - - # 获取IMEI - IMEI=$( sh modem_at.sh $at_port "AT+CGSN" | sed -n '2p' ) - # 获取IMSI - IMSI=$( sh modem_at.sh $at_port "AT+CIMI" | sed -n '2p' ) - # 获取ICCID - ICCID=$( sh modem_at.sh $at_port "AT+ICCID" | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}" ) - # 获取电话号码 - phone=$( sh modem_at.sh $at_port "AT+CNUM" | grep "+CNUM:" ) -} - -#fibocom查找基站AT +#获取Fibocom模块信息 # $1:AT串口 -get_fibocom_data() +get_fibocom_info() { - debug "get fibocom data" + debug "get fibocom info" #设置AT串口 at_port=$1 - # All_CSQ - - Fibocom_SIMINFO - Fibocom_Cellinfo + #基本信息 + fibocom_base_info + #SIM卡信息 + fibocom_sim_info + #网络信息 + fibocom_net_info + + # All_CSQ + # Fibocom_Cellinfo - #温度 - OX=$( sh modem_at.sh $at_port "AT+CPMUTEMP") - TEMP=$(echo "$OX" | grep -o "+CPMUTEMP:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") - if [ -n "$TEMP" ]; then - TEMP=$(echo $TEMP)$(printf "\xc2\xb0")"C" - fi - #基站信息 - OX=$( sh modem_at.sh $at_port "AT+CPSI?") + OX=$( sh $current_dir/modem_at.sh $at_port "AT+CPSI?") rec=$(echo "$OX" | grep "+CPSI:") w=$(echo $rec |grep "NO SERVICE"| wc -l) if [ $w -ge 1 ];then @@ -244,7 +330,7 @@ get_fibocom_data() fi #CNMP - OX=$( sh modem_at.sh $at_port "AT+CNMP?") + OX=$( sh $current_dir/modem_at.sh $at_port "AT+CNMP?") CNMP=$(echo "$OX" | grep -o "+CNMP:[ ]*[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}") if [ -n "$CNMP" ]; then case $CNMP in @@ -266,7 +352,7 @@ get_fibocom_data() fi # CMGRMI 信息 - OX=$( sh modem_at.sh $at_port "AT+CMGRMI=4") + OX=$( sh $current_dir/modem_at.sh $at_port "AT+CMGRMI=4") CAINFO=$(echo "$OX" | grep -o "$REGXz" | tr ' ' ':') if [ -n "$CAINFO" ]; then for CASV in $(echo "$CAINFO"); do diff --git a/luci-app-modem/root/usr/share/modem/fibocom_command b/luci-app-modem/root/usr/share/modem/fibocom_command new file mode 100644 index 0000000..170d308 --- /dev/null +++ b/luci-app-modem/root/usr/share/modem/fibocom_command @@ -0,0 +1,27 @@ +模组信息 > ATI;ATI +查询SIM卡状态 > AT+CPIN?;AT+CPIN? +查询此时信号强度 > AT+CSQ;AT+CSQ +查询网络信息 > AT+COPS?;AT+COPS? +查询PDP信息 > AT+CGDCONT?;AT+CGDCONT? +最小功能模式 > AT+CFUN=0;AT+CFUN=0 +全功能模式 > AT+CFUN=1;AT+CFUN=1 +设置当前使用的为卡1 > AT+GTDUALSIM=0;AT+GTDUALSIM=0 +设置当前使用的为卡2 > AT+GTDUALSIM=1;AT+GTDUALSIM=1 +ECM手动拨号 > AT+GTRNDIS=1,1;AT+GTRNDIS=1,1 +ECM拨号断开 > AT+GTRNDIS=0,1;AT+GTRNDIS=0,1 +查询当前端口模式 > AT+GTUSBMODE?;AT+GTUSBMODE? +QMI/GobiNet拨号 > AT+GTUSBMODE=32;AT+GTUSBMODE=32 +ECM拨号 > AT+GTUSBMODE=18;AT+GTUSBMODE=18 +MBIM拨号 > AT+GTUSBMODE=30;AT+GTUSBMODE=30 +RNDIS拨号 > AT+GTUSBMODE=24;AT+GTUSBMODE=24 +NCM拨号 > AT+GTUSBMODE=18;AT+GTUSBMODE=18 +锁4G > AT+GTACT=2;AT+GTACT=2 +锁5G > AT+GTACT=14;AT+GTACT=14 +恢复自动搜索网络 > AT+GTACT=20;AT+GTACT=20 +查询当前连接的网络类型 > AT+PSRAT?;AT+PSRAT? +查询模组IMEI > AT+CGSN?;AT+CGSN? +查询模组IMEI > AT+GSN?;AT+GSN? +更改模组IMEI > AT+GTSN=1,7,"IMEI";AT+GTSN=1,7,"在此设置IMEI" +报告一次当前BBIC的温度 > AT+MTSM=1,6;AT+MTSM=1,6 +报告一次当前射频的温度 > AT+MTSM=1,7;AT+MTSM=1,7 +重置模组 > AT+CFUN=15;AT+CFUN=15 \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_data.sh b/luci-app-modem/root/usr/share/modem/modem_data.sh deleted file mode 100644 index 36ee0d3..0000000 --- a/luci-app-modem/root/usr/share/modem/modem_data.sh +++ /dev/null @@ -1,166 +0,0 @@ -#!/bin/sh -current_dir="$(dirname "$0")" -source "$current_dir/modem_debug.sh" -source "$current_dir/modem_scan.sh" -source "$current_dir/quectel.sh" -source "$current_dir/fibocom.sh" -source "$current_dir/simcom.sh" - -#初值化数据结构 -initData() -{ - Date='' - CHANNEL="-" - ECIO="-" - RSCP="-" - ECIO1=" " - RSCP1=" " - NETMODE="-" - LBAND="-" - PCI="-" - CTEMP="-" - net_type="-" - SINR="-" - IMEI='-' - IMSI='-' - ICCID='-' - phone='-' - manufacturer='' - modem='' -} - -#保存模块数据 -setData() -{ - { - echo $modem #'RM520N-GL' - echo $manufacturer #制造商 - # echo '1e0e:9001' #厂商号 - echo $COPS #运营商 - echo $at_port #AT串口 - echo $TEMP #温度 - echo $mode #拨号模式 - echo '---------------------------------' - echo $IMEI #imei - echo $IMSI #imsi - echo $ICCID #iccid - echo $phone #phone - echo '---------------------------------' - - echo $net_type - echo $CSQ - echo $CSQ_PER - echo $CSQ_RSSI - echo $ECIO #参考信号接收质量 RSRQ ecio - echo $ECIO1 #参考信号接收质量 RSRQ ecio1 - echo $RSCP #参考信号接收功率 RSRP rscp0 - echo $RSCP1 #参考信号接收功率 RSRP rscp1 - echo $SINR #信噪比 SINR rv["sinr"] - echo $NETMODE #连接状态监控 rv["netmode"] - echo '---------------------------------' - - echo $COPS_MCC #MCC - echo $$COPS_MNC #MNC - echo $LAC #eNB ID - echo '' #LAC_NUM - echo $RNC #TAC - echo '' #RNC_NUM - echo $CID - echo '' #CID_NUM - echo $LBAND - echo $CHANNEL - echo $PCI - - echo $Date - - echo $MODTYPE - echo $QTEMP - - } > /tmp/modem_cell.file -} - -#采集模块数据(暂时设置为单模块信息收集) -data_acquisition() -{ - debug "--检查模块的AT串口--" - #获取模块AT串口 - at_port=$(uci -q get modem.modem0.at_port) - if [ -z "$at_port" ]; then - debug "模块0没有找到AT串口" - return - fi - - debug "--检查SIM状态--" - local sim_status=$(echo `sh modem_at.sh $at_port "AT+CPIN?"`) - local sim_error=$(echo "$sim_status" | grep "ERROR") - if [ -n "$sim_error" ]; then - debug "未插入SIM卡" - sleep 5s - return - fi - local sim_ready=$(echo "$sim_status" | grep "READY") - if [ -n "$sim_ready" ]; then - debug "SIM卡正常" - else - debug "SIM卡被锁定" - sleep 5s - return - fi - - debug "--根据模块类型开始采集数据--" - # 获取模块基本信息 - modem=$(uci -q get modem.modem0.name) #模块名称 - manufacturer=$(uci -q get modem.modem0.manufacturer) #制造商 - mode=$(uci -q get modem.@config[0].mode) #制造商 - - #信号获取 - case $manufacturer in - "quectel") get_quectel_data $at_port ;; - "fibocom") get_fibocom_data $at_port ;; - "simcom") et_simcom_data $at_port ;; - "*") debug "未适配该模块" ;; - esac -} - -#数据采集循环 -data_acquisition_task() -{ - while true; do - enable=$(uci -q get modem.global.enable) - if [ "$enable" = "1" ] ;then - modem_scan - debug "------------------------------开启任务---------------------------" - data_acquisition - setData - debug "------------------------------结束任务---------------------------" - fi - sleep 10s - done -} - -main() -{ - #扫描并配置模块信息 - modem_scan - sleep 1s - - #初值化模块数据 - debug "开启数据采集服务" - initData - debug "初值化数据完成" - sleep 1s - - #采集模块数据 - debug "采集数据" - data_acquisition - #保存模块数据 - setData - - #数据采集循环 - data_acquisition_task - - #移动网络联网检查 - # checkMobileNetwork -} - -main \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_debug.sh b/luci-app-modem/root/usr/share/modem/modem_debug.sh index dd45178..15198a6 100644 --- a/luci-app-modem/root/usr/share/modem/modem_debug.sh +++ b/luci-app-modem/root/usr/share/modem/modem_debug.sh @@ -1,10 +1,14 @@ #!/bin/sh +current_dir="$(dirname "$0")" +source "$current_dir/quectel.sh" +source "$current_dir/fibocom.sh" +source "$current_dir/simcom.sh" #调试开关 # 0关闭 # 1打开 # 2输出到文件 -switch=1 +switch=0 out_file="/tmp/modem.log" #输出文件 #日志信息 debug() @@ -24,9 +28,32 @@ at() { local new_str="${2/[$]/$}" local atCommand="${new_str/\"/\"}" + + #echo + # echo -e $2 > $1 2>&1 + + #sms_tool sms_tool -d $1 at $atCommand 2>&1 } #测试时打开 # debug $1 -# at $1 $2 \ No newline at end of file +# at $1 $2 + +#获取模块拨号模式 +# $1:制造商 +# $2:AT串口 +get_mode() +{ + local mode + case $1 in + "quectel") mode=$(get_quectel_mode "$2") ;; + "fibocom") mode=$(get_fibocom_mode "$2") ;; + "simcom") mode=$(get_simcom_mode "$2") ;; + "*") + debug "未适配该模块,尝试使用拨号工具自动拨号" + mode="qmi" + ;; + esac + echo "$mode" +} \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_info.sh b/luci-app-modem/root/usr/share/modem/modem_info.sh new file mode 100644 index 0000000..9efe4ce --- /dev/null +++ b/luci-app-modem/root/usr/share/modem/modem_info.sh @@ -0,0 +1,165 @@ +#!/bin/sh +current_dir="$(dirname "$0")" +source "$current_dir/modem_debug.sh" +source "$current_dir/quectel.sh" +source "$current_dir/fibocom.sh" +source "$current_dir/simcom.sh" + +#初值化数据结构 +init_modem_info() +{ + #基本信息 + name='' #名称 + manufacturer='' #制造商 + revision='-' #固件版本 + at_port='-' #AT串口 + mode='' #拨号模式 + temperature="NaN $(printf "\xc2\xb0")C" #温度 + update_time='' #更新时间 + + #SIM卡信息 + isp="-" #运营商(互联网服务提供商) + imei='-' #IMEI + imsi='-' #IMSI + iccid='-' #ICCID + phone='-' #SIM卡号码(手机号) + + #信号信息 + net_type="-" #蜂窝网络类型 + csq="" #CSQ + csq_per="" + ssi="" #信号强度 + rssi="" #信号接收强度 RSSI + ECIO="-" #参考信号接收质量 RSRQ ecio + ECIO1=" " #参考信号接收质量 RSRQ ecio1 + RSCP="-" #参考信号接收功率 RSRP rscp0 + RSCP1=" " #参考信号接收功率 RSRP rscp1 + SINR="-" #信噪比 SINR rv["sinr"] + NETMODE="-" #连接状态监控 rv["netmode"] + + #基站信息 + MCC="" + eNBID="" + TAC="" + cell_id="" + LBAND="-" #频段 + CHANNEL="-" #频点 + PCI="-" #物理小区标识 + qos="" #最大Qos级别 +} + +#保存模块数据 +info_to_json() +{ + modem_info="{ + \"manufacturer\":\"$manufacturer\", + \"revision\":\"$revision\", + \"at_port\":\"$at_port\", + \"mode\":\"$mode\", + \"temperature\":\"$temperature\", + \"update_time\":\"$update_time\", + + \"isp\":\"$isp\", + \"imei\":\"$imei\", + \"imsi\":\"$imsi\", + \"iccid\":\"$iccid\", + \"phone\":\"$phone\", + + \"net_type\":\"$net_type\", + \"csq\":\"$csq\" + + + }" +} + + + # echo $CSQ_RSSI + # echo $ECIO #参考信号接收质量 RSRQ ecio + # echo $ECIO1 #参考信号接收质量 RSRQ ecio1 + # echo $RSCP #参考信号接收功率 RSRP rscp0 + # echo $RSCP1 #参考信号接收功率 RSRP rscp1 + # echo $SINR #信噪比 SINR rv["sinr"] + # echo $NETMODE #连接状态监控 rv["netmode"] + # echo '---------------------------------' + # #基站信息 + # echo $COPS_MCC #MCC + # echo $$COPS_MNC #MNC + # echo $LAC #eNB ID + # echo '' #LAC_NUM + # echo $RNC #TAC + # echo '' #RNC_NUM + # echo $CID + # echo '' #CID_NUM + # echo $LBAND + # echo $CHANNEL + # echo $PCI + # echo $MODTYPE + # echo $QTEMP + +#获取模组信息 +get_modem_info() +{ + update_time=$(date +"%Y-%m-%d %H:%M:%S") + + debug "检查模块的AT串口" + #获取模块AT串口 + if [ -z "$at_port" ]; then + debug "模块0没有找到AT串口" + return + fi + + debug "检查SIM状态" + local sim_status=$(echo `sh $current_dir/modem_at.sh $at_port "AT+CPIN?"`) + local sim_error=$(echo "$sim_status" | grep "ERROR") + if [ -n "$sim_error" ]; then + debug "未插入SIM卡" + sleep 1s + return + fi + local sim_ready=$(echo "$sim_status" | grep "READY") + if [ -n "$sim_ready" ]; then + debug "SIM卡正常" + else + debug "SIM卡被锁定" + sleep 1s + return + fi + + debug "根据模块类型开始采集数据" + #更多信息获取 + case $manufacturer in + "quectel") get_quectel_info $at_port ;; + "fibocom") get_fibocom_info $at_port ;; + "simcom") get_simcom_info $at_port ;; + "*") debug "未适配该模块" ;; + esac + + #获取更新时间 + update_time=$(date +"%Y-%m-%d %H:%M:%S") +} + +#获取模组数据信息 +# $1:AT串口 +# $2:制造商 +modem_info() +{ + #初值化模组信息 + debug "初值化模组信息" + init_modem_info + debug "初值化模组信息完成" + + #获取模组信息 + at_port=$1 + manufacturer=$2 + debug "获取模组信息" + get_modem_info + + #整合模块信息 + info_to_json + echo $modem_info + + #移动网络联网检查 + # checkMobileNetwork +} + +modem_info $1 $2 \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_scan.sh b/luci-app-modem/root/usr/share/modem/modem_scan.sh index c5d931d..4c0592f 100644 --- a/luci-app-modem/root/usr/share/modem/modem_scan.sh +++ b/luci-app-modem/root/usr/share/modem/modem_scan.sh @@ -1,6 +1,24 @@ #!/bin/sh +current_dir="$(dirname "$0")" +source "$current_dir/modem_debug.sh" + +#获取USB串口总线地址 +# $1:USB串口 +getUSBDeviceBusPath() +{ + local device_name="$(basename "$1")" + local device_path="$(find /sys/class/ -name $device_name)" + local device_physical_path="$(readlink -f $device_path/device/)" + + #获取父路径的上两层 + local tmp=$(dirname "$device_physical_path") + local device_bus_path=$(dirname $tmp) + + echo $device_bus_path +} #获取设备总线地址 +# $1:网络设备或PCIE串口 getDeviceBusPath() { local device_name="$(basename "$1")" @@ -11,21 +29,27 @@ getDeviceBusPath() if [ "$device_name" != "mhi_BHI" ]; then #未考虑多个mhi_BHI的情况 device_bus_path=$(dirname "$device_physical_path") fi + echo $device_bus_path } #设置模块配置 # $1:模块序号 -# $2:设备(设备节点) -# $3:设备数据接口 -# $4:总线地址 +# $2:设备数据接口 +# $3:总线地址 setModemConfig() { + #判断地址是否为net + local path=$(basename "$3") + if [ "$path" = "net" ]; then + return + fi + #处理获取到的地址 - # local substr="${4/\/sys\/devices\//}" #x86平台,替换掉/sys/devices/ - # local substr="${4/\/sys\/devices\/platform\//}" #arm平台,替换掉/sys/devices/platform/ - # local substr="${4/\/sys\/devices\/platform\/soc\//}" #arm平台,替换掉/sys/devices/platform/soc/ - local substr=$4 #路径存在不同,暂不处理 + # local substr="${3/\/sys\/devices\//}" #x86平台,替换掉/sys/devices/ + # local substr="${3/\/sys\/devices\/platform\//}" #arm平台,替换掉/sys/devices/platform/ + # local substr="${3/\/sys\/devices\/platform\/soc\//}" #arm平台,替换掉/sys/devices/platform/soc/ + local substr=$3 #路径存在不同,暂不处理 #获取网络接口 local net_path="$(find $substr -name net | sed -n '1p')" @@ -35,36 +59,19 @@ setModemConfig() local net_count="$(find $substr -name net | wc -l)" if [ "$net_count" = "2" ]; then net_net_interface_path="$(find $substr -name net | sed -n '2p')" - fi - local net=$(ls $net_path) - local net_interface=$(ls $net_net_interface_path) + local network=$(ls $net_path) + local network_interface=$(ls $net_net_interface_path) #设置配置 uci set modem.modem$1="modem-device" - uci set modem.modem$1.device_node="$2" - uci set modem.modem$1.data_interface="$3" + uci set modem.modem$1.data_interface="$2" uci set modem.modem$1.path="$substr" - uci set modem.modem$1.net="$net" - uci set modem.modem$1.net_interface="$net_interface" -} - -#设置模块网络接口 -# $1:模块序号 -# $2:总线地址 -setModemNet() -{ - local net_count="$(find $2 -name net | wc -l)" - local net_path - if [ "$net_count" = "1" ]; then - net_path="$(find $2 -name net | sed -n '1p')" - elif [ "$net_count" = "2" ]; then - net_path="$(find $2 -name net | sed -n '2p')" - fi - local net=$(ls $net_path) - - #设置配置 - uci set modem.modem$1.net="$net" + uci set modem.modem$1.network="$network" + uci set modem.modem$1.network_interface="$network_interface" + + #增加模组计数 + modem_count=$((modem_count + 1)) } #设置模块串口配置 @@ -86,10 +93,11 @@ setPortConfig() #添加新的串口 uci add_list modem.modem$i.ports="$2" #判断是不是AT串口 - local result=$(sh modem_at.sh $2 "ATI") - local str1="No response from modem." + local result=$(sh $current_dir/modem_at.sh $2 "ATI") + local str1="No" #No response from modem. local str2="failed" - if [ "$result" != "$str1" ] && [[ "$result" != *"failed"* ]]; then + if [[ "$result" != *"$str1"* ]] && [[ "$result" != *"$str2"* ]]; then + #原先的AT串口会被覆盖掉(是否需要加判断) uci set modem.modem$i.at_port="$2" setModemInfoConfig $i $2 fi @@ -107,19 +115,19 @@ setModemInfoConfig() local data_interface=$(uci -q get modem.modem$1.data_interface) #遍历模块信息文件 - local line_count=$(wc -l < "$modem_info_file") + local line_count=$(wc -l < "$modem_support_file") local line_context for i in $(seq 1 $(($line_count))); do #获取一行的内容 - local line_context=$(sed -n $i'p' "$modem_info_file") + local line_context=$(sed -n $i'p' "$modem_support_file") #获取数据接口内容 local data_interface_info=$(echo "$line_context" | cut -d ";" -f 3) if [ "$data_interface" = "$data_interface_info" ]; then #获取模块名 local modem_name=$(echo "$line_context" | cut -d ";" -f 2) #获取AT命令返回的内容 - local at_result=$(echo `sh modem_at.sh $2 "ATI" | sed -n '3p' | tr 'A-Z' 'a-z'`) + local at_result=$(echo `sh $current_dir/modem_at.sh $2 "ATI" | sed -n '3p' | tr 'A-Z' 'a-z'`) if [[ "$at_result" = *"$modem_name"* ]]; then #设置模块名 uci set modem.modem$1.name="$modem_name" @@ -128,11 +136,15 @@ setModemInfoConfig() local manufacturer=$(echo "$line_context" | cut -d ";" -f 1) uci set modem.modem$1.manufacturer="$manufacturer" - #设置拨号模式 + #设置当前的拨号模式 + local mode=$(get_mode $manufacturer $2) + uci set modem.modem$1.mode="$mode" + + #设置支持的拨号模式 local modes=$(echo "$line_context" | cut -d ";" -f 4 | tr ',' ' ') #删除原来的拨号模式列表 - uci del modem.modem$1.modes + uci -q del modem.modem$1.modes #添加新的拨号模式列表 for mode in $modes; do uci add_list modem.modem$1.modes="$mode" @@ -149,7 +161,7 @@ setModemInfoConfig() local manufacturer=$(echo "$line_context" | cut -d ";" -f 1) uci set modem.modem$1.manufacturer="$manufacturer" #删除原来的拨号模式列表 - uci del modem.modem$1.modes + uci -q del modem.modem$1.modes #添加新的拨号模式列表 for mode in $modes; do uci add_list modem.modem$1.modes="$mode" @@ -164,62 +176,70 @@ setModemInfoConfig() setModemCount() { uci set modem.global.modem_number="$modem_count" + + #数量为0时,清空模块列表 + if [ "$modem_count" = "0" ]; then + for i in $(seq 0 $((modem_count-1))); do + uci -q del modem.modem$i + done + fi } #模块计数 modem_count=0 -#模块信息文件 -modem_info_file="modem_info" +#模块支持文件 +modem_support_file="$current_dir/modem_support" #设置模块信息 modem_scan() { #初始化 modem_count=0 ########设置模块基本信息######## - #USB - local usb_devices=$(ls /dev/cdc-wdm*) - for device in $usb_devices; do - local usb_device_bus_path=$(getDeviceBusPath $device) - setModemConfig $modem_count $device "usb" $usb_device_bus_path - modem_count=$((modem_count + 1)) + #USB + local usb_network=$(find /sys/class/net -name usb*) + for network in $usb_network; do + local usb_device_bus_path=$(getDeviceBusPath $network) + setModemConfig $modem_count "usb" $usb_device_bus_path + done + local usb_network=$(find /sys/class/net -name wwan*) + for network in $usb_network; do + local usb_device_bus_path=$(getDeviceBusPath $network) + setModemConfig $modem_count "usb" $usb_device_bus_path done #PCIE - local pcie_devices=$(ls /dev/mhi_QMI*) - for device in $pcie_devices; do - local pcie_device_bus_path=$(getDeviceBusPath $device) - setModemConfig $modem_count $device "pcie" $pcie_device_bus_path - modem_count=$((modem_count + 1)) + local pcie_network=$(find /sys/class/net -name mhi_hwip*) #(通用mhi驱动) + for network in $pcie_network; do + local pcie_device_bus_path=$(getDeviceBusPath $network) + setModemConfig $modem_count "pcie" $pcie_device_bus_path + done + local pcie_network=$(find /sys/class/net -name rmnet_mhi*) #(制造商mhi驱动) + for network in $pcie_network; do + local pcie_device_bus_path=$(getDeviceBusPath $network) + setModemConfig $modem_count "pcie" $pcie_device_bus_path done - - #写入到配置中 - # uci commit modem ########设置模块串口######## #清除原串口配置 for i in $(seq 0 $((modem_count-1))); do - uci del modem.modem$i.ports + uci -q del modem.modem$i.ports done #USB串口 - local usb_port=$(ls /dev/ttyUSB*) + local usb_port=$(find /dev -name ttyUSB*) for port in $usb_port; do - local device_node=$(uci -q get modem.modem$i.device_node) - if [ "$port" = "$device_node" ]; then - continue - fi - local usb_port_device_bus_path=$(getDeviceBusPath $port) + local usb_port_device_bus_path=$(getUSBDeviceBusPath $port) setPortConfig $usb_port_device_bus_path $port done #PCIE串口 - local pcie_port=$(ls /dev/mhi*) + local pcie_port=$(find /dev -name wwan*) + for port in $pcie_port; do + local pcie_port_device_bus_path=$(getDeviceBusPath $port) + setPortConfig $pcie_port_device_bus_path $port + done + local pcie_port=$(find /dev -name mhi*) for port in $pcie_port; do - local device_node=$(uci -q get modem.modem$i.device_node) - if [ "$port" = "$device_node" ]; then - continue - fi local pcie_port_device_bus_path=$(getDeviceBusPath $port) setPortConfig $pcie_port_device_bus_path $port done - ########设置模块数量######## setModemCount diff --git a/luci-app-modem/root/usr/share/modem/modem_info b/luci-app-modem/root/usr/share/modem/modem_support similarity index 88% rename from luci-app-modem/root/usr/share/modem/modem_info rename to luci-app-modem/root/usr/share/modem/modem_support index 56d1516..9a5e4f3 100644 --- a/luci-app-modem/root/usr/share/modem/modem_info +++ b/luci-app-modem/root/usr/share/modem/modem_support @@ -5,5 +5,6 @@ quectel;rm500q-gl;pcie;qmi,gobinet,ecm,mbim,rndis,ncm fibocom;fm650-cn;usb;ecm,mbim,rndis,ncm fibocom;fm150-ae;usb;qmi,gobinet,ecm,mbim,rndis,ncm fibocom;fm150-ae;pcie;qmi +fibocom;fm160-cn;usb;qmi,gobinet,ecm,mbim,rndis,ncm unknown;unknown;usb;qmi,gobinet,ecm,mbim,rndis,ncm unknown;unknown;pcie;qmi,gobinet,mbim \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_task.sh b/luci-app-modem/root/usr/share/modem/modem_task.sh new file mode 100644 index 0000000..90cdad6 --- /dev/null +++ b/luci-app-modem/root/usr/share/modem/modem_task.sh @@ -0,0 +1,21 @@ +#!/bin/sh +current_dir="$(dirname "$0")" +source "$current_dir/modem_debug.sh" +source "$current_dir/modem_scan.sh" + +#模组扫描任务 +modem_scan_task() +{ + while true; do + enable=$(uci -q get modem.@global[0].enable) + if [ "$enable" = "1" ] ;then + #扫描模块 + debug "开启模块扫描任务" + modem_scan + debug "结束模块扫描任务" + fi + sleep 10s + done +} + +modem_scan_task \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/modem_usb_network.sh b/luci-app-modem/root/usr/share/modem/modem_usb_network.sh new file mode 100644 index 0000000..b66c14a --- /dev/null +++ b/luci-app-modem/root/usr/share/modem/modem_usb_network.sh @@ -0,0 +1,76 @@ +#!/bin/sh +current_dir="$(dirname "$0")" +source "$current_dir/modem_debug.sh" +source "$current_dir/modem_scan.sh" + +#拨号 +# $1:AT串口 +# $2:制造商 +ecm_dial() +{ + #拨号 + local manufacturer=$2 + local at_command + if [ "$manufacturer" = "quectel" ]; then + at_command='ATI' + elif [ "$manufacturer" = "fibocom" ]; then + at_command='AT+GTRNDIS=1,1' + else + at_command='ATI' + fi + sh "$current_dir/modem_at.sh" $1 $at_command +} + +#拨号 +# $1:AT串口 +# $2:制造商 +gobinet_dial() +{ + #拨号 + local manufacturer=$2 + local at_command + if [ "$manufacturer" = "quectel" ]; then + at_command='ATI' + elif [ "$manufacturer" = "fibocom" ]; then + at_command='AT$QCRMCALL=1,1' + else + at_command='ATI' + fi + sh "$current_dir/modem_at.sh" $1 $at_command +} + +#检查模组网络连接 +# $1:配置ID +# $2:AT串口 +# $3:制造商 +# $4:拨号模式 +modem_network_task() +{ + while true; do + local enable=$(uci -q get modem.@global[0].enable) + if [ "$enable" != "1" ] ;then + break + fi + enable=$(uci -q get modem.$1.enable) + if [ "$enable" != "1" ] ;then + break + fi + + #网络连接检查 + debug "开启网络连接检查任务" + local at_port=$2 + local at_command="AT+COPS?" + local connect_status=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p') + if [ "$connect_status" = "0" ]; then + case "$4" in + "ecm") ecm_dial $at_port $3 ;; + "gobinet") gobinet_dial $at_port $3 ;; + "*") ecm_dial $at_port $3 ;; + esac + fi + debug "结束网络连接检查任务" + sleep 10s + done +} + +modem_network_task $1 $2 $3 $4 \ No newline at end of file diff --git a/luci-app-modem/root/usr/share/modem/quectel.sh b/luci-app-modem/root/usr/share/modem/quectel.sh index 8c63438..5774736 100644 --- a/luci-app-modem/root/usr/share/modem/quectel.sh +++ b/luci-app-modem/root/usr/share/modem/quectel.sh @@ -1,4 +1,114 @@ #!/bin/sh +current_dir="$(dirname "$0")" + +#获取拨号模式 +# $1:AT串口 +get_quectel_mode() +{ + local at_port="$1" + local at_command='AT+QCFG="usbnet"' + local mode_num=$(echo "$response" | sed -n '2p' | sed 's/+QCFG: "usbnet",//g' | sed 's/\r//g') + + local mode + case "$mode_num" in + "0") mode="qmi" ;; + # "0") mode="gobinet" ;; + "1") mode="ecm" ;; + "2") mode="mbim" ;; + "3") mode="rndis" ;; + "5") mode='ncm' ;; + "*") mode="$mode_num" ;; + esac + echo "$mode" +} + +#基本信息 +quectel_base_info() +{ + debug "Quectel base info" + + local at_command="ATI" + local response=$(sh $current_dir/modem_at.sh $at_port $at_command) + + #名称 + name=$(echo "$response" | sed -n '3p' | sed 's/\r//g') + #制造商 + manufacturer=$(echo "$response" | sed -n '2p' | sed 's/\r//g') + #固件版本 + revision=$(echo "$response" | sed -n '4p' | sed 's/Revision: //g' | sed 's/\r//g') + + #拨号模式 + mode=$(get_quectel_mode $at_port | tr 'a-z' 'A-Z') + + #温度 + at_command="AT+QTEMP" + response=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $4}') + if [ -n "$response" ]; then + temperature="$response$(printf "\xc2\xb0")C" + fi + # response=$(sh $current_dir/modem_at.sh $at_port $at_command | grep "+QTEMP:") + # QTEMP=$(echo $response | grep -o -i "+QTEMP: [0-9]\{1,3\}") + # if [ -z "$QTEMP" ]; then + # QTEMP=$(echo $response | grep -o -i "+QTEMP:[ ]\?\"XO[_-]THERM[_-][^,]\+,[\"]\?[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}") + # fi + # if [ -z "$QTEMP" ]; then + # QTEMP=$(echo $response | grep -o -i "+QTEMP:[ ]\?\"MDM-CORE-USR.\+[0-9]\{1,3\}\"" | cut -d\" -f4) + # fi + # if [ -z "$QTEMP" ]; then + # QTEMP=$(echo $response | grep -o -i "+QTEMP:[ ]\?\"MDMSS.\+[0-9]\{1,3\}\"" | cut -d\" -f4) + # fi + # if [ -n "$QTEMP" ]; then + # CTEMP=$(echo $QTEMP | grep -o -i "[0-9]\{1,3\}")$(printf "\xc2\xb0")"C" + # fi +} + +#SIM卡信息 +quectel_sim_info() +{ + debug "Quectel sim info" + + #ISP(互联网服务提供商) + local at_command="AT+COPS?" + isp=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') + if [ "$isp" = "CHN-CMCC" ] || [ "$isp" = "CMCC" ]|| [ "$isp" = "46000" ]; then + isp="中国移动" + elif [ "$isp" = "CHN-UNICOM" ] || [ "$isp" = "UNICOM" ] || [ "$isp" = "46001" ]; then + isp="中国联通" + elif [ "$isp" = "CHN-CT" ] || [ "$isp" = "CT" ] || [ "$isp" = "46011" ]; then + isp="中国电信" + fi + + #IMEI + at_command="AT+CGSN" + imei=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') + + #IMSI + at_command="AT+CIMI" + imsi=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | sed 's/\r//g') + + #ICCID + at_command="AT+ICCID" + # iccid=$(sh $current_dir/modem_at.sh $at_port $at_command | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}") + + #SIM卡号码(手机号) + at_command="AT+CNUM" + phone=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $4}') +} + +#网络信息 +quectel_net_info() +{ + debug "Quectel net info" + + #Network Type(网络类型) + # local at_command="AT+COPS?" + local at_command="AT+QNWINFO" + net_type=$(sh $current_dir/modem_at.sh $at_port $at_command | sed -n '2p' | awk -F'"' '{print $2}') + + #CSQ + #per(信号强度) + +} #quectel lte_bw() { @@ -48,19 +158,6 @@ All_CSQ() fi } -Quectel_SIMINFO() -{ - debug "Quectel_SIMINFO" - # 获取IMEI - IMEI=$( sh modem_at.sh $at_port "AT+CGSN" | sed -n '2p' ) - # 获取IMSI - IMSI=$( sh modem_at.sh $at_port "AT+CIMI" | sed -n '2p' ) - # 获取ICCID - ICCID=$( sh modem_at.sh $at_port "AT+ICCID" | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}" ) - # 获取电话号码 - phone=$( sh modem_at.sh $at_port "AT+CNUM" | grep "+CNUM:" ) - -} # SIMCOM获取基站信息 Quectel_Cellinfo() { @@ -189,18 +286,25 @@ Quectel_Cellinfo() fi } -#Quectel公司查找基站AT +#获取Quectel模块信息 # $1:AT串口 -get_quectel_data() +get_quectel_info() { - debug "get quectel data" + debug "get quectel info" #设置AT串口 at_port=$1 - Quectel_SIMINFO - All_CSQ + #基本信息 + quectel_base_info + #SIM卡信息 + quectel_sim_info + #网络信息 + quectel_net_info + + return + # All_CSQ - Quectel_Cellinfo + # Quectel_Cellinfo # OX=$( sh modem_at.sh $at_port 'AT+QENG="servingcell"' | grep "+QENG:" ) @@ -435,24 +539,6 @@ get_quectel_data() OX=$( sh modem_at.sh $at_port 'AT+QNWPREFCFG="mode_pref"' | grep "+QNWPREFCFG:" ) QNWP=$(echo $OX | grep -o -i "+QNWPREFCFG: \"MODE_PREF\",[A-Z5:]\+" | cut -d, -f2) - #温度 - OX=$( sh modem_at.sh $at_port 'AT+QTEMP' | grep "+QTEMP:" ) - QTEMP=$(echo $OX | grep -o -i "+QTEMP: [0-9]\{1,3\}") - if [ -z "$QTEMP" ]; then - QTEMP=$(echo $OX | grep -o -i "+QTEMP:[ ]\?\"XO[_-]THERM[_-][^,]\+,[\"]\?[0-9]\{1,3\}" | grep -o "[0-9]\{1,3\}") - fi - if [ -z "$QTEMP" ]; then - QTEMP=$(echo $OX | grep -o -i "+QTEMP:[ ]\?\"MDM-CORE-USR.\+[0-9]\{1,3\}\"" | cut -d\" -f4) - fi - if [ -z "$QTEMP" ]; then - QTEMP=$(echo $OX | grep -o -i "+QTEMP:[ ]\?\"MDMSS.\+[0-9]\{1,3\}\"" | cut -d\" -f4) - fi - if [ -n "$QTEMP" ]; then - CTEMP=$(echo $QTEMP | grep -o -i "[0-9]\{1,3\}")$(printf "\xc2\xb0")"C" - fi - - - # OX=$( sh modem_at.sh $at_port "AT+QRSRP" | grep "+QRSRP:" ) QRSRP=$(echo "$OX" | grep -o -i "+QRSRP:[^,]\+,-[0-9]\{1,5\},-[0-9]\{1,5\},-[0-9]\{1,5\}[^ ]*") diff --git a/luci-app-modem/root/usr/share/modem/quectel_command b/luci-app-modem/root/usr/share/modem/quectel_command new file mode 100644 index 0000000..0f61155 --- /dev/null +++ b/luci-app-modem/root/usr/share/modem/quectel_command @@ -0,0 +1,28 @@ +模组信息 > ATI;ATI +查询SIM卡状态 > AT+CPIN?;AT+CPIN? +查询此时信号强度 > AT+CSQ;AT+CSQ +查询网络信息 > AT+COPS?;AT+COPS? +查询PDP信息 > AT+CGDCONT?;AT+CGDCONT? +最小功能模式 > AT+CFUN=0;AT+CFUN=0 +全功能模式 > AT+CFUN=1;AT+CFUN=1 +SIM卡状态上报 > AT+QSIMSTAT?;AT+QSIMSTAT? +设置当前使用的为卡1 > AT+QUIMSLOT=1;AT+QUIMSLOT=1 +设置当前使用的为卡2 > AT+QUIMSLOT=2;AT+QUIMSLOT=2 +查询网络信息 > AT+QNWINFO;AT+QNWINFO +查询载波聚合参数 > AT+QCAINFO;AT+QCAINFO +查询当前拨号模式 > AT+QCFG="usbnet";AT+QCFG="usbnet" +QMI/GobiNet拨号 > AT+QCFG="usbnet",0;AT+QCFG="usbnet",0 +ECM拨号 > AT+QCFG="usbnet",1;AT+QCFG="usbnet",1 +MBIM拨号 > AT+QCFG="usbnet",2;AT+QCFG="usbnet",2 +RNDIS拨号 > AT+QCFG="usbnet",3;AT+QCFG="usbnet",3 +NCM拨号 > AT+QCFG="usbnet",5;AT+QCFG="usbnet",5 +锁4G > AT+QNWPREFCFG="mode_pref",LTE;AT+QNWPREFCFG="mode_pref",LTE +锁5G > AT+QNWPREFCFG="mode_pref",NR5G;AT+QNWPREFCFG="mode_pref",NR5G +恢复自动搜索网络 > AT+QNWPREFCFG="mode_pref",AUTO;AT+QNWPREFCFG="mode_pref",AUTO +查询模组IMEI > AT+CGSN;AT+CGSN +查询模组IMEI > AT+GSN;AT+GSN +更改模组IMEI > AT+EGMR=1,7,"IMEI";AT+EGMR=1,7,"在此设置IMEI" +获取模组温度 > AT+QTEMP;AT+QTEMP +切换为USB通信端口 > AT+QCFG="data_interface",0,0;AT+QCFG="data_interface",0,0 +切换为PCIE通信端口 > AT+QCFG="data_interface",1,0;AT+QCFG="data_interface",1,0 +重置模组 > AT+CFUN=1,1;AT+CFUN=1,1 \ No newline at end of file