mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 16:03:51 +00:00
feat(dashboard): backport staged refresh and SMS layout from E5
Split lightweight rates from status polling, publish cellular stages early, decode UCS2 operators, and retain MU300 adapters and identity/SMS behavior. Include three-language UI, configuration migration, package inventory guards, and offline regressions.
This commit is contained in:
23 files changed
+916
-153
No files matched your search
@@ -0,0 +1,73 @@
|
||||
E5 看板增量回迁 MU300:第一批(2026-10-10)
|
||||
|
||||
来源:D:\Git\e5-linux,feat/t551m-openwrt,HEAD 7d7df8e。
|
||||
范围依据:来源 docs/MU300-DASHBOARD-BACKPORT-TASKS.zh-CN.md。
|
||||
目标基线:MU300 clean-tf-7.2 的 f092671;实施分支 feat/dashboard-backports-20261010。
|
||||
运营商解析参考 b026b49;短信局部样式参考 edbc146。
|
||||
这是选择性移植,不是两个设备分支的整树合并。
|
||||
|
||||
本批实现
|
||||
|
||||
M01:状态与网速分别刷新。新 rates RPC 只读所选网卡计数,不发 AT、
|
||||
不采集完整系统状态、不更新流量账本,也不写每秒诊断日志。
|
||||
网卡仍由 data_device 或 data_interface/netifd 决定,原有 sipa_eth0 回退保留。
|
||||
速率采用设备 uptime,检查 boot_id、ifindex 和计数回退;失效时重新建立基线。
|
||||
主页状态默认/最小 2 秒、最大 60 秒,网速固定独立 1 秒。
|
||||
轮询按请求开始时间计时;同类请求不重叠,隐藏暂停、返回重设速率基线,
|
||||
卸载或移除页面停止轮询,迟到结果不再绘制。
|
||||
|
||||
旧设置迁移:0.5–<2 秒改为 2 秒,2–60 秒(含小数)保留;空或无效值改为 2。
|
||||
运行中的旧配置在设置页/主页按同一规则解释;安装 postinst 和 UI 服务启动
|
||||
会持久化迁移,已经合规时不写配置。不触碰其他适配设置或锁定状态。
|
||||
|
||||
M02:核心信号、完整工程信号先发布,随后独立发布邻区和最终 QoS/身份资料。
|
||||
前端通过 partial/neigh_pending 区分“还没读完”和“读完但没有数据”。
|
||||
刷新时保留尚未完成的旧字段并提示更新,完成后的空值会正常替换旧值。
|
||||
锁定页元数据使用 cells RPC,不再重复采集完整系统状态;实时信号仍走
|
||||
原来每轮新读的 signal RPC,不把缓存改装成实时数据。
|
||||
相关 RPC 不合批,各区域独立加载;同页在途查询去重,退出后忽略旧响应。
|
||||
沿用原来的 AT 池、1 秒/5 秒后台缓存层,只修正 >= 的过期边界。
|
||||
|
||||
M05:一次 AT+CSCS?;+COPS? 查询匹配字符集与运营商,仅在字符集确认为
|
||||
UCS2 且名称格式合法时解码。数字 PLMN、普通十六进制样式名称不猜测解码。
|
||||
移动、联通、电信、广电常见英文别名统一随界面语言显示,国外名称保留。
|
||||
|
||||
M06:短信收件人移入发送区,会话/消息区和操作按钮改为独立响应式样式。
|
||||
保留全部 MU300 短信 API、短信存储、转发及历史重发屏障。
|
||||
没有引入来源的双卡筛选/发送卡选择器,避免单卡 UI 依赖 E5 后端。
|
||||
样式只作用于短信页面,沿用 Aurora/官方 Bootstrap 的颜色变量。
|
||||
|
||||
M13:新增界面文案同步中文、英语、土耳其语;菜单没有变化,现有 PO/LMO
|
||||
校验通过。ACL 已允许 mu300dash 对象,rates/cells 使用同一权限,不增加
|
||||
文件读取或其他服务权限。插件版本为 1.2.0,仍是独立 luci-app-mu300。
|
||||
包安装和 rootfs 的目录拷贝会纳入新增文件;TF Magisk/通用 release 两条
|
||||
构建入口都新增了 refresh.js、sms.css、rates、operator 和配置迁移的漏件检查。
|
||||
|
||||
明确未移植
|
||||
|
||||
M03/M04:锁定任务 ID、写入后的统一核验;原控制流程暂时保持。
|
||||
M07/M08:清空流量账本、按实际 AP 定位热点开关。
|
||||
M09/M10:USB 状态增强及新网卡自动加入 LAN。
|
||||
M11/M12:没有改动早期回放/AT 服务,原有相关回归仍通过;并未完成新的实机并发审计。
|
||||
双卡、屏幕、驱动、设备树、充电/音频、NV、启动镜像、Wi-Fi 内核补丁全部不带入。
|
||||
保留 f092671 的平台修复和 0d93695 的本机号码实时读取。
|
||||
|
||||
验证记录
|
||||
|
||||
183 项 Python 回归通过(MU300_TEST_SHELLS=dash,bash)。
|
||||
417 项 PowerShell 安装脚本检查通过。
|
||||
OpenWrt 25.12.5 ARM64 隔离容器:64 项后台检查通过。
|
||||
离线浏览器:主页真实 render/独立网速刷新/移除停止请求通过;短信 390px 与
|
||||
1280px、Aurora/Bootstrap 变量、明暗模式、中英土共 24 组布局/翻译检查通过。
|
||||
git diff --check 通过。
|
||||
|
||||
复现命令(在目标仓库执行)
|
||||
|
||||
MU300_TEST_SHELLS=dash,bash python3 -m unittest discover -s tests -v
|
||||
pwsh -NoProfile -File tests/installer.Tests.ps1
|
||||
docker run --rm --platform linux/arm64 -e MU300_TEST_CONTAINER=1 -v REPO:/src:ro --entrypoint ucode mu300-openwrt-base:25.12.5 /src/tests/dashboard_backport.uc
|
||||
python tests/dashboard_sms_layout.py --browser PATH_TO_CHROME
|
||||
|
||||
ucode 集成检查只能在一次性容器中运行,不能在路由器上执行;它会写容器的测试 UCI。
|
||||
布局检查使用隔离浏览器和模拟 RPC,不连接设备或互联网,不等同于完整 LuCI 实机验收。
|
||||
本批未接触实机、未构建 rootfs/Magisk 包、未推送远端;现有安装包仍为旧版本。
|
||||
@@ -1,7 +1,7 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=luci-app-mu300
|
||||
PKG_VERSION:=1.1.0
|
||||
PKG_VERSION:=1.2.0
|
||||
PKG_RELEASE:=1
|
||||
PKG_LICENSE:=MIT
|
||||
PKG_MAINTAINER:=MU300 Linux contributors
|
||||
@@ -42,6 +42,7 @@ endef
|
||||
define Package/luci-app-mu300/postinst
|
||||
#!/bin/sh
|
||||
[ -n "$${IPKG_INSTROOT}" ] || {
|
||||
/usr/libexec/unisoc-modem/refresh-config
|
||||
state=$$(uci -q get unisoc_modem.main.state_dir 2>/dev/null)
|
||||
state=$${state:-/etc/unisoc-modem/lock-state.d}
|
||||
old=/etc/mu300/dash/lock-state.d
|
||||
|
||||
@@ -11,14 +11,16 @@
|
||||
* 质量色不用写死的色值,走 --success/--warning/--danger 与 color-mix,
|
||||
* 深浅两套模式都跟随主题。 */
|
||||
|
||||
var callStatus = rpc.declare({ object: 'mu300dash', method: 'status', expect: { '': {} } });
|
||||
var callSignal = rpc.declare({ object: 'mu300dash', method: 'signal', expect: { '': {} } });
|
||||
var callSysinfo = rpc.declare({ object: 'mu300dash', method: 'sysinfo', expect: { '': {} } });
|
||||
var callRates = rpc.declare({ object: 'mu300dash', method: 'rates', nobatch: true, expect: { '': {} } });
|
||||
var callCells = rpc.declare({ object: 'mu300dash', method: 'cells', nobatch: true, expect: { '': {} } });
|
||||
var callStatus = rpc.declare({ object: 'mu300dash', method: 'status', nobatch: true, expect: { '': {} } });
|
||||
var callSignal = rpc.declare({ object: 'mu300dash', method: 'signal', nobatch: true, expect: { '': {} } });
|
||||
var callSysinfo = rpc.declare({ object: 'mu300dash', method: 'sysinfo', nobatch: true, expect: { '': {} } });
|
||||
var callAct = rpc.declare({ object: 'mu300dash', method: 'act', params: [ 'op', 'arg' ], expect: { '': {} } });
|
||||
var callAt = rpc.declare({ object: 'mu300dash', method: 'at', params: [ 'cmd' ], expect: { '': {} } });
|
||||
var callAtHist = rpc.declare({ object: 'mu300dash', method: 'at_history', expect: { '': {} } });
|
||||
var callLockGet = rpc.declare({ object: 'mu300dash', method: 'lock_get', expect: { '': {} } });
|
||||
var callLockFresh = rpc.declare({ object: 'mu300dash', method: 'lock_get', params: [ 'fresh' ], expect: { '': {} } });
|
||||
var callLockGet = rpc.declare({ object: 'mu300dash', method: 'lock_get', nobatch: true, expect: { '': {} } });
|
||||
var callLockFresh = rpc.declare({ object: 'mu300dash', method: 'lock_get', nobatch: true, params: [ 'fresh' ], expect: { '': {} } });
|
||||
var callLockSet = rpc.declare({ object: 'mu300dash', method: 'lock_set', params: [ 'kind', 'val' ], expect: { '': {} } });
|
||||
var callSmsList = rpc.declare({ object: 'mu300dash', method: 'sms_list', params: [ 'page' ], expect: { '': {} } });
|
||||
var callSmsShow = rpc.declare({ object: 'mu300dash', method: 'sms_show', params: [ 'id' ], expect: { '': {} } });
|
||||
@@ -372,7 +374,11 @@ var DASH_I18N = {
|
||||
'AT 终端': ['AT terminal', 'AT terminali'],
|
||||
'适配设置': ['Adapter settings', 'Bağdaştırıcı ayarları'],
|
||||
'主页刷新间隔(秒)': ['Home dashboard refresh interval (seconds)', 'Ana pano yenileme aralığı (saniye)'],
|
||||
'仅控制主页状态看板的刷新频率;允许 0.5–60 秒,保存后重新进入主页生效。': ['Controls only the home dashboard refresh rate; 0.5–60 seconds. Reopen Home after saving to apply.', 'Yalnızca ana panonun yenileme hızını kontrol eder; 0,5–60 saniye. Kaydettikten sonra uygulamak için Ana Sayfa’yı yeniden açın.'],
|
||||
'主页状态每 2–60 秒刷新,网速独立每秒刷新;旧设置不足 2 秒时按 2 秒处理。保存后重新进入主页生效。': ['Status refreshes every 2–60 seconds; speed refreshes independently every second. Older settings below 2 seconds use 2 seconds. Reopen Home after saving.', 'Durum 2–60 saniyede bir, hız bağımsız olarak her saniye yenilenir. 2 saniyenin altındaki eski ayarlar 2 saniye olarak uygulanır. Kaydettikten sonra Ana Sayfa’yı yeniden açın.'],
|
||||
'正在更新…': ['Updating…', 'Güncelleniyor…'],
|
||||
'读取失败,稍后重试': ['Read failed; retrying shortly', 'Okuma başarısız; kısa süre sonra yeniden denenecek'],
|
||||
'收件人': ['Recipient', 'Alıcı'],
|
||||
'会话': ['Conversations', 'Görüşmeler'],
|
||||
'当前驻网': ['Serving network', 'Bağlı olunan ağ'],
|
||||
'网络模式 · EN-DC': ['Network mode · EN-DC', 'Ağ modu · EN-DC'],
|
||||
'自动(5G/4G)': ['Automatic (5G/4G)', 'Otomatik (5G/4G)'],
|
||||
@@ -579,7 +585,28 @@ var PLMN_CN = {
|
||||
|
||||
function carrierName(op) {
|
||||
if (!op) return '--';
|
||||
return translate(op.name || PLMN_CN[op.plmn] || op.plmn || '--');
|
||||
var name = op.name || PLMN_CN[op.plmn] || op.plmn || '--';
|
||||
var key = String(name).toUpperCase().replace(/[\s_\-]/g, '');
|
||||
var aliases = [
|
||||
[['中国移动', '中国移动通信', 'CHINAMOBILE', 'CHNMOBILE', 'CMCC'], '中国移动'],
|
||||
[['中国联通', 'CHINAUNICOM', 'CHNUNICOM', 'UNICOM', 'CUCC'], '中国联通'],
|
||||
[['中国电信', 'CHINATELECOM', 'CHNCT', 'CHNCTLTE', 'CTCC'], '中国电信'],
|
||||
[['中国广电', 'CHINABROADNET', 'CHNBG', 'CBN', 'CHINABROADCASTINGNETWORK'], '中国广电']
|
||||
];
|
||||
for (var i = 0; i < aliases.length; i++)
|
||||
if (aliases[i][0].indexOf(key) >= 0) return translate(aliases[i][1]);
|
||||
return translate(name);
|
||||
}
|
||||
|
||||
/* Staged snapshots retain only slow fields that have not completed yet.
|
||||
* Explicit null in a completed stage means unavailable, not stale data. */
|
||||
function mergeCell(previous, next) {
|
||||
if (!next) return previous || null;
|
||||
if (!next.partial || !previous || next.error) return Object.assign({}, next);
|
||||
var merged = Object.assign({}, next);
|
||||
['ident', 'qos'].forEach(function(k) { merged[k] = previous[k]; });
|
||||
if (next.neigh_pending) merged.neigh = previous.neigh;
|
||||
return merged;
|
||||
}
|
||||
|
||||
/* 信号质量分级(阈值来自 ufi_tools 的 SignalQuality.kt),返回 CSS 颜色表达式 */
|
||||
@@ -813,7 +840,8 @@ html.mud-bootstrap-theme{--surface:var(--background-color-high);--surface-sunken
|
||||
.mud-toast.notify .mud-nb{display:flex;flex-direction:column;gap:2px;min-width:0}
|
||||
.mud-toast.notify .mud-nb b{font-size:.82rem;font-weight:700}
|
||||
.mud-toast.notify .mud-nb span{font-size:.76rem;color:var(--text-muted,var(--text-light,#888));overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
|
||||
.mud-btn .mud-spin,.mud-lockbtn .mud-spin{flex:0 0 auto;width:12px;height:12px;border-radius:50%;border:2px solid color-mix(in oklab,currentColor 30%,transparent);border-top-color:currentColor;animation:mudspin .7s linear infinite}
|
||||
.mud-progress.is-loading::before{content:'';display:inline-block;margin-right:6px;vertical-align:middle}
|
||||
.mud-progress.is-loading::before,.mud-btn .mud-spin,.mud-lockbtn .mud-spin{flex:0 0 auto;width:12px;height:12px;border-radius:50%;border:2px solid color-mix(in oklab,currentColor 30%,transparent);border-top-color:currentColor;animation:mudspin .7s linear infinite}
|
||||
.mud-btn.busy,.mud-lockbtn.busy{pointer-events:none;opacity:.75}
|
||||
/* ---- 主题化对话框(替代浏览器 confirm/alert) ---- */
|
||||
.mud-dlg-wrap{position:fixed;inset:0;z-index:10000;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.42);animation:mudfade-in .16s ease-out;padding:20px}
|
||||
@@ -1132,7 +1160,7 @@ function choiceBox(title, message, choices, opts) {
|
||||
|
||||
/* LuCI 的 require 把模块当类工厂:必须返回 baseclass 派生的类,加载后拿到的是它的实例 */
|
||||
return baseclass.extend({
|
||||
callStatus: callStatus, callSignal: callSignal, callSysinfo: callSysinfo, callAct: callAct, callAt: callAt, callAtHist: callAtHist,
|
||||
callRates: callRates, callCells: callCells, mergeCell: mergeCell, callStatus: callStatus, callSignal: callSignal, callSysinfo: callSysinfo, callAct: callAct, callAt: callAt, callAtHist: callAtHist,
|
||||
callLockGet: callLockGet, callLockFresh: callLockFresh, callLockSet: callLockSet,
|
||||
callSmsList: callSmsList, callSmsShow: callSmsShow, callSmsSend: callSmsSend,
|
||||
callSmsDel: callSmsDel, callSmsSync: callSmsSync,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
'use strict';
|
||||
'require baseclass';
|
||||
|
||||
/* Independent, start-to-start polling lanes. Hidden pages do no background
|
||||
* work; an in-flight request finishes before its lane can start another. */
|
||||
function poll(request, accept, interval, failed, reset, active) {
|
||||
var stopped = false, running = false, timer, epoch = 0;
|
||||
function stop() {
|
||||
stopped = true;
|
||||
epoch++;
|
||||
clearTimeout(timer);
|
||||
document.removeEventListener('visibilitychange', visibility);
|
||||
}
|
||||
function current(generation) {
|
||||
if (active && !active()) stop();
|
||||
return !stopped && !document.hidden && generation === epoch;
|
||||
}
|
||||
function tick() {
|
||||
clearTimeout(timer);
|
||||
if (active && !active()) stop();
|
||||
if (stopped || running || document.hidden) return;
|
||||
running = true;
|
||||
var started = performance.now(), generation = epoch;
|
||||
Promise.resolve().then(request).then(function(value) {
|
||||
if (current(generation)) accept(value);
|
||||
}, function(error) {
|
||||
if (current(generation) && failed) failed(error);
|
||||
}).catch(function(error) {
|
||||
if (current(generation) && failed) failed(error);
|
||||
}).finally(function() {
|
||||
running = false;
|
||||
if (!stopped && !document.hidden)
|
||||
timer = setTimeout(tick, Math.max(50, interval() - (performance.now() - started)));
|
||||
});
|
||||
}
|
||||
function visibility() {
|
||||
epoch++;
|
||||
clearTimeout(timer);
|
||||
if (reset) reset();
|
||||
if (!document.hidden) tick();
|
||||
}
|
||||
document.addEventListener('visibilitychange', visibility);
|
||||
// Allow LuCI to attach the returned view before the initial response arrives.
|
||||
timer = setTimeout(tick, 0);
|
||||
return stop;
|
||||
}
|
||||
|
||||
function seconds(value) {
|
||||
var n = Number(value);
|
||||
return Number.isFinite(n) && n > 0 && n <= 60 ? Math.max(2, n) : 2;
|
||||
}
|
||||
|
||||
function rateDelta(previous, current) {
|
||||
if (!previous || !current || !current.available || !previous.available ||
|
||||
previous.device !== current.device || previous.ifindex !== current.ifindex ||
|
||||
previous.boot_id !== current.boot_id) return null;
|
||||
var dt = current.ts - previous.ts;
|
||||
if (!(dt > 0) || current.rx < previous.rx || current.tx < previous.tx) return null;
|
||||
var dl = (current.rx - previous.rx) / dt, ul = (current.tx - previous.tx) / dt;
|
||||
return Number.isFinite(dl) && Number.isFinite(ul) ? { dl: dl, ul: ul } : null;
|
||||
}
|
||||
|
||||
return baseclass.extend({ poll: poll, seconds: seconds, rateDelta: rateDelta });
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require uci';
|
||||
'require mu300.refresh as R';
|
||||
'require mu300.common as M';
|
||||
|
||||
/* MU300 状态看板 -- LuCI 落地页(menu.d 挂在 admin/home)。
|
||||
@@ -8,18 +9,15 @@
|
||||
* 布局:顶部驻网卡片是唯一的卡片;其余都是全宽分区(链路与流量 / 邻区 / 无线·局域网·
|
||||
* 设备·SIM / 快捷控制)。锁频、短信、AT 终端在「蜂窝」子菜单。
|
||||
*
|
||||
* 数据只有一个来源:ubus mu300dash status(info 快照 + sig 快档蜂窝缓存 + cell 慢档缓存)。
|
||||
* 页面默认 1.5 s 一轮:信号/速率/CPU 每轮都刷;邻区/QoS/身份只在慢档时间戳变化时重绘。
|
||||
* 状态走 status,网速独立走无 AT 的 rates;隐藏页面停止轮询。
|
||||
* 状态默认 2 s 一轮、网速 1 s 一轮;慢档数据分段发布并保留尚未完成的旧值。
|
||||
* 邻区行内「锁定」走 lock_set cell(SFUN 重启协议栈,约半分钟断网);锁定状态来自
|
||||
* lock_get(页面加载时取一次,锁定操作后刷新)。 */
|
||||
|
||||
var DEFAULT_POLL_S = 1.5;
|
||||
var DEFAULT_POLL_S = 2;
|
||||
var RATE_WIN = 40;
|
||||
|
||||
function pollSeconds(value) {
|
||||
var seconds = Number(value);
|
||||
return Number.isFinite(seconds) && seconds >= 0.5 && seconds <= 60 ? seconds : DEFAULT_POLL_S;
|
||||
}
|
||||
function pollSeconds(value) { return R.seconds(value); }
|
||||
|
||||
/* 工程口只提供 MCS/BLER;调制方式按 3GPP 常用 MCS table 1 就地换算,
|
||||
* 不为展示项增加 AT 请求。LTE 上行的 MCS 分界与下行/NR 不同。 */
|
||||
@@ -68,30 +66,51 @@ return view.extend({
|
||||
this.wire(root);
|
||||
var self = this;
|
||||
var intervalMs = DEFAULT_POLL_S * 1000;
|
||||
var config = L.resolveDefault(uci.load('unisoc_modem')).then(function() {
|
||||
L.resolveDefault(uci.load('unisoc_modem')).then(function() {
|
||||
intervalMs = pollSeconds(uci.get('unisoc_modem', 'main', 'home_refresh_interval')) * 1000;
|
||||
});
|
||||
/* 立即取一次完整状态;不要同时重复执行 sysinfo 与 status 两轮本地采集。 */
|
||||
var first = L.resolveDefault(M.callStatus()).then(function(st) {
|
||||
self.update(st || {});
|
||||
});
|
||||
/* LuCI poll.add() truncates intervals to whole seconds. Use a one-shot
|
||||
* timer so 1.5 s remains 1.5 s and slow requests never overlap. */
|
||||
function refresh() {
|
||||
if (!document.documentElement.contains(root)) return;
|
||||
L.resolveDefault(M.callStatus()).then(function(st) { self.update(st || {}); }).finally(function() {
|
||||
if (document.documentElement.contains(root))
|
||||
self._refreshTimer = setTimeout(refresh, intervalMs);
|
||||
});
|
||||
}
|
||||
Promise.all([first, config]).then(function() {
|
||||
self._refreshTimer = setTimeout(refresh, intervalMs);
|
||||
});
|
||||
this._disposed = false;
|
||||
var active = function() { return !self._disposed && root.isConnected; };
|
||||
this._stopStatus = R.poll(M.callStatus, function(st) { self.update(st || {}); },
|
||||
function() { return intervalMs; }, null, null, active);
|
||||
this._stopRates = R.poll(M.callRates, function(sample) { self.updateRates(sample); },
|
||||
function() { return 1000; }, function() { self.updateRates(null); },
|
||||
function() { self.lastNet = null; }, active);
|
||||
|
||||
return root;
|
||||
},
|
||||
|
||||
unload: function() {
|
||||
clearTimeout(this._refreshTimer);
|
||||
this._disposed = true;
|
||||
clearTimeout(this._lockTimer);
|
||||
if (this._stopStatus) this._stopStatus();
|
||||
if (this._stopRates) this._stopRates();
|
||||
},
|
||||
|
||||
updateRates: function(sample) {
|
||||
var delta = R.rateDelta(this.lastNet, sample);
|
||||
if (!delta) {
|
||||
this.dlHist = []; this.ulHist = [];
|
||||
M.v('spark-dl').innerHTML = ''; M.v('spark-ul').innerHTML = '';
|
||||
}
|
||||
this.lastNet = sample && sample.available ? sample : null;
|
||||
if (!this.lastNet) {
|
||||
M.set('dl', '--'); M.set('ul', '--');
|
||||
M.set('rx', '--'); M.set('tx', '--');
|
||||
return;
|
||||
}
|
||||
M.set('rx', M.fmtBytes(sample.rx)); M.set('tx', M.fmtBytes(sample.tx));
|
||||
if (!delta) {
|
||||
M.set('dl', '--'); M.set('ul', '--');
|
||||
this.dlHist = []; this.ulHist = [];
|
||||
} else {
|
||||
M.set('dl', M.fmtRate(delta.dl)); M.set('ul', M.fmtRate(delta.ul));
|
||||
this.dlHist.push(delta.dl); this.ulHist.push(delta.ul);
|
||||
if (this.dlHist.length > RATE_WIN) { this.dlHist.shift(); this.ulHist.shift(); }
|
||||
}
|
||||
var peak = Math.max(1, Math.max.apply(null, this.dlHist.concat(this.ulHist)));
|
||||
M.spark(M.v('spark-dl'), this.dlHist, 0, peak, RATE_WIN);
|
||||
M.spark(M.v('spark-ul'), this.ulHist, 0, peak, RATE_WIN);
|
||||
},
|
||||
|
||||
html: function() {
|
||||
@@ -226,6 +245,7 @@ return view.extend({
|
||||
</div>
|
||||
<div class="mud-sec">
|
||||
<h3>邻区</h3>
|
||||
<div class="mud-note mud-progress" id="mud-slow-progress" role="status"></div>
|
||||
<div class="mud-scroll">
|
||||
<table class="mud-table"><thead><tr><th>制式/频段</th><th>PCI</th><th>频点</th><th>RSRP</th><th>RSRQ</th><th>SINR</th><th></th></tr></thead>
|
||||
<tbody id="mud-neigh"><tr><td colspan="7" style="color:var(--text-muted,var(--text-light,#777))">--</td></tr></tbody></table>
|
||||
@@ -311,7 +331,7 @@ return view.extend({
|
||||
M.busy(btn, false);
|
||||
M.toast(r.ok ? '已后台锁定 ' + key + ',稍后自动刷新状态' : '锁定失败:' + (r.error || '未知错误'),
|
||||
{ type: r.ok ? 'success' : 'error' });
|
||||
setTimeout(function() { self.refreshLock(); }, 35000);
|
||||
self._lockTimer = setTimeout(function() { self.refreshLock(); }, 35000);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -319,8 +339,10 @@ return view.extend({
|
||||
},
|
||||
|
||||
refreshLock: function() {
|
||||
if (this._disposed) return;
|
||||
var self = this;
|
||||
L.resolveDefault(M.callLockGet()).then(function(l) {
|
||||
if (self._disposed) return;
|
||||
self.lockedCell = (l || {}).cells || [];
|
||||
self.repaintNeigh();
|
||||
});
|
||||
@@ -352,8 +374,15 @@ return view.extend({
|
||||
this._bootEl.classList.remove('mud-booting');
|
||||
this._bootEl = null;
|
||||
}
|
||||
/* 快档覆盖:sig(服务小区/注册,1.5 s 级)盖在慢档缓存 c 的对应字段上 */
|
||||
var c = st.cell || null;
|
||||
/* 快档覆盖:sig(服务小区/注册)盖在慢档缓存 c 的对应字段上 */
|
||||
this._slowCell = M.mergeCell(this._slowCell, st.cell);
|
||||
var pending = !st.cell || !!st.cell.partial || !!st.refreshing;
|
||||
var progress = M.v('slow-progress');
|
||||
if (progress) {
|
||||
progress.classList.toggle('is-loading', pending && !(st.cell && st.cell.error));
|
||||
progress.textContent = M.translate(st.cell && st.cell.error ? '读取失败,稍后重试' : pending ? '正在更新…' : '');
|
||||
}
|
||||
var c = this._slowCell;
|
||||
var s = st.sig || null;
|
||||
if (s && !s.error && (!c || !c.ts || (s.ts || 0) >= c.ts)) {
|
||||
if (c && s.partial) {
|
||||
@@ -368,7 +397,7 @@ return view.extend({
|
||||
}
|
||||
this.lastCell = c;
|
||||
/* 慢档数据(邻区/运营商/身份)只在整份缓存的时间戳变化时重绘 */
|
||||
var fullTs = (st.cell && st.cell.ts) || 0;
|
||||
var fullTs = st.cell ? [st.cell.ts, st.cell.partial || 0, st.cell.neigh_pending || 0].join(':') : '';
|
||||
var slowChanged = fullTs !== this.lastFullTs;
|
||||
this.lastFullTs = fullTs;
|
||||
|
||||
@@ -439,23 +468,6 @@ return view.extend({
|
||||
M.set('qci', qos && qos.qci != null ? qos.qci : '--');
|
||||
M.set('ambr', qos && qos.dl != null ? qos.dl + ' / ' + qos.ul + ' Mbps' : '--');
|
||||
|
||||
var net = (i.net && (i.net.mobile || i.net.sipa_eth0)) || null;
|
||||
if (net && this.lastNet && i.ts && this.lastNet.ts) {
|
||||
var dt = i.ts - this.lastNet.ts;
|
||||
if (dt > 0) {
|
||||
var dl = (net.rx - this.lastNet.rx) / dt, ul = (net.tx - this.lastNet.tx) / dt;
|
||||
M.set('dl', M.fmtRate(dl)); M.set('ul', M.fmtRate(ul));
|
||||
this.dlHist.push(dl); this.ulHist.push(ul);
|
||||
if (this.dlHist.length > RATE_WIN) { this.dlHist.shift(); this.ulHist.shift(); }
|
||||
var peak = Math.max(1, Math.max.apply(null, this.dlHist.concat(this.ulHist)));
|
||||
M.spark(M.v('spark-dl'), this.dlHist, 0, peak, RATE_WIN);
|
||||
M.spark(M.v('spark-ul'), this.ulHist, 0, peak, RATE_WIN);
|
||||
}
|
||||
}
|
||||
if (net) {
|
||||
M.set('rx', M.fmtBytes(net.rx)); M.set('tx', M.fmtBytes(net.tx));
|
||||
this.lastNet = { ts: i.ts, rx: net.rx, tx: net.tx };
|
||||
}
|
||||
var w = i.wan || {};
|
||||
var traffic = i.traffic && i.traffic.clock_ok && i.ts - i.traffic.updated_at < 30 ? i.traffic : null;
|
||||
M.set('tr-day', traffic ? M.fmtTrafficBytes(traffic.today_used) : '--');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
'require view';
|
||||
'require poll';
|
||||
'require mu300.refresh as R';
|
||||
'require mu300.common as M';
|
||||
|
||||
/* 网络锁定 -- 模式 / 频段 / 小区 / EN-DC,全部经 ubus mu300dash lock_set -> 后端
|
||||
@@ -8,7 +8,7 @@
|
||||
* 开机由插件自己的 procd 服务在 AT 适配器就绪后回放,不依赖平台拨号脚本。
|
||||
*
|
||||
* 当前驻网 hero 每 2 秒执行一次独立的实时 AT 快照,不读取蜂窝缓存;运营商与
|
||||
* 邻区等低频元数据只在打开页面时从 status 取一次。
|
||||
* 邻区等低频元数据独立轮询 cells,按阶段显示,不阻塞实时信号。
|
||||
* 邻区表每行带「锁定」按钮,与主页共用 M.neighborRows。 */
|
||||
|
||||
var MODES = [ [ 'auto', '自动' ], [ '4g', '仅 4G' ], [ 'sa', '5G SA' ], [ 'nsa', '5G NSA' ] ];
|
||||
@@ -22,6 +22,9 @@ return view.extend({
|
||||
M.injectCss();
|
||||
M.watchSms();
|
||||
var root = document.createElement('div');
|
||||
this._root = root;
|
||||
this._disposed = false;
|
||||
this._timers = [];
|
||||
root.className = 'mud';
|
||||
root.innerHTML = `
|
||||
<!-- 与主页同一套 hero 结构:mud-hero-l/mud-hero-r 让手机端媒体查询统一生效
|
||||
@@ -31,6 +34,7 @@ return view.extend({
|
||||
<div style="font-size:.78rem;color:var(--text-muted,var(--text-light,#777))">当前驻网</div>
|
||||
<div style="font-size:1.25rem;font-weight:700;margin-top:2px" id="mud-srv-rat">--</div>
|
||||
<div class="mud-cellline" id="mud-srv"></div>
|
||||
<div class="mud-note mud-progress" id="mud-serving-progress" role="status"></div>
|
||||
</div>
|
||||
<div class="mud-hero-r">
|
||||
<div class="mud-rsrp" id="mud-srv-rsrp" style="font-size:1.9rem">--</div>
|
||||
@@ -40,6 +44,7 @@ return view.extend({
|
||||
|
||||
<div class="mud-sec">
|
||||
<h3>网络模式 · EN-DC</h3>
|
||||
<div class="mud-note mud-progress" id="mud-lock-progress" role="status"></div>
|
||||
<div class="mud-ctl" id="mud-lock-modes" style="grid-template-columns:repeat(4,1fr);max-width:520px"></div>
|
||||
<div class="mud-ctl" style="margin-top:7px;grid-template-columns:1fr 1fr;max-width:340px">
|
||||
<button class="mud-btn" id="mud-lock-endc">EN-DC</button>
|
||||
@@ -75,6 +80,7 @@ return view.extend({
|
||||
|
||||
<div class="mud-sec">
|
||||
<h3>邻区与小区锁定</h3>
|
||||
<div class="mud-note mud-progress" id="mud-neighbor-progress" role="status"></div>
|
||||
<div id="mud-lockedcells"></div>
|
||||
<div class="mud-ctl" style="max-width:400px;margin-bottom:8px">
|
||||
<button class="mud-btn" id="mud-lock-cell">锁定当前服务小区</button>
|
||||
@@ -103,7 +109,8 @@ return view.extend({
|
||||
M.confirmBox('应用「' + what + '」?',
|
||||
opts.noSfun ? '' : '协议栈会重启(SFUN),蜂窝断开约半分钟。',
|
||||
{ danger: !opts.noSfun, okText: '应用' })
|
||||
.then(function(go) { if (go) applyNow(kind, val, what, opts); });
|
||||
.then(function(go) {
|
||||
if (self._disposed) return; if (go) applyNow(kind, val, what, opts); });
|
||||
};
|
||||
var applyNow = function(kind, val, what, opts) {
|
||||
var btn = opts.btn;
|
||||
@@ -111,6 +118,7 @@ return view.extend({
|
||||
M.busy(btn, true); /* 在 optimistic 之后:它可能重置按钮的 className */
|
||||
self.note('正在后台应用 ' + what + ' …' + (opts.noSfun ? '' : '(SFUN 重启 + 重新驻网,约半分钟)'), 'busy');
|
||||
L.resolveDefault(M.callLockSet(kind, val)).then(function(r) {
|
||||
if (self._disposed) return;
|
||||
r = r || {};
|
||||
if (!r.ok) {
|
||||
M.busy(btn, false);
|
||||
@@ -170,12 +178,13 @@ return view.extend({
|
||||
M.busy(btn, true);
|
||||
self.note('正在直读调制解调器(最多几秒)…', 'busy');
|
||||
L.resolveDefault(M.callLockFresh('1')).then(function(l) {
|
||||
if (self._disposed) return;
|
||||
M.busy(btn, false);
|
||||
self.lastLock = l || {};
|
||||
self.paint();
|
||||
self.note('已刷新', 'success');
|
||||
var nb = self.Q('neigh');
|
||||
if (nb && self.lastCell) nb.innerHTML = M.neighborRows(self.lastCell, self.lastLock.cells || []);
|
||||
if (nb && self.lastCell) nb.innerHTML = M.neighborRows(self.neighborCell || self.lastCell, self.lastLock.cells || []);
|
||||
}, function() { M.busy(btn, false); self.note('刷新失败', 'error'); });
|
||||
self.loadServing();
|
||||
};
|
||||
@@ -226,10 +235,12 @@ return view.extend({
|
||||
var rat = btn.getAttribute('data-unlock');
|
||||
M.confirmBox('解除 ' + rat.toUpperCase() + ' 的小区锁定', '协议栈会重启(SFUN),约半分钟。', { danger: true })
|
||||
.then(function(go) {
|
||||
if (self._disposed) return;
|
||||
if (!go) return;
|
||||
M.busy(btn, true);
|
||||
self.note('正在解除 ' + rat.toUpperCase() + ' 小区锁定…', 'busy');
|
||||
L.resolveDefault(M.callLockSet('cell', 'off-' + rat)).then(function(r) {
|
||||
if (self._disposed) return;
|
||||
r = r || {};
|
||||
M.busy(btn, false);
|
||||
if (!r.ok) { self.note('解锁失败:' + (r.error || '未知错误'), 'error'); return; }
|
||||
@@ -246,10 +257,12 @@ return view.extend({
|
||||
var key = btn.getAttribute('data-lock');
|
||||
M.confirmBox('锁定小区 ' + key.replace(':', ' ') + '?', '协议栈会重启(SFUN),蜂窝断开约半分钟。', { danger: true })
|
||||
.then(function(go) {
|
||||
if (self._disposed) return;
|
||||
if (!go) return;
|
||||
M.busy(btn, true);
|
||||
self.note('正在后台锁定 ' + key + ' …', 'busy');
|
||||
L.resolveDefault(M.callLockSet('cell', key)).then(function(r) {
|
||||
if (self._disposed) return;
|
||||
r = r || {};
|
||||
M.busy(btn, false);
|
||||
if (!r.ok) { self.note('锁定失败:' + (r.error || '未知错误'), 'error'); return; }
|
||||
@@ -259,43 +272,96 @@ return view.extend({
|
||||
});
|
||||
});
|
||||
|
||||
this.loading('serving', true);
|
||||
this.loading('neighbor', true);
|
||||
this.loading('lock', true);
|
||||
this.refresh();
|
||||
this.loadServingMeta();
|
||||
this.loadServing();
|
||||
poll.add(function() { return self.loadServing(); }, 2);
|
||||
var active = function() { return !self._disposed && root.isConnected; };
|
||||
this._stopMeta = R.poll(function() { return self.loadServingMeta(); }, function() {}, function() { return 2000; }, null, null, active);
|
||||
this._stopSignal = R.poll(function() { return self.loadServing(); }, function() {}, function() { return 2000; }, null, null, active);
|
||||
},
|
||||
|
||||
/* 统一反馈:所有提示走顶部 toast(M.toast),进行中的用 busy 自带转圈;
|
||||
* 同一时间只保留一条(新提示顶掉旧提示,进度→结果一路更新不堆叠)。 */
|
||||
note: function(txt, type) {
|
||||
if (this._disposed) return;
|
||||
if (this._toast) this._toast.close();
|
||||
this._toast = M.toast(txt, { type: type || 'info' });
|
||||
},
|
||||
|
||||
/* 运营商与邻区属于低频元数据;实时信号不会从这里读取。 */
|
||||
loadServingMeta: function() {
|
||||
var self = this;
|
||||
return L.resolveDefault(M.callStatus()).then(function(st) {
|
||||
self.servingMeta = (st || {}).cell || {};
|
||||
});
|
||||
unload: function() {
|
||||
this._disposed = true;
|
||||
if (this._stopMeta) this._stopMeta();
|
||||
if (this._stopSignal) this._stopSignal();
|
||||
(this._timers || []).forEach(clearTimeout);
|
||||
if (this._toast) this._toast.close();
|
||||
},
|
||||
|
||||
/* 每次都由后端完成一轮新的 AT 快照;不接受上一轮 signal/cell 缓存。 */
|
||||
loadServing: function() {
|
||||
later: function(fn, ms) {
|
||||
var self = this;
|
||||
return L.resolveDefault(M.callSignal()).then(function(live) {
|
||||
live = live || {};
|
||||
var c = {}, meta = self.servingMeta || {};
|
||||
Object.keys(meta).forEach(function(k) { c[k] = meta[k]; });
|
||||
Object.keys(live).forEach(function(k) { c[k] = live[k]; });
|
||||
self.paintServing(c);
|
||||
if (this._disposed) return;
|
||||
var timer = setTimeout(function() {
|
||||
self._timers = self._timers.filter(function(t) { return t !== timer; });
|
||||
if (!self._disposed) fn();
|
||||
}, ms);
|
||||
this._timers.push(timer);
|
||||
return timer;
|
||||
},
|
||||
|
||||
loading: function(part, pending, failed) {
|
||||
var el = this.Q(part + '-progress');
|
||||
if (!el || this._disposed) return;
|
||||
el.classList.toggle('is-loading', !!pending && !failed);
|
||||
el.textContent = M.translate(failed ? '读取失败,稍后重试' : pending ? '正在更新…' : '');
|
||||
},
|
||||
|
||||
loadServingMeta: function() {
|
||||
if (this._disposed) return Promise.resolve();
|
||||
if (this._metaRequest) return this._metaRequest;
|
||||
var self = this;
|
||||
this._metaRequest = M.callCells().then(function(st) {
|
||||
if (self._disposed || (self._root && !self._root.isConnected) || document.hidden) return;
|
||||
st = st || {};
|
||||
self.servingMeta = M.mergeCell(self.servingMeta, st.cell) || {};
|
||||
if (st.cell && !st.cell.neigh_pending && !st.cell.error) self.neighborCell = st.cell;
|
||||
// A cheap cached core paints immediately while the live lane completes.
|
||||
var signal = self.liveSignal || st.sig;
|
||||
if (signal && signal.partial && self.servingMeta.ts)
|
||||
signal = { ts: signal.ts, cfun: signal.cfun, reg: signal.reg, reg5g: signal.reg5g };
|
||||
self.paintServing(Object.assign({}, self.servingMeta, signal || {}));
|
||||
self.loading('neighbor', !st.cell || !!st.cell.neigh_pending || !!st.refreshing,
|
||||
!!(st.cell && st.cell.error));
|
||||
}, function() { self.loading('neighbor', false, true); }).finally(function() {
|
||||
self._metaRequest = null;
|
||||
});
|
||||
return this._metaRequest;
|
||||
},
|
||||
|
||||
/* Always a newly completed AT round; never replace the 2 s live hero
|
||||
* with the full-cache engineering fields while a live request is pending. */
|
||||
loadServing: function() {
|
||||
if (this._disposed) return Promise.resolve();
|
||||
if (this._signalRequest) return this._signalRequest;
|
||||
var self = this;
|
||||
this.loading('serving', true);
|
||||
this._signalRequest = M.callSignal().then(function(live) {
|
||||
if (self._disposed || (self._root && !self._root.isConnected) || document.hidden) return;
|
||||
if (!live || live.error || !live.ts) {
|
||||
self.loading('serving', false, true); return;
|
||||
}
|
||||
self.liveSignal = live;
|
||||
self.paintServing(Object.assign({}, self.servingMeta || {}, live));
|
||||
self.loading('serving', false);
|
||||
}, function() { self.loading('serving', false, true); }).finally(function() {
|
||||
self._signalRequest = null;
|
||||
});
|
||||
return this._signalRequest;
|
||||
},
|
||||
|
||||
paintServing: function(c) {
|
||||
var e = this.Q('srv'); if (!e) return;
|
||||
var e = this.Q('srv'); if (!e || this._disposed) return;
|
||||
this.lastCell = c;
|
||||
if (!c || c.error) {
|
||||
if (!c || !c.ts || c.error) {
|
||||
this.Q('srv-rat').textContent = c && c.error ? c.error : M.translate('暂无驻网数据');
|
||||
e.innerHTML = '';
|
||||
return;
|
||||
@@ -308,6 +374,7 @@ return view.extend({
|
||||
this.Q('srv-rat').textContent = ratTxt + ' · ' + operName;
|
||||
this.Q('srv-rat').style.color = M.qCol(label);
|
||||
var rsrpEl = this.Q('srv-rsrp');
|
||||
rsrpEl.textContent = '--';
|
||||
if (sig.rsrp != null) { rsrpEl.innerHTML = sig.rsrp.toFixed(1) + '<small> dBm</small>'; rsrpEl.style.color = M.qCol(label); }
|
||||
this.Q('srv-chips').innerHTML =
|
||||
(sig.rsrq != null ? '<span class="mud-tag">RSRQ ' + sig.rsrq.toFixed(1) + '</span>' : '') +
|
||||
@@ -319,7 +386,7 @@ return view.extend({
|
||||
return '<div class="mud-srvline"><span class="k">' + M.esc(M.translate(x[0])) + '</span><span class="v">' + M.esc(x[1]) + '</span></div>';
|
||||
}).join('');
|
||||
var nb = this.Q('neigh');
|
||||
if (nb) nb.innerHTML = M.neighborRows(c, (this.lastLock || {}).cells || []);
|
||||
if (nb) nb.innerHTML = M.neighborRows(this.neighborCell || c, (this.lastLock || {}).cells || []);
|
||||
},
|
||||
|
||||
/* 应用后自动回读:轮询缓存 lock_get 直到 ts 越过本次应用(后端 apply 后会 fresh 刷新缓存) */
|
||||
@@ -329,20 +396,21 @@ return view.extend({
|
||||
var self = this, tries = 0, t0 = t0ms || Date.now();
|
||||
var step = function() {
|
||||
L.resolveDefault(M.callLockGet()).then(function(l) {
|
||||
if (self._disposed) return;
|
||||
l = l || {};
|
||||
if ((l.ts && l.ts * 1000 > t0) || ++tries > 40) {
|
||||
M.busy(btn, false);
|
||||
self.lastLock = l; self.paint(); self.paintServing(self.lastCell);
|
||||
self.note((l.ts && l.ts * 1000 > t0) ? '状态已回读' : '回读超时,请点「刷新锁定状态」',
|
||||
(l.ts && l.ts * 1000 > t0) ? 'success' : 'error');
|
||||
} else setTimeout(step, 2500);
|
||||
} else self.later(step, 2500);
|
||||
});
|
||||
};
|
||||
step();
|
||||
},
|
||||
refreshSoon: function() {
|
||||
var self = this;
|
||||
setTimeout(function() { self.refresh(); }, 1500);
|
||||
self.later(function() { self.refresh(); }, 1500);
|
||||
},
|
||||
|
||||
/* 即时开关(EN-DC / 开机自动应用)确认式回读:后端已把这些状态即时写进
|
||||
@@ -357,6 +425,7 @@ return view.extend({
|
||||
};
|
||||
var step = function() {
|
||||
L.resolveDefault(M.callLockGet()).then(function(l) {
|
||||
if (self._disposed) return;
|
||||
l = l || {};
|
||||
if (matches(l) || ++tries > 10) {
|
||||
M.busy(btn, false);
|
||||
@@ -366,25 +435,28 @@ return view.extend({
|
||||
self.note(kind == 'endc' ? '已生效(EN-DC 不需要重启协议栈)' : '开机自动应用已' + (val == 'on' ? '开启' : '关闭'), 'success');
|
||||
else
|
||||
self.note((kind == 'endc' ? 'EN-DC' : '开机自动应用') + '状态回读超时,点「刷新锁定状态」确认', 'error');
|
||||
} else setTimeout(step, 1500);
|
||||
} else self.later(step, 1500);
|
||||
});
|
||||
};
|
||||
setTimeout(step, 1500);
|
||||
self.later(step, 1500);
|
||||
},
|
||||
|
||||
refresh: function() {
|
||||
if (this._disposed) return;
|
||||
var self = this;
|
||||
L.resolveDefault(M.callLockGet()).then(function(l) {
|
||||
if (self._disposed) return;
|
||||
l = l || {};
|
||||
/* 空结果多半是 rpcd 高并发下的一次瞬时失败(实测同请求重发即好):轻量重试 */
|
||||
if (!l.mode && !l.error && (self._retry = (self._retry || 0) + 1) <= 3)
|
||||
return setTimeout(function() { self.refresh(); }, 1800);
|
||||
return self.later(function() { self.refresh(); }, 1800);
|
||||
self._retry = 0;
|
||||
self.loading('lock', false, !l.mode || !!l.error);
|
||||
self.lastLock = l;
|
||||
self.paint();
|
||||
/* 锁定状态回来了,把邻区表的“已锁定”标记也刷新一下 */
|
||||
var nb = self.Q('neigh');
|
||||
if (nb && self.lastCell) nb.innerHTML = M.neighborRows(self.lastCell, self.lastLock.cells || []);
|
||||
if (nb && self.lastCell) nb.innerHTML = M.neighborRows(self.neighborCell || self.lastCell, self.lastLock.cells || []);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
'require form';
|
||||
'require uci';
|
||||
'require mu300.refresh as R';
|
||||
'require view';
|
||||
'require mu300.common as M';
|
||||
|
||||
@@ -51,11 +53,12 @@ return view.extend({
|
||||
o.datatype = 'uinteger';
|
||||
o.placeholder = '90';
|
||||
o = s.option(form.Value, 'home_refresh_interval', t('主页刷新间隔(秒)'));
|
||||
o.datatype = 'range(0.5,60)';
|
||||
o.placeholder = '1.5';
|
||||
o.default = '1.5';
|
||||
o.datatype = 'range(2,60)';
|
||||
o.placeholder = '2';
|
||||
o.default = '2';
|
||||
o.rmempty = false;
|
||||
o.description = t('仅控制主页状态看板的刷新频率;允许 0.5–60 秒,保存后重新进入主页生效。');
|
||||
o.cfgvalue = function(section) { return String(R.seconds(uci.get('unisoc_modem', section, 'home_refresh_interval'))); };
|
||||
o.description = t('主页状态每 2–60 秒刷新,网速独立每秒刷新;旧设置不足 2 秒时按 2 秒处理。保存后重新进入主页生效。');
|
||||
o = s.option(form.Value, 'state_dir', t('持久化状态目录'));
|
||||
o.placeholder = '/etc/unisoc-modem/lock-state.d';
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/* Scoped to the SMS view; size against LuCI's content, not the browser sidebar. */
|
||||
.mud.mud-sms{container-type:inline-size;min-width:0}
|
||||
.mud-sms,.mud-sms *{box-sizing:border-box}
|
||||
.mud-sms-heading{display:flex;align-items:baseline;flex-wrap:wrap;gap:8px 14px;margin-bottom:18px}
|
||||
.mud-sms .mud-sms-heading h2{margin:0;padding:0;border:0;font-size:1.35rem;font-weight:650;letter-spacing:0}
|
||||
.mud-sms #mud-sms-stat{margin:0;font-size:.8rem}
|
||||
.mud-sms #mud-sms-capacity{margin:0 0 12px}
|
||||
.mud-sms-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:10px;margin-bottom:16px}
|
||||
.mud-sms-actions{display:flex;gap:8px;flex-wrap:wrap}
|
||||
.mud-sms #mud-sms-clear{margin-left:auto}
|
||||
.mud-sms .mud-btn{min-height:40px;height:auto;line-height:1.3;margin-top:0;margin-bottom:0;white-space:nowrap;font-size:.82rem;padding:9px 14px}
|
||||
.mud-sms input,.mud-sms select,.mud-sms textarea{min-width:0;max-width:100%;margin:0;border:1px solid var(--hairline,var(--border,#ccc));border-radius:var(--radius-base,.5rem);background:var(--surface,var(--background,#fff));color:var(--text,#222);font:inherit;box-shadow:none}
|
||||
.mud-sms input,.mud-sms select{height:40px;min-height:40px;padding:8px 11px;line-height:1.4}
|
||||
.mud-sms select{padding-right:30px}
|
||||
.mud-sms :is(input,select,textarea,button):focus-visible{outline:2px solid var(--brand,var(--primary,#2f7bf6));outline-offset:2px}
|
||||
.mud-sms .mud-chat{display:grid;grid-template-columns:minmax(180px,28%) minmax(0,1fr);gap:0;min-height:440px;height:clamp(440px,65vh,660px);border:1px solid var(--hairline,var(--border,#ddd));border-radius:12px;overflow:hidden;background:var(--surface,var(--background,#fff))}
|
||||
.mud-sms-sidebar{display:flex;flex-direction:column;min-height:0;min-width:0;background:var(--surface-sunken,rgba(127,127,127,.04))}
|
||||
.mud-sms .mud-sms-pane-title{display:flex;align-items:center;flex:0 0 auto;min-height:50px;padding:14px 18px;border-bottom:1px solid var(--hairline,var(--border,#ddd));font-size:.85rem;font-weight:600;overflow-wrap:anywhere}
|
||||
.mud-sms .mud-convs{flex:1;min-height:0;max-height:none;padding:8px;overflow:auto}
|
||||
.mud-sms .mud-conv{padding:12px;margin-bottom:4px}
|
||||
.mud-sms .mud-conv .n{font-size:.9rem}
|
||||
.mud-sms .mud-conv .p{margin-top:5px;line-height:1.5}
|
||||
.mud-sms .mud-thread{min-height:0;padding:0;border-top:0;border-left:1px solid var(--hairline,var(--border,#ddd))}
|
||||
.mud-sms .mud-msgs{min-height:120px;max-height:none;padding:18px;gap:12px;overscroll-behavior:contain}
|
||||
.mud-sms .mud-bub{max-width:88%;padding:10px 32px 10px 13px;line-height:1.55}
|
||||
.mud-sms-empty{display:flex;flex:1;align-items:center;justify-content:center;flex-direction:column;gap:10px;text-align:center;color:var(--text-muted,var(--text-light,#787d85));padding:18px 8px;font-size:.8rem;line-height:1.65}
|
||||
.mud-sms-empty svg{opacity:.65;margin-bottom:2px;flex-shrink:0}
|
||||
.mud-sms-empty strong{font-size:.95rem;font-weight:500;color:var(--text,#222)}
|
||||
.mud-sms-empty span{max-width:280px}
|
||||
.mud-sms-list-empty{display:flex;flex-direction:column;gap:8px;padding:20px 12px;color:var(--text-muted,var(--text-light,#787d85));font-size:.8rem;line-height:1.7}
|
||||
.mud-sms-list-empty strong{font-weight:500;color:var(--text,#222)}
|
||||
.mud-sms-compose{flex:0 0 auto;padding:16px 18px;border-top:1px solid var(--hairline,var(--border,#ddd))}
|
||||
.mud-sms-address{display:grid;grid-template-columns:minmax(0,1fr);gap:12px}
|
||||
.mud-sms .mud-sms-address label{display:flex;flex-direction:column;gap:7px;margin:0;min-width:0;font-size:.8rem;color:var(--text-muted,var(--text-light,#787d85))}
|
||||
.mud-sms-address input,.mud-sms-address select{width:100%}
|
||||
.mud-sms .mud-comp{gap:10px;align-items:flex-end;margin-top:12px}
|
||||
.mud-sms .mud-comp textarea{display:block;min-height:82px;max-height:120px;padding:10px 12px;line-height:1.5;font-size:.85rem}
|
||||
.mud-sms #mud-sms-send{flex-shrink:0;min-width:72px}
|
||||
.mud-sms #mud-sms-note{margin:12px 2px 0;font-size:.75rem;line-height:1.7}
|
||||
@container(max-width:680px){
|
||||
.mud-sms .mud-chat{grid-template-columns:minmax(0,1fr);height:auto;min-height:0}
|
||||
.mud-sms-sidebar{max-height:200px}
|
||||
.mud-sms .mud-convs{flex:auto;max-height:150px}
|
||||
.mud-sms .mud-thread{border-left:0;border-top:1px solid var(--hairline,var(--border,#ddd));min-height:400px;max-height:620px}
|
||||
.mud-sms .mud-msgs{flex:1;max-height:300px}
|
||||
.mud-sms-list-empty{padding:12px;gap:4px}
|
||||
}
|
||||
@container(max-width:460px){
|
||||
.mud-sms-toolbar{gap:10px 8px}
|
||||
.mud-sms .mud-btn{padding:9px 10px;font-size:.78rem}
|
||||
.mud-sms .mud-sms-pane-title{padding:12px 14px;min-height:44px}
|
||||
.mud-sms-compose{padding:14px}
|
||||
.mud-sms-address{grid-template-columns:minmax(0,1fr)}
|
||||
.mud-sms .mud-thread{min-height:470px}
|
||||
.mud-sms #mud-sms-send{min-width:60px}
|
||||
}
|
||||
.mud-sms .mud-bub{overflow-wrap:anywhere;word-break:break-word}
|
||||
.mud-sms .mud-conv .n,.mud-sms .mud-conv .p{overflow-wrap:anywhere}
|
||||
@@ -19,30 +19,37 @@ return view.extend({
|
||||
M.injectCss();
|
||||
M.watchSms();
|
||||
var root = document.createElement('div');
|
||||
root.className = 'mud';
|
||||
root.className = 'mud mud-sms';
|
||||
root.innerHTML = `
|
||||
<div class="mud-sec" style="margin-top:0">
|
||||
<h3>短信 <span id="mud-sms-stat" style="font-weight:400"></span></h3>
|
||||
<div class="mud-sms-heading"><h2>短信</h2><span id="mud-sms-stat"></span></div>
|
||||
<div class="mud-note" id="mud-sms-capacity" style="display:none;margin-bottom:10px"></div>
|
||||
<input id="mud-sms-num" placeholder="收件人:号码,如 10086 或 +86..." spellcheck="false"
|
||||
style="width:100%;margin-bottom:8px;padding:7px 11px;border:1px solid var(--hairline,var(--border,#ccc));border-radius:var(--radius-base,.5rem);background:var(--surface,var(--background,#fff));color:var(--text,#222)"/>
|
||||
<div class="mud-ctl" style="max-width:460px;margin-bottom:8px">
|
||||
<div class="mud-sms-toolbar">
|
||||
<button class="mud-btn" id="mud-sms-refresh">刷新</button>
|
||||
<button class="mud-btn" id="mud-sms-sync">从 SIM 同步</button>
|
||||
<button class="mud-btn warn" id="mud-sms-clear">清空本地池</button>
|
||||
</div>
|
||||
<div class="mud-chat">
|
||||
<div class="mud-convs" id="mud-sms-convs"><div class="mud-note">加载中…</div></div>
|
||||
<div class="mud-sms-sidebar">
|
||||
<div class="mud-sms-pane-title">会话</div>
|
||||
<div class="mud-convs" id="mud-sms-convs"><div class="mud-note">加载中…</div></div>
|
||||
</div>
|
||||
<div class="mud-thread">
|
||||
<div class="mud-msgs" id="mud-sms-msgs"><div class="mud-note" style="margin:8px 2px">选择左侧会话,或直接在下方输入号码发送。</div></div>
|
||||
<div class="mud-sms-compose">
|
||||
<div class="mud-sms-address"><label><span>收件人</span>
|
||||
<input id="mud-sms-num" placeholder="收件人:号码,如 10086 或 +86..." spellcheck="false" inputmode="tel"/>
|
||||
</label></div>
|
||||
<div class="mud-comp">
|
||||
<textarea id="mud-sms-text" placeholder="短信内容(Enter 发送,Shift+Enter 换行)" rows="1"></textarea>
|
||||
<button class="mud-btn" id="mud-sms-send" style="align-self:flex-end;padding:8px 18px">发送</button>
|
||||
<button class="mud-btn" id="mud-sms-send">发送</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mud-note" id="mud-sms-note">发送走 AT+CMGS(PDU 模式);通道忙会提示重试。删除单条:在气泡上右键(手机长按)。</div>
|
||||
</div>`;
|
||||
root.prepend(E('link', { rel: 'stylesheet', href: L.resource('view/mu300/sms.css') }));
|
||||
M.localize(root);
|
||||
this.Q = function(id) { return root.querySelector('#mud-' + id); };
|
||||
this.sel = null; /* 当前会话的 peer */
|
||||
|
||||
@@ -11,7 +11,7 @@ config core 'main'
|
||||
option wifi_device 'wlan0'
|
||||
option usb_device 'usb0'
|
||||
option replay_timeout '90'
|
||||
option home_refresh_interval '1.5'
|
||||
option home_refresh_interval '2'
|
||||
option state_dir '/etc/unisoc-modem/lock-state.d'
|
||||
|
||||
config device 'usb'
|
||||
|
||||
@@ -4,6 +4,7 @@ START=95
|
||||
USE_PROCD=1
|
||||
|
||||
start_service() {
|
||||
/usr/libexec/unisoc-modem/refresh-config
|
||||
# Complete this short policy step before S99 mu300-post decides whether the
|
||||
# device-mode gadget needs its one boot-time rebind. The normal device path
|
||||
# performs only local UCI reads; host mode may use a platform power helper.
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
export PATH="$PATH:/opt/mu300/bin:/opt/mu300/busybox-bin:/usr/libexec/unisoc-modem:/usr/sbin:/sbin"
|
||||
|
||||
DASH=${MU300_DASH_BIN:-/usr/libexec/unisoc-modem}
|
||||
# The 1 s counter lane needs neither SMS configuration nor forensic logging.
|
||||
if [ "${1:-}" = call ] && [ "${2:-}" = rates ]; then
|
||||
exec "$DASH/dashboard-rates"
|
||||
fi
|
||||
# One pool everywhere: a platform SMS adapter may honor this environment value.
|
||||
# Keep the former MU300 path as an automatic upgrade fallback.
|
||||
SMS_POOL=$(uci -q get unisoc_modem.main.sms_pool 2>/dev/null)
|
||||
@@ -69,7 +73,8 @@ age_of() { [ -s "$1" ] && echo $(( $(now) - $(date -r "$1" +%s 2>/dev/null || ec
|
||||
|
||||
m_status() {
|
||||
local info cage sage busy=0 fbusy=0
|
||||
info=$("$DASH/dashboard-info" 2>/dev/null)
|
||||
if [ "${1:-}" = cells ]; then info=null
|
||||
else info=$("$DASH/dashboard-info" 2>/dev/null); fi
|
||||
[ -n "$info" ] || info='{"error":"dashboard-info failed"}'
|
||||
cage=$(age_of "$CELL"); sage=$(age_of "$SIGF")
|
||||
# two refresh tiers, both detached: the fast one keeps the serving-cell data
|
||||
@@ -82,10 +87,10 @@ m_status() {
|
||||
fast_busy && fbusy=1
|
||||
# A full round also refreshes sig.json. Prefer it when both tiers are stale;
|
||||
# starting full and fast together doubles the AT burst for no benefit.
|
||||
if { [ "$cage" -lt 0 ] || [ "$cage" -gt "$TTL" ]; } && [ "$busy" = 0 ]; then
|
||||
if { [ "$cage" -lt 0 ] || [ "$cage" -ge "$TTL" ]; } && [ "$busy" = 0 ]; then
|
||||
setsid "$DASH/cell" >/dev/null 2>&1 &
|
||||
busy=1; fbusy=1
|
||||
elif { [ "$sage" -lt 0 ] || [ "$sage" -gt "$TTL_FAST" ]; } && [ "$fbusy" = 0 ]; then
|
||||
elif { [ "$sage" -lt 0 ] || [ "$sage" -ge "$TTL_FAST" ]; } && [ "$fbusy" = 0 ]; then
|
||||
setsid "$DASH/cell" fast >/dev/null 2>&1 &
|
||||
fbusy=1
|
||||
fi
|
||||
@@ -332,6 +337,8 @@ do_list() {
|
||||
{
|
||||
"sysinfo": { },
|
||||
"status": { },
|
||||
"rates": { },
|
||||
"cells": { },
|
||||
"signal": { },
|
||||
"act": { "op": "String", "arg": "String" },
|
||||
"at": { "cmd": "String" },
|
||||
@@ -378,6 +385,9 @@ call)
|
||||
case ${2:-} in
|
||||
sysinfo) run_m sysinfo 'm_sysinfo' ;;
|
||||
status) run_m status 'm_status' ;;
|
||||
cells) m_status cells ;;
|
||||
# Avoid the forensic log's fork/tail/rewrite on every speed sample.
|
||||
rates) "$DASH/dashboard-rates" ;;
|
||||
signal) run_m signal 'm_signal' ;;
|
||||
act) run_m act 'm_act' ;;
|
||||
at) run_m at 'm_at' ;;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#
|
||||
# Commands per round (about 10, roughly one second on this modem):
|
||||
# AT+CFUN? radio on/off - the honest state for the toggle
|
||||
# AT+COPS? operator name + access technology
|
||||
# AT+CSCS?;+COPS? operator name + access technology
|
||||
# AT+CEREG? LTE registration, TAC, cell ID
|
||||
# AT+C5GREG? NR registration - CEREG alone still reports LTE-style AcT on n78
|
||||
# AT+CESQ RSRP/RSRQ indexes - the fallback when the engineering mode below says nothing
|
||||
@@ -38,7 +38,7 @@
|
||||
# mu300-dash-cell full: everything below, ~11 commands, neighbours included
|
||||
# mu300-dash-cell fast serving-cell tier: CFUN/CEREG/C5GREG/CESQ + the two
|
||||
# SPENGMD serving reads (~6 commands, well under a second),
|
||||
# written to sig.json only - the page polls this at 1.5 s
|
||||
# written to sig.json only - the page polls this at 2 s
|
||||
# and the slow tier (neighbours, operator, QoS, identity)
|
||||
# rides the 5 s full cache. A fast round yields to a full
|
||||
# round in flight (the full round writes sig.json too).
|
||||
@@ -330,13 +330,8 @@ reg_fragment() { # reg_fragment LINE
|
||||
(($2=="")?"null":$2), (($3=="")?"null":"\""$3"\""), (($4=="")?"null":"\""$4"\""), act }'
|
||||
}
|
||||
|
||||
cops_fragment() { # COPS LINE -> name/plmn/act
|
||||
[ -n "$1" ] || { echo null; return; }
|
||||
printf '%s\n' "$1" | awk -F'"' '{ name = $2; n = split($0, f, ","); act = f[n]; gsub(/[^0-9]/, "", act)
|
||||
plmn = (name ~ /^[0-9]+$/) ? name : ""
|
||||
if (plmn != "") name = ""
|
||||
printf "{\"name\":%s,\"plmn\":%s,\"act\":%s}",
|
||||
(name==""?"null":"\""name"\""), (plmn==""?"null":"\""plmn"\""), (act==""?"null":act) }'
|
||||
cops_fragment() {
|
||||
ucode "$(dirname "$0")/operator.uc" "$1" 2>/dev/null || echo null
|
||||
}
|
||||
|
||||
cesq_fragment() { # "+CESQ: 24,99,55,255,36,98"
|
||||
@@ -380,8 +375,47 @@ if [ "$REGISTERED" = 1 ]; then
|
||||
SP_LTEPHY=$(at 'AT+SPENGMD=0,0,6' 2 | grep -v '^AT' | grep -- '-' | head -n1)
|
||||
SP_NR=$(at 'AT+SPENGMD=0,14,1' 2 | grep -v '^AT' | grep -- '-' | head -n1)
|
||||
fi
|
||||
|
||||
# "no answer at all" is a modem/daemon problem, not "no signal".
|
||||
if [ -z "$CFUN$CEREG$CESQ$SP_LTE$SP_NR$COPS" ]; then
|
||||
ERR="AT backend did not answer (radio off, modem restarting, or adapter unavailable)"
|
||||
printf '{"ts":%d,"error":%s}\n' "$(now)" "$(qs "$ERR")" > "$SIGF.part" && mv "$SIGF.part" "$SIGF"
|
||||
[ "$MODE" = full ] && cp "$SIGF" "$CELL"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
LTE=$(sp_fragment lte "$SP_LTE" "$SP_LTEPHY")
|
||||
NR=$(sp_fragment nr "$SP_NR")
|
||||
REG=$(reg_fragment "$CEREG")
|
||||
REG5=$(reg_fragment "$C5GREG")
|
||||
CESQJ=$(cesq_fragment "$CESQ")
|
||||
CFUNN=$(n_or_null "$CFUN")
|
||||
|
||||
# preferred signal source: NR (NSA/SA), then LTE, then the CESQ fallback
|
||||
if [ "$NR" != null ]; then SIG="$NR"; SRC=nr
|
||||
elif [ "$LTE" != null ]; then SIG="$LTE"; SRC=lte
|
||||
else SIG="$CESQJ"; SRC=cesq; fi
|
||||
|
||||
# the fast tier: serving cell + registration only (both modes write it; the page
|
||||
# polls this at 2 s and overlays it on the slower full cache)
|
||||
printf '{"ts":%d,"cfun":%s,"reg":%s,"reg5g":%s,"sig_src":"%s","sig":%s,"lte":%s,"nr":%s}\n' \
|
||||
"$(now)" "$CFUNN" "$REG" "$REG5" "$SRC" "$SIG" "$LTE" "$NR" > "$SIGF.part" && mv "$SIGF.part" "$SIGF"
|
||||
|
||||
[ "$MODE" = fast ] && exit 0
|
||||
|
||||
# Each atomic publication has an explicit completion state. Frontends retain
|
||||
# old QoS/identity/neighbours only while that particular stage is pending.
|
||||
publish_cell() {
|
||||
printf '{"ts":%d,"partial":%s,"neigh_pending":%s,"cfun":%s,"reg":%s,"reg5g":%s,"operator":%s,"sig_src":"%s","sig":%s,"lte":%s,"nr":%s,"qos":%s,"neigh":%s,"ident":%s}\n' \
|
||||
"$(now)" "$1" "$2" "$CFUNN" "$REG" "$REG5" "$COPSJ" "$SRC" "$SIG" "$LTE" "$NR" "$QOSJ" "$NEIGH" "$IDENT_JSON" > "$CELL.part" && mv "$CELL.part" "$CELL"
|
||||
}
|
||||
|
||||
if [ "$MODE" = full ]; then
|
||||
COPS=$(at 'AT+COPS?' 2 | grep '^+COPS:' | head -n1)
|
||||
# One serialized transaction: do not let an SMS charset change interleave.
|
||||
COPS=$(at 'AT+CSCS?;+COPS?' 2)
|
||||
COPSJ=$(cops_fragment "$COPS")
|
||||
NEIGH=null; QOSJ=null
|
||||
publish_cell 1 1
|
||||
if [ "$REGISTERED" = 1 ]; then
|
||||
SP_LN=$(at 'AT+SPENGMD=0,6,6' 2 | grep -v '^AT' | grep -- '-' | head -n1)
|
||||
SP_NRNB=$(at 'AT+SPENGMD=0,14,2' 2 | grep -v '^AT' | grep -- '-' | head -n1)
|
||||
@@ -390,8 +424,20 @@ if [ "$MODE" = full ]; then
|
||||
SP_NRNB=$(at 'AT+SPQ5GNCELLEX' 2 | sed -n 's/^+SPQ5GNCELLEX: *//p' | head -n1)
|
||||
SP_NRNB_SOURCE=spq
|
||||
fi
|
||||
fi
|
||||
LN=$(sp_fragment ltenb "$SP_LN")
|
||||
NN=$(nr_neighbours "$SP_NRNB" "$SP_NRNB_SOURCE")
|
||||
# one neighbour list, NR first (the page shows NR cells at the top)
|
||||
if [ -n "$NN" ] && [ -n "$LN" ]; then NEIGH="[$NN,$LN]"
|
||||
elif [ -n "$NN" ]; then NEIGH="[$NN]"
|
||||
elif [ -n "$LN" ]; then NEIGH="[$LN]"
|
||||
else NEIGH=null; fi
|
||||
|
||||
publish_cell 1 0
|
||||
if [ "$REGISTERED" = 1 ]; then
|
||||
QOS=$(at 'AT+CGEQOSRDP=1' 2 | sed -n 's/^+CGEQOSRDP: *//p' | head -n1)
|
||||
fi
|
||||
QOSJ=$(qos_fragment "$QOS")
|
||||
IDENT_AGE=999999
|
||||
[ -s "$IDENT" ] && IDENT_AGE=$(( $(now) - $(date -r "$IDENT" +%s 2>/dev/null || echo 0) ))
|
||||
if [ "$IDENT_AGE" -ge 0 ] && [ "$IDENT_AGE" -le "$IDENT_MAXAGE" ] &&
|
||||
@@ -432,44 +478,4 @@ if [ "$MODE" = full ]; then
|
||||
"$IDENT_JSON" "$(qs "$i_msisdn")" "$(qs "$i_msisdn_source")")
|
||||
fi
|
||||
|
||||
# "no answer at all" is a modem/daemon problem, not "no signal".
|
||||
if [ -z "$CFUN$CEREG$CESQ$SP_LTE$SP_NR$COPS" ]; then
|
||||
ERR="AT backend did not answer (radio off, modem restarting, or adapter unavailable)"
|
||||
printf '{"ts":%d,"error":%s}\n' "$(now)" "$(qs "$ERR")" > "$SIGF.part" && mv "$SIGF.part" "$SIGF"
|
||||
[ "$MODE" = full ] && cp "$SIGF" "$CELL"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
LTE=$(sp_fragment lte "$SP_LTE" "$SP_LTEPHY")
|
||||
NR=$(sp_fragment nr "$SP_NR")
|
||||
REG=$(reg_fragment "$CEREG")
|
||||
REG5=$(reg_fragment "$C5GREG")
|
||||
CESQJ=$(cesq_fragment "$CESQ")
|
||||
CFUNN=$(n_or_null "$CFUN")
|
||||
|
||||
# preferred signal source: NR (NSA/SA), then LTE, then the CESQ fallback
|
||||
if [ "$NR" != null ]; then SIG="$NR"; SRC=nr
|
||||
elif [ "$LTE" != null ]; then SIG="$LTE"; SRC=lte
|
||||
else SIG="$CESQJ"; SRC=cesq; fi
|
||||
|
||||
# the fast tier: serving cell + registration only (both modes write it; the page
|
||||
# polls this at 1.5 s and overlays it on the slower full cache)
|
||||
printf '{"ts":%d,"cfun":%s,"reg":%s,"reg5g":%s,"sig_src":"%s","sig":%s,"lte":%s,"nr":%s}\n' \
|
||||
"$(now)" "$CFUNN" "$REG" "$REG5" "$SRC" "$SIG" "$LTE" "$NR" > "$SIGF.part" && mv "$SIGF.part" "$SIGF"
|
||||
|
||||
[ "$MODE" = fast ] && exit 0
|
||||
|
||||
# the full tier: everything else the page needs only every few seconds
|
||||
LN=$(sp_fragment ltenb "$SP_LN")
|
||||
NN=$(nr_neighbours "$SP_NRNB" "$SP_NRNB_SOURCE")
|
||||
# one neighbour list, NR first (the page shows NR cells at the top)
|
||||
if [ -n "$NN" ] && [ -n "$LN" ]; then NEIGH="[$NN,$LN]"
|
||||
elif [ -n "$NN" ]; then NEIGH="[$NN]"
|
||||
elif [ -n "$LN" ]; then NEIGH="[$LN]"
|
||||
else NEIGH=null; fi
|
||||
|
||||
COPSJ=$(cops_fragment "$COPS")
|
||||
QOSJ=$(qos_fragment "$QOS")
|
||||
|
||||
printf '{"ts":%d,"cfun":%s,"reg":%s,"reg5g":%s,"operator":%s,"sig_src":"%s","sig":%s,"lte":%s,"nr":%s,"qos":%s,"neigh":%s,"ident":%s}\n' \
|
||||
"$(now)" "$CFUNN" "$REG" "$REG5" "$COPSJ" "$SRC" "$SIG" "$LTE" "$NR" "$QOSJ" "$NEIGH" "$IDENT_JSON" > "$CELL.part" && mv "$CELL.part" "$CELL"
|
||||
publish_cell 0 0
|
||||
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/ucode
|
||||
// No AT, interface dump, process list or traffic-ledger query on the 1 s lane.
|
||||
import { readfile } from 'fs';
|
||||
import { cursor } from 'uci';
|
||||
import { connect } from 'ubus';
|
||||
|
||||
const cfg = cursor();
|
||||
let device = cfg.get('unisoc_modem', 'main', 'data_device');
|
||||
if (!device) {
|
||||
const bus = connect();
|
||||
const iface = cfg.get('unisoc_modem', 'main', 'data_interface') || 'wan';
|
||||
let status;
|
||||
try { status = bus?.call('network.interface.' + iface, 'status', {}); } catch (e) {}
|
||||
device = status?.l3_device || 'sipa_eth0';
|
||||
}
|
||||
if (!match(device, /^[A-Za-z0-9_.:-]{1,15}$/)) {
|
||||
print('{"available":false}\n');
|
||||
exit(0);
|
||||
}
|
||||
const path = '/sys/class/net/' + device + '/';
|
||||
const rx = readfile(path + 'statistics/rx_bytes');
|
||||
const tx = readfile(path + 'statistics/tx_bytes');
|
||||
const index = readfile(path + 'ifindex');
|
||||
const uptime = readfile('/proc/uptime');
|
||||
const valid = rx != null && tx != null && index != null && uptime != null;
|
||||
printf('%J\n', {
|
||||
available: valid,
|
||||
device: device,
|
||||
ifindex: valid ? int(index) : null,
|
||||
boot_id: trim(readfile('/proc/sys/kernel/random/boot_id') || ''),
|
||||
ts: valid ? +split(uptime, ' ')[0] : null,
|
||||
rx: valid ? +trim(rx) : null,
|
||||
tx: valid ? +trim(tx) : null
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
// Parse a combined read-only CSCS/COPS reply. Never guess the encoding of a
|
||||
// plain hexadecimal-looking name or confuse numeric PLMN with UCS2 text.
|
||||
const reply = ARGV[0] || '';
|
||||
const cops = match(reply, /\+COPS: *([0-9]+), *([0-9]+), *"([^"]*)"(, *([0-9]+))?/);
|
||||
if (!cops) {
|
||||
print('null\n');
|
||||
exit(0);
|
||||
}
|
||||
let name = cops[3] || null;
|
||||
const charset = match(reply, /\+CSCS: *"([^"]*)"/);
|
||||
if (name && (cops[2] == '0' || cops[2] == '1') && charset && uc(charset[1]) == 'UCS2' && match(name, /^([0-9A-Fa-f]{4})+$/)) {
|
||||
let encoded = '"', valid = true, high = false;
|
||||
for (let i = 0; i < length(name); i += 4) {
|
||||
let unit = uc(substr(name, i, 4));
|
||||
let low = !!match(unit, /^D[CDEF]/);
|
||||
if (high != low || match(unit, /^00([01][0-9A-F]|7F|[89][0-9A-F])$/)) { valid = false; break; }
|
||||
high = !!match(unit, /^D[89AB]/);
|
||||
encoded += '\\u' + unit;
|
||||
}
|
||||
if (valid && !high) {
|
||||
try { name = json(encoded + '"'); } catch (e) { /* keep original */ }
|
||||
}
|
||||
}
|
||||
const numeric = cops[2] == '2';
|
||||
printf('%J\n', {name: numeric ? null : name, plmn: numeric ? name : null, act: cops[5] != null ? int(cops[5]) : null});
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/ucode
|
||||
// Upgrade only the refresh policy; never reset platform or modem settings.
|
||||
import { cursor } from 'uci';
|
||||
const cfg = cursor();
|
||||
if (cfg.get('unisoc_modem', 'main') != 'core') exit(0);
|
||||
const value = cfg.get('unisoc_modem', 'main', 'home_refresh_interval');
|
||||
const n = +value;
|
||||
if (value == null || !(n >= 2 && n <= 60)) {
|
||||
cfg.set('unisoc_modem', 'main', 'home_refresh_interval', '2');
|
||||
cfg.commit('unisoc_modem');
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// ONLY in a throwaway OpenWrt container; never execute on a real router.
|
||||
// docker run --rm -e MU300_TEST_CONTAINER=1 -v REPO:/src:ro --entrypoint ucode
|
||||
// mu300-openwrt-base:25.12.5 /src/tests/dashboard_backport.uc
|
||||
import { popen, writefile, mkdir, readfile } from 'fs';
|
||||
if (getenv('MU300_TEST_CONTAINER') != '1') die('Disposable container required\n');
|
||||
const lib = '/src/openwrt/luci-app-mu300/root/usr/libexec/unisoc-modem/';
|
||||
let checks = 0;
|
||||
function check(ok, label) { if (!ok) die('FAIL: ' + label + '\n'); checks++; }
|
||||
function quote(s) { return "'" + replace(s, /'/g, "'\\''") + "'"; }
|
||||
function run(cmd) {
|
||||
const p = popen(cmd, 'r');
|
||||
const out = p.read('all');
|
||||
check(p.close() == 0, 'command: ' + cmd);
|
||||
return out;
|
||||
}
|
||||
function operator(reply) { return json(run('ucode ' + lib + 'operator.uc ' + quote(reply))); }
|
||||
const cases = [
|
||||
['+CSCS: "UCS2"\n+COPS: 0,0,"4E2D56FD8054901A",7', '中国联通', null],
|
||||
['+CSCS: "UCS2"\n+COPS: 0,1,"00410042",7', 'AB', null],
|
||||
['+CSCS: "UCS2"\n+COPS: 0,2,"46001",7', null, '46001'],
|
||||
['+CSCS: "IRA"\n+COPS: 0,0,"FACE",7', 'FACE', null],
|
||||
['+COPS: 0,0,"00410042",7', '00410042', null],
|
||||
['+CSCS: "UCS2"\n+COPS: 0,0,"123",7', '123', null],
|
||||
['+CSCS: "UCS2"\n+COPS: 0,0,"D8000041",7', 'D8000041', null],
|
||||
['+CSCS: "UCS2"\n+COPS: 0,0,"000A",7', '000A', null],
|
||||
['+CSCS: "IRA"\n+COPS: 0,0,"Turkcell",7', 'Turkcell', null]
|
||||
];
|
||||
for (let row in cases) {
|
||||
const op = operator(row[0]);
|
||||
check(op.name == row[1] && op.plmn == row[2] && op.act == 7, 'COPS decoding: ' + row[0]);
|
||||
}
|
||||
check(operator('ERROR') == null, 'missing operator');
|
||||
|
||||
mkdir('/etc/config');
|
||||
function config(value, device) {
|
||||
writefile('/etc/config/unisoc_modem', "config core 'main'\n option home_refresh_interval '" + value +
|
||||
"'\n option data_device '" + device + "'\n option data_interface 'customwan'\n");
|
||||
}
|
||||
for (let value in ['0.5', '1.5', '', 'bad', '61']) {
|
||||
config(value, 'lo');
|
||||
run('ucode ' + lib + 'refresh-config');
|
||||
check(trim(run('uci -q get unisoc_modem.main.home_refresh_interval')) == '2', 'migrate ' + value);
|
||||
check(trim(run('uci -q get unisoc_modem.main.data_interface')) == 'customwan', 'keep adapter');
|
||||
}
|
||||
for (let value in ['2', '2.5', '10', '60']) {
|
||||
config(value, 'lo');
|
||||
run('ucode ' + lib + 'refresh-config');
|
||||
check(trim(run('uci -q get unisoc_modem.main.home_refresh_interval')) == value, 'retain ' + value);
|
||||
}
|
||||
const sample = json(run('ucode ' + lib + 'dashboard-rates'));
|
||||
check(sample.available && sample.device == 'lo' && sample.ifindex == 1, 'configured device');
|
||||
check(sample.rx >= 0 && sample.tx >= 0 && sample.ts > 0 && length(sample.boot_id) > 0, 'counter types');
|
||||
config('2', '../etc/passwd');
|
||||
check(!json(run('ucode ' + lib + 'dashboard-rates')).available, 'reject path traversal');
|
||||
config('2', 'missing0');
|
||||
check(!json(run('ucode ' + lib + 'dashboard-rates')).available, 'missing interface');
|
||||
printf('dashboard backend: %d checks passed\n', checks);
|
||||
@@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
const fs = require('fs'), assert = require('assert');
|
||||
const file = process.argv[2];
|
||||
let now = 0, seq = 0;
|
||||
const timers = new Map(), listeners = new Set();
|
||||
const document = { hidden: false,
|
||||
addEventListener: (name, fn) => listeners.add(fn),
|
||||
removeEventListener: (name, fn) => listeners.delete(fn) };
|
||||
const timeout = (fn, delay) => { const id = ++seq; timers.set(id, { fn, at: now + delay }); return id; };
|
||||
const clear = id => timers.delete(id);
|
||||
const R = new Function('baseclass', 'document', 'performance', 'setTimeout', 'clearTimeout', fs.readFileSync(file, 'utf8'))(
|
||||
{ extend: obj => obj }, document, { now: () => now }, timeout, clear);
|
||||
const flush = async () => { for (let i = 0; i < 12; i++) await Promise.resolve(); };
|
||||
async function advance(ms) {
|
||||
const end = now + ms;
|
||||
for (;;) {
|
||||
const next = [...timers].filter(([,t]) => t.at <= end).sort((a,b) => a[1].at - b[1].at)[0];
|
||||
if (!next) break;
|
||||
now = next[1].at; timers.delete(next[0]); next[1].fn(); await flush();
|
||||
}
|
||||
now = end; await flush();
|
||||
}
|
||||
async function hidden(value) { document.hidden = value; [...listeners].forEach(fn => fn()); await flush(); }
|
||||
async function main() {
|
||||
for (const n of [undefined, '', 'bad', 0, -1, 61, .5, 1.5]) assert.equal(R.seconds(n), 2);
|
||||
for (const n of [2, 2.5, 10, 60]) assert.equal(R.seconds(n), n);
|
||||
const sample = { available:true, device:'cell0', ifindex:3, boot_id:'a', ts:10.5, rx:100, tx:200 };
|
||||
const next = { ...sample, ts:11.5, rx:1100, tx:700 };
|
||||
assert.deepEqual(R.rateDelta(sample, next), { dl:1000, ul:500 });
|
||||
for (const bad of [null, {...next, available:false}, {...next, ts:10.5}, {...next, ts:9},
|
||||
{...next, rx:99}, {...next, tx:0}, {...next, ifindex:4}, {...next, device:'cell1'}, {...next, boot_id:'b'}])
|
||||
assert.equal(R.rateDelta(sample, bad), null);
|
||||
|
||||
let statusCalls = 0, speedCalls = 0, paints = 0, resets = 0, done;
|
||||
const stop = R.poll(() => { statusCalls++; return new Promise(resolve => { done = resolve; }); },
|
||||
() => paints++, () => 2000, null, () => resets++);
|
||||
const stopSpeed = R.poll(() => ++speedCalls, () => {}, () => 1000);
|
||||
await advance(0); assert.equal(statusCalls, 1);
|
||||
await advance(3100); assert.equal(statusCalls, 1); assert.equal(speedCalls, 4);
|
||||
done({}); await flush(); assert.equal(paints, 1);
|
||||
await advance(50); assert.equal(statusCalls, 2); // no completion + interval drift
|
||||
await hidden(true); await advance(5000); assert.equal(speedCalls, 4);
|
||||
await hidden(false); assert.equal(statusCalls, 2); // same lane still in flight
|
||||
done({}); await flush(); assert.equal(paints, 1); // response from hidden generation ignored
|
||||
await advance(50); assert.equal(statusCalls, 3);
|
||||
stop(); stopSpeed(); done({}); await flush(); await advance(10000);
|
||||
assert.equal(paints, 1); assert.equal(statusCalls, 3);
|
||||
assert.equal(listeners.size, 0); assert.equal(timers.size, 0); assert.equal(resets, 2);
|
||||
|
||||
let errors = 0, calls = 0;
|
||||
const stopErrors = R.poll(() => { calls++; throw Error('offline'); }, () => {}, () => 1000, () => errors++);
|
||||
await advance(2000); assert.equal(errors, 3); assert.equal(calls, 3);
|
||||
stopErrors(); assert.equal(timers.size, 0);
|
||||
let attached = true, removedPaints = 0, removedDone;
|
||||
R.poll(() => new Promise(r => { removedDone = r; }), () => removedPaints++, () => 1000,
|
||||
null, null, () => attached);
|
||||
await advance(0); attached = false; removedDone({}); await flush();
|
||||
assert.equal(removedPaints, 0); assert.equal(timers.size, 0); assert.equal(listeners.size, 0);
|
||||
|
||||
// A slow live signal must not hold the cache-only metadata lane hostage.
|
||||
let liveDone, metaDone, liveCalls = 0, metaCalls = 0;
|
||||
const painted = [], progress = {};
|
||||
const M = {
|
||||
callSignal: () => { liveCalls++; return new Promise(r => { liveDone = r; }); },
|
||||
callCells: () => { metaCalls++; return new Promise(r => { metaDone = r; }); },
|
||||
mergeCell: (old, next) => Object.assign({}, old, next), translate: x => x
|
||||
};
|
||||
const locks = new Function('view', 'M', 'R', 'L', 'document', fs.readFileSync(process.argv[3], 'utf8'))(
|
||||
{ extend: obj => obj }, M, R, {}, document);
|
||||
locks._timers = [];
|
||||
locks.Q = id => progress[id] || (progress[id] = {classList:{toggle:()=>{}},textContent:''});
|
||||
locks.paintServing = data => painted.push(data);
|
||||
const livePromise = locks.loadServing(), metaPromise = locks.loadServingMeta();
|
||||
assert.equal(locks.loadServing(), livePromise); assert.equal(liveCalls, 1);
|
||||
assert.equal(locks.loadServingMeta(), metaPromise); assert.equal(metaCalls, 1);
|
||||
metaDone({ cell: {ts:5,partial:1,neigh_pending:1,operator:{name:'Carrier'}}, sig:{ts:5,cfun:1} });
|
||||
await flush(); assert.equal(painted.length, 1); assert.equal(painted[0].cfun, 1);
|
||||
assert.equal(progress['neighbor-progress'].textContent, '正在更新…');
|
||||
locks.unload(); liveDone({ts:6,cfun:1}); await flush();
|
||||
assert.equal(painted.length, 1); // no late paint after navigation
|
||||
console.log('refresh: cadence, independence, failures, pause/dispose, counters OK');
|
||||
}
|
||||
main().catch(e => { console.error(e); process.exitCode = 1; });
|
||||
@@ -0,0 +1,96 @@
|
||||
"""Offline rendering smoke test. Requires Python Playwright and a local browser.
|
||||
|
||||
Run explicitly: python tests/dashboard_sms_layout.py [--browser PATH]
|
||||
No router, modem, external URL or saved browser profile is used.
|
||||
"""
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
TOP = Path(__file__).resolve().parents[1]
|
||||
RES = TOP / 'openwrt/luci-app-mu300/htdocs/luci-static/resources'
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--browser')
|
||||
args = parser.parse_args()
|
||||
common = (RES / 'mu300/common.js').read_text(encoding='utf-8')
|
||||
sms = (RES / 'view/mu300/sms.js').read_text(encoding='utf-8')
|
||||
css = (RES / 'view/mu300/sms.css').read_text(encoding='utf-8')
|
||||
checked = 0
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True, **({'executable_path': args.browser} if args.browser else {}))
|
||||
page = browser.new_page()
|
||||
page.route('**/*', lambda route: route.abort())
|
||||
page.set_content('<html><head></head><body><main id="app"></main></body></html>')
|
||||
page.evaluate('''([common, refresh, home]) => {
|
||||
window.calls = {status:0,rates:0};
|
||||
const L = {env:{lang:'en'},resolveDefault:(p,d)=>Promise.resolve(p).catch(()=>d)};
|
||||
const rpc = {declare:spec=>()=>{
|
||||
if (spec.method==='status') { calls.status++; return Promise.resolve({info:{ts:1,host:'test'},cell:null}); }
|
||||
if (spec.method==='rates') { calls.rates++; return Promise.resolve({available:true,device:'cell0',ifindex:1,boot_id:'a',ts:performance.now()/1000,rx:calls.rates*1000,tx:calls.rates*500}); }
|
||||
return Promise.resolve({});
|
||||
}};
|
||||
const base={extend:x=>x};
|
||||
const M=new Function('rpc','baseclass','L',common)(rpc,base,L); M.watchSms=()=>{};
|
||||
const R=new Function('baseclass',refresh)(base);
|
||||
const view=new Function('view','uci','R','M','L',home)(base,{load:()=>Promise.resolve(),get:()=>2},R,M,L);
|
||||
document.querySelector('#app').appendChild(view.render());
|
||||
}''', [common, (RES / 'mu300/refresh.js').read_text(encoding='utf-8'),
|
||||
(RES / 'view/mu300/home.js').read_text(encoding='utf-8')])
|
||||
page.wait_for_function("calls.status >= 2 && calls.rates >= 3 && document.querySelector('#mud-dl').textContent.includes('/s')")
|
||||
assert page.inner_text('#mud-host') == 'test'
|
||||
calls = page.evaluate('() => {document.querySelector(".mud").remove(); return {...calls};}')
|
||||
page.wait_for_timeout(2200)
|
||||
assert page.evaluate('calls') == calls, 'removed home view kept polling'
|
||||
page.close()
|
||||
print('Home render: separate live counters and detached-view cleanup passed')
|
||||
for width in (390, 1280):
|
||||
for theme in ('bootstrap', 'aurora'):
|
||||
for dark in (False, True):
|
||||
for lang in ('zh', 'en', 'tr'):
|
||||
page = browser.new_page(viewport={'width': width, 'height': 900})
|
||||
page.route('**/*', lambda route: route.abort())
|
||||
page.set_content('<html><head></head><body><main id="app"></main></body></html>')
|
||||
background, text = ('#202226', '#eeeeee') if dark else ('#ffffff', '#222222')
|
||||
variables = (f'--surface:{background};--text:{text};--hairline:#777;--brand:#467bef;' if theme == 'aurora' else
|
||||
f'--background-color-high:{background};--background-color-low:{background};--text-color-high:{text};--border-color-low:#777;--primary-color-high:#467bef;')
|
||||
page.add_style_tag(content=f'html{{{variables}}}body{{margin:0;padding:12px;background:{background};font-family:sans-serif}}main{{max-width:1050px;margin:auto;min-width:0}}')
|
||||
page.evaluate('''([common, sms, lang]) => {
|
||||
const L = { env:{lang}, resource:s => 'https://offline.invalid/' + s };
|
||||
const M = new Function('rpc','baseclass','L',common)({declare:()=>()=>{}},{extend:x=>x},L);
|
||||
M.watchSms = () => {};
|
||||
const E = (tag, attrs) => {const e=document.createElement(tag);Object.entries(attrs).forEach(([k,v])=>e.setAttribute(k,v));return e;};
|
||||
const view = new Function('view','M','E','L',sms)({extend:x=>x},M,E,L);
|
||||
view.wire = () => {}; view.reload = () => {};
|
||||
document.querySelector('#app').appendChild(view.render());
|
||||
document.querySelector('#mud-sms-num').value = '+90555123456789012345678901234567890';
|
||||
document.querySelector('#mud-sms-convs').innerHTML = '<div class="mud-conv"><div class="n">+90555123456789012345678901234567890</div><div class="p">long-message-preview</div></div>';
|
||||
document.querySelector('#mud-sms-msgs').innerHTML = '<div class="mud-bub">' + 'LongMessage'.repeat(100) + '</div>';
|
||||
}''', [common, sms, lang])
|
||||
page.add_style_tag(content=css)
|
||||
result = page.evaluate('''() => {
|
||||
const root=document.querySelector('.mud-sms'), box=root.getBoundingClientRect();
|
||||
const overflow=[...root.querySelectorAll('input,textarea,button,.mud-bub,.mud-chat,.mud-thread')]
|
||||
.filter(e=>{const r=e.getBoundingClientRect();return r.right>box.right+1||r.left<box.left-1;})
|
||||
.map(e=>e.id||e.className);
|
||||
return {overflow, width:document.documentElement.scrollWidth,
|
||||
chinese:/[\u3400-\u9fff]/.test(root.innerText),
|
||||
background:getComputedStyle(root.querySelector('.mud-chat')).backgroundColor,
|
||||
color:getComputedStyle(root.querySelector('input')).color};
|
||||
}''')
|
||||
label = (width, theme, dark, lang)
|
||||
assert not result['overflow'], (label, result)
|
||||
assert result['width'] <= width, (label, result)
|
||||
assert lang == 'zh' or not result['chinese'], (label, 'untranslated', page.inner_text('.mud-sms'))
|
||||
assert result['background'] == ('rgb(32, 34, 38)' if dark else 'rgb(255, 255, 255)'), (label, result)
|
||||
assert result['color'] == ('rgb(238, 238, 238)' if dark else 'rgb(34, 34, 34)'), (label, result)
|
||||
checked += 1
|
||||
page.close()
|
||||
browser.close()
|
||||
print(f'SMS layout: {checked} viewport/theme/locale cases passed')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,91 @@
|
||||
"""E5 dashboard backports must preserve the single-SIM MU300 contracts."""
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
from helpers import TOP, ShellTest
|
||||
|
||||
PKG = TOP / 'openwrt/luci-app-mu300'
|
||||
LIB = PKG / 'root/usr/libexec/unisoc-modem'
|
||||
JS = PKG / 'htdocs/luci-static/resources'
|
||||
|
||||
|
||||
class Refresh(unittest.TestCase):
|
||||
@unittest.skipUnless(shutil.which('node'), 'Node required')
|
||||
def test_scheduler_and_counter_resets(self):
|
||||
result = subprocess.run(['node', str(TOP / 'tests/dashboard_refresh.js'),
|
||||
str(JS / 'mu300/refresh.js'), str(JS / 'view/mu300/locks.js')],
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
@unittest.skipUnless(shutil.which('node'), 'Node required')
|
||||
def test_js_syntax(self):
|
||||
for p in JS.rglob('*.js'):
|
||||
result = subprocess.run(['node', '--check', str(p)], capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, str(p) + result.stderr)
|
||||
|
||||
def test_rpc_packaging_and_safety_boundaries(self):
|
||||
rpc = (PKG / 'root/usr/libexec/rpcd/mu300dash').read_text()
|
||||
self.assertIn('"rates": { }', rpc)
|
||||
self.assertIn('"cells": { }', rpc)
|
||||
self.assertIn('"$cage" -ge "$TTL"', rpc)
|
||||
self.assertIn('"$sage" -ge "$TTL_FAST"', rpc)
|
||||
rates = (LIB / 'dashboard-rates').read_text()
|
||||
self.assertNotIn('AT+', rates)
|
||||
self.assertNotIn('dashboard-info', rates)
|
||||
self.assertIn("'data_interface'", rates)
|
||||
self.assertIn("'data_device'", rates)
|
||||
for name in ('dashboard-rates', 'refresh-config', 'operator.uc'):
|
||||
self.assertTrue((LIB / name).is_file())
|
||||
for name in ('home', 'locks'):
|
||||
src = (JS / f'view/mu300/{name}.js').read_text()
|
||||
self.assertIn('unload: function()', src)
|
||||
self.assertNotIn('e5-', rates)
|
||||
self.assertNotIn('t551m', rates)
|
||||
|
||||
def test_sms_styles_are_scoped_and_backend_unchanged(self):
|
||||
css = (JS / 'view/mu300/sms.css').read_text()
|
||||
self.assertIn('@container(max-width:680px)', css)
|
||||
self.assertIn('minmax(0,1fr)', css)
|
||||
self.assertIn('overflow-wrap:anywhere', css)
|
||||
self.assertIn('var(--surface', css)
|
||||
sms = (JS / 'view/mu300/sms.js').read_text()
|
||||
self.assertIn("L.resource('view/mu300/sms.css')", sms)
|
||||
self.assertEqual(sms.count('id="mud-sms-num"'), 1)
|
||||
self.assertIn('M.callSmsSend', sms)
|
||||
self.assertNotIn('callSim', sms)
|
||||
|
||||
|
||||
class StagedCollector(ShellTest):
|
||||
def test_engineering_and_neighbors_published_before_identity(self):
|
||||
self.stub('uci', 'exit 1')
|
||||
self.stub('ucode', "printf 'null\\n'")
|
||||
self.stub('fake-at', '''
|
||||
printf '%s\\n' "$*" >> "$STUBLOG/commands"
|
||||
case "$*" in
|
||||
*'AT+CFUN?'*) printf '+CFUN: 1\\nOK\\n' ;;
|
||||
*'AT+CEREG?'*) printf '+CEREG: 2,1,"01","01",7\\nOK\\n' ;;
|
||||
*'AT+CESQ'*) printf '+CESQ: 99,99,255,255,30,80\\nOK\\n' ;;
|
||||
*'AT+CSCS?;+COPS?'*) cp "$MU300_DASH_DIR/sig.json" "$STUBLOG/engineering.json" ;;
|
||||
*'AT+SPENGMD=0,6,6'*) cp "$MU300_DASH_DIR/cell.json" "$STUBLOG/before-neighbors.json" ;;
|
||||
*'AT+CGEQOSRDP=1'*) cp "$MU300_DASH_DIR/cell.json" "$STUBLOG/before-qos.json" ;;
|
||||
*'AT+CNUM'*) cp "$MU300_DASH_DIR/cell.json" "$STUBLOG/before-number.json" ;;
|
||||
*) printf 'OK\\n' ;;
|
||||
esac''')
|
||||
for i, shell in enumerate(self.each_shell()):
|
||||
cache = self.tmp / f'cache-{i}'
|
||||
result = self.script(shell, LIB / 'cell', 'full', MU300_AT=self.stubs / 'fake-at',
|
||||
MU300_DASH_IDENT_DIR=self.tmp / f'ident-{i}', MU300_DASH_DIR=cache,
|
||||
MU300_DASH_POOL_DIR=self.tmp / f'pool-{i}')
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
get = lambda name: json.loads((self.tmp / name).read_text())
|
||||
self.assertNotIn('partial', get('engineering.json'))
|
||||
self.assertEqual(get('engineering.json')['cfun'], 1)
|
||||
self.assertEqual(get('before-neighbors.json')['neigh_pending'], 1)
|
||||
self.assertEqual(get('before-qos.json')['neigh_pending'], 0)
|
||||
self.assertEqual(get('before-number.json')['partial'], 1)
|
||||
complete = json.loads((cache / 'cell.json').read_text())
|
||||
self.assertEqual(complete['partial'], 0)
|
||||
self.assertEqual(complete['neigh_pending'], 0)
|
||||
self.assertIn('msisdn', complete['ident'])
|
||||
@@ -69,6 +69,30 @@ const M = new Function('rpc', 'baseclass', 'L', 'document', 'navigator', 'getCom
|
||||
result = subprocess.run(['node', '-', str(COMMON)], input=harness, capture_output=True, text=True, encoding='utf-8')
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
def test_staged_cell_merge_does_not_erase_pending_fields(self):
|
||||
self.run_js("""
|
||||
const old = {ts:1, ident:{msisdn:'123'}, qos:{qci:9}, neigh:[{pci:2}], lte:{band:3}};
|
||||
let merged = M.mergeCell(old, {ts:2, partial:1, neigh_pending:1, ident:null, qos:null, neigh:null, lte:{band:1}});
|
||||
if (merged.ident.msisdn !== '123' || merged.neigh.length !== 1 || merged.qos.qci !== 9 || merged.lte.band !== 1)
|
||||
throw Error('pending fields erased');
|
||||
merged = M.mergeCell(merged, {ts:2, partial:1, neigh_pending:0, neigh:null});
|
||||
if (merged.neigh !== null || merged.ident.msisdn !== '123') throw Error('neighbor completion');
|
||||
merged = M.mergeCell(merged, {ts:2, partial:0, ident:{msisdn:null}, qos:null, neigh:null});
|
||||
if (merged.ident.msisdn !== null || merged.qos !== null) throw Error('completed empty value must replace old value');
|
||||
if (old.ts !== 1 || old.lte.band !== 3) throw Error('input mutated');
|
||||
""")
|
||||
|
||||
def test_operator_aliases_leave_foreign_names_unchanged(self):
|
||||
self.run_js("""
|
||||
for (const locale of ['en', 'tr', 'zh_Hans']) {
|
||||
lang = locale;
|
||||
for (const [alias, name] of [['CHN-UNICOM','中国联通'], ['CHN_CT','中国电信'], ['CHINA MOBILE','中国移动'], ['CBN','中国广电']])
|
||||
if (M.carrierName({name:alias}) !== M.translate(name)) throw Error(locale + ':' + alias);
|
||||
for (const name of ['Vodafone', 'Turkcell', 'FACE', 'Orange F'])
|
||||
if (M.carrierName({name}) !== name) throw Error('foreign name changed:' + name);
|
||||
}
|
||||
""")
|
||||
|
||||
def test_three_dashboard_languages(self):
|
||||
self.run_js("""
|
||||
lang = 'en';
|
||||
@@ -125,7 +149,8 @@ const labels = [
|
||||
'删除这条短信', '本地 + SIM', '发送失败:未知错误',
|
||||
'收件人:号码,如 10086 或 +86...', '蜂窝逻辑接口',
|
||||
'等待 AT 就绪上限(秒)', '留空则从 netifd 自动获取',
|
||||
'主页刷新间隔(秒)', '仅控制主页状态看板的刷新频率;允许 0.5–60 秒,保存后重新进入主页生效。'
|
||||
'主页刷新间隔(秒)', '主页状态每 2–60 秒刷新,网速独立每秒刷新;旧设置不足 2 秒时按 2 秒处理。保存后重新进入主页生效。',
|
||||
'正在更新…', '读取失败,稍后重试', '收件人', '会话'
|
||||
];
|
||||
for (const locale of ['en', 'tr']) {
|
||||
lang = locale;
|
||||
|
||||
@@ -67,6 +67,10 @@ for f in ./lib/netifd/proto/mu300cell.sh ./lib/netifd/proto/mu300cell-v6.sh \
|
||||
./etc/init.d/mu300-smsd ./etc/sysctl.d/99-mu300-console.conf \
|
||||
./usr/share/luci/menu.d/luci-app-mu300.json \
|
||||
./www/luci-static/resources/view/mu300/home.js \
|
||||
./www/luci-static/resources/mu300/refresh.js \
|
||||
./www/luci-static/resources/view/mu300/sms.css \
|
||||
./usr/libexec/unisoc-modem/dashboard-rates \
|
||||
./usr/libexec/unisoc-modem/operator.uc ./usr/libexec/unisoc-modem/refresh-config \
|
||||
./www/luci-static/resources/view/mu300/device.js \
|
||||
./usr/libexec/unisoc-modem/device-usb \
|
||||
./etc/hotplug.d/net/90-unisoc-usb-host \
|
||||
|
||||
@@ -81,6 +81,9 @@ MU300_INPUTS="$IN" MU300_LUCI_PLUGIN_SRC="$TOP/openwrt/luci-app-mu300" MU300_VER
|
||||
sh "$TOP/openwrt/build-rootfs.sh" mu300-openwrt-release.tar.gz >/dev/null
|
||||
mv "$TOP/openwrt/mu300-openwrt-release.tar.gz" "$D/mu300-openwrt-rootfs.tar.gz"
|
||||
for f in ./usr/share/luci/menu.d/luci-app-mu300.json ./www/luci-static/resources/view/mu300/home.js \
|
||||
./www/luci-static/resources/mu300/refresh.js ./www/luci-static/resources/view/mu300/sms.css \
|
||||
./usr/libexec/unisoc-modem/dashboard-rates ./usr/libexec/unisoc-modem/operator.uc \
|
||||
./usr/libexec/unisoc-modem/refresh-config \
|
||||
./www/luci-static/resources/view/mu300/device.js ./usr/libexec/unisoc-modem/device-usb \
|
||||
./etc/hotplug.d/net/90-unisoc-usb-host ./etc/hotplug.d/iface/90-unisoc-usb-host \
|
||||
./etc/init.d/unisoc-modem-ui ./usr/lib/lua/luci/i18n/mu300.en.lmo ./usr/lib/lua/luci/i18n/mu300.tr.lmo; do
|
||||
|
||||
Reference in new issue
Block a user