Instrument Neutral Distributed Interface INDI
1.9.5
|
Go to the documentation of this file.
29 #define DOWNLOAD_TAB "Download images"
30 #define IMAGE_NAME "%s/%s_%d_%03d%s"
31 #define IMAGE_PREFIX "_TMP_"
34 #define GROUP_PREFIX "GROUP_"
35 #define GROUP_PREFIX_LEN 6
48 std::generate(groups.begin(), groups.end(), [
this, &i] { return std::make_shared<Group>(i++, this); });
51 bool Imager::isRunning()
56 bool Imager::isCCDConnected()
58 return StatusL[0].s ==
IPS_OK;
61 bool Imager::isFilterConnected()
63 return StatusL[1].s ==
IPS_OK;
66 std::shared_ptr<Group> Imager::getGroup(
int index)
const {
67 if(index > -1 && index <= maxGroup)
72 std::shared_ptr<Group> Imager::currentGroup()
const {
73 return getGroup(group - 1);
78 std::shared_ptr<Group> Imager::nextGroup()
const {
79 return getGroup(group);
82 void Imager::initiateNextFilter()
87 if (group > 0 && image > 0 && group <= maxGroup && image <= maxImage)
89 int filterSlot = currentGroup()->filterSlot();
91 if (!isFilterConnected())
96 IDSetNumber(&ProgressNP,
"Filter wheel is not connected");
101 initiateNextCapture();
104 else if (filterSlot != 0 && FilterSlotN[0].value != filterSlot)
106 FilterSlotN[0].value = filterSlot;
108 LOGF_DEBUG(
"Group %d of %d, image %d of %d, filer %d, filter set initiated on %s",
109 group, maxGroup, image, maxImage, (
int)FilterSlotN[0].value, FilterSlotNP.
device);
113 initiateNextCapture();
118 void Imager::initiateNextCapture()
122 if (group > 0 && image > 0 && group <= maxGroup && image <= maxImage)
124 if (!isCCDConnected())
130 CCDImageBinN[0].value = currentGroup()->binning();
131 CCDImageBinN[1].value = currentGroup()->binning();
133 CCDImageExposureN[0].value = currentGroup()->exposure();
135 IUSaveText(&CCDUploadSettingsT[0], ImageNameT[0].text);
139 LOGF_DEBUG(
"Group %d of %d, image %d of %d, duration %.1fs, binning %d, capture initiated on %s", group,
140 maxGroup, image, maxImage, CCDImageExposureN[0].value, (
int)CCDImageBinN[0].value,
141 CCDImageExposureNP.
device);
146 void Imager::startBatch()
149 ProgressN[0].value = group = 1;
150 ProgressN[1].value = image = 1;
151 maxImage = currentGroup()->count();
154 initiateNextFilter();
157 void Imager::abortBatch()
163 void Imager::batchDone()
169 void Imager::initiateDownload()
171 int group = (int)DownloadN[0].value;
172 int image = (int)DownloadN[1].value;
176 if (group == 0 || image == 0)
179 sprintf(
name,
IMAGE_NAME, ImageNameT[0].text, ImageNameT[1].text, group, image, format);
180 file.open(
name, std::ios::in | std::ios::binary | std::ios::ate);
181 DownloadN[0].value = 0;
182 DownloadN[1].value = 0;
185 long size = file.tellg();
186 char *data =
new char[size];
188 file.seekg(0, std::ios::beg);
189 file.read(data, size);
192 LOGF_DEBUG(
"Group %d, image %d, download initiated", group, image);
196 FitsB[0].blob = data;
197 FitsB[0].bloblen = FitsB[0].size = size;
207 LOGF_DEBUG(
"Group %d, image %d, upload failed", group, image);
228 IUFillText(&ControlledDeviceT[0],
"CCD",
"CCD",
"CCD Simulator");
229 IUFillText(&ControlledDeviceT[1],
"FILTER",
"Filter wheel",
"Filter Simulator");
232 controlledCCD = ControlledDeviceT[0].text;
233 controlledFilterWheel = ControlledDeviceT[1].text;
240 IUFillNumber(&ProgressN[1],
"IMAGE",
"Current image",
"%3.0f", 1, 100, 1, 0);
241 IUFillNumber(&ProgressN[2],
"REMAINING_TIME",
"Remaining time",
"%5.2f", 0, 36000, 0, 0.0);
250 IUFillText(&ImageNameT[0],
"IMAGE_FOLDER",
"Image folder",
"/tmp");
251 IUFillText(&ImageNameT[1],
"IMAGE_PREFIX",
"Image prefix",
"IMG");
256 IUFillNumber(&DownloadN[1],
"IMAGE",
"Image",
"%3.0f", 1, 100, 1, 1);
267 for (
int i = 0; i < GroupCountN[0].value; i++)
269 groups[i]->defineProperties();
272 IUFillNumber(&CCDImageExposureN[0],
"CCD_EXPOSURE_VALUE",
"Duration (s)",
"%5.2f", 0, 36000, 0, 1.0);
273 IUFillNumberVector(&CCDImageExposureNP, CCDImageExposureN, 1, ControlledDeviceT[0].text,
"CCD_EXPOSURE",
"Expose",
276 IUFillNumber(&CCDImageBinN[0],
"HOR_BIN",
"X",
"%2.0f", 1, 4, 1, 1);
277 IUFillNumber(&CCDImageBinN[1],
"VER_BIN",
"Y",
"%2.0f", 1, 4, 1, 1);
278 IUFillNumberVector(&CCDImageBinNP, CCDImageBinN, 2, ControlledDeviceT[0].text,
"CCD_BINNING",
"Binning",
287 IUFillText(&CCDUploadSettingsT[0],
"UPLOAD_DIR",
"Dir",
"");
289 IUFillTextVector(&CCDUploadSettingsTP, CCDUploadSettingsT, 2, ControlledDeviceT[0].text,
"UPLOAD_SETTINGS",
292 IUFillNumber(&FilterSlotN[0],
"FILTER_SLOT_VALUE",
"Filter",
"%3.0f", 1.0, 12.0, 1.0, 1.0);
293 IUFillNumberVector(&FilterSlotNP, FilterSlotN, 1, ControlledDeviceT[1].text,
"FILTER_SLOT",
"Filter Slot",
304 ProgressN[0].value = group = 0;
305 ProgressN[1].value = image = 0;
310 DownloadN[0].value = 0;
311 DownloadN[1].value = 0;
337 if (std::string{
name} == std::string{GroupCountNP.
name})
339 for (
int i = 0; i < maxGroup; i++)
340 groups[i]->deleteProperties();
342 maxGroup = (int)GroupCountN[0].value;
345 for (
int i = 0; i < maxGroup; i++)
346 groups[i]->defineProperties();
351 if (std::string{
name} == std::string{DownloadNP.
name})
359 for (
int i = 0; i < GroupCountN[0].value; i++)
374 if (std::string{
name} == std::string{BatchSP.
name})
376 for (
int i = 0; i < n; i++)
378 if (strcmp(names[i], BatchS[0].
name) == 0 && states[i] ==
ISS_ON)
383 if (strcmp(names[i], BatchS[1].
name) == 0 && states[i] ==
ISS_ON)
401 if (std::string{
name} == std::string{ControlledDeviceTP.
name})
405 strncpy(StatusL[0].label, ControlledDeviceT[0].text,
sizeof(StatusL[0].label));
406 strncpy(CCDImageExposureNP.
device, ControlledDeviceT[0].text,
sizeof(CCDImageExposureNP.
device));
407 strncpy(CCDImageBinNP.
device, ControlledDeviceT[0].text,
sizeof(CCDImageBinNP.
device));
408 strncpy(StatusL[1].label, ControlledDeviceT[1].text,
sizeof(StatusL[1].label));
409 strncpy(FilterSlotNP.
device, ControlledDeviceT[1].text,
sizeof(FilterSlotNP.
device));
412 if (std::string{
name} == std::string{ImageNameTP.
name})
422 bool Imager::ISNewBLOB(
const char *dev,
const char *
name,
int sizes[],
int blobsizes[],
char *blobs[],
char *formats[],
423 char *names[],
int n)
466 LOGF_DEBUG(
"Device %s detected", deviceName.c_str());
467 if (deviceName == controlledCCD)
469 if (deviceName == controlledFilterWheel)
477 std::string deviceName{
property->getDeviceName()};
481 bool state =
property->getSwitch()->sp[0].s !=
ISS_OFF;
482 if (deviceName == controlledCCD)
494 if (deviceName == controlledFilterWheel)
503 LOGF_DEBUG(
"Connecting %s", controlledFilterWheel);
527 strncpy(format, bp->format, 16);
528 sprintf(
name,
IMAGE_NAME, ImageNameT[0].text, ImageNameT[1].text, group, image, format);
529 file.open(
name, std::ios::out | std::ios::binary | std::ios::trunc);
530 file.write(
static_cast<char *
>(bp->blob), bp->bloblen);
532 LOGF_DEBUG(
"Group %d of %d, image %d of %d, saved to %s", group, maxGroup, image, maxImage,
534 if (image == maxImage)
536 if (group == maxGroup)
542 maxImage = nextGroup()->count();
543 ProgressN[0].value = group = group + 1;
544 ProgressN[1].value = image = 1;
546 initiateNextFilter();
551 ProgressN[1].value = image = image + 1;
553 initiateNextFilter();
560 std::string deviceName{svp->
device};
565 if (deviceName == controlledCCD)
576 if (deviceName == controlledFilterWheel)
593 std::string deviceName{nvp->
device};
595 if (deviceName == controlledCCD)
597 if (strcmp(nvp->
name,
"CCD_EXPOSURE") == 0)
599 ProgressN[2].value = nvp->
np[0].value;
603 if (deviceName == controlledFilterWheel)
605 if (strcmp(nvp->
name,
"FILTER_SLOT") == 0)
607 FilterSlotN[0].value = nvp->
np->value;
609 initiateNextCapture();
616 std::string deviceName{tvp->
device};
618 if (deviceName == controlledCCD)
620 if (strcmp(tvp->
name,
"CCD_FILE_PATH") == 0)
624 strncpy(format, strrchr(tvp->
tp[0].text,
'.'),
sizeof(format));
625 sprintf(
name,
IMAGE_NAME, ImageNameT[0].text, ImageNameT[1].text, group, image, format);
626 rename(tvp->
tp[0].text,
name);
627 LOGF_DEBUG(
"Group %d of %d, image %d of %d, saved to %s", group, maxGroup, image,
629 if (image == maxImage)
631 if (group == maxGroup)
637 maxImage = nextGroup()->count();
638 ProgressN[0].value = group = group + 1;
639 ProgressN[1].value = image = 1;
641 initiateNextFilter();
646 ProgressN[1].value = image = image + 1;
648 initiateNextFilter();
virtual const char * getDefaultName() override
void connectDevice(const char *deviceName)
Connect to INDI driver.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
static const std::string DEVICE_NAME
char device[MAXINDIDEVICE]
const char * getName() const
Light vector property descriptor.
virtual void removeProperty(INDI::Property *property) override
Emmited when a property is deleted for an INDI driver.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
bool disconnectServer(int exit_code=0)
Disconnect from INDI server.
void IDSetText(const ITextVectorProperty *t, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing text vector property.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
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 defineProperty(INumberVectorProperty *property)
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
virtual void removeDevice(INDI::BaseDevice *dp) override
Emmited when a device is deleted from INDI server.
virtual void newMessage(INDI::BaseDevice *dp, int messageID) override
Emmited when a new message arrives from INDI server.
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.
std::shared_ptr< Imager > imager(new Imager())
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
const char * getDeviceName() const
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
void void void void void void void void void IDSetBLOB(const IBLOBVectorProperty *b, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing BLOB vector property.
void IUFillLight(ILight *lp, const char *name, const char *label, IPState s)
Assign attributes for a light property. The light's auxiliary elements will be set to NULL.
virtual void newBLOB(IBLOB *bp) override
Emmited when a new BLOB value arrives from INDI server.
virtual void newDevice(INDI::BaseDevice *dp) override
Emmited when a new device is created from INDI server.
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.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
char device[MAXINDIDEVICE]
int IUUpdateText(ITextVectorProperty *tvp, char *texts[], char *names[], int n)
Update all text members in a text vector property.
virtual void newLight(ILightVectorProperty *lvp) override
Emmited when a new light value arrives from INDI server.
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
Provides generic container for INDI properties.
void watchDevice(const char *deviceName)
Add a device to the watch list.
virtual void serverConnected() override
Emmited when the server is connected.
Text vector property descriptor.
void ISNewNumber(const char *dev, const char *name, double *values, char *names[], int n)
Update the value of an existing number vector property.
void sendNewNumber(INumberVectorProperty *pp)
Send new Number command to server.
virtual void newText(ITextVectorProperty *tvp) override
Emmited when a new text value arrives from INDI server.
#define LOGF_DEBUG(fmt,...)
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
virtual bool Disconnect() override
Disconnect from device.
void ISGetProperties(const char *dev)
Get Device Properties.
Number vector property descriptor.
void void void void void void void IDSetLight(const ILightVectorProperty *l, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing light vector property.
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 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 setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop=nullptr)
Set Binary Large Object policy mode.
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
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.
virtual void newSwitch(ISwitchVectorProperty *svp) override
Emmited when a new switch value arrives from INDI server.
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.
void sendNewSwitch(ISwitchVectorProperty *pp)
Send new Switch command to server.
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
void sendNewText(ITextVectorProperty *pp)
Send new Text command to server.
virtual void serverDisconnected(int exit_code) override
Emmited when the server gets disconnected.
char device[MAXINDIDEVICE]
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...
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.
int IUUpdateNumber(INumberVectorProperty *nvp, double values[], char *names[], int n)
Update all numbers in a number vector property.
const char * CONNECTION
Connect to and disconnect from device.
void setServer(const char *hostname, unsigned int port)
Set the server host name and port.
void addDebugControl()
Add Debug control to the driver.
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.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void IUFillLightVector(ILightVectorProperty *lvp, ILight *lp, int nlp, const char *dev, const char *name, const char *label, const char *group, IPState s)
Assign attributes for a light vector property. The vector's auxiliary elements will be set to NULL.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual void newNumber(INumberVectorProperty *nvp) override
Emmited when a new number value arrives from INDI server.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
void void void IDSetNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing number vector property.
void void void void void IDSetSwitch(const ISwitchVectorProperty *s, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing switch vector property.
Class to provide basic INDI device functionality.
virtual void newProperty(INDI::Property *property) override
Emmited when a new property is created for an INDI driver.
One Blob (Binary Large Object) descriptor.
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.
Switch vector property descriptor.
bool connectServer()
Connect to INDI server.