Commit 09b581a538f00992585dae2ccaaf4857c7152c9c
1 parent
cfaa872f
Rename data_dest|src in dest|src to match header
Showing
1 changed file
with
21 additions
and
20 deletions
src/modbus.c
| @@ -855,7 +855,7 @@ int modbus_reply_exception(modbus_t *ctx, const uint8_t *req, | @@ -855,7 +855,7 @@ int modbus_reply_exception(modbus_t *ctx, const uint8_t *req, | ||
| 855 | 855 | ||
| 856 | /* Reads IO status */ | 856 | /* Reads IO status */ |
| 857 | static int read_io_status(modbus_t *ctx, int function, | 857 | static int read_io_status(modbus_t *ctx, int function, |
| 858 | - int addr, int nb, uint8_t *data_dest) | 858 | + int addr, int nb, uint8_t *dest) |
| 859 | { | 859 | { |
| 860 | int rc; | 860 | int rc; |
| 861 | int req_length; | 861 | int req_length; |
| @@ -883,7 +883,7 @@ static int read_io_status(modbus_t *ctx, int function, | @@ -883,7 +883,7 @@ static int read_io_status(modbus_t *ctx, int function, | ||
| 883 | temp = rsp[i]; | 883 | temp = rsp[i]; |
| 884 | 884 | ||
| 885 | for (bit = 0x01; (bit & 0xff) && (pos < nb);) { | 885 | for (bit = 0x01; (bit & 0xff) && (pos < nb);) { |
| 886 | - data_dest[pos++] = (temp & bit) ? TRUE : FALSE; | 886 | + dest[pos++] = (temp & bit) ? TRUE : FALSE; |
| 887 | bit = bit << 1; | 887 | bit = bit << 1; |
| 888 | } | 888 | } |
| 889 | 889 | ||
| @@ -895,7 +895,7 @@ static int read_io_status(modbus_t *ctx, int function, | @@ -895,7 +895,7 @@ static int read_io_status(modbus_t *ctx, int function, | ||
| 895 | 895 | ||
| 896 | /* Reads the boolean status of bits and sets the array elements | 896 | /* Reads the boolean status of bits and sets the array elements |
| 897 | in the destination to TRUE or FALSE (single bits). */ | 897 | in the destination to TRUE or FALSE (single bits). */ |
| 898 | -int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | 898 | +int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest) |
| 899 | { | 899 | { |
| 900 | int rc; | 900 | int rc; |
| 901 | 901 | ||
| @@ -909,7 +909,7 @@ int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | @@ -909,7 +909,7 @@ int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | ||
| 909 | return -1; | 909 | return -1; |
| 910 | } | 910 | } |
| 911 | 911 | ||
| 912 | - rc = read_io_status(ctx, _FC_READ_COILS, addr, nb, data_dest); | 912 | + rc = read_io_status(ctx, _FC_READ_COILS, addr, nb, dest); |
| 913 | 913 | ||
| 914 | if (rc == -1) | 914 | if (rc == -1) |
| 915 | return -1; | 915 | return -1; |
| @@ -919,7 +919,7 @@ int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | @@ -919,7 +919,7 @@ int modbus_read_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | ||
| 919 | 919 | ||
| 920 | 920 | ||
| 921 | /* Same as modbus_read_bits but reads the remote device input table */ | 921 | /* Same as modbus_read_bits but reads the remote device input table */ |
| 922 | -int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | 922 | +int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *dest) |
| 923 | { | 923 | { |
| 924 | int rc; | 924 | int rc; |
| 925 | 925 | ||
| @@ -933,7 +933,7 @@ int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | @@ -933,7 +933,7 @@ int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | ||
| 933 | return -1; | 933 | return -1; |
| 934 | } | 934 | } |
| 935 | 935 | ||
| 936 | - rc = read_io_status(ctx, _FC_READ_DISCRETE_INPUTS, addr, nb, data_dest); | 936 | + rc = read_io_status(ctx, _FC_READ_DISCRETE_INPUTS, addr, nb, dest); |
| 937 | 937 | ||
| 938 | if (rc == -1) | 938 | if (rc == -1) |
| 939 | return -1; | 939 | return -1; |
| @@ -943,7 +943,7 @@ int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | @@ -943,7 +943,7 @@ int modbus_read_input_bits(modbus_t *ctx, int addr, int nb, uint8_t *data_dest) | ||
| 943 | 943 | ||
| 944 | /* Reads the data from a remove device and put that data into an array */ | 944 | /* Reads the data from a remove device and put that data into an array */ |
| 945 | static int read_registers(modbus_t *ctx, int function, int addr, int nb, | 945 | static int read_registers(modbus_t *ctx, int function, int addr, int nb, |
| 946 | - uint16_t *data_dest) | 946 | + uint16_t *dest) |
| 947 | { | 947 | { |
| 948 | int rc; | 948 | int rc; |
| 949 | int req_length; | 949 | int req_length; |
| @@ -976,7 +976,7 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, | @@ -976,7 +976,7 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, | ||
| 976 | 976 | ||
| 977 | for (i = 0; i < rc; i++) { | 977 | for (i = 0; i < rc; i++) { |
| 978 | /* shift reg hi_byte to temp OR with lo_byte */ | 978 | /* shift reg hi_byte to temp OR with lo_byte */ |
| 979 | - data_dest[i] = (rsp[offset + 2 + (i << 1)] << 8) | | 979 | + dest[i] = (rsp[offset + 2 + (i << 1)] << 8) | |
| 980 | rsp[offset + 3 + (i << 1)]; | 980 | rsp[offset + 3 + (i << 1)]; |
| 981 | } | 981 | } |
| 982 | } | 982 | } |
| @@ -986,7 +986,7 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, | @@ -986,7 +986,7 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb, | ||
| 986 | 986 | ||
| 987 | /* Reads the holding registers of remote device and put the data into an | 987 | /* Reads the holding registers of remote device and put the data into an |
| 988 | array */ | 988 | array */ |
| 989 | -int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *data_dest) | 989 | +int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *dest) |
| 990 | { | 990 | { |
| 991 | int status; | 991 | int status; |
| 992 | 992 | ||
| @@ -1001,13 +1001,13 @@ int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *data_dest) | @@ -1001,13 +1001,13 @@ int modbus_read_registers(modbus_t *ctx, int addr, int nb, uint16_t *data_dest) | ||
| 1001 | } | 1001 | } |
| 1002 | 1002 | ||
| 1003 | status = read_registers(ctx, _FC_READ_HOLDING_REGISTERS, | 1003 | status = read_registers(ctx, _FC_READ_HOLDING_REGISTERS, |
| 1004 | - addr, nb, data_dest); | 1004 | + addr, nb, dest); |
| 1005 | return status; | 1005 | return status; |
| 1006 | } | 1006 | } |
| 1007 | 1007 | ||
| 1008 | /* Reads the input registers of remote device and put the data into an array */ | 1008 | /* Reads the input registers of remote device and put the data into an array */ |
| 1009 | int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, | 1009 | int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, |
| 1010 | - uint16_t *data_dest) | 1010 | + uint16_t *dest) |
| 1011 | { | 1011 | { |
| 1012 | int status; | 1012 | int status; |
| 1013 | 1013 | ||
| @@ -1020,7 +1020,7 @@ int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, | @@ -1020,7 +1020,7 @@ int modbus_read_input_registers(modbus_t *ctx, int addr, int nb, | ||
| 1020 | } | 1020 | } |
| 1021 | 1021 | ||
| 1022 | status = read_registers(ctx, _FC_READ_INPUT_REGISTERS, | 1022 | status = read_registers(ctx, _FC_READ_INPUT_REGISTERS, |
| 1023 | - addr, nb, data_dest); | 1023 | + addr, nb, dest); |
| 1024 | 1024 | ||
| 1025 | return status; | 1025 | return status; |
| 1026 | } | 1026 | } |
| @@ -1069,7 +1069,7 @@ int modbus_write_register(modbus_t *ctx, int addr, int value) | @@ -1069,7 +1069,7 @@ int modbus_write_register(modbus_t *ctx, int addr, int value) | ||
| 1069 | } | 1069 | } |
| 1070 | 1070 | ||
| 1071 | /* Write the bits of the array in the remote device */ | 1071 | /* Write the bits of the array in the remote device */ |
| 1072 | -int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data_src) | 1072 | +int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *src) |
| 1073 | { | 1073 | { |
| 1074 | int rc; | 1074 | int rc; |
| 1075 | int i; | 1075 | int i; |
| @@ -1089,7 +1089,8 @@ int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data_src) | @@ -1089,7 +1089,8 @@ int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data_src) | ||
| 1089 | return -1; | 1089 | return -1; |
| 1090 | } | 1090 | } |
| 1091 | 1091 | ||
| 1092 | - req_length = ctx->backend->build_request_basis(ctx, _FC_WRITE_MULTIPLE_COILS, | 1092 | + req_length = ctx->backend->build_request_basis(ctx, |
| 1093 | + _FC_WRITE_MULTIPLE_COILS, | ||
| 1093 | addr, nb, req); | 1094 | addr, nb, req); |
| 1094 | byte_count = (nb / 8) + ((nb % 8) ? 1 : 0); | 1095 | byte_count = (nb / 8) + ((nb % 8) ? 1 : 0); |
| 1095 | req[req_length++] = byte_count; | 1096 | req[req_length++] = byte_count; |
| @@ -1101,7 +1102,7 @@ int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data_src) | @@ -1101,7 +1102,7 @@ int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data_src) | ||
| 1101 | req[req_length] = 0; | 1102 | req[req_length] = 0; |
| 1102 | 1103 | ||
| 1103 | while ((bit & 0xFF) && (bit_check++ < nb)) { | 1104 | while ((bit & 0xFF) && (bit_check++ < nb)) { |
| 1104 | - if (data_src[pos++]) | 1105 | + if (src[pos++]) |
| 1105 | req[req_length] |= bit; | 1106 | req[req_length] |= bit; |
| 1106 | else | 1107 | else |
| 1107 | req[req_length] &=~ bit; | 1108 | req[req_length] &=~ bit; |
| @@ -1122,7 +1123,7 @@ int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data_src) | @@ -1122,7 +1123,7 @@ int modbus_write_bits(modbus_t *ctx, int addr, int nb, const uint8_t *data_src) | ||
| 1122 | } | 1123 | } |
| 1123 | 1124 | ||
| 1124 | /* Write the values from the array to the registers of the remote device */ | 1125 | /* Write the values from the array to the registers of the remote device */ |
| 1125 | -int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *data_src) | 1126 | +int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *src) |
| 1126 | { | 1127 | { |
| 1127 | int rc; | 1128 | int rc; |
| 1128 | int i; | 1129 | int i; |
| @@ -1148,8 +1149,8 @@ int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *data | @@ -1148,8 +1149,8 @@ int modbus_write_registers(modbus_t *ctx, int addr, int nb, const uint16_t *data | ||
| 1148 | req[req_length++] = byte_count; | 1149 | req[req_length++] = byte_count; |
| 1149 | 1150 | ||
| 1150 | for (i = 0; i < nb; i++) { | 1151 | for (i = 0; i < nb; i++) { |
| 1151 | - req[req_length++] = data_src[i] >> 8; | ||
| 1152 | - req[req_length++] = data_src[i] & 0x00FF; | 1152 | + req[req_length++] = src[i] >> 8; |
| 1153 | + req[req_length++] = src[i] & 0x00FF; | ||
| 1153 | } | 1154 | } |
| 1154 | 1155 | ||
| 1155 | rc = send_msg(ctx, req, req_length); | 1156 | rc = send_msg(ctx, req, req_length); |
| @@ -1229,7 +1230,7 @@ int modbus_read_and_write_registers(modbus_t *ctx, | @@ -1229,7 +1230,7 @@ int modbus_read_and_write_registers(modbus_t *ctx, | ||
| 1229 | 1230 | ||
| 1230 | /* Send a request to get the slave ID of the device (only available in serial | 1231 | /* Send a request to get the slave ID of the device (only available in serial |
| 1231 | communication). */ | 1232 | communication). */ |
| 1232 | -int modbus_report_slave_id(modbus_t *ctx, uint8_t *data_dest) | 1233 | +int modbus_report_slave_id(modbus_t *ctx, uint8_t *dest) |
| 1233 | { | 1234 | { |
| 1234 | int rc; | 1235 | int rc; |
| 1235 | int req_length; | 1236 | int req_length; |
| @@ -1256,7 +1257,7 @@ int modbus_report_slave_id(modbus_t *ctx, uint8_t *data_dest) | @@ -1256,7 +1257,7 @@ int modbus_report_slave_id(modbus_t *ctx, uint8_t *data_dest) | ||
| 1256 | offset = ctx->backend->header_length + 2; | 1257 | offset = ctx->backend->header_length + 2; |
| 1257 | 1258 | ||
| 1258 | for (i=0; i < rc; i++) { | 1259 | for (i=0; i < rc; i++) { |
| 1259 | - data_dest[i] = rsp[offset + i]; | 1260 | + dest[i] = rsp[offset + i]; |
| 1260 | } | 1261 | } |
| 1261 | } | 1262 | } |
| 1262 | 1263 |