File view
| 1 | // ************************************************************************************************ |
| 2 | // |
| 3 | // File Name: Plc_Elec_Testing.lib |
| 4 | // Created: 07-28-20 |
| 5 | // By: Carl Eggleston |
| 6 | // |
| 7 | // Info: State Machine and associated functions / data for the |
| 8 | // Electronic Line Leak Detection features of the PLC-5000 System |
| 9 | // |
| 10 | // ************************************************************************************************ |
| 11 | |
| 12 | /*** BeginHeader */ |
| 13 | |
| 14 | #ifndef __PLC_ELEC_TESTING_ |
| 15 | #define __PLC_ELEC_TESTING_ |
| 16 | |
| 17 | /*** EndHeader */ |
| 18 | |
| 19 | /*** BeginHeader |
| 20 | |
| 21 | TestingStateHandler |
| 22 | TestInitialize |
| 23 | TestReset |
| 24 | TestStart |
| 25 | TestStop |
| 26 | TestHold |
| 27 | TestConfig |
| 28 | |
| 29 | */ |
| 30 | |
| 31 | // Defines **************************************************************************************** |
| 32 | |
| 33 | // Test Code |
| 34 | #define TEST_PNT1 1 |
| 35 | #define TEST_PNT2 2 |
| 36 | #define TEST_GPH3 3 |
| 37 | |
| 38 | //Test Status |
| 39 | #define PT_INACTIVE 0 |
| 40 | #define PT_PENDING 1 |
| 41 | #define PT_ACTIVE 2 |
| 42 | #define PT_COMPLETE 3 |
| 43 | #define PT_NO_ERROR 4 |
| 44 | #define PT_NO_PRESSURE 5 |
| 45 | #define PT_CYCLE_LIMIT 6 |
| 46 | #define PT_INGRESS 7 |
| 47 | //#define PT_ABORT_TEST 8 |
| 48 | |
| 49 | // Test Resaults |
| 50 | #define NORESULT 2 |
| 51 | #define PASS 1 |
| 52 | #define FAIL 0 |
| 53 | |
| 54 | // Test Constants |
| 55 | #define GPH3_TF 50 |
| 56 | #define PT_TF_2 2797 |
| 57 | #define PT_TF_1 5594 |
| 58 | #define PT_CYCLES 10 |
| 59 | |
| 60 | // Global Structurures Init *********************************************************************** |
| 61 | |
| 62 | /** In plc_types.lib for now **/ |
| 63 | |
| 64 | // Global function prototypes ********************************************************************* |
| 65 | |
| 66 | void TestingStateHandler (ElecTestingStr *curTest); |
| 67 | void TestInitialize (ElecTestingStr *curTest); |
| 68 | void TestReset (ElecTestingStr *curTest); |
| 69 | void TestStart (ElecTestingStr *curTest); |
| 70 | void TestStop (ElecTestingStr *curTest); |
| 71 | void TestHold (ElecTestingStr *curTest); |
| 72 | void TestConfig (ElecTestingStr *curTest, uint8_t type, uint16_t resil, uint8_t id, |
| 73 | uint8_t highPres, uint8_t lowPres); |
| 74 | |
| 75 | // Global declorations **************************************************************************** |
| 76 | |
| 77 | /*** EndHeader */ |
| 78 | |
| 79 | |
| 80 | // Local Structurures Init ************************************************************************ |
| 81 | |
| 82 | |
| 83 | |
| 84 | // Local declorations ***************************************************************************** |
| 85 | |
| 86 | ElecTestingStr *this; |
| 87 | |
| 88 | // Local function prototypes ********************************************************************** |
| 89 | |
| 90 | void GPH3Repressure (uint8_t first); // Repressure State for 3 GPH Tests |
| 91 | void GPH3DropPressure (uint8_t first); // Pressure bleed off state for 3 GPH Tests |
| 92 | void GPH3Monitor (uint8_t first); // Actualy Timed test state for 3 GPH Tests |
| 93 | void PtRepressure (uint8_t first); // Repressure State for Precision Tests |
| 94 | void PtDropPressure (uint8_t first); // Pressure bleed off state for Precision Tests |
| 95 | void PtMonitor (uint8_t first); // Actualy Timed test state for Precision Tests |
| 96 | void Expansion (uint8_t first); // Leak Rate calculations |
| 97 | void Contraction (uint8_t first); // Leak Rate calculations |
| 98 | void Steady (uint8_t first); // Leak Rate calculations |
| 99 | |
| 100 | // Testing State index list *********************************************************************** |
| 101 | |
| 102 | enum { |
| 103 | GPH3_REPRES = 0, |
| 104 | GPH3_DROP_PRES = 1, |
| 105 | GPH3_MONITOR, |
| 106 | PREC_REPRES, |
| 107 | PREC_DROP_PRES, |
| 108 | PREC_MONITOR, |
| 109 | EXPANSION, |
| 110 | CONTRACTION, |
| 111 | STEADY, |
| 112 | PT_NOSTATE |
| 113 | }; |
| 114 | |
| 115 | |
| 116 | /****************************************************************** |
| 117 | * Function Name: |
| 118 | * |
| 119 | * |
| 120 | * Args / Parameters: |
| 121 | * |
| 122 | * |
| 123 | * Description: |
| 124 | * |
| 125 | * |
| 126 | * |
| 127 | * Returns: |
| 128 | * |
| 129 | */ |
| 130 | void (* const TestingStateTable[]) () = { |
| 131 | GPH3Repressure, |
| 132 | GPH3DropPressure, |
| 133 | GPH3Monitor, |
| 134 | PtRepressure, |
| 135 | PtDropPressure, |
| 136 | PtMonitor, |
| 137 | Expansion, |
| 138 | Contraction, |
| 139 | Steady }; |
| 140 | |
| 141 | |
| 142 | /****************************************************************** |
| 143 | * Function Name: |
| 144 | * |
| 145 | * |
| 146 | * Args / Parameters: |
| 147 | * |
| 148 | * |
| 149 | * Description: |
| 150 | * |
| 151 | * |
| 152 | * |
| 153 | * Returns: |
| 154 | * |
| 155 | */ |
| 156 | void TestStart(ElecTestingStr *curTest) |
| 157 | { |
| 158 | this = curTest; |
| 159 | this->Status = PT_ACTIVE; |
| 160 | this->PreviousState = PT_NOSTATE; |
| 161 | |
| 162 | if (this->Type == TEST_GPH3) |
| 163 | { |
| 164 | if (this->PresFlag == 2) |
| 165 | { |
| 166 | this->State = GPH3_DROP_PRES; |
| 167 | } |
| 168 | else //not looking for press flag |
| 169 | { |
| 170 | this->State = GPH3_REPRES; |
| 171 | } |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | this->State = PREC_REPRES; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | |
| 180 | /****************************************************************** |
| 181 | * Function Name: |
| 182 | * |
| 183 | * |
| 184 | * Args / Parameters: |
| 185 | * |
| 186 | * |
| 187 | * Description: |
| 188 | * |
| 189 | * |
| 190 | * |
| 191 | * Returns: |
| 192 | * |
| 193 | */ |
| 194 | void TestStop(ElecTestingStr *curTest) |
| 195 | { |
| 196 | this = curTest; |
| 197 | this->Status = PT_INACTIVE; |
| 198 | } |
| 199 | |
| 200 | |
| 201 | /****************************************************************** |
| 202 | * Function Name: |
| 203 | * |
| 204 | * |
| 205 | * Args / Parameters: |
| 206 | * |
| 207 | * |
| 208 | * Description: |
| 209 | * |
| 210 | * |
| 211 | * |
| 212 | * Returns: |
| 213 | * |
| 214 | */ |
| 215 | void TestHold(ElecTestingStr *curTest) |
| 216 | { |
| 217 | this = curTest; |
| 218 | this->Status = PT_PENDING; |
| 219 | } |
| 220 | |
| 221 | /****************************************************************** |
| 222 | * Function Name: |
| 223 | * |
| 224 | * |
| 225 | * Args / Parameters: |
| 226 | * |
| 227 | * |
| 228 | * Description: |
| 229 | * |
| 230 | * |
| 231 | * |
| 232 | * Returns: |
| 233 | * |
| 234 | */ |
| 235 | void TestingStateHandler (ElecTestingStr *curTest) |
| 236 | { |
| 237 | uint8_t first; |
| 238 | uint8_t tmpPrevious; |
| 239 | |
| 240 | this = curTest; |
| 241 | |
| 242 | if (this->PreviousState != this->State) |
| 243 | { |
| 244 | first = 1; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | first = 0; |
| 249 | } |
| 250 | |
| 251 | tmpPrevious = this->State; |
| 252 | TestingStateTable[this->State] (first); |
| 253 | this->PreviousState = tmpPrevious; |
| 254 | } |
| 255 | |
| 256 | /****************************************************************** |
| 257 | * Function Name: |
| 258 | * |
| 259 | * |
| 260 | * Args / Parameters: |
| 261 | * |
| 262 | * |
| 263 | * Description: |
| 264 | * |
| 265 | * |
| 266 | * |
| 267 | * Returns: |
| 268 | * |
| 269 | */ |
| 270 | void GPH3Repressure (uint8_t first) |
| 271 | { |
| 272 | if (first) |
| 273 | { |
| 274 | this->Turbine = ON; |
| 275 | this->ShuntValve = OFF; |
| 276 | this->RdyFlag = OFF; |
| 277 | this->StartTime = SEC_TIMER; |
| 278 | this->DurationTime = PRESSUREDLY; |
| 279 | ResetLDN (this->ID, this->Resil); |
| 280 | printf("CH: %d | State: %s | Test: %d \n", this->ID, GPH3TestName[this->State], this->Type); |
| 281 | } |
| 282 | else if (this->PresFlag == 2 && SEC_TIMER - this->StartTime > 2) |
| 283 | { |
| 284 | this->State = GPH3_DROP_PRES; |
| 285 | } |
| 286 | else if (this->PresFlag < 2 && SEC_TIMER - this->StartTime > 20) |
| 287 | { |
| 288 | this->Status = PT_NO_PRESSURE; |
| 289 | this->Result = FAIL; |
| 290 | this->Note = PT_NO_PRESSURE; |
| 291 | } |
| 292 | |
| 293 | } |
| 294 | |
| 295 | /****************************************************************** |
| 296 | * Function Name: |
| 297 | * |
| 298 | * |
| 299 | * Args / Parameters: |
| 300 | * |
| 301 | * |
| 302 | * Description: |
| 303 | * |
| 304 | * |
| 305 | * |
| 306 | * Returns: |
| 307 | * |
| 308 | */ |
| 309 | void GPH3DropPressure (uint8_t first) |
| 310 | { |
| 311 | printf("FIRST: %d CH: %d | State: %s | Test: %d \n",first, this->ID, GPH3TestName[this->State], this->Type); |
| 312 | printf("TIME is true: %d \n", (SEC_TIMER - this->StartTime > STABLE_TIME)); |
| 313 | printf("REG 1: %d REG 2: %d \n", GetLDNReg(this->ID, SHUNT_COMPLETE), GetLDNReg(this->ID, LDN_STATE)); |
| 314 | printf("\n \n SEC_TIMER: %Lu %Lu \n \n",SEC_TIMER, this->StartTime); |
| 315 | |
| 316 | if (first) |
| 317 | { |
| 318 | printf("Attempting to drop pressure...\n"); |
| 319 | this->Turbine = OFF; |
| 320 | this->ShuntValve = ON; |
| 321 | this->StartTime = SEC_TIMER; |
| 322 | SetLDNReg (this->ID, MONITOR_PRES, OFF); |
| 323 | SetLDNReg (this->ID, SET_PRES, this->HighPressure); |
| 324 | SetLDNReg (this->ID, SHUNT_PRES, ON); |
| 325 | } |
| 326 | |
| 327 | else if (GetLDNReg(this->ID, SHUNT_COMPLETE) && (SEC_TIMER - this->StartTime > 10)) |
| 328 | { |
| 329 | this->State = GPH3_MONITOR; |
| 330 | } |
| 331 | // If pressure does not drop within the allotted maximum shunt time, |
| 332 | // end the test with a No Drop Pressure condition (mirrors VALVE state behavior) |
| 333 | else if (SEC_TIMER - this->StartTime > MAXSHUNTTIME) |
| 334 | { |
| 335 | this->ShuntValve = OFF; |
| 336 | SetLDNReg (this->ID, SHUNT_PRES, OFF); |
| 337 | this->Status = PT_COMPLETE; |
| 338 | this->Result = NORESULT; |
| 339 | this->Note = NO_PRES_DROP; |
| 340 | } |
| 341 | |
| 342 | else if (GetLDNReg(this->ID, LDN_STATE) != LDN_SHUNT && SEC_TIMER - this->StartTime > 10) |
| 343 | { |
| 344 | |
| 345 | printf("Aborting test in Drop pressure state.....\n"); |
| 346 | this->Result = NORESULT; |
| 347 | this->Status = PT_NO_ERROR; |
| 348 | this->Note = PT_NO_ERROR; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | /****************************************************************** |
| 353 | * Function Name: |
| 354 | * |
| 355 | * |
| 356 | * Args / Parameters: |
| 357 | * |
| 358 | * |
| 359 | * Description: |
| 360 | * |
| 361 | * |
| 362 | * |
| 363 | * Returns: |
| 364 | * |
| 365 | */ |
| 366 | void GPH3Monitor (uint8_t first) |
| 367 | { |
| 368 | if (first) |
| 369 | { |
| 370 | printf("Attempting to Monitor GPH...\n"); |
| 371 | this->Turbine = OFF; |
| 372 | this->ShuntValve = OFF; |
| 373 | this->StartTime = SEC_TIMER; |
| 374 | SetLDNReg (this->ID, SHUNT_PRES, OFF); |
| 375 | SetLDNReg (this->ID, SET_PRES, this->LowPressure); |
| 376 | SetLDNReg (this->ID, TIME_FACTOR, GPH3_TF); |
| 377 | SetLDNReg (this->ID, MONITOR_PRES, ON); |
| 378 | printf("CH: %d | State: %s | Test: %d \n", this->ID, GPH3TestName[this->State], this->Type); |
| 379 | } |
| 380 | |
| 381 | else if (this->PresFlag == 2 && SEC_TIMER - this->StartTime > 2) |
| 382 | { |
| 383 | this->State = GPH3_DROP_PRES; |
| 384 | } |
| 385 | |
| 386 | else if (GetLDNReg(this->ID, MONITOR_COMPLETE) && GetLDNReg(this->ID, LEAK_RATE) == 0) |
| 387 | { |
| 388 | printf("CH: %d 3GPH Pass :\n", this->ID); |
| 389 | this->Result = PASS; |
| 390 | this->Status = PT_COMPLETE; |
| 391 | this->Note = PT_NO_ERROR; |
| 392 | } |
| 393 | |
| 394 | else if (GetLDNReg(this->ID, MONITOR_COMPLETE)) |
| 395 | { |
| 396 | if (++this->CurCycle <= this->MaxCycles) |
| 397 | { |
| 398 | this->State = GPH3_REPRES; |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | printf("Failed in GetReg GPH Monitor. \n"); |
| 403 | printf("curCycle set to: %d", this->CurCycle); |
| 404 | this->Result = FAIL; |
| 405 | this->Status = PT_COMPLETE; |
| 406 | this->Note = PT_NO_ERROR; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | else if (GetLDNReg(this->ID, LDN_STATE) != LDN_MONITOR && SEC_TIMER - this->StartTime > 10) |
| 411 | { |
| 412 | this->Result = NORESULT; |
| 413 | this->Status = PT_NO_ERROR; |
| 414 | this->Note = PT_NO_ERROR; |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /****************************************************************** |
| 419 | * Function Name: |
| 420 | * |
| 421 | * |
| 422 | * Args / Parameters: |
| 423 | * |
| 424 | * |
| 425 | * Description: |
| 426 | * |
| 427 | * |
| 428 | * |
| 429 | * Returns: |
| 430 | * |
| 431 | */ |
| 432 | void PtRepressure (uint8_t first) |
| 433 | { |
| 434 | printf("%lu %d %d\n", SEC_TIMER, this->PresFlag, first); |
| 435 | if (first) |
| 436 | { |
| 437 | this->Turbine = ON; |
| 438 | this->ShuntValve = OFF; |
| 439 | this->RdyFlag = OFF; |
| 440 | this->StartTime = SEC_TIMER; |
| 441 | this->DurationTime = PRESSUREDLY; |
| 442 | ResetLDN (this->ID, this->Resil); |
| 443 | printf("CH: %d | State: %s | Test: %d\n", this->ID, PTestName[this->State - 3], this->Type); |
| 444 | } |
| 445 | else if (this->PresFlag == 2 && SEC_TIMER - this->StartTime > 2) |
| 446 | |
| 447 | { |
| 448 | this->State = PREC_DROP_PRES; |
| 449 | } |
| 450 | else if (SEC_TIMER - this->StartTime > 20) |
| 451 | { |
| 452 | this->Status = PT_NO_PRESSURE; |
| 453 | this->Result = FAIL; |
| 454 | this->Note = PT_NO_PRESSURE; |
| 455 | this->Rate[0] = 0.0; |
| 456 | } |
| 457 | |
| 458 | } |
| 459 | |
| 460 | /****************************************************************** |
| 461 | * Function Name: |
| 462 | * |
| 463 | * |
| 464 | * Args / Parameters: |
| 465 | * |
| 466 | * |
| 467 | * Description: |
| 468 | * |
| 469 | * |
| 470 | * |
| 471 | * Returns: |
| 472 | * |
| 473 | */ |
| 474 | void PtDropPressure (uint8_t first) |
| 475 | { |
| 476 | printf("SHUNT COMPLETE %d SEC_TIMER %Lu \n", GetLDNReg(this->ID, SHUNT_COMPLETE), SEC_TIMER); |
| 477 | if (first) |
| 478 | { |
| 479 | this->Turbine = OFF; |
| 480 | this->ShuntValve = ON; |
| 481 | this->StartTime = SEC_TIMER; |
| 482 | SetLDNReg (this->ID, MONITOR_PRES, OFF); |
| 483 | SetLDNReg (this->ID, SET_PRES, this->HighPressure); |
| 484 | SetLDNReg (this->ID, SHUNT_PRES, ON); |
| 485 | printf("CH: %d | State: %s | Test: %d \n", this->ID, PTestName[this->State - 3], this->Type); |
| 486 | } |
| 487 | else if (GetLDNReg(this->ID, SHUNT_COMPLETE) && SEC_TIMER - this->StartTime > 10) |
| 488 | { |
| 489 | this->State = PREC_MONITOR; |
| 490 | } |
| 491 | else if (GetLDNReg(this->ID, LDN_STATE) != LDN_SHUNT && SEC_TIMER - this->StartTime > 10) |
| 492 | { |
| 493 | this->Result = NORESULT; |
| 494 | this->Status = PT_NO_ERROR; |
| 495 | this->Note = PT_NO_ERROR; |
| 496 | this->Rate[0] = 0.0; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /****************************************************************** |
| 501 | * Function Name: |
| 502 | * PtMonitor |
| 503 | * |
| 504 | * Args / Parameters: |
| 505 | * uint8_t first |
| 506 | * |
| 507 | * Description: |
| 508 | * Function to monitor the precision tests for .2 and .1 |
| 509 | * |
| 510 | * |
| 511 | * Returns: |
| 512 | * |
| 513 | */ |
| 514 | void PtMonitor (uint8_t first) |
| 515 | { |
| 516 | if (first) |
| 517 | { |
| 518 | printf("LR: %6.3f\n", this->Rate[this->CurCycle]); |
| 519 | this->Turbine = OFF; |
| 520 | this->ShuntValve = OFF; |
| 521 | this->StartTime = SEC_TIMER; |
| 522 | |
| 523 | SetLDNReg (this->ID, SHUNT_PRES, OFF); |
| 524 | SetLDNReg (this->ID, SET_PRES, this->LowPressure); |
| 525 | SetLDNReg (this->ID, MONITOR_PRES, ON); |
| 526 | |
| 527 | if (this->Type == TEST_PNT2) |
| 528 | SetLDNReg (this->ID, TIME_FACTOR, PT_TF_2); |
| 529 | else |
| 530 | SetLDNReg (this->ID, TIME_FACTOR, PT_TF_1); |
| 531 | printf("CH: %d | State: %s | Test: %d\n", this->ID, PTestName[this->State - 3], this->Type); |
| 532 | } |
| 533 | else if (this->PresFlag == 2 && SEC_TIMER - this->StartTime > STABLE_TIME) |
| 534 | { |
| 535 | this->State = PREC_DROP_PRES; |
| 536 | } |
| 537 | else if (GetLDNReg(this->ID, MONITOR_COMPLETE) && GetLDNReg(this->ID, LEAK_RATE) == 0) |
| 538 | { |
| 539 | this->Status = PT_COMPLETE; |
| 540 | this->Result = PASS; |
| 541 | this->Note = PT_NO_ERROR; |
| 542 | this->Rate[0] = 0.0; |
| 543 | } |
| 544 | else if (GetLDNReg(this->ID, MONITOR_COMPLETE)) |
| 545 | { |
| 546 | this->Rate[++this->CurCycle] = (float)GetLDNReg(this->ID, LEAK_RATE) * 2 / 1000.0; |
| 547 | printf("LR: %6.3f\n", this->Rate[this->CurCycle]); |
| 548 | if (this->CurCycle == 1) { |
| 549 | this->State = PREC_REPRES; |
| 550 | } |
| 551 | else { |
| 552 | if (this->Type == TEST_PNT1) |
| 553 | { |
| 554 | if ((this->Rate[this->CurCycle] - this->Rate[this->CurCycle - 1]) > 0.004) |
| 555 | this->State = EXPANSION; |
| 556 | else if ((this->Rate[this->CurCycle] - this->Rate[this->CurCycle - 1]) < -0.004) |
| 557 | this->State = CONTRACTION; |
| 558 | else |
| 559 | this->State = STEADY; |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | if ((this->Rate[this->CurCycle] - this->Rate[this->CurCycle - 1]) > 0.008) |
| 564 | this->State = EXPANSION; |
| 565 | else if ((this->Rate[this->CurCycle] - this->Rate[this->CurCycle - 1]) < -0.008) |
| 566 | this->State = CONTRACTION; |
| 567 | else |
| 568 | this->State = STEADY; |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | /****************************************************************** |
| 575 | * Function Name: |
| 576 | * Expansion |
| 577 | * |
| 578 | * Args / Parameters: |
| 579 | * uint8_t first |
| 580 | * |
| 581 | * Description: |
| 582 | * |
| 583 | * |
| 584 | * |
| 585 | * Returns: |
| 586 | * |
| 587 | */ |
| 588 | void Expansion (uint8_t first) |
| 589 | { |
| 590 | printf("CH: %d | State: %s | Test: %d\n", this->ID, PTestName[this->State - 3], this->Type); |
| 591 | |
| 592 | if (this->Type == TEST_PNT1 && this->Rate[this->CurCycle] > 0.075) |
| 593 | { |
| 594 | this->Status = PT_COMPLETE; |
| 595 | this->Result = FAIL; |
| 596 | this->Note = PT_INGRESS; |
| 597 | this->Rate[0] = this->Rate[this->CurCycle]; |
| 598 | } |
| 599 | else if (this->Type == TEST_PNT1 && this->Rate[this->CurCycle] > 0.068) |
| 600 | { |
| 601 | this->Status = PT_COMPLETE; |
| 602 | this->Result = FAIL; |
| 603 | this->Note = PT_INGRESS; |
| 604 | this->Rate[0] = 0.072; |
| 605 | } |
| 606 | else if (this->Type == TEST_PNT2 && this->Rate[this->CurCycle] > 0.150) |
| 607 | { |
| 608 | this->Status = PT_COMPLETE; |
| 609 | this->Result = FAIL; |
| 610 | this->Note = PT_INGRESS; |
| 611 | this->Rate[0] = this->Rate[this->CurCycle]; |
| 612 | } |
| 613 | else if (this->Type == TEST_PNT2 && this->Rate[this->CurCycle] > 0.136) |
| 614 | { |
| 615 | this->Status = PT_COMPLETE; |
| 616 | this->Result = FAIL; |
| 617 | this->Note = PT_INGRESS; |
| 618 | this->Rate[0] = 0.144; |
| 619 | } |
| 620 | else if (this->CurCycle >= PT_CYCLES) |
| 621 | { |
| 622 | this->Status = PT_CYCLE_LIMIT; |
| 623 | this->Result = NORESULT; |
| 624 | this->Note = PT_CYCLE_LIMIT; |
| 625 | this->Rate[0] = 0.0; |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | this->State = PREC_REPRES; |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | |
| 634 | /****************************************************************** |
| 635 | * Function Name: |
| 636 | * |
| 637 | * |
| 638 | * Args / Parameters: |
| 639 | * |
| 640 | * |
| 641 | * Description: |
| 642 | * |
| 643 | * |
| 644 | * |
| 645 | * Returns: |
| 646 | * |
| 647 | */ |
| 648 | void Contraction (uint8_t first) { |
| 649 | printf("CH: %d | State: %s | Test: %d\n", this->ID, PTestName[this->State - 3], this->Type); |
| 650 | |
| 651 | if (this->Type == TEST_PNT1 && this->Rate[this->CurCycle] < 0.066) |
| 652 | { |
| 653 | this->Status = PT_COMPLETE; |
| 654 | this->Result = PASS; |
| 655 | this->Note = PT_NO_ERROR; |
| 656 | this->Rate[0] = 0.0; |
| 657 | } |
| 658 | else if (this->Type == TEST_PNT2 && this->Rate[this->CurCycle] < 0.132) |
| 659 | { |
| 660 | this->Status = PT_COMPLETE; |
| 661 | this->Result = PASS; |
| 662 | this->Note = PT_NO_ERROR; |
| 663 | this->Rate[0] = 0.0; |
| 664 | } |
| 665 | else if (this->CurCycle >= PT_CYCLES) |
| 666 | { |
| 667 | this->Status = PT_CYCLE_LIMIT; |
| 668 | this->Result = NORESULT; |
| 669 | this->Note = PT_CYCLE_LIMIT; |
| 670 | this->Rate[0] = 0.0; |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | this->State = PREC_REPRES; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | |
| 679 | /****************************************************************** |
| 680 | * Function Name: |
| 681 | * |
| 682 | * |
| 683 | * Args / Parameters: |
| 684 | * |
| 685 | * |
| 686 | * Description: |
| 687 | * |
| 688 | * |
| 689 | * |
| 690 | * Returns: |
| 691 | * |
| 692 | */ |
| 693 | void Steady (uint8_t first) |
| 694 | { |
| 695 | this->Status = PT_COMPLETE; |
| 696 | this->Note = PT_NO_ERROR; |
| 697 | printf("CH: %d | State: %s | Test: %d\n", this->ID, PTestName[this->State - 3], this->Type); |
| 698 | |
| 699 | if (this->Type == TEST_PNT1 && this->Rate[this->CurCycle] > 0.075) |
| 700 | { |
| 701 | this->Result = FAIL; |
| 702 | this->Rate[0] = this->Rate[this->CurCycle]; |
| 703 | } |
| 704 | else if (this->Type == TEST_PNT1 && this->Rate[this->CurCycle] > 0.068) |
| 705 | { |
| 706 | this->Result = FAIL; |
| 707 | this->Rate[0] = 0.072; |
| 708 | } |
| 709 | else if (this->Type == TEST_PNT2 && this->Rate[this->CurCycle] > 0.150) |
| 710 | { |
| 711 | this->Result = FAIL; |
| 712 | this->Rate[0] = this->Rate[this->CurCycle]; |
| 713 | } |
| 714 | else if (this->Type == TEST_PNT2 && this->Rate[this->CurCycle] > 0.136) |
| 715 | { |
| 716 | this->Result = FAIL; |
| 717 | this->Rate[0] = 0.144; |
| 718 | } |
| 719 | else |
| 720 | { |
| 721 | this->Result = PASS; |
| 722 | this->Rate[0] = 0.0; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | |
| 727 | /****************************************************************** |
| 728 | * Function Name: |
| 729 | * |
| 730 | * |
| 731 | * Args / Parameters: |
| 732 | * |
| 733 | * |
| 734 | * Description: |
| 735 | * |
| 736 | * |
| 737 | * |
| 738 | * Returns: |
| 739 | * |
| 740 | */ |
| 741 | void TestInitialize(ElecTestingStr *curTest) |
| 742 | { |
| 743 | this = curTest; |
| 744 | this->Type = 0; |
| 745 | this->Resil = 0; |
| 746 | this->TestTime = 0; |
| 747 | this->MaxCycles = 0; |
| 748 | this->HighPressure = DEFAULT_HIGH_PRES; |
| 749 | this->LowPressure = DEFAULT_LOW_PRES; |
| 750 | TestReset(this); |
| 751 | } |
| 752 | |
| 753 | |
| 754 | /****************************************************************** |
| 755 | * Function Name: |
| 756 | * |
| 757 | * |
| 758 | * Args / Parameters: |
| 759 | * |
| 760 | * |
| 761 | * Description: |
| 762 | * |
| 763 | * |
| 764 | * |
| 765 | * Returns: |
| 766 | * |
| 767 | */ |
| 768 | void TestReset(ElecTestingStr *curTest) |
| 769 | { |
| 770 | this = curTest; |
| 771 | this->State = GPH3_REPRES; |
| 772 | this->PreviousState = PT_NOSTATE; |
| 773 | this->Status = PT_INACTIVE; |
| 774 | this->Result = NORESULT; |
| 775 | this->Rate[0] = 0.0; |
| 776 | this->Rate[1] = 0.0; |
| 777 | this->Rate[2] = 0.0; |
| 778 | this->Rate[3] = 0.0; |
| 779 | this->Note = 0; |
| 780 | this->StartTime = 0; |
| 781 | this->CurCycle = 0; |
| 782 | this->Turbine = 0; |
| 783 | this->ShuntValve = 0; |
| 784 | this->RdyFlag = 0; |
| 785 | this->PresFlag = 0; |
| 786 | } |
| 787 | |
| 788 | |
| 789 | /****************************************************************** |
| 790 | * Function Name: |
| 791 | * |
| 792 | * |
| 793 | * Args / Parameters: |
| 794 | * |
| 795 | * |
| 796 | * Description: |
| 797 | * |
| 798 | * |
| 799 | * |
| 800 | * Returns: |
| 801 | * |
| 802 | */ |
| 803 | void TestConfig(ElecTestingStr *curTest, uint8_t type, uint16_t resil, uint8_t id, |
| 804 | uint8_t highPres, uint8_t lowPres) |
| 805 | { |
| 806 | |
| 807 | this = curTest; |
| 808 | this->Type = type; |
| 809 | this->Resil = resil; |
| 810 | this->ID = id; |
| 811 | this->HighPressure = highPres; |
| 812 | this->LowPressure = lowPres; |
| 813 | |
| 814 | if (this->Type == TEST_GPH3) |
| 815 | { |
| 816 | this->State = GPH3_REPRES; |
| 817 | this->MaxCycles = this->Resil / 100; |
| 818 | this->TestTime = (Ms)(this->Resil / 2); |
| 819 | if (this->MaxCycles > 8) |
| 820 | this->MaxCycles = 8; |
| 821 | this->MaxCycles = 10 - this->MaxCycles; |
| 822 | } |
| 823 | else |
| 824 | { |
| 825 | this->State = PREC_REPRES; |
| 826 | this->TestTime = (Ms)((float)this->Resil * 27.97); |
| 827 | this->MaxCycles = 1; |
| 828 | if (this->Type == TEST_PNT1) |
| 829 | this->TestTime *= 2; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | /*** BeginHeader */ |
| 834 | #endif |
| 835 | /*** EndHeader */ |
| 836 | |
| 837 |