From c35ab2e33615e51e067981c3cda39f4884fad28b Mon Sep 17 00:00:00 2001 From: cxh Date: Thu, 22 Jan 2026 16:53:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/serial_AT.cpp | 55 ++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/serial_AT.cpp b/src/serial_AT.cpp index 5a2d02a..f892b5b 100644 --- a/src/serial_AT.cpp +++ b/src/serial_AT.cpp @@ -75,57 +75,50 @@ static std::vector split_csv(const std::string& line) // ---------- 解析入口 ---------- static void parse_qeng_servingcell(const std::string& line) { - // 1) 必须先确认是 +QENG: + // 必须有前缀 if (line.rfind("+QENG:", 0) != 0) return; - // 2) 切掉 "+QENG:" 前缀,留下后面的 CSV + // 去掉前缀 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.back())) payload.pop_back(); - // 3) 对 payload 做 CSV split(此时第一项应当是 servingcell) 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; 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") { - // servingcell, CONNECT, NR5G-SA, TDD, 460,00, NRCellID, TAC, ARFCN, NR_BAND?, PCI, SSB, RSRP, RSRQ, SINR, ... - // 你这条样例切完前缀后的索引: - // 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) + // 按手册 NR5G-SA 至少 18 个字段(到 SCS) + if (t.size() >= 18) { - safe_stoi(t[8], arfcn); - safe_stoi(t[10], pci); + safe_stoi(t[7], pci); // PCID + safe_stoi(t[9], arfcn); // ARFCN + safe_stoi(t[10], band); // band + safe_stoi(t[12], rsrp); safe_stoi(t[13], rsrq); 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") { // 注意: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(line.find_last_not_of(" \t\r\n") + 1); - LOG_INFO("[serial_at][RAW] " + line); - // IMEI:14~17 位纯数字 if (line.size() >= 14 && line.size() <= 17 && std::all_of(line.begin(), line.end(), ::isdigit)) {