Commit 17994074d2ac22957750b89b1a907bc0714dab7d
1 parent
6e6e2602
modbus_mapping_new returns 0 on success
- adjusts various comments on return values - updated tests - added entry to MIGRATION
Showing
7 changed files
with
17 additions
and
15 deletions
MIGRATION
| @@ -34,6 +34,8 @@ int modbus_slave_receive(modbus_param_t *mb_param, int sockfd, | @@ -34,6 +34,8 @@ int modbus_slave_receive(modbus_param_t *mb_param, int sockfd, | ||
| 34 | - HEADER_LENGTH_RTU 0 -> 1 | 34 | - HEADER_LENGTH_RTU 0 -> 1 |
| 35 | - HEADER_LENGTH_TCP 6 -> 7 | 35 | - HEADER_LENGTH_TCP 6 -> 7 |
| 36 | 36 | ||
| 37 | +6 - modbus_mapping_new returns 0 on success and -1 on failure. | ||
| 38 | + | ||
| 37 | 39 | ||
| 38 | ============================================= | 40 | ============================================= |
| 39 | Migration notes from the 1.2 series (for 2.0) | 41 | Migration notes from the 1.2 series (for 2.0) |
src/modbus.c
| @@ -651,7 +651,7 @@ static int receive_msg(modbus_param_t *mb_param, | @@ -651,7 +651,7 @@ static int receive_msg(modbus_param_t *mb_param, | ||
| 651 | internal one of modbus_param_t. | 651 | internal one of modbus_param_t. |
| 652 | 652 | ||
| 653 | Returns: | 653 | Returns: |
| 654 | - - 0 if OK, or a negative error number if the request fails | 654 | + - 0 on success, or a negative error number if the request fails |
| 655 | - query, message received | 655 | - query, message received |
| 656 | - query_length, length in bytes of the message */ | 656 | - query_length, length in bytes of the message */ |
| 657 | int modbus_slave_receive(modbus_param_t *mb_param, int sockfd, | 657 | int modbus_slave_receive(modbus_param_t *mb_param, int sockfd, |
| @@ -1740,7 +1740,7 @@ static int modbus_connect_tcp(modbus_param_t *mb_param) | @@ -1740,7 +1740,7 @@ static int modbus_connect_tcp(modbus_param_t *mb_param) | ||
| 1740 | } | 1740 | } |
| 1741 | 1741 | ||
| 1742 | /* Establishes a modbus connexion. | 1742 | /* Establishes a modbus connexion. |
| 1743 | - Returns -1 if an error occured. */ | 1743 | + Returns 0 on success or -1 on failure. */ |
| 1744 | int modbus_connect(modbus_param_t *mb_param) | 1744 | int modbus_connect(modbus_param_t *mb_param) |
| 1745 | { | 1745 | { |
| 1746 | int ret; | 1746 | int ret; |
| @@ -1787,7 +1787,7 @@ void modbus_set_debug(modbus_param_t *mb_param, int boolean) | @@ -1787,7 +1787,7 @@ void modbus_set_debug(modbus_param_t *mb_param, int boolean) | ||
| 1787 | /* Allocates 4 arrays to store coils, input status, input registers and | 1787 | /* Allocates 4 arrays to store coils, input status, input registers and |
| 1788 | holding registers. The pointers are stored in modbus_mapping structure. | 1788 | holding registers. The pointers are stored in modbus_mapping structure. |
| 1789 | 1789 | ||
| 1790 | - Returns: TRUE if ok, FALSE on failure | 1790 | + Returns 0 on success and -1 on failure. |
| 1791 | */ | 1791 | */ |
| 1792 | int modbus_mapping_new(modbus_mapping_t *mb_mapping, | 1792 | int modbus_mapping_new(modbus_mapping_t *mb_mapping, |
| 1793 | int nb_coil_status, int nb_input_status, | 1793 | int nb_coil_status, int nb_input_status, |
| @@ -1800,7 +1800,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping, | @@ -1800,7 +1800,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping, | ||
| 1800 | memset(mb_mapping->tab_coil_status, 0, | 1800 | memset(mb_mapping->tab_coil_status, 0, |
| 1801 | nb_coil_status * sizeof(uint8_t)); | 1801 | nb_coil_status * sizeof(uint8_t)); |
| 1802 | if (mb_mapping->tab_coil_status == NULL) | 1802 | if (mb_mapping->tab_coil_status == NULL) |
| 1803 | - return FALSE; | 1803 | + return -1; |
| 1804 | 1804 | ||
| 1805 | /* 1X */ | 1805 | /* 1X */ |
| 1806 | mb_mapping->nb_input_status = nb_input_status; | 1806 | mb_mapping->nb_input_status = nb_input_status; |
| @@ -1810,7 +1810,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping, | @@ -1810,7 +1810,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping, | ||
| 1810 | nb_input_status * sizeof(uint8_t)); | 1810 | nb_input_status * sizeof(uint8_t)); |
| 1811 | if (mb_mapping->tab_input_status == NULL) { | 1811 | if (mb_mapping->tab_input_status == NULL) { |
| 1812 | free(mb_mapping->tab_coil_status); | 1812 | free(mb_mapping->tab_coil_status); |
| 1813 | - return FALSE; | 1813 | + return -1; |
| 1814 | } | 1814 | } |
| 1815 | 1815 | ||
| 1816 | /* 4X */ | 1816 | /* 4X */ |
| @@ -1822,7 +1822,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping, | @@ -1822,7 +1822,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping, | ||
| 1822 | if (mb_mapping->tab_holding_registers == NULL) { | 1822 | if (mb_mapping->tab_holding_registers == NULL) { |
| 1823 | free(mb_mapping->tab_coil_status); | 1823 | free(mb_mapping->tab_coil_status); |
| 1824 | free(mb_mapping->tab_input_status); | 1824 | free(mb_mapping->tab_input_status); |
| 1825 | - return FALSE; | 1825 | + return -1; |
| 1826 | } | 1826 | } |
| 1827 | 1827 | ||
| 1828 | /* 3X */ | 1828 | /* 3X */ |
| @@ -1835,10 +1835,10 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping, | @@ -1835,10 +1835,10 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping, | ||
| 1835 | free(mb_mapping->tab_coil_status); | 1835 | free(mb_mapping->tab_coil_status); |
| 1836 | free(mb_mapping->tab_input_status); | 1836 | free(mb_mapping->tab_input_status); |
| 1837 | free(mb_mapping->tab_holding_registers); | 1837 | free(mb_mapping->tab_holding_registers); |
| 1838 | - return FALSE; | 1838 | + return -1; |
| 1839 | } | 1839 | } |
| 1840 | 1840 | ||
| 1841 | - return TRUE; | 1841 | + return 0; |
| 1842 | } | 1842 | } |
| 1843 | 1843 | ||
| 1844 | /* Frees the 4 arrays */ | 1844 | /* Frees the 4 arrays */ |
src/modbus.h
| @@ -265,7 +265,7 @@ void modbus_init_tcp(modbus_param_t *mb_param, const char *ip_address, int port, | @@ -265,7 +265,7 @@ void modbus_init_tcp(modbus_param_t *mb_param, const char *ip_address, int port, | ||
| 265 | void modbus_set_error_handling(modbus_param_t *mb_param, error_handling_t error_handling); | 265 | void modbus_set_error_handling(modbus_param_t *mb_param, error_handling_t error_handling); |
| 266 | 266 | ||
| 267 | /* Establishes a modbus connexion. | 267 | /* Establishes a modbus connexion. |
| 268 | - Returns -1 if an error occured. */ | 268 | + Returns 0 on success or -1 on failure. */ |
| 269 | int modbus_connect(modbus_param_t *mb_param); | 269 | int modbus_connect(modbus_param_t *mb_param); |
| 270 | 270 | ||
| 271 | /* Closes a modbus connection */ | 271 | /* Closes a modbus connection */ |
| @@ -284,7 +284,7 @@ void modbus_set_debug(modbus_param_t *mb_param, int boolean); | @@ -284,7 +284,7 @@ void modbus_set_debug(modbus_param_t *mb_param, int boolean); | ||
| 284 | /* Allocates 4 arrays to store coils, input status, input registers and | 284 | /* Allocates 4 arrays to store coils, input status, input registers and |
| 285 | holding registers. The pointers are stored in modbus_mapping structure. | 285 | holding registers. The pointers are stored in modbus_mapping structure. |
| 286 | 286 | ||
| 287 | - Returns: TRUE if ok, FALSE on failure | 287 | + Returns 0 on success and -1 on failure |
| 288 | */ | 288 | */ |
| 289 | int modbus_mapping_new(modbus_mapping_t *mb_mapping, | 289 | int modbus_mapping_new(modbus_mapping_t *mb_mapping, |
| 290 | int nb_coil_status, int nb_input_status, | 290 | int nb_coil_status, int nb_input_status, |
| @@ -306,7 +306,7 @@ int modbus_slave_accept_tcp(modbus_param_t *mb_param, int *socket); | @@ -306,7 +306,7 @@ int modbus_slave_accept_tcp(modbus_param_t *mb_param, int *socket); | ||
| 306 | descriptor etablished with the master device in argument. | 306 | descriptor etablished with the master device in argument. |
| 307 | 307 | ||
| 308 | Returns: | 308 | Returns: |
| 309 | - - 0 if OK, or a negative error number if the request fails | 309 | + - 0 on success, or a negative error number if the request fails |
| 310 | - query, message received | 310 | - query, message received |
| 311 | - query_length, length in bytes of the message | 311 | - query_length, length in bytes of the message |
| 312 | */ | 312 | */ |
tests/bandwidth-slave-many-up.c
| @@ -53,7 +53,7 @@ int main(void) | @@ -53,7 +53,7 @@ int main(void) | ||
| 53 | modbus_init_tcp(&mb_param, "127.0.0.1", 1502, SLAVE); | 53 | modbus_init_tcp(&mb_param, "127.0.0.1", 1502, SLAVE); |
| 54 | 54 | ||
| 55 | ret = modbus_mapping_new(&mb_mapping, MAX_STATUS, 0, MAX_REGISTERS, 0); | 55 | ret = modbus_mapping_new(&mb_mapping, MAX_STATUS, 0, MAX_REGISTERS, 0); |
| 56 | - if (ret == FALSE) { | 56 | + if (ret < 0) { |
| 57 | printf("Memory allocation failure\n"); | 57 | printf("Memory allocation failure\n"); |
| 58 | exit(1); | 58 | exit(1); |
| 59 | } | 59 | } |
tests/bandwidth-slave-one.c
| @@ -34,7 +34,7 @@ int main(void) | @@ -34,7 +34,7 @@ int main(void) | ||
| 34 | modbus_init_tcp(&mb_param, "127.0.0.1", 1502, SLAVE); | 34 | modbus_init_tcp(&mb_param, "127.0.0.1", 1502, SLAVE); |
| 35 | 35 | ||
| 36 | ret = modbus_mapping_new(&mb_mapping, MAX_STATUS, 0, MAX_REGISTERS, 0); | 36 | ret = modbus_mapping_new(&mb_mapping, MAX_STATUS, 0, MAX_REGISTERS, 0); |
| 37 | - if (ret == FALSE) { | 37 | + if (ret < 0) { |
| 38 | printf("Memory allocation failed\n"); | 38 | printf("Memory allocation failed\n"); |
| 39 | exit(1); | 39 | exit(1); |
| 40 | } | 40 | } |
tests/random-test-slave.c
| @@ -34,7 +34,7 @@ int main(void) | @@ -34,7 +34,7 @@ int main(void) | ||
| 34 | /* modbus_set_debug(&mb_param, TRUE); */ | 34 | /* modbus_set_debug(&mb_param, TRUE); */ |
| 35 | 35 | ||
| 36 | ret = modbus_mapping_new(&mb_mapping, 500, 500, 500, 500); | 36 | ret = modbus_mapping_new(&mb_mapping, 500, 500, 500, 500); |
| 37 | - if (ret == FALSE) { | 37 | + if (ret < 0) { |
| 38 | printf("Memory allocation failed\n"); | 38 | printf("Memory allocation failed\n"); |
| 39 | exit(1); | 39 | exit(1); |
| 40 | } | 40 | } |
tests/unit-test-slave.c
| @@ -39,7 +39,7 @@ int main(void) | @@ -39,7 +39,7 @@ int main(void) | ||
| 39 | UT_INPUT_STATUS_ADDRESS + UT_INPUT_STATUS_NB_POINTS, | 39 | UT_INPUT_STATUS_ADDRESS + UT_INPUT_STATUS_NB_POINTS, |
| 40 | UT_HOLDING_REGISTERS_ADDRESS + UT_HOLDING_REGISTERS_NB_POINTS, | 40 | UT_HOLDING_REGISTERS_ADDRESS + UT_HOLDING_REGISTERS_NB_POINTS, |
| 41 | UT_INPUT_REGISTERS_ADDRESS + UT_INPUT_REGISTERS_NB_POINTS); | 41 | UT_INPUT_REGISTERS_ADDRESS + UT_INPUT_REGISTERS_NB_POINTS); |
| 42 | - if (ret == FALSE) { | 42 | + if (ret < 0) { |
| 43 | printf("Memory allocation failed\n"); | 43 | printf("Memory allocation failed\n"); |
| 44 | exit(1); | 44 | exit(1); |
| 45 | } | 45 | } |