| 437 | } |
| 438 | |
| 439 | void |
| 440 | FrequencyCorrectionDialog::recalcALOS(void) |
| 441 | { |
| 442 | if (!this->haveOrbit) { |
| 443 | this->haveALOS = false; |
| 444 | } else { |
| 445 | if (!this->haveALOS |
| 446 | || timercmp(&this->timeStamp, &this->losTime, >=)) { |
| 447 | xyz_t azel; |
| 448 | SUDOUBLE window; |
| 449 | SUDOUBLE searchWindow; |
| 450 | struct timeval delta, search; |
| 451 | this->haveALOS = false; |
| 452 | |
| 453 | // Get current prediction |
| 454 | if (!sgdp4_prediction_update(&this->prediction, &this->timeStamp)) |
| 455 | return; |
| 456 | |
| 457 | sgdp4_prediction_get_azel(&this->prediction, &azel); |
| 458 | |
| 459 | searchWindow = qBound( |
| 460 | FREQUENCY_CORRECTION_DIALOG_TIME_WINDOW_MIN, // 1 day |
| 461 | 3 * 86400.0 / this->currentOrbit.rev, |
| 462 | FREQUENCY_CORRECTION_DIALOG_TIME_WINDOW_MAX); // 30 days |
| 463 | |
| 464 | window = searchWindow; |
| 465 | |
| 466 | if (azel.elevation > 0) { |
| 467 | // For visible satellites, the strategy is as follows: |
| 468 | // 1. In the current timeStamp, look for the next LOS event. |
| 469 | // 2. Compute the lapse between the current timeStamp and the LOS |
| 470 | // 3. Perform exponentially bigger backward time steps, of initial |
| 471 | // length equal to that length |
| 472 | // 4. If the satellite is now invisible, assume that the next |
| 473 | // AOS event is the corresponding to the current pass. |
| 474 | |
| 475 | // Step 1 |
| 476 | if (!sgdp4_prediction_find_los( |
| 477 | &this->prediction, |
| 478 | &this->timeStamp, |
| 479 | window, |
| 480 | &this->losTime)) |
| 481 | return; // Something went wrong |
| 482 | |
| 483 | // Step 2 |
| 484 | timersub(&this->losTime, &this->timeStamp, &delta); |
| 485 | delta.tv_sec += 1; |
| 486 | |
| 487 | // Step 3 |
| 488 | do { |
| 489 | timersub(&this->losTime, &delta, &search); |
| 490 | SigDiggerHelpers::timerdup(&delta); |
| 491 | |
| 492 | if (!sgdp4_prediction_update(&this->prediction, &search)) |
| 493 | break; |
| 494 | |
| 495 | sgdp4_prediction_get_azel(&this->prediction, &azel); |
| 496 | } while (azel.elevation > 0 |