Improve API of how client should use our library#5
Open
PolarGoose wants to merge 1 commit intomainfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the library’s public parsing API to use a single per-parser callback that receives the full AxdrCapture, enabling callers to choose how to interpret OBIS/value data (including preserving precision) and avoiding per-parse callback plumbing. It also consolidates logging into utils.h and updates tools/tests to the new API.
Changes:
- Replace the “cooked” callback signature with
DlmsDataCallback(std::function<void(const AxdrCapture&)>)and pass it viaDlmsParser/AxdrParserconstructors; simplifyparse()to only take the buffer. - Introduce
AxdrCapturehelper methods (obis_as_string,value_as_string,value_as_float_with_scaler_applied, etc.) and remove older utility conversion helpers fromutils. - Refactor logging: move
Logger/LogLevelfromlog.hintoutils.hand update call sites; add a shared test log fixture.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/decode_readout.cpp | Updated CLI tool to use constructor-injected AxdrCapture callback and parse(data) API. |
| tests/test_util.h | Adds shared log fixture for tests; used across multiple test files. |
| tests/test_utils.cpp | Updates to TEST_CASE_FIXTURE and removes tests tied to removed utils helpers. |
| tests/test_meter_dumps.cpp | Updates integration tests to new parser callback + parse() signature. |
| tests/test_mbus_decoder.cpp | Switches to fixture-based tests (logging setup). |
| tests/test_hdlc_decoder.cpp | Switches to fixture-based tests (logging setup). |
| tests/test_example.cpp | Updates example usage to new callback/constructor and parse() API. |
| tests/test_axdr_registry.cpp | Updates AxdrParser construction to require callback. |
| src/dlms_parser/utils.h / utils.cpp | Moves logger into utils.h; removes old float/string/OBIS/hex formatting helpers. |
| src/dlms_parser/axdr_parser.h / axdr_parser.cpp | Renames capture type to AxdrCapture, adds helper methods, stores callback as member, and emits via member callback. |
| src/dlms_parser/dlms_parser.h / dlms_parser.cpp | Requires callback in constructor; parse() no longer accepts callback argument. |
| src/dlms_parser/log.h | Deleted (logging moved into utils.h). |
| src/dlms_parser/{hdlc_decoder,mbus_decoder,apdu_handler}.cpp | Update includes from log.h to utils.h. |
| src/dlms_parser/decryption/* | Drops log.h include (now provided via utils.h). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b90d8d7 to
15a9660
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It is an attempt to elegantly solve #4.
I propose having a single callback that returns the entire
AxdrCaptureobject, which includes methods to retrieve a string or float value if needed.Also, I pass this callback into a constructor. It is better. It reduces potential dynamic memory allocations and aligns with how we use our library in EspHome.