New function modbus_reply_callback()
The modbus_reply_callback() function is modelled closely on modbus_reply(), but should be used when more complex actions are required for handling Modbus functions that what is possible with the current mapping scheme.
Thank you for your patch and the very good documentation. The patch duplicates too many lines of code.
I think we can achieve the same behaviour with https://github.com/stephane/libmodbus/pull/323.
It would be nice if you could participate to this new feature (tests, docs, whatever), I'm intend to talk about that on the mailing list... stay tuned.
It has been a while since I coded this together for a project and only recently managed to push it. I agree that there are some duplication in the code. However, when I started to make this I did try to look at some way to reduce the duplication. There were a few reasons why I ended up with what I did:
- I didn't want to break existing code base. Not a real reason - unless you'r on a deadline. :)
- I didn't want to pollute the code with additional branches which could adversely affect the branch predictor (i.e. less code, but worse performance).
- My initial attempts produced code which was much worse from a maintenance perspective.
- All in all, the total number of identical code lines between the two functions are relatively low - there are probably more duplications internally in each functions, like the error handling.
I am no longer involved in the project which spawned this patch, but I will try to contribute in any way I can.
I tried pushing four changes to this fork to address your concern, but it looks like I ended up with a merge mess. Does the changes make sense or should I start from scratch?