Instrument Neutral Distributed Interface INDI  1.2.0
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 
40 class StreamRecorder;
41 
46 class CCDChip
47 {
48 
49 public:
50  CCDChip();
51  ~CCDChip();
52 
53  typedef enum { LIGHT_FRAME=0, BIAS_FRAME, DARK_FRAME, FLAT_FRAME } CCD_FRAME;
54  typedef enum { FRAME_X, FRAME_Y, FRAME_W, FRAME_H} CCD_FRAME_INDEX;
55  typedef enum { BIN_W, BIN_H} CCD_BIN_INDEX;
56  typedef enum { CCD_MAX_X, CCD_MAX_Y, CCD_PIXEL_SIZE, CCD_PIXEL_SIZE_X, CCD_PIXEL_SIZE_Y, CCD_BITSPERPIXEL} CCD_INFO_INDEX;
57 
62  inline int getXRes() { return XRes; }
63 
68  inline int getYRes() { return YRes; }
69 
74  inline int getSubX() { return SubX; }
75 
80  inline int getSubY() { return SubY; }
81 
86  inline int getSubW() { return SubW; }
87 
92  inline int getSubH() { return SubH; }
93 
98  inline int getBinX() { return BinX; }
99 
104  inline int getBinY() { return BinY; }
105 
110  inline float getPixelSizeX() { return PixelSizex; }
111 
116  inline float getPixelSizeY() { return PixelSizey; }
117 
122  inline int getBPP() { return BPP; }
123 
128  inline int getFrameBufferSize() { return RawFrameSize; }
129 
134  inline double getExposureLeft() { return ImageExposureN[0].value; }
135 
140  inline double getExposureDuration() { return exposureDuration; }
141 
146  const char *getExposureStartTime();
147 
152  inline uint8_t * getFrameBuffer() { return RawFrame; }
153 
160  void setFrameBuffer(uint8_t *buffer) { RawFrame = buffer; }
161 
166  inline bool isCompressed() { return SendCompressed; }
167 
172  inline bool isInterlaced() { return Interlaced; }
173 
178  inline CCD_FRAME getFrameType() { return FrameType; }
179 
185  const char *getFrameTypeName(CCD_FRAME fType);
186 
190  INumberVectorProperty * getCCDInfo() { return &ImagePixelSizeNP; }
191 
197  void setResolution(int x, int y);
198 
206  void setFrame(int subx, int suby, int subw, int subh);
207 
213  void setBin(int hor, int ver);
214 
224  void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true);
225 
231  void setPixelSize(float x, float y);
232 
237  void setCompressed (bool cmp);
238 
243  void setInterlaced(bool intr);
244 
252  void setFrameBufferSize(int nbuf, bool allocMem=true);
253 
258  void setBPP(int bpp);
259 
264  void setFrameType(CCD_FRAME type);
265 
271  void setExposureDuration(double duration);
272 
277  void setExposureLeft(double duration);
278 
282  void setExposureFailed();
283 
287  int getNAxis() const;
288 
293  void setNAxis(int value);
294 
299  void setImageExtension(const char *ext);
300 
304  char *getImageExtension() { return imageExtention;}
305 
309  bool isExposing() { return (ImageExposureNP.s == IPS_BUSY); }
310 
314  void binFrame();
315 
316 private:
317 
318  int XRes; // native resolution of the ccd
319  int YRes; // ditto
320  int SubX; // left side of the subframe we are requesting
321  int SubY; // top of the subframe requested
322  int SubW; // UNBINNED width of the subframe
323  int SubH; // UNBINNED height of the subframe
324  int BinX; // Binning requested in the x direction
325  int BinY; // Binning requested in the Y direction
326  int NAxis; // # of Axis
327  float PixelSizex; // pixel size in microns, x direction
328  float PixelSizey; // pixel size in microns, y direction
329  int BPP; // Bytes per Pixel
330  bool Interlaced;
331  uint8_t *RawFrame;
332  uint8_t *BinFrame;
333  int RawFrameSize;
334  bool SendCompressed;
335  CCD_FRAME FrameType;
336  double exposureDuration;
337  timeval startExposureTime;
338  int lastRapidX;
339  int lastRapidY;
340  char imageExtention[MAXINDIBLOBFMT];
341 
342  INumberVectorProperty ImageExposureNP;
343  INumber ImageExposureN[1];
344 
345  ISwitchVectorProperty AbortExposureSP;
346  ISwitch AbortExposureS[1];
347 
348  INumberVectorProperty ImageFrameNP;
349  INumber ImageFrameN[4];
350 
351  INumberVectorProperty ImageBinNP;
352  INumber ImageBinN[2];
353 
354  INumberVectorProperty ImagePixelSizeNP;
355  INumber ImagePixelSizeN[6];
356 
357  ISwitch FrameTypeS[5];
358  ISwitchVectorProperty FrameTypeSP;
359 
360  ISwitch CompressS[2];
361  ISwitchVectorProperty CompressSP;
362 
363  IBLOB FitsB;
364  IBLOBVectorProperty FitsBP;
365 
366  ISwitch RapidGuideS[2];
367  ISwitchVectorProperty RapidGuideSP;
368 
369  ISwitch RapidGuideSetupS[3];
370  ISwitchVectorProperty RapidGuideSetupSP;
371 
372  INumber RapidGuideDataN[3];
373  INumberVectorProperty RapidGuideDataNP;
374 
375  ISwitch ResetS[1];
376  ISwitchVectorProperty ResetSP;
377 
378  friend class INDI::CCD;
379  friend class StreamRecoder;
380 
381 };
382 
399 {
400  public:
401  CCD();
402  virtual ~CCD();
403 
404  enum
405  {
406  CCD_CAN_BIN = 1 << 0,
407  CCD_CAN_SUBFRAME = 1 << 1,
408  CCD_CAN_ABORT = 1 << 2,
409  CCD_HAS_GUIDE_HEAD = 1 << 3,
410  CCD_HAS_ST4_PORT = 1 << 4,
411  CCD_HAS_SHUTTER = 1 << 5,
412  CCD_HAS_COOLER = 1 << 6,
413  CCD_HAS_BAYER = 1 << 7,
414  CCD_HAS_STREAMING = 1 << 8
415  } CCDCapability;
416 
417  virtual bool initProperties();
418  virtual bool updateProperties();
419  virtual void ISGetProperties (const char *dev);
420  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
421  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
422  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
423  virtual bool ISSnoopDevice (XMLEle *root);
424 
425  protected:
426 
430  uint32_t GetCCDCapability() const { return capability;}
431 
436  void SetCCDCapability(uint32_t cap);
437 
441  bool CanAbort() { return capability & CCD_CAN_ABORT;}
442 
446  bool CanBin() { return capability & CCD_CAN_BIN;}
447 
451  bool CanSubFrame() { return capability & CCD_CAN_SUBFRAME;}
452 
456  bool HasGuideHead() { return capability & CCD_HAS_GUIDE_HEAD; }
457 
461  bool HasShutter() { return capability & CCD_HAS_SHUTTER;}
462 
466  bool HasST4Port() { return capability & CCD_HAS_ST4_PORT;}
467 
471  bool HasCooler() { return capability & CCD_HAS_COOLER;}
472 
476  bool HasBayer() { return capability & CCD_HAS_BAYER;}
477 
481  bool HasStreaming() { return capability & CCD_HAS_STREAMING; }
482 
492  virtual int SetTemperature(double temperature);
493 
499  virtual bool StartExposure(float duration);
500 
505  virtual bool ExposureComplete(CCDChip *targetChip);
506 
511  virtual bool AbortExposure();
512 
518  virtual bool StartGuideExposure(float duration);
519 
524  virtual bool AbortGuideExposure();
525 
535  virtual bool UpdateCCDFrame(int x, int y, int w, int h);
536 
537 
547  virtual bool UpdateGuiderFrame(int x, int y, int w, int h);
548 
549 
556  virtual bool UpdateCCDBin(int hor, int ver);
557 
558 
565  virtual bool UpdateGuiderBin(int hor, int ver);
566 
573  virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType);
574 
581  virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType);
582 
590  virtual void SetCCDParams(int x,int y,int bpp,float xf,float yf);
591 
599  virtual void SetGuiderParams(int x,int y,int bpp,float xf,float yf);
600 
601 
607  virtual IPState GuideNorth(float ms);
608 
614  virtual IPState GuideSouth(float ms);
615 
621  virtual IPState GuideEast(float ms);
622 
628  virtual IPState GuideWest(float ms);
629 
634  virtual bool StartStreaming();
635 
640  virtual bool StopStreaming();
641 
661  virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip);
662 
664  void fits_update_key_s(fitsfile* fptr, int type, std::string name, void* p, std::string explanation, int* status);
665 
669  virtual void activeDevicesUpdated() {}
670 
676  virtual bool saveConfigItems(FILE *fp);
677 
678  void GuideComplete(INDI_EQ_AXIS axis);
679 
680  double RA, Dec;
681  double FocalLength, Aperture;
682  bool InExposure;
683  bool InGuideExposure;
684  bool RapidGuideEnabled;
685  bool GuiderRapidGuideEnabled;
686 
687  bool AutoLoop;
688  bool GuiderAutoLoop;
689  bool SendImage;
690  bool GuiderSendImage;
691  bool ShowMarker;
692  bool GuiderShowMarker;
693 
694  float ExposureTime;
695  float GuiderExposureTime;
696 
697  std::vector<std::string> FilterNames;
698  int CurrentFilterSlot;
699 
700  StreamRecorder *streamer;
701 
702  CCDChip PrimaryCCD;
703  CCDChip GuideCCD;
704 
705  // We are going to snoop these from a telescope
707  INumber EqN[2];
708 
709  ITextVectorProperty ActiveDeviceTP;
710  IText ActiveDeviceT[3];
711 
712  ISwitch WorldCoordS[2];
713  ISwitchVectorProperty WorldCoordSP;
714 
715  INumber CCDRotationN[1];
716  INumberVectorProperty CCDRotationNP;
717 
718  ISwitch TelescopeTypeS[2];
719  ISwitchVectorProperty TelescopeTypeSP;
720 
721  INumber TemperatureN[1];
722  INumberVectorProperty TemperatureNP;
723 
724  IText BayerT[3];
725  ITextVectorProperty BayerTP;
726 
727  ISwitch UploadS[3];
728  ISwitchVectorProperty UploadSP;
729 
730  IText UploadSettingsT[2];
731  ITextVectorProperty UploadSettingsTP;
732 
733  private:
734  uint32_t capability;
735 
736  bool ValidCCDRotation;
737 
738  bool uploadFile(CCDChip * targetChip, const void *fitsData, size_t totalBytes, bool sendImage, bool saveImage);
739  void getMinMax(double *min, double *max, CCDChip *targetChip);
740  int getFileIndex(const char *dir, const char *prefix, const char *ext);
741 
742  friend class ::StreamRecorder;
743 
744 
745 };
746 
747 #endif // INDI:CCD_H
void setPixelSize(float x, float y)
setPixelSize Set CCD Chip pixel size
Definition: indiccd.cpp:161
int getSubH()
getSubH Get the height of the frame
Definition: indiccd.h:92
void setFrameBufferSize(int nbuf, bool allocMem=true)
setFrameBufferSize Set desired frame buffer size. The function will allocate memory accordingly...
Definition: indiccd.cpp:183
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition: indiccd.h:398
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:121
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
Definition: indiccd.cpp:79
void setFrameBuffer(uint8_t *buffer)
setFrameBuffer Set raw frame buffer pointer.
Definition: indiccd.h:160
bool isExposing()
Definition: indiccd.h:309
bool HasStreaming()
Definition: indiccd.h:481
bool HasCooler()
Definition: indiccd.h:471
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
Definition: indiccd.cpp:206
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value...
Definition: indiccd.cpp:199
IPState
Property state.
Definition: indiapi.h:129
void setImageExtension(const char *ext)
setImageExtension Set image exntension
Definition: indiccd.cpp:250
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:84
bool isCompressed()
isCompressed
Definition: indiccd.h:166
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
Definition: indiccd.cpp:212
bool HasShutter()
Definition: indiccd.h:461
One number descriptor.
Definition: indiapi.h:238
bool isInterlaced()
isInterlaced
Definition: indiccd.h:172
Provides interface to implement guider (ST4) port functionality.
One Blob (Binary Large Object) descriptor.
Definition: indiapi.h:370
int getYRes()
Get the vertical resolution in pixels of the CCD Chip.
Definition: indiccd.h:68
bool HasGuideHead()
Definition: indiccd.h:456
bool HasBayer()
Definition: indiccd.h:476
double getExposureDuration()
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
Definition: indiccd.h:140
int getNAxis() const
Definition: indiccd.cpp:240
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
Definition: dome.cpp:65
int getFrameBufferSize()
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
Definition: indiccd.h:128
void binFrame()
binFrame Perform softwre binning on the CCD frame. Only use this function if hardware binning is not ...
Definition: indiccd.cpp:255
float getPixelSizeY()
getPixelSizeY Get vertical pixel size in microns.
Definition: indiccd.h:116
float getPixelSizeX()
getPixelSizeX Get horizontal pixel size in microns.
Definition: indiccd.h:110
Switch vector property descriptor.
Definition: indiapi.h:305
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
Definition: indiccd.cpp:234
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int num)
Update the value of an existing text vector property.
Definition: dome.cpp:43
virtual void activeDevicesUpdated()
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
Definition: indiccd.h:669
bool CanSubFrame()
Definition: indiccd.h:451
void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true)
setMinMaxStep for a number property element
Definition: indiccd.cpp:133
void ISNewNumber(const char *dev, const char *name, double *doubles, char *names[], int n)
Update the value of an existing number vector property.
One switch descriptor.
Definition: indiapi.h:294
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int num)
Update the value of an existing switch vector property.
Definition: dome.cpp:38
void setNAxis(int value)
setNAxis Set FITS number of axis
Definition: indiccd.cpp:245
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition: indiccd.h:46
bool CanAbort()
Definition: indiccd.h:441
void setFrame(int subx, int suby, int subw, int subh)
setFrame Set desired frame resolutoin for an exposure.
Definition: indiccd.cpp:106
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:393
void setInterlaced(bool intr)
setInterlaced Set whether the CCD chip is interlaced or not?
Definition: indiccd.cpp:229
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
Definition: indiccd.h:152
char * getImageExtension()
Definition: indiccd.h:304
void ISGetProperties(const char *dev)
Get Device Properties.
Definition: dome.cpp:33
Number vector property descriptor.
Definition: indiapi.h:266
One text descriptor.
Definition: indiapi.h:192
int getXRes()
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition: indiccd.h:62
int getBinX()
getBinX Get horizontal binning of the CCD chip.
Definition: indiccd.h:98
int getSubW()
getSubW Get the width of the frame
Definition: indiccd.h:86
double getExposureLeft()
getExposureLeft Get exposure time left in seconds.
Definition: indiccd.h:134
const char * getExposureStartTime()
getExposureStartTime
Definition: indiccd.cpp:217
CCD_FRAME getFrameType()
getFrameType
Definition: indiccd.h:178
ISState
Switch state.
Definition: indiapi.h:120
bool HasST4Port()
Definition: indiccd.h:466
int getBinY()
getBinY Get vertical binning of the CCD chip.
Definition: indiccd.h:104
void setBPP(int bpp)
setBPP Set depth of CCD chip.
Definition: indiccd.cpp:174
Text vector property descriptor.
Definition: indiapi.h:210
int getSubX()
getSubX Get the starting left coordinates (X) of the frame.
Definition: indiccd.h:74
int getSubY()
getSubY Get the starting top coordinates (Y) of the frame.
Definition: indiccd.h:80
uint32_t GetCCDCapability() const
GetCCDCapability returns the CCD capabilities.
Definition: indiccd.h:430
int getBPP()
getBPP Get CCD Chip depth (bits per pixel).
Definition: indiccd.h:122
bool CanBin()
Definition: indiccd.h:446
INumberVectorProperty * getCCDInfo()
Return CCD Info Property.
Definition: indiccd.h:190
double value
Definition: indiapi.h:244