Instrument Neutral Distributed Interface INDI  1.5.0
indiccd.h
Go to the documentation of this file.
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 #pragma once
26 
27 #include "defaultdevice.h"
28 
29 #include "indiguiderinterface.h"
30 
31 #include <fitsio.h>
32 
33 #include <memory>
34 #include <cstring>
35 
36 #include <stdint.h>
37 
38 extern const char *IMAGE_SETTINGS_TAB;
39 extern const char *IMAGE_INFO_TAB;
40 extern const char *GUIDE_HEAD_TAB;
41 extern const char *RAPIDGUIDE_TAB;
42 
43 class StreamRecorder;
44 
48 class CCDChip
49 {
50  public:
51  CCDChip();
52  ~CCDChip();
53 
56  typedef enum { BIN_W, BIN_H } CCD_BIN_INDEX;
57  typedef enum {
65 
70  inline int getXRes() { return XRes; }
71 
76  inline int getYRes() { return YRes; }
77 
82  inline int getSubX() { return SubX; }
83 
88  inline int getSubY() { return SubY; }
89 
94  inline int getSubW() { return SubW; }
95 
100  inline int getSubH() { return SubH; }
101 
106  inline int getBinX() { return BinX; }
107 
112  inline int getBinY() { return BinY; }
113 
118  inline float getPixelSizeX() { return PixelSizex; }
119 
124  inline float getPixelSizeY() { return PixelSizey; }
125 
130  inline int getBPP() { return BPP; }
131 
136  inline int getFrameBufferSize() { return RawFrameSize; }
137 
142  inline double getExposureLeft() { return ImageExposureN[0].value; }
143 
148  inline double getExposureDuration() { return exposureDuration; }
149 
154  const char *getExposureStartTime();
155 
160  inline uint8_t *getFrameBuffer() { return RawFrame; }
161 
170  void setFrameBuffer(uint8_t *buffer) { RawFrame = buffer; }
171 
176  inline bool isCompressed() { return SendCompressed; }
177 
182  inline bool isInterlaced() { return Interlaced; }
183 
188  inline CCD_FRAME getFrameType() { return FrameType; }
189 
195  const char *getFrameTypeName(CCD_FRAME fType);
196 
200  INumberVectorProperty *getCCDInfo() { return &ImagePixelSizeNP; }
201 
207  void setResolution(int x, int y);
208 
216  void setFrame(int subx, int suby, int subw, int subh);
217 
223  void setBin(int hor, int ver);
224 
235  void setMinMaxStep(const char *property, const char *element, double min, double max, double step,
236  bool sendToClient = true);
237 
243  void setPixelSize(float x, float y);
244 
249  void setCompressed(bool cmp);
250 
255  void setInterlaced(bool intr);
256 
265  void setFrameBufferSize(int nbuf, bool allocMem = true);
266 
271  void setBPP(int bpp);
272 
277  void setFrameType(CCD_FRAME type);
278 
285  void setExposureDuration(double duration);
286 
292  void setExposureLeft(double duration);
293 
297  void setExposureFailed();
298 
302  int getNAxis() const;
303 
308  void setNAxis(int value);
309 
314  void setImageExtension(const char *ext);
315 
319  char *getImageExtension() { return imageExtention; }
320 
324  bool isExposing() { return (ImageExposureNP.s == IPS_BUSY); }
325 
330  void binFrame();
331 
332  private:
334  int XRes;
336  int YRes;
338  int SubX;
340  int SubY;
342  int SubW;
344  int SubH;
346  int BinX;
348  int BinY;
350  int NAxis;
352  float PixelSizex;
354  float PixelSizey;
356  int BPP;
357  bool Interlaced;
358  uint8_t *RawFrame;
359  uint8_t *BinFrame;
360  int RawFrameSize;
361  bool SendCompressed;
362  CCD_FRAME FrameType;
363  double exposureDuration;
364  timeval startExposureTime;
365  int lastRapidX;
366  int lastRapidY;
367  char imageExtention[MAXINDIBLOBFMT];
368 
369  INumberVectorProperty ImageExposureNP;
370  INumber ImageExposureN[1];
371 
372  ISwitchVectorProperty AbortExposureSP;
373  ISwitch AbortExposureS[1];
374 
375  INumberVectorProperty ImageFrameNP;
376  INumber ImageFrameN[4];
377 
378  INumberVectorProperty ImageBinNP;
379  INumber ImageBinN[2];
380 
381  INumberVectorProperty ImagePixelSizeNP;
382  INumber ImagePixelSizeN[6];
383 
384  ISwitch FrameTypeS[5];
385  ISwitchVectorProperty FrameTypeSP;
386 
387  ISwitch CompressS[2];
388  ISwitchVectorProperty CompressSP;
389 
390  IBLOB FitsB;
391  IBLOBVectorProperty FitsBP;
392 
393  ISwitch RapidGuideS[2];
394  ISwitchVectorProperty RapidGuideSP;
395 
396  ISwitch RapidGuideSetupS[3];
397  ISwitchVectorProperty RapidGuideSetupSP;
398 
399  INumber RapidGuideDataN[3];
400  INumberVectorProperty RapidGuideDataNP;
401 
402  ISwitch ResetS[1];
403  ISwitchVectorProperty ResetSP;
404 
405  friend class INDI::CCD;
406  friend class StreamRecoder;
407 };
408 
433 {
434  public:
435  CCD();
436  virtual ~CCD();
437 
438  enum
439  {
440  CCD_CAN_BIN = 1 << 0,
441  CCD_CAN_SUBFRAME = 1 << 1,
442  CCD_CAN_ABORT = 1 << 2,
443  CCD_HAS_GUIDE_HEAD = 1 << 3,
444  CCD_HAS_ST4_PORT = 1 << 4,
445  CCD_HAS_SHUTTER = 1 << 5,
446  CCD_HAS_COOLER = 1 << 6,
447  CCD_HAS_BAYER = 1 << 7,
448  CCD_HAS_STREAMING = 1 << 8
449  } CCDCapability;
450 
451  typedef enum { UPLOAD_CLIENT, UPLOAD_LOCAL, UPLOAD_BOTH } CCD_UPLOAD_MODE;
452 
453  virtual bool initProperties();
454  virtual bool updateProperties();
455  virtual void ISGetProperties(const char *dev);
456  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n);
457  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
458  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n);
459  virtual bool ISSnoopDevice(XMLEle *root);
460 
461  protected:
465  uint32_t GetCCDCapability() const { return capability; }
466 
471  void SetCCDCapability(uint32_t cap);
472 
476  bool CanAbort() { return capability & CCD_CAN_ABORT; }
477 
481  bool CanBin() { return capability & CCD_CAN_BIN; }
482 
486  bool CanSubFrame() { return capability & CCD_CAN_SUBFRAME; }
487 
491  bool HasGuideHead() { return capability & CCD_HAS_GUIDE_HEAD; }
492 
496  bool HasShutter() { return capability & CCD_HAS_SHUTTER; }
497 
501  bool HasST4Port() { return capability & CCD_HAS_ST4_PORT; }
502 
506  bool HasCooler() { return capability & CCD_HAS_COOLER; }
507 
511  bool HasBayer() { return capability & CCD_HAS_BAYER; }
512 
516  bool HasStreaming() { return capability & CCD_HAS_STREAMING; }
517 
529  virtual int SetTemperature(double temperature);
530 
537  virtual bool StartExposure(float duration);
538 
545  virtual bool ExposureComplete(CCDChip *targetChip);
546 
552  virtual bool AbortExposure();
553 
560  virtual bool StartGuideExposure(float duration);
561 
567  virtual bool AbortGuideExposure();
568 
580  virtual bool UpdateCCDFrame(int x, int y, int w, int h);
581 
593  virtual bool UpdateGuiderFrame(int x, int y, int w, int h);
594 
603  virtual bool UpdateCCDBin(int hor, int ver);
604 
613  virtual bool UpdateGuiderBin(int hor, int ver);
614 
623  virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType);
624 
632  virtual bool UpdateCCDUploadMode(CCD_UPLOAD_MODE mode) { INDI_UNUSED(mode); return true; }
633 
642  virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType);
643 
653  virtual void SetCCDParams(int x, int y, int bpp, float xf, float yf);
654 
664  virtual void SetGuiderParams(int x, int y, int bpp, float xf, float yf);
665 
672  virtual IPState GuideNorth(float ms);
673 
680  virtual IPState GuideSouth(float ms);
681 
688  virtual IPState GuideEast(float ms);
689 
696  virtual IPState GuideWest(float ms);
697 
702  virtual bool StartStreaming();
703 
708  virtual bool StopStreaming();
709 
732  virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip);
733 
735  void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status);
736 
741  virtual void activeDevicesUpdated() {}
742 
748  virtual bool saveConfigItems(FILE *fp);
749 
750  void GuideComplete(INDI_EQ_AXIS axis);
751 
752  double RA, Dec;
753  double primaryFocalLength, primaryAperture, guiderFocalLength, guiderAperture;
758 
759  bool AutoLoop;
761  bool SendImage;
765 
768 
769  // Sky Quality
770  double MPSAS;
771 
772  // Rotator Angle
773  double RotatorAngle;
774 
775  std::vector<std::string> FilterNames;
777 
778  std::unique_ptr<StreamRecorder> Streamer;
779 
782 
783  // We are going to snoop these from a telescope
785  INumber EqN[2];
786 
788  IText ActiveDeviceT[4];
789 
790  INumber TemperatureN[1];
792 
793  IText BayerT[3];
795 
796  IText FileNameT[1];
798 
799  ISwitch UploadS[3];
801 
802  IText UploadSettingsT[2];
804  enum
805  {
807  UPLOAD_PREFIX
808  };
809 
810  ISwitch TelescopeTypeS[2];
812  enum
813  {
815  TELESCOPE_GUIDE
816  };
817 
818  // WCS
819  ISwitch WorldCoordS[2];
821 
822  // WCS CCD Rotation
823  INumber CCDRotationN[1];
825 
826  // FITS Header
827  IText FITSHeaderT[2];
829  enum
830  {
832  FITS_OBJECT
833  };
834 
835  private:
836  uint32_t capability;
837 
838  bool ValidCCDRotation;
839 
840  bool uploadFile(CCDChip *targetChip, const void *fitsData, size_t totalBytes, bool sendImage, bool saveImage);
841  void getMinMax(double *min, double *max, CCDChip *targetChip);
842  int getFileIndex(const char *dir, const char *prefix, const char *ext);
843 
844  friend class ::StreamRecorder;
845 };
void setPixelSize(float x, float y)
setPixelSize Set CCD Chip pixel size
Definition: indiccd.cpp:196
ITextVectorProperty FITSHeaderTP
Definition: indiccd.h:828
int getSubH()
getSubH Get the height of the frame
Definition: indiccd.h:100
void setFrameBufferSize(int nbuf, bool allocMem=true)
setFrameBufferSize Set desired frame buffer size. The function will allocate memory accordingly...
Definition: indiccd.cpp:217
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition: indiccd.h:432
int CurrentFilterSlot
Definition: indiccd.h:776
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
void setBin(int hor, int ver)
setBin Set CCD Chip binnig
Definition: indiccd.cpp:157
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
Definition: indiccd.cpp:115
void setFrameBuffer(uint8_t *buffer)
setFrameBuffer Set raw frame buffer pointer.
Definition: indiccd.h:170
bool isExposing()
Definition: indiccd.h:324
std::vector< std::string > FilterNames
Definition: indiccd.h:775
bool InGuideExposure
Definition: indiccd.h:755
double primaryFocalLength
Definition: indiccd.h:753
bool HasStreaming()
Definition: indiccd.h:516
bool HasCooler()
Definition: indiccd.h:506
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
Definition: indiccd.cpp:240
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value...
Definition: indiccd.cpp:233
IPState
Property state.
Definition: indiapi.h:133
void setImageExtension(const char *ext)
setImageExtension Set image exntension
Definition: indiccd.cpp:287
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:120
bool isCompressed()
isCompressed
Definition: indiccd.h:176
bool RapidGuideEnabled
Definition: indiccd.h:756
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
Definition: indiccd.cpp:246
CCD_BIN_INDEX
Definition: indiccd.h:56
bool HasShutter()
Definition: indiccd.h:496
One number descriptor.
Definition: indiapi.h:246
bool isInterlaced()
isInterlaced
Definition: indiccd.h:182
Provides interface to implement guider (ST4) port functionality.
One Blob (Binary Large Object) descriptor.
Definition: indiapi.h:413
int getYRes()
Get the vertical resolution in pixels of the CCD Chip.
Definition: indiccd.h:76
bool HasGuideHead()
Definition: indiccd.h:491
double max(void)
CCD_UPLOAD_MODE
Definition: indiccd.h:451
bool HasBayer()
Definition: indiccd.h:511
#define MAXINDIBLOBFMT
Definition: indiapi.h:167
double getExposureDuration()
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
Definition: indiccd.h:148
double RA
Definition: indiccd.h:752
int getNAxis() const
Definition: indiccd.cpp:277
INumberVectorProperty EqNP
Definition: indiccd.h:784
Class to provide video streaming and recording functionality.
Definition: indiccd.cpp:48
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
const char * name
Definition: indiserver.c:112
int getFrameBufferSize()
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
Definition: indiccd.h:136
void binFrame()
binFrame Perform softwre binning on the CCD frame. Only use this function if hardware binning is not ...
Definition: indiccd.cpp:292
float getPixelSizeY()
getPixelSizeY Get vertical pixel size in microns.
Definition: indiccd.h:124
float getPixelSizeX()
getPixelSizeX Get horizontal pixel size in microns.
Definition: indiccd.h:118
INumberVectorProperty TemperatureNP
Definition: indiccd.h:791
Switch vector property descriptor.
Definition: indiapi.h:337
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
Definition: indiccd.cpp:271
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Update the value of an existing text vector property.
virtual void activeDevicesUpdated()
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
Definition: indiccd.h:741
const char * IMAGE_SETTINGS_TAB
Definition: indiccd.cpp:53
const char * IMAGE_INFO_TAB
Definition: indiccd.cpp:54
virtual bool UpdateCCDUploadMode(CCD_UPLOAD_MODE mode)
INDI::CCD calls this function when client upload mode switch is updated.
Definition: indiccd.h:632
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
bool CanSubFrame()
Definition: indiccd.h:486
const char * GUIDE_HEAD_TAB
Definition: indiccd.cpp:55
CCDChip PrimaryCCD
Definition: indiccd.h:780
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:168
const char * RAPIDGUIDE_TAB
Definition: indiccd.cpp:57
bool GuiderShowMarker
Definition: indiccd.h:764
CCD_FRAME
Definition: indiccd.h:54
INumberVectorProperty CCDRotationNP
Definition: indiccd.h:824
One switch descriptor.
Definition: indiapi.h:319
bool GuiderAutoLoop
Definition: indiccd.h:760
ITextVectorProperty BayerTP
Definition: indiccd.h:794
bool SendImage
Definition: indiccd.h:761
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
void setNAxis(int value)
setNAxis Set FITS number of axis
Definition: indiccd.cpp:282
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition: indiccd.h:48
bool CanAbort()
Definition: indiccd.h:476
CCDChip GuideCCD
Definition: indiccd.h:781
void setFrame(int subx, int suby, int subw, int subh)
setFrame Set desired frame resolutoin for an exposure.
Definition: indiccd.cpp:142
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:441
void setInterlaced(bool intr)
setInterlaced Set whether the CCD chip is interlaced or not?
Definition: indiccd.cpp:266
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
Definition: indiccd.h:160
ISwitchVectorProperty TelescopeTypeSP
Definition: indiccd.h:811
char * getImageExtension()
Definition: indiccd.h:319
void ISGetProperties(const char *dev)
Get Device Properties.
double RotatorAngle
Definition: indiccd.h:773
CCD_FRAME_INDEX
Definition: indiccd.h:55
Number vector property descriptor.
Definition: indiapi.h:289
~CCDChip()
Definition: indiccd.cpp:107
One text descriptor.
Definition: indiapi.h:196
ISwitchVectorProperty UploadSP
Definition: indiccd.h:800
int getXRes()
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition: indiccd.h:70
int getBinX()
getBinX Get horizontal binning of the CCD chip.
Definition: indiccd.h:106
CCDChip()
Definition: indiccd.cpp:85
double MPSAS
Definition: indiccd.h:770
INDI_EQ_AXIS
Definition: indibasetypes.h:32
int getSubW()
getSubW Get the width of the frame
Definition: indiccd.h:94
CCD_INFO_INDEX
Definition: indiccd.h:57
double getExposureLeft()
getExposureLeft Get exposure time left in seconds.
Definition: indiccd.h:142
bool InExposure
Definition: indiccd.h:754
#define INDI_UNUSED(x)
Definition: indidevapi.h:797
float ExposureTime
Definition: indiccd.h:766
const char * getExposureStartTime()
getExposureStartTime
Definition: indiccd.cpp:251
CCD_FRAME getFrameType()
getFrameType
Definition: indiccd.h:188
ISState
Switch state.
Definition: indiapi.h:124
ITextVectorProperty UploadSettingsTP
Definition: indiccd.h:803
bool HasST4Port()
Definition: indiccd.h:501
ITextVectorProperty ActiveDeviceTP
Definition: indiccd.h:787
bool AutoLoop
Definition: indiccd.h:759
int getBinY()
getBinY Get vertical binning of the CCD chip.
Definition: indiccd.h:112
bool ShowMarker
Definition: indiccd.h:763
void setBPP(int bpp)
setBPP Set depth of CCD chip.
Definition: indiccd.cpp:208
ISwitchVectorProperty WorldCoordSP
Definition: indiccd.h:820
bool GuiderRapidGuideEnabled
Definition: indiccd.h:757
friend class StreamRecoder
Definition: indiccd.h:406
double min(void)
Text vector property descriptor.
Definition: indiapi.h:216
std::unique_ptr< StreamRecorder > Streamer
Definition: indiccd.h:778
float GuiderExposureTime
Definition: indiccd.h:767
int getSubX()
getSubX Get the starting left coordinates (X) of the frame.
Definition: indiccd.h:82
__le16 type
Definition: pwc-ioctl.h:65
int getSubY()
getSubY Get the starting top coordinates (Y) of the frame.
Definition: indiccd.h:88
bool GuiderSendImage
Definition: indiccd.h:762
ITextVectorProperty FileNameTP
Definition: indiccd.h:797
uint32_t GetCCDCapability() const
GetCCDCapability returns the CCD capabilities.
Definition: indiccd.h:465
int getBPP()
getBPP Get CCD Chip depth (bits per pixel).
Definition: indiccd.h:130
bool CanBin()
Definition: indiccd.h:481
INumberVectorProperty * getCCDInfo()
Return CCD Info Property.
Definition: indiccd.h:200
void addFITSKeywords(fitsfile *fptr, IMAGE_INFO *image_info)
Definition: stv.c:1597
void uploadFile(const char *filename)
Definition: stv.c:1710
double value
Definition: indiapi.h:261