Instrument Neutral Distributed Interface INDI  0.9.9
indiccd.h
1 /*******************************************************************************
2  Copyright(c) 2010, 2011 Gerry Rozema, Jasem Mutlaq. All rights reserved.
3 
4  Rapid Guide support added by CloudMakers, s. r. o.
5  Copyright(c) 2013 CloudMakers, s. r. o. All rights reserved.
6 
7  Star detection algorithm is based on PHD Guiding by Craig Stark
8  Copyright (c) 2006-2010 Craig Stark. All rights reserved.
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Library General Public
12  License version 2 as published by the Free Software Foundation.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Library General Public License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to
21  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  Boston, MA 02110-1301, USA.
23 *******************************************************************************/
24 
25 
26 #ifndef INDI_CCD_H
27 #define INDI_CCD_H
28 
29 #include <fitsio.h>
30 #include <string.h>
31 
32 #include "defaultdevice.h"
33 #include "indiguiderinterface.h"
34 
35 extern const char *IMAGE_SETTINGS_TAB;
36 extern const char *IMAGE_INFO_TAB;
37 extern const char *GUIDE_HEAD_TAB;
38 extern const char *RAPIDGUIDE_TAB;
39 
44 class CCDChip
45 {
46 
47 public:
48  CCDChip();
49  ~CCDChip();
50 
51  typedef enum { LIGHT_FRAME=0, BIAS_FRAME, DARK_FRAME, FLAT_FRAME } CCD_FRAME;
52  typedef enum { FRAME_X, FRAME_Y, FRAME_W, FRAME_H} CCD_FRAME_INDEX;
53  typedef enum { BIN_W, BIN_H} CCD_BIN_INDEX;
54  typedef enum { CCD_MAX_X, CCD_MAX_Y, CCD_PIXEL_SIZE, CCD_PIXEL_SIZE_X, CCD_PIXEL_SIZE_Y, CCD_BITSPERPIXEL} CCD_INFO_INDEX;
55 
60  inline int getXRes() { return XRes; }
61 
66  inline int getYRes() { return YRes; }
67 
72  inline int getSubX() { return SubX; }
73 
78  inline int getSubY() { return SubY; }
79 
84  inline int getSubW() { return SubW; }
85 
90  inline int getSubH() { return SubH; }
91 
96  inline int getBinX() { return BinX; }
97 
102  inline int getBinY() { return BinY; }
103 
108  inline float getPixelSizeX() { return PixelSizex; }
109 
114  inline float getPixelSizeY() { return PixelSizey; }
115 
120  inline int getBPP() { return BPP; }
121 
126  inline int getFrameBufferSize() { return RawFrameSize; }
127 
132  inline double getExposureLeft() { return ImageExposureN[0].value; }
133 
138  inline double getExposureDuration() { return exposureDuration; }
139 
144  const char *getExposureStartTime();
145 
150  inline char *getFrameBuffer() { return RawFrame; }
151 
158  void setFrameBuffer(char *buffer) { RawFrame = buffer; }
159 
164  inline bool isCompressed() { return SendCompressed; }
165 
170  inline bool isInterlaced() { return Interlaced; }
171 
176  inline CCD_FRAME getFrameType() { return FrameType; }
177 
183  const char *getFrameTypeName(CCD_FRAME fType);
184 
188  void setCCDInfoWritable();
189 
195  void setResolution(int x, int y);
196 
204  void setFrame(int subx, int suby, int subw, int subh);
205 
211  void setBin(int hor, int ver);
212 
218  void setMaxBin(int max_hor, int max_ver);
219 
220 
226  void setPixelSize(float x, float y);
227 
232  void setCompressed (bool cmp);
233 
238  void setInterlaced(bool intr);
239 
247  void setFrameBufferSize(int nbuf, bool allocMem=true);
248 
253  void setBPP(int bpp);
254 
259  void setFrameType(CCD_FRAME type);
260 
266  void setExposureDuration(double duration);
267 
272  void setExposureLeft(double duration);
273 
277  void setExposureFailed();
278 
282  int getNAxis() const;
283 
288  void setNAxis(int value);
289 
294  void setImageExtension(const char *ext);
295 
299  char *getImageExtension() { return imageExtention;}
300 
304  bool isExposing() { return (ImageExposureNP->s == IPS_BUSY); }
305 
306 private:
307 
308  int XRes; // native resolution of the ccd
309  int YRes; // ditto
310  int SubX; // left side of the subframe we are requesting
311  int SubY; // top of the subframe requested
312  int SubW; // UNBINNED width of the subframe
313  int SubH; // UNBINNED height of the subframe
314  int BinX; // Binning requested in the x direction
315  int BinY; // Binning requested in the Y direction
316  int NAxis; // # of Axis
317  float PixelSizex; // pixel size in microns, x direction
318  float PixelSizey; // pixel size in microns, y direction
319  int BPP; // Bytes per Pixel
320  bool Interlaced;
321  char *RawFrame;
322  int RawFrameSize;
323  bool SendCompressed;
324  CCD_FRAME FrameType;
325  double exposureDuration;
326  timeval startExposureTime;
327  int lastRapidX;
328  int lastRapidY;
329  char imageExtention[MAXINDIBLOBFMT];
330 
331  INumberVectorProperty *ImageExposureNP;
332  INumber ImageExposureN[1];
333 
334  ISwitchVectorProperty *AbortExposureSP;
335  ISwitch AbortExposureS[1];
336 
337  INumberVectorProperty *ImageFrameNP;
338  INumber ImageFrameN[4];
339 
340  INumberVectorProperty *ImageBinNP;
341  INumber ImageBinN[2];
342 
343  INumberVectorProperty *ImagePixelSizeNP;
344  INumber ImagePixelSizeN[6];
345 
346  ISwitch FrameTypeS[5];
347  ISwitchVectorProperty *FrameTypeSP;
348 
349  ISwitch CompressS[2];
350  ISwitchVectorProperty *CompressSP;
351 
352  IBLOB FitsB;
353  IBLOBVectorProperty *FitsBP;
354 
355  ISwitch RapidGuideS[2];
356  ISwitchVectorProperty *RapidGuideSP;
357 
358  ISwitch RapidGuideSetupS[3];
359  ISwitchVectorProperty *RapidGuideSetupSP;
360 
361  INumber RapidGuideDataN[3];
362  INumberVectorProperty *RapidGuideDataNP;
363 
364  friend class INDI::CCD;
365 };
366 
377 {
378  public:
379  CCD();
380  virtual ~CCD();
381 
382  typedef struct
383  {
384  bool hasGuideHead;
385  bool hasST4Port;
386  bool hasShutter;
387  bool hasCooler;
388  bool canBin;
389  bool canSubFrame;
390  bool canAbort;
391  } Capability;
392 
393  virtual bool initProperties();
394  virtual bool updateProperties();
395  virtual void ISGetProperties (const char *dev);
396  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
397  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
398  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
399  virtual bool ISSnoopDevice (XMLEle *root);
400 
401  protected:
402 
403  Capability GetCapability() const { return capability;}
404  void SetCapability(Capability * cap);
405 
409  bool CanAbort() { return capability.canAbort;}
410 
414  bool CanBin() { return capability.canBin;}
415 
419  bool CanSubFrame() { return capability.canSubFrame;}
420 
424  bool HasGuideHead() { return capability.hasGuideHead; }
425 
429  bool HasShutter() { return capability.hasShutter;}
430 
434  bool HasST4Port() { return capability.hasST4Port;}
435 
439  bool HasCooler() { return capability.hasCooler;}
440 
450  virtual int SetTemperature(double temperature);
451 
457  virtual bool StartExposure(float duration);
458 
463  virtual bool ExposureComplete(CCDChip *targetChip);
464 
469  virtual bool AbortExposure();
470 
476  virtual bool StartGuideExposure(float duration);
477 
482  virtual bool AbortGuideExposure();
483 
493  virtual bool UpdateCCDFrame(int x, int y, int w, int h);
494 
495 
505  virtual bool UpdateGuiderFrame(int x, int y, int w, int h);
506 
507 
514  virtual bool UpdateCCDBin(int hor, int ver);
515 
516 
523  virtual bool UpdateGuiderBin(int hor, int ver);
524 
531  virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType);
532 
539  virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType);
540 
548  virtual void SetCCDParams(int x,int y,int bpp,float xf,float yf);
549 
557  virtual void SetGuiderParams(int x,int y,int bpp,float xf,float yf);
558 
559 
565  virtual bool GuideNorth(float ms);
566 
572  virtual bool GuideSouth(float ms);
573 
579  virtual bool GuideEast(float ms);
580 
586  virtual bool GuideWest(float ms);
587 
607  virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip);
608 
609  /* A function to just remove GCC warnings about deprecated conversion */
610  void fits_update_key_s(fitsfile* fptr, int type, std::string name, void* p, std::string explanation, int* status);
611 
615  virtual void activeDevicesUpdated() {}
616 
617  virtual bool saveConfigItems(FILE *fp);
618 
619 
620  double RA, Dec;
621  bool InExposure;
622  bool InGuideExposure;
623  bool RapidGuideEnabled;
624  bool GuiderRapidGuideEnabled;
625 
626  bool AutoLoop;
627  bool GuiderAutoLoop;
628  bool SendImage;
629  bool GuiderSendImage;
630  bool ShowMarker;
631  bool GuiderShowMarker;
632 
633  float ExposureTime;
634  float GuiderExposureTime;
635 
636  std::vector<std::string> FilterNames;
637  int CurrentFilterSlot;
638 
639  CCDChip PrimaryCCD;
640  CCDChip GuideCCD;
641 
642  // We are going to snoop these from a telescope
644  INumber EqN[2];
645 
646  ITextVectorProperty *ActiveDeviceTP;
647  IText ActiveDeviceT[3];
648 
649  INumber TemperatureN[1];
650  INumberVectorProperty TemperatureNP;
651 
652  ISwitch UploadS[3];
653  ISwitchVectorProperty UploadSP;
654 
655  IText UploadSettingsT[2];
656  ITextVectorProperty UploadSettingsTP;
657 
658  private:
659  Capability capability;
660 
661  bool uploadFile(CCDChip * targetChip, const void *fitsData, size_t totalBytes, bool sendImage, bool saveImage);
662  void getMinMax(double *min, double *max, CCDChip *targetChip);
663  int getFileIndex(const char *dir, const char *prefix, const char *ext);
664 
665 
666 };
667 
668 #endif // INDI:CCD_H
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver...
Definition: indiccd.cpp:455
void setPixelSize(float x, float y)
setPixelSize Set CCD Chip pixel size
Definition: indiccd.cpp:158
int getSubH()
getSubH Get the height of the frame
Definition: indiccd.h:90
void setFrameBufferSize(int nbuf, bool allocMem=true)
setFrameBufferSize Set desired frame buffer size. The function will allocate memory accordingly...
Definition: indiccd.cpp:180
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition: indiccd.h:376
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:93
void setBin(int hor, int ver)
setBin Set CCD Chip binnig
Definition: indiccd.cpp:138
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
Definition: indiccd.cpp:96
bool isExposing()
Definition: indiccd.h:304
virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip)
Add FITS keywords to a fits file.
Definition: indiccd.cpp:1191
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition: indiccd.cpp:665
void setMaxBin(int max_hor, int max_ver)
setMaxBin Set Maximum CCD Chip binning
Definition: indiccd.cpp:150
virtual bool UpdateCCDFrame(int x, int y, int w, int h)
INDI::CCD calls this function when CCD Frame dimension needs to be updated in the hardware...
Definition: indiccd.cpp:1150
bool HasCooler()
Definition: indiccd.h:439
virtual bool StartExposure(float duration)
Start exposing primary CCD chip.
Definition: indiccd.cpp:1126
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
Definition: indiccd.cpp:200
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value...
Definition: indiccd.cpp:193
virtual bool GuideEast(float ms)
Guide easward for ms milliseconds.
Definition: indiccd.cpp:1709
void setImageExtension(const char *ext)
setImageExtension Set image exntension
Definition: indiccd.cpp:244
void setCompressed(bool cmp)
setCompressed Set whether a frame is compressed after exposure?
void setResolution(int x, int y)
setResolution set CCD Chip resolution
Definition: indiccd.cpp:101
bool isCompressed()
isCompressed
Definition: indiccd.h:164
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
Definition: indiccd.cpp:206
bool HasShutter()
Definition: indiccd.h:429
One number descriptor.
Definition: indiapi.h:224
bool isInterlaced()
isInterlaced
Definition: indiccd.h:170
Provides interface to implement guider (ST4) port functionality.
One Blob (Binary Large Object) descriptor.
Definition: indiapi.h:356
virtual bool StartGuideExposure(float duration)
Start exposing guide CCD chip.
Definition: indiccd.cpp:1132
int getYRes()
Get the vertical resolution in pixels of the CCD Chip.
Definition: indiccd.h:66
bool HasGuideHead()
Definition: indiccd.h:424
double getExposureDuration()
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
Definition: indiccd.h:138
int getNAxis() const
Definition: indiccd.cpp:234
void setFrameBuffer(char *buffer)
setFrameBuffer Set raw frame buffer pointer.
Definition: indiccd.h:158
virtual bool GuideNorth(float ms)
Guide northward for ms milliseconds.
Definition: indiccd.cpp:1699
virtual int SetTemperature(double temperature)
Set CCD temperature.
Definition: indiccd.cpp:1119
int getFrameBufferSize()
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
Definition: indiccd.h:126
float getPixelSizeY()
getPixelSizeY Get vertical pixel size in microns.
Definition: indiccd.h:114
virtual bool GuideWest(float ms)
Guide westward for ms milliseconds.
Definition: indiccd.cpp:1714
virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType)
INDI::CCD calls this function when Guide frame type is updated by the client.
Definition: indiccd.cpp:1184
float getPixelSizeX()
getPixelSizeX Get horizontal pixel size in microns.
Definition: indiccd.h:108
Switch vector property descriptor.
Definition: indiapi.h:291
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
Definition: indiccd.cpp:228
virtual void SetCCDParams(int x, int y, int bpp, float xf, float yf)
Setup CCD paramters for primary CCD. Child classes call this function to update CCD paramaters...
Definition: indiccd.cpp:1657
virtual void activeDevicesUpdated()
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
Definition: indiccd.h:615
bool CanSubFrame()
Definition: indiccd.h:419
One switch descriptor.
Definition: indiapi.h:280
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function...
Definition: indiccd.cpp:297
void setNAxis(int value)
setNAxis Set FITS number of axis
Definition: indiccd.cpp:239
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition: indiccd.h:44
virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType)
INDI::CCD calls this function when CCD frame type needs to be updated in the hardware.
Definition: indiccd.cpp:1177
bool CanAbort()
Definition: indiccd.h:409
char * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
Definition: indiccd.h:150
void setFrame(int subx, int suby, int subw, int subh)
setFrame Set desired frame resolutoin for an exposure.
Definition: indiccd.cpp:123
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:379
void setInterlaced(bool intr)
setInterlaced Set whether the CCD chip is interlaced or not?
Definition: indiccd.cpp:223
char * getImageExtension()
Definition: indiccd.h:299
Number vector property descriptor.
Definition: indiapi.h:252
One text descriptor.
Definition: indiapi.h:178
virtual bool GuideSouth(float ms)
Guide southward for ms milliseconds.
Definition: indiccd.cpp:1704
int getXRes()
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition: indiccd.h:60
int getBinX()
getBinX Get horizontal binning of the CCD chip.
Definition: indiccd.h:96
virtual void SetGuiderParams(int x, int y, int bpp, float xf, float yf)
Setup CCD paramters for guide head CCD. Child classes call this function to update CCD paramaters...
Definition: indiccd.cpp:1668
int getSubW()
getSubW Get the width of the frame
Definition: indiccd.h:84
virtual bool UpdateCCDBin(int hor, int ver)
INDI::CCD calls this function when CCD Binning needs to be updated in the hardware. Derived classes should implement this function.
Definition: indiccd.cpp:1163
double getExposureLeft()
getExposureLeft Get exposure time left in seconds.
Definition: indiccd.h:132
const char * getExposureStartTime()
getExposureStartTime
Definition: indiccd.cpp:211
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: indiccd.cpp:584
CCD_FRAME getFrameType()
getFrameType
Definition: indiccd.h:176
ISState
Switch state.
Definition: indiapi.h:106
bool HasST4Port()
Definition: indiccd.h:434
virtual bool AbortExposure()
Abort ongoing exposure.
Definition: indiccd.cpp:1138
int getBinY()
getBinY Get vertical binning of the CCD chip.
Definition: indiccd.h:102
void setBPP(int bpp)
setBPP Set depth of CCD chip.
Definition: indiccd.cpp:171
void setCCDInfoWritable()
Make CCD Info writable.
Definition: indiccd.cpp:91
Text vector property descriptor.
Definition: indiapi.h:196
int getSubX()
getSubX Get the starting left coordinates (X) of the frame.
Definition: indiccd.h:72
int getSubY()
getSubY Get the starting top coordinates (Y) of the frame.
Definition: indiccd.h:78
virtual bool AbortGuideExposure()
Abort ongoing exposure.
Definition: indiccd.cpp:1144
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
Definition: indiccd.cpp:624
virtual bool UpdateGuiderBin(int hor, int ver)
INDI::CCD calls this function when Guide head binning is updated by the client. Derived classes shoul...
Definition: indiccd.cpp:1170
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minumum set of properties are defined t...
Definition: indiccd.cpp:444
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition: indiccd.cpp:892
virtual bool UpdateGuiderFrame(int x, int y, int w, int h)
INDI::CCD calls this function when Guide head frame dimension is updated by the client. Derived classes should implement this function.
Definition: indiccd.cpp:1157
int getBPP()
getBPP Get CCD Chip depth (bits per pixel).
Definition: indiccd.h:120
bool CanBin()
Definition: indiccd.h:414
virtual bool ExposureComplete(CCDChip *targetChip)
Uploads target Chip exposed buffer as FITS to the client. Dervied classes should class this functon w...
Definition: indiccd.cpp:1272
double value
Definition: indiapi.h:230