Commit f2f42c01a963b9434748babaa03ca6482c805d05
1 parent
67f8d030
Shorter names for constants which hold the number of values in UT
Showing
3 changed files
with
65 additions
and
89 deletions
tests/unit-test-client.c
| @@ -87,15 +87,13 @@ int main(int argc, char *argv[]) | @@ -87,15 +87,13 @@ int main(int argc, char *argv[]) | ||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | /* Allocate and initialize the memory to store the bits */ | 89 | /* Allocate and initialize the memory to store the bits */ |
| 90 | - nb_points = (UT_BITS_NB_POINTS > UT_INPUT_BITS_NB_POINTS) ? | ||
| 91 | - UT_BITS_NB_POINTS : UT_INPUT_BITS_NB_POINTS; | 90 | + nb_points = (UT_BITS_NB > UT_INPUT_BITS_NB) ? UT_BITS_NB : UT_INPUT_BITS_NB; |
| 92 | tab_rp_bits = (uint8_t *) malloc(nb_points * sizeof(uint8_t)); | 91 | tab_rp_bits = (uint8_t *) malloc(nb_points * sizeof(uint8_t)); |
| 93 | memset(tab_rp_bits, 0, nb_points * sizeof(uint8_t)); | 92 | memset(tab_rp_bits, 0, nb_points * sizeof(uint8_t)); |
| 94 | 93 | ||
| 95 | /* Allocate and initialize the memory to store the registers */ | 94 | /* Allocate and initialize the memory to store the registers */ |
| 96 | - nb_points = (UT_REGISTERS_NB_POINTS > | ||
| 97 | - UT_INPUT_REGISTERS_NB_POINTS) ? | ||
| 98 | - UT_REGISTERS_NB_POINTS : UT_INPUT_REGISTERS_NB_POINTS; | 95 | + nb_points = (UT_REGISTERS_NB > UT_INPUT_REGISTERS_NB) ? |
| 96 | + UT_REGISTERS_NB : UT_INPUT_REGISTERS_NB; | ||
| 99 | tab_rp_registers = (uint16_t *) malloc(nb_points * sizeof(uint16_t)); | 97 | tab_rp_registers = (uint16_t *) malloc(nb_points * sizeof(uint16_t)); |
| 100 | memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t)); | 98 | memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t)); |
| 101 | 99 | ||
| @@ -131,14 +129,13 @@ int main(int argc, char *argv[]) | @@ -131,14 +129,13 @@ int main(int argc, char *argv[]) | ||
| 131 | 129 | ||
| 132 | /* Multiple bits */ | 130 | /* Multiple bits */ |
| 133 | { | 131 | { |
| 134 | - uint8_t tab_value[UT_BITS_NB_POINTS]; | 132 | + uint8_t tab_value[UT_BITS_NB]; |
| 135 | 133 | ||
| 136 | - modbus_set_bits_from_bytes(tab_value, 0, UT_BITS_NB_POINTS, | ||
| 137 | - UT_BITS_TAB); | 134 | + modbus_set_bits_from_bytes(tab_value, 0, UT_BITS_NB, UT_BITS_TAB); |
| 138 | rc = modbus_write_bits(ctx, UT_BITS_ADDRESS, | 135 | rc = modbus_write_bits(ctx, UT_BITS_ADDRESS, |
| 139 | - UT_BITS_NB_POINTS, tab_value); | 136 | + UT_BITS_NB, tab_value); |
| 140 | printf("1/2 modbus_write_bits: "); | 137 | printf("1/2 modbus_write_bits: "); |
| 141 | - if (rc == UT_BITS_NB_POINTS) { | 138 | + if (rc == UT_BITS_NB) { |
| 142 | printf("OK\n"); | 139 | printf("OK\n"); |
| 143 | } else { | 140 | } else { |
| 144 | printf("FAILED\n"); | 141 | printf("FAILED\n"); |
| @@ -146,24 +143,22 @@ int main(int argc, char *argv[]) | @@ -146,24 +143,22 @@ int main(int argc, char *argv[]) | ||
| 146 | } | 143 | } |
| 147 | } | 144 | } |
| 148 | 145 | ||
| 149 | - rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, | ||
| 150 | - UT_BITS_NB_POINTS, tab_rp_bits); | 146 | + rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, UT_BITS_NB, tab_rp_bits); |
| 151 | printf("2/2 modbus_read_bits: "); | 147 | printf("2/2 modbus_read_bits: "); |
| 152 | - if (rc != UT_BITS_NB_POINTS) { | 148 | + if (rc != UT_BITS_NB) { |
| 153 | printf("FAILED (nb points %d)\n", rc); | 149 | printf("FAILED (nb points %d)\n", rc); |
| 154 | goto close; | 150 | goto close; |
| 155 | } | 151 | } |
| 156 | 152 | ||
| 157 | i = 0; | 153 | i = 0; |
| 158 | address = UT_BITS_ADDRESS; | 154 | address = UT_BITS_ADDRESS; |
| 159 | - nb_points = UT_BITS_NB_POINTS; | 155 | + nb_points = UT_BITS_NB; |
| 160 | while (nb_points > 0) { | 156 | while (nb_points > 0) { |
| 161 | int nb_bits = (nb_points > 8) ? 8 : nb_points; | 157 | int nb_bits = (nb_points > 8) ? 8 : nb_points; |
| 162 | 158 | ||
| 163 | value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits); | 159 | value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits); |
| 164 | if (value != UT_BITS_TAB[i]) { | 160 | if (value != UT_BITS_TAB[i]) { |
| 165 | - printf("FAILED (%0X != %0X)\n", | ||
| 166 | - value, UT_BITS_TAB[i]); | 161 | + printf("FAILED (%0X != %0X)\n", value, UT_BITS_TAB[i]); |
| 167 | goto close; | 162 | goto close; |
| 168 | } | 163 | } |
| 169 | 164 | ||
| @@ -175,24 +170,23 @@ int main(int argc, char *argv[]) | @@ -175,24 +170,23 @@ int main(int argc, char *argv[]) | ||
| 175 | 170 | ||
| 176 | /** DISCRETE INPUTS **/ | 171 | /** DISCRETE INPUTS **/ |
| 177 | rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, | 172 | rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, |
| 178 | - UT_INPUT_BITS_NB_POINTS, tab_rp_bits); | 173 | + UT_INPUT_BITS_NB, tab_rp_bits); |
| 179 | printf("1/1 modbus_read_input_bits: "); | 174 | printf("1/1 modbus_read_input_bits: "); |
| 180 | 175 | ||
| 181 | - if (rc != UT_INPUT_BITS_NB_POINTS) { | 176 | + if (rc != UT_INPUT_BITS_NB) { |
| 182 | printf("FAILED (nb points %d)\n", rc); | 177 | printf("FAILED (nb points %d)\n", rc); |
| 183 | goto close; | 178 | goto close; |
| 184 | } | 179 | } |
| 185 | 180 | ||
| 186 | i = 0; | 181 | i = 0; |
| 187 | address = UT_INPUT_BITS_ADDRESS; | 182 | address = UT_INPUT_BITS_ADDRESS; |
| 188 | - nb_points = UT_INPUT_BITS_NB_POINTS; | 183 | + nb_points = UT_INPUT_BITS_NB; |
| 189 | while (nb_points > 0) { | 184 | while (nb_points > 0) { |
| 190 | int nb_bits = (nb_points > 8) ? 8 : nb_points; | 185 | int nb_bits = (nb_points > 8) ? 8 : nb_points; |
| 191 | 186 | ||
| 192 | value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits); | 187 | value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits); |
| 193 | if (value != UT_INPUT_BITS_TAB[i]) { | 188 | if (value != UT_INPUT_BITS_TAB[i]) { |
| 194 | - printf("FAILED (%0X != %0X)\n", | ||
| 195 | - value, UT_INPUT_BITS_TAB[i]); | 189 | + printf("FAILED (%0X != %0X)\n", value, UT_INPUT_BITS_TAB[i]); |
| 196 | goto close; | 190 | goto close; |
| 197 | } | 191 | } |
| 198 | 192 | ||
| @@ -231,10 +225,9 @@ int main(int argc, char *argv[]) | @@ -231,10 +225,9 @@ int main(int argc, char *argv[]) | ||
| 231 | 225 | ||
| 232 | /* Many registers */ | 226 | /* Many registers */ |
| 233 | rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS, | 227 | rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS, |
| 234 | - UT_REGISTERS_NB_POINTS, | ||
| 235 | - UT_REGISTERS_TAB); | 228 | + UT_REGISTERS_NB, UT_REGISTERS_TAB); |
| 236 | printf("1/5 modbus_write_registers: "); | 229 | printf("1/5 modbus_write_registers: "); |
| 237 | - if (rc == UT_REGISTERS_NB_POINTS) { | 230 | + if (rc == UT_REGISTERS_NB) { |
| 238 | printf("OK\n"); | 231 | printf("OK\n"); |
| 239 | } else { | 232 | } else { |
| 240 | printf("FAILED\n"); | 233 | printf("FAILED\n"); |
| @@ -242,15 +235,14 @@ int main(int argc, char *argv[]) | @@ -242,15 +235,14 @@ int main(int argc, char *argv[]) | ||
| 242 | } | 235 | } |
| 243 | 236 | ||
| 244 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, | 237 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, |
| 245 | - UT_REGISTERS_NB_POINTS, | ||
| 246 | - tab_rp_registers); | 238 | + UT_REGISTERS_NB, tab_rp_registers); |
| 247 | printf("2/5 modbus_read_registers: "); | 239 | printf("2/5 modbus_read_registers: "); |
| 248 | - if (rc != UT_REGISTERS_NB_POINTS) { | 240 | + if (rc != UT_REGISTERS_NB) { |
| 249 | printf("FAILED (nb points %d)\n", rc); | 241 | printf("FAILED (nb points %d)\n", rc); |
| 250 | goto close; | 242 | goto close; |
| 251 | } | 243 | } |
| 252 | 244 | ||
| 253 | - for (i=0; i < UT_REGISTERS_NB_POINTS; i++) { | 245 | + for (i=0; i < UT_REGISTERS_NB; i++) { |
| 254 | if (tab_rp_registers[i] != UT_REGISTERS_TAB[i]) { | 246 | if (tab_rp_registers[i] != UT_REGISTERS_TAB[i]) { |
| 255 | printf("FAILED (%0X != %0X)\n", | 247 | printf("FAILED (%0X != %0X)\n", |
| 256 | tab_rp_registers[i], | 248 | tab_rp_registers[i], |
| @@ -269,24 +261,23 @@ int main(int argc, char *argv[]) | @@ -269,24 +261,23 @@ int main(int argc, char *argv[]) | ||
| 269 | } | 261 | } |
| 270 | printf("OK\n"); | 262 | printf("OK\n"); |
| 271 | 263 | ||
| 272 | - nb_points = (UT_REGISTERS_NB_POINTS > | ||
| 273 | - UT_INPUT_REGISTERS_NB_POINTS) ? | ||
| 274 | - UT_REGISTERS_NB_POINTS : UT_INPUT_REGISTERS_NB_POINTS; | 264 | + nb_points = (UT_REGISTERS_NB > |
| 265 | + UT_INPUT_REGISTERS_NB) ? | ||
| 266 | + UT_REGISTERS_NB : UT_INPUT_REGISTERS_NB; | ||
| 275 | memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t)); | 267 | memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t)); |
| 276 | 268 | ||
| 277 | /* Write registers to zero from tab_rp_registers and store read registers | 269 | /* Write registers to zero from tab_rp_registers and store read registers |
| 278 | into tab_rp_registers. So the read registers must set to 0, except the | 270 | into tab_rp_registers. So the read registers must set to 0, except the |
| 279 | first one because there is an offset of 1 register on write. */ | 271 | first one because there is an offset of 1 register on write. */ |
| 280 | rc = modbus_read_and_write_registers(ctx, | 272 | rc = modbus_read_and_write_registers(ctx, |
| 281 | - UT_REGISTERS_ADDRESS, | ||
| 282 | - UT_REGISTERS_NB_POINTS, | 273 | + UT_REGISTERS_ADDRESS, UT_REGISTERS_NB, |
| 283 | tab_rp_registers, | 274 | tab_rp_registers, |
| 284 | UT_REGISTERS_ADDRESS + 1, | 275 | UT_REGISTERS_ADDRESS + 1, |
| 285 | - UT_REGISTERS_NB_POINTS - 1, | 276 | + UT_REGISTERS_NB - 1, |
| 286 | tab_rp_registers); | 277 | tab_rp_registers); |
| 287 | printf("4/5 modbus_read_and_write_registers: "); | 278 | printf("4/5 modbus_read_and_write_registers: "); |
| 288 | - if (rc != UT_REGISTERS_NB_POINTS) { | ||
| 289 | - printf("FAILED (nb points %d != %d)\n", rc, UT_REGISTERS_NB_POINTS); | 279 | + if (rc != UT_REGISTERS_NB) { |
| 280 | + printf("FAILED (nb points %d != %d)\n", rc, UT_REGISTERS_NB); | ||
| 290 | goto close; | 281 | goto close; |
| 291 | } | 282 | } |
| 292 | 283 | ||
| @@ -295,7 +286,7 @@ int main(int argc, char *argv[]) | @@ -295,7 +286,7 @@ int main(int argc, char *argv[]) | ||
| 295 | tab_rp_registers[0], UT_REGISTERS_TAB[0]); | 286 | tab_rp_registers[0], UT_REGISTERS_TAB[0]); |
| 296 | } | 287 | } |
| 297 | 288 | ||
| 298 | - for (i=1; i < UT_REGISTERS_NB_POINTS; i++) { | 289 | + for (i=1; i < UT_REGISTERS_NB; i++) { |
| 299 | if (tab_rp_registers[i] != 0) { | 290 | if (tab_rp_registers[i] != 0) { |
| 300 | printf("FAILED (%0X != %0X)\n", | 291 | printf("FAILED (%0X != %0X)\n", |
| 301 | tab_rp_registers[i], 0); | 292 | tab_rp_registers[i], 0); |
| @@ -309,15 +300,14 @@ int main(int argc, char *argv[]) | @@ -309,15 +300,14 @@ int main(int argc, char *argv[]) | ||
| 309 | 300 | ||
| 310 | /** INPUT REGISTERS **/ | 301 | /** INPUT REGISTERS **/ |
| 311 | rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS, | 302 | rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS, |
| 312 | - UT_INPUT_REGISTERS_NB_POINTS, | ||
| 313 | - tab_rp_registers); | 303 | + UT_INPUT_REGISTERS_NB, tab_rp_registers); |
| 314 | printf("1/1 modbus_read_input_registers: "); | 304 | printf("1/1 modbus_read_input_registers: "); |
| 315 | - if (rc != UT_INPUT_REGISTERS_NB_POINTS) { | 305 | + if (rc != UT_INPUT_REGISTERS_NB) { |
| 316 | printf("FAILED (nb points %d)\n", rc); | 306 | printf("FAILED (nb points %d)\n", rc); |
| 317 | goto close; | 307 | goto close; |
| 318 | } | 308 | } |
| 319 | 309 | ||
| 320 | - for (i=0; i < UT_INPUT_REGISTERS_NB_POINTS; i++) { | 310 | + for (i=0; i < UT_INPUT_REGISTERS_NB; i++) { |
| 321 | if (tab_rp_registers[i] != UT_INPUT_REGISTERS_TAB[i]) { | 311 | if (tab_rp_registers[i] != UT_INPUT_REGISTERS_TAB[i]) { |
| 322 | printf("FAILED (%0X != %0X)\n", | 312 | printf("FAILED (%0X != %0X)\n", |
| 323 | tab_rp_registers[i], UT_INPUT_REGISTERS_TAB[i]); | 313 | tab_rp_registers[i], UT_INPUT_REGISTERS_TAB[i]); |
| @@ -357,8 +347,7 @@ int main(int argc, char *argv[]) | @@ -357,8 +347,7 @@ int main(int argc, char *argv[]) | ||
| 357 | * the addresses are not valid. */ | 347 | * the addresses are not valid. */ |
| 358 | 348 | ||
| 359 | rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, | 349 | rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, |
| 360 | - UT_BITS_NB_POINTS + 1, | ||
| 361 | - tab_rp_bits); | 350 | + UT_BITS_NB + 1, tab_rp_bits); |
| 362 | printf("* modbus_read_bits: "); | 351 | printf("* modbus_read_bits: "); |
| 363 | if (rc == -1 && errno == EMBXILADD) { | 352 | if (rc == -1 && errno == EMBXILADD) { |
| 364 | printf("OK\n"); | 353 | printf("OK\n"); |
| @@ -368,8 +357,7 @@ int main(int argc, char *argv[]) | @@ -368,8 +357,7 @@ int main(int argc, char *argv[]) | ||
| 368 | } | 357 | } |
| 369 | 358 | ||
| 370 | rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, | 359 | rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, |
| 371 | - UT_INPUT_BITS_NB_POINTS + 1, | ||
| 372 | - tab_rp_bits); | 360 | + UT_INPUT_BITS_NB + 1, tab_rp_bits); |
| 373 | printf("* modbus_read_input_bits: "); | 361 | printf("* modbus_read_input_bits: "); |
| 374 | if (rc == -1 && errno == EMBXILADD) | 362 | if (rc == -1 && errno == EMBXILADD) |
| 375 | printf("OK\n"); | 363 | printf("OK\n"); |
| @@ -379,8 +367,7 @@ int main(int argc, char *argv[]) | @@ -379,8 +367,7 @@ int main(int argc, char *argv[]) | ||
| 379 | } | 367 | } |
| 380 | 368 | ||
| 381 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, | 369 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, |
| 382 | - UT_REGISTERS_NB_POINTS + 1, | ||
| 383 | - tab_rp_registers); | 370 | + UT_REGISTERS_NB + 1, tab_rp_registers); |
| 384 | printf("* modbus_read_registers: "); | 371 | printf("* modbus_read_registers: "); |
| 385 | if (rc == -1 && errno == EMBXILADD) | 372 | if (rc == -1 && errno == EMBXILADD) |
| 386 | printf("OK\n"); | 373 | printf("OK\n"); |
| @@ -390,8 +377,7 @@ int main(int argc, char *argv[]) | @@ -390,8 +377,7 @@ int main(int argc, char *argv[]) | ||
| 390 | } | 377 | } |
| 391 | 378 | ||
| 392 | rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS, | 379 | rc = modbus_read_input_registers(ctx, UT_INPUT_REGISTERS_ADDRESS, |
| 393 | - UT_INPUT_REGISTERS_NB_POINTS + 1, | ||
| 394 | - tab_rp_registers); | 380 | + UT_INPUT_REGISTERS_NB + 1, tab_rp_registers); |
| 395 | printf("* modbus_read_input_registers: "); | 381 | printf("* modbus_read_input_registers: "); |
| 396 | if (rc == -1 && errno == EMBXILADD) | 382 | if (rc == -1 && errno == EMBXILADD) |
| 397 | printf("OK\n"); | 383 | printf("OK\n"); |
| @@ -400,7 +386,7 @@ int main(int argc, char *argv[]) | @@ -400,7 +386,7 @@ int main(int argc, char *argv[]) | ||
| 400 | goto close; | 386 | goto close; |
| 401 | } | 387 | } |
| 402 | 388 | ||
| 403 | - rc = modbus_write_bit(ctx, UT_BITS_ADDRESS + UT_BITS_NB_POINTS, ON); | 389 | + rc = modbus_write_bit(ctx, UT_BITS_ADDRESS + UT_BITS_NB, ON); |
| 404 | printf("* modbus_write_bit: "); | 390 | printf("* modbus_write_bit: "); |
| 405 | if (rc == -1 && errno == EMBXILADD) { | 391 | if (rc == -1 && errno == EMBXILADD) { |
| 406 | printf("OK\n"); | 392 | printf("OK\n"); |
| @@ -409,9 +395,8 @@ int main(int argc, char *argv[]) | @@ -409,9 +395,8 @@ int main(int argc, char *argv[]) | ||
| 409 | goto close; | 395 | goto close; |
| 410 | } | 396 | } |
| 411 | 397 | ||
| 412 | - rc = modbus_write_bits(ctx, UT_BITS_ADDRESS + UT_BITS_NB_POINTS, | ||
| 413 | - UT_BITS_NB_POINTS, | ||
| 414 | - tab_rp_bits); | 398 | + rc = modbus_write_bits(ctx, UT_BITS_ADDRESS + UT_BITS_NB, |
| 399 | + UT_BITS_NB, tab_rp_bits); | ||
| 415 | printf("* modbus_write_coils: "); | 400 | printf("* modbus_write_coils: "); |
| 416 | if (rc == -1 && errno == EMBXILADD) { | 401 | if (rc == -1 && errno == EMBXILADD) { |
| 417 | printf("OK\n"); | 402 | printf("OK\n"); |
| @@ -420,10 +405,8 @@ int main(int argc, char *argv[]) | @@ -420,10 +405,8 @@ int main(int argc, char *argv[]) | ||
| 420 | goto close; | 405 | goto close; |
| 421 | } | 406 | } |
| 422 | 407 | ||
| 423 | - rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS + | ||
| 424 | - UT_REGISTERS_NB_POINTS, | ||
| 425 | - UT_REGISTERS_NB_POINTS, | ||
| 426 | - tab_rp_registers); | 408 | + rc = modbus_write_registers(ctx, UT_REGISTERS_ADDRESS + UT_REGISTERS_NB, |
| 409 | + UT_REGISTERS_NB, tab_rp_registers); | ||
| 427 | printf("* modbus_write_registers: "); | 410 | printf("* modbus_write_registers: "); |
| 428 | if (rc == -1 && errno == EMBXILADD) { | 411 | if (rc == -1 && errno == EMBXILADD) { |
| 429 | printf("OK\n"); | 412 | printf("OK\n"); |
| @@ -436,8 +419,8 @@ int main(int argc, char *argv[]) | @@ -436,8 +419,8 @@ int main(int argc, char *argv[]) | ||
| 436 | /** TOO MANY DATA **/ | 419 | /** TOO MANY DATA **/ |
| 437 | printf("\nTEST TOO MANY DATA ERROR:\n"); | 420 | printf("\nTEST TOO MANY DATA ERROR:\n"); |
| 438 | 421 | ||
| 439 | - rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, MODBUS_MAX_READ_BITS + 1, | ||
| 440 | - tab_rp_bits); | 422 | + rc = modbus_read_bits(ctx, UT_BITS_ADDRESS, |
| 423 | + MODBUS_MAX_READ_BITS + 1, tab_rp_bits); | ||
| 441 | printf("* modbus_read_bits: "); | 424 | printf("* modbus_read_bits: "); |
| 442 | if (rc == -1 && errno == EMBMDATA) { | 425 | if (rc == -1 && errno == EMBMDATA) { |
| 443 | printf("OK\n"); | 426 | printf("OK\n"); |
| @@ -447,8 +430,7 @@ int main(int argc, char *argv[]) | @@ -447,8 +430,7 @@ int main(int argc, char *argv[]) | ||
| 447 | } | 430 | } |
| 448 | 431 | ||
| 449 | rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, | 432 | rc = modbus_read_input_bits(ctx, UT_INPUT_BITS_ADDRESS, |
| 450 | - MODBUS_MAX_READ_BITS + 1, | ||
| 451 | - tab_rp_bits); | 433 | + MODBUS_MAX_READ_BITS + 1, tab_rp_bits); |
| 452 | printf("* modbus_read_input_bits: "); | 434 | printf("* modbus_read_input_bits: "); |
| 453 | if (rc == -1 && errno == EMBMDATA) { | 435 | if (rc == -1 && errno == EMBMDATA) { |
| 454 | printf("OK\n"); | 436 | printf("OK\n"); |
| @@ -480,8 +462,7 @@ int main(int argc, char *argv[]) | @@ -480,8 +462,7 @@ int main(int argc, char *argv[]) | ||
| 480 | } | 462 | } |
| 481 | 463 | ||
| 482 | rc = modbus_write_bits(ctx, UT_BITS_ADDRESS, | 464 | rc = modbus_write_bits(ctx, UT_BITS_ADDRESS, |
| 483 | - MODBUS_MAX_WRITE_BITS + 1, | ||
| 484 | - tab_rp_bits); | 465 | + MODBUS_MAX_WRITE_BITS + 1, tab_rp_bits); |
| 485 | printf("* modbus_write_bits: "); | 466 | printf("* modbus_write_bits: "); |
| 486 | if (rc == -1 && errno == EMBMDATA) { | 467 | if (rc == -1 && errno == EMBMDATA) { |
| 487 | printf("OK\n"); | 468 | printf("OK\n"); |
| @@ -505,8 +486,7 @@ int main(int argc, char *argv[]) | @@ -505,8 +486,7 @@ int main(int argc, char *argv[]) | ||
| 505 | printf("\nTEST SLAVE REPLY:\n"); | 486 | printf("\nTEST SLAVE REPLY:\n"); |
| 506 | modbus_set_slave(ctx, 18); | 487 | modbus_set_slave(ctx, 18); |
| 507 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, | 488 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, |
| 508 | - UT_REGISTERS_NB_POINTS, | ||
| 509 | - tab_rp_registers); | 489 | + UT_REGISTERS_NB, tab_rp_registers); |
| 510 | if (use_backend == RTU) { | 490 | if (use_backend == RTU) { |
| 511 | /* No response in RTU mode */ | 491 | /* No response in RTU mode */ |
| 512 | printf("1/4 No response from slave %d: ", 18); | 492 | printf("1/4 No response from slave %d: ", 18); |
| @@ -521,7 +501,7 @@ int main(int argc, char *argv[]) | @@ -521,7 +501,7 @@ int main(int argc, char *argv[]) | ||
| 521 | /* Response in TCP mode */ | 501 | /* Response in TCP mode */ |
| 522 | printf("1/4 Response from slave %d: ", 18); | 502 | printf("1/4 Response from slave %d: ", 18); |
| 523 | 503 | ||
| 524 | - if (rc == UT_REGISTERS_NB_POINTS) { | 504 | + if (rc == UT_REGISTERS_NB) { |
| 525 | printf("OK\n"); | 505 | printf("OK\n"); |
| 526 | } else { | 506 | } else { |
| 527 | printf("FAILED\n"); | 507 | printf("FAILED\n"); |
| @@ -536,10 +516,9 @@ int main(int argc, char *argv[]) | @@ -536,10 +516,9 @@ int main(int argc, char *argv[]) | ||
| 536 | } | 516 | } |
| 537 | 517 | ||
| 538 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, | 518 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, |
| 539 | - UT_REGISTERS_NB_POINTS, | ||
| 540 | - tab_rp_registers); | 519 | + UT_REGISTERS_NB, tab_rp_registers); |
| 541 | printf("2/4 Reply after a broadcast query: "); | 520 | printf("2/4 Reply after a broadcast query: "); |
| 542 | - if (rc == UT_REGISTERS_NB_POINTS) { | 521 | + if (rc == UT_REGISTERS_NB) { |
| 543 | printf("OK\n"); | 522 | printf("OK\n"); |
| 544 | } else { | 523 | } else { |
| 545 | printf("FAILED\n"); | 524 | printf("FAILED\n"); |
| @@ -578,8 +557,7 @@ int main(int argc, char *argv[]) | @@ -578,8 +557,7 @@ int main(int argc, char *argv[]) | ||
| 578 | modbus_set_timeout_begin(ctx, &timeout_begin_new); | 557 | modbus_set_timeout_begin(ctx, &timeout_begin_new); |
| 579 | 558 | ||
| 580 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, | 559 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, |
| 581 | - UT_REGISTERS_NB_POINTS, | ||
| 582 | - tab_rp_registers); | 560 | + UT_REGISTERS_NB, tab_rp_registers); |
| 583 | printf("4/4 Too short timeout: "); | 561 | printf("4/4 Too short timeout: "); |
| 584 | if (rc == -1 && errno == ETIMEDOUT) { | 562 | if (rc == -1 && errno == ETIMEDOUT) { |
| 585 | printf("OK\n"); | 563 | printf("OK\n"); |
| @@ -600,10 +578,9 @@ int main(int argc, char *argv[]) | @@ -600,10 +578,9 @@ int main(int argc, char *argv[]) | ||
| 600 | 578 | ||
| 601 | /* Allocate only the required space */ | 579 | /* Allocate only the required space */ |
| 602 | tab_rp_registers_bad = (uint16_t *) malloc( | 580 | tab_rp_registers_bad = (uint16_t *) malloc( |
| 603 | - UT_REGISTERS_NB_POINTS_SPECIAL * sizeof(uint16_t)); | 581 | + UT_REGISTERS_NB_SPECIAL * sizeof(uint16_t)); |
| 604 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, | 582 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS, |
| 605 | - UT_REGISTERS_NB_POINTS_SPECIAL, | ||
| 606 | - tab_rp_registers_bad); | 583 | + UT_REGISTERS_NB_SPECIAL, tab_rp_registers_bad); |
| 607 | printf("* modbus_read_registers: "); | 584 | printf("* modbus_read_registers: "); |
| 608 | if (rc == -1 && errno == EMBBADDATA) { | 585 | if (rc == -1 && errno == EMBBADDATA) { |
| 609 | printf("OK\n"); | 586 | printf("OK\n"); |
| @@ -618,8 +595,7 @@ int main(int argc, char *argv[]) | @@ -618,8 +595,7 @@ int main(int argc, char *argv[]) | ||
| 618 | printf("\nTEST MANUAL EXCEPTION:\n"); | 595 | printf("\nTEST MANUAL EXCEPTION:\n"); |
| 619 | 596 | ||
| 620 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS_SPECIAL, | 597 | rc = modbus_read_registers(ctx, UT_REGISTERS_ADDRESS_SPECIAL, |
| 621 | - UT_REGISTERS_NB_POINTS, | ||
| 622 | - tab_rp_registers); | 598 | + UT_REGISTERS_NB, tab_rp_registers); |
| 623 | printf("* modbus_read_registers at special address: "); | 599 | printf("* modbus_read_registers at special address: "); |
| 624 | if (rc == -1 && errno == EMBXSBUSY) { | 600 | if (rc == -1 && errno == EMBXSBUSY) { |
| 625 | printf("OK\n"); | 601 | printf("OK\n"); |
tests/unit-test-server.c
| @@ -74,10 +74,10 @@ int main(int argc, char*argv[]) | @@ -74,10 +74,10 @@ int main(int argc, char*argv[]) | ||
| 74 | modbus_set_error_recovery(ctx, TRUE); | 74 | modbus_set_error_recovery(ctx, TRUE); |
| 75 | 75 | ||
| 76 | mb_mapping = modbus_mapping_new( | 76 | mb_mapping = modbus_mapping_new( |
| 77 | - UT_BITS_ADDRESS + UT_BITS_NB_POINTS, | ||
| 78 | - UT_INPUT_BITS_ADDRESS + UT_INPUT_BITS_NB_POINTS, | ||
| 79 | - UT_REGISTERS_ADDRESS + UT_REGISTERS_NB_POINTS, | ||
| 80 | - UT_INPUT_REGISTERS_ADDRESS + UT_INPUT_REGISTERS_NB_POINTS); | 77 | + UT_BITS_ADDRESS + UT_BITS_NB, |
| 78 | + UT_INPUT_BITS_ADDRESS + UT_INPUT_BITS_NB, | ||
| 79 | + UT_REGISTERS_ADDRESS + UT_REGISTERS_NB, | ||
| 80 | + UT_INPUT_REGISTERS_ADDRESS + UT_INPUT_REGISTERS_NB); | ||
| 81 | if (mb_mapping == NULL) { | 81 | if (mb_mapping == NULL) { |
| 82 | fprintf(stderr, "Failed to allocate the mapping: %s\n", | 82 | fprintf(stderr, "Failed to allocate the mapping: %s\n", |
| 83 | modbus_strerror(errno)); | 83 | modbus_strerror(errno)); |
| @@ -90,11 +90,11 @@ int main(int argc, char*argv[]) | @@ -90,11 +90,11 @@ int main(int argc, char*argv[]) | ||
| 90 | 90 | ||
| 91 | /** INPUT STATUS **/ | 91 | /** INPUT STATUS **/ |
| 92 | modbus_set_bits_from_bytes(mb_mapping->tab_input_bits, | 92 | modbus_set_bits_from_bytes(mb_mapping->tab_input_bits, |
| 93 | - UT_INPUT_BITS_ADDRESS, UT_INPUT_BITS_NB_POINTS, | 93 | + UT_INPUT_BITS_ADDRESS, UT_INPUT_BITS_NB, |
| 94 | UT_INPUT_BITS_TAB); | 94 | UT_INPUT_BITS_TAB); |
| 95 | 95 | ||
| 96 | /** INPUT REGISTERS **/ | 96 | /** INPUT REGISTERS **/ |
| 97 | - for (i=0; i < UT_INPUT_REGISTERS_NB_POINTS; i++) { | 97 | + for (i=0; i < UT_INPUT_REGISTERS_NB; i++) { |
| 98 | mb_mapping->tab_input_registers[UT_INPUT_REGISTERS_ADDRESS+i] = | 98 | mb_mapping->tab_input_registers[UT_INPUT_REGISTERS_ADDRESS+i] = |
| 99 | UT_INPUT_REGISTERS_TAB[i];; | 99 | UT_INPUT_REGISTERS_TAB[i];; |
| 100 | } | 100 | } |
| @@ -124,10 +124,10 @@ int main(int argc, char*argv[]) | @@ -124,10 +124,10 @@ int main(int argc, char*argv[]) | ||
| 124 | /* Read holding registers */ | 124 | /* Read holding registers */ |
| 125 | if (query[header_length] == 0x03) { | 125 | if (query[header_length] == 0x03) { |
| 126 | if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 3) | 126 | if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 3) |
| 127 | - == UT_REGISTERS_NB_POINTS_SPECIAL) { | 127 | + == UT_REGISTERS_NB_SPECIAL) { |
| 128 | printf("Set an incorrect number of values\n"); | 128 | printf("Set an incorrect number of values\n"); |
| 129 | MODBUS_SET_INT16_TO_INT8(query, header_length + 3, | 129 | MODBUS_SET_INT16_TO_INT8(query, header_length + 3, |
| 130 | - UT_REGISTERS_NB_POINTS); | 130 | + UT_REGISTERS_NB); |
| 131 | } else if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 1) | 131 | } else if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 1) |
| 132 | == UT_REGISTERS_ADDRESS_SPECIAL) { | 132 | == UT_REGISTERS_ADDRESS_SPECIAL) { |
| 133 | printf("Reply to this special register address by an exception\n"); | 133 | printf("Reply to this special register address by an exception\n"); |
tests/unit-test.h
| @@ -34,25 +34,25 @@ | @@ -34,25 +34,25 @@ | ||
| 34 | #define SERVER_ID 17 | 34 | #define SERVER_ID 17 |
| 35 | 35 | ||
| 36 | const uint16_t UT_BITS_ADDRESS = 0x13; | 36 | const uint16_t UT_BITS_ADDRESS = 0x13; |
| 37 | -const uint16_t UT_BITS_NB_POINTS = 0x25; | 37 | +const uint16_t UT_BITS_NB = 0x25; |
| 38 | const uint8_t UT_BITS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B }; | 38 | const uint8_t UT_BITS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B }; |
| 39 | 39 | ||
| 40 | const uint16_t UT_INPUT_BITS_ADDRESS = 0xC4; | 40 | const uint16_t UT_INPUT_BITS_ADDRESS = 0xC4; |
| 41 | -const uint16_t UT_INPUT_BITS_NB_POINTS = 0x16; | 41 | +const uint16_t UT_INPUT_BITS_NB = 0x16; |
| 42 | const uint8_t UT_INPUT_BITS_TAB[] = { 0xAC, 0xDB, 0x35 }; | 42 | const uint8_t UT_INPUT_BITS_TAB[] = { 0xAC, 0xDB, 0x35 }; |
| 43 | 43 | ||
| 44 | const uint16_t UT_REGISTERS_ADDRESS = 0x6B; | 44 | const uint16_t UT_REGISTERS_ADDRESS = 0x6B; |
| 45 | /* Raise a manual exception when this adress is used for the first byte */ | 45 | /* Raise a manual exception when this adress is used for the first byte */ |
| 46 | const uint16_t UT_REGISTERS_ADDRESS_SPECIAL = 0x6C; | 46 | const uint16_t UT_REGISTERS_ADDRESS_SPECIAL = 0x6C; |
| 47 | -const uint16_t UT_REGISTERS_NB_POINTS = 0x3; | 47 | +const uint16_t UT_REGISTERS_NB = 0x3; |
| 48 | const uint16_t UT_REGISTERS_TAB[] = { 0x022B, 0x0001, 0x0064 }; | 48 | const uint16_t UT_REGISTERS_TAB[] = { 0x022B, 0x0001, 0x0064 }; |
| 49 | /* If the following value is used, a bad response is sent. | 49 | /* If the following value is used, a bad response is sent. |
| 50 | It's better to test with a lower value than | 50 | It's better to test with a lower value than |
| 51 | UT_REGISTERS_NB_POINTS to try to raise a segfault. */ | 51 | UT_REGISTERS_NB_POINTS to try to raise a segfault. */ |
| 52 | -const uint16_t UT_REGISTERS_NB_POINTS_SPECIAL = 0x2; | 52 | +const uint16_t UT_REGISTERS_NB_SPECIAL = 0x2; |
| 53 | 53 | ||
| 54 | const uint16_t UT_INPUT_REGISTERS_ADDRESS = 0x08; | 54 | const uint16_t UT_INPUT_REGISTERS_ADDRESS = 0x08; |
| 55 | -const uint16_t UT_INPUT_REGISTERS_NB_POINTS = 0x1; | 55 | +const uint16_t UT_INPUT_REGISTERS_NB = 0x1; |
| 56 | const uint16_t UT_INPUT_REGISTERS_TAB[] = { 0x000A }; | 56 | const uint16_t UT_INPUT_REGISTERS_TAB[] = { 0x000A }; |
| 57 | 57 | ||
| 58 | const float UT_REAL = 916.540649; | 58 | const float UT_REAL = 916.540649; |