Conversation
yahyayozo
commented
May 18, 2025
- Add ModbusLayer first implementation with header parsing only (no test included)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1823 +/- ##
==========================================
- Coverage 83.47% 83.47% -0.01%
==========================================
Files 298 304 +6
Lines 53945 54152 +207
Branches 11705 12013 +308
==========================================
+ Hits 45029 45201 +172
- Misses 7709 7735 +26
- Partials 1207 1216 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@seladb I've prepared only 1 constructor which initiates the layer with default fields values |
|
@yahyayozo we usually have at least 2 c'tors, sometimes more:
|
…sPlus into feature/modbus
|
Hi @seladb can you please guide me briefly on how to add tests for my ModbusLayer for parsing/crafting headers? As I want to pass to function types request/response after testing the header part. |
|
@yahyayozo sure! You can learn about tests here: https://pcapplusplus.github.io/docs/tests At a high level:
Please look at similar tests that were written for other layers and follow the same patterns. Please let me know if you have any questions. |
|
@seladb I'll add tests for the headers crafting/parsing implementation and then you can a review before we move to adding the different PDU types |
… instead of raw data
|
@yahyayozo the tests fail in CI... |
|
@seladb should be fixed now |
Packet++/src/ModbusLayer.cpp
Outdated
| { | ||
| ModbusLayer::ModbusLayer(uint16_t transactionId, uint8_t unitId, ModbusLayer::ModbusFunctionCode functionCode) | ||
| { | ||
| const int16_t pduSize = getFunctionDataSize(functionCode); |
There was a problem hiding this comment.
I can see that getFunctionDataSize() currently supports only one function code, which is ModbusFunctionCode::READ_INPUT_REGISTERS. In that case, maybe we can remove the functionCode parameter, remove the getFunctionDataSize() method, and set the function code in this constructor to be ModbusFunctionCode::READ_INPUT_REGISTERS
| /// @struct ModbusReadInputRegisters | ||
| /// Represents a Modbus request to read input registers. | ||
| struct ModbusReadInputRegisters | ||
| { | ||
| uint16_t startingAddress; ///< Starting address of the input registers to read | ||
| uint16_t quantity; ///< Number of input registers to read | ||
| }; |
There was a problem hiding this comment.
This struct is only used in getFunctionDataSize(). If we remove it we can remove this struct as well
Packet++/src/ModbusLayer.cpp
Outdated
| { | ||
| ModbusLayer::ModbusLayer(uint16_t transactionId, uint8_t unitId, ModbusLayer::ModbusFunctionCode functionCode) | ||
| { | ||
| const int16_t pduSize = getFunctionDataSize(functionCode); |
|
@yahyayozo I think the only comments left are: Once you address those I think we can merge this PR |
|
@seladb all the comments shall be addressed now |
|
@seladb can you please check why it shows forbid submodules in the failed pre-commit? |
|
@yahyayozo thank you so much for working on this and contributing to PcapPlusPlus, it is much appreciated! 🙏 |
|
@seladb so, the other PDUs types will added in another PR? |
|
Yes, it's easier to review that way as it results in smaller differential changes in PRs. |
Yes I agree. Smaller PRs are always better and easier to review |
