LAPTOP-SNT8I5JK\Boounion
2025-05-15 48d848201d91187c21d015ed54c0e5e81ceb2c66
SourceCode/Bond/Servo/AlarmManager.cpp
@@ -781,18 +781,21 @@
        std::string cell;
        AlarmInfo alarm;
        std::getline(ss, cell, ',');
        std::getline(ss, alarm.strUnitID, ',');
        std::getline(ss, alarm.strUnitNo, ',');
        std::getline(ss, cell, ',');
        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");
            if (!std::getline(ss, cell, ',')) throw std::runtime_error("Missing field: AlarmLevel");
        alarm.nAlarmLevel = std::stoi(cell);
        std::getline(ss, cell, ',');
            if (!std::getline(ss, cell, ',')) throw std::runtime_error("Missing field: AlarmCode");
        alarm.nAlarmCode = std::stoi(cell);
        std::getline(ss, cell, ',');
            if (!std::getline(ss, cell, ',')) throw std::runtime_error("Missing field: AlarmID");
        alarm.nAlarmID = std::stoi(cell);
        std::getline(ss, alarm.strAlarmText, ',');
        std::getline(ss, alarm.strDescription, ',');
            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;
        }
@@ -800,6 +803,12 @@
            std::cerr << "Duplicate AlarmID: " << alarm.nAlarmID << std::endl;
        }
    }
        catch (const std::exception& e) {
            // 捕获并记录解析错误
            std::cerr << "Error parsing line: " << line << " - " << e.what() << std::endl;
            continue;
        }
    }
    file.close();
    return true;