read sms loop

This commit is contained in:
stswangzhiping
2026-05-01 09:29:04 +08:00
parent 44f69a99b7
commit 46153b5a5e
2 changed files with 202 additions and 166 deletions

View File

@@ -8,6 +8,7 @@ const path = require('path');
const { exec } = require('child_process');
const { ClawClient } = require('../lib/client');
const log = require('../lib/logger');
const { pollSms } = require('../drivers/sim/sms-reader');
// 每次启动绑定 Quectel 串口驱动(失败不影响主流程)
const bindScript = path.join(__dirname, '..', 'tools', 'bind-quectel-serial.sh');
@@ -16,15 +17,40 @@ exec(`bash "${bindScript}"`, (err, stdout, stderr) => {
else log.info('clawd', `bind-quectel-serial: ok`);
});
let smsTimer = null;
let smsPolling = false;
async function pollSmsSafe() {
if (smsPolling) return;
smsPolling = true;
try {
const text = await pollSms();
process.stdout.write(text);
} catch (err) {
log.warn('clawd', `sms-reader poll failed: ${err.message}`);
} finally {
smsPolling = false;
}
}
const client = new ClawClient();
client.start();
pollSmsSafe();
smsTimer = setInterval(pollSmsSafe, 15_000);
let stopping = false;
function shutdown(signal) {
if (stopping) return;
stopping = true;
log.info('clawd', `收到 ${signal},正在停止...`);
if (smsTimer) {
clearInterval(smsTimer);
smsTimer = null;
}
client.stop();
setTimeout(() => process.exit(0), 500);
}