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);
157 char *formats[],
char *names[],
int n)
172 LOG_INFO(
"Astrometry solver is enabled.");
176 processBLOB(
reinterpret_cast<uint8_t *
>(blobs[0]),
static_cast<uint32_t
>(sizes[0]),
177 static_cast<uint32_t
>(blobsizes[0]));
226 pthread_mutex_lock(&lock);
233 LOG_INFO(
"Astrometry solver is enabled.");
238 LOG_INFO(
"Astrometry solver is disabled.");
244 pthread_mutex_unlock(&lock);
256 processBLOB(
reinterpret_cast<uint8_t *
>(
CCDDataB[0].blob),
static_cast<uint32_t
>(
CCDDataB[0].size),
257 static_cast<uint32_t
>(
CCDDataB[0].bloblen));
271 bool AstrometryDriver::processBLOB(uint8_t *data, uint32_t size, uint32_t len)
276 uint8_t *processedData = data;
281 uint8_t *dataBuffer =
new uint8_t[size];
282 uLongf destLen = size;
284 if (dataBuffer ==
nullptr)
286 LOG_DEBUG(
"Unable to allocate memory for data buffer");
290 int r = uncompress(dataBuffer, &destLen, data, len);
293 LOGF_ERROR(
"Astrometry compression error: %d", r);
300 LOGF_WARN(
"Discrepency between uncompressed data size %ld and expected size %ld",
304 processedData = dataBuffer;
307 strncpy(imageFileName,
"/tmp/ccdsolver.fits",
MAXRBUF);
309 fp = fopen(imageFileName,
"w");
312 LOGF_ERROR(
"Unable to save image file (%s). %s", imageFileName, strerror(
errno));
314 delete[] processedData;
320 for (uint32_t nr = 0; nr < size; nr += n)
321 n = fwrite(processedData + nr, 1, size - nr, fp);
327 delete[] processedData;
329 pthread_mutex_lock(&lock);
333 pthread_mutex_unlock(&lock);
353 void AstrometryDriver::runSolver()
355 char cmd[
MAXRBUF] = {0}, line[256] = {0}, parity_str[8] = {0};
356 float ra = -1000,
dec = -1000, angle = -1000, pixscale = -1000, parity = 0;
357 snprintf(
cmd,
MAXRBUF,
"%s %s -W /tmp/solution.wcs /tmp/ccdsolver.fits",
361 FILE *handle = popen(
cmd,
"r");
362 if (handle ==
nullptr)
365 pthread_mutex_lock(&lock);
368 pthread_mutex_unlock(&lock);
372 while (fgets(line,
sizeof(line), handle) !=
nullptr)
376 sscanf(line,
"Field rotation angle: up is %f", &angle);
377 sscanf(line,
"Field center: (RA,Dec) = (%f,%f)", &
ra, &
dec);
378 sscanf(line,
"Field parity: %s", parity_str);
379 sscanf(line,
"%*[^p]pixel scale %f", &pixscale);
381 if (strcmp(parity_str,
"pos") == 0)
383 else if (strcmp(parity_str,
"neg") == 0)
386 if (
ra != -1000 &&
dec != -1000 && angle != -1000 && pixscale != -1000)
402 pthread_mutex_lock(&lock);
405 pthread_mutex_unlock(&lock);
412 pthread_mutex_lock(&lock);
417 pthread_mutex_unlock(&lock);
422 pthread_mutex_unlock(&lock);
427 pthread_mutex_lock(&lock);
431 pthread_mutex_unlock(&lock);
433 pthread_exit(
nullptr);
std::unique_ptr< AstrometryDriver > astrometry(new AstrometryDriver())
The AstrometryDriver class is an INDI driver frontend for astrometry.net.
@ ASTROMETRY_SETTINGS_BINARY
@ ASTROMETRY_SETTINGS_OPTIONS
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
@ ASTROMETRY_RESULTS_ORIENTATION
@ ASTROMETRY_RESULTS_PIXSCALE
@ ASTROMETRY_RESULTS_PARITY
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
Initilize 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...
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 setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
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()
Initilize 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 setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
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.
void ISGetProperties(const char *dev)
Get Device Properties.
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]