Skip to content

Refactor modbus register#18

Merged
jgeudens merged 4 commits intomasterfrom
dev/modbus_register
Apr 2, 2026
Merged

Refactor modbus register#18
jgeudens merged 4 commits intomasterfrom
dev/modbus_register

Conversation

@jgeudens
Copy link
Copy Markdown
Member

@jgeudens jgeudens commented Apr 2, 2026

Summary by CodeRabbit

  • Refactor

    • Simplified internal register handling by moving to a compact data-point representation, streamlining expression parsing and communication setup across the app.
    • Reduced complexity in configuring and serialising read expressions, improving consistency of descriptions shown in logs and diagnostics.
  • Tests

    • Updated test suite to align with the new data-point model.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 04d191f0-7ae7-47fe-9312-bdb6162f4679

📥 Commits

Reviewing files that changed from the base of the PR and between c1d997e and 8946ff9.

📒 Files selected for processing (4)
  • src/communication/datapoint.cpp
  • src/communication/datapoint.h
  • src/communication/modbuspoll.h
  • tests/datahandling/tst_expressionparser.h
✅ Files skipped from review due to trivial changes (1)
  • src/communication/datapoint.h
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/datahandling/tst_expressionparser.h
  • src/communication/datapoint.cpp
  • src/communication/modbuspoll.h

Walkthrough

Replaces the ModbusRegister type with a lightweight DataPoint across communication, parsing, data handling and tests; adds DataPoint implementation and removes ModbusRegister declaration/implementation, adjusting APIs and logic to use address+deviceId strings only.

Changes

Cohort / File(s) Summary
New DataPoint class
src/communication/datapoint.h, src/communication/datapoint.cpp
Adds DataPoint value type with default/parameterised constructors, accessors address()/deviceId()/description(), copy-assignment, operator==, QDebug stream overload and dumpListToString() utility.
Removed ModbusRegister
src/communication/modbusregister.h, src/communication/modbusregister.cpp
Deletes the entire ModbusRegister API and implementation including address/type parsing, endianness and value processing, debug streaming and list dumping.
ModbusPoll refactor
src/communication/modbuspoll.h, src/communication/modbuspoll.cpp
API and member changes to accept QList<DataPoint> instead of QList<ModbusRegister>; buildRegisterExpressions() now emits address strings from DataPoint.
ExpressionParser refactor
src/datahandling/expressionparser.h, src/datahandling/expressionparser.cpp
Replaces modbusRegisters() with dataPoints(), swaps internal storage to _dataPoints, simplifies processRegisterExpression() to validate expressions and extract deviceId only, removes address/type parsing helpers.
Data handling & integration
src/datahandling/graphdatahandler.h, src/datahandling/graphdatahandler.cpp, src/util/expressionchecker.cpp, src/dialogs/mainwindow.cpp
Updates APIs and callers to use QList<DataPoint>, changes logging to DataPoint::dumpListToString(), and adjusts loops/iterations to DataPoint semantics.
Tests updated
tests/datahandling/tst_expressionparser.h, tests/datahandling/tst_expressionparser.cpp, tests/datahandling/tst_graphdatahandler.cpp, tests/util/tst_expressionchecker.cpp
All tests switched from ModbusRegister expectations to DataPoint instances and updated helper signatures and assertions accordingly.

Possibly related PRs

  • Remove modbus protocol and related code #3: Overlaps on large-scale removal/refactor of Modbus-related types and files, including deletion/modification of ModbusRegister usages.
  • Configuration (UI) #6: Modifies ModbusPoll::startCommunication() and adapter configuration paths — intersects with this PR's change of that method signature and expression building.
  • Support adapter #5: Changes ExpressionParser and ModbusPoll code paths related to expression parsing and adapter configuration, overlapping with this PR's parser-to-DataPoint migration.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.13% 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 'Refactor modbus register' accurately describes the main change: replacing the ModbusRegister abstraction with a simpler DataPoint type throughout the codebase.

✏️ 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/modbus_register

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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)
tests/datahandling/tst_expressionparser.h (1)

1-38: ⚠️ Potential issue | 🟡 Minor

Missing include guards.

As per the coding guidelines, all header files must use #ifndef/#define/#endif include guards. The guard name format should be the filename uppercased with dots replaced by underscores.

🛡️ Suggested fix
+#ifndef TST_EXPRESSIONPARSER_H
+#define TST_EXPRESSIONPARSER_H
+
 `#include` "communication/datapoint.h"

 `#include` <QObject>
 ...
 private:
 };
+
+#endif // TST_EXPRESSIONPARSER_H
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/datahandling/tst_expressionparser.h` around lines 1 - 38, Add
traditional include guards to the header to prevent multiple inclusion: wrap the
entire file with `#ifndef/` `#define` / `#endif` using an uppercase guard name derived
from the filename (use TESTS_DATAHANDLING_TST_EXPRESSIONPARSER_H as the guard),
placing the `#ifndef/`#define at the very top (before any includes) and a closing
`#endif` at the end of the file; this applies to the header that declares class
TestExpressionParser so the guard surrounds the current contents.
🧹 Nitpick comments (3)
src/communication/datapoint.h (1)

6-6: Unnecessary QObject include.

DataPoint does not inherit from QObject and does not use any QObject-specific features. This include can be removed.

🧹 Suggested fix
 `#include` "models/device.h"
 `#include` <QDebug>
-#include <QObject>
 `#include` <QString>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/communication/datapoint.h` at line 6, The header currently includes
QObject unnecessarily; remove the line including QObject from datapoint.h
because the DataPoint class does not inherit from or use any QObject-specific
features (look for the DataPoint declaration in datapoint.h and ensure no
QObject dependencies remain), then rebuild to confirm no missing symbols.
src/communication/datapoint.cpp (1)

45-55: Simplify operator== implementation.

The equality comparison can be reduced to a single return statement.

♻️ Suggested refactor
 bool operator==(const DataPoint& dp1, const DataPoint& dp2)
 {
-    if ((dp1._address == dp2._address) && (dp1._deviceId == dp2._deviceId))
-    {
-        return true;
-    }
-    else
-    {
-        return false;
-    }
+    return (dp1._address == dp2._address) && (dp1._deviceId == dp2._deviceId);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/communication/datapoint.cpp` around lines 45 - 55, The operator==
implementation for DataPoint is overly verbose; replace the current if/else in
bool operator==(const DataPoint& dp1, const DataPoint& dp2) with a single return
expression that directly compares dp1._address and dp1._deviceId to dp2._address
and dp2._deviceId (e.g., return (dp1._address == dp2._address) && (dp1._deviceId
== dp2._deviceId);) to simplify the function while preserving behavior.
src/communication/modbuspoll.h (1)

1-2: Consider updating include guard name to match filename.

The include guard COMMUNICATION_MANAGER_H doesn't match the filename modbuspoll.h. Per coding guidelines, the guard name should be the filename uppercased with dots replaced by underscores (i.e., MODBUSPOLL_H).

This is a pre-existing inconsistency, not introduced by this PR, so can be addressed separately.

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

In `@src/communication/modbuspoll.h` around lines 1 - 2, The include guard in
modbuspoll.h currently uses COMMUNICATION_MANAGER_H which mismatches the
filename; update the guard to MODBUSPOLL_H by replacing the
`#ifndef/`#define/#endif macros (search for COMMUNICATION_MANAGER_H in
modbuspoll.h) so the guard equals the filename uppercased with dots replaced by
underscores (MODBUSPOLL_H).
🤖 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/datapoint.cpp`:
- Around line 1-3: The file datapoint.cpp currently includes "datapoint.h"
twice; remove the redundant second `#include` "datapoint.h" so the header is only
included once, and verify the header has proper include guards or `#pragma` once
(in datapoint.h) to prevent future duplicates; update the include list in
datapoint.cpp accordingly.

---

Outside diff comments:
In `@tests/datahandling/tst_expressionparser.h`:
- Around line 1-38: Add traditional include guards to the header to prevent
multiple inclusion: wrap the entire file with `#ifndef/` `#define` / `#endif` using an
uppercase guard name derived from the filename (use
TESTS_DATAHANDLING_TST_EXPRESSIONPARSER_H as the guard), placing the
`#ifndef/`#define at the very top (before any includes) and a closing `#endif` at
the end of the file; this applies to the header that declares class
TestExpressionParser so the guard surrounds the current contents.

---

Nitpick comments:
In `@src/communication/datapoint.cpp`:
- Around line 45-55: The operator== implementation for DataPoint is overly
verbose; replace the current if/else in bool operator==(const DataPoint& dp1,
const DataPoint& dp2) with a single return expression that directly compares
dp1._address and dp1._deviceId to dp2._address and dp2._deviceId (e.g., return
(dp1._address == dp2._address) && (dp1._deviceId == dp2._deviceId);) to simplify
the function while preserving behavior.

In `@src/communication/datapoint.h`:
- Line 6: The header currently includes QObject unnecessarily; remove the line
including QObject from datapoint.h because the DataPoint class does not inherit
from or use any QObject-specific features (look for the DataPoint declaration in
datapoint.h and ensure no QObject dependencies remain), then rebuild to confirm
no missing symbols.

In `@src/communication/modbuspoll.h`:
- Around line 1-2: The include guard in modbuspoll.h currently uses
COMMUNICATION_MANAGER_H which mismatches the filename; update the guard to
MODBUSPOLL_H by replacing the `#ifndef/`#define/#endif macros (search for
COMMUNICATION_MANAGER_H in modbuspoll.h) so the guard equals the filename
uppercased with dots replaced by underscores (MODBUSPOLL_H).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 29e90882-f5e5-4f22-a338-390c84075428

📥 Commits

Reviewing files that changed from the base of the PR and between 77f791f and c1d997e.

📒 Files selected for processing (16)
  • src/communication/datapoint.cpp
  • src/communication/datapoint.h
  • src/communication/modbuspoll.cpp
  • src/communication/modbuspoll.h
  • src/communication/modbusregister.cpp
  • src/communication/modbusregister.h
  • src/datahandling/expressionparser.cpp
  • src/datahandling/expressionparser.h
  • src/datahandling/graphdatahandler.cpp
  • src/datahandling/graphdatahandler.h
  • src/dialogs/mainwindow.cpp
  • src/util/expressionchecker.cpp
  • tests/datahandling/tst_expressionparser.cpp
  • tests/datahandling/tst_expressionparser.h
  • tests/datahandling/tst_graphdatahandler.cpp
  • tests/util/tst_expressionchecker.cpp
💤 Files with no reviewable changes (2)
  • src/communication/modbusregister.cpp
  • src/communication/modbusregister.h

@jgeudens jgeudens merged commit 5265f61 into master Apr 2, 2026
10 checks passed
@jgeudens jgeudens deleted the dev/modbus_register branch April 2, 2026 18:19
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