Skip to content

feat: Add support for reading Group 50 Var 1 (absolute time) in master#397

Merged
jadamcrain merged 3 commits intomainfrom
feature/issue-373
Aug 8, 2025
Merged

feat: Add support for reading Group 50 Var 1 (absolute time) in master#397
jadamcrain merged 3 commits intomainfrom
feature/issue-373

Conversation

@jadamcrain
Copy link
Member

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

  • Added handle_abs_time method to the ReadHandler trait that receives a single Timestamp value
  • Updated extraction logic in extract.rs to handle g50v1 responses:
    • Supports both one-byte and two-byte count qualifiers
    • Only processes headers with count == 1 (semantically correct for absolute time)
    • Logs warnings and ignores headers with count != 1
  • Added comprehensive test coverage for g50v1 handling
  • Updated FFI bindings for C, .NET, and Java

Breaking Changes

⚠️ C# Users: This is a breaking change. The IReadHandler interface now requires implementing the HandleAbsTime method. This is because .NET Standard 2.0 (which we target) does not support default interface methods.

C# implementations of IReadHandler must add:

public void HandleAbsTime(HeaderInfo info, Timestamp time)
{
    // Handle absolute time value
}

Testing

  • Added unit tests for all g50v1 scenarios (count=0, count=1, count>1)
  • All existing tests pass
  • FFI bindings compile and test successfully

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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_time method to the ReadHandler trait. 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_time functionality. 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 IReadHandler interface will now be required to explicitly add the HandleAbsTime method.
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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +43 to +51
if let Some(item) = seq.single() {
handler.handle_abs_time(
HeaderInfo::new(header.variation, header.details.qualifier(), false, false),
item.time,
);
true
} else {
false
}

Choose a reason for hiding this comment

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

medium

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()

Comment on lines +74 to +79
HeaderDetails::OneByteCount(1, CountVariation::Group50Var1(seq)) => {
extract_g50v1(seq, &header, handler)
}
HeaderDetails::TwoByteCount(1, CountVariation::Group50Var1(seq)) => {
extract_g50v1(seq, &header, handler)
}

Choose a reason for hiding this comment

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

medium

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)
            }

@jadamcrain jadamcrain merged commit 933d25c into main Aug 8, 2025
31 checks passed
@jadamcrain jadamcrain deleted the feature/issue-373 branch August 8, 2025 23:54
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.

Allow master to read Group 50 Var 1

1 participant

Comments