Kaynağa Gözat

modbus_mapping_new returns 0 on success

- adjusts various comments on return values
- updated tests
- added entry to MIGRATION
Stéphane Raimbault 16 yıl önce
ebeveyn
işleme
17994074d2

+ 2 - 0
MIGRATION

@@ -34,6 +34,8 @@ int modbus_slave_receive(modbus_param_t *mb_param, int sockfd,
      - HEADER_LENGTH_RTU           0 -> 1
      - HEADER_LENGTH_TCP           6 -> 7
 
+6 - modbus_mapping_new returns 0 on success and -1 on failure.
+
 
 =============================================
 Migration notes from the 1.2 series (for 2.0)

+ 8 - 8
src/modbus.c

@@ -651,7 +651,7 @@ static int receive_msg(modbus_param_t *mb_param,
    internal one of modbus_param_t.
 
    Returns:
-   - 0 if OK, or a negative error number if the request fails
+   - 0 on success, or a negative error number if the request fails
    - query, message received
    - query_length, length in bytes of the message */
 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)
 }
 
 /* Establishes a modbus connexion.
-   Returns -1 if an error occured. */
+   Returns 0 on success or -1 on failure. */
 int modbus_connect(modbus_param_t *mb_param)
 {
         int ret;
@@ -1787,7 +1787,7 @@ void modbus_set_debug(modbus_param_t *mb_param, int boolean)
 /* Allocates 4 arrays to store coils, input status, input registers and
    holding registers. The pointers are stored in modbus_mapping structure.
 
-   Returns: TRUE if ok, FALSE on failure
+   Returns 0 on success and -1 on failure.
 */
 int modbus_mapping_new(modbus_mapping_t *mb_mapping,
                        int nb_coil_status, int nb_input_status,
@@ -1800,7 +1800,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping,
         memset(mb_mapping->tab_coil_status, 0,
                nb_coil_status * sizeof(uint8_t));
         if (mb_mapping->tab_coil_status == NULL)
-                return FALSE;
+                return -1;
 
         /* 1X */
         mb_mapping->nb_input_status = nb_input_status;
@@ -1810,7 +1810,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping,
                nb_input_status * sizeof(uint8_t));
         if (mb_mapping->tab_input_status == NULL) {
                 free(mb_mapping->tab_coil_status);
-                return FALSE;
+                return -1;
         }
 
         /* 4X */
@@ -1822,7 +1822,7 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping,
         if (mb_mapping->tab_holding_registers == NULL) {
                 free(mb_mapping->tab_coil_status);
                 free(mb_mapping->tab_input_status);
-                return FALSE;
+                return -1;
         }
 
         /* 3X */
@@ -1835,10 +1835,10 @@ int modbus_mapping_new(modbus_mapping_t *mb_mapping,
                 free(mb_mapping->tab_coil_status);
                 free(mb_mapping->tab_input_status);
                 free(mb_mapping->tab_holding_registers);
-                return FALSE;
+                return -1;
         }
 
-        return TRUE;
+        return 0;
 }
 
 /* Frees the 4 arrays */

+ 3 - 3
src/modbus.h

@@ -265,7 +265,7 @@ void modbus_init_tcp(modbus_param_t *mb_param, const char *ip_address, int port,
 void modbus_set_error_handling(modbus_param_t *mb_param, error_handling_t error_handling);
 
 /* Establishes a modbus connexion.
-   Returns -1 if an error occured. */
+   Returns 0 on success or -1 on failure. */
 int modbus_connect(modbus_param_t *mb_param);
 
 /* Closes a modbus connection */
@@ -284,7 +284,7 @@ void modbus_set_debug(modbus_param_t *mb_param, int boolean);
 /* Allocates 4 arrays to store coils, input status, input registers and
    holding registers. The pointers are stored in modbus_mapping structure.
 
-   Returns: TRUE if ok, FALSE on failure
+   Returns 0 on success and -1 on failure
  */
 int modbus_mapping_new(modbus_mapping_t *mb_mapping,
                        int nb_coil_status, int nb_input_status,
@@ -306,7 +306,7 @@ int modbus_slave_accept_tcp(modbus_param_t *mb_param, int *socket);
    descriptor etablished with the master device in argument.
 
    Returns:
-   - 0 if OK, or a negative error number if the request fails
+   - 0 on success, or a negative error number if the request fails
    - query, message received
    - query_length, length in bytes of the message
 */

+ 1 - 1
tests/bandwidth-slave-many-up.c

@@ -53,7 +53,7 @@ int main(void)
         modbus_init_tcp(&mb_param, "127.0.0.1", 1502, SLAVE);
 
         ret = modbus_mapping_new(&mb_mapping,  MAX_STATUS, 0, MAX_REGISTERS, 0);
-        if (ret == FALSE) {
+        if (ret < 0) {
                 printf("Memory allocation failure\n");
                 exit(1);
         }

+ 1 - 1
tests/bandwidth-slave-one.c

@@ -34,7 +34,7 @@ int main(void)
         modbus_init_tcp(&mb_param, "127.0.0.1", 1502, SLAVE);
 
         ret = modbus_mapping_new(&mb_mapping,  MAX_STATUS, 0, MAX_REGISTERS, 0);
-        if (ret == FALSE) {
+        if (ret < 0) {
                 printf("Memory allocation failed\n");
                 exit(1);
         }

+ 1 - 1
tests/random-test-slave.c

@@ -34,7 +34,7 @@ int main(void)
         /* modbus_set_debug(&mb_param, TRUE); */
 
         ret = modbus_mapping_new(&mb_mapping, 500, 500, 500, 500);
-        if (ret == FALSE) {
+        if (ret < 0) {
                 printf("Memory allocation failed\n");
                 exit(1);
         }

+ 1 - 1
tests/unit-test-slave.c

@@ -39,7 +39,7 @@ int main(void)
                                  UT_INPUT_STATUS_ADDRESS + UT_INPUT_STATUS_NB_POINTS,
                                  UT_HOLDING_REGISTERS_ADDRESS + UT_HOLDING_REGISTERS_NB_POINTS,
                                  UT_INPUT_REGISTERS_ADDRESS + UT_INPUT_REGISTERS_NB_POINTS);
-        if (ret == FALSE) {
+        if (ret < 0) {
                 printf("Memory allocation failed\n");
                 exit(1);
         }