Skip to content

Improve API of how client should use our library#5

Open
PolarGoose wants to merge 1 commit intomainfrom
improve_api
Open

Improve API of how client should use our library#5
PolarGoose wants to merge 1 commit intomainfrom
improve_api

Conversation

@PolarGoose
Copy link
Copy Markdown
Collaborator

It is an attempt to elegantly solve #4.
I propose having a single callback that returns the entire AxdrCapture object, 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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 via DlmsParser/AxdrParser constructors; simplify parse() to only take the buffer.
  • Introduce AxdrCapture helper methods (obis_as_string, value_as_string, value_as_float_with_scaler_applied, etc.) and remove older utility conversion helpers from utils.
  • Refactor logging: move Logger/LogLevel from log.h into utils.h and 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.

Comment thread src/dlms_parser/utils.h
Comment thread src/dlms_parser/axdr_parser.cpp
Comment thread src/dlms_parser/axdr_parser.cpp
Comment thread src/dlms_parser/dlms_parser.h
Comment thread tests/test_util.h
Comment thread tests/test_util.h
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.

2 participants