Add extended response filter support to ModbusBridge - #438
Conversation
Introduced `addresponseExFilter` and `removeresponseExFilter` methods to enable adding and removing extended response filters (`MBSExResponseWorker`) for specific `aliasID`s. Added a new type alias `MBSExResponseWorker` in `ModbusServer.h` to support more complex filtering based on read start address and count. Updated the `ServerData` structure to include a `responseExFilter` member and initialized it in constructors. Modified the `bridgeWorker` method to invoke `responseExFilter` if set, falling back to `responseFilter` otherwise. Added logging for better debugging and updated comments to reflect the new functionality. These changes enhance the `ModbusBridge` class, enabling more advanced and flexible filtering mechanisms for Modbus messages.
|
I am afraid I have some objections against your PR. Primarily it does not add real benefit as compared to the existing filter hooks, since the extraction of both address and length can easily be done within a regular filter callback. Second, and even more relevant, the proposed change will try to extract these values even from Modbus messages that may have a completely different structure and hence will result in invalid data. |
Simplified the extended response filter hook logic in `ModbusBridgeTemp.h` by passing the entire request message to `responseExFilter`, removing the individual parameters. Updated the `MBSExResponseWorker` function signature in `ModbusServer.h` to accept two `ModbusMessage` parameters (`responseMsg` and `requestMsg`)
|
Changed to include the full request message reference along the response. |
|
How is this now supposed to work? Where do you get the matching request and response messages when calling the filter? |
|
These are populated in src/ModbusBridgeTemp.h, bridgeWorker, line 314-319 |
|
Can you give me an example on how to make a use from the extended callback? |
|
I have implemented it like the following snipit. It allows to change the response parsing to be depended upon the request: |
|
I see, thank you. So basically who would need the plain response filter any more? How about replacing it with yours? I actually did not see the availability of the causing request for a response when writing the filter hooks 😆 |
You still need the original one in case you want to modify the request. And also to ensure this is not breaking existing implementations, I would advice to keep both. |
|
@roelandkluit Thank you very much for your contribution. |
Introduced
addresponseExFilterandremoveresponseExFiltermethods to enable adding and removing extended response filters (MBSExResponseWorker) for specificaliasIDs.Added a new type alias
MBSExResponseWorkerinModbusServer.hto support more complex filtering based on read start address and count. Updated theServerDatastructure to include aresponseExFiltermember and initialized it in constructors.Modified the
bridgeWorkermethod to invokeresponseExFilterif set, falling back toresponseFilterotherwise if set. Added logging and updated comments to reflect the new functionality.These changes enhance the
ModbusBridgeclass, enabling more advanced and flexible filtering mechanisms for Modbus messages after receiving the request, allowing to handle the response with the original request address and count in mind.