Commit 0a80018a648804bdccc885456b310971fe820847
1 parent
0ef574f6
Minor s/count/nb/ in modbus.[ch]
Showing
2 changed files
with
97 additions
and
97 deletions
modbus/modbus.c
| ... | ... | @@ -175,8 +175,8 @@ static unsigned int compute_response_length(modbus_param_t *mb_param, |
| 175 | 175 | case FC_READ_COIL_STATUS: |
| 176 | 176 | case FC_READ_INPUT_STATUS: { |
| 177 | 177 | /* Header + nb values (code from force_multiple_coils) */ |
| 178 | - int nb_points = (query[offset + 4] << 8) | query[offset + 5]; | |
| 179 | - resp_length = 3 + (nb_points / 8) + ((nb_points % 8) ? 1 : 0); | |
| 178 | + int nb = (query[offset + 4] << 8) | query[offset + 5]; | |
| 179 | + resp_length = 3 + (nb / 8) + ((nb % 8) ? 1 : 0); | |
| 180 | 180 | } |
| 181 | 181 | break; |
| 182 | 182 | case FC_READ_HOLDING_REGISTERS: |
| ... | ... | @@ -199,22 +199,22 @@ static unsigned int compute_response_length(modbus_param_t *mb_param, |
| 199 | 199 | |
| 200 | 200 | /* Builds a RTU query header */ |
| 201 | 201 | static int build_query_basis_rtu(int slave, int function, |
| 202 | - int start_addr, int count, | |
| 202 | + int start_addr, int nb, | |
| 203 | 203 | uint8_t *query) |
| 204 | 204 | { |
| 205 | 205 | query[0] = slave; |
| 206 | 206 | query[1] = function; |
| 207 | 207 | query[2] = start_addr >> 8; |
| 208 | 208 | query[3] = start_addr & 0x00ff; |
| 209 | - query[4] = count >> 8; | |
| 210 | - query[5] = count & 0x00ff; | |
| 209 | + query[4] = nb >> 8; | |
| 210 | + query[5] = nb & 0x00ff; | |
| 211 | 211 | |
| 212 | 212 | return PRESET_QUERY_LENGTH_RTU; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /* Builds a TCP query header */ |
| 216 | 216 | static int build_query_basis_tcp(int slave, int function, |
| 217 | - int start_addr, int count, | |
| 217 | + int start_addr, int nb, | |
| 218 | 218 | uint8_t *query) |
| 219 | 219 | { |
| 220 | 220 | |
| ... | ... | @@ -244,22 +244,22 @@ static int build_query_basis_tcp(int slave, int function, |
| 244 | 244 | query[7] = function; |
| 245 | 245 | query[8] = start_addr >> 8; |
| 246 | 246 | query[9] = start_addr & 0x00ff; |
| 247 | - query[10] = count >> 8; | |
| 248 | - query[11] = count & 0x00ff; | |
| 247 | + query[10] = nb >> 8; | |
| 248 | + query[11] = nb & 0x00ff; | |
| 249 | 249 | |
| 250 | 250 | return PRESET_QUERY_LENGTH_TCP; |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | static int build_query_basis(modbus_param_t *mb_param, int slave, |
| 254 | 254 | int function, int start_addr, |
| 255 | - int count, uint8_t *query) | |
| 255 | + int nb, uint8_t *query) | |
| 256 | 256 | { |
| 257 | 257 | if (mb_param->type_com == RTU) |
| 258 | 258 | return build_query_basis_rtu(slave, function, start_addr, |
| 259 | - count, query); | |
| 259 | + nb, query); | |
| 260 | 260 | else |
| 261 | 261 | return build_query_basis_tcp(slave, function, start_addr, |
| 262 | - count, query); | |
| 262 | + nb, query); | |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /* Builds a RTU response header */ |
| ... | ... | @@ -688,7 +688,7 @@ static int modbus_check_response(modbus_param_t *mb_param, |
| 688 | 688 | return response_length; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | -static int response_io_status(int address, int count, | |
| 691 | +static int response_io_status(int address, int nb, | |
| 692 | 692 | uint8_t *tab_io_status, |
| 693 | 693 | uint8_t *response, int offset) |
| 694 | 694 | { |
| ... | ... | @@ -696,7 +696,7 @@ static int response_io_status(int address, int count, |
| 696 | 696 | int byte = 0; |
| 697 | 697 | int i; |
| 698 | 698 | |
| 699 | - for (i = address; i < address+count; i++) { | |
| 699 | + for (i = address; i < address+nb; i++) { | |
| 700 | 700 | byte |= tab_io_status[i] << shift; |
| 701 | 701 | if (shift == 7) { |
| 702 | 702 | /* Byte is full */ |
| ... | ... | @@ -753,17 +753,17 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query, |
| 753 | 753 | |
| 754 | 754 | switch (function) { |
| 755 | 755 | case FC_READ_COIL_STATUS: { |
| 756 | - int count = (query[offset+4] << 8) + query[offset+5]; | |
| 756 | + int nb = (query[offset+4] << 8) + query[offset+5]; | |
| 757 | 757 | |
| 758 | - if ((address + count) > mb_mapping->nb_coil_status) { | |
| 758 | + if ((address + nb) > mb_mapping->nb_coil_status) { | |
| 759 | 759 | printf("Illegal data address %0X in read_coil_status\n", |
| 760 | - address + count); | |
| 760 | + address + nb); | |
| 761 | 761 | resp_length = response_exception(mb_param, &sft, |
| 762 | 762 | ILLEGAL_DATA_ADDRESS, response); |
| 763 | 763 | } else { |
| 764 | 764 | resp_length = build_response_basis(mb_param, &sft, response); |
| 765 | - response[resp_length++] = (count / 8) + ((count % 8) ? 1 : 0); | |
| 766 | - resp_length = response_io_status(address, count, | |
| 765 | + response[resp_length++] = (nb / 8) + ((nb % 8) ? 1 : 0); | |
| 766 | + resp_length = response_io_status(address, nb, | |
| 767 | 767 | mb_mapping->tab_coil_status, |
| 768 | 768 | response, resp_length); |
| 769 | 769 | } |
| ... | ... | @@ -771,36 +771,36 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query, |
| 771 | 771 | break; |
| 772 | 772 | case FC_READ_INPUT_STATUS: { |
| 773 | 773 | /* Similar to coil status */ |
| 774 | - int count = (query[offset+4] << 8) + query[offset+5]; | |
| 774 | + int nb = (query[offset+4] << 8) + query[offset+5]; | |
| 775 | 775 | |
| 776 | - if ((address + count) > mb_mapping->nb_input_status) { | |
| 776 | + if ((address + nb) > mb_mapping->nb_input_status) { | |
| 777 | 777 | printf("Illegal data address %0X in read_input_status\n", |
| 778 | - address + count); | |
| 778 | + address + nb); | |
| 779 | 779 | resp_length = response_exception(mb_param, &sft, |
| 780 | 780 | ILLEGAL_DATA_ADDRESS, response); |
| 781 | 781 | } else { |
| 782 | 782 | resp_length = build_response_basis(mb_param, &sft, response); |
| 783 | - response[resp_length++] = (count / 8) + ((count % 8) ? 1 : 0); | |
| 784 | - resp_length = response_io_status(address, count, | |
| 783 | + response[resp_length++] = (nb / 8) + ((nb % 8) ? 1 : 0); | |
| 784 | + resp_length = response_io_status(address, nb, | |
| 785 | 785 | mb_mapping->tab_input_status, |
| 786 | 786 | response, resp_length); |
| 787 | 787 | } |
| 788 | 788 | } |
| 789 | 789 | break; |
| 790 | 790 | case FC_READ_HOLDING_REGISTERS: { |
| 791 | - int count = (query[offset+4] << 8) + query[offset+5]; | |
| 791 | + int nb = (query[offset+4] << 8) + query[offset+5]; | |
| 792 | 792 | |
| 793 | - if ((address + count) > mb_mapping->nb_holding_registers) { | |
| 793 | + if ((address + nb) > mb_mapping->nb_holding_registers) { | |
| 794 | 794 | printf("Illegal data address %0X in read_holding_registers\n", |
| 795 | - address + count); | |
| 795 | + address + nb); | |
| 796 | 796 | resp_length = response_exception(mb_param, &sft, |
| 797 | 797 | ILLEGAL_DATA_ADDRESS, response); |
| 798 | 798 | } else { |
| 799 | 799 | int i; |
| 800 | 800 | |
| 801 | 801 | resp_length = build_response_basis(mb_param, &sft, response); |
| 802 | - response[resp_length++] = count << 1; | |
| 803 | - for (i = address; i < address + count; i++) { | |
| 802 | + response[resp_length++] = nb << 1; | |
| 803 | + for (i = address; i < address + nb; i++) { | |
| 804 | 804 | response[resp_length++] = mb_mapping->tab_holding_registers[i] >> 8; |
| 805 | 805 | response[resp_length++] = mb_mapping->tab_holding_registers[i] & 0xFF; |
| 806 | 806 | } |
| ... | ... | @@ -809,19 +809,19 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query, |
| 809 | 809 | break; |
| 810 | 810 | case FC_READ_INPUT_REGISTERS: { |
| 811 | 811 | /* Similar to holding registers */ |
| 812 | - int count = (query[offset+4] << 8) + query[offset+5]; | |
| 812 | + int nb = (query[offset+4] << 8) + query[offset+5]; | |
| 813 | 813 | |
| 814 | - if ((address + count) > mb_mapping->nb_input_registers) { | |
| 814 | + if ((address + nb) > mb_mapping->nb_input_registers) { | |
| 815 | 815 | printf("Illegal data address %0X in read_input_registers\n", |
| 816 | - address + count); | |
| 816 | + address + nb); | |
| 817 | 817 | resp_length = response_exception(mb_param, &sft, |
| 818 | 818 | ILLEGAL_DATA_ADDRESS, response); |
| 819 | 819 | } else { |
| 820 | 820 | int i; |
| 821 | 821 | |
| 822 | 822 | resp_length = build_response_basis(mb_param, &sft, response); |
| 823 | - response[resp_length++] = count << 1; | |
| 824 | - for (i = address; i < address + count; i++) { | |
| 823 | + response[resp_length++] = nb << 1; | |
| 824 | + for (i = address; i < address + nb; i++) { | |
| 825 | 825 | response[resp_length++] = mb_mapping->tab_input_registers[i] >> 8; |
| 826 | 826 | response[resp_length++] = mb_mapping->tab_input_registers[i] & 0xFF; |
| 827 | 827 | } |
| ... | ... | @@ -865,11 +865,11 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query, |
| 865 | 865 | } |
| 866 | 866 | break; |
| 867 | 867 | case FC_FORCE_MULTIPLE_COILS: { |
| 868 | - int count = (query[offset+4] << 8) + query[offset+5]; | |
| 868 | + int nb = (query[offset+4] << 8) + query[offset+5]; | |
| 869 | 869 | |
| 870 | - if ((address + count) > mb_mapping->nb_coil_status) { | |
| 870 | + if ((address + nb) > mb_mapping->nb_coil_status) { | |
| 871 | 871 | printf("Illegal data address %0X in force_multiple_coils\n", |
| 872 | - address + count); | |
| 872 | + address + nb); | |
| 873 | 873 | resp_length = response_exception(mb_param, &sft, |
| 874 | 874 | ILLEGAL_DATA_ADDRESS, response); |
| 875 | 875 | } else { |
| ... | ... | @@ -881,11 +881,11 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query, |
| 881 | 881 | } |
| 882 | 882 | break; |
| 883 | 883 | case FC_PRESET_MULTIPLE_REGISTERS: { |
| 884 | - int count = (query[offset+4] << 8) + query[offset+5]; | |
| 884 | + int nb = (query[offset+4] << 8) + query[offset+5]; | |
| 885 | 885 | |
| 886 | - if ((address + count) > mb_mapping->nb_holding_registers) { | |
| 886 | + if ((address + nb) > mb_mapping->nb_holding_registers) { | |
| 887 | 887 | printf("Illegal data address %0X in preset_multiple_registers\n", |
| 888 | - address + count); | |
| 888 | + address + nb); | |
| 889 | 889 | resp_length = response_exception(mb_param, &sft, |
| 890 | 890 | ILLEGAL_DATA_ADDRESS, response); |
| 891 | 891 | } else { |
| ... | ... | @@ -924,7 +924,7 @@ int modbus_listen(modbus_param_t *mb_param, uint8_t *query, int *query_length) |
| 924 | 924 | |
| 925 | 925 | /* Reads IO status */ |
| 926 | 926 | static int read_io_status(modbus_param_t *mb_param, int slave, int function, |
| 927 | - int start_addr, int count, uint8_t *data_dest) | |
| 927 | + int start_addr, int nb, uint8_t *data_dest) | |
| 928 | 928 | { |
| 929 | 929 | int query_length; |
| 930 | 930 | int query_ret; |
| ... | ... | @@ -934,7 +934,7 @@ static int read_io_status(modbus_param_t *mb_param, int slave, int function, |
| 934 | 934 | uint8_t response[MAX_MESSAGE_LENGTH]; |
| 935 | 935 | |
| 936 | 936 | query_length = build_query_basis(mb_param, slave, function, |
| 937 | - start_addr, count, query); | |
| 937 | + start_addr, nb, query); | |
| 938 | 938 | |
| 939 | 939 | query_ret = modbus_send(mb_param, query, query_length); |
| 940 | 940 | if (query_ret > 0) { |
| ... | ... | @@ -952,7 +952,7 @@ static int read_io_status(modbus_param_t *mb_param, int slave, int function, |
| 952 | 952 | /* Shift reg hi_byte to temp */ |
| 953 | 953 | temp = response[3 + i]; |
| 954 | 954 | |
| 955 | - for (bit = 0x01; (bit & 0xff) && (processed < count);) { | |
| 955 | + for (bit = 0x01; (bit & 0xff) && (processed < nb);) { | |
| 956 | 956 | data_dest[pos++] = (temp & bit) ? TRUE : FALSE; |
| 957 | 957 | processed++; |
| 958 | 958 | bit = bit << 1; |
| ... | ... | @@ -969,21 +969,21 @@ static int read_io_status(modbus_param_t *mb_param, int slave, int function, |
| 969 | 969 | /* Reads the boolean status of coils and sets the array elements |
| 970 | 970 | in the destination to TRUE or FALSE. */ |
| 971 | 971 | int read_coil_status(modbus_param_t *mb_param, int slave, int start_addr, |
| 972 | - int count, uint8_t *data_dest) | |
| 972 | + int nb, uint8_t *data_dest) | |
| 973 | 973 | { |
| 974 | 974 | int status; |
| 975 | 975 | |
| 976 | - if (count > MAX_STATUS) { | |
| 976 | + if (nb > MAX_STATUS) { | |
| 977 | 977 | printf("ERROR Too many coils status requested (%d > %d)\n", |
| 978 | - count, MAX_STATUS); | |
| 978 | + nb, MAX_STATUS); | |
| 979 | 979 | return TOO_MANY_DATA; |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | status = read_io_status(mb_param, slave, FC_READ_COIL_STATUS, |
| 983 | - start_addr, count, data_dest); | |
| 983 | + start_addr, nb, data_dest); | |
| 984 | 984 | |
| 985 | 985 | if (status > 0) |
| 986 | - status = count; | |
| 986 | + status = nb; | |
| 987 | 987 | |
| 988 | 988 | return status; |
| 989 | 989 | } |
| ... | ... | @@ -991,42 +991,42 @@ int read_coil_status(modbus_param_t *mb_param, int slave, int start_addr, |
| 991 | 991 | |
| 992 | 992 | /* Same as read_coil_status but reads the slaves input table */ |
| 993 | 993 | int read_input_status(modbus_param_t *mb_param, int slave, int start_addr, |
| 994 | - int count, uint8_t *data_dest) | |
| 994 | + int nb, uint8_t *data_dest) | |
| 995 | 995 | { |
| 996 | 996 | int status; |
| 997 | 997 | |
| 998 | - if (count > MAX_STATUS) { | |
| 999 | - printf("ERROR Too many inputs status requested (%d > %d)\n", | |
| 1000 | - count, MAX_STATUS); | |
| 998 | + if (nb > MAX_STATUS) { | |
| 999 | + printf("ERROR Too many input status requested (%d > %d)\n", | |
| 1000 | + nb, MAX_STATUS); | |
| 1001 | 1001 | return TOO_MANY_DATA; |
| 1002 | 1002 | } |
| 1003 | 1003 | |
| 1004 | 1004 | status = read_io_status(mb_param, slave, FC_READ_INPUT_STATUS, |
| 1005 | - start_addr, count, data_dest); | |
| 1005 | + start_addr, nb, data_dest); | |
| 1006 | 1006 | |
| 1007 | 1007 | if (status > 0) |
| 1008 | - status = count; | |
| 1008 | + status = nb; | |
| 1009 | 1009 | |
| 1010 | 1010 | return status; |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | /* Reads the data from a modbus slave and put that data into an array */ |
| 1014 | 1014 | static int read_registers(modbus_param_t *mb_param, int slave, int function, |
| 1015 | - int start_addr, int count, uint16_t *data_dest) | |
| 1015 | + int start_addr, int nb, uint16_t *data_dest) | |
| 1016 | 1016 | { |
| 1017 | 1017 | int query_length; |
| 1018 | 1018 | int status; |
| 1019 | 1019 | int query_ret; |
| 1020 | 1020 | uint8_t query[MIN_QUERY_LENGTH]; |
| 1021 | 1021 | |
| 1022 | - if (count > MAX_REGISTERS) { | |
| 1022 | + if (nb > MAX_REGISTERS) { | |
| 1023 | 1023 | printf("EROOR Too many holding registers requested (%d > %d)\n", |
| 1024 | - count, MAX_REGISTERS); | |
| 1024 | + nb, MAX_REGISTERS); | |
| 1025 | 1025 | return TOO_MANY_DATA; |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | query_length = build_query_basis(mb_param, slave, function, |
| 1029 | - start_addr, count, query); | |
| 1029 | + start_addr, nb, query); | |
| 1030 | 1030 | |
| 1031 | 1031 | query_ret = modbus_send(mb_param, query, query_length); |
| 1032 | 1032 | if (query_ret > 0) |
| ... | ... | @@ -1040,36 +1040,36 @@ static int read_registers(modbus_param_t *mb_param, int slave, int function, |
| 1040 | 1040 | /* Reads the holding registers in a slave and put the data into an |
| 1041 | 1041 | array */ |
| 1042 | 1042 | int read_holding_registers(modbus_param_t *mb_param, int slave, |
| 1043 | - int start_addr, int count, uint16_t *data_dest) | |
| 1043 | + int start_addr, int nb, uint16_t *data_dest) | |
| 1044 | 1044 | { |
| 1045 | 1045 | int status; |
| 1046 | 1046 | |
| 1047 | - if (count > MAX_REGISTERS) { | |
| 1047 | + if (nb > MAX_REGISTERS) { | |
| 1048 | 1048 | printf("ERROR Too many holding registers requested (%d > %d)\n", |
| 1049 | - count, MAX_REGISTERS); | |
| 1049 | + nb, MAX_REGISTERS); | |
| 1050 | 1050 | return TOO_MANY_DATA; |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | status = read_registers(mb_param, slave, FC_READ_HOLDING_REGISTERS, |
| 1054 | - start_addr, count, data_dest); | |
| 1054 | + start_addr, nb, data_dest); | |
| 1055 | 1055 | return status; |
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | /* Reads the input registers in a slave and put the data into |
| 1059 | 1059 | an array */ |
| 1060 | 1060 | int read_input_registers(modbus_param_t *mb_param, int slave, |
| 1061 | - int start_addr, int count, uint16_t *data_dest) | |
| 1061 | + int start_addr, int nb, uint16_t *data_dest) | |
| 1062 | 1062 | { |
| 1063 | 1063 | int status; |
| 1064 | 1064 | |
| 1065 | - if (count > MAX_REGISTERS) { | |
| 1065 | + if (nb > MAX_REGISTERS) { | |
| 1066 | 1066 | printf("ERROR Too many input registers requested (%d > %d)\n", |
| 1067 | - count, MAX_REGISTERS); | |
| 1067 | + nb, MAX_REGISTERS); | |
| 1068 | 1068 | return TOO_MANY_DATA; |
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | status = read_registers(mb_param, slave, FC_READ_INPUT_REGISTERS, |
| 1072 | - start_addr, count, data_dest); | |
| 1072 | + start_addr, nb, data_dest); | |
| 1073 | 1073 | |
| 1074 | 1074 | return status; |
| 1075 | 1075 | } |
| ... | ... | @@ -1160,7 +1160,7 @@ int preset_single_register(modbus_param_t *mb_param, int slave, |
| 1160 | 1160 | |
| 1161 | 1161 | /* Sets/resets the coils in the slave from an array in argument */ |
| 1162 | 1162 | int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1163 | - int start_addr, int nb_points, | |
| 1163 | + int start_addr, int nb, | |
| 1164 | 1164 | uint8_t *data_src) |
| 1165 | 1165 | { |
| 1166 | 1166 | int i; |
| ... | ... | @@ -1173,16 +1173,16 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1173 | 1173 | |
| 1174 | 1174 | uint8_t query[MAX_MESSAGE_LENGTH]; |
| 1175 | 1175 | |
| 1176 | - if (nb_points > MAX_STATUS) { | |
| 1176 | + if (nb > MAX_STATUS) { | |
| 1177 | 1177 | printf("ERROR Writing to too many coils (%d > %d)\n", |
| 1178 | - nb_points, MAX_STATUS); | |
| 1178 | + nb, MAX_STATUS); | |
| 1179 | 1179 | return TOO_MANY_DATA; |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | query_length = build_query_basis(mb_param, slave, |
| 1183 | 1183 | FC_FORCE_MULTIPLE_COILS, |
| 1184 | - start_addr, nb_points, query); | |
| 1185 | - byte_count = (nb_points / 8) + ((nb_points % 8) ? 1 : 0); | |
| 1184 | + start_addr, nb, query); | |
| 1185 | + byte_count = (nb / 8) + ((nb % 8) ? 1 : 0); | |
| 1186 | 1186 | query[query_length++] = byte_count; |
| 1187 | 1187 | |
| 1188 | 1188 | for (i = 0; i < byte_count; i++) { |
| ... | ... | @@ -1191,7 +1191,7 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1191 | 1191 | bit = 0x01; |
| 1192 | 1192 | query[query_length] = 0; |
| 1193 | 1193 | |
| 1194 | - while ((bit & 0xFF) && (coil_check++ < nb_points)) { | |
| 1194 | + while ((bit & 0xFF) && (coil_check++ < nb)) { | |
| 1195 | 1195 | if (data_src[pos++]) |
| 1196 | 1196 | query[query_length] |= bit; |
| 1197 | 1197 | else |
| ... | ... | @@ -1213,7 +1213,7 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1213 | 1213 | |
| 1214 | 1214 | /* Copies the values in the slave from the array given in argument */ |
| 1215 | 1215 | int preset_multiple_registers(modbus_param_t *mb_param, int slave, |
| 1216 | - int start_addr, int nb_points, uint16_t *data_src) | |
| 1216 | + int start_addr, int nb, uint16_t *data_src) | |
| 1217 | 1217 | { |
| 1218 | 1218 | int i; |
| 1219 | 1219 | int query_length; |
| ... | ... | @@ -1223,19 +1223,19 @@ int preset_multiple_registers(modbus_param_t *mb_param, int slave, |
| 1223 | 1223 | |
| 1224 | 1224 | uint8_t query[MAX_MESSAGE_LENGTH]; |
| 1225 | 1225 | |
| 1226 | - if (nb_points > MAX_REGISTERS) { | |
| 1226 | + if (nb > MAX_REGISTERS) { | |
| 1227 | 1227 | printf("ERROR Trying to write to too many registers (%d > %d)\n", |
| 1228 | - nb_points, MAX_REGISTERS); | |
| 1228 | + nb, MAX_REGISTERS); | |
| 1229 | 1229 | return TOO_MANY_DATA; |
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | query_length = build_query_basis(mb_param, slave, |
| 1233 | 1233 | FC_PRESET_MULTIPLE_REGISTERS, |
| 1234 | - start_addr, nb_points, query); | |
| 1235 | - byte_count = nb_points * 2; | |
| 1234 | + start_addr, nb, query); | |
| 1235 | + byte_count = nb * 2; | |
| 1236 | 1236 | query[query_length++] = byte_count; |
| 1237 | 1237 | |
| 1238 | - for (i = 0; i < nb_points; i++) { | |
| 1238 | + for (i = 0; i < nb; i++) { | |
| 1239 | 1239 | query[query_length++] = data_src[i] >> 8; |
| 1240 | 1240 | query[query_length++] = data_src[i] & 0x00FF; |
| 1241 | 1241 | } |
| ... | ... | @@ -1827,8 +1827,8 @@ int modbus_init_listen_tcp(modbus_param_t *mb_param) |
| 1827 | 1827 | |
| 1828 | 1828 | /** Utils **/ |
| 1829 | 1829 | |
| 1830 | -/* Sets many inputs/coils from a single byte value (all 8 bits of the | |
| 1831 | - byte value are setted) */ | |
| 1830 | +/* Sets many input/coil status from a single byte value (all 8 bits of | |
| 1831 | + the byte value are setted) */ | |
| 1832 | 1832 | void set_bits_from_byte(uint8_t *dest, int address, const uint8_t value) |
| 1833 | 1833 | { |
| 1834 | 1834 | int i; |
| ... | ... | @@ -1838,15 +1838,15 @@ void set_bits_from_byte(uint8_t *dest, int address, const uint8_t value) |
| 1838 | 1838 | } |
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | -/* Sets many inputs/coils from a table of bytes (only the bits between | |
| 1842 | - address and address + nb_points are setted) */ | |
| 1843 | -void set_bits_from_bytes(uint8_t *dest, int address, int nb_points, | |
| 1841 | +/* Sets many input/coil status from a table of bytes (only the bits | |
| 1842 | + between address and address + nb_bits are setted) */ | |
| 1843 | +void set_bits_from_bytes(uint8_t *dest, int address, int nb_bits, | |
| 1844 | 1844 | const uint8_t tab_byte[]) |
| 1845 | 1845 | { |
| 1846 | 1846 | int i; |
| 1847 | 1847 | int shift = 0; |
| 1848 | 1848 | |
| 1849 | - for (i=address; i < address + nb_points; i++) { | |
| 1849 | + for (i = address; i < address + nb_bits; i++) { | |
| 1850 | 1850 | dest[i] = tab_byte[(i - address) / 8] & (1 << shift) ? ON : OFF; |
| 1851 | 1851 | /* gcc doesn't like: shift = (++shift) % 8; */ |
| 1852 | 1852 | shift++; |
| ... | ... | @@ -1854,8 +1854,8 @@ void set_bits_from_bytes(uint8_t *dest, int address, int nb_points, |
| 1854 | 1854 | } |
| 1855 | 1855 | } |
| 1856 | 1856 | |
| 1857 | -/* Gets the byte value from many inputs/coils. | |
| 1858 | - To obtain a full byte, set nb_points to 8. */ | |
| 1857 | +/* Gets the byte value from many input/coil status. | |
| 1858 | + To obtain a full byte, set nb_bits to 8. */ | |
| 1859 | 1859 | uint8_t get_byte_from_bits(const uint8_t *src, int address, int nb_bits) |
| 1860 | 1860 | { |
| 1861 | 1861 | int i; |
| ... | ... | @@ -1866,7 +1866,7 @@ uint8_t get_byte_from_bits(const uint8_t *src, int address, int nb_bits) |
| 1866 | 1866 | nb_bits = 8; |
| 1867 | 1867 | } |
| 1868 | 1868 | |
| 1869 | - for (i=0; i<nb_bits; i++) { | |
| 1869 | + for (i=0; i < nb_bits; i++) { | |
| 1870 | 1870 | value |= (src[address+i] << i); |
| 1871 | 1871 | } |
| 1872 | 1872 | ... | ... |
modbus/modbus.h
| ... | ... | @@ -171,21 +171,21 @@ typedef struct { |
| 171 | 171 | /* Reads the boolean status of coils and sets the array elements in |
| 172 | 172 | the destination to TRUE or FALSE */ |
| 173 | 173 | int read_coil_status(modbus_param_t *mb_param, int slave, |
| 174 | - int start_addr, int count, uint8_t *dest); | |
| 174 | + int start_addr, int nb, uint8_t *dest); | |
| 175 | 175 | |
| 176 | 176 | /* Same as read_coil_status but reads the slaves input table */ |
| 177 | 177 | int read_input_status(modbus_param_t *mb_param, int slave, |
| 178 | - int start_addr, int count, uint8_t *dest); | |
| 178 | + int start_addr, int nb, uint8_t *dest); | |
| 179 | 179 | |
| 180 | 180 | /* Reads the holding registers in a slave and put the data into an |
| 181 | 181 | array */ |
| 182 | 182 | int read_holding_registers(modbus_param_t *mb_param, int slave, |
| 183 | - int start_addr, int count, uint16_t *dest); | |
| 183 | + int start_addr, int nb, uint16_t *dest); | |
| 184 | 184 | |
| 185 | 185 | /* Reads the input registers in a slave and put the data into an |
| 186 | 186 | array */ |
| 187 | 187 | int read_input_registers(modbus_param_t *mb_param, int slave, |
| 188 | - int start_addr, int count, uint16_t *dest); | |
| 188 | + int start_addr, int nb, uint16_t *dest); | |
| 189 | 189 | |
| 190 | 190 | /* Turns ON or OFF a single coil in the slave device */ |
| 191 | 191 | int force_single_coil(modbus_param_t *mb_param, int slave, |
| ... | ... | @@ -197,11 +197,11 @@ int preset_single_register(modbus_param_t *mb_param, int slave, |
| 197 | 197 | |
| 198 | 198 | /* Sets/resets the coils in the slave from an array in argument */ |
| 199 | 199 | int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 200 | - int start_addr, int nb_points, uint8_t *data); | |
| 200 | + int start_addr, int nb, uint8_t *data); | |
| 201 | 201 | |
| 202 | 202 | /* Copies the values in the slave from the array given in argument */ |
| 203 | 203 | int preset_multiple_registers(modbus_param_t *mb_param, int slave, |
| 204 | - int start_addr, int nb_points, uint16_t *data); | |
| 204 | + int start_addr, int nb, uint16_t *data); | |
| 205 | 205 | |
| 206 | 206 | /* Returns the slave id! */ |
| 207 | 207 | int report_slave_id(modbus_param_t *mb_param, int slave, uint8_t *dest); |
| ... | ... | @@ -289,16 +289,16 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query, |
| 289 | 289 | * UTILS FUNCTIONS |
| 290 | 290 | **/ |
| 291 | 291 | |
| 292 | -/* Sets many inputs/coils from a single byte value (all 8 bits of the | |
| 293 | - byte value are setted) */ | |
| 292 | +/* Sets many input/coil status from a single byte value (all 8 bits of | |
| 293 | + the byte value are setted) */ | |
| 294 | 294 | void set_bits_from_byte(uint8_t *dest, int address, const uint8_t value); |
| 295 | 295 | |
| 296 | -/* Sets many inputs/coils from a table of bytes (only the bits between | |
| 297 | - address and address + nb_bits are setted) */ | |
| 296 | +/* Sets many input/coil status from a table of bytes (only the bits | |
| 297 | + between address and address + nb_bits are setted) */ | |
| 298 | 298 | void set_bits_from_bytes(uint8_t *dest, int address, int nb_bits, |
| 299 | 299 | const uint8_t *tab_byte); |
| 300 | 300 | |
| 301 | -/* Gets the byte value from many inputs/coils. | |
| 301 | +/* Gets the byte value from many input/coil status. | |
| 302 | 302 | To obtain a full byte, set nb_bits to 8. */ |
| 303 | 303 | uint8_t get_byte_from_bits(const uint8_t *src, int address, int nb_bits); |
| 304 | 304 | ... | ... |