6#include "schedulermodulestate.h"
7#include "schedulerjob.h"
8#include <ekos_scheduler_debug.h>
9#include "schedulerprocess.h"
10#include "schedulerjob.h"
11#include "kstarsdata.h"
15#define MAX_FAILURE_ATTEMPTS 5
20QDateTime SchedulerModuleState::m_Dawn, SchedulerModuleState::m_Dusk, SchedulerModuleState::m_PreDawnDateTime;
21GeoLocation *SchedulerModuleState::storedGeo =
nullptr;
23SchedulerModuleState::SchedulerModuleState() {}
25void SchedulerModuleState::init()
30 enablePreemptiveShutdown(SchedulerModuleState::getLocalTime());
32 setIterationSetup(
false);
33 setupNextIteration(RUN_WAKEUP, 10);
36void SchedulerModuleState::setCurrentProfile(
const QString &
newName,
bool signal)
38 bool changed = (
newName != m_currentProfile);
44 changed = (m_currentProfile != m_profiles.
first());
45 m_currentProfile = m_profiles.
first();
48 if (signal && changed)
49 emit currentProfileChanged();
54 QString selected = currentProfile();
61 setCurrentProfile(selected,
false);
62 emit profilesChanged();
65void SchedulerModuleState::setActiveJob(SchedulerJob *
newActiveJob)
70void SchedulerModuleState::updateJobStage(SchedulerJobStage stage)
72 if (activeJob() ==
nullptr)
74 emit jobStageChanged(SCHEDSTAGE_IDLE);
78 activeJob()->setStage(stage);
79 emit jobStageChanged(stage);
87 for (
const auto &
oneJob : jobs())
105void SchedulerModuleState::setStartupState(StartupState state)
107 if (m_startupState != state)
109 m_startupState = state;
110 emit startupStateChanged(state);
114void SchedulerModuleState::setShutdownState(ShutdownState state)
116 if (m_shutdownState != state)
118 m_shutdownState = state;
119 emit shutdownStateChanged(state);
123void SchedulerModuleState::setParkWaitState(ParkWaitState state)
125 if (m_parkWaitState != state)
127 m_parkWaitState = state;
128 emit parkWaitStateChanged(state);
132bool SchedulerModuleState::removeJob(
const int currentRow)
139 SchedulerJob *
const job = jobs().at(currentRow);
142 if (job == m_activeJob)
144 emit newLog(
i18n(
"Cannot delete currently running job '%1'.", job->getName()));
147 else if (job ==
nullptr || (activeJob() ==
nullptr && schedulerState() != SCHEDULER_IDLE))
150 emit newLog(
i18n(
"Cannot delete job. Scheduler state: %1",
151 getSchedulerStatusString(schedulerState(),
true)));
162 if (currentPosition() >= jobs().count())
163 setCurrentPosition(jobs().count() - 1);
175void SchedulerModuleState::disablePreemptiveShutdown()
177 m_preemptiveShutdownWakeupTime =
QDateTime();
180const QDateTime &SchedulerModuleState::preemptiveShutdownWakeupTime()
const
182 return m_preemptiveShutdownWakeupTime;
185bool SchedulerModuleState::preemptiveShutdown()
const
187 return m_preemptiveShutdownWakeupTime.
isValid();
190void SchedulerModuleState::setEkosState(EkosState state)
192 if (m_ekosState != state)
196 emit ekosStateChanged(state);
200bool SchedulerModuleState::increaseEkosConnectFailureCount()
202 return (++m_ekosConnectFailureCount <= MAX_FAILURE_ATTEMPTS);
205bool SchedulerModuleState::increaseParkingCapFailureCount()
207 return (++m_parkingCapFailureCount <= MAX_FAILURE_ATTEMPTS);
210bool SchedulerModuleState::increaseParkingMountFailureCount()
212 return (++m_parkingMountFailureCount <= MAX_FAILURE_ATTEMPTS);
215bool SchedulerModuleState::increaseParkingDomeFailureCount()
217 return (++m_parkingDomeFailureCount <= MAX_FAILURE_ATTEMPTS);
220void SchedulerModuleState::resetFailureCounters()
222 resetIndiConnectFailureCount();
223 resetEkosConnectFailureCount();
224 resetFocusFailureCount();
225 resetGuideFailureCount();
226 resetAlignFailureCount();
227 resetCaptureFailureCount();
230bool SchedulerModuleState::increaseIndiConnectFailureCount()
232 return (++m_indiConnectFailureCount <= MAX_FAILURE_ATTEMPTS);
235bool SchedulerModuleState::increaseCaptureFailureCount()
237 return (++m_captureFailureCount <= MAX_FAILURE_ATTEMPTS);
240bool SchedulerModuleState::increaseFocusFailureCount()
242 return (++m_focusFailureCount <= MAX_FAILURE_ATTEMPTS);
245bool SchedulerModuleState::increaseGuideFailureCount()
247 return (++m_guideFailureCount <= MAX_FAILURE_ATTEMPTS);
250bool SchedulerModuleState::increaseAlignFailureCount()
252 return (++m_alignFailureCount <= MAX_FAILURE_ATTEMPTS);
255void SchedulerModuleState::setIndiState(INDIState state)
257 if (m_indiState != state)
261 emit indiStateChanged(state);
265qint64 SchedulerModuleState::getCurrentOperationMsec()
const
267 if (!currentOperationTimeStarted)
return 0;
268 return currentOperationTime.
msecsTo(KStarsData::Instance()->ut());
271void SchedulerModuleState::startCurrentOperationTimer()
273 currentOperationTimeStarted =
true;
274 currentOperationTime = KStarsData::Instance()->ut();
277void SchedulerModuleState::cancelGuidingTimer()
279 m_restartGuidingInterval = -1;
283bool SchedulerModuleState::isGuidingTimerActive()
285 return (m_restartGuidingInterval > 0 &&
286 m_restartGuidingTime.
msecsTo(KStarsData::Instance()->ut()) >= 0);
289void SchedulerModuleState::startGuidingTimer(
int milliseconds)
292 m_restartGuidingTime = KStarsData::Instance()->ut();
301 return *storedLocalTime;
302 return KStarsData::Instance()->geo()->UTtoLT(KStarsData::Instance()->clock()->utc());
310 startup = getLocalTime();
327 dawn = getGeo()->UTtoLT(ksal.getDate().addSecs((ksal.getDawnAstronomicalTwilight() * 24.0 + Options::dawnOffset()) *
331 dusk = getGeo()->UTtoLT(ksal.getDate().addSecs((ksal.getDuskAstronomicalTwilight() * 24.0 + Options::duskOffset()) *
337 getGeo()->lng()->Degrees());
353 dawn = getGeo()->UTtoLT(ksal->getDate().
addSecs((ksal->getDawnAstronomicalTwilight() * 24.0 + Options::dawnOffset()) *
358 dusk = getGeo()->UTtoLT(ksal->getDate().
addSecs((ksal->getDuskAstronomicalTwilight() * 24.0 + Options::duskOffset()) *
370void SchedulerModuleState::calculateDawnDusk()
372 calculateDawnDusk(
QDateTime(), m_Dawn, m_Dusk);
374 m_PreDawnDateTime = m_Dawn.addSecs(-60.0 *
abs(Options::preDawnTime()));
375 emit updateNightTime();
382 return KStarsData::Instance()->geo();
385bool SchedulerModuleState::hasGeo()
387 return storedGeo !=
nullptr;
390void SchedulerModuleState::setupNextIteration(SchedulerTimerState
nextState)
392 setupNextIteration(
nextState, m_UpdatePeriodMs);
397 if (iterationSetup())
400 <<
QString(
"Multiple setupNextIteration calls: current %1 %2, previous %3 %4")
405 if (iterationTimer().isActive())
409 iterationTimer().
stop();
411 iterationTimer().
start(timerInterval());
418 setIterationSetup(
true);
421uint SchedulerModuleState::maxFailureAttempts()
423 return MAX_FAILURE_ATTEMPTS;
426void SchedulerModuleState::clearLog()
432bool SchedulerModuleState::checkRepeatSequence()
434 return (!Options::rememberJobProgress() && Options::schedulerRepeatEverything() &&
435 (Options::schedulerExecutionSequencesLimit() == 0
436 || sequenceExecutionCounter()) < Options::schedulerExecutionSequencesLimit());
Contains all relevant information for specifying a location on Earth: City Name, State/Province name,...
A class that implements methods to find sun rise, sun set, twilight begin / end times,...
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
KStarsDateTime addSecs(double s) const
The SchedulerState class holds all attributes defining the scheduler's state.
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
bool isValid() const const
qint64 msecsTo(const QDateTime &other) const const
bool removeOne(const AT &t)
QString arg(Args &&... args) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const