Skip to content

Remove modbus protocol and related code#3

Open
jgeudens wants to merge 2 commits intomasterfrom
dev/remove_modbus
Open

Remove modbus protocol and related code#3
jgeudens wants to merge 2 commits intomasterfrom
dev/remove_modbus

Conversation

@jgeudens
Copy link
Member

@jgeudens jgeudens commented Mar 20, 2026

Summary by CodeRabbit

Release Notes

  • Refactoring

    • Simplified Modbus communication architecture by removing intermediate polling coordination layer.
    • Removed MBC configuration file import functionality.
    • Removed register import dialog and associated UI workflows.
    • Removed register filtering and update preview features.
  • Tests

    • Removed all communication and import-related test suites.

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

Walkthrough

This pull request removes MBC file import functionality and its associated Modbus communication infrastructure. Deleted are: the MBC configuration example file, import dialogs and UI models, Modbus connection management classes, register value handling and polling layers, and all related unit tests and test infrastructure.

Changes

Cohort / File(s) Summary
MBC Configuration & File Import
data/example.mbc, src/importexport/mbcfileimporter.*, src/importexport/mbcregisterdata.*
Removed MBC file format handling, including example configuration file, XML parsing/import logic, and register data model used to represent imported Modbus registers.
MBC Import UI & Dialogs
src/dialogs/importmbcdialog.*, src/dialogs/mbcheader.h
Removed MBC import dialog window, custom header view with checkbox support, and all file selection/register import UI components.
Modbus Connection & Communication
src/communication/modbusconnection.*, src/communication/modbusmaster.*, src/communication/modbusdataunit.*, src/communication/modbusresultmap.h
Removed Modbus TCP/serial connection lifecycle management, request/response handling, master polling orchestration, and associated data structures for managing register addresses with slave IDs and result mappings.
Register Read Management
src/communication/readregisters.*, src/communication/registervaluehandler.*
Removed queued register read sequencing logic, batch read clustering with consecutive-address constraints, and register value processing/aggregation with endianness handling and double conversion.
MBC Register Models
src/models/mbcregistermodel.*, src/models/mbcregisterfilter.*, src/models/mbcupdatemodel.*
Removed table models backing MBC register import UI, including filter proxy for tab/text filtering, and update-detection model for tracking changed register expressions/labels.
Modbus Polling & Data Flow
src/communication/modbuspoll.*, src/communication/modbuspoll.h
Simplified polling workflow: removed multi-connection orchestration, register value handler integration, and result aggregation logic; reduced to basic register list iteration with immediate result emission.
GUI Integration
src/dialogs/mainwindow.*, src/models/guimodel.*
Removed MBC import menu action, associated dialog invocation, and last-imported-file tracking state.
Test Infrastructure
tests/communication/*, tests/importexport/*, tests/models/tst_mbc*, tests/testslave/*, tests/util/tst_modbusaddress.*
Removed comprehensive test suites for Modbus communication, register handling, MBC parsing, fake connection stubs, and address utilities; also removed test device/slave infrastructure and CMake test configurations.
Utility
src/util/modbusdatatype.cpp
Removed leading blank line (formatting).

Possibly related PRs

  • PR #1: Applies formatting/tooling updates to src/communication/ and related Modbus communication files that are being removed in this change.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Remove modbus protocol and related code' directly and accurately summarises the primary purpose of this changeset: a comprehensive removal of Modbus-related functionality across multiple layers.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/remove_modbus
📝 Coding Plan
  • Generate coding plan for human review comments

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/dialogs/mainwindow.cpp (1)

850-862: ⚠️ Potential issue | 🟠 Major

Add an explicit .mbc rejection guard in DataFileHandler::openDataFile() before the data-file parsing path.

Currently, drag-and-drop and CLI opens of .mbc files fallthrough to the generic data importer, which will attempt CSV-like parsing and fail with confusing importer errors rather than a clear "unsupported format" message. Although FILE_TYPE_MBC exists in the file selection helpers, no dedicated MBC handler or import functionality has been implemented in the codebase. The .mbc file format should be explicitly rejected in openDataFile() with a specific error message, or alternatively, a proper MBC import path should be implemented to align with the documented functionality.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/dialogs/mainwindow.cpp` around lines 850 - 862, Add an explicit `.mbc`
rejection in DataFileHandler::openDataFile(): detect files whose suffix
(case-insensitive) equals "mbc" (the same extension represented by
FILE_TYPE_MBC/mbc) and immediately abort the data-file import path with a clear,
user-facing error (e.g., "Unsupported file format: .mbc — no MBC importer
implemented") instead of falling through to CSV-like parsing; update
DataFileHandler::openDataFile to return/throw the appropriate error or call the
existing UI/error-reporting helper so MainWindow::handleFileOpen (which
currently routes non-.mbs files to _pDataFileHandler->openDataFile) surfaces a
specific unsupported-format message for .mbc files.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/communication/modbuspoll.cpp`:
- Around line 60-82: The current loop in ModbusPoll builds a results list of
default ResultDouble() (which are NO_VALUE) and emits
registerDataReady(results), causing empty samples downstream; fix by either (A)
preventing this placeholder path when the Modbus backend is disabled: stop
scheduling the timer and do not emit registerDataReady (e.g., return early from
ModbusPoll::triggerRegisterRead or disable _pPollTimer when backend not
configured), or (B) populate results with actual register values before
emitting: iterate _registerList and read each register via the real Modbus read
path (use the existing read method or backend API used elsewhere) to set valid
ResultDouble values, then emit registerDataReady(results) and reschedule the
timer as before.

---

Outside diff comments:
In `@src/dialogs/mainwindow.cpp`:
- Around line 850-862: Add an explicit `.mbc` rejection in
DataFileHandler::openDataFile(): detect files whose suffix (case-insensitive)
equals "mbc" (the same extension represented by FILE_TYPE_MBC/mbc) and
immediately abort the data-file import path with a clear, user-facing error
(e.g., "Unsupported file format: .mbc — no MBC importer implemented") instead of
falling through to CSV-like parsing; update DataFileHandler::openDataFile to
return/throw the appropriate error or call the existing UI/error-reporting
helper so MainWindow::handleFileOpen (which currently routes non-.mbs files to
_pDataFileHandler->openDataFile) surfaces a specific unsupported-format message
for .mbc files.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 238e6d37-61b9-4fbd-9523-05750240f5de

📥 Commits

Reviewing files that changed from the base of the PR and between 2b092d8 and ecc0e52.

📒 Files selected for processing (84)
  • data/example.mbc
  • src/communication/modbusconnection.cpp
  • src/communication/modbusconnection.h
  • src/communication/modbusdataunit.cpp
  • src/communication/modbusdataunit.h
  • src/communication/modbusmaster.cpp
  • src/communication/modbusmaster.h
  • src/communication/modbuspoll.cpp
  • src/communication/modbuspoll.h
  • src/communication/modbusresultmap.h
  • src/communication/readregisters.cpp
  • src/communication/readregisters.h
  • src/communication/registervaluehandler.cpp
  • src/communication/registervaluehandler.h
  • src/dialogs/importmbcdialog.cpp
  • src/dialogs/importmbcdialog.h
  • src/dialogs/importmbcdialog.ui
  • src/dialogs/mainwindow.cpp
  • src/dialogs/mainwindow.h
  • src/dialogs/mainwindow.ui
  • src/dialogs/mbcheader.h
  • src/importexport/mbcfileimporter.cpp
  • src/importexport/mbcfileimporter.h
  • src/importexport/mbcregisterdata.cpp
  • src/importexport/mbcregisterdata.h
  • src/models/guimodel.cpp
  • src/models/guimodel.h
  • src/models/mbcregisterfilter.cpp
  • src/models/mbcregisterfilter.h
  • src/models/mbcregistermodel.cpp
  • src/models/mbcregistermodel.h
  • src/models/mbcupdatemodel.cpp
  • src/models/mbcupdatemodel.h
  • src/util/modbusdatatype.cpp
  • tests/CMakeLists.txt
  • tests/communication/CMakeLists.txt
  • tests/communication/communicationhelpers.h
  • tests/communication/tst_communication.cpp
  • tests/communication/tst_communication.h
  • tests/communication/tst_communicationstats.cpp
  • tests/communication/tst_communicationstats.h
  • tests/communication/tst_modbusconnection.cpp
  • tests/communication/tst_modbusconnection.h
  • tests/communication/tst_modbusdatatype.cpp
  • tests/communication/tst_modbusdatatype.h
  • tests/communication/tst_modbusdataunit.cpp
  • tests/communication/tst_modbusdataunit.h
  • tests/communication/tst_modbusmaster.cpp
  • tests/communication/tst_modbusmaster.h
  • tests/communication/tst_modbusmasterfake.cpp
  • tests/communication/tst_modbusmasterfake.h
  • tests/communication/tst_modbuspoll.cpp
  • tests/communication/tst_modbuspoll.h
  • tests/communication/tst_modbusregister.cpp
  • tests/communication/tst_modbusregister.h
  • tests/communication/tst_readregisters.cpp
  • tests/communication/tst_readregisters.h
  • tests/communication/tst_registervaluehandler.cpp
  • tests/communication/tst_registervaluehandler.h
  • tests/importexport/CMakeLists.txt
  • tests/importexport/mbctestdata.cpp
  • tests/importexport/mbctestdata.h
  • tests/importexport/tst_mbcfileimporter.cpp
  • tests/importexport/tst_mbcfileimporter.h
  • tests/importexport/tst_mbcregisterfilter.cpp
  • tests/importexport/tst_mbcregisterfilter.h
  • tests/models/CMakeLists.txt
  • tests/models/tst_mbcregistermodel.cpp
  • tests/models/tst_mbcregistermodel.h
  • tests/models/tst_mbcupdatemodel.cpp
  • tests/models/tst_mbcupdatemodel.h
  • tests/testslave/modbusconnectionfake.cpp
  • tests/testslave/modbusconnectionfake.h
  • tests/testslave/testdevice.cpp
  • tests/testslave/testdevice.h
  • tests/testslave/testslavedata.cpp
  • tests/testslave/testslavedata.h
  • tests/testslave/testslavemodbus.cpp
  • tests/testslave/testslavemodbus.h
  • tests/testslave/testslavemodbusmulti.cpp
  • tests/testslave/testslavemodbusmulti.h
  • tests/util/CMakeLists.txt
  • tests/util/tst_modbusaddress.cpp
  • tests/util/tst_modbusaddress.h
💤 Files with no reviewable changes (80)
  • src/util/modbusdatatype.cpp
  • tests/communication/communicationhelpers.h
  • src/dialogs/mainwindow.ui
  • tests/CMakeLists.txt
  • tests/util/CMakeLists.txt
  • src/communication/modbusresultmap.h
  • tests/models/CMakeLists.txt
  • data/example.mbc
  • src/dialogs/mbcheader.h
  • tests/importexport/CMakeLists.txt
  • tests/communication/CMakeLists.txt
  • tests/communication/tst_modbusmasterfake.h
  • tests/models/tst_mbcupdatemodel.h
  • tests/communication/tst_readregisters.cpp
  • src/dialogs/importmbcdialog.ui
  • tests/communication/tst_modbusdataunit.h
  • src/importexport/mbcfileimporter.h
  • tests/testslave/testslavemodbus.cpp
  • src/models/guimodel.h
  • tests/communication/tst_modbusmasterfake.cpp
  • tests/models/tst_mbcregistermodel.cpp
  • tests/importexport/tst_mbcfileimporter.h
  • tests/util/tst_modbusaddress.cpp
  • tests/communication/tst_registervaluehandler.cpp
  • tests/communication/tst_communication.cpp
  • src/importexport/mbcregisterdata.cpp
  • tests/importexport/tst_mbcfileimporter.cpp
  • tests/testslave/testdevice.cpp
  • tests/util/tst_modbusaddress.h
  • tests/testslave/testslavemodbusmulti.h
  • tests/communication/tst_modbusregister.cpp
  • src/models/mbcregisterfilter.h
  • src/communication/modbusdataunit.h
  • tests/communication/tst_communicationstats.h
  • src/communication/modbusmaster.h
  • tests/communication/tst_modbusdataunit.cpp
  • tests/importexport/mbctestdata.cpp
  • tests/communication/tst_modbusconnection.h
  • tests/testslave/modbusconnectionfake.h
  • tests/testslave/modbusconnectionfake.cpp
  • src/communication/modbusdataunit.cpp
  • tests/testslave/testslavedata.h
  • tests/communication/tst_modbusdatatype.h
  • src/communication/registervaluehandler.cpp
  • tests/communication/tst_modbusmaster.h
  • tests/importexport/tst_mbcregisterfilter.cpp
  • src/models/mbcregisterfilter.cpp
  • tests/testslave/testdevice.h
  • tests/communication/tst_modbusmaster.cpp
  • src/importexport/mbcregisterdata.h
  • tests/importexport/mbctestdata.h
  • tests/testslave/testslavemodbus.h
  • tests/models/tst_mbcregistermodel.h
  • tests/communication/tst_modbusconnection.cpp
  • tests/communication/tst_modbusdatatype.cpp
  • tests/communication/tst_modbusregister.h
  • src/dialogs/importmbcdialog.h
  • tests/communication/tst_readregisters.h
  • tests/models/tst_mbcupdatemodel.cpp
  • src/communication/registervaluehandler.h
  • tests/communication/tst_communicationstats.cpp
  • src/communication/readregisters.cpp
  • src/models/mbcupdatemodel.h
  • tests/communication/tst_modbuspoll.h
  • tests/testslave/testslavemodbusmulti.cpp
  • tests/communication/tst_modbuspoll.cpp
  • src/communication/modbusconnection.h
  • tests/communication/tst_communication.h
  • src/importexport/mbcfileimporter.cpp
  • src/communication/readregisters.h
  • tests/communication/tst_registervaluehandler.h
  • tests/importexport/tst_mbcregisterfilter.h
  • src/models/guimodel.cpp
  • src/models/mbcupdatemodel.cpp
  • src/models/mbcregistermodel.cpp
  • src/communication/modbusmaster.cpp
  • src/models/mbcregistermodel.h
  • src/dialogs/importmbcdialog.cpp
  • tests/testslave/testslavedata.cpp
  • src/communication/modbusconnection.cpp

Comment on lines +60 to +82
ResultDoubleList results;
for (qsizetype i = 0; i < _registerList.size(); i++)
{
regAddrList.append(QList<ModbusDataUnit>());

_pRegisterValueHandler->registerAddresListForConnection(regAddrList.last(), i);

if (regAddrList.last().count() > 0)
{
_activeMastersCount++;
}
results.append(ResultDouble());
}
emit registerDataReady(results);

for (connectionId_t i = 0u; i < ConnectionTypes::ID_CNT; i++)
{
if (regAddrList.at(i).count() > 0)
{
quint8 consecutiveMax = lowestConsecutiveMaxForConnection(i);
_modbusMasters[i]->bActive = true;
_modbusMasters[i]->pModbusMaster->readRegisterList(regAddrList.at(i), consecutiveMax);
}
}
// Reschedule timer
uint waitInterval;
const quint32 passedInterval = static_cast<quint32>(QDateTime::currentMSecsSinceEpoch() - _lastPollStart);

if (_activeMastersCount == 0)
if (passedInterval > _pSettingsModel->pollTime())
{
ModbusResultMap emptyResultMap;
handlePollDone(emptyResultMap, ConnectionTypes::ID_1);
// Poll again immediately
waitInterval = 1;
}
}
}

quint8 ModbusPoll::lowestConsecutiveMaxForConnection(connectionId_t connId) const
{
quint8 consecutiveMax = 128;
QList<deviceId_t> devList = _pSettingsModel->deviceListForConnection(connId);
for (deviceId_t devId : std::as_const(devList))
{
quint8 devConsecutiveMax = _pSettingsModel->deviceSettings(devId)->consecutiveMax();
if (devConsecutiveMax < consecutiveMax)
else
{
consecutiveMax = devConsecutiveMax;
// Set waitInterval to remaining time
waitInterval = _pSettingsModel->pollTime() - passedInterval;
}

_pPollTimer->singleShot(static_cast<int>(waitInterval), this, &ModbusPoll::triggerRegisterRead);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Do not keep polling with placeholder NO_VALUE samples.

This loop now only uses _registerList.size() and appends default-constructed ResultDouble() objects. MainWindow still reaches this path when logging starts (src/dialogs/mainwindow.cpp:471-479), but ResultDouble() defaults to NO_VALUE (src/util/result.h:62-65), and GraphDataHandler::handleRegisterData() forwards that list into QMuParser::setRegistersData() (src/datahandling/graphdatahandler.cpp:73-100). The graph/logging pipeline therefore receives an all-invalid sample set on every poll instead of actual register values.

Please either remove/disable this path together with the Modbus backend, or keep a backend here that can populate successful ResultDouble values before emitting registerDataReady.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/communication/modbuspoll.cpp` around lines 60 - 82, The current loop in
ModbusPoll builds a results list of default ResultDouble() (which are NO_VALUE)
and emits registerDataReady(results), causing empty samples downstream; fix by
either (A) preventing this placeholder path when the Modbus backend is disabled:
stop scheduling the timer and do not emit registerDataReady (e.g., return early
from ModbusPoll::triggerRegisterRead or disable _pPollTimer when backend not
configured), or (B) populate results with actual register values before
emitting: iterate _registerList and read each register via the real Modbus read
path (use the existing read method or backend API used elsewhere) to set valid
ResultDouble values, then emit registerDataReady(results) and reschedule the
timer as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant