Changeset View
Changeset View
Standalone View
Standalone View
kstars/ekos/scheduler/scheduler.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 179 Lines • ▼ Show 20 Line(s) | 46 | { | |||
---|---|---|---|---|---|
180 | connect(queueTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &Scheduler::queueTableSelectionChanged); | 180 | connect(queueTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &Scheduler::queueTableSelectionChanged); | ||
181 | connect(queueTable, &QAbstractItemView::clicked, this, &Scheduler::clickQueueTable); | 181 | connect(queueTable, &QAbstractItemView::clicked, this, &Scheduler::clickQueueTable); | ||
182 | connect(queueTable, &QAbstractItemView::doubleClicked, this, &Scheduler::loadJob); | 182 | connect(queueTable, &QAbstractItemView::doubleClicked, this, &Scheduler::loadJob); | ||
183 | 183 | | |||
184 | startB->setIcon(QIcon::fromTheme("media-playback-start")); | 184 | startB->setIcon(QIcon::fromTheme("media-playback-start")); | ||
185 | startB->setAttribute(Qt::WA_LayoutUsesWidgetRect); | 185 | startB->setAttribute(Qt::WA_LayoutUsesWidgetRect); | ||
186 | pauseB->setIcon(QIcon::fromTheme("media-playback-pause")); | 186 | pauseB->setIcon(QIcon::fromTheme("media-playback-pause")); | ||
187 | pauseB->setAttribute(Qt::WA_LayoutUsesWidgetRect); | 187 | pauseB->setAttribute(Qt::WA_LayoutUsesWidgetRect); | ||
188 | pauseB->setCheckable(false); | ||||
188 | 189 | | |||
189 | connect(startB, &QPushButton::clicked, this, &Scheduler::toggleScheduler); | 190 | connect(startB, &QPushButton::clicked, this, &Scheduler::toggleScheduler); | ||
190 | connect(pauseB, &QPushButton::clicked, this, &Scheduler::pause); | 191 | connect(pauseB, &QPushButton::clicked, this, &Scheduler::pause); | ||
191 | 192 | | |||
192 | connect(queueSaveAsB, &QPushButton::clicked, this, &Scheduler::saveAs); | 193 | connect(queueSaveAsB, &QPushButton::clicked, this, &Scheduler::saveAs); | ||
193 | connect(queueSaveB, &QPushButton::clicked, this, &Scheduler::save); | 194 | connect(queueSaveB, &QPushButton::clicked, this, &Scheduler::save); | ||
194 | connect(queueLoadB, &QPushButton::clicked, this, &Scheduler::load); | 195 | connect(queueLoadB, &QPushButton::clicked, this, &Scheduler::load); | ||
195 | 196 | | |||
▲ Show 20 Lines • Show All 1084 Lines • ▼ Show 20 Line(s) | 1264 | case SCHEDULER_IDLE: | |||
1280 | qCInfo(KSTARS_EKOS_SCHEDULER) << "Scheduler is starting..."; | 1281 | qCInfo(KSTARS_EKOS_SCHEDULER) << "Scheduler is starting..."; | ||
1281 | 1282 | | |||
1282 | /* Update UI to reflect startup */ | 1283 | /* Update UI to reflect startup */ | ||
1283 | pi->startAnimation(); | 1284 | pi->startAnimation(); | ||
1284 | sleepLabel->hide(); | 1285 | sleepLabel->hide(); | ||
1285 | startB->setIcon(QIcon::fromTheme("media-playback-stop")); | 1286 | startB->setIcon(QIcon::fromTheme("media-playback-stop")); | ||
1286 | startB->setToolTip(i18n("Stop Scheduler")); | 1287 | startB->setToolTip(i18n("Stop Scheduler")); | ||
1287 | pauseB->setEnabled(true); | 1288 | pauseB->setEnabled(true); | ||
1289 | pauseB->setChecked(false); | ||||
1288 | 1290 | | |||
1289 | /* Disable edit-related buttons */ | 1291 | /* Disable edit-related buttons */ | ||
1290 | queueLoadB->setEnabled(false); | 1292 | queueLoadB->setEnabled(false); | ||
1291 | addToQueueB->setEnabled(false); | 1293 | addToQueueB->setEnabled(false); | ||
1292 | setJobManipulation(false, false); | 1294 | setJobManipulation(false, false); | ||
1293 | mosaicB->setEnabled(false); | 1295 | mosaicB->setEnabled(false); | ||
1294 | evaluateOnlyB->setEnabled(false); | 1296 | evaluateOnlyB->setEnabled(false); | ||
1295 | startupB->setEnabled(false); | 1297 | startupB->setEnabled(false); | ||
1296 | shutdownB->setEnabled(false); | 1298 | shutdownB->setEnabled(false); | ||
1297 | 1299 | | |||
1298 | /* Reset and re-evaluate all scheduler jobs, then start the Scheduler */ | 1300 | /* Reset and re-evaluate all scheduler jobs, then start the Scheduler */ | ||
1299 | startJobEvaluation(); | 1301 | startJobEvaluation(); | ||
1300 | state = SCHEDULER_RUNNING; | 1302 | state = SCHEDULER_RUNNING; | ||
1301 | emit newStatus(state); | 1303 | emit newStatus(state); | ||
1302 | schedulerTimer.start(); | 1304 | schedulerTimer.start(); | ||
1303 | 1305 | | |||
1306 | appendLogText(i18n("Scheduler started.")); | ||||
1304 | qCDebug(KSTARS_EKOS_SCHEDULER) << "Scheduler started."; | 1307 | qCDebug(KSTARS_EKOS_SCHEDULER) << "Scheduler started."; | ||
1305 | break; | 1308 | break; | ||
1306 | 1309 | | |||
1307 | case SCHEDULER_PAUSED: | 1310 | case SCHEDULER_PAUSED: | ||
1308 | /* Update UI to reflect resume */ | 1311 | /* Update UI to reflect resume */ | ||
1309 | startB->setIcon(QIcon::fromTheme("media-playback-stop")); | 1312 | startB->setIcon(QIcon::fromTheme("media-playback-stop")); | ||
1310 | startB->setToolTip(i18n("Stop Scheduler")); | 1313 | startB->setToolTip(i18n("Stop Scheduler")); | ||
1314 | pauseB->setEnabled(true); | ||||
1315 | pauseB->setCheckable(false); | ||||
1316 | pauseB->setChecked(false); | ||||
1311 | 1317 | | |||
1312 | /* Edit-related buttons are still disabled */ | 1318 | /* Edit-related buttons are still disabled */ | ||
1313 | 1319 | | |||
1314 | /* The end-user cannot update the schedule, don't re-evaluate jobs. Timer schedulerTimer is already running. */ | 1320 | /* The end-user cannot update the schedule, don't re-evaluate jobs. Timer schedulerTimer is already running. */ | ||
1315 | state = SCHEDULER_RUNNING; | 1321 | state = SCHEDULER_RUNNING; | ||
1316 | emit newStatus(state); | 1322 | emit newStatus(state); | ||
1323 | schedulerTimer.start(); | ||||
1317 | 1324 | | |||
1318 | qCDebug(KSTARS_EKOS_SCHEDULER) << "Scheduler paused."; | 1325 | appendLogText(i18n("Scheduler resuming.")); | ||
1326 | qCDebug(KSTARS_EKOS_SCHEDULER) << "Scheduler resuming."; | ||||
1319 | break; | 1327 | break; | ||
1320 | 1328 | | |||
1321 | default: | 1329 | default: | ||
1322 | break; | 1330 | break; | ||
1323 | } | 1331 | } | ||
1324 | } | 1332 | } | ||
1325 | 1333 | | |||
1326 | void Scheduler::pause() | 1334 | void Scheduler::pause() | ||
1327 | { | 1335 | { | ||
1328 | state = SCHEDULER_PAUSED; | 1336 | state = SCHEDULER_PAUSED; | ||
1329 | emit newStatus(state); | 1337 | emit newStatus(state); | ||
1330 | appendLogText(i18n("Scheduler paused.")); | 1338 | appendLogText(i18n("Scheduler pause planned...")); | ||
1331 | pauseB->setEnabled(false); | 1339 | pauseB->setEnabled(false); | ||
1332 | 1340 | | |||
1333 | startB->setIcon(QIcon::fromTheme("media-playback-start")); | 1341 | startB->setIcon(QIcon::fromTheme("media-playback-start")); | ||
1334 | startB->setToolTip(i18n("Resume Scheduler")); | 1342 | startB->setToolTip(i18n("Resume Scheduler")); | ||
1335 | } | 1343 | } | ||
1336 | 1344 | | |||
1345 | void Scheduler::setPaused() | ||||
1346 | { | ||||
1347 | pauseB->setCheckable(true); | ||||
1348 | pauseB->setChecked(true); | ||||
1349 | schedulerTimer.stop(); | ||||
1350 | appendLogText(i18n("Scheduler paused.")); | ||||
1351 | } | ||||
1352 | | ||||
1337 | void Scheduler::setCurrentJob(SchedulerJob *job) | 1353 | void Scheduler::setCurrentJob(SchedulerJob *job) | ||
1338 | { | 1354 | { | ||
1339 | /* Reset job widgets */ | 1355 | /* Reset job widgets */ | ||
1340 | if (currentJob) | 1356 | if (currentJob) | ||
1341 | { | 1357 | { | ||
1342 | currentJob->setStageLabel(nullptr); | 1358 | currentJob->setStageLabel(nullptr); | ||
1343 | } | 1359 | } | ||
1344 | 1360 | | |||
▲ Show 20 Lines • Show All 1588 Lines • ▼ Show 20 Line(s) | 2948 | { | |||
2933 | appendLogText(i18n("Shutdown script failed, aborting...")); | 2949 | appendLogText(i18n("Shutdown script failed, aborting...")); | ||
2934 | shutdownState = SHUTDOWN_ERROR; | 2950 | shutdownState = SHUTDOWN_ERROR; | ||
2935 | } | 2951 | } | ||
2936 | } | 2952 | } | ||
2937 | 2953 | | |||
2938 | bool Scheduler::checkStatus() | 2954 | bool Scheduler::checkStatus() | ||
2939 | { | 2955 | { | ||
2940 | if (state == SCHEDULER_PAUSED) | 2956 | if (state == SCHEDULER_PAUSED) | ||
2941 | return true; | 2957 | { | ||
2958 | if (currentJob == nullptr) | ||||
2959 | { | ||||
2960 | setPaused(); | ||||
2961 | return false; | ||||
2962 | } | ||||
2963 | switch (currentJob->getState()) { | ||||
2964 | case SchedulerJob::JOB_BUSY: | ||||
2965 | // do nothing | ||||
2966 | break; | ||||
2967 | case SchedulerJob::JOB_COMPLETE: | ||||
2968 | // start finding next job before pausing | ||||
2969 | break; | ||||
2970 | default: | ||||
2971 | // in all other cases pause | ||||
2972 | setPaused(); | ||||
2973 | break; | ||||
2974 | } | ||||
2975 | } | ||||
2942 | 2976 | | |||
2943 | // #1 If no current job selected, let's check if we need to shutdown or evaluate jobs | 2977 | // #1 If no current job selected, let's check if we need to shutdown or evaluate jobs | ||
2944 | if (currentJob == nullptr) | 2978 | if (currentJob == nullptr) | ||
2945 | { | 2979 | { | ||
2946 | // #2.1 If shutdown is already complete or in error, we need to stop | 2980 | // #2.1 If shutdown is already complete or in error, we need to stop | ||
2947 | if (shutdownState == SHUTDOWN_COMPLETE || shutdownState == SHUTDOWN_ERROR) | 2981 | if (shutdownState == SHUTDOWN_COMPLETE || shutdownState == SHUTDOWN_ERROR) | ||
2948 | { | 2982 | { | ||
2949 | // If INDI is not done disconnecting, try again later | 2983 | // If INDI is not done disconnecting, try again later | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 3043 | { | |||
3030 | // #6.1 Check if park wait procedure is in progress - in the case we're waiting for a distant job | 3064 | // #6.1 Check if park wait procedure is in progress - in the case we're waiting for a distant job | ||
3031 | if (checkParkWaitState() == false) | 3065 | if (checkParkWaitState() == false) | ||
3032 | return false; | 3066 | return false; | ||
3033 | 3067 | | |||
3034 | // #7 Check if startup procedure Phase #2 is complete (Unparking phase) | 3068 | // #7 Check if startup procedure Phase #2 is complete (Unparking phase) | ||
3035 | if (startupState > STARTUP_SCRIPT && startupState < STARTUP_ERROR && checkStartupState() == false) | 3069 | if (startupState > STARTUP_SCRIPT && startupState < STARTUP_ERROR && checkStartupState() == false) | ||
3036 | return false; | 3070 | return false; | ||
3037 | 3071 | | |||
3038 | // #8 Execute the job | 3072 | // #8 Check it it already completed (should only happen starting a paused job) | ||
3073 | // Find the next job in this case, otherwise execute the current one | ||||
3074 | if (currentJob->getState() == SchedulerJob::JOB_COMPLETE) | ||||
3075 | findNextJob(); | ||||
3076 | else | ||||
3039 | executeJob(currentJob); | 3077 | executeJob(currentJob); | ||
3040 | } | 3078 | } | ||
3041 | 3079 | | |||
3042 | return true; | 3080 | return true; | ||
3043 | } | 3081 | } | ||
3044 | 3082 | | |||
3045 | void Scheduler::checkJobStage() | 3083 | void Scheduler::checkJobStage() | ||
3046 | { | 3084 | { | ||
3047 | if (state == SCHEDULER_PAUSED) | | |||
3048 | return; | | |||
3049 | | ||||
3050 | Q_ASSERT_X(currentJob, __FUNCTION__, "Actual current job is required to check job stage"); | 3085 | Q_ASSERT_X(currentJob, __FUNCTION__, "Actual current job is required to check job stage"); | ||
3051 | if (!currentJob) | 3086 | if (!currentJob) | ||
3052 | return; | 3087 | return; | ||
3053 | 3088 | | |||
3054 | qCDebug(KSTARS_EKOS_SCHEDULER) << "Checking job stage for" << currentJob->getName() << "startup" << currentJob->getStartupCondition() << currentJob->getStartupTime().toString(currentJob->getDateTimeDisplayFormat()) << "state" << currentJob->getState(); | 3089 | qCDebug(KSTARS_EKOS_SCHEDULER) << "Checking job stage for" << currentJob->getName() << "startup" << currentJob->getStartupCondition() << currentJob->getStartupTime().toString(currentJob->getDateTimeDisplayFormat()) << "state" << currentJob->getState(); | ||
3055 | 3090 | | |||
3056 | QDateTime const now = KStarsData::Instance()->lt(); | 3091 | QDateTime const now = KStarsData::Instance()->lt(); | ||
3057 | 3092 | | |||
▲ Show 20 Lines • Show All 1259 Lines • ▼ Show 20 Line(s) | 4266 | { | |||
4317 | 4352 | | |||
4318 | currentJob->setStage(SchedulerJob::STAGE_FOCUSING); | 4353 | currentJob->setStage(SchedulerJob::STAGE_FOCUSING); | ||
4319 | appendLogText(i18n("Job '%1' is focusing.", currentJob->getName())); | 4354 | appendLogText(i18n("Job '%1' is focusing.", currentJob->getName())); | ||
4320 | currentOperationTime.restart(); | 4355 | currentOperationTime.restart(); | ||
4321 | } | 4356 | } | ||
4322 | 4357 | | |||
4323 | void Scheduler::findNextJob() | 4358 | void Scheduler::findNextJob() | ||
4324 | { | 4359 | { | ||
4360 | if (state == SCHEDULER_PAUSED) | ||||
4361 | { | ||||
4362 | // everything finished, we can pause | ||||
4363 | setPaused(); | ||||
4364 | return; | ||||
4365 | } | ||||
4366 | | ||||
4325 | Q_ASSERT_X(currentJob->getState() == SchedulerJob::JOB_ERROR || | 4367 | Q_ASSERT_X(currentJob->getState() == SchedulerJob::JOB_ERROR || | ||
4326 | currentJob->getState() == SchedulerJob::JOB_ABORTED || | 4368 | currentJob->getState() == SchedulerJob::JOB_ABORTED || | ||
4327 | currentJob->getState() == SchedulerJob::JOB_COMPLETE, | 4369 | currentJob->getState() == SchedulerJob::JOB_COMPLETE, | ||
4328 | __FUNCTION__, "Finding next job requires current to be in error, aborted or complete"); | 4370 | __FUNCTION__, "Finding next job requires current to be in error, aborted or complete"); | ||
4329 | 4371 | | |||
4330 | jobTimer.stop(); | 4372 | jobTimer.stop(); | ||
4331 | 4373 | | |||
4332 | // Reset failed count | 4374 | // Reset failed count | ||
▲ Show 20 Lines • Show All 2357 Lines • ▼ Show 20 Line(s) | 6731 | { | |||
6690 | QVariant guideStatus = guideInterface->property("status"); | 6732 | QVariant guideStatus = guideInterface->property("status"); | ||
6691 | Ekos::GuideState gStatus = static_cast<Ekos::GuideState>(guideStatus.toInt()); | 6733 | Ekos::GuideState gStatus = static_cast<Ekos::GuideState>(guideStatus.toInt()); | ||
6692 | 6734 | | |||
6693 | return gStatus; | 6735 | return gStatus; | ||
6694 | } | 6736 | } | ||
6695 | 6737 | | |||
6696 | void Scheduler::setCaptureStatus(Ekos::CaptureState status) | 6738 | void Scheduler::setCaptureStatus(Ekos::CaptureState status) | ||
6697 | { | 6739 | { | ||
6698 | if (state == SCHEDULER_PAUSED || currentJob == nullptr) | 6740 | if (currentJob == nullptr) | ||
6699 | return; | 6741 | return; | ||
6700 | 6742 | | |||
6701 | qCDebug(KSTARS_EKOS_SCHEDULER) << "Capture State" << Ekos::getCaptureStatusString(status); | 6743 | qCDebug(KSTARS_EKOS_SCHEDULER) << "Capture State" << Ekos::getCaptureStatusString(status); | ||
6702 | 6744 | | |||
6703 | /* If current job is scheduled and has not started yet, wait */ | 6745 | /* If current job is scheduled and has not started yet, wait */ | ||
6704 | if (SchedulerJob::JOB_SCHEDULED == currentJob->getState()) | 6746 | if (SchedulerJob::JOB_SCHEDULED == currentJob->getState()) | ||
6705 | { | 6747 | { | ||
6706 | QDateTime const now = KStarsData::Instance()->lt(); | 6748 | QDateTime const now = KStarsData::Instance()->lt(); | ||
▲ Show 20 Lines • Show All 350 Lines • Show Last 20 Lines |