Commit 558538ab5b3c18b10564db5be49a5931779b821c

Authored by Stéphane Raimbault
1 parent 1e288713

Minor comment improvements

src/modbus-rtu.c
@@ -351,7 +351,7 @@ static int _modbus_rtu_pre_check_confirmation(modbus_t *ctx, const uint8_t *req, @@ -351,7 +351,7 @@ static int _modbus_rtu_pre_check_confirmation(modbus_t *ctx, const uint8_t *req,
351 if (req[0] != rsp[0] && req[0] != MODBUS_BROADCAST_ADDRESS) { 351 if (req[0] != rsp[0] && req[0] != MODBUS_BROADCAST_ADDRESS) {
352 if (ctx->debug) { 352 if (ctx->debug) {
353 fprintf(stderr, 353 fprintf(stderr,
354 - "The responding slave %d isn't the requested slave %d", 354 + "The responding slave %d isn't the requested slave %d\n",
355 rsp[0], req[0]); 355 rsp[0], req[0]);
356 } 356 }
357 errno = EMBBADSLAVE; 357 errno = EMBBADSLAVE;
@@ -371,13 +371,13 @@ static int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg, @@ -371,13 +371,13 @@ static int _modbus_rtu_check_integrity(modbus_t *ctx, uint8_t *msg,
371 uint16_t crc_received; 371 uint16_t crc_received;
372 int slave = msg[0]; 372 int slave = msg[0];
373 373
374 - /* Filter on the Modbus unit identifier (slave) in RTU mode */ 374 + /* Filter on the Modbus unit identifier (slave) in RTU mode to avoid useless
  375 + * CRC computing. */
375 if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS) { 376 if (slave != ctx->slave && slave != MODBUS_BROADCAST_ADDRESS) {
376 - /* Ignores the request (not for me) */  
377 if (ctx->debug) { 377 if (ctx->debug) {
378 printf("Request for slave %d ignored (not %d)\n", slave, ctx->slave); 378 printf("Request for slave %d ignored (not %d)\n", slave, ctx->slave);
379 } 379 }
380 - 380 + /* Following call to check_confirmation handles this error */
381 return 0; 381 return 0;
382 } 382 }
383 383
src/modbus.c
@@ -1468,8 +1468,6 @@ int modbus_write_and_read_registers(modbus_t *ctx, @@ -1468,8 +1468,6 @@ int modbus_write_and_read_registers(modbus_t *ctx,
1468 return -1; 1468 return -1;
1469 1469
1470 offset = ctx->backend->header_length; 1470 offset = ctx->backend->header_length;
1471 -  
1472 - /* If rc is negative, the loop is jumped ! */  
1473 for (i = 0; i < rc; i++) { 1471 for (i = 0; i < rc; i++) {
1474 /* shift reg hi_byte to temp OR with lo_byte */ 1472 /* shift reg hi_byte to temp OR with lo_byte */
1475 dest[i] = (rsp[offset + 2 + (i << 1)] << 8) | 1473 dest[i] = (rsp[offset + 2 + (i << 1)] << 8) |