7#include "remoteastrometryparser.h"
10#include "ekos_align_debug.h"
12#include "indi/clientmanager.h"
13#include "indi/driverinfo.h"
14#include "indi/guimanager.h"
15#include "indi/indidevice.h"
23RemoteAstrometryParser::RemoteAstrometryParser() : AstrometryParser()
27bool RemoteAstrometryParser::init()
29 if (m_RemoteAstrometry ==
nullptr)
32 i18n(
"Cannot set solver to remote. The Ekos equipment profile must include the astrometry Auxiliary driver."));
39void RemoteAstrometryParser::verifyIndexFiles(
double,
double)
43bool RemoteAstrometryParser::startSolver(
const QString &filename,
const QStringList &args,
bool generated)
45 INDI_UNUSED(generated);
50 align->appendLogText(
i18n(
"Cannot open file %1 for reading.", filename));
55 auto solverSwitch = m_RemoteAstrometry->getProperty(
"ASTROMETRY_SOLVER").getSwitch();
56 auto solverBLOB = m_RemoteAstrometry->getProperty(
"ASTROMETRY_DATA").getBLOB();
58 if (solverSwitch->isEmpty() || solverBLOB->isEmpty())
60 align->appendLogText(
i18n(
"Failed to find solver properties."));
68 auto enableSW = solverSwitch->findWidgetByName(
"ASTROMETRY_SOLVER_ENABLE");
69 if (enableSW->getState() == ISS_OFF)
71 solverSwitch->reset();
72 enableSW->setState(ISS_ON);
73 m_RemoteAstrometry->sendNewProperty(solverSwitch);
77 auto bp = solverBLOB->at(0);
79 bp->setBlobLen(fp.size());
80 bp->setSize(fp.size());
82 bp->setBlob(
static_cast<uint8_t *
>(realloc(bp->getBlob(), bp->getSize())));
83 if (bp->getBlob() ==
nullptr)
85 align->appendLogText(
i18n(
"Not enough memory for file %1.", filename));
91 memcpy(bp->blob, fp.readAll().constData(), bp->size);
95 m_RemoteAstrometry->getDriverInfo()->getClientManager()->startBlob(solverBLOB->getDeviceName(), solverBLOB->getName(),
98 m_RemoteAstrometry->getDriverInfo()->getClientManager()->sendOneBlob(bp);
100 m_RemoteAstrometry->getDriverInfo()->getClientManager()->finishBlob();
102 align->appendLogText(
i18n(
"Starting remote solver..."));
106bool RemoteAstrometryParser::sendArgs(
const QStringList &args)
108 auto solverSettings = m_RemoteAstrometry->getBaseDevice().getText(
"ASTROMETRY_SETTINGS");
112 align->appendLogText(
i18n(
"Failed to find solver settings."));
120 if (Options::astrometryDetectParity() && args.
contains(
"parity") ==
false &&
125 for (
auto it : solverSettings)
131 if (it.isNameMatch(
"ASTROMETRY_SETTINGS_OPTIONS"))
135 m_RemoteAstrometry->sendNewProperty(solverSettings);
136 INDI_D *guiDevice = GUIManager::Instance()->findGUIDevice(m_RemoteAstrometry->getDeviceName());
138 guiDevice->updateTextGUI(solverSettings);
143void RemoteAstrometryParser::setEnabled(
bool enable)
145 auto solverSwitch = m_RemoteAstrometry->getBaseDevice().getSwitch(
"ASTROMETRY_SOLVER");
150 auto enableSW = solverSwitch.findWidgetByName(
"ASTROMETRY_SOLVER_ENABLE");
151 auto disableSW = solverSwitch.findWidgetByName(
"ASTROMETRY_SOLVER_DISABLE");
153 if (!enableSW || !disableSW)
156 if (enable && enableSW->getState() == ISS_OFF)
158 solverSwitch.reset();
159 enableSW->setState(ISS_ON);
160 m_RemoteAstrometry->sendNewProperty(solverSwitch);
161 solverRunning =
true;
162 qCDebug(KSTARS_EKOS_ALIGN) <<
"Enabling remote solver...";
164 else if (enable ==
false && disableSW->s == ISS_OFF)
166 solverSwitch.reset();
167 disableSW->setState(ISS_ON);
168 m_RemoteAstrometry->sendNewProperty(solverSwitch);
169 solverRunning =
false;
170 qCDebug(KSTARS_EKOS_ALIGN) <<
"Disabling remote solver...";
174bool RemoteAstrometryParser::setCCD(
const QString &ccd)
178 if (!m_RemoteAstrometry)
181 auto activeDevices = m_RemoteAstrometry->getBaseDevice().getText(
"ACTIVE_DEVICES");
186 auto activeCCD = activeDevices.findWidgetByName(
"ACTIVE_CCD");
192 if (
QString(activeCCD->getText()) == ccd)
196 m_RemoteAstrometry->sendNewProperty(activeDevices);
201bool RemoteAstrometryParser::stopSolver()
203 if (solverRunning ==
false)
207 auto svp = m_RemoteAstrometry->getProperty(
"ASTROMETRY_SOLVER").getSwitch();
211 auto disableSW = svp->findWidgetByName(
"ASTROMETRY_SOLVER_DISABLE");
212 if (disableSW->getState() == ISS_OFF)
215 disableSW->setState(ISS_ON);
216 m_RemoteAstrometry->sendNewProperty(svp);
219 solverRunning =
false;
226 if (device == m_RemoteAstrometry)
229 m_RemoteAstrometry = device;
231 m_RemoteAstrometry->disconnect(
this);
233 connect(m_RemoteAstrometry.get(), &ISD::GenericDevice::propertyUpdated,
this, &RemoteAstrometryParser::checkStatus);
234 connect(m_RemoteAstrometry.get(), &ISD::GenericDevice::propertyUpdated,
this, &RemoteAstrometryParser::checkResults);
236 if (targetCCD.isEmpty() ==
false)
240void RemoteAstrometryParser::checkStatus(INDI::Property prop)
242 if (solverRunning ==
false || !prop.isNameMatch(
"ASTROMETRY_SOLVER"))
245 if (prop.getState() == IPS_ALERT)
248 align->appendLogText(
i18n(
"Solver failed. Try again."));
254void RemoteAstrometryParser::checkResults(INDI::Property prop)
256 if (solverRunning ==
false || !prop.isNameMatch(
"ASTROMETRY_RESULTS") || prop.getState() != IPS_OK)
259 double pixscale, ra, de, orientation;
260 pixscale = ra = de = orientation = -1000;
262 auto nvp = prop.getNumber();
264 for (
int i = 0; i < nvp->count(); i++)
266 auto value = nvp->at(i)->getValue();
267 if (nvp->at(i)->isNameMatch(
"ASTROMETRY_RESULTS_PIXSCALE"))
269 else if (nvp->at(i)->isNameMatch(
"ASTROMETRY_RESULTS_ORIENTATION"))
271 else if (nvp->at(i)->isNameMatch(
"ASTROMETRY_RESULTS_RA"))
273 else if (nvp->at(i)->isNameMatch(
"ASTROMETRY_RESULTS_DE"))
275 else if (nvp->at(i)->isNameMatch(
"ASTROMETRY_RESULTS_PARITY"))
278 parity = FITSImage::POSITIVE;
279 else if (value == -1)
280 parity = FITSImage::NEGATIVE;
284 if (pixscale != -1000 && ra != -1000 && de != -1000 && orientation != -1000)
287 emit solverFinished(orientation, ra, de, pixscale, parity != FITSImage::POSITIVE);
INDI_D represents an INDI GUI Device.
QString i18n(const char *text, const TYPE &arg...)
Ekos is an advanced Astrophotography tool for Linux.
const char * constData() const const
QDateTime currentDateTimeUtc()
QString toString(QStringView format, QCalendar cal) const const
QString number(double n, char format, int precision)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QByteArray toLatin1() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QString join(QChar separator) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)