From 2444bfcf24f4d699a3086fb09c33c00c486f5d1d Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期四, 13 十一月 2025 16:54:38 +0800
Subject: [PATCH] 1.最大化/窗口标题/版本号
---
SourceCode/Bond/Servo/AlarmManager.cpp | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/SourceCode/Bond/Servo/AlarmManager.cpp b/SourceCode/Bond/Servo/AlarmManager.cpp
index 2143f34..56d6cbb 100644
--- a/SourceCode/Bond/Servo/AlarmManager.cpp
+++ b/SourceCode/Bond/Servo/AlarmManager.cpp
@@ -784,16 +784,33 @@
// 读取报警文件
bool AlarmManager::readAlarmFile(const std::string& filename) {
- std::ifstream file(filename);
- std::string line;
- bool first_line = true;
-
+ std::ifstream file(filename, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Error opening file!" << std::endl;
return false;
}
- while (std::getline(file, line)) {
+ auto getline_cross = [](std::ifstream& f, std::string& out) -> bool {
+ out.clear();
+ char ch;
+ while (f.get(ch)) {
+ if (ch == '\r') {
+ // 处理 \r\n 或 单独 \r
+ if (f.peek() == '\n') f.get();
+ break;
+ }
+ else if (ch == '\n') {
+ break;
+ }
+ out.push_back(ch);
+ }
+ return !out.empty() || !f.eof();
+ };
+
+ std::string line;
+ bool first_line = true;
+
+ while (getline_cross(file, line)) {
if (first_line) {
first_line = false;
continue;
@@ -804,7 +821,6 @@
AlarmInfo alarm;
try {
- // 逐字段解析并验证
if (!std::getline(ss, cell, ',')) throw std::runtime_error("Missing field: No");
if (!std::getline(ss, alarm.strUnitID, ',')) throw std::runtime_error("Missing field: UnitID");
if (!std::getline(ss, alarm.strUnitNo, ',')) throw std::runtime_error("Missing field: UnitNo");
@@ -817,7 +833,6 @@
if (!std::getline(ss, alarm.strAlarmText, ',')) throw std::runtime_error("Missing field: AlarmText");
if (!std::getline(ss, alarm.strDescription, ',')) throw std::runtime_error("Missing field: Description");
- // 检查是否重复
if (m_mapAlarm.find(alarm.nAlarmID) == m_mapAlarm.end()) {
m_mapAlarm[alarm.nAlarmID] = alarm;
}
@@ -826,7 +841,6 @@
}
}
catch (const std::exception& e) {
- // 捕获并记录解析错误
std::cerr << "Error parsing line: " << line << " - " << e.what() << std::endl;
continue;
}
--
Gitblit v1.9.3