feat: 添加移动数据开关和启动断网保护

This commit is contained in:
2026-06-26 16:48:40 +08:00
parent 69c49ab29b
commit 679737c737
7 changed files with 462 additions and 50 deletions
+44
View File
@@ -364,6 +364,7 @@ class APIServer {
try {
const signal = await this.modem.getSignalQuality();
const operator = await this.modem.getOperator();
const mobileData = await this.modem.getMobileDataStatus();
res.json({
success: true,
@@ -372,6 +373,7 @@ class APIServer {
model: this.modem.modelInfo,
signal,
operator,
mobileData,
uptime: process.uptime()
}
});
@@ -466,6 +468,48 @@ class APIServer {
}
});
// 查询移动数据连接状态
this.app.get('/api/modem/mobile-data', async (req, res) => {
try {
const mobileData = await this.modem.getMobileDataStatus();
res.json({
success: true,
data: mobileData
});
} catch (err) {
logger.error('查询移动数据状态失败:', err);
res.status(500).json({
success: false,
error: err.message
});
}
});
// 开启或关闭移动数据连接
this.app.post('/api/modem/mobile-data', async (req, res) => {
try {
if (typeof req.body?.enabled !== 'boolean') {
return res.status(400).json({
success: false,
error: '缺少必要参数: enabled'
});
}
const mobileData = await this.modem.setMobileDataEnabled(req.body.enabled);
res.json({
success: true,
message: req.body.enabled ? '移动数据已开启' : '移动数据已关闭',
data: mobileData
});
} catch (err) {
logger.error('设置移动数据状态失败:', err);
res.status(500).json({
success: false,
error: err.message
});
}
});
// 发送AT命令
this.app.post('/api/modem/at', async (req, res) => {
try {