API of modbus_mapping_offset_new

45 views
Skip to first unread message

Stéphane Raimbault

unread,
Sep 21, 2015, 3:27:19 PM9/21/15
to libm...@googlegroups.com, Michael Heimpold
Hi,

Michael wrote yet another very good patch for libmodbus!

I merged it and I was going to write a unit test for modbus_mapping_offset_new but I had to read the documentation (and the source code) to have a good comprehension so we could certainly improve it. Naming things is most difficult problem in the world so I need help ;)

Currently (in master only):

modbus_mapping_t* modbus_mapping_offset_new(int 'nb_bits', int 'offset_bits',
                                      int 'nb_input_bits', int 'offset_input_bits',
                                      int 'nb_registers', int 'offset_registers',
                                      int 'nb_input_registers', int 'offset_input_registers');

If I use nb_bits of 10 and offset_bits of 2, does it mean bit addresses from 2 to 12 or 2 to 10 [1]?

and the provided example, doesn't help me either

/* The first value of each array is accessible at address 4. */
mb_mapping = modbus_mapping_offset_new(BITS_ADDRESS + BITS_NB, 4, ...)

so I propose the following changes:

- modbus_mapping_offset_new(int bit_addr_start, int bit_addr_stop, ...)
  => (2, 12) allocates 10 bits

  with better names for the variables if you have...

- another name for the function: modbus_mapping_with_limited_ranges_new? modbus_advanced_mapping_new?
modbus_complex_mapping_new?

- add information in the documentation to explain the range of available addresses and the memory allocated by the lib.

- adjust the documentation with modbus_mapping_offset_new(BIT_ADDRESS, BIT_ADDRESS + NB_BITS, ...)

What do you think?

Bye,
Stéphane

[1] the answer is 2 to 12.
Reply all
Reply to author
Forward
0 new messages