luci-app-qmodem-hc: update

This commit is contained in:
fujr 2024-10-09 13:57:25 +08:00
parent 99d3709f76
commit 54fc042d30
11 changed files with 35 additions and 128 deletions

View File

@ -3,18 +3,18 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-5gmodem-hc PKG_NAME:=luci-app-qmodem-hc
LUCI_TITLE:=hc-g50 sim switch LUCI_TITLE:=hc-g80 sim switch
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
PKG_VERSION:=2.0 PKG_VERSION:=2.1
PKG_LICENSE:=GPLv3 PKG_LICENSE:=GPLv3
PKG_LINCESE_FILES:=LICENSE PKG_LINCESE_FILES:=LICENSE
PKF_MAINTAINER:=fujr PKG_MAINTAINER:=Tom <fjrcn@outlook.com>
LUCI_DEPENDS:=+luci-app-5gmodem LUCI_DEPENDS:=+luci-app-qmodem
define Package/luci-app-5gmodem-hc/conffiles define Package/luci-app-qmodem-hc/conffiles
/etc/config/modem_sim /etc/config/qmodem_hc_sim
endef endef
include $(TOPDIR)/feeds/luci/luci.mk include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -1,12 +1,12 @@
module("luci.controller.modem_hc", package.seeall) module("luci.controller.qmodem_hc", package.seeall)
local http = require "luci.http" local http = require "luci.http"
local fs = require "nixio.fs" local fs = require "nixio.fs"
local json = require("luci.jsonc") local json = require("luci.jsonc")
function index() function index()
--sim卡配置 --sim卡配置
entry({"admin", "network", "modem", "modem_sim"}, cbi("modem_hc/modem_sim"), luci.i18n.translate("SIM Config"), 23).leaf = true entry({"admin", "network", "qmodem", "modem_sim"}, cbi("qmodem_hc/modem_sim"), luci.i18n.translate("SIM Config"), 23).leaf = true
entry({"admin", "network", "modem", "set_sim"}, call("setSIM"), nil).leaf = true entry({"admin", "network", "qmodem", "set_sim"}, call("setSIM"), nil).leaf = true
entry({"admin", "network", "modem", "get_sim"}, call("getSIM"), nil).leaf = true entry({"admin", "network", "qmodem", "get_sim"}, call("getSIM"), nil).leaf = true
end end
function getSimSlot(sim_path) function getSimSlot(sim_path)

View File

@ -1,5 +1,5 @@
m = Map("modem_sim", translate("SIM Settings")) m = Map("qmodem_hc_sim", translate("SIM Settings"))
s = m:section(TypedSection, "global", translate("SIM Settings")) s = m:section(NamedSection,"main","main", translate("SIM Settings"))
s.anonymous = true s.anonymous = true
s.addremove = false s.addremove = false
@ -24,6 +24,6 @@ o.nocreate = true
o.default = "cpewan0" o.default = "cpewan0"
m:section(SimpleSection).template = "modem_hc/modem_sim" m:section(SimpleSection).template = "qmodem_hc/modem_sim"
return m return m

View File

@ -12,7 +12,7 @@
function set_sim(){ function set_sim(){
select = document.getElementById("sim_slot_select"); select = document.getElementById("sim_slot_select");
slot = select.value; slot = select.value;
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "set_sim")%>', {"slot": slot }, XHR.get('<%=luci.dispatcher.build_url("admin", "network", "qmodem", "set_sim")%>', {"slot": slot },
function (x, data) { function (x, data) {
set_sim_view(data); set_sim_view(data);
} }
@ -20,7 +20,7 @@
} }
window.onload=function(){ window.onload=function(){
XHR.get('<%=luci.dispatcher.build_url("admin", "network", "modem", "get_sim")%>', null, XHR.get('<%=luci.dispatcher.build_url("admin", "network", "qmodem", "get_sim")%>', null,
function (x, data) { function (x, data) {
set_sim_view(data); set_sim_view(data);
} }

View File

@ -1,4 +1,4 @@
config global config main main
option sim_auto_switch '1' option sim_auto_switch '1'
option detect_interval '15' option detect_interval '15'
option judge_time '5' option judge_time '5'

View File

@ -2,9 +2,9 @@
USE_PROCD=1 USE_PROCD=1
START=99 START=99
STOP=10 STOP=10
PROG="/usr/share/modem/modem_sim.sh" PROG="/usr/share/qmodem/modem_sim.sh"
start_service() { start_service() {
local sim_auto_switch=$(uci -q get modem_sim.@global[0].sim_auto_switch) local sim_auto_switch=$(uci -q get qmodem_hc_sim.main.sim_auto_switch)
logger -t modem_sim start_service $sim_auto_switch logger -t modem_sim start_service $sim_auto_switch
if [ "$sim_auto_switch" == 1 ];then if [ "$sim_auto_switch" == 1 ];then
start_instace start_instace
@ -15,7 +15,7 @@ start_service() {
start_instace(){ start_instace(){
procd_open_instance "$PROG" procd_open_instance "$PROG"
procd_set_param command /usr/share/modem/modem_sim.sh procd_set_param command /usr/share/qmodem/modem_sim.sh
procd_close_instance procd_close_instance
logger -t modem_sim running logger -t modem_sim running
} }
@ -31,5 +31,5 @@ stop_service() {
} }
service_triggers() { service_triggers() {
procd_add_reload_trigger 'modem_sim' procd_add_reload_trigger 'qmodem_hc_sim'
} }

View File

@ -1,15 +1,15 @@
#!/bin/sh #!/bin/sh
sim_gpio="/sys/class/gpio/sim/value" sim_gpio="/sys/class/gpio/sim/value"
modem_gpio="/sys/class/gpio/4g/value" modem_gpio="/sys/class/gpio/4g/value"
ping_dest=$(uci -q get modem_sim.@global[0].ping_dest) ping_dest=$(uci -q get qmodem_hc_sim.main.ping_dest)
wwan_ifname=$(uci -q get modem_sim.@global[0].wwan_ifname) wwan_ifname=$(uci -q get qmodem_hc_sim.main.wwan_ifname)
[ -n $wwan_ifname ] && modem_config=$wwan_ifname [ -n $wwan_ifname ] && modem_config=$(uci -q get network.$wwan_ifname.modem_config)
is_empty=$(uci -q get modem.$modem_config) is_empty=$(uci -q get qmodem.$modem_config)
[ -z $is_empty ] && unset modem_config [ -z $is_empty ] && unset modem_config
[ -z "$modem_config" ] && get_first_avalible_config [ -z "$modem_config" ] && get_first_avalible_config
netdev=$(ifstatus $wwan_ifname | jq -r .device) netdev=$(ifstatus $wwan_ifname | jq -r .device)
judge_time=$(uci -q get modem_sim.@global[0].judge_time) judge_time=$(uci -q get qmodem_hc_sim.main.judge_time)
detect_interval=$(uci -q get modem_sim.@global[0].detect_interval) detect_interval=$(uci -q get qmodem_hc_sim.main.detect_interval)
[ -z $detect_interval ] && detect_interval=10 [ -z $detect_interval ] && detect_interval=10
[ -z $judge_time ] && judge_time=5 [ -z $judge_time ] && judge_time=5
@ -24,7 +24,7 @@ set_modem_config()
get_first_avalible_config() get_first_avalible_config()
{ {
. /lib/functions.sh . /lib/functions.sh
config_load modem config_load qmodem
config_foreach set_modem_config modem-device config_foreach set_modem_config modem-device
} }
@ -32,7 +32,7 @@ sendat()
{ {
tty=$1 tty=$1
cmd=$2 cmd=$2
sms_tool -d $tty at $cmd 2>&1 sms_tool_q -d $tty at $cmd 2>&1
} }
reboot_modem() { reboot_modem() {
@ -103,11 +103,11 @@ at_sim_monitor() {
precheck() precheck()
{ {
modem_config=$1 modem_config=$1
config=$(uci -q show modem.$modem_config) config=$(uci -q show qmodem.$modem_config)
[ -z "$config" ] && return 1 [ -z "$config" ] && return 1
ttydev=$(uci -q get modem.$modem_config.at_port) ttydev=$(uci -q get qmodem.$modem_config.at_port)
enable_dial=$(uci -q get modem.$modem_config.enable_dial) enable_dial=$(uci -q get qmodem.$modem_config.enable_dial)
global_en=$(uci -q get modem.global.enable_dial) global_en=$(uci -q get qmodem.global.enable_dial)
[ "$global_en" == "0" ] && return 1 [ "$global_en" == "0" ] && return 1
[ -z "$enable_dial" ] || [ "$enable_dial" == "0" ] && return 1 [ -z "$enable_dial" ] || [ "$enable_dial" == "0" ] && return 1
[ -z "$ttydev" ] && return 1 [ -z "$ttydev" ] && return 1
@ -133,8 +133,8 @@ main_monitor() {
ping_result=$? ping_result=$?
fi fi
[ -z $ttydev ] && ttydev=$(uci -q get modem.$modem_config.at_port) [ -z $ttydev ] && ttydev=$(uci -q get qmodem.$modem_config.at_port)
[ -z $define_connect ] && define_connect=$(uci -q get modem.$modem_config.define_connect) [ -z $define_connect ] && define_connect=$(uci -q get qmodem.$modem_config.define_connect)
if [ -n $define_connect ] && [ -n $ttydev ];then if [ -n $define_connect ] && [ -n $ttydev ];then
at_dial_monitor $ttydev $define_connect at_dial_monitor $ttydev $define_connect
dial_result=$? dial_result=$?

View File

@ -1,28 +0,0 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=sms-tool_q
PKG_RELEASE:=1
PKG_SOURCE_URL:=https://github.com/obsy/sms_tool
PKG_SOURCE_PROTO:=git
PKG_SOURCE_DATE:=2024-7-25
PKG_SOURCE_VERSION:=fce2b931c8d749c28b8281363950e963c98324eb
include $(INCLUDE_DIR)/package.mk
define Package/sms-tool_q
SECTION:=utils
CATEGORY:=Utilities
TITLE:=sms tool
URL:=https://github.com/obsy/sms_tool
endef
define Package/sms-tool_q/description
SMS Tool for 3G/4G modem
endef
define Package/sms-tool_q/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/sms_tool $(1)/usr/bin/sms_tool_q
endef
$(eval $(call BuildPackage,sms-tool_q))

View File

@ -1,65 +0,0 @@
--- a/sms_main.c 2024-10-08 23:11:01.169908895 +0800
+++ b/sms_main.c 2024-10-08 23:10:52.929909691 +0800
@@ -200,7 +200,12 @@
{
if(argc < 2)
usage();
- }else if (!strcmp("recv", argv[0]))
+ }
+ else if (!strcmp("send_raw_pdu", argv[0])){
+ if(argc < 2)
+ usage();
+ }
+ else if (!strcmp("recv", argv[0]))
{
}else if (!strcmp("status", argv[0]))
{
@@ -288,6 +293,48 @@
fprintf(stderr,"reading port\n");
}
+ if (!strcmp("send_raw_pdu", argv[0]))
+ {
+ int pdu_len;
+ int pdu_len_except_smsc;
+ char pdustr[1024];
+
+ alarm(5);
+ pdu_len_except_smsc = strlen(argv[1]) / 2 - 1;
+ sprintf(pdustr, "%s%c\r\n", argv[1],0x1A);
+ sprintf(cmdstr, "AT+CMGS=%d\r\n", pdu_len_except_smsc);
+ //set to pdu mode
+ fputs("AT+CMGF=0\r\n", pf);
+ while(fgets(buf, sizeof(buf), pfi)) {
+ if(starts_with("OK", buf))
+ break;
+ }
+ fputs(cmdstr, pf);
+ sleep(1);
+ fputs(pdustr, pf);
+
+ errno = 0;
+
+ while(fgets(buf, sizeof(buf), pfi))
+ {
+ if(starts_with("+CMGS:", buf))
+ {
+ printf("sms sent sucessfully: %s", buf + 7);
+ return 0;
+ } else if(starts_with("+CMS ERROR:", buf))
+ {
+ fprintf(stderr,"sms not sent, code: %s\n", buf + 11);
+ } else if(starts_with("ERROR", buf))
+ {
+ fprintf(stderr,"sms not sent, command error\n");
+ } else if(starts_with("OK", buf))
+ {
+ return 0;
+ }
+ }
+ fprintf(stderr,"reading port\n");
+ }
+
if (!strcmp("recv", argv[0]))
{
alarm(10);