Commit d457ea864e2bfdd4610983ee71e98fea05399402

Authored by Stéphane Raimbault
1 parent 9be43128

Minor

- remove a comment about perror (useless)
- remove some printf
- rename write_ret to ret
Showing 1 changed file with 8 additions and 13 deletions
modbus/modbus.c
@@ -136,9 +136,6 @@ static int read_reg_response(modbus_param_t *mb_param, @@ -136,9 +136,6 @@ static int read_reg_response(modbus_param_t *mb_param,
136 /* Treats errors and flush or close connection if necessary */ 136 /* Treats errors and flush or close connection if necessary */
137 static void error_treat(int code, const char *string, modbus_param_t *mb_param) 137 static void error_treat(int code, const char *string, modbus_param_t *mb_param)
138 { 138 {
139 - // FIXME restore perror management  
140 - // if (code 0)  
141 - // perror(string);  
142 printf("\n\nERROR %s (%.2X)\n\n", string, code); 139 printf("\n\nERROR %s (%.2X)\n\n", string, code);
143 140
144 if (mb_param->error_handling == FLUSH_OR_RECONNECT_ON_ERROR) { 141 if (mb_param->error_handling == FLUSH_OR_RECONNECT_ON_ERROR) {
@@ -358,7 +355,7 @@ int check_crc16(modbus_param_t *mb_param, @@ -358,7 +355,7 @@ int check_crc16(modbus_param_t *mb_param,
358 static int modbus_send(modbus_param_t *mb_param, uint8_t *query, 355 static int modbus_send(modbus_param_t *mb_param, uint8_t *query,
359 size_t query_size) 356 size_t query_size)
360 { 357 {
361 - int write_ret; 358 + int ret;
362 uint16_t s_crc; 359 uint16_t s_crc;
363 int i; 360 int i;
364 361
@@ -379,18 +376,18 @@ static int modbus_send(modbus_param_t *mb_param, uint8_t *query, @@ -379,18 +376,18 @@ static int modbus_send(modbus_param_t *mb_param, uint8_t *query,
379 } 376 }
380 377
381 if (mb_param->type_com == RTU) 378 if (mb_param->type_com == RTU)
382 - write_ret = write(mb_param->fd, query, query_size); 379 + ret = write(mb_param->fd, query, query_size);
383 else 380 else
384 - write_ret = send(mb_param->fd, query, query_size, 0); 381 + ret = send(mb_param->fd, query, query_size, 0);
385 382
386 /* Return the number of bytes written (0 to n) 383 /* Return the number of bytes written (0 to n)
387 or PORT_SOCKET_FAILURE on error */ 384 or PORT_SOCKET_FAILURE on error */
388 - if ((write_ret == -1) || (write_ret != query_size)) {  
389 - write_ret = PORT_SOCKET_FAILURE;  
390 - error_treat(write_ret, "Write port/socket failure", mb_param); 385 + if ((ret == -1) || (ret != query_size)) {
  386 + ret = PORT_SOCKET_FAILURE;
  387 + error_treat(ret, "Write port/socket failure", mb_param);
391 } 388 }
392 389
393 - return write_ret; 390 + return ret;
394 } 391 }
395 392
396 /* Computes the size of the header following the function code */ 393 /* Computes the size of the header following the function code */
@@ -548,20 +545,18 @@ int receive_msg(modbus_param_t *mb_param, @@ -548,20 +545,18 @@ int receive_msg(modbus_param_t *mb_param,
548 size_to_read = compute_query_size_header(msg[mb_param->header_length + 1]); 545 size_to_read = compute_query_size_header(msg[mb_param->header_length + 1]);
549 msg_size_computed += size_to_read; 546 msg_size_computed += size_to_read;
550 state = BYTE; 547 state = BYTE;
551 - printf("\nBYTE:");  
552 break; 548 break;
553 case BYTE: 549 case BYTE:
554 size_to_read = compute_query_size_data(mb_param, msg); 550 size_to_read = compute_query_size_data(mb_param, msg);
555 msg_size_computed += size_to_read; 551 msg_size_computed += size_to_read;
556 state = COMPLETE; 552 state = COMPLETE;
557 - printf("\nCOMPLETE:");  
558 break; 553 break;
559 case COMPLETE: 554 case COMPLETE:
560 size_to_read = 0; 555 size_to_read = 0;
561 break; 556 break;
562 } 557 }
563 } 558 }
564 - printf(" size to read %d\n", size_to_read); 559 + printf("\nsize_to_read: %d\n", size_to_read);
565 560
566 /* Moves the pointer to receive other datas */ 561 /* Moves the pointer to receive other datas */
567 p_msg = &(p_msg[read_ret]); 562 p_msg = &(p_msg[read_ret]);