Skip to content

Bugfix/values spikes#408

Merged
kellerza merged 12 commits intokellerza:mainfrom
maslyankov:bugfix/values-spikes
Jan 22, 2025
Merged

Bugfix/values spikes#408
kellerza merged 12 commits intokellerza:mainfrom
maslyankov:bugfix/values-spikes

Conversation

@maslyankov
Copy link
Copy Markdown
Contributor

@maslyankov maslyankov commented Jan 22, 2025

Add sequence number management for packet validation in SolarmanSunsynk
Add Modbus packet validation methods in SolarmanSunsynk
Enhance Modbus frame handling in SolarmanSunsynk

  • Introduced current_sequence_number attribute to track the sequence number.
  • Added advance_sequence_number method to generate and increment the sequence number.
  • Updated write_register and read_holding_registers methods to utilize the new sequence number for packet validation.
  • Introduced validate_modbus_crc method to check the integrity of Modbus frames.
  • Added validate_packet method to ensure received packets conform to expected structure and CRC.
  • Updated read_holding_registers to validate response packets before returning registers.
  • Defined a constant POLY for Modbus CRC polynomial.
  • Updated the extraction of the Modbus frame to include the CRC byte for improved validation.
  • Added detailed logging for extracted Modbus frames and calculated CRC values to aid in debugging.
  • Introduced a new calculate_modbus_crc function in tests to ensure accurate CRC calculations for Modbus frames.
  • Enhanced unit tests to validate the reading and writing of registers, ensuring proper interaction with the Modbus client.

Related PR & issues:

github-actions bot and others added 5 commits January 22, 2025 11:48
- Introduced `current_sequence_number` attribute to track the sequence number.
- Added `advance_sequence_number` method to generate and increment the sequence number.
- Updated `write_register` and `read_holding_registers` methods to utilize the new sequence number for packet validation.
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.

Project coverage is 72.73%. Comparing base (a664930) to head (bd46569).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/sunsynk/solarmansunsynk.py 97.95% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #408      +/-   ##
==========================================
+ Coverage   71.00%   72.73%   +1.72%     
==========================================
  Files          26       26              
  Lines        1914     1962      +48     
==========================================
+ Hits         1359     1427      +68     
+ Misses        555      535      -20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- Introduced `validate_modbus_crc` method to check the integrity of Modbus frames.
- Added `validate_packet` method to ensure received packets conform to expected structure and CRC.
- Updated `read_holding_registers` to validate response packets before returning registers.
- Defined a constant `POLY` for Modbus CRC polynomial.

These enhancements improve the reliability of communication with Modbus devices.
- Updated the extraction of the Modbus frame to include the CRC byte for improved validation.
- Added detailed logging for extracted Modbus frames and calculated CRC values to aid in debugging.
- Introduced a new `calculate_modbus_crc` function in tests to ensure accurate CRC calculations for Modbus frames.
- Enhanced unit tests to validate the reading and writing of registers, ensuring proper interaction with the Modbus client.

These changes improve the reliability and traceability of Modbus communication in the SolarmanSunsynk implementation.
- Introduced multiple test cases for validating Modbus packets, including checks for invalid start/stop bytes, sequence numbers, CRC, and length.
- Enhanced error handling in connection and disconnection scenarios.
- Improved write_register method to handle timeout and general exceptions effectively.

These additions strengthen the reliability and robustness of the SolarmanSunsynk's Modbus communication and error management.
@kellerza
Copy link
Copy Markdown
Owner

Thanks!

(You should install pre-commit - helps with formatting)

@kellerza kellerza merged commit e37dd6d into kellerza:main Jan 22, 2025
kellerza added a commit that referenced this pull request Jan 23, 2025
kellerza added a commit that referenced this pull request Jan 23, 2025
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