Instrument Neutral Distributed Interface INDI  0.9.6
indiccd.h
1 /*******************************************************************************
2  Copyright(c) 2010, 2011 Gerry Rozema, Jasem Mutlaq. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 *******************************************************************************/
18 
19 
20 #ifndef INDI_CCD_H
21 #define INDI_CCD_H
22 
23 #include <fitsio.h>
24 #include <string.h>
25 
26 #include "defaultdevice.h"
27 #include "indiguiderinterface.h"
28 
29 extern const char *IMAGE_SETTINGS_TAB;
30 extern const char *IMAGE_INFO_TAB;
31 extern const char *GUIDE_HEAD_TAB;
32 extern const char *GUIDE_CONTROL_TAB;
33 
34 class CCDChip
35 {
36 
37 public:
38  CCDChip();
39  ~CCDChip();
40 
41  typedef enum { LIGHT_FRAME=0, BIAS_FRAME, DARK_FRAME, FLAT_FRAME } CCD_FRAME;
42  typedef enum { FRAME_X, FRAME_Y, FRAME_W, FRAME_H} CCD_FRAME_INDEX;
43  typedef enum { BIN_W, BIN_H} CCD_BIN_INDEX;
44  typedef enum { CCD_MAX_X, CCD_MAX_Y, CCD_PIXEL_SIZE, CCD_PIXEL_SIZE_X, CCD_PIXEL_SIZE_Y, CCD_BITSPERPIXEL} CCD_INFO_INDEX;
45 
46  inline int getXRes() { return XRes; }
47  inline int getYRes() { return YRes; }
48  inline int getSubX() { return SubX; }
49  inline int getSubY() { return SubY; }
50  inline int getSubW() { return SubW; }
51  inline int getSubH() { return SubH; }
52  inline int getBinX() { return BinX; }
53  inline int getBinY() { return BinY; }
54  inline float getPixelSizeX() { return PixelSizex; }
55  inline float getPixelSizeY() { return PixelSizey; }
56  inline int getBPP() { return BPP; }
57  inline int getFrameBufferSize() { return RawFrameSize; }
58  inline double getExposureLeft() { return ImageExposureN[0].value; }
59  inline double getExposureDuration() { return exposureDuration; }
60  inline char *getFrameBuffer() { return RawFrame; }
61  inline bool isCompressed() { return SendCompressed; }
62  inline bool isInterlaced() { return Interlaced; }
63  inline CCD_FRAME getFrameType() { return FrameType; }
64  const char *getExposureStartTime();
65 
66  void setResolutoin(int x, int y);
67  void setFrame(int subx, int suby, int subw, int subh);
68  void setBin(int hor, int ver);
69  void setPixelSize(float x, float y);
70  void setCompressed (bool cmp);
71  void setInterlaced(bool intr);
72  void setFrameBufferSize(int nbuf);
73  void setBPP(int bpp);
74  int setFrameType(CCD_FRAME);
75  void setExposureDuration(double duration);
76  void setExposureLeft(double duration);
77  void setExposureFailed();
78 
79 private:
80 
81  int XRes; // native resolution of the ccd
82  int YRes; // ditto
83  int SubX; // left side of the subframe we are requesting
84  int SubY; // top of the subframe requested
85  int SubW; // width of the subframe
86  int SubH; // height of the subframe
87  int BinX; // Binning requested in the x direction
88  int BinY; // Binning requested in the Y direction
89  float PixelSizex; // pixel size in microns, x direction
90  float PixelSizey; // pixel size in microns, y direction
91  int BPP; // Bytes per Pixel
92  bool Interlaced;
93  char *RawFrame;
94  int RawFrameSize;
95  bool SendCompressed;
96  CCD_FRAME FrameType;
97  double exposureDuration;
98  timeval startExposureTime;
99 
100  INumberVectorProperty *ImageExposureNP;
101  INumber ImageExposureN[1];
102 
103  ISwitchVectorProperty *AbortExposureSP;
104  ISwitch AbortExposureS[1];
105 
106  INumberVectorProperty *ImageFrameNP;
107  INumber ImageFrameN[4];
108 
109  INumberVectorProperty *ImageBinNP;
110  INumber ImageBinN[2];
111 
112  INumberVectorProperty *ImagePixelSizeNP;
113  INumber ImagePixelSizeN[6];
114 
115  ISwitch FrameTypeS[4];
116  ISwitchVectorProperty *FrameTypeSP;
117 
118  ISwitch CompressS[2];
119  ISwitchVectorProperty *CompressSP;
120 
121  IBLOB FitsB;
122  IBLOBVectorProperty *FitsBP;
123 
124  friend class INDI::CCD;
125 };
126 
137 {
138  public:
139  CCD();
140  virtual ~CCD();
141 
142  virtual bool initProperties();
143  virtual bool updateProperties();
144  virtual void ISGetProperties (const char *dev);
145  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
146  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
147  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
148  virtual bool ISSnoopDevice (XMLEle *root);
149 
150  protected:
156  virtual int StartExposure(float duration);
157 
161  virtual bool ExposureComplete(CCDChip *targetChip);
162 
167  virtual bool AbortExposure();
168 
174  virtual int StartGuideExposure(float duration);
175 
180  virtual bool AbortGuideExposure();
181 
191  virtual bool updateCCDFrame(int x, int y, int w, int h);
192 
199  virtual bool updateCCDBin(int hor, int ver);
200 
201 
208  virtual bool updateCCDFrameType(CCDChip::CCD_FRAME fType);
209 
217  virtual void SetCCDParams(int x,int y,int bpp,float xf,float yf);
218 
226  virtual void SetGuidHeadParams(int x,int y,int bpp,float xf,float yf);
227 
228 
234  virtual bool GuideNorth(float ms);
235 
241  virtual bool GuideSouth(float ms);
242 
248  virtual bool GuideEast(float ms);
249 
255  virtual bool GuideWest(float ms);
256 
276  virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip);
277 
278  /* A function to just remove GCC warnings about deprecated conversion */
279  void fits_update_key_s(fitsfile* fptr, int type, std::string name, void* p, std::string explanation, int* status);
280 
281  virtual bool saveConfigItems(FILE *fp);
282 
283  float RA;
284  float Dec;
285  bool HasGuideHead;
286  bool HasSt4Port;
287  bool InExposure;
288 
289  CCDChip PrimaryCCD;
290  CCDChip GuideCCD;
291 
292  // We are going to snoop these from a telescope
294  INumber EqN[2];
295 
296  ITextVectorProperty *ActiveDeviceTP;
297  IText ActiveDeviceT[2];
298 
299  private:
300  void getMinMax(double *min, double *max, CCDChip *targetChip);
301 
302 
303 };
304 
305 #endif // INDI:CCD_H