Instrument Neutral Distributed Interface INDI  0.9.8
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 
190  void setResolution(int x, int y);
191 
199  void setFrame(int subx, int suby, int subw, int subh);
200 
206  void setBin(int hor, int ver);
207 
213  void setMaxBin(int max_hor, int max_ver);
214 
215 
221  void setPixelSize(float x, float y);
222 
227  void setCompressed (bool cmp);
228 
233  void setInterlaced(bool intr);
234 
242  void setFrameBufferSize(int nbuf, bool allocMem=true);
243 
248  void setBPP(int bpp);
249 
254  void setFrameType(CCD_FRAME type);
255 
261  void setExposureDuration(double duration);
262 
267  void setExposureLeft(double duration);
268 
272  void setExposureFailed();
273 
277  int getNAxis() const;
278 
283  void setNAxis(int value);
284 
289  void setImageExtension(const char *ext);
290 
294  char *getImageExtension() { return imageExtention;}
295 
299  bool isExposing() { return (ImageExposureNP->s == IPS_BUSY); }
300 
301 private:
302 
303  int XRes; // native resolution of the ccd
304  int YRes; // ditto
305  int SubX; // left side of the subframe we are requesting
306  int SubY; // top of the subframe requested
307  int SubW; // UNBINNED width of the subframe
308  int SubH; // UNBINNED height of the subframe
309  int BinX; // Binning requested in the x direction
310  int BinY; // Binning requested in the Y direction
311  int NAxis; // # of Axis
312  float PixelSizex; // pixel size in microns, x direction
313  float PixelSizey; // pixel size in microns, y direction
314  int BPP; // Bytes per Pixel
315  bool Interlaced;
316  char *RawFrame;
317  int RawFrameSize;
318  bool SendCompressed;
319  CCD_FRAME FrameType;
320  double exposureDuration;
321  timeval startExposureTime;
322  int lastRapidX;
323  int lastRapidY;
324  char imageExtention[MAXINDIBLOBFMT];
325 
326  INumberVectorProperty *ImageExposureNP;
327  INumber ImageExposureN[1];
328 
329  ISwitchVectorProperty *AbortExposureSP;
330  ISwitch AbortExposureS[1];
331 
332  INumberVectorProperty *ImageFrameNP;
333  INumber ImageFrameN[4];
334 
335  INumberVectorProperty *ImageBinNP;
336  INumber ImageBinN[2];
337 
338  INumberVectorProperty *ImagePixelSizeNP;
339  INumber ImagePixelSizeN[6];
340 
341  ISwitch FrameTypeS[5];
342  ISwitchVectorProperty *FrameTypeSP;
343 
344  ISwitch CompressS[2];
345  ISwitchVectorProperty *CompressSP;
346 
347  IBLOB FitsB;
348  IBLOBVectorProperty *FitsBP;
349 
350  ISwitch RapidGuideS[2];
351  ISwitchVectorProperty *RapidGuideSP;
352 
353  ISwitch RapidGuideSetupS[3];
354  ISwitchVectorProperty *RapidGuideSetupSP;
355 
356  INumber RapidGuideDataN[3];
357  INumberVectorProperty *RapidGuideDataNP;
358 
359  friend class INDI::CCD;
360 };
361 
372 {
373  public:
374  CCD();
375  virtual ~CCD();
376 
377  typedef struct
378  {
379  bool hasGuideHead;
380  bool hasST4Port;
381  bool hasShutter;
382  bool hasCooler;
383  bool canBin;
384  bool canSubFrame;
385  bool canAbort;
386  } Capability;
387 
388  virtual bool initProperties();
389  virtual bool updateProperties();
390  virtual void ISGetProperties (const char *dev);
391  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
392  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
393  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
394  virtual bool ISSnoopDevice (XMLEle *root);
395 
396  protected:
397 
398  Capability GetCapability() const { return capability;}
399  void SetCapability(Capability * cap);
400 
404  bool CanAbort() { return capability.canAbort;}
405 
409  bool CanBin() { return capability.canBin;}
410 
414  bool CanSubFrame() { return capability.canSubFrame;}
415 
419  bool HasGuideHead() { return capability.hasGuideHead; }
420 
424  bool HasShutter() { return capability.hasShutter;}
425 
429  bool HasST4Port() { return capability.hasST4Port;}
430 
434  bool HasCooler() { return capability.hasCooler;}
435 
445  virtual int SetTemperature(double temperature);
446 
452  virtual bool StartExposure(float duration);
453 
457  virtual bool ExposureComplete(CCDChip *targetChip);
458 
463  virtual bool AbortExposure();
464 
470  virtual bool StartGuideExposure(float duration);
471 
476  virtual bool AbortGuideExposure();
477 
487  virtual bool UpdateCCDFrame(int x, int y, int w, int h);
488 
489 
499  virtual bool UpdateGuiderFrame(int x, int y, int w, int h);
500 
501 
508  virtual bool UpdateCCDBin(int hor, int ver);
509 
510 
517  virtual bool UpdateGuiderBin(int hor, int ver);
518 
525  virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType);
526 
533  virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType);
534 
542  virtual void SetCCDParams(int x,int y,int bpp,float xf,float yf);
543 
551  virtual void SetGuiderParams(int x,int y,int bpp,float xf,float yf);
552 
553 
559  virtual bool GuideNorth(float ms);
560 
566  virtual bool GuideSouth(float ms);
567 
573  virtual bool GuideEast(float ms);
574 
580  virtual bool GuideWest(float ms);
581 
601  virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip);
602 
603  /* A function to just remove GCC warnings about deprecated conversion */
604  void fits_update_key_s(fitsfile* fptr, int type, std::string name, void* p, std::string explanation, int* status);
605 
609  virtual void activeDevicesUpdated() {}
610 
611  virtual bool saveConfigItems(FILE *fp);
612 
613 
614  double RA, Dec;
615  bool InExposure;
616  bool InGuideExposure;
617  bool RapidGuideEnabled;
618  bool GuiderRapidGuideEnabled;
619 
620  bool AutoLoop;
621  bool GuiderAutoLoop;
622  bool SendImage;
623  bool GuiderSendImage;
624  bool ShowMarker;
625  bool GuiderShowMarker;
626 
627  float ExposureTime;
628  float GuiderExposureTime;
629 
630  CCDChip PrimaryCCD;
631  CCDChip GuideCCD;
632 
633  // We are going to snoop these from a telescope
635  INumber EqN[2];
636 
637  ITextVectorProperty *ActiveDeviceTP;
638  IText ActiveDeviceT[2];
639 
640  INumber TemperatureN[1];
641  INumberVectorProperty TemperatureNP;
642 
643  private:
644  Capability capability;
645 
646  bool uploadFile(CCDChip * targetChip, const void *fitsData, size_t totalBytes);
647  void getMinMax(double *min, double *max, CCDChip *targetChip);
648 
649 
650 };
651 
652 #endif // INDI:CCD_H