19
2024
08
10:37:51

luci-app-cpe/Makefile 5G-Modem-Support

 34 changes: 34 additions & 0 deletions luci-app-cpe/Makefile

Original file line numberDiff line numberDiff line change


@@ -0,0 +1,34 @@


#将openwrt顶层目录下的rules.mk文件中的内容导入进来


include $(TOPDIR)/rules.mk


#软件包名


PKG_NAME:=luci-app-cpe


#软件包版本


PKG_VERSION:=5.0.1


#真正编译当前软件包的目录


PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)








#将$(TOPDIR)/include目录下的package.mk文件中的内容导入进来


include $(INCLUDE_DIR)/package.mk





define Package/luci-app-cpe


PKGARCH:=all


SECTION:=wrtnode


CATEGORY:=Daocaoren


SUBMENU :=CPE


TITLE:=luci-app-cpe


DEPENDS:=+sendat + 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 \


+quectel-CM-5G +kmod-usb-net-cdc-mbim


endef





PKG_LICENSE:=GPLv3


PKG_LINCESE_FILES:=LICENSE


PKF_MAINTAINER:=daocaoren <168620188@qq.com>





include $(TOPDIR)/feeds/luci/luci.mk


# call BuildPackage - OpenWrt buildroot signature



 189 changes: 189 additions & 0 deletions luci-app-cpe/luasrc/controller/admin/cpe.lua
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,189 @@


module("luci.controller.admin.cpe", package.seeall)





I18N = require "luci.i18n"


translate = I18N.translate





function index()


entry({"admin", "modem"}, firstchild(), translate("移动数据"), 25).dependent=false


entry({"admin", "modem", "nets"}, template("cpe/net_status"), translate("信号状态"), 0)


entry({"admin", "modem", "get_csq"}, call("action_get_csq"))


entry({"admin", "modem", "send_atcmd"}, call("action_send_atcmd"))





-- entry({"admin", "modem", "sms"}, template("cpe/sms"), translate("短信信息"), 1)


-- entry({"admin", "modem", "band"}, template("cpe/band"), translate("锁频段/锁PCI"), 1)


entry({"admin", "modem", "at"}, template("cpe/at"), translate("AT工具"), 98)





if not nixio.fs.access("/etc/config/modem") then


return


end


entry({"admin", "modem", "modem"}, cbi("cpe/modem"), _("模块设置"), 99)





end





function action_send_atcmd()


local rv ={}


local file


local p = luci.http.formvalue("p")


local set = luci.http.formvalue("set")


fixed = string.gsub(set, "\"", "~")


port= string.gsub(p, "\"", "~")


rv["at"] = fixed


rv["port"] = port





os.execute("/usr/share/cpe/atcmd.sh \'" .. port .. "\' \'" .. fixed .. "\'")


result = "/tmp/result.at"


file = io.open(result, "r")


if file ~= nil then


rv["result"] = file:read("*all")


file:close()


else


rv["result"] = " "


end


os.execute("/usr/share/cpe/delatcmd.sh")


luci.http.prepare_content("application/json")


luci.http.write_json(rv)





end





function action_get_csq()


local file


stat = "/tmp/cpe_cell.file"


file = io.open(stat, "r")


local rv ={}





-- echo 'RM520N-GL'


-- echo 'conntype'


-- echo '1e0e:9001'


-- echo $COPS #运营商


-- echo '' #端口


-- echo '' #温度


-- echo '' #协议


   rv["modem"] = file:read("*line")


rv["conntype"] = 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")


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 $MODE


-- 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["mode"] = 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 = "-"


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秒更新一次)")


luci.http.prepare_content("application/json")


luci.http.write_json(rv)


end
 144 changes: 144 additions & 0 deletions luci-app-cpe/luasrc/model/cbi/cpe/modem.lua
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,144 @@


local m, section, m2, s2





m = Map("modem", translate("Mobile Network"))


m.description = translate("Modem Server For OpenWrt")








-------------------------------Fibocom Wireless Inc. FM650 Module----------------------------------


if (string.gsub(luci.sys.exec('lsusb |grep "ID 2cb7:0a05 " | wc -l'),"%s+","")=="1") then


section = m:section(TypedSection, "ndis", translate("FMFM650-CN Settings"), translate("[1]Automatic start upon startup: Check</br>[2] FMFMFM650-CN module default ECM (36) mode. If not, please modify it, otherwise dialing cannot proceed normally</br>"))


section.anonymous = true


section.addremove = false


enable = section:option(Flag, "enabled", translate("Enable"))


enable.rmempty  = false


else


section = m:section(TypedSection, "ndis", translate("SIM Settings"), translate("Automatic operation upon startup \r\n ooo"))


section.anonymous = true


section.addremove = false


section:tab("general", translate("General Setup"))


section:tab("advanced", translate("Advanced Settings"))








enable = section:taboption("general", Flag, "enabled", translate("Enable"))


enable.rmempty  = false





device = section:taboption("general",Value, "device", translate("Modem device"))


device.rmempty = false


local device_suggestions = nixio.fs.glob("/dev/cdc-wdm*")


if device_suggestions then


local node


for node in device_suggestions do


device:value(node)


end


end


apn = section:taboption("general", Value, "apn", translate("APN"))


username = section:taboption("general", Value, "username", translate("PAP/CHAP Username"))


password = section:taboption("general", Value, "password", translate("PAP/CHAP Password"))


password.password = true


pincode = section:taboption("general", Value, "pincode", translate("PIN Code"))


auth = section:taboption("general", Value, "auth", translate("Authentication Type"))


auth.rmempty = true


auth:value("", translate("-- Please choose --"))


auth:value("both", "PAP/CHAP (both)")


auth:value("pap", "PAP")


auth:value("chap", "CHAP")


auth:value("none", "NONE")


tool = section:taboption("general", Value, "tool", translate("Tools"))


tool:value("quectel-CM", "quectel-CM")


tool.rmempty = true


PdpType= section:taboption("general", Value, "pdptype", translate("PdpType"))


PdpType:value("IPV4", "IPV4")


PdpType:value("IPV6", "IPV6")


PdpType:value("IPV4V6", "IPV4V6")


PdpType.rmempty = true








---------------------------advanced------------------------------


bandlist = section:taboption("advanced", ListValue, "bandlist", translate("Lock Band List"))


-- if (string.gsub(luci.sys.exec('uci get system.@system[0].modem |grep lte |wc -l'),"%s+","")=="1") then


-- bandlist.default = "0"


-- bandlist:value("1", "LTE BAND1")


-- bandlist:value("2", "LTE BAND2")


-- bandlist:value("3", "LTE BAND3")


-- bandlist:value("4", "LTE BAND4")


-- bandlist:value("5", "LTE BAND5")


-- bandlist:value("7", "LTE BAND7")


-- bandlist:value("8", "LTE BAND8")


-- bandlist:value("20", "LTE BAND20")


-- bandlist:value("38", "LTE BAND38")


-- bandlist:value("40", "LTE BAND40")


-- bandlist:value("41", "LTE BAND41")


-- bandlist:value("28", "LTE BAND28")


-- bandlist:value("A", "AUTO")


-- end


bandlist:value("0", translate("Disable"))





servertype = section:taboption("advanced", ListValue, "servertype", translate("Server Type"))


servertype.default = "0"





--if (string.gsub(luci.sys.exec('uci get system.@system[0].modem |grep nr5g |wc -l'),"%s+","")=="1") then


servertype:value("1", "5G Only")


servertype:value("5", "4G/5G Only")


--end


servertype:value("2", "4G Only")


servertype:value("3", "3G Only")


servertype:value("4", "2G Only")


servertype:value("0", "AUTO")








-- s1 = m:section(TypedSection, "ndis", translate("AT Port Settings"),translate("Set tyyUSB port"))


-- s1.anonymous = true


-- s1.addremove = false


-- tyyusb= s1:option(Value, "tyyusb", translate("tyyUSB port"))


-- tyyusb.default = "2"


-- tyyusb:value("0", "0")


-- tyyusb:value("1", "1")


-- tyyusb:value("2", "2")


-- tyyusb:value("3", "3")


-- tyyusb:value("4", "4")


-- tyyusb.rmempty=false


end





























s2 = m:section(TypedSection, "ndis", translate("Network Diagnostics"),translate("Network exception handling: \


check the network connection in a loop for 5 seconds. If the Ping IP address is not successful, After the network \


exceeds the abnormal number, restart and search the registered network again."))


s2.anonymous = true


s2.addremove = false





en = s2:option(Flag, "en", translate("Enable"))


en.rmempty = false











ipaddress= s2:option(Value, "ipaddress", translate("Ping IP address"))


ipaddress.default = "114.114.114.114"


ipaddress.rmempty=false





an = s2:option(Value, "an", translate("Abnormal number"))


an.default = "15"


an:value("3", "3")


an:value("5", "5")


an:value("10", "10")


an:value("15", "15")


an:value("20", "20")


an:value("25", "25")


an:value("30", "30")


an.rmempty=false











local apply = luci.http.formvalue("cbi.apply")


if apply then


   -- io.popen("/etc/init.d/modeminit restart")


io.popen("/etc/init.d/modem restart")


end





return m,m2
 152 changes: 152 additions & 0 deletions luci-app-cpe/luasrc/view/cpe/at.htm
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,152 @@


<%+header%>


<%


local sys = require "luci.sys"


local utl = require "luci.util"


local fs = require "nixio.fs"


local uci = require "luci.model.uci".cursor()


local s = uci:get("custom", "bandlock", "enabled")


local a = uci:get("custom", "atcmd", "enabled")





local multilock = uci:get("custom", "multiuser", "multi") or "0"


local rootlock = uci:get("custom", "multiuser", "root") or "0"


nomulti=1


if (multilock == "0") or (multilock == "1" and rootlock == "1") then


nosms = 1


if a == "1" then


nosms = 0


end


else


nosms = 1


nomulti = 0


end


block = 1


if s == "1" then


block = 0


end





function showicon(lck)


end





-%>


<script type="text/javascript" src="<%=resource%>/xhr.js"></script>


//]]></script>








<div class="cbi-map" id="cbi-misc">


<h2><a id="content" name="content"><%:AT命令工具%></a></h2>


<div class="cbi-map-descr"><%:AT命令工具%></div>


<head>


    <style>


     input {


       vertical-align: bottom;


     }





  #popup {


width:560px;


height:190px;


padding:20px;


background-color:gainsboro;  


border-style : solid;


position:fixed;


top : 40%;


margin-left: auto;


margin-right: auto;


left: 0;


right: 0;


text-align: center;


display:none;


}


 textarea{


background:#373737;


border:none;


color:#FFF;


}


   </style>


</head>





<fieldset class="cbi-section" id="cbi-term">


<legend><%:AT命令终端%></legend>


<div id="popup">


<table width="500" border="0">


<tr>


<td width="50px"><div><%:Enter Password to Unlock Full Terminal%></div></td>


</tr>


<tr>


<td width="200px"><input id="pass" type="password"/></td>


</tr>


<tr>


<td><input type="image" src="<%=showicon(0)%>" style="width:48px;height:48px;" onclick="return done()" /></td>


</tr>


</table>


</div>





<table width="700" border="0" id="droptxt">


<tr>


<td width="10%"><div align="right"><%:模块端口 : %></div></td>


<td width="15%">


<select style="width:200px" name="atdrop" id="drop1">


<option value="0">ttyUSB0</option>


<option value="1">ttyUSB1</option>


<option value="2" selected>ttyUSB2</option>


<option value="3">ttyUSB3</option>


<option value="4">ttyUSB4</option>


<option value="5">ttyUSB5</option>


<option value="6">ttyUSB6</option>


<option value="7">ttyUSB7</option>


<option value="8">ttyUSB8</option>


<option value="9">ttyUSB9</option>


<option value="10">ttyUSB10</option>


<option value="11">ttyUSB11</option>


<option value="12">ttyUSB12</option>


</select>


</td>


<td width="10%"><div align="right"><%:AT命令 : %></div></td>


<td width="15%"><input style="visibility:visible;width: 500px;maxlength="200" type="text" name="atcmdlck" id="atcmd" class="cbi-input-text"></input></td>


<td width="10%">


<input style="visibility:visible" type="submit" id="sendat" class="cbi-button cbi-button-apply" value="<%:发送%>" onclick="return sendcmd()" />


<input style="visibility:visible" type="submit" id="sendclean" class="cbi-button cbi-button-reset" value="<%:清除%>" onclick="return sendclean()" />


</td>


<td width="47%">&nbsp;</td>


</tr>


</table>





<textarea readonly="readonly"  name="attxt" id="attxt" rows="50" style="width: 100%;" maxlength="160"></textarea>





</div>





</fieldset>


</div>





<%+footer%>
 296 changes: 296 additions & 0 deletions luci-app-cpe/luasrc/view/cpe/net_status.htm
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,296 @@


<%+header%>


<%


local fs = require "nixio.fs"


nosms = 1


if not fs.stat("/etc/nosim") then


nosms = 0


end


havegps = 0


if fs.stat("/etc/havegps") then


havegps = 1


end


-%>


<style>g {color:grey; font-size:75%; vertical-align: super;}</style>


<script type="text/javascript" src="<%=resource%>/xhr.js?v=git-23.159.15540-7154b89"></script>


//]]></script>








<div class="cbi-map" id="cbi-modem">


<h2><a id="content" name="content"><%:信号状态/模块信息%></a></h2>


<div class="cbi-map-descr">请注意该插件所有功能并无适配所有5G模块,不用妄想冷门模块插上就能用(有能力者自行适配)


</div>





<fieldset class="cbi-section" id="simwarn" style="display:none;">


<legend><%:SIM警告%></legend>


<table width="550"  border="0">


<tr>


<td width="10%"></td>


    <td width="60%"><div align="left" id="simsg" style="font-size:1.875em"><strong></strong></div></td>


<td width="30%"></td>


</tr>


</table>


</fieldset>








<fieldset class="cbi-section" id="cbi-mod">


<legend><%:综合信息%></legend>


<table width="100%" cellspacing="10">


<tr><td width="20%"><%:模块 :%></td><td id="modem">-</td><td></td></tr>


<tr><td width="20%"><%:制造商 :%></td><td id="conntype"></td><td></td></tr>


<tr><td width="20%"><%:温度 : %></td><td id="tempur"></td><td></td></tr>


<tr><td width="20%"><%:更新时间 : %></td><td id="date"></td><td></td></tr>


<tr><td width="20%"><%:协议 : %></td><td id="proto"></td><td></td></tr> -->


</table>


</fieldset>





<% if nosms == 0 then %>


<% end %>





<fieldset class="cbi-section" id="cbi-msinfo">


<legend><%:通信模块/SIM卡信息%></legend>


<table width="100%" cellspacing="10">


<tr><td width="20%"><%:运营商 : %></td><td id="cops"></td><td></td></tr>


<tr><td width="20%"><%:IMEI :%></td><td id="imei"></td><td></td></tr>


<tr><td width="20%"><%:IMSI : %></td><td id="imsi"></td><td></td></tr>


<tr><td width="20%"><%:ICCID : %></td><td id="iccid"></td><td></td></tr>


<tr><td width="20%"><%:SIM卡号码 : %></td><td id="phone"></td><td></td></tr>


</table>


</fieldset>








<fieldset class="cbi-section" id="cbi-sig">


<legend><%:信号状态%></legend>


<table width="100%" cellspacing="10">


<tr><td width="20%"><%:蜂窝网络类型 :%></td><td id="mode"></td><td></td></tr>


<tr><td width="20%"><%:CSQ : %></td><td id="csq"></td><td></td></tr>


<tr><td width="20%"><%:信号强度 : %></td><td id="per"></td><td></td></tr>


<tr><td width="20%"><%:信号接收强度 RSSI : %></td><td id="rssi"></td><td></td></tr>


<tr><td width="20%"><%:参考信号接收质量 RSRQ : %></td><td><ul><span id="ecio" class="r"></span><span id="ecio1" class="r"></span></ul></td><td></td></tr>


<tr><td width="20%"><%:参考信号接收功率 RSRP : %></td><td><ul><span id="rscp" class="r"></span><span id="rscp1" class="r"></span></ul></td><td></td></tr>


<tr><td width="20%"><%:信噪比 SINR : %></td><td id="sinr"></td><td></td></tr>


<tr><td width="20%"><%:连接状态监控 : %></td><td id="conmon"></td><td></td></tr>





</table>


</fieldset>





<fieldset class="cbi-section" id="cbi-sig">


<legend><%:基站信息%></legend>


<table width="100%" cellspacing="10">


<tr><td width="20%"><%:MCC / MNC  :%></td><td id="mcc"></td><td id="mnc"></td></tr>


<tr><td width="20%"><%:eNB ID : %></td><td><ul><span id="rnc" class="r"></span><span id="rncn" class="r"></span></ul></td><td></td></tr>


<tr><td width="20%"><%:TAC : %></td><td><ul><span id="lac" class="r"></span><span id="lacn" class="r"></span></ul></td><td></td></tr>


<tr><td width="20%"><%:Cell ID : %></td><td><ul><span id="cid" class="r"></span><span id="cidn" class="r"></span></ul></td><td></td></tr>


<tr><td width="20%"><%:频段 Band : %></td><td id="lband"></td><td></td></tr>


<tr><td width="20%"><%:频点 Channel : %></td><td id="chan"></td><td></td></tr>


<tr><td width="20%"><%:物理小区标识 PCI : %></td><td id="pci"></td><td></td></tr>


<tr><td width="20%"><%:最大Qos级别 Maximum Qos : %></td><td><ul><span id="down" class="r"></span><span id="up" class="r"></span></ul></td><td></td></tr>





</table>


</fieldset>








<% if havegps == 1 then %>


<fieldset class="cbi-section" id="cbi-gps">


<legend><%:GPS 定位%></legend>


<table width="550"  border="0">


  <tr>


    <td width="30%"><div align="right"><%:纬度 :%></div></td>


    <td><ul id="lat"></ul></td>


    <td width="1%">&nbsp;</td>


  </tr>


  <tr>


    <td><div align="right"><%:经度 :%></div></td>


    <td><ul id="long"></ul></td>


    <td>&nbsp;</td>


  </tr>


</table>


</fieldset>


<% end %>








</div>


<%+footer%>



 73 changes: 73 additions & 0 deletions luci-app-cpe/po/zh-cn/modem.po
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,73 @@


msgid ""


msgstr ""





msgid "Mobile Network"


msgstr "模块设置"








msgid "Automatic operation upon startup ooo"


msgstr "开机自动启动:勾选"





msgid "Tools"


msgstr "拨号工具"





msgid "PAP/CHAP Username"


msgstr "PAP/CHAP 用户"





msgid "PAP/CHAP Password"


msgstr "PAP/CHAP 密码"








msgid "Modem Server For OpenWrt"


msgstr "4G/5G模块管理"








msgid "SIM Settings"


msgstr "SIM 配置 (联通ANP:3gnet)  (电信APN:ctnet)  (移动APN:cmnet)  (广电APN:cbnet) "





msgid "PdpType"


msgstr "IP获取方式"





msgid "AT Port Settings"


msgstr "AT 模块配置"





msgid "Set tyyUSB port"


msgstr "AT 模块端口配置 (全模块指定端口)"





msgid "tyyUSB port"


msgstr "ttyUSB 配置ID"





msgid "Network Diagnostics"


msgstr "网络诊断"








msgid "Network Diagnostics"


msgstr "网络诊断"








msgid "Network exception handling: check the network connection in a loop for 5 seconds. If the Ping IP address is not successful, After the network exceeds the abnormal number, restart and search the registered network again."


msgstr "网络异常处理:循环检查网络连接5秒。如果Ping IP地址不成功,则在网络超过异常数量后,重新启动并搜索已注册的网络。"





msgid "Ping IP address"


msgstr "Ping IP地址"





msgid "Abnormal number"


msgstr "异常次数"





msgid "Lock Band List"


msgstr "锁定频段列表"





msgid "Server Type"


msgstr "服务类型"





msgid "FMFM650-CN Settings"


msgstr "FMFM650-CN 设置"





msgid "[1]Automatic start upon startup: Check</br>[2] FMFMFM650-CN module default ECM (36) mode. If not, please modify it, otherwise dialing cannot proceed normally</br>"


msgstr "【1】 开机自动启动:勾选 </br> 【2】 FMFM650-CN 模块默认 ECM (36)模式如果不是请修改 否则不能正常进行拨号 </br>"


















 1 change: 1 addition & 0 deletions luci-app-cpe/po/zh_Hans
Original file line numberDiff line numberDiff line change


@@ -0,0 +1 @@


zh-cn
 12 changes: 12 additions & 0 deletions luci-app-cpe/root/etc/config/modem
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,12 @@


config ndis


option enabled '0'


option bandlist '0'


option servertype '0'


option ipaddress '114.114.114.114'


option en '0'


option an '5'


option model 'nr5g'


option tyyusb '2'


option tool 'quectel-CM'


option device '/dev/cdc-wdm0'


option pdptype 'IPV4V6'
 7 changes: 7 additions & 0 deletions luci-app-cpe/root/etc/init.d/cpeinit
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,7 @@


#!/bin/sh /etc/rc.common





START=99





start() {


 /bin/sh /usr/share/cpe/rssi &


}
 103 changes: 103 additions & 0 deletions luci-app-cpe/root/etc/init.d/modem
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,103 @@


#!/bin/sh /etc/rc.common


# Copyright (C) 2006-2014 OpenWrt.org





START=16


STOP=16


USE_PROCD=1


#使用procd启动








# start启动服务


# stop停止服务


# restart重新启动服务


# reload重新加载配置文件(如果服务未实现重新加载,则重新启动)


# enable启用服务自动启动


# disable禁用服务自动启动


# enabled检查服务是否在启动时启动


# 正在运行检查服务是否正在运行


# status服务状态


# trace从系统调用跟踪开始





runModem()


{


   local enabled


   config_get_bool enabled $1 enabled


   echo "run runModem" >> /tmp/log4g


   if [ "$enabled" = "1" ]; then








       local user


       local password


       local apn


       local auth


       local pincode


       local device


       local tool


       local pdptype








       config_get user $1 user


       config_get password $1 password


       config_get apn $1 apn


       config_get auth $1 auth


       config_get pincode $1 pincode


       config_get device $1 device


       config_get tool $1 tool


       config_get pdptype $1 pdptype


       config_get tty $1 tty


       config_get atcmd $1 atcmd





       if [ "$pdptype" = "IPV4V6" ]; then


           pdptype='-4 -6'


       elif [ "$pdptype" = "IPV6" ]; then


           pdptype='-6'


       else


            pdptype=''


       fi





       devname="$(basename "$device")"


       devpath="$(readlink -f /sys/class/usbmisc/$devname/device/)"


       ifname="$( ls "$devpath"/net )"








       procd_open_instance


       #创建一个实例, 在procd看来一个应用程序可以多个实\E4\BE?


       #ubus call service list 可以查看实例


       procd_set_param command $tool -i $ifname -s $apn $pdptype


       if [ "$password" != "" ];then


           procd_append_param command $user $password $auth


       fi


       if [ "$pincode" != "" ]; then


           procd_append_param command -p $pincode


       fi


       # procd_append_param command -f /tmp/4g.log


       procd_set_param respawn


       echo "quectel-CM has started."


       procd_close_instance


       #关闭实例


   fi











}














service_triggers()


{


procd_add_reload_trigger "modem"


}





start_service() {


config_load modem


config_foreach runModem ndis


}





stop_service()


{


   echo "runModem stop" >> /tmp/log4g


   killall quectel-CM


   echo "quectel-CM has stoped."


}



 11 changes: 11 additions & 0 deletions luci-app-cpe/root/etc/uci-defaults/luci-modem
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,11 @@


#!/bin/sh





uci -q batch <<-EOF >/dev/null


delete ucitrack.@modem[-1]


add ucitrack modem


set ucitrack.@modem[-1].init=modem


commit ucitrack


EOF





rm -f /tmp/luci-indexcache


exit 0
 19 changes: 19 additions & 0 deletions luci-app-cpe/root/usr/bin/bmask128
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,19 @@


#!/bin/sh


#


printf "Band  128-bit bandmask\n"


LBAND=1


BBAND=1


while [ $LBAND -le 48 ]


do


       printf "%-6s%016X%016X\n" "$LBAND" "0" "$BBAND"


       LBAND=$(( $LBAND + 1 ))


       BBAND=$(( $BBAND * 2 ))


done


LBAND=65


BBAND=1


while [ $LBAND -le 85 ]


do


       printf "%-6s%016X%016X\n" "$LBAND" "$BBAND" "0"


       LBAND=$(( $LBAND + 1 ))


       BBAND=$(( $BBAND * 2 ))


done
 317 changes: 317 additions & 0 deletions luci-app-cpe/root/usr/bin/chan2band.sh
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,317 @@


#!/bin/sh


CHAN=$1


CHAN=$(echo "$CHAN" | grep -o "[0-9]*")





decode_lte() {


if [ $CHAN -lt 600 ]; then


BAND="B1"


elif [ $CHAN -lt 1200 ]; then


BAND="B2"


elif [ $CHAN -lt 1950 ]; then


BAND="B3"


elif [ $CHAN -lt 2400 ]; then


BAND="B4"


elif [ $CHAN -lt 2650 ]; then


BAND="B5"


elif [ $CHAN -lt 2750 ]; then


BAND="B6"


elif [ $CHAN -lt 3450 ]; then


BAND="B7"


elif [ $CHAN -lt 3800 ]; then


BAND="B8"


elif [ $CHAN -lt 4150 ]; then


BAND="B9"


elif [ $CHAN -lt 4750 ]; then


BAND="B10"


elif [ $CHAN -lt 4950 ]; then


BAND="B11"


elif [ $CHAN -lt 5010 ]; then


BAND="-"


elif [ $CHAN -lt 5180 ]; then


BAND="B12"


elif [ $CHAN -lt 5280 ]; then


BAND="B13"


elif [ $CHAN -lt 5380 ]; then


BAND="B14"


elif [ $CHAN -lt 5730 ]; then


BAND="-"


elif [ $CHAN -lt 5850 ]; then


BAND="B17"


elif [ $CHAN -lt 6000 ]; then


BAND="B18"


elif [ $CHAN -lt 6150 ]; then


BAND="B19"


elif [ $CHAN -lt 6450 ]; then


BAND="B20"


elif [ $CHAN -lt 6600 ]; then


BAND="B21"


elif [ $CHAN -lt 7400 ]; then


BAND="B22"


elif [ $CHAN -lt 7500 ]; then


BAND="-"


elif [ $CHAN -lt 7700 ]; then


BAND="B23"


elif [ $CHAN -lt 8040 ]; then


BAND="B24"


elif [ $CHAN -lt 8690 ]; then


BAND="B25"


elif [ $CHAN -lt 9040 ]; then


BAND="B26"


elif [ $CHAN -lt 9210 ]; then


BAND="B27"


elif [ $CHAN -lt 9660 ]; then


BAND="B28"


elif [ $CHAN -lt 9770 ]; then


BAND="B29"


elif [ $CHAN -lt 9870 ]; then


BAND="B30"


elif [ $CHAN -lt 9920 ]; then


BAND="B31"


elif [ $CHAN -lt 10400 ]; then


BAND="B32"


elif [ $CHAN -lt 36000 ]; then


BAND="-"


elif [ $CHAN -lt 36200 ]; then


BAND="B33"


elif [ $CHAN -lt 36350 ]; then


BAND="B34"


elif [ $CHAN -lt 36950 ]; then


BAND="B35"


elif [ $CHAN -lt 37550 ]; then


BAND="B36"


elif [ $CHAN -lt 37750 ]; then


BAND="B37"


elif [ $CHAN -lt 38250 ]; then


BAND="B38"


elif [ $CHAN -lt 38650 ]; then


BAND="B39"


elif [ $CHAN -lt 39650 ]; then


BAND="B40"


elif [ $CHAN -lt 41590 ]; then


BAND="B41"


elif [ $CHAN -lt 43590 ]; then


BAND="B42"


elif [ $CHAN -lt 45590 ]; then


BAND="B43"


elif [ $CHAN -lt 46590 ]; then


BAND="B44"


elif [ $CHAN -lt 46790 ]; then


BAND="B45"


elif [ $CHAN -lt 54540 ]; then


BAND="B46"


elif [ $CHAN -lt 55240 ]; then


BAND="B47"


elif [ $CHAN -lt 56740 ]; then


BAND="B48"


elif [ $CHAN -lt 58240 ]; then


BAND="B49"


elif [ $CHAN -lt 59090 ]; then


BAND="B50"


elif [ $CHAN -lt 59140 ]; then


BAND="B51"


elif [ $CHAN -lt 60140 ]; then


BAND="B52"


elif [ $CHAN -lt 60255 ]; then


BAND="B53"


elif [ $CHAN -lt 65536 ]; then


BAND="-"


elif [ $CHAN -lt 66436 ]; then


BAND="B65"


elif [ $CHAN -lt 67336 ]; then


BAND="B66"


elif [ $CHAN -lt 67536 ]; then


BAND="B67"


elif [ $CHAN -lt 67836 ]; then


BAND="B68"


elif [ $CHAN -lt 68336 ]; then


BAND="B69"


elif [ $CHAN -lt 68586 ]; then


BAND="B70"


elif [ $CHAN -lt 68936 ]; then


BAND="B71"


elif [ $CHAN -lt 68986 ]; then


BAND="B72"


elif [ $CHAN -lt 69036 ]; then


BAND="B73"


elif [ $CHAN -lt 69466 ]; then


BAND="B74"


elif [ $CHAN -lt 70316 ]; then


BAND="B75"


elif [ $CHAN -lt 70366 ]; then


BAND="B76"


elif [ $CHAN -lt 70546 ]; then


BAND="B85"


elif [ $CHAN -lt 70596 ]; then


BAND="B87"


elif [ $CHAN -lt 70646 ]; then


BAND="B88"


else


BAND="-"


fi


}





decode_nr5g() {


if [ $CHAN -lt 123400 ]; then


BAND="-"


elif [ $CHAN -le 130400 ]; then


BAND="n71"


elif [ $CHAN -lt 143400 ]; then


BAND="-"


elif [ $CHAN -lt 145600 ]; then


BAND="n29"


elif [ $CHAN -eq 145600 ]; then


BAND="n29|n85"


elif [ $CHAN -lt 145800 ]; then


BAND="n85"


elif [ $CHAN -eq 145800 ]; then


BAND="n12|n85"


elif [ $CHAN -lt 147600 ]; then


BAND="n12|n85"


elif [ $CHAN -lt 149200 ]; then


BAND="n12|n67|n85"


elif [ $CHAN -eq 149200 ]; then


BAND="n12|n13|n67|n85"


elif [ $CHAN -le 151200 ]; then


BAND="n13|n67"


elif [ $CHAN -lt 151600 ]; then


BAND="n67"


elif [ $CHAN -eq 151600 ]; then


BAND="n14|n28|n67"


elif [ $CHAN -le 153600 ]; then


BAND="n14|n28"


elif [ $CHAN -lt 158200 ]; then


BAND="n28"


elif [ $CHAN -eq 158200 ]; then


BAND="n14|n20|n28"


elif [ $CHAN -le 160600 ]; then


BAND="n20|n28"


elif [ $CHAN -le 164200 ]; then


BAND="n20"


elif [ $CHAN -lt 171800 ]; then


BAND="-"


elif [ $CHAN -lt 172000 ]; then


BAND="n26"


elif [ $CHAN -lt 173800 ]; then


BAND="n18|n26"


elif [ $CHAN -le 175000 ]; then


BAND="n5|n18|n26"


elif [ $CHAN -le 178800 ]; then


BAND="n5|n26"


elif [ $CHAN -lt 185000 ]; then


BAND="-"


elif [ $CHAN -le 192000 ]; then


BAND="n8"


elif [ $CHAN -lt 285400 ]; then


BAND="-"


elif [ $CHAN -lt 286400 ]; then


BAND="n51|n76|n91|n93"


elif [ $CHAN -eq 286400 ]; then


BAND="n50|n51|n75|n76|n91|92|n93|94"


elif [ $CHAN -lt 295000 ]; then


BAND="n50|n75|n92|n94"


elif [ $CHAN -eq 295000 ]; then


BAND="n50|n74|n75|n92|n94"


elif [ $CHAN -le 303400 ]; then


BAND="n50|n74|n75|n92|n94"


elif [ $CHAN -le 303600 ]; then


BAND="n74"


elif [ $CHAN -lt 305000 ]; then


BAND="-"


elif [ $CHAN -le 311800 ]; then


BAND="n24"


elif [ $CHAN -lt 361000 ]; then


BAND="-"


elif [ $CHAN -lt 376000 ]; then


BAND="n3"


elif [ $CHAN -eq 376000 ]; then


BAND="n3|n39"


elif [ $CHAN -le 384000 ]; then


BAND="n39"


elif [ $CHAN -lt 386000 ]; then


BAND="-"


elif [ $CHAN -le 398000 ]; then


BAND="n2|n25"


elif [ $CHAN -lt 399000 ]; then


BAND="n25"


elif [ $CHAN -eq 399000 ]; then


BAND="n25|n70"


elif [ $CHAN -lt 402000 ]; then


BAND="n70"


elif [ $CHAN -eq 402000 ]; then


BAND="n34|n70"


elif [ $CHAN -le 404000 ]; then


BAND="n34|n70"


elif [ $CHAN -le 405000 ]; then


BAND="n34"


elif [ $CHAN -lt 422000 ]; then


BAND="-"


elif [ $CHAN -le 434000 ]; then


BAND="n1|n65|n66"


elif [ $CHAN -le 440000 ]; then


BAND="n65|n66"


elif [ $CHAN -lt 460000 ]; then


BAND="-"


elif [ $CHAN -lt 470000 ]; then


BAND="n40"


elif [ $CHAN -eq 470000 ]; then


BAND="n30|n40"


elif [ $CHAN -le 472000 ]; then


BAND="n30|n40"


elif [ $CHAN -le 480000 ]; then


BAND="n40"


elif [ $CHAN -lt 496700 ]; then


BAND="-"


elif [ $CHAN -le 499000 ]; then


BAND="n53"


elif [ $CHAN -lt 499200 ]; then


BAND="-"


elif [ $CHAN -lt 514000 ]; then


BAND="n41|n90"


elif [ $CHAN -eq 514000 ]; then


BAND="n38|n41|n90"


elif [ $CHAN -lt 524000 ]; then


BAND="n38|n41|n90"


elif [ $CHAN -eq 524000 ]; then


BAND="n7|n38|n41|n90"


elif [ $CHAN -lt 538000 ]; then


BAND="n7|n41|n90"


elif [ $CHAN -eq 538000 ]; then


BAND="n7|n90"


elif [ $CHAN -lt 620000 ]; then


BAND="-"


elif [ $CHAN -lt 636667 ]; then


BAND="n77|n78"


elif [ $CHAN -le 646666 ]; then


BAND="n48|n77|n78"


elif [ $CHAN -le 653333 ]; then


BAND="n77|n78"


elif [ $CHAN -le 680000 ]; then


BAND="n77"


elif [ $CHAN -lt 693334 ]; then


BAND="-"


elif [ $CHAN -le 733333 ]; then


BAND="n79"


elif [ $CHAN -lt 743333 ]; then


BAND="-"


elif [ $CHAN -lt 795000 ]; then


BAND="n46"


elif [ $CHAN -eq 795000 ]; then


BAND="n46|n96"


elif [ $CHAN -le 875000 ]; then


BAND="n96"


else


BAND="-"


fi


}





if [ -z "$CHAN" ]; then


BAND="-"


elif [ "$CHAN" -lt 123400 ]; then


decode_lte


elif [ "$CHAN" -le 875000 ]; then


decode_nr5g


else


BAND="-"


fi


echo $BAND


exit
 24 changes: 24 additions & 0 deletions luci-app-cpe/root/usr/bin/encodemask
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,24 @@


#!/usr/bin/lua





mtab = {}


vtab = {1, 2, 4, 8}





for i = 1, 32 do


mtab[i] = 0


end





numarg = #arg


for argval = 1, numarg do


band = arg[argval]


if tonumber(band) <= 128 then


idx = math.floor((band - 1) / 4) + 1


idxr = 33 - idx


val = vtab[(band - ((idx - 1) * 4 ))]


mtab[idxr] = mtab[idxr] + val


end


end


for i = 1, 32 do


mtab[i] = string.format("%X", mtab[i])


end





print(table.concat(mtab))
 9 changes: 9 additions & 0 deletions luci-app-cpe/root/usr/bin/jkillall
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,9 @@


#!/bin/sh


LOOKFOR=$1


KILLLIST=$(ps | grep $LOOKFOR)


echo "$KILLLIST" | while read line; do


if `echo "$line" | grep "/$LOOKFOR" > /dev/null` ; then


PIDV=$(echo $line | grep -o "^[0-9]\{1,5\}" | grep -o "[0-9]\{1,5\}")


kill $PIDV


fi


done
 21 changes: 21 additions & 0 deletions luci-app-cpe/root/usr/bin/rsrp2rssi
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,21 @@


#!/usr/bin/lua





rsrp = tonumber(arg[1])


bw = tonumber(arg[2])


if bw == 1.4 then


n = 6


else


n = bw * 5


end





if tonumber(string.match(_VERSION, "%d+%.%d")) > 5.1 then


rssi = rsrp + (10 * math.log(n * 12, 10))


else


rssi = rsrp + (10 * math.log10(n * 12))


end


if rssi < -113 then


rssi = -113


elseif rssi > -51 then


rssi = -51


end


print(math.floor(rssi))
 18 changes: 18 additions & 0 deletions luci-app-cpe/root/usr/bin/set_gpio
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,18 @@


#!/bin/sh





PIN=$1


VALUE=$2





PIN_FILE=/sys/class/gpio/gpio$PIN





if [ -z "$PIN" -o -z "$VALUE" ]; then


   exit 1


fi





echo $PIN >/sys/class/gpio/export





if [ $(cat $PIN_FILE/direction) = "out" ]; then


   echo $VALUE >$PIN_FILE/value


fi





echo $PIN >/sys/class/gpio/unexport
 285 changes: 285 additions & 0 deletions luci-app-cpe/root/usr/share/cpe/Fibocom
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,285 @@


#!/bin/sh


ATPORT=1











# SIMCOM获取基站信息


Fibocom_Cellinfo()


{


   #baseinfo.gcom


   OX=$( sendat $ATPORT "ATI")


   OX=$( sendat $ATPORT "AT+CGEQNEG=1")





   #cellinfo0.gcom


   OX1=$( sendat $ATPORT "AT+COPS=3,0;+COPS?")


   OX2=$( sendat $ATPORT "AT+COPS=3,2;+COPS?")


   OX=$OX1" "$OX2





   #cellinfo.gcom


   OY1=$( sendat $ATPORT "AT+CREG=2;+CREG?;+CREG=0")


   OY2=$( sendat $ATPORT "AT+CEREG=2;+CEREG?;+CEREG=0")


   OY3=$( sendat $ATPORT "AT+C5GREG=2;+C5GREG?;+C5GREG=0")


   OY=$OY1" "$OY2" "$OY3








   OXx=$OX


   OX=$(echo $OX | tr 'a-z' 'A-Z')


   OY=$(echo $OY | tr 'a-z' 'A-Z')


   OX=$OX" "$OY





   #Debug "$OX"


   #Debug "$OY"





   COPS="-"


   COPS_MCC="-"


   COPS_MNC="-"


   COPSX=$(echo $OXx | grep -o "+COPS: [01],0,.\+," | cut -d, -f3 | grep -o "[^\"]\+")





   if [ "x$COPSX" != "x" ]; then


       COPS=$COPSX


   fi





   COPSX=$(echo $OX | grep -o "+COPS: [01],2,.\+," | cut -d, -f3 | grep -o "[^\"]\+")





   if [ "x$COPSX" != "x" ]; then


       COPS_MCC=${COPSX:0:3}


       COPS_MNC=${COPSX:3:3}


       if [ "$COPS" = "-" ]; then


           COPS=$(awk -F[\;] '/'$COPS'/ {print $2}' $ROOTER/signal/mccmnc.data)


           [ "x$COPS" = "x" ] && COPS="-"


       fi


   fi





   if [ "$COPS" = "-" ]; then


       COPS=$(echo "$O" | awk -F[\"] '/^\+COPS: 0,0/ {print $2}')


       if [ "x$COPS" = "x" ]; then


           COPS="-"


           COPS_MCC="-"


           COPS_MNC="-"


       fi


   fi


   COPS_MNC=" "$COPS_MNC





   OX=$(echo "${OX//[ \"]/}")


   CID=""


   CID5=""


   RAT=""


   REGV=$(echo "$OX" | grep -o "+C5GREG:2,[0-9],[A-F0-9]\{2,6\},[A-F0-9]\{5,10\},[0-9]\{1,2\}")


   if [ -n "$REGV" ]; then


       LAC5=$(echo "$REGV" | cut -d, -f3)


       LAC5=$LAC5" ($(printf "%d" 0x$LAC5))"


       CID5=$(echo "$REGV" | cut -d, -f4)


       CID5L=$(printf "%010X" 0x$CID5)


       RNC5=${CID5L:1:6}


       RNC5=$RNC5" ($(printf "%d" 0x$RNC5))"


       CID5=${CID5L:7:3}


       CID5="Short $(printf "%X" 0x$CID5) ($(printf "%d" 0x$CID5)), Long $(printf "%X" 0x$CID5L) ($(printf "%d" 0x$CID5L))"


       RAT=$(echo "$REGV" | cut -d, -f5)


   fi


   REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{5,8\}")


   REGFMT="3GPP"


   if [ -z "$REGV" ]; then


       REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{1,3\},[A-F0-9]\{5,8\}")


       REGFMT="SW"


   fi


   if [ -n "$REGV" ]; then


       LAC=$(echo "$REGV" | cut -d, -f3)


       LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))"


       if [ $REGFMT = "3GPP" ]; then


           CID=$(echo "$REGV" | cut -d, -f4)


       else


           CID=$(echo "$REGV" | cut -d, -f5)


       fi


       CIDL=$(printf "%08X" 0x$CID)


       RNC=${CIDL:1:5}


       RNC=$RNC" ($(printf "%d" 0x$RNC))"


       CID=${CIDL:6:2}


       CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))"





   else


       REGV=$(echo "$OX" | grep -o "+CREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{2,8\}")


       if [ -n "$REGV" ]; then


           LAC=$(echo "$REGV" | cut -d, -f3)


           CID=$(echo "$REGV" | cut -d, -f4)


           if [ ${#CID} -gt 4 ]; then


               LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))"


               CIDL=$(printf "%08X" 0x$CID)


               RNC=${CIDL:1:3}


               CID=${CIDL:4:4}


               CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))"


           else


               LAC=""


           fi


       else


           LAC=""


       fi


   fi


   REGSTAT=$(echo "$REGV" | cut -d, -f2)


   if [ "$REGSTAT" == "5" -a "$COPS" != "-" ]; then


       COPS_MNC=$COPS_MNC" (Roaming)"


   fi


   if [ -n "$CID" -a -n "$CID5" ] && [ "$RAT" == "13" -o "$RAT" == "10" ]; then


       LAC="4G $LAC, 5G $LAC5"


       CID="4G $CID<br />5G $CID5"


       RNC="4G $RNC, 5G $RNC5"


   elif [ -n "$CID5" ]; then


       LAC=$LAC5


       CID=$CID5


       RNC=$RNC5


   fi


   if [ -z "$LAC" ]; then


       LAC="-"


       CID="-"


       RNC="-"


   fi


}


Fibocom_SIMINFO()


{


   Debug "Fibocom_SIMINFO"


   # 获取IMEI


IMEI=$( sendat $ATPORT "AT+CGSN"  | sed -n '2p'  )


# 获取IMSI


IMSI=$( sendat $ATPORT "AT+CIMI"  | sed -n '2p'  )


# 获取ICCID


ICCID=$( sendat $ATPORT "AT+ICCID"  | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}"  )


# 获取电话号码


phone=$( sendat $ATPORT "AT+CNUM"  | grep "+CNUM:"  )


}





#SIMCOM查找基站AT


Fibocom_AT()


{


   Debug "Fibocom_AT"


   ATPORT


   All_CSQ


Fibocom_SIMINFO


   Fibocom_Cellinfo





   #温度


OX=$( sendat $ATPORT "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=$( sendat $ATPORT "AT+CPSI?")


rec=$(echo "$OX" | grep "+CPSI:")


w=$(echo $rec |grep "NO SERVICE"| wc -l)


if [ $w -ge 1 ];then


Debug "NO SERVICE"


return


fi


w=$(echo $rec |grep "NR5G_"| wc -l)


if [ $w -ge 1 ];then





w=$(echo $rec |grep "32768"| wc -l)


if [ $w -ge 1 ];then


Debug "-32768"


return


fi





Debug "$rec"


rec1=${rec##*+CPSI:}


#echo "$rec1"


MODE="${rec1%%,*}" # MODE="NR5G"


rect1=${rec1#*,}


rect1s="${rect1%%,*}" #Online


rect2=${rect1#*,}


rect2s="${rect2%%,*}" #460-11


rect3=${rect2#*,}


rect3s="${rect3%%,*}" #0xCFA102


rect4=${rect3#*,}


rect4s="${rect4%%,*}" #55744245764


rect5=${rect4#*,}


rect5s="${rect5%%,*}" #196


rect6=${rect5#*,}


rect6s="${rect6%%,*}" #NR5G_BAND78


rect7=${rect6#*,}


rect7s="${rect7%%,*}" #627264


rect8=${rect7#*,}


rect8s="${rect8%%,*}" #-940


rect9=${rect8#*,}


rect9s="${rect9%%,*}" #-110


# "${rec1##*,}" #最后一位


rect10=${rect9#*,}


rect10s="${rect10%%,*}" #最后一位


PCI=$rect5s


LBAND="n"$(echo $rect6s | cut -d, -f0 | grep -o "BAND[0-9]\{1,3\}" | grep -o "[0-9]\+")


CHANNEL=$rect7s


RSCP=$(($(echo $rect8s | cut -d, -f0) / 10))


ECIO=$(($(echo $rect9s | cut -d, -f0) / 10))


if [ "$CSQ_PER" = "-" ]; then


CSQ_PER=$((100 - (($RSCP + 31) * 100/-125)))"%"


fi


SINR=$(($(echo $rect10s | cut -d, -f0) / 10))" dB"


fi


w=$(echo $rec |grep "LTE"|grep "EUTRAN"| wc -l)


if [ $w -ge 1 ];then


rec1=${rec#*EUTRAN-}


lte_band=${rec1%%,*} #EUTRAN-BAND


rec1=${rec1#*,}


rec1=${rec1#*,}


rec1=${rec1#*,}


rec1=${rec1#*,}


#rec1=${rec1#*,}


rec1=${rec1#*,}


lte_rssi=${rec1%%,*} #LTE_RSSI


lte_rssi=`expr $lte_rssi / 10` #LTE_RSSI


Debug "LTE_BAND=$lte_band LTE_RSSI=$lte_rssi"


if [ $rssi == 0 ];then


rssi=$lte_rssi


fi


fi


w=$(echo $rec |grep "WCDMA"| wc -l)


if [ $w -ge 1 ];then


w=$(echo $rec |grep "UNKNOWN"|wc -l)


if [ $w -ge 1 ];then


Debug "UNKNOWN BAND"


return


fi


fi




















#CNMP


OX=$( sendat $ATPORT "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


"2"|"55" )


NETMODE="1" ;;


"13" )


NETMODE="3" ;;


"14" )


NETMODE="5" ;;


"38" )


NETMODE="7" ;;


"71" )


NETMODE="9" ;;


"109" )


NETMODE="8" ;;


* )


NETMODE="0" ;;


esac


fi





# CMGRMI 信息


OX=$( sendat $ATPORT "AT+CMGRMI=4")


CAINFO=$(echo "$OX" | grep -o "$REGXz" | tr ' ' ':')


if [ -n "$CAINFO" ]; then


for CASV in $(echo "$CAINFO"); do


LBAND=$LBAND"<br />B"$(echo "$CASV" | cut -d, -f4)


BW=$(echo "$CASV" | cut -d, -f5)


decode_bw


LBAND=$LBAND" (CA, Bandwidth $BW MHz)"


CHANNEL="$CHANNEL, "$(echo "$CASV" | cut -d, -f2)


PCI="$PCI, "$(echo "$CASV" | cut -d, -f7)


done


fi





}
 507 changes: 507 additions & 0 deletions luci-app-cpe/root/usr/share/cpe/Quectel

Large diffs are not rendered by default.

 303 changes: 303 additions & 0 deletions luci-app-cpe/root/usr/share/cpe/SIMCOM
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,303 @@


#!/bin/sh


ATPORT=1





#查询信息强度


All_CSQ()


{


    Debug "All_CSQ"


#信号


OX=$( sendat $ATPORT "AT+CSQ" |grep "+CSQ:")


OX=$(echo $OX | tr 'a-z' 'A-Z')


CSQ=$(echo "$OX" | grep -o "+CSQ: [0-9]\{1,2\}" | grep -o "[0-9]\{1,2\}")


if [ $CSQ = "99" ]; then


CSQ=""


fi


if [ -n "$CSQ" ]; then


CSQ_PER=$(($CSQ * 100/31))"%"


CSQ_RSSI=$((2 * CSQ - 113))" dBm"


else


CSQ="-"


CSQ_PER="-"


CSQ_RSSI="-"


fi


}





# SIMCOM获取基站信息


SIMCOM_Cellinfo()


{


   #baseinfo.gcom


   OX=$( sendat 2 "ATI")


   OX=$( sendat 2 "AT+CGEQNEG=1")





   #cellinfo0.gcom


   OX1=$( sendat 2 "AT+COPS=3,0;+COPS?")


   OX2=$( sendat 2 "AT+COPS=3,2;+COPS?")


   OX=$OX1" "$OX2





   #cellinfo.gcom


   OY1=$( sendat 2 "AT+CREG=2;+CREG?;+CREG=0")


   OY2=$( sendat 2 "AT+CEREG=2;+CEREG?;+CEREG=0")


   OY3=$( sendat 2 "AT+C5GREG=2;+C5GREG?;+C5GREG=0")


   OY=$OY1" "$OY2" "$OY3








   OXx=$OX


   OX=$(echo $OX | tr 'a-z' 'A-Z')


   OY=$(echo $OY | tr 'a-z' 'A-Z')


   OX=$OX" "$OY





   #Debug "$OX"


   #Debug "$OY"





   COPS="-"


   COPS_MCC="-"


   COPS_MNC="-"


   COPSX=$(echo $OXx | grep -o "+COPS: [01],0,.\+," | cut -d, -f3 | grep -o "[^\"]\+")





   if [ "x$COPSX" != "x" ]; then


       COPS=$COPSX


   fi





   COPSX=$(echo $OX | grep -o "+COPS: [01],2,.\+," | cut -d, -f3 | grep -o "[^\"]\+")





   if [ "x$COPSX" != "x" ]; then


       COPS_MCC=${COPSX:0:3}


       COPS_MNC=${COPSX:3:3}


       if [ "$COPS" = "-" ]; then


           COPS=$(awk -F[\;] '/'$COPS'/ {print $2}' $ROOTER/signal/mccmnc.data)


           [ "x$COPS" = "x" ] && COPS="-"


       fi


   fi





   if [ "$COPS" = "-" ]; then


       COPS=$(echo "$O" | awk -F[\"] '/^\+COPS: 0,0/ {print $2}')


       if [ "x$COPS" = "x" ]; then


           COPS="-"


           COPS_MCC="-"


           COPS_MNC="-"


       fi


   fi


   COPS_MNC=" "$COPS_MNC





   OX=$(echo "${OX//[ \"]/}")


   CID=""


   CID5=""


   RAT=""


   REGV=$(echo "$OX" | grep -o "+C5GREG:2,[0-9],[A-F0-9]\{2,6\},[A-F0-9]\{5,10\},[0-9]\{1,2\}")


   if [ -n "$REGV" ]; then


       LAC5=$(echo "$REGV" | cut -d, -f3)


       LAC5=$LAC5" ($(printf "%d" 0x$LAC5))"


       CID5=$(echo "$REGV" | cut -d, -f4)


       CID5L=$(printf "%010X" 0x$CID5)


       RNC5=${CID5L:1:6}


       RNC5=$RNC5" ($(printf "%d" 0x$RNC5))"


       CID5=${CID5L:7:3}


       CID5="Short $(printf "%X" 0x$CID5) ($(printf "%d" 0x$CID5)), Long $(printf "%X" 0x$CID5L) ($(printf "%d" 0x$CID5L))"


       RAT=$(echo "$REGV" | cut -d, -f5)


   fi


   REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{5,8\}")


   REGFMT="3GPP"


   if [ -z "$REGV" ]; then


       REGV=$(echo "$OX" | grep -o "+CEREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{1,3\},[A-F0-9]\{5,8\}")


       REGFMT="SW"


   fi


   if [ -n "$REGV" ]; then


       LAC=$(echo "$REGV" | cut -d, -f3)


       LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))"


       if [ $REGFMT = "3GPP" ]; then


           CID=$(echo "$REGV" | cut -d, -f4)


       else


           CID=$(echo "$REGV" | cut -d, -f5)


       fi


       CIDL=$(printf "%08X" 0x$CID)


       RNC=${CIDL:1:5}


       RNC=$RNC" ($(printf "%d" 0x$RNC))"


       CID=${CIDL:6:2}


       CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))"





   else


       REGV=$(echo "$OX" | grep -o "+CREG:2,[0-9],[A-F0-9]\{2,4\},[A-F0-9]\{2,8\}")


       if [ -n "$REGV" ]; then


           LAC=$(echo "$REGV" | cut -d, -f3)


           CID=$(echo "$REGV" | cut -d, -f4)


           if [ ${#CID} -gt 4 ]; then


               LAC=$(printf "%04X" 0x$LAC)" ($(printf "%d" 0x$LAC))"


               CIDL=$(printf "%08X" 0x$CID)


               RNC=${CIDL:1:3}


               CID=${CIDL:4:4}


               CID="Short $(printf "%X" 0x$CID) ($(printf "%d" 0x$CID)), Long $(printf "%X" 0x$CIDL) ($(printf "%d" 0x$CIDL))"


           else


               LAC=""


           fi


       else


           LAC=""


       fi


   fi


   REGSTAT=$(echo "$REGV" | cut -d, -f2)


   if [ "$REGSTAT" == "5" -a "$COPS" != "-" ]; then


       COPS_MNC=$COPS_MNC" (Roaming)"


   fi


   if [ -n "$CID" -a -n "$CID5" ] && [ "$RAT" == "13" -o "$RAT" == "10" ]; then


       LAC="4G $LAC, 5G $LAC5"


       CID="4G $CID<br />5G $CID5"


       RNC="4G $RNC, 5G $RNC5"


   elif [ -n "$CID5" ]; then


       LAC=$LAC5


       CID=$CID5


       RNC=$RNC5


   fi


   if [ -z "$LAC" ]; then


       LAC="-"


       CID="-"


       RNC="-"


   fi


}


SIMCOM_SIMINFO()


{


   Debug "Quectel_SIMINFO"


   # 获取IMEI


IMEI=$( sendat $ATPORT "AT+CGSN"  | sed -n '2p'  )


# 获取IMSI


IMSI=$( sendat $ATPORT "AT+CIMI"  | sed -n '2p'  )


# 获取ICCID


ICCID=$( sendat $ATPORT "AT+ICCID"  | grep -o "+ICCID:[ ]*[-0-9]\+" | grep -o "[-0-9]\{1,4\}"  )


# 获取电话号码


phone=$( sendat $ATPORT "AT+CNUM"  | grep "+CNUM:"  )


}


#SIMCOM查找基站AT


SIMCOM_AT()


{


   Debug "SIMCOM_AT"


ATPORT


   All_CSQ


SIMCOM_SIMINFO


   SIMCOM_Cellinfo





   #温度


OX=$( sendat $ATPORT "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=$( sendat $ATPORT "AT+CPSI?")


rec=$(echo "$OX" | grep "+CPSI:")


w=$(echo $rec |grep "NO SERVICE"| wc -l)


if [ $w -ge 1 ];then


Debug "NO SERVICE"


return


fi


w=$(echo $rec |grep "NR5G_"| wc -l)


if [ $w -ge 1 ];then





w=$(echo $rec |grep "32768"| wc -l)


if [ $w -ge 1 ];then


Debug "-32768"


return


fi





Debug "$rec"


rec1=${rec##*+CPSI:}


#echo "$rec1"


MODE="${rec1%%,*}" # MODE="NR5G"


rect1=${rec1#*,}


rect1s="${rect1%%,*}" #Online


rect2=${rect1#*,}


rect2s="${rect2%%,*}" #460-11


rect3=${rect2#*,}


rect3s="${rect3%%,*}" #0xCFA102


rect4=${rect3#*,}


rect4s="${rect4%%,*}" #55744245764


rect5=${rect4#*,}


rect5s="${rect5%%,*}" #196


rect6=${rect5#*,}


rect6s="${rect6%%,*}" #NR5G_BAND78


rect7=${rect6#*,}


rect7s="${rect7%%,*}" #627264


rect8=${rect7#*,}


rect8s="${rect8%%,*}" #-940


rect9=${rect8#*,}


rect9s="${rect9%%,*}" #-110


# "${rec1##*,}" #最后一位


rect10=${rect9#*,}


rect10s="${rect10%%,*}" #最后一位


PCI=$rect5s


LBAND="n"$(echo $rect6s | cut -d, -f0 | grep -o "BAND[0-9]\{1,3\}" | grep -o "[0-9]\+")


CHANNEL=$rect7s


RSCP=$(($(echo $rect8s | cut -d, -f0) / 10))


ECIO=$(($(echo $rect9s | cut -d, -f0) / 10))


if [ "$CSQ_PER" = "-" ]; then


CSQ_PER=$((100 - (($RSCP + 31) * 100/-125)))"%"


fi


SINR=$(($(echo $rect10s | cut -d, -f0) / 10))" dB"


fi


w=$(echo $rec |grep "LTE"|grep "EUTRAN"| wc -l)


if [ $w -ge 1 ];then


rec1=${rec#*EUTRAN-}


lte_band=${rec1%%,*} #EUTRAN-BAND


rec1=${rec1#*,}


rec1=${rec1#*,}


rec1=${rec1#*,}


rec1=${rec1#*,}


#rec1=${rec1#*,}


rec1=${rec1#*,}


lte_rssi=${rec1%%,*} #LTE_RSSI


lte_rssi=`expr $lte_rssi / 10` #LTE_RSSI


Debug "LTE_BAND=$lte_band LTE_RSSI=$lte_rssi"


if [ $rssi == 0 ];then


rssi=$lte_rssi


fi


fi


w=$(echo $rec |grep "WCDMA"| wc -l)


if [ $w -ge 1 ];then


w=$(echo $rec |grep "UNKNOWN"|wc -l)


if [ $w -ge 1 ];then


Debug "UNKNOWN BAND"


return


fi


fi




















#CNMP


OX=$( sendat $ATPORT "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


"2"|"55" )


NETMODE="1" ;;


"13" )


NETMODE="3" ;;


"14" )


NETMODE="5" ;;


"38" )


NETMODE="7" ;;


"71" )


NETMODE="9" ;;


"109" )


NETMODE="8" ;;


* )


NETMODE="0" ;;


esac


fi





# CMGRMI 信息


OX=$( sendat $ATPORT "AT+CMGRMI=4")


CAINFO=$(echo "$OX" | grep -o "$REGXz" | tr ' ' ':')


if [ -n "$CAINFO" ]; then


for CASV in $(echo "$CAINFO"); do


LBAND=$LBAND"<br />B"$(echo "$CASV" | cut -d, -f4)


BW=$(echo "$CASV" | cut -d, -f5)


decode_bw


LBAND=$LBAND" (CA, Bandwidth $BW MHz)"


CHANNEL="$CHANNEL, "$(echo "$CASV" | cut -d, -f2)


PCI="$PCI, "$(echo "$CASV" | cut -d, -f7)


done


fi





}
 3 changes: 3 additions & 0 deletions luci-app-cpe/root/usr/share/cpe/atcmd.sh
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,3 @@


#!/bin/sh


rec=$(sendat $1 $2)


echo $rec  >>  /tmp/result.at
 27 changes: 27 additions & 0 deletions luci-app-cpe/root/usr/share/cpe/cpedebug
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,27 @@


#!/bin/sh





en=1 #调试开关:0关闭,1打开 ,2输出到文件


outfile="/tmp/cpe.log" #输出文件


#日志信息


Debug()


{


tim=$(date "+%Y-%m-%d %H:%M:%S") #获取系统时间


if [ $en == 1 ]; then


echo $tim $1 #打印输出


elif [ $en == 2 ]; then


echo $tim $1 >> $outfile #输出到文件


fi


}


ATPORT()


{


MODEMNAME="ALL"


# ATPORT=$(uci -q get modem.@ndis[0].tyyusb)


lsusb=$( lsusb )


RDFM650=$(echo "$lsusb" | grep "ID 2cb7:0a05 " | wc -l)


if [ "$RDFM650" == 1 ]; then


ATPORT=0


MODEMNAME="FM650CN"


else


ATPORT=2


fi


}
 2 changes: 2 additions & 0 deletions luci-app-cpe/root/usr/share/cpe/delatcmd.sh
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,2 @@


#!/bin/sh


rm -f /tmp/result.at
 418 changes: 418 additions & 0 deletions luci-app-cpe/root/usr/share/cpe/rssi

Large diffs are not rendered by default.

 33 changes: 33 additions & 0 deletions sendat/Makefile
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,33 @@


include $(TOPDIR)/rules.mk#将openwrt顶层目录下的rules.mk文件中的内容导入进来





PKG_NAME:=sendat#软件包名


PKG_VERSION:=6.8.2#软件包版本


PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)#真正编译当前软件包的目录








include $(INCLUDE_DIR)/package.mk#将$(TOPDIR)/include目录下的package.mk文件中的内容导入进来





define Package/sendat


SECTION:=wrtnode#软件包类型


CATEGORY:=Daocaoren#menuconfig中软件包所属的一级目录


SUBMENU :=CPE#menuconfig中软件包所属的二级目录


TITLE:=Sendat AT#软件包标题


DEPENDS:=+libpthread#运行本软件依赖的其他包


endef





define Package/sendat/description #软件包描述


A sample for sendat test


endef





define Build/Prepare #编译之前的准备动作


mkdir -p $(PKG_BUILD_DIR)


$(CP) ./src/* $(PKG_BUILD_DIR)/


endef








define Package/sendat/install #软件包的安装方法,主要就是将一系列编译好的文件、启动脚本、UCI配置文件等拷贝到指定位置


$(INSTALL_DIR) $(1)/bin


$(INSTALL_BIN) $(PKG_BUILD_DIR)/sendat $(1)/bin/


endef





$(eval $(call BuildPackage,sendat))
 5 changes: 5 additions & 0 deletions sendat/README.md
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,5 @@


# sendat


AT 命令工具


1简化使用AT命令请求方式


使用命令说明


sendat 2 'ATI'  2表示 /dev/ttyUSB2  'ATI' 为at命令
 9 changes: 9 additions & 0 deletions sendat/src/Makefile
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,9 @@


all:sendat





OBJS = sendat.o





sendat:$(OBJS)


$(CC) $(CFLAGS) -o $@ $(OBJS) -lpthread





clean:


rm -f sendat *.o
 420 changes: 420 additions & 0 deletions sendat/src/pdu.c

Large diffs are not rendered by default.

 52 changes: 52 additions & 0 deletions sendat/src/pdu.h
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,52 @@


/*


* 2017 - 2021 Cezary Jackiewicz <cezary@eko.one.pl>


* 2014 lovewilliam <ztong@vt.edu>


*/


// Copyright 2011 The Avalon Project Authors. All rights reserved.


// Use of this source code is governed by the Apache License 2.0


// that can be found in the LICENSE file.


#ifndef SMS_PDU_H_


#define SMS_PDU_H_





#include <time.h>





enum { SMS_MAX_PDU_LENGTH  = 256 };





/*


* Encode an SMS message. Output the encoded message into output pdu buffer.


* Returns the length of the SMS encoded message in the output buffer or


* a negative number in case encoding failed (for example provided output buffer


* does not have enough space).


*/


int pdu_encode(const char* service_center_number, const char* phone_number, const char* text,


      unsigned char* pdu, int pdu_size);





/*


* Decode an SMS message. Output the decoded message into the sms text buffer.


* Returns the length of the SMS dencoded message or a negative number in


* case encoding failed (for example provided output buffer has not enough


* space).


*/


int pdu_decode(const unsigned char* pdu, int pdu_len,


       time_t* sms_time,


       char* phone_number, int phone_number_size,


       char* text, int text_size,


       int* tp_dcs,


       int* ref_number,


       int* total_parts,


       int* part_number,


       int* skip_bytes);





int ucs2_to_utf8 (int ucs2, unsigned char * utf8);





int DecodePDUMessage_GSM_7bit(const unsigned char* buffer,


      int buffer_length,


      char* output_sms_text,


      int sms_text_length);





int EncodePDUMessage(const char* sms_text,


     int sms_text_length,


     unsigned char* output_buffer,


     int buffer_size);





#endif   // SMS_SMS_H_
 107 changes: 107 additions & 0 deletions sendat/src/pdu_decoder.c
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,107 @@


/*


* 2014 lovewilliam <ztong@vt.edu>


* SMS PDU Decoder


*/


#include "pdu.h"





#include <stdio.h>


#include <stdlib.h>


#include <string.h>


#include <time.h>


#include <wchar.h>





int ucs2_to_utf8 (int ucs2, unsigned char * utf8);





int sms_decode()


{


char buffer[2*SMS_MAX_PDU_LENGTH+4];


char *p = buffer;


char t[2];


int d;


do


{


t[0] = getchar();


if(t[0]=='\n')


{


break;


}


t[1] = getchar();


if(t[1]=='\n')


{


break;


}


*p = strtol(t,NULL,16);


p++;


}while(1);





time_t sms_time;


char sms_phone[40];


char sms_text[161];


int tp_dcs_type;


int ref_number;


int total_parts;


int part_number;


int skip_bytes;





int sms_text_length = pdu_decode((const unsigned char*)buffer,


sizeof(buffer),


&sms_time,


sms_phone, sizeof(sms_phone),


sms_text, sizeof(sms_text),


&tp_dcs_type,


&ref_number,


&total_parts,


&part_number,


&skip_bytes);





printf("From:%s\n",sms_phone);


printf("Textlen=%d\n",sms_text_length);


char time_data_str[64];


strftime(time_data_str,64,"%D %T", localtime(&sms_time));


printf("Date/Time:%s\n",time_data_str);





if (total_parts > 0) {


printf("Reference number: %d\n", ref_number);


printf("SMS segment %d of %d\n", part_number, total_parts);


}





switch((tp_dcs_type / 4) % 4)


{


case 0:


{


// GSM7 bit


int i = skip_bytes;


if(skip_bytes > 0) i = (skip_bytes*8+6)/7;


for(;i<sms_text_length;i++)


{


printf("%c", sms_text[i]);


}


break;


}


case 2:


{


// UCS2


for(int i = skip_bytes;i<sms_text_length;i+=2)


{


int ucs2_char = 0x000000FF&sms_text[i+1];


ucs2_char|=(0x0000FF00&(sms_text[i]<<8));


unsigned char utf8_char[5];


int len = ucs2_to_utf8(ucs2_char,utf8_char);


int j;


for(j=0;j<len;j++)


{


printf("%c",utf8_char[j]);


}


}


break;


}


default:


break;


}





printf("\n");





return 0;


}






 450 changes: 450 additions & 0 deletions sendat/src/sendat.c

Large diffs are not rendered by default.

 53 changes: 53 additions & 0 deletions sendat/src/ucs2_to_utf8.c
Original file line numberDiff line numberDiff line change


@@ -0,0 +1,53 @@


/*


* 2014 lovewilliam <ztong@vt.edu>


* from http://www.lemoda.net/c/ucs2-to-utf8/ucs2-to-utf8.c


*/


/* Input: a Unicode code point, "ucs2".





  Output: UTF-8 characters in buffer "utf8".





  Return value: the number of bytes written into "utf8", or -1 if


  there was an error.





  This adds a zero byte to the end of the string. It assumes that the


  buffer "utf8" has at least four bytes of space to write to. */





#define UNICODE_SURROGATE_PAIR -2


#define UNICODE_BAD_INPUT -1





int ucs2_to_utf8 (int ucs2, unsigned char * utf8)


{


   if (ucs2 < 0x80) {


       utf8[0] = ucs2;


       utf8[1] = '\0';


       return 1;


   }


   if (ucs2 >= 0x80  && ucs2 < 0x800) {


       utf8[0] = (ucs2 >> 6)   | 0xC0;


       utf8[1] = (ucs2 & 0x3F) | 0x80;


       utf8[2] = '\0';


       return 2;


   }


   if (ucs2 >= 0x800 && ucs2 < 0xFFFF) {


if (ucs2 >= 0xD800 && ucs2 <= 0xDFFF) {


    /* Ill-formed. */


    return UNICODE_SURROGATE_PAIR;


}


       utf8[0] = ((ucs2 >> 12)       ) | 0xE0;


       utf8[1] = ((ucs2 >> 6 ) & 0x3F) | 0x80;


       utf8[2] = ((ucs2      ) & 0x3F) | 0x80;


       utf8[3] = '\0';


       return 3;


   }


   if (ucs2 >= 0x10000 && ucs2 < 0x10FFFF) {


/* http://tidy.sourceforge.net/cgi-bin/lxr/source/src/utf8.c#L380 */


utf8[0] = 0xF0 | (ucs2 >> 18);


utf8[1] = 0x80 | ((ucs2 >> 12) & 0x3F);


utf8[2] = 0x80 | ((ucs2 >> 6) & 0x3F);


utf8[3] = 0x80 | ((ucs2 & 0x3F));


       utf8[4] = '\0';


       return 4;


   }


   return UNICODE_BAD_INPUT;


}





推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

本文链接:https://sg.hqyman.cn/post/7694.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:
打赏





休息一下~~


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

请先 登录 再评论,若不是会员请先 注册

您的IP地址是: