Commit f5cd596264b0ca1015eae5eee75f17527a96f1aa
1 parent
7b320fa2
Cleanup reg_count, coil_count -> nb_points
Showing
3 changed files
with
16 additions
and
17 deletions
TODO
| ... | ... | @@ -10,7 +10,6 @@ Cleanups |
| 10 | 10 | * split modbus.c (tcp/rtu, query/response) |
| 11 | 11 | * t_id in param_msqg |
| 12 | 12 | * only one build_header_message function to replace build_query_packet/response_packet |
| 13 | -* reg_count, coil_count -> nb_points | |
| 14 | 13 | * avoid copies (use ptr) |
| 15 | 14 | |
| 16 | 15 | Documentation | ... | ... |
modbus/modbus.c
| ... | ... | @@ -168,9 +168,9 @@ static unsigned int compute_response_size(modbus_param_t *mb_param, |
| 168 | 168 | case FC_READ_COIL_STATUS: |
| 169 | 169 | case FC_READ_INPUT_STATUS: { |
| 170 | 170 | /* Header + nb values (code from force_multiple_coils) */ |
| 171 | - int coil_count = (query[offset + 4] << 8) | query[offset + 5]; | |
| 171 | + int nb_points = (query[offset + 4] << 8) | query[offset + 5]; | |
| 172 | 172 | response_size_computed = 3 + |
| 173 | - (coil_count / 8) + ((coil_count % 8) ? 1 : 0); | |
| 173 | + (nb_points / 8) + ((nb_points % 8) ? 1 : 0); | |
| 174 | 174 | } |
| 175 | 175 | break; |
| 176 | 176 | case FC_READ_HOLDING_REGISTERS: |
| ... | ... | @@ -1124,7 +1124,7 @@ int preset_single_register(modbus_param_t *mb_param, int slave, |
| 1124 | 1124 | |
| 1125 | 1125 | /* Sets/resets the coils in the slave from an array in argument */ |
| 1126 | 1126 | int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1127 | - int start_addr, int coil_count, | |
| 1127 | + int start_addr, int nb_points, | |
| 1128 | 1128 | uint8_t *data_src) |
| 1129 | 1129 | { |
| 1130 | 1130 | int i; |
| ... | ... | @@ -1137,14 +1137,14 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1137 | 1137 | |
| 1138 | 1138 | uint8_t query[MAX_PACKET_SIZE]; |
| 1139 | 1139 | |
| 1140 | - if (coil_count > MAX_WRITE_COILS) { | |
| 1140 | + if (nb_points > MAX_WRITE_COILS) { | |
| 1141 | 1141 | printf("WARNING Writing to too many coils\n"); |
| 1142 | - coil_count = MAX_WRITE_COILS; | |
| 1142 | + nb_points = MAX_WRITE_COILS; | |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | query_size = build_query_basis(mb_param, slave, FC_FORCE_MULTIPLE_COILS, |
| 1146 | - start_addr, coil_count, query); | |
| 1147 | - byte_count = (coil_count / 8) + ((coil_count % 8) ? 1 : 0); | |
| 1146 | + start_addr, nb_points, query); | |
| 1147 | + byte_count = (nb_points / 8) + ((nb_points % 8) ? 1 : 0); | |
| 1148 | 1148 | query[query_size++] = byte_count; |
| 1149 | 1149 | |
| 1150 | 1150 | for (i = 0; i < byte_count; i++) { |
| ... | ... | @@ -1153,7 +1153,7 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1153 | 1153 | bit = 0x01; |
| 1154 | 1154 | query[query_size] = 0; |
| 1155 | 1155 | |
| 1156 | - while ((bit & 0xFF) && (coil_check++ < coil_count)) { | |
| 1156 | + while ((bit & 0xFF) && (coil_check++ < nb_points)) { | |
| 1157 | 1157 | if (data_src[pos++]) |
| 1158 | 1158 | query[query_size] |= bit; |
| 1159 | 1159 | else |
| ... | ... | @@ -1175,7 +1175,7 @@ int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 1175 | 1175 | |
| 1176 | 1176 | /* Copies the values in the slave from the array given in argument */ |
| 1177 | 1177 | int preset_multiple_registers(modbus_param_t *mb_param, int slave, |
| 1178 | - int start_addr, int reg_count, uint16_t *data_src) | |
| 1178 | + int start_addr, int nb_points, uint16_t *data_src) | |
| 1179 | 1179 | { |
| 1180 | 1180 | int i; |
| 1181 | 1181 | int query_size; |
| ... | ... | @@ -1185,18 +1185,18 @@ int preset_multiple_registers(modbus_param_t *mb_param, int slave, |
| 1185 | 1185 | |
| 1186 | 1186 | uint8_t query[MAX_PACKET_SIZE]; |
| 1187 | 1187 | |
| 1188 | - if (reg_count > MAX_WRITE_REGS) { | |
| 1188 | + if (nb_points > MAX_WRITE_REGS) { | |
| 1189 | 1189 | printf("WARNING Trying to write to too many registers\n"); |
| 1190 | - reg_count = MAX_WRITE_REGS; | |
| 1190 | + nb_points = MAX_WRITE_REGS; | |
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | query_size = build_query_basis(mb_param, slave, |
| 1194 | 1194 | FC_PRESET_MULTIPLE_REGISTERS, |
| 1195 | - start_addr, reg_count, query); | |
| 1196 | - byte_count = reg_count * 2; | |
| 1195 | + start_addr, nb_points, query); | |
| 1196 | + byte_count = nb_points * 2; | |
| 1197 | 1197 | query[query_size++] = byte_count; |
| 1198 | 1198 | |
| 1199 | - for (i = 0; i < reg_count; i++) { | |
| 1199 | + for (i = 0; i < nb_points; i++) { | |
| 1200 | 1200 | query[query_size++] = data_src[i] >> 8; |
| 1201 | 1201 | query[query_size++] = data_src[i] & 0x00FF; |
| 1202 | 1202 | } | ... | ... |
modbus/modbus.h
| ... | ... | @@ -201,11 +201,11 @@ int preset_single_register(modbus_param_t *mb_param, int slave, |
| 201 | 201 | |
| 202 | 202 | /* Sets/resets the coils in the slave from an array in argument */ |
| 203 | 203 | int force_multiple_coils(modbus_param_t *mb_param, int slave, |
| 204 | - int start_addr, int coil_count, uint8_t *data); | |
| 204 | + int start_addr, int nb_points, uint8_t *data); | |
| 205 | 205 | |
| 206 | 206 | /* Copies the values in the slave from the array given in argument */ |
| 207 | 207 | int preset_multiple_registers(modbus_param_t *mb_param, int slave, |
| 208 | - int start_addr, int reg_count, uint16_t *data); | |
| 208 | + int start_addr, int nb_points, uint16_t *data); | |
| 209 | 209 | |
| 210 | 210 | /* Returns the slave id! */ |
| 211 | 211 | int report_slave_id(modbus_param_t *mb_param, int slave, uint8_t *dest); | ... | ... |