Instrument Neutral Distributed Interface INDI  1.4.1
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 
406 {
407  public:
408  CCD();
409  virtual ~CCD();
410 
411  enum
412  {
413  CCD_CAN_BIN = 1 << 0,
414  CCD_CAN_SUBFRAME = 1 << 1,
415  CCD_CAN_ABORT = 1 << 2,
416  CCD_HAS_GUIDE_HEAD = 1 << 3,
417  CCD_HAS_ST4_PORT = 1 << 4,
418  CCD_HAS_SHUTTER = 1 << 5,
419  CCD_HAS_COOLER = 1 << 6,
420  CCD_HAS_BAYER = 1 << 7,
421  CCD_HAS_STREAMING = 1 << 8
422  } CCDCapability;
423 
424  enum
425  {
426  ASTROMETRY_SETTINGS_BINARY,
427  ASTROMETRY_SETTINGS_OPTIONS
428  };
429 
430  enum
431  {
432  ASTROMETRY_RESULTS_PIXSCALE,
433  ASTROMETRY_RESULTS_ORIENTATION,
434  ASTROMETRY_RESULTS_RA,
435  ASTROMETRY_RESULTS_DE,
436  ASTROMETRY_RESULTS_PARITY
437  };
438 
439  virtual bool initProperties();
440  virtual bool updateProperties();
441  virtual void ISGetProperties (const char *dev);
442  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
443  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
444  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
445  virtual bool ISSnoopDevice (XMLEle *root);
446 
447  static void * runSolverHelper(void *context);
448 
449  protected:
450 
454  uint32_t GetCCDCapability() const { return capability;}
455 
460  void SetCCDCapability(uint32_t cap);
461 
465  bool CanAbort() { return capability & CCD_CAN_ABORT;}
466 
470  bool CanBin() { return capability & CCD_CAN_BIN;}
471 
475  bool CanSubFrame() { return capability & CCD_CAN_SUBFRAME;}
476 
480  bool HasGuideHead() { return capability & CCD_HAS_GUIDE_HEAD; }
481 
485  bool HasShutter() { return capability & CCD_HAS_SHUTTER;}
486 
490  bool HasST4Port() { return capability & CCD_HAS_ST4_PORT;}
491 
495  bool HasCooler() { return capability & CCD_HAS_COOLER;}
496 
500  bool HasBayer() { return capability & CCD_HAS_BAYER;}
501 
505  bool HasStreaming() { return capability & CCD_HAS_STREAMING; }
506 
516  virtual int SetTemperature(double temperature);
517 
523  virtual bool StartExposure(float duration);
524 
529  virtual bool ExposureComplete(CCDChip *targetChip);
530 
535  virtual bool AbortExposure();
536 
542  virtual bool StartGuideExposure(float duration);
543 
548  virtual bool AbortGuideExposure();
549 
559  virtual bool UpdateCCDFrame(int x, int y, int w, int h);
560 
561 
571  virtual bool UpdateGuiderFrame(int x, int y, int w, int h);
572 
573 
580  virtual bool UpdateCCDBin(int hor, int ver);
581 
582 
589  virtual bool UpdateGuiderBin(int hor, int ver);
590 
597  virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType);
598 
605  virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType);
606 
614  virtual void SetCCDParams(int x,int y,int bpp,float xf,float yf);
615 
623  virtual void SetGuiderParams(int x,int y,int bpp,float xf,float yf);
624 
625 
631  virtual IPState GuideNorth(float ms);
632 
638  virtual IPState GuideSouth(float ms);
639 
645  virtual IPState GuideEast(float ms);
646 
652  virtual IPState GuideWest(float ms);
653 
658  virtual bool StartStreaming();
659 
664  virtual bool StopStreaming();
665 
685  virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip);
686 
688  void fits_update_key_s(fitsfile* fptr, int type, std::string name, void* p, std::string explanation, int* status);
689 
693  virtual void activeDevicesUpdated() {}
694 
700  virtual bool saveConfigItems(FILE *fp);
701 
702  void GuideComplete(INDI_EQ_AXIS axis);
703 
704  double RA, Dec;
705  double primaryFocalLength, primaryAperture, guiderFocalLength, guiderAperture;
706  bool InExposure;
707  bool InGuideExposure;
708  bool RapidGuideEnabled;
709  bool GuiderRapidGuideEnabled;
710 
711  bool AutoLoop;
712  bool GuiderAutoLoop;
713  bool SendImage;
714  bool GuiderSendImage;
715  bool ShowMarker;
716  bool GuiderShowMarker;
717 
718  float ExposureTime;
719  float GuiderExposureTime;
720 
721  // Sky Quality
722  double MPSAS;
723 
724  std::vector<std::string> FilterNames;
725  int CurrentFilterSlot;
726 
727  StreamRecorder *streamer;
728 
729  CCDChip PrimaryCCD;
730  CCDChip GuideCCD;
731 
732  // We are going to snoop these from a telescope
734  INumber EqN[2];
735 
736  ITextVectorProperty ActiveDeviceTP;
737  IText ActiveDeviceT[4];
738 
739  // Astrometry
740 
741  // Enable/Disable solver
742  ISwitch SolverS[2];
743  ISwitchVectorProperty SolverSP;
744 
745  // Solver Settings
746  IText SolverSettingsT[2];
747  ITextVectorProperty SolverSettingsTP;
748 
749  // Solver Results
750  INumber SolverResultN[5];
751  INumberVectorProperty SolverResultNP;
752 
753  // WCS
754  ISwitch WorldCoordS[2];
755  ISwitchVectorProperty WorldCoordSP;
756 
757  // WCS CCD Rotation
758  INumber CCDRotationN[1];
759  INumberVectorProperty CCDRotationNP;
760 
761  ISwitch TelescopeTypeS[2];
762  ISwitchVectorProperty TelescopeTypeSP;
763  enum { TELESCOPE_PRIMARY, TELESCOPE_GUIDE };
764 
765  INumber TemperatureN[1];
766  INumberVectorProperty TemperatureNP;
767 
768  IText BayerT[3];
769  ITextVectorProperty BayerTP;
770 
771  IText FileNameT[1];
772  ITextVectorProperty FileNameTP;
773 
774  ISwitch UploadS[3];
775  ISwitchVectorProperty UploadSP;
776 
777  IText UploadSettingsT[2];
778  ITextVectorProperty UploadSettingsTP;
779 
780  private:
781  uint32_t capability;
782 
783  bool ValidCCDRotation;
784 
785  bool uploadFile(CCDChip * targetChip, const void *fitsData, size_t totalBytes, bool sendImage, bool saveImage, bool useSolver=false);
786  void getMinMax(double *min, double *max, CCDChip *targetChip);
787  int getFileIndex(const char *dir, const char *prefix, const char *ext);
788 
789  // Run solver thread
790  void runSolver();
791 
792  // Thread for listenINDI()
793  pthread_t solverThread;
794  pthread_mutex_t lock;
795 
796  friend class ::StreamRecorder;
797 
798 
799 };
800 
801 #endif // INDI:CCD_H
void setPixelSize(float x, float y)
setPixelSize Set CCD Chip pixel size
Definition: indiccd.cpp:186
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:208
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition: indiccd.h:405
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:146
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
Definition: indiccd.cpp:104
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:505
bool HasCooler()
Definition: indiccd.h:495
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
Definition: indiccd.cpp:231
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value...
Definition: indiccd.cpp:224
IPState
Property state.
Definition: indiapi.h:128
void setImageExtension(const char *ext)
setImageExtension Set image exntension
Definition: indiccd.cpp:278
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:109
bool isCompressed()
isCompressed
Definition: indiccd.h:166
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
Definition: indiccd.cpp:237
bool HasShutter()
Definition: indiccd.h:485
One number descriptor.
Definition: indiapi.h:237
bool isInterlaced()
isInterlaced
Definition: indiccd.h:172
Provides interface to implement guider (ST4) port functionality.
One Blob (Binary Large Object) descriptor.
Definition: indiapi.h:369
int getYRes()
Get the vertical resolution in pixels of the CCD Chip.
Definition: indiccd.h:68
bool HasGuideHead()
Definition: indiccd.h:480
bool HasBayer()
Definition: indiccd.h:500
double getExposureDuration()
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
Definition: indiccd.h:140
int getNAxis() const
Definition: indiccd.cpp:268
Class to provide video streaming and recording functionality.
Definition: indiccd.cpp:41
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:283
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:304
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
Definition: indiccd.cpp:262
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:693
bool CanSubFrame()
Definition: indiccd.h:475
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:158
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:293
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:273
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition: indiccd.h:46
bool CanAbort()
Definition: indiccd.h:465
void setFrame(int subx, int suby, int subw, int subh)
setFrame Set desired frame resolutoin for an exposure.
Definition: indiccd.cpp:131
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:392
void setInterlaced(bool intr)
setInterlaced Set whether the CCD chip is interlaced or not?
Definition: indiccd.cpp:257
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:265
One text descriptor.
Definition: indiapi.h:191
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:242
CCD_FRAME getFrameType()
getFrameType
Definition: indiccd.h:178
ISState
Switch state.
Definition: indiapi.h:119
bool HasST4Port()
Definition: indiccd.h:490
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:199
Text vector property descriptor.
Definition: indiapi.h:209
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:454
int getBPP()
getBPP Get CCD Chip depth (bits per pixel).
Definition: indiccd.h:122
bool CanBin()
Definition: indiccd.h:470
INumberVectorProperty * getCCDInfo()
Return CCD Info Property.
Definition: indiccd.h:190
double value
Definition: indiapi.h:243