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 | 87 | } |
| 88 | 88 | |
| 89 | 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 | 91 | tab_rp_bits = (uint8_t *) malloc(nb_points * sizeof(uint8_t)); |
| 93 | 92 | memset(tab_rp_bits, 0, nb_points * sizeof(uint8_t)); |
| 94 | 93 | |
| 95 | 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 | 97 | tab_rp_registers = (uint16_t *) malloc(nb_points * sizeof(uint16_t)); |
| 100 | 98 | memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t)); |
| 101 | 99 | |
| ... | ... | @@ -131,14 +129,13 @@ int main(int argc, char *argv[]) |
| 131 | 129 | |
| 132 | 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 | 135 | rc = modbus_write_bits(ctx, UT_BITS_ADDRESS, |
| 139 | - UT_BITS_NB_POINTS, tab_value); | |
| 136 | + UT_BITS_NB, tab_value); | |
| 140 | 137 | printf("1/2 modbus_write_bits: "); |
| 141 | - if (rc == UT_BITS_NB_POINTS) { | |
| 138 | + if (rc == UT_BITS_NB) { | |
| 142 | 139 | printf("OK\n"); |
| 143 | 140 | } else { |
| 144 | 141 | printf("FAILED\n"); |
| ... | ... | @@ -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 | 147 | printf("2/2 modbus_read_bits: "); |
| 152 | - if (rc != UT_BITS_NB_POINTS) { | |
| 148 | + if (rc != UT_BITS_NB) { | |
| 153 | 149 | printf("FAILED (nb points %d)\n", rc); |
| 154 | 150 | goto close; |
| 155 | 151 | } |
| 156 | 152 | |
| 157 | 153 | i = 0; |
| 158 | 154 | address = UT_BITS_ADDRESS; |
| 159 | - nb_points = UT_BITS_NB_POINTS; | |
| 155 | + nb_points = UT_BITS_NB; | |
| 160 | 156 | while (nb_points > 0) { |
| 161 | 157 | int nb_bits = (nb_points > 8) ? 8 : nb_points; |
| 162 | 158 | |
| 163 | 159 | value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits); |
| 164 | 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 | 162 | goto close; |
| 168 | 163 | } |
| 169 | 164 | |
| ... | ... | @@ -175,24 +170,23 @@ int main(int argc, char *argv[]) |
| 175 | 170 | |
| 176 | 171 | /** DISCRETE INPUTS **/ |
| 177 | 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 | 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 | 177 | printf("FAILED (nb points %d)\n", rc); |
| 183 | 178 | goto close; |
| 184 | 179 | } |
| 185 | 180 | |
| 186 | 181 | i = 0; |
| 187 | 182 | address = UT_INPUT_BITS_ADDRESS; |
| 188 | - nb_points = UT_INPUT_BITS_NB_POINTS; | |
| 183 | + nb_points = UT_INPUT_BITS_NB; | |
| 189 | 184 | while (nb_points > 0) { |
| 190 | 185 | int nb_bits = (nb_points > 8) ? 8 : nb_points; |
| 191 | 186 | |
| 192 | 187 | value = modbus_get_byte_from_bits(tab_rp_bits, i*8, nb_bits); |
| 193 | 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 | 190 | goto close; |
| 197 | 191 | } |
| 198 | 192 | |
| ... | ... | @@ -231,10 +225,9 @@ int main(int argc, char *argv[]) |
| 231 | 225 | |
| 232 | 226 | /* Many registers */ |
| 233 | 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 | 229 | printf("1/5 modbus_write_registers: "); |
| 237 | - if (rc == UT_REGISTERS_NB_POINTS) { | |
| 230 | + if (rc == UT_REGISTERS_NB) { | |
| 238 | 231 | printf("OK\n"); |
| 239 | 232 | } else { |
| 240 | 233 | printf("FAILED\n"); |
| ... | ... | @@ -242,15 +235,14 @@ int main(int argc, char *argv[]) |
| 242 | 235 | } |
| 243 | 236 | |
| 244 | 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 | 239 | printf("2/5 modbus_read_registers: "); |
| 248 | - if (rc != UT_REGISTERS_NB_POINTS) { | |
| 240 | + if (rc != UT_REGISTERS_NB) { | |
| 249 | 241 | printf("FAILED (nb points %d)\n", rc); |
| 250 | 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 | 246 | if (tab_rp_registers[i] != UT_REGISTERS_TAB[i]) { |
| 255 | 247 | printf("FAILED (%0X != %0X)\n", |
| 256 | 248 | tab_rp_registers[i], |
| ... | ... | @@ -269,24 +261,23 @@ int main(int argc, char *argv[]) |
| 269 | 261 | } |
| 270 | 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 | 267 | memset(tab_rp_registers, 0, nb_points * sizeof(uint16_t)); |
| 276 | 268 | |
| 277 | 269 | /* Write registers to zero from tab_rp_registers and store read registers |
| 278 | 270 | into tab_rp_registers. So the read registers must set to 0, except the |
| 279 | 271 | first one because there is an offset of 1 register on write. */ |
| 280 | 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 | 274 | tab_rp_registers, |
| 284 | 275 | UT_REGISTERS_ADDRESS + 1, |
| 285 | - UT_REGISTERS_NB_POINTS - 1, | |
| 276 | + UT_REGISTERS_NB - 1, | |
| 286 | 277 | tab_rp_registers); |
| 287 | 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 | 281 | goto close; |
| 291 | 282 | } |
| 292 | 283 | |
| ... | ... | @@ -295,7 +286,7 @@ int main(int argc, char *argv[]) |
| 295 | 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 | 290 | if (tab_rp_registers[i] != 0) { |
| 300 | 291 | printf("FAILED (%0X != %0X)\n", |
| 301 | 292 | tab_rp_registers[i], 0); |
| ... | ... | @@ -309,15 +300,14 @@ int main(int argc, char *argv[]) |
| 309 | 300 | |
| 310 | 301 | /** INPUT REGISTERS **/ |
| 311 | 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 | 304 | printf("1/1 modbus_read_input_registers: "); |
| 315 | - if (rc != UT_INPUT_REGISTERS_NB_POINTS) { | |
| 305 | + if (rc != UT_INPUT_REGISTERS_NB) { | |
| 316 | 306 | printf("FAILED (nb points %d)\n", rc); |
| 317 | 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 | 311 | if (tab_rp_registers[i] != UT_INPUT_REGISTERS_TAB[i]) { |
| 322 | 312 | printf("FAILED (%0X != %0X)\n", |
| 323 | 313 | tab_rp_registers[i], UT_INPUT_REGISTERS_TAB[i]); |
| ... | ... | @@ -357,8 +347,7 @@ int main(int argc, char *argv[]) |
| 357 | 347 | * the addresses are not valid. */ |
| 358 | 348 | |
| 359 | 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 | 351 | printf("* modbus_read_bits: "); |
| 363 | 352 | if (rc == -1 && errno == EMBXILADD) { |
| 364 | 353 | printf("OK\n"); |
| ... | ... | @@ -368,8 +357,7 @@ int main(int argc, char *argv[]) |
| 368 | 357 | } |
| 369 | 358 | |
| 370 | 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 | 361 | printf("* modbus_read_input_bits: "); |
| 374 | 362 | if (rc == -1 && errno == EMBXILADD) |
| 375 | 363 | printf("OK\n"); |
| ... | ... | @@ -379,8 +367,7 @@ int main(int argc, char *argv[]) |
| 379 | 367 | } |
| 380 | 368 | |
| 381 | 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 | 371 | printf("* modbus_read_registers: "); |
| 385 | 372 | if (rc == -1 && errno == EMBXILADD) |
| 386 | 373 | printf("OK\n"); |
| ... | ... | @@ -390,8 +377,7 @@ int main(int argc, char *argv[]) |
| 390 | 377 | } |
| 391 | 378 | |
| 392 | 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 | 381 | printf("* modbus_read_input_registers: "); |
| 396 | 382 | if (rc == -1 && errno == EMBXILADD) |
| 397 | 383 | printf("OK\n"); |
| ... | ... | @@ -400,7 +386,7 @@ int main(int argc, char *argv[]) |
| 400 | 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 | 390 | printf("* modbus_write_bit: "); |
| 405 | 391 | if (rc == -1 && errno == EMBXILADD) { |
| 406 | 392 | printf("OK\n"); |
| ... | ... | @@ -409,9 +395,8 @@ int main(int argc, char *argv[]) |
| 409 | 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 | 400 | printf("* modbus_write_coils: "); |
| 416 | 401 | if (rc == -1 && errno == EMBXILADD) { |
| 417 | 402 | printf("OK\n"); |
| ... | ... | @@ -420,10 +405,8 @@ int main(int argc, char *argv[]) |
| 420 | 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 | 410 | printf("* modbus_write_registers: "); |
| 428 | 411 | if (rc == -1 && errno == EMBXILADD) { |
| 429 | 412 | printf("OK\n"); |
| ... | ... | @@ -436,8 +419,8 @@ int main(int argc, char *argv[]) |
| 436 | 419 | /** TOO MANY DATA **/ |
| 437 | 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 | 424 | printf("* modbus_read_bits: "); |
| 442 | 425 | if (rc == -1 && errno == EMBMDATA) { |
| 443 | 426 | printf("OK\n"); |
| ... | ... | @@ -447,8 +430,7 @@ int main(int argc, char *argv[]) |
| 447 | 430 | } |
| 448 | 431 | |
| 449 | 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 | 434 | printf("* modbus_read_input_bits: "); |
| 453 | 435 | if (rc == -1 && errno == EMBMDATA) { |
| 454 | 436 | printf("OK\n"); |
| ... | ... | @@ -480,8 +462,7 @@ int main(int argc, char *argv[]) |
| 480 | 462 | } |
| 481 | 463 | |
| 482 | 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 | 466 | printf("* modbus_write_bits: "); |
| 486 | 467 | if (rc == -1 && errno == EMBMDATA) { |
| 487 | 468 | printf("OK\n"); |
| ... | ... | @@ -505,8 +486,7 @@ int main(int argc, char *argv[]) |
| 505 | 486 | printf("\nTEST SLAVE REPLY:\n"); |
| 506 | 487 | modbus_set_slave(ctx, 18); |
| 507 | 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 | 490 | if (use_backend == RTU) { |
| 511 | 491 | /* No response in RTU mode */ |
| 512 | 492 | printf("1/4 No response from slave %d: ", 18); |
| ... | ... | @@ -521,7 +501,7 @@ int main(int argc, char *argv[]) |
| 521 | 501 | /* Response in TCP mode */ |
| 522 | 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 | 505 | printf("OK\n"); |
| 526 | 506 | } else { |
| 527 | 507 | printf("FAILED\n"); |
| ... | ... | @@ -536,10 +516,9 @@ int main(int argc, char *argv[]) |
| 536 | 516 | } |
| 537 | 517 | |
| 538 | 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 | 520 | printf("2/4 Reply after a broadcast query: "); |
| 542 | - if (rc == UT_REGISTERS_NB_POINTS) { | |
| 521 | + if (rc == UT_REGISTERS_NB) { | |
| 543 | 522 | printf("OK\n"); |
| 544 | 523 | } else { |
| 545 | 524 | printf("FAILED\n"); |
| ... | ... | @@ -578,8 +557,7 @@ int main(int argc, char *argv[]) |
| 578 | 557 | modbus_set_timeout_begin(ctx, &timeout_begin_new); |
| 579 | 558 | |
| 580 | 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 | 561 | printf("4/4 Too short timeout: "); |
| 584 | 562 | if (rc == -1 && errno == ETIMEDOUT) { |
| 585 | 563 | printf("OK\n"); |
| ... | ... | @@ -600,10 +578,9 @@ int main(int argc, char *argv[]) |
| 600 | 578 | |
| 601 | 579 | /* Allocate only the required space */ |
| 602 | 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 | 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 | 584 | printf("* modbus_read_registers: "); |
| 608 | 585 | if (rc == -1 && errno == EMBBADDATA) { |
| 609 | 586 | printf("OK\n"); |
| ... | ... | @@ -618,8 +595,7 @@ int main(int argc, char *argv[]) |
| 618 | 595 | printf("\nTEST MANUAL EXCEPTION:\n"); |
| 619 | 596 | |
| 620 | 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 | 599 | printf("* modbus_read_registers at special address: "); |
| 624 | 600 | if (rc == -1 && errno == EMBXSBUSY) { |
| 625 | 601 | printf("OK\n"); | ... | ... |
tests/unit-test-server.c
| ... | ... | @@ -74,10 +74,10 @@ int main(int argc, char*argv[]) |
| 74 | 74 | modbus_set_error_recovery(ctx, TRUE); |
| 75 | 75 | |
| 76 | 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 | 81 | if (mb_mapping == NULL) { |
| 82 | 82 | fprintf(stderr, "Failed to allocate the mapping: %s\n", |
| 83 | 83 | modbus_strerror(errno)); |
| ... | ... | @@ -90,11 +90,11 @@ int main(int argc, char*argv[]) |
| 90 | 90 | |
| 91 | 91 | /** INPUT STATUS **/ |
| 92 | 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 | 94 | UT_INPUT_BITS_TAB); |
| 95 | 95 | |
| 96 | 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 | 98 | mb_mapping->tab_input_registers[UT_INPUT_REGISTERS_ADDRESS+i] = |
| 99 | 99 | UT_INPUT_REGISTERS_TAB[i];; |
| 100 | 100 | } |
| ... | ... | @@ -124,10 +124,10 @@ int main(int argc, char*argv[]) |
| 124 | 124 | /* Read holding registers */ |
| 125 | 125 | if (query[header_length] == 0x03) { |
| 126 | 126 | if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 3) |
| 127 | - == UT_REGISTERS_NB_POINTS_SPECIAL) { | |
| 127 | + == UT_REGISTERS_NB_SPECIAL) { | |
| 128 | 128 | printf("Set an incorrect number of values\n"); |
| 129 | 129 | MODBUS_SET_INT16_TO_INT8(query, header_length + 3, |
| 130 | - UT_REGISTERS_NB_POINTS); | |
| 130 | + UT_REGISTERS_NB); | |
| 131 | 131 | } else if (MODBUS_GET_INT16_FROM_INT8(query, header_length + 1) |
| 132 | 132 | == UT_REGISTERS_ADDRESS_SPECIAL) { |
| 133 | 133 | printf("Reply to this special register address by an exception\n"); | ... | ... |
tests/unit-test.h
| ... | ... | @@ -34,25 +34,25 @@ |
| 34 | 34 | #define SERVER_ID 17 |
| 35 | 35 | |
| 36 | 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 | 38 | const uint8_t UT_BITS_TAB[] = { 0xCD, 0x6B, 0xB2, 0x0E, 0x1B }; |
| 39 | 39 | |
| 40 | 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 | 42 | const uint8_t UT_INPUT_BITS_TAB[] = { 0xAC, 0xDB, 0x35 }; |
| 43 | 43 | |
| 44 | 44 | const uint16_t UT_REGISTERS_ADDRESS = 0x6B; |
| 45 | 45 | /* Raise a manual exception when this adress is used for the first byte */ |
| 46 | 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 | 48 | const uint16_t UT_REGISTERS_TAB[] = { 0x022B, 0x0001, 0x0064 }; |
| 49 | 49 | /* If the following value is used, a bad response is sent. |
| 50 | 50 | It's better to test with a lower value than |
| 51 | 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 | 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 | 56 | const uint16_t UT_INPUT_REGISTERS_TAB[] = { 0x000A }; |
| 57 | 57 | |
| 58 | 58 | const float UT_REAL = 916.540649; | ... | ... |