Skip to content

Conversation

@tcdrop
Copy link
Contributor

@tcdrop tcdrop commented Dec 16, 2025

This change fixes an issue with the internal OpenEMS Edge-2-Edge communication. It has been discussed in this forum post.

Short Summary: when an OpenEMS edge has an undefined integer channel value, it sets the value to the max. int value (e.g. 65535 for 16bit unsigned integer) in the Modbus API. The master edge then reads this Modbus value, but doesn't recognize it as undefined. Instead, the value gets used just like any other value. This can lead to problems like SOC of 65535%.

This fix adds a converter for integer values to the AbstractEdge2Edge class, that sets channel values to null, if the Modbus value is undefined.

@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 67.44186% with 14 lines in your changes missing coverage. Please review.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #3479      +/-   ##
=============================================
+ Coverage      59.61%   59.62%   +0.01%     
  Complexity       105      105              
=============================================
  Files           3004     3004              
  Lines         130410   130427      +17     
  Branches        9637     9639       +2     
=============================================
+ Hits           77737    77754      +17     
+ Misses         49764    49762       -2     
- Partials        2909     2911       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@tsicking tsicking left a comment

Choose a reason for hiding this comment

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

Thanks for the helpful PR. I have some comments, mostly of code style nature.

*/
private ElementToChannelConverter getConverterForType(ModbusType type) {
return switch (type) {
case UINT16 -> ElementToChannelConverter.SET_NULL_FOR_DEFAULT(0xFFFF); // 65535
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there is any way to use ModbusRecordUint16.UNDEFINED_VALUE instead of 0xFFFF as I suggested in the forum, but it's not too important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for your feedback! I tried to do that but I couldn't find a nice way of getting the byte array ModbusRecordUint16.UNDEFINED_VALUE to work with this code.
Also I ran into problems with casting between unsigned types Uint16-64 and signed Java types Short, Int, Long. Having it as 0xFFFF worked.

@tcdrop tcdrop requested a review from tsicking December 17, 2025 09:36
@parapluplu
Copy link
Contributor

Is it feasible to add some kind of unit test for this?

- Add UNDEFINED_VALUE and UNDEFINED_BYTE_ARRAY
- Add JUnit tests
@sfeilmeier
Copy link
Contributor

I used a different approach, reusing the existing UNDEFINED_VALUEs in 41db621.

I added JUnit tests, but did not test it in production yet.

Could anybody test it?

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.

4 participants