feat: Add support for reading Group 50 Var 1 (absolute time) in master#397
feat: Add support for reading Group 50 Var 1 (absolute time) in master#397jadamcrain merged 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @jadamcrain, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've implemented support for DNP3 masters to correctly process Group 50 Variation 1 (absolute time) responses from outstations. Previously, while masters could initiate requests for this data, there was no dedicated callback mechanism to handle the incoming responses. This enhancement allows the master to properly receive and interpret the outstation's absolute time, which is crucial for maintaining accurate time synchronization within the DNP3 system.
Highlights
- New ReadHandler Method: I've introduced a new
handle_abs_timemethod to theReadHandlertrait. This method is specifically designed to process Group 50 Variation 1 (absolute time) responses, allowing masters to now correctly receive and act upon the outstation's current time. - Robust G50V1 Extraction: I've updated the measurement extraction logic to robustly handle Group 50 Variation 1 data. This includes supporting both one-byte and two-byte count qualifiers, and crucially, only processing responses where the count is exactly 1, as this is the semantically correct interpretation for a single absolute time value. Responses with other counts will be logged as warnings and ignored.
- Comprehensive Testing: I've added comprehensive unit tests covering various Group 50 Variation 1 scenarios. This includes tests for valid counts (count=1), as well as cases where the count is 0 or greater than 1, ensuring the new logic behaves as expected and correctly ignores invalid multi-time responses.
- FFI Binding Updates: I've updated the FFI bindings for C, .NET, and Java to expose the new
handle_abs_timefunctionality. This ensures that applications written in these languages can leverage the master's enhanced ability to process absolute time responses. - Breaking Change for C# Users: Please note for C# users: This PR introduces a breaking change. Due to limitations in .NET Standard 2.0 regarding default interface methods, implementations of the
IReadHandlerinterface will now be required to explicitly add theHandleAbsTimemethod.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request adds support for reading Group 50 Variation 1 (absolute time) in the master, which is a great feature addition. The changes are well-structured, including updates to the core logic, FFI bindings, and comprehensive test cases. The breaking change for C# users is also clearly documented. I have a couple of suggestions to make the Rust code more idiomatic and concise.
| if let Some(item) = seq.single() { | ||
| handler.handle_abs_time( | ||
| HeaderInfo::new(header.variation, header.details.qualifier(), false, false), | ||
| item.time, | ||
| ); | ||
| true | ||
| } else { | ||
| false | ||
| } |
There was a problem hiding this comment.
This function can be written more idiomatically using Option::map and Option::is_some. This would make the code more concise and align with common Rust patterns.
seq.single()
.map(|item| {
handler.handle_abs_time(
HeaderInfo::new(header.variation, header.details.qualifier(), false, false),
item.time,
);
})
.is_some()| HeaderDetails::OneByteCount(1, CountVariation::Group50Var1(seq)) => { | ||
| extract_g50v1(seq, &header, handler) | ||
| } | ||
| HeaderDetails::TwoByteCount(1, CountVariation::Group50Var1(seq)) => { | ||
| extract_g50v1(seq, &header, handler) | ||
| } |
There was a problem hiding this comment.
These two match arms have identical bodies. They can be combined using the | (or) operator to reduce code duplication and improve readability.
HeaderDetails::OneByteCount(1, CountVariation::Group50Var1(seq))
| HeaderDetails::TwoByteCount(1, CountVariation::Group50Var1(seq)) => {
extract_g50v1(seq, &header, handler)
}
Summary
Closes #373
This PR adds support for masters to read Group 50 Variation 1 (absolute time) responses from outstations. Previously, while masters could construct requests for g50v1, there was no callback in the ReadHandler to process the response.
Changes
handle_abs_timemethod to theReadHandlertrait that receives a singleTimestampvalueextract.rsto handle g50v1 responses:Breaking Changes
IReadHandlerinterface now requires implementing theHandleAbsTimemethod. This is because .NET Standard 2.0 (which we target) does not support default interface methods.C# implementations of
IReadHandlermust add:Testing