Commit 31b4be6f authored by Jasem Mutlaq's avatar Jasem Mutlaq
Browse files

+ On INDI connection success, we must always run INDI property check.

+ Calculate predawn limit before a job is run to check it against current local time
+ Set scheduler job score to BAD_SCORE if its startup condition changes to START_AT so that it gets checked against the timer the next time it is polled.
parent 69873ca8
......@@ -686,7 +686,7 @@ void Scheduler::start()
job->setState(SchedulerJob::JOB_IDLE);
job->setStage(SchedulerJob::STAGE_IDLE);
}
}
}
addToQueueB->setEnabled(false);
removeFromQueueB->setEnabled(false);
......@@ -738,6 +738,8 @@ void Scheduler::evaluateJobs()
{
//appendLogText(i18n("%1 observation job is scheduled at %2", job->getName(), job->getStartupTime().toString()));
job->setState(SchedulerJob::JOB_SCHEDULED);
// Since it's scheduled, we need to skip it now and re-check it later since its startup condition changed to START_AT
job->setScore(BAD_SCORE);
continue;
}
else
......@@ -766,6 +768,8 @@ void Scheduler::evaluateJobs()
{
appendLogText(i18n("%1 observation job is scheduled at %2", job->getName(), job->getStartupTime().toString()));
job->setState(SchedulerJob::JOB_SCHEDULED);
// Since it's scheduled, we need to skip it now and re-check it later since its startup condition changed to START_AT
job->setScore(BAD_SCORE);
continue;
}
else
......@@ -1336,6 +1340,26 @@ int16_t Scheduler::getAltitudeScore(SchedulerJob *job, QDateTime when)
return score;
}
double Scheduler::getCurrentMoonSeparation(SchedulerJob *job)
{
// Get target altitude given the time
SkyPoint p = job->getTargetCoords();
QDateTime midnight( KStarsData::Instance()->lt().date(), QTime() );
KStarsDateTime ut = geo->LTtoUT( midnight );
KStarsDateTime myUT = ut.addSecs(KStarsData::Instance()->lt().time().msecsSinceStartOfDay()/1000);
dms LST = geo->GSTtoLST( myUT.gst() );
p.EquatorialToHorizontal( &LST, geo->lat() );
// Update moon
ut = geo->LTtoUT(KStarsData::Instance()->lt());
KSNumbers ksnum(ut.djd());
LST = geo->GSTtoLST( ut.gst() );
moon->updateCoords(&ksnum, true, geo->lat(), &LST);
// Moon/Sky separation p
return moon->angularDistanceTo(&p).Degrees();
}
int16_t Scheduler::getMoonSeparationScore(SchedulerJob *job, QDateTime when)
{
int16_t score=0;
......@@ -1413,6 +1437,7 @@ void Scheduler::calculateDawnDusk()
QTime dusk = QTime(0,0,0).addSecs(Dusk*24*3600);
appendLogText(i18n("Dawn is at %1, Dusk is at %2, and current time is %3", dawn.toString(), dusk.toString(), now.toString()));
}
void Scheduler::executeJob(SchedulerJob *job)
......@@ -1421,6 +1446,8 @@ void Scheduler::executeJob(SchedulerJob *job)
currentJob->setState(SchedulerJob::JOB_BUSY);
updatePreDawn();
// No need to continue evaluating jobs as we already have one.
disconnect(KStars::Instance()->data()->clock(), SIGNAL(timeAdvanced()), this, SLOT(checkStatus()));
......@@ -1489,8 +1516,8 @@ bool Scheduler::checkINDIState()
QDBusReply<int> isINDIConnected = ekosInterface->call(QDBus::AutoDetect,"getINDIConnectionStatus");
if (isINDIConnected.value()== EkosManager::STATUS_SUCCESS)
{
indiState = INDI_READY;
return true;
indiState = INDI_PROPERTY_CHECK;
return false;
}
else
{
......@@ -1920,11 +1947,11 @@ void Scheduler::checkJobStage()
SkyPoint p = currentJob->getTargetCoords();
p.EquatorialToHorizontal(KStarsData::Instance()->lst(), geo->lat());
double moonScore = getMoonSeparationScore(currentJob, KStarsData::Instance()->lt());
double moonSeparation = getCurrentMoonSeparation(currentJob);
if (moonScore < 0)
if (moonSeparation < currentJob->getMinMoonSeparation())
{
appendLogText(i18n("Current moon separation is lower than %1 minimum constraint (%2 degrees), aborting job...", currentJob->getName(),
appendLogText(i18n("Current moon separation (%1 degrees) is lower than %2 minimum constraint (%3 degrees), aborting job...", moonSeparation, currentJob->getName(),
currentJob->getMinMoonSeparation()));
currentJob->setState(SchedulerJob::JOB_ABORTED);
......@@ -1934,12 +1961,7 @@ void Scheduler::checkJobStage()
}
}
// #4 Check if we're not at dawn
double earlyDawn = Dawn - Options::preDawnTime()/(60.0 * 24.0);
int dayOffset=0;
if (KStarsData::Instance()->lt().time().hour() > 12)
dayOffset=1;
QDateTime preDawnDateTime(KStarsData::Instance()->lt().date().addDays(dayOffset), QTime::fromMSecsSinceStartOfDay(earlyDawn * 24 * 3600 * 1000));
// #4 Check if we're not at dawn
if (KStarsData::Instance()->lt() > preDawnDateTime)
{
......@@ -3049,6 +3071,16 @@ void Scheduler::clearScriptURL()
}
}
void Scheduler::updatePreDawn()
{
double earlyDawn = Dawn - Options::preDawnTime()/(60.0 * 24.0);
int dayOffset=0;
if (KStarsData::Instance()->lt().time().hour() > 12)
dayOffset=1;
preDawnDateTime.setDate(KStarsData::Instance()->lt().date().addDays(dayOffset));
preDawnDateTime.setTime(QTime::fromMSecsSinceStartOfDay(earlyDawn * 24 * 3600 * 1000));
}
}
......@@ -345,6 +345,18 @@ private:
*/
double findAltitude(const SkyPoint & target, const QDateTime when);
/**
* @brief getCurrentMoonSeparation Get current moon separation in degrees at current time for the given job
* @param job scheduler job
* @return Separation in degrees
*/
double getCurrentMoonSeparation(SchedulerJob *job);
/**
* @brief updatePreDawn Update predawn time depending on current time and user offset
*/
void updatePreDawn();
/**
* @brief estimateJobTime Estimates the time the job takes to complete based on the sequence file and what modules to utilize during the observation run.
* @param job target job
......@@ -395,6 +407,7 @@ private:
QProcess scriptProcess; // Startup and Shutdown scripts process
double Dawn, Dusk; // Store day fraction of dawn and dusk to calculate dark skies range
QDateTime preDawnDateTime; // Pre-dawn is where we stop all jobs, it is a user-configurable value before Dawn.
bool mDirty; // Was job modified and needs saving?
IPState weatherStatus; // Keep watch of weather status
QTimer weatherTimer; // Call checkWeather when weatherTimer time expires. It is equal to the UpdatePeriod time in INDI::Weather device.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment