stephane/libmodbus — pull request #148 by forslund (2013-10-15 09:07:12+00:00)
Title: Custom table handlers

After a couple of iterations I've at something that might work regarding the callback functions discussed in the libmodbus google group.

The purpose of this pull request is to have something to discuss and continue to work on, I don't think this is in a mergable state just yet.

Purpose
======
To allow the user to have custom handlers for registers and coils. This allows them to make libmodbus read/write into existing settings-structures.

I have designed this to make the user defined handler do as little as possible, basically just fetch a register/bit value. It should be very backwards compatible, if no handlers are specified the library uses default handlers that will work just as previous versions.

The error checks are moved to the handlers allowing user to use structures with gaps in the addressing space for example holding register 1-100 are defined and 982 - 999 are also defined. the default (and previous) implementation does not allow for this but nothing hinders the user to define an handler that verifies the address against a list of valid addresses.

TODO
====
- modbus_reply() contains a lot of duplicated code and needs cleaning
- comments
- example of custom handler

Question
========
Currently holding registers and input registers uses the same get/set-function, should these be separated into different functions? (The same goes for get/set coil)

Any comments, insights and/or corrections are welcome =)