调整解析

This commit is contained in:
cxh 2026-01-22 16:53:48 +08:00
parent e0f30c6d75
commit c35ab2e336

View File

@ -75,57 +75,50 @@ static std::vector<std::string> split_csv(const std::string& line)
// ---------- 解析入口 ---------- // ---------- 解析入口 ----------
static void parse_qeng_servingcell(const std::string& line) static void parse_qeng_servingcell(const std::string& line)
{ {
// 1) 必须先确认是 +QENG: // 必须有前缀
if (line.rfind("+QENG:", 0) != 0) return; if (line.rfind("+QENG:", 0) != 0) return;
// 2) 切掉 "+QENG:" 前缀,留下后面的 CSV // 去掉前缀
std::string payload = line.substr(std::string("+QENG:").size()); std::string payload = line.substr(std::string("+QENG:").size());
// trim payload
while (!payload.empty() && isspace(payload.front())) payload.erase(payload.begin()); while (!payload.empty() && isspace(payload.front())) payload.erase(payload.begin());
while (!payload.empty() && isspace(payload.back())) payload.pop_back(); while (!payload.empty() && isspace(payload.back())) payload.pop_back();
// 3) 对 payload 做 CSV split此时第一项应当是 servingcell
auto t = split_csv(payload); auto t = split_csv(payload);
if (t.size() < 4) return; if (t.size() < 5) return;
// t[0] = servingcell // 语法检查
// t[1] = CONNECT/NOCONN
// t[2] = RAT: LTE / NR5G-SA / NR5G-NSA
// t[3] = TDD/FDD/...
if (t[0] != "servingcell") return; if (t[0] != "servingcell") return;
std::string rat = t[2]; std::string rat = t[2];
int pci = -1, rsrp = 0, rsrq = 0, sinr = 0, arfcn = 0; int pci = -1;
int band = -1;
int arfcn = -1;
int rsrp = 0;
int rsrq = 0;
int sinr = 0;
if (rat == "NR5G-SA") if (rat == "NR5G-SA")
{ {
// servingcell, CONNECT, NR5G-SA, TDD, 460,00, NRCellID, TAC, ARFCN, NR_BAND?, PCI, SSB, RSRP, RSRQ, SINR, ... // 按手册 NR5G-SA 至少 18 个字段(到 SCS
// 你这条样例切完前缀后的索引: if (t.size() >= 18)
// 0 servingcell
// 1 CONNECT
// 2 NR5G-SA
// 3 TDD
// 4 460
// 5 00
// 6 A053FB01F
// 7 494
// 8 100186 <- ARFCN
// 9 524910
// 10 41 <- PCI
// 11 60
// 12 -90 <- RSRP
// 13 -7 <- RSRQ
// 14 11 <- SINR
if (t.size() >= 15)
{ {
safe_stoi(t[8], arfcn); safe_stoi(t[7], pci); // PCID
safe_stoi(t[10], pci); safe_stoi(t[9], arfcn); // ARFCN
safe_stoi(t[10], band); // band
safe_stoi(t[12], rsrp); safe_stoi(t[12], rsrp);
safe_stoi(t[13], rsrq); safe_stoi(t[13], rsrq);
safe_stoi(t[14], sinr); safe_stoi(t[14], sinr);
// 下面这三个你暂时没放进 RadioInfo也可以先不存
// int tx_power=0, srxlev=0, scs=0;
// safe_stoi(t[15], tx_power);
// safe_stoi(t[16], srxlev);
// safe_stoi(t[17], scs);
} }
} }
else if (rat == "LTE") else if (rat == "LTE")
{ {
// 注意LTE 的字段布局各固件/版本差异挺大,你原来的索引不一定总对 // 注意LTE 的字段布局各固件/版本差异挺大,你原来的索引不一定总对
@ -303,8 +296,6 @@ static void handle_serial_at_data(const std::string& data)
line.erase(0, line.find_first_not_of(" \t\r\n")); line.erase(0, line.find_first_not_of(" \t\r\n"));
line.erase(line.find_last_not_of(" \t\r\n") + 1); line.erase(line.find_last_not_of(" \t\r\n") + 1);
LOG_INFO("[serial_at][RAW] " + line);
// IMEI14~17 位纯数字 // IMEI14~17 位纯数字
if (line.size() >= 14 && line.size() <= 17 && std::all_of(line.begin(), line.end(), ::isdigit)) if (line.size() >= 14 && line.size() <= 17 && std::all_of(line.begin(), line.end(), ::isdigit))
{ {