Commit 692f6b76f7675f40a5d86a1d9e019175544decf0
1 parent
e6e3c8e4
Rename modbus_set_float_swapped to modbus_set_float_dcba
Showing
10 changed files
with
38 additions
and
38 deletions
doc/Makefile.am
| ... | ... | @@ -9,7 +9,7 @@ MAN3 = \ |
| 9 | 9 | modbus_get_byte_from_bits.3 \ |
| 10 | 10 | modbus_get_byte_timeout.3 \ |
| 11 | 11 | modbus_get_float.3 \ |
| 12 | - modbus_get_float_swapped.3 \ | |
| 12 | + modbus_get_float_dcba.3 \ | |
| 13 | 13 | modbus_get_header_length.3 \ |
| 14 | 14 | modbus_get_response_timeout.3 \ |
| 15 | 15 | modbus_get_socket.3 \ |
| ... | ... | @@ -40,7 +40,7 @@ MAN3 = \ |
| 40 | 40 | modbus_set_debug.3 \ |
| 41 | 41 | modbus_set_error_recovery.3 \ |
| 42 | 42 | modbus_set_float.3 \ |
| 43 | - modbus_set_float_swapped.3 \ | |
| 43 | + modbus_set_float_dcba.3 \ | |
| 44 | 44 | modbus_set_response_timeout.3 \ |
| 45 | 45 | modbus_set_slave.3 \ |
| 46 | 46 | modbus_set_socket.3 \ | ... | ... |
doc/libmodbus.txt
| ... | ... | @@ -152,8 +152,8 @@ Handling of bits and bytes:: |
| 152 | 152 | Set or get float numbers:: |
| 153 | 153 | linkmb:modbus_get_float[3] |
| 154 | 154 | linkmb:modbus_set_float[3] |
| 155 | - linkmb:modbus_get_float_swapped[3] | |
| 156 | - linkmb:modbus_set_float_swapped[3] | |
| 155 | + linkmb:modbus_get_float_dcba[3] | |
| 156 | + linkmb:modbus_set_float_dcba[3] | |
| 157 | 157 | |
| 158 | 158 | |
| 159 | 159 | Connection | ... | ... |
doc/modbus_get_float.txt
| ... | ... | @@ -28,8 +28,8 @@ The _modbus_get_float()_ function shall return a float. |
| 28 | 28 | SEE ALSO |
| 29 | 29 | -------- |
| 30 | 30 | linkmb:modbus_set_float[3] |
| 31 | -linkmb:modbus_set_float_swapped[3] | |
| 32 | -linkmb:modbus_get_float_swapped[3] | |
| 31 | +linkmb:modbus_set_float_dcba[3] | |
| 32 | +linkmb:modbus_get_float_dcba[3] | |
| 33 | 33 | |
| 34 | 34 | AUTHORS |
| 35 | 35 | ------- | ... | ... |
doc/modbus_get_float_swapped.txt renamed to doc/modbus_get_float_dcba.txt
| 1 | -modbus_get_float_swapped(3) | |
| 2 | -=========================== | |
| 1 | +modbus_get_float_dcba(3) | |
| 2 | +======================== | |
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | NAME |
| 6 | 6 | ---- |
| 7 | -modbus_get_float_swapped - get a float value from 2 byte swapped registers | |
| 7 | +modbus_get_float_dcba - get a float value from 2 registers in DCBA byte order | |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | SYNOPSIS |
| 11 | 11 | -------- |
| 12 | -*float modbus_get_float_swapped(const uint16_t *'src');* | |
| 12 | +*float modbus_get_float_dcba(const uint16_t *'src');* | |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | DESCRIPTION |
| 16 | 16 | ----------- |
| 17 | -The _modbus_get_float_swapped()_ function shall get a float from 4 bytes in | |
| 18 | -swapped Modbus format (DCBA order). The 'src' array must be pointer on two 16 | |
| 17 | +The _modbus_get_float_dcba()_ function shall get a float from 4 bytes in | |
| 18 | +inversed Modbus format (DCBA order). The 'src' array must be pointer on two 16 | |
| 19 | 19 | bits values, for example, if the first word is set to 0x9a22 and the second to |
| 20 | 20 | 0x6544, the float value read will be 916.540649. |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | RETURN VALUE |
| 24 | 24 | ------------ |
| 25 | -The _modbus_get_float_swapped()_ function shall return a float. | |
| 25 | +The _modbus_get_float_dcba()_ function shall return a float. | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | SEE ALSO |
| 29 | 29 | -------- |
| 30 | -linkmb:modbus_set_float_swapped[3] | |
| 30 | +linkmb:modbus_set_float_dcba[3] | |
| 31 | 31 | linkmb:modbus_set_float[3] |
| 32 | 32 | linkmb:modbus_get_float[3] |
| 33 | 33 | ... | ... |
doc/modbus_set_float.txt
| ... | ... | @@ -27,8 +27,8 @@ The is no return values. |
| 27 | 27 | SEE ALSO |
| 28 | 28 | -------- |
| 29 | 29 | linkmb:modbus_set_float[3] |
| 30 | -linkmb:modbus_set_float_swapped[3] | |
| 31 | -linkmb:modbus_get_float_swapped[3] | |
| 30 | +linkmb:modbus_set_float_dcba[3] | |
| 31 | +linkmb:modbus_get_float_dcba[3] | |
| 32 | 32 | |
| 33 | 33 | AUTHORS |
| 34 | 34 | ------- | ... | ... |
doc/modbus_set_float_swapped.txt renamed to doc/modbus_set_float_dcba.txt
| 1 | -modbus_set_float_swapped(3) | |
| 2 | -=========================== | |
| 1 | +modbus_set_float_dcba(3) | |
| 2 | +======================== | |
| 3 | 3 | |
| 4 | 4 | |
| 5 | 5 | NAME |
| 6 | 6 | ---- |
| 7 | -modbus_set_float_swapped - set a float value in 2 registers using a byte order swapped integer | |
| 7 | +modbus_set_float_dcba - set a float value in 2 registers using DCBA byte order | |
| 8 | 8 | |
| 9 | 9 | |
| 10 | 10 | SYNOPSIS |
| 11 | 11 | -------- |
| 12 | -*void modbus_set_float_swapped(float 'f', uint16_t *'dest');* | |
| 12 | +*void modbus_set_float_dcba(float 'f', uint16_t *'dest');* | |
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | DESCRIPTION |
| 16 | 16 | ----------- |
| 17 | -The _modbus_set_float_swapped()_ function shall set a float to 4 bytes in | |
| 18 | -swapped Modbus format (DCBA order). The 'dest' array must be pointer on two 16 | |
| 19 | -bits values to be able to store the full result of the conversion. | |
| 17 | +The _modbus_set_float_dcba()_ function shall set a float to 4 bytes in inversed | |
| 18 | +Modbus format (DCBA order). The 'dest' array must be pointer on two 16 bits | |
| 19 | +values to be able to store the full result of the conversion. | |
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | RETURN VALUE |
| ... | ... | @@ -26,7 +26,7 @@ The is no return values. |
| 26 | 26 | |
| 27 | 27 | SEE ALSO |
| 28 | 28 | -------- |
| 29 | -linkmb:modbus_get_float_swapped[3] | |
| 29 | +linkmb:modbus_get_float_dcba[3] | |
| 30 | 30 | linkmb:modbus_set_float[3] |
| 31 | 31 | linkmb:modbus_get_float[3] |
| 32 | 32 | ... | ... |
src/modbus-data.c
| ... | ... | @@ -88,8 +88,8 @@ float modbus_get_float(const uint16_t *src) |
| 88 | 88 | return f; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | -/* Get a float from 4 bytes in swapped Modbus format (DCBA) */ | |
| 92 | -float modbus_get_float_swapped(const uint16_t *src) | |
| 91 | +/* Get a float from 4 bytes in inversed Modbus format (DCBA) */ | |
| 92 | +float modbus_get_float_dcba(const uint16_t *src) | |
| 93 | 93 | { |
| 94 | 94 | float f; |
| 95 | 95 | uint32_t i; |
| ... | ... | @@ -110,8 +110,8 @@ void modbus_set_float(float f, uint16_t *dest) |
| 110 | 110 | dest[1] = (uint16_t)(i >> 16); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | -/* Set a float to 4 bytes in swapped Modbus format (DCBA) */ | |
| 114 | -void modbus_set_float_swapped(float f, uint16_t *dest) | |
| 113 | +/* Set a float to 4 bytes in inversed Modbus format (DCBA) */ | |
| 114 | +void modbus_set_float_dcba(float f, uint16_t *dest) | |
| 115 | 115 | { |
| 116 | 116 | uint32_t i; |
| 117 | 117 | ... | ... |
src/modbus.h
| ... | ... | @@ -226,9 +226,9 @@ EXPORT void modbus_set_bits_from_bytes(uint8_t *dest, int index, unsigned int nb |
| 226 | 226 | const uint8_t *tab_byte); |
| 227 | 227 | EXPORT uint8_t modbus_get_byte_from_bits(const uint8_t *src, int index, unsigned int nb_bits); |
| 228 | 228 | EXPORT float modbus_get_float(const uint16_t *src); |
| 229 | -EXPORT float modbus_get_float_swapped(const uint16_t *src); | |
| 229 | +EXPORT float modbus_get_float_dcba(const uint16_t *src); | |
| 230 | 230 | EXPORT void modbus_set_float(float f, uint16_t *dest); |
| 231 | -EXPORT void modbus_set_float_swapped(float f, uint16_t *dest); | |
| 231 | +EXPORT void modbus_set_float_dcba(float f, uint16_t *dest); | |
| 232 | 232 | |
| 233 | 233 | #include "modbus-tcp.h" |
| 234 | 234 | #include "modbus-rtu.h" | ... | ... |
tests/unit-test-client.c
| ... | ... | @@ -342,20 +342,20 @@ int main(int argc, char *argv[]) |
| 342 | 342 | goto close; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - printf("3/4 Set float swapped: "); | |
| 346 | - modbus_set_float_swapped(UT_REAL, tab_rp_registers); | |
| 347 | - if (tab_rp_registers[1] == (UT_IREAL_SWAPPED >> 16) && | |
| 348 | - tab_rp_registers[0] == (UT_IREAL_SWAPPED & 0xFFFF)) { | |
| 345 | + printf("3/4 Set float in DBCA order: "); | |
| 346 | + modbus_set_float_dcba(UT_REAL, tab_rp_registers); | |
| 347 | + if (tab_rp_registers[1] == (UT_IREAL_DCBA >> 16) && | |
| 348 | + tab_rp_registers[0] == (UT_IREAL_DCBA & 0xFFFF)) { | |
| 349 | 349 | printf("OK\n"); |
| 350 | 350 | } else { |
| 351 | 351 | ireal = (uint32_t) tab_rp_registers[0] & 0xFFFF; |
| 352 | 352 | ireal |= (uint32_t) tab_rp_registers[1] << 16; |
| 353 | - printf("FAILED (%x != %x)\n", ireal, UT_IREAL_SWAPPED); | |
| 353 | + printf("FAILED (%x != %x)\n", ireal, UT_IREAL_DCBA); | |
| 354 | 354 | goto close; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - printf("4/4 Get float swapped: "); | |
| 358 | - real = modbus_get_float_swapped(tab_rp_registers); | |
| 357 | + printf("4/4 Get float in DCBA order: "); | |
| 358 | + real = modbus_get_float_dcba(tab_rp_registers); | |
| 359 | 359 | if (real == UT_REAL) { |
| 360 | 360 | printf("OK\n"); |
| 361 | 361 | } else { | ... | ... |
tests/unit-test.h.in
| ... | ... | @@ -63,6 +63,6 @@ const uint16_t UT_INPUT_REGISTERS_TAB[] = { 0x000A }; |
| 63 | 63 | |
| 64 | 64 | const float UT_REAL = 916.540649; |
| 65 | 65 | const uint32_t UT_IREAL = 0x4465229a; |
| 66 | -const uint32_t UT_IREAL_SWAPPED = 0x9a226544; | |
| 66 | +const uint32_t UT_IREAL_DCBA = 0x9a226544; | |
| 67 | 67 | |
| 68 | 68 | #endif /* _UNIT_TEST_H_ */ | ... | ... |