58 "/usr/bin/solve-field");
60 "--no-verify --no-plots --resort --downsample 2 -O");
66 "%g", 0, 10000, 1, 0);
68 "Orientation (E of N) °",
"%g", -360, 360, 1, 0);
106 DefaultDevice::ISGetProperties(dev);
156 char *formats[],
char *names[],
int n)
171 LOG_INFO(
"Astrometry solver is enabled.");
175 processBLOB(
reinterpret_cast<uint8_t *
>(blobs[0]),
static_cast<uint32_t
>(sizes[0]),
176 static_cast<uint32_t
>(blobsizes[0]));
225 pthread_mutex_lock(&lock);
232 LOG_INFO(
"Astrometry solver is enabled.");
237 LOG_INFO(
"Astrometry solver is disabled.");
243 pthread_mutex_unlock(&lock);
255 processBLOB(
reinterpret_cast<uint8_t *
>(
CCDDataB[0].blob),
static_cast<uint32_t
>(
CCDDataB[0].size),
256 static_cast<uint32_t
>(
CCDDataB[0].bloblen));
270bool AstrometryDriver::processBLOB(uint8_t *data, uint32_t size, uint32_t len)
275 uint8_t *processedData = data;
280 uint8_t *dataBuffer =
new uint8_t[size];
281 uLongf destLen = size;
283 if (dataBuffer ==
nullptr)
285 LOG_DEBUG(
"Unable to allocate memory for data buffer");
289 int r = uncompress(dataBuffer, &destLen, data, len);
292 LOGF_ERROR(
"Astrometry compression error: %d", r);
299 LOGF_WARN(
"Discrepancy between uncompressed data size %ld and expected size %ld",
303 processedData = dataBuffer;
306 strncpy(imageFileName,
"/tmp/ccdsolver.fits",
MAXRBUF);
308 fp = fopen(imageFileName,
"w");
311 LOGF_ERROR(
"Unable to save image file (%s). %s", imageFileName, strerror(
errno));
313 delete[] processedData;
319 for (uint32_t nr = 0; nr < size; nr += n)
320 n = fwrite(processedData + nr, 1, size - nr, fp);
326 delete[] processedData;
328 pthread_mutex_lock(&lock);
332 pthread_mutex_unlock(&lock);
352void AstrometryDriver::runSolver()
354 char cmd[
MAXRBUF] = {0}, line[256] = {0}, parity_str[8] = {0};
355 float ra = -1000,
dec = -1000, angle = -1000, pixscale = -1000, parity = 0;
356 snprintf(
cmd,
MAXRBUF,
"%s %s -W /tmp/solution.wcs /tmp/ccdsolver.fits",
360 FILE *handle = popen(
cmd,
"r");
361 if (handle ==
nullptr)
364 pthread_mutex_lock(&lock);
367 pthread_mutex_unlock(&lock);
371 while (fgets(line,
sizeof(line), handle) !=
nullptr)
375 sscanf(line,
"Field rotation angle: up is %f", &angle);
376 sscanf(line,
"Field center: (RA,Dec) = (%f,%f)", &
ra, &
dec);
377 sscanf(line,
"Field parity: %s", parity_str);
378 sscanf(line,
"%*[^p]pixel scale %f", &pixscale);
380 if (strcmp(parity_str,
"pos") == 0)
382 else if (strcmp(parity_str,
"neg") == 0)
385 if (
ra != -1000 &&
dec != -1000 && angle != -1000 && pixscale != -1000)
401 pthread_mutex_lock(&lock);
404 pthread_mutex_unlock(&lock);
411 pthread_mutex_lock(&lock);
416 pthread_mutex_unlock(&lock);
421 pthread_mutex_unlock(&lock);
426 pthread_mutex_lock(&lock);
430 pthread_mutex_unlock(&lock);
432 pthread_exit(
nullptr);
std::unique_ptr< AstrometryDriver > astrometry(new AstrometryDriver())
The AstrometryDriver class is an INDI driver frontend for astrometry.net.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
static void * runSolverHelper(void *context)
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
Process the client newBLOB command.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
IBLOBVectorProperty SolverDataBP
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
ITextVectorProperty ActiveDeviceTP
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
ISwitchVectorProperty SolverSP
INumberVectorProperty SolverResultNP
ITextVectorProperty SolverSettingsTP
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
bool Disconnect() override
Disconnect from device.
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
IBLOBVectorProperty CCDDataBP
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * getDefaultName() override
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
@ ASTROMETRY_SETTINGS_BINARY
@ ASTROMETRY_SETTINGS_OPTIONS
@ ASTROMETRY_RESULTS_ORIENTATION
@ ASTROMETRY_RESULTS_PIXSCALE
@ ASTROMETRY_RESULTS_PARITY
const char * getDeviceName() const
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool initProperties()
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Process the client newBLOB command.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
void addDebugControl()
Add Debug control to the driver.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
int IUSnoopBLOB(XMLEle *root, IBLOBVectorProperty *bvp)
Update a snooped BLOB vector property from the given XML root element.
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IUSaveConfigText(FILE *fp, const ITextVectorProperty *tvp)
Add a text vector property value to the configuration file.
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
void IUFillBLOBVector(IBLOBVectorProperty *bvp, IBLOB *bp, int nbp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a BLOB vector property. The vector's auxiliary elements will be set to NULL.
void IUFillBLOB(IBLOB *bp, const char *name, const char *label, const char *format)
Assign attributes for a BLOB property. The BLOB's data and auxiliary elements will be set to NULL.
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSnoopBLOBs(const char *snooped_device, const char *snooped_property, BLOBHandling bh)
Function a Driver calls to control whether they will receive BLOBs from snooped devices.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
int IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
void IDSnoopDevice(const char *snooped_device, const char *snooped_property)
Function a Driver calls to snoop on another Device. Snooped messages will then arrive via ISSnoopDevi...
void IDSetBLOB(const IBLOBVectorProperty *bvp, const char *fmt,...)
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
#define LOGF_INFO(fmt,...)
#define LOGF_WARN(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOGF_ERROR(fmt,...)
char device[MAXINDIDEVICE]