* @brief Parses a CSV register map with header-based column auto-detection. */
| 458 | * @brief Parses a CSV register map with header-based column auto-detection. |
| 459 | */ |
| 460 | bool DataModel::ModbusMapImporter::parseCSV(const QString& path) |
| 461 | { |
| 462 | QFile file(path); |
| 463 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) |
| 464 | return false; |
| 465 | |
| 466 | if (file.size() > kMaxImportFileBytes) |
| 467 | return false; |
| 468 | |
| 469 | const QString content = QString::fromUtf8(file.readAll()); |
| 470 | file.close(); |
| 471 | |
| 472 | const auto lines = content.split('\n', Qt::SkipEmptyParts); |
| 473 | if (lines.count() < 2) |
| 474 | return false; |
| 475 | |
| 476 | const auto map = buildCsvColumnMap(lines[0].trimmed().split(',')); |
| 477 | if (map.addr < 0) |
| 478 | return false; |
| 479 | |
| 480 | for (int row = 1; row < lines.count(); ++row) { |
| 481 | const auto line = lines[row].trimmed(); |
| 482 | if (line.isEmpty() || line.startsWith('#')) |
| 483 | continue; |
| 484 | |
| 485 | RegisterEntry entry; |
| 486 | if (!parseCsvRow(line.split(','), map, row, entry)) |
| 487 | continue; |
| 488 | |
| 489 | m_registers.append(entry); |
| 490 | } |
| 491 | |
| 492 | return !m_registers.isEmpty(); |
| 493 | } |
| 494 | |
| 495 | //-------------------------------------------------------------------------------------------------- |
| 496 | // XML parser |
nothing calls this directly
no test coverage detected