fix: 调整 ICCID 查询方式
This commit is contained in:
+38
-10
@@ -1316,12 +1316,16 @@ class ModemManager extends EventEmitter {
|
|||||||
return this.iccid;
|
return this.iccid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commands = ['AT+ICCID', 'AT+CCID', 'AT+QCCID'];
|
||||||
|
|
||||||
|
for (const command of commands) {
|
||||||
try {
|
try {
|
||||||
const resp = await this.sendATCommand('AT+CCID', 2000);
|
const resp = await this.sendATCommand(command, 2000);
|
||||||
const match = resp.match(/\+CCID:\s*(\d+)/);
|
const iccid = this.parseICCIDResponse(resp);
|
||||||
if (match) {
|
|
||||||
|
if (iccid) {
|
||||||
const previousICCID = this.iccid;
|
const previousICCID = this.iccid;
|
||||||
this.iccid = match[1];
|
this.iccid = iccid;
|
||||||
this.iccidCheckedAt = new Date().toISOString();
|
this.iccidCheckedAt = new Date().toISOString();
|
||||||
if (previousICCID !== this.iccid) {
|
if (previousICCID !== this.iccid) {
|
||||||
logger.info(`✓ 当前SIM ICCID: ${this.formatICCID(this.iccid)}`);
|
logger.info(`✓ 当前SIM ICCID: ${this.formatICCID(this.iccid)}`);
|
||||||
@@ -1329,17 +1333,41 @@ class ModemManager extends EventEmitter {
|
|||||||
return this.iccid;
|
return this.iccid;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.iccid = null;
|
logger.debug(`${command}未返回可识别ICCID: ${this.formatATResponse(resp)}`);
|
||||||
this.iccidCheckedAt = new Date().toISOString();
|
|
||||||
return null;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (options.refresh) {
|
logger.debug(`${command}查询ICCID失败: ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.iccid = null;
|
this.iccid = null;
|
||||||
this.iccidCheckedAt = new Date().toISOString();
|
this.iccidCheckedAt = new Date().toISOString();
|
||||||
}
|
logger.warn('查询ICCID失败: 模组未返回可识别ICCID');
|
||||||
logger.error('查询ICCID失败:', err);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parseICCIDResponse(resp) {
|
||||||
|
const lines = String(resp || '')
|
||||||
|
.split('\n')
|
||||||
|
.map(line => line.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
if (/^AT/i.test(line) || line === 'OK' || line === 'ERROR') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const prefixed = line.match(/^\+(?:ICCID|CCID|QCCID):\s*"?([0-9]{18,22})"?/i);
|
||||||
|
if (prefixed) {
|
||||||
|
return prefixed[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
const plain = line.match(/^"?([0-9]{18,22})"?$/);
|
||||||
|
if (plain) {
|
||||||
|
return plain[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
formatICCID(iccid) {
|
formatICCID(iccid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user