Instrument Neutral Distributed Interface INDI  1.6.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 namespace INDI
44 {
45 
46 class StreamManager;
47 
51 class CCDChip
52 {
53  public:
54  CCDChip();
55  ~CCDChip();
56 
59  typedef enum { BIN_W, BIN_H } CCD_BIN_INDEX;
60  typedef enum {
68 
73  inline int getXRes() { return XRes; }
74 
79  inline int getYRes() { return YRes; }
80 
85  inline int getSubX() { return SubX; }
86 
91  inline int getSubY() { return SubY; }
92 
97  inline int getSubW() { return SubW; }
98 
103  inline int getSubH() { return SubH; }
104 
109  inline int getBinX() { return BinX; }
110 
115  inline int getBinY() { return BinY; }
116 
121  inline float getPixelSizeX() { return PixelSizex; }
122 
127  inline float getPixelSizeY() { return PixelSizey; }
128 
133  inline int getBPP() { return BPP; }
134 
139  inline int getFrameBufferSize() { return RawFrameSize; }
140 
145  inline double getExposureLeft() { return ImageExposureN[0].value; }
146 
151  inline double getExposureDuration() { return exposureDuration; }
152 
157  const char *getExposureStartTime();
158 
163  inline uint8_t *getFrameBuffer() { return RawFrame; }
164 
173  void setFrameBuffer(uint8_t *buffer) { RawFrame = buffer; }
174 
179  inline bool isCompressed() { return SendCompressed; }
180 
185  inline bool isInterlaced() { return Interlaced; }
186 
191  inline CCD_FRAME getFrameType() { return FrameType; }
192 
198  const char *getFrameTypeName(CCD_FRAME fType);
199 
203  INumberVectorProperty *getCCDInfo() { return &ImagePixelSizeNP; }
204 
210  void setResolution(int x, int y);
211 
219  void setFrame(int subx, int suby, int subw, int subh);
220 
226  void setBin(int hor, int ver);
227 
238  void setMinMaxStep(const char *property, const char *element, double min, double max, double step,
239  bool sendToClient = true);
240 
246  void setPixelSize(float x, float y);
247 
252  void setCompressed(bool cmp);
253 
258  void setInterlaced(bool intr);
259 
268  void setFrameBufferSize(int nbuf, bool allocMem = true);
269 
274  void setBPP(int bpp);
275 
280  void setFrameType(CCD_FRAME type);
281 
288  void setExposureDuration(double duration);
289 
295  void setExposureLeft(double duration);
296 
300  void setExposureFailed();
301 
305  int getNAxis() const;
306 
311  void setNAxis(int value);
312 
317  void setImageExtension(const char *ext);
318 
322  char *getImageExtension() { return imageExtention; }
323 
327  bool isExposing() { return (ImageExposureNP.s == IPS_BUSY); }
328 
333  void binFrame();
334 
335  private:
337  int XRes;
339  int YRes;
341  int SubX;
343  int SubY;
345  int SubW;
347  int SubH;
349  int BinX;
351  int BinY;
353  int NAxis;
355  float PixelSizex;
357  float PixelSizey;
359  int BPP;
360  bool Interlaced = false;
361  uint8_t *RawFrame = nullptr;
362  uint8_t *BinFrame = nullptr;
363  int RawFrameSize = 0;
364  bool SendCompressed = false;
365  CCD_FRAME FrameType;
366  double exposureDuration;
367  timeval startExposureTime;
368  int lastRapidX;
369  int lastRapidY;
370  char imageExtention[MAXINDIBLOBFMT];
371 
372  INumberVectorProperty ImageExposureNP;
373  INumber ImageExposureN[1];
374 
375  ISwitchVectorProperty AbortExposureSP;
376  ISwitch AbortExposureS[1];
377 
378  INumberVectorProperty ImageFrameNP;
379  INumber ImageFrameN[4];
380 
381  INumberVectorProperty ImageBinNP;
382  INumber ImageBinN[2];
383 
384  INumberVectorProperty ImagePixelSizeNP;
385  INumber ImagePixelSizeN[6];
386 
387  ISwitch FrameTypeS[5];
388  ISwitchVectorProperty FrameTypeSP;
389 
390  ISwitch CompressS[2];
391  ISwitchVectorProperty CompressSP;
392 
393  IBLOB FitsB;
394  IBLOBVectorProperty FitsBP;
395 
396  ISwitch RapidGuideS[2];
397  ISwitchVectorProperty RapidGuideSP;
398 
399  ISwitch RapidGuideSetupS[3];
400  ISwitchVectorProperty RapidGuideSetupSP;
401 
402  INumber RapidGuideDataN[3];
403  INumberVectorProperty RapidGuideDataNP;
404 
405  ISwitch ResetS[1];
406  ISwitchVectorProperty ResetSP;
407 
408  friend class CCD;
409  friend class StreamRecoder;
410 };
411 
436 {
437  public:
438  CCD();
439  virtual ~CCD();
440 
441  enum
442  {
443  CCD_CAN_BIN = 1 << 0,
444  CCD_CAN_SUBFRAME = 1 << 1,
445  CCD_CAN_ABORT = 1 << 2,
446  CCD_HAS_GUIDE_HEAD = 1 << 3,
447  CCD_HAS_ST4_PORT = 1 << 4,
448  CCD_HAS_SHUTTER = 1 << 5,
449  CCD_HAS_COOLER = 1 << 6,
450  CCD_HAS_BAYER = 1 << 7,
451  CCD_HAS_STREAMING = 1 << 8
452  } CCDCapability;
453 
454  typedef enum { UPLOAD_CLIENT, UPLOAD_LOCAL, UPLOAD_BOTH } CCD_UPLOAD_MODE;
455 
456  virtual bool initProperties();
457  virtual bool updateProperties();
458  virtual void ISGetProperties(const char *dev);
459  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n);
460  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
461  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n);
462  virtual bool ISSnoopDevice(XMLEle *root);
463 
464  protected:
468  uint32_t GetCCDCapability() const { return capability; }
469 
474  void SetCCDCapability(uint32_t cap);
475 
479  bool CanAbort() { return capability & CCD_CAN_ABORT; }
480 
484  bool CanBin() { return capability & CCD_CAN_BIN; }
485 
489  bool CanSubFrame() { return capability & CCD_CAN_SUBFRAME; }
490 
494  bool HasGuideHead() { return capability & CCD_HAS_GUIDE_HEAD; }
495 
499  bool HasShutter() { return capability & CCD_HAS_SHUTTER; }
500 
504  bool HasST4Port() { return capability & CCD_HAS_ST4_PORT; }
505 
509  bool HasCooler() { return capability & CCD_HAS_COOLER; }
510 
514  bool HasBayer() { return capability & CCD_HAS_BAYER; }
515 
519  bool HasStreaming() { return capability & CCD_HAS_STREAMING; }
520 
532  virtual int SetTemperature(double temperature);
533 
540  virtual bool StartExposure(float duration);
541 
548  virtual bool ExposureComplete(CCDChip *targetChip);
549 
555  virtual bool AbortExposure();
556 
563  virtual bool StartGuideExposure(float duration);
564 
570  virtual bool AbortGuideExposure();
571 
583  virtual bool UpdateCCDFrame(int x, int y, int w, int h);
584 
596  virtual bool UpdateGuiderFrame(int x, int y, int w, int h);
597 
606  virtual bool UpdateCCDBin(int hor, int ver);
607 
616  virtual bool UpdateGuiderBin(int hor, int ver);
617 
626  virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType);
627 
635  virtual bool UpdateCCDUploadMode(CCD_UPLOAD_MODE mode) { INDI_UNUSED(mode); return true; }
636 
645  virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType);
646 
656  virtual void SetCCDParams(int x, int y, int bpp, float xf, float yf);
657 
667  virtual void SetGuiderParams(int x, int y, int bpp, float xf, float yf);
668 
675  virtual IPState GuideNorth(float ms);
676 
683  virtual IPState GuideSouth(float ms);
684 
691  virtual IPState GuideEast(float ms);
692 
699  virtual IPState GuideWest(float ms);
700 
705  virtual bool StartStreaming();
706 
711  virtual bool StopStreaming();
712 
735  virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip);
736 
738  void fits_update_key_s(fitsfile *fptr, int type, std::string name, void *p, std::string explanation, int *status);
739 
744  virtual void activeDevicesUpdated() {}
745 
751  virtual bool saveConfigItems(FILE *fp);
752 
753  void GuideComplete(INDI_EQ_AXIS axis);
754 
755  // Epoch Position
756  double RA, Dec;
757 
758  // J2000 Position
759  double J2000RA;
760  double J2000DE;
761 
762  double primaryFocalLength, primaryAperture, guiderFocalLength, guiderAperture;
767 
768  bool AutoLoop;
770  bool SendImage;
774 
777 
778  // Sky Quality
779  double MPSAS;
780 
781  // Rotator Angle
782  double RotatorAngle;
783 
784  // Airmas
785  double Airmass;
786  double Latitude;
787  double Longitude;
788 
789  std::vector<std::string> FilterNames;
791 
792  std::unique_ptr<StreamManager> Streamer;
793 
796 
797  // We are going to snoop these from a telescope
799  INumber EqN[2];
800 
802  IText ActiveDeviceT[4];
803  enum
804  {
808  SNOOP_SQM
809  };
810 
811  INumber TemperatureN[1];
813 
814  IText BayerT[3];
816 
817  IText FileNameT[1];
819 
820  ISwitch UploadS[3];
822 
823  IText UploadSettingsT[2];
825  enum
826  {
828  UPLOAD_PREFIX
829  };
830 
831  ISwitch TelescopeTypeS[2];
833  enum
834  {
836  TELESCOPE_GUIDE
837  };
838 
839  // WCS
840  ISwitch WorldCoordS[2];
842 
843  // WCS CCD Rotation
844  INumber CCDRotationN[1];
846 
847  // FITS Header
848  IText FITSHeaderT[2];
850  enum
851  {
853  FITS_OBJECT
854  };
855 
856  private:
857  uint32_t capability;
858 
859  bool ValidCCDRotation;
860 
861  bool uploadFile(CCDChip *targetChip, const void *fitsData, size_t totalBytes, bool sendImage, bool saveImage);
862  void getMinMax(double *min, double *max, CCDChip *targetChip);
863  int getFileIndex(const char *dir, const char *prefix, const char *ext);
864 
865  friend class StreamManager;
866 };
867 }
ITextVectorProperty FITSHeaderTP
Definition: indiccd.h:849
int getSubW()
getSubW Get the width of the frame
Definition: indiccd.h:97
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition: indiccd.h:435
int CurrentFilterSlot
Definition: indiccd.h:790
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
bool isCompressed()
isCompressed
Definition: indiccd.h:179
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value...
Definition: indiccd.cpp:230
void setImageExtension(const char *ext)
setImageExtension Set image exntension
Definition: indiccd.cpp:284
std::vector< std::string > FilterNames
Definition: indiccd.h:789
int getYRes()
Get the vertical resolution in pixels of the CCD Chip.
Definition: indiccd.h:79
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:161
bool InGuideExposure
Definition: indiccd.h:764
double primaryFocalLength
Definition: indiccd.h:762
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
Definition: indiccd.cpp:108
bool HasStreaming()
Definition: indiccd.h:519
bool HasCooler()
Definition: indiccd.h:509
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition: indiccd.h:51
double Longitude
Definition: indiccd.h:787
IPState
Property state.
Definition: indiapi.h:143
double getExposureLeft()
getExposureLeft Get exposure time left in seconds.
Definition: indiccd.h:145
int getNAxis() const
Definition: indiccd.cpp:274
std::unique_ptr< StreamManager > Streamer
Definition: indiccd.h:792
bool RapidGuideEnabled
Definition: indiccd.h:765
const char * getExposureStartTime()
getExposureStartTime
Definition: indiccd.cpp:248
bool HasShutter()
Definition: indiccd.h:499
One number descriptor.
Definition: indiapi.h:256
int getBPP()
getBPP Get CCD Chip depth (bits per pixel).
Definition: indiccd.h:133
Class to provide video streaming and recording functionality.
void setInterlaced(bool intr)
setInterlaced Set whether the CCD chip is interlaced or not?
Definition: indiccd.cpp:263
One Blob (Binary Large Object) descriptor.
Definition: indiapi.h:423
bool HasGuideHead()
Definition: indiccd.h:494
double max(void)
CCD_UPLOAD_MODE
Definition: indiccd.h:454
bool HasBayer()
Definition: indiccd.h:514
#define MAXINDIBLOBFMT
Definition: indiapi.h:177
void setFrameBuffer(uint8_t *buffer)
setFrameBuffer Set raw frame buffer pointer.
Definition: indiccd.h:173
void setNAxis(int value)
setNAxis Set FITS number of axis
Definition: indiccd.cpp:279
double RA
Definition: indiccd.h:756
bool isExposing()
Definition: indiccd.h:327
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
Definition: indiccd.cpp:243
INumberVectorProperty EqNP
Definition: indiccd.h:798
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:113
int getBinX()
getBinX Get horizontal binning of the CCD chip.
Definition: indiccd.h:109
int getFrameBufferSize()
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
Definition: indiccd.h:139
INumberVectorProperty TemperatureNP
Definition: indiccd.h:812
Switch vector property descriptor.
Definition: indiapi.h:347
double Latitude
Definition: indiccd.h:786
Namespace to encapsulate INDI client, drivers, and mediator classes. Developers can subclass the base...
int getSubH()
getSubH Get the height of the frame
Definition: indiccd.h:103
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:744
const char * IMAGE_SETTINGS_TAB
Definition: indiccd.cpp:48
double J2000DE
Definition: indiccd.h:760
const char * IMAGE_INFO_TAB
Definition: indiccd.cpp:49
virtual bool UpdateCCDUploadMode(CCD_UPLOAD_MODE mode)
CCD calls this function when client upload mode switch is updated.
Definition: indiccd.h:635
int getSubY()
getSubY Get the starting top coordinates (Y) of the frame.
Definition: indiccd.h:91
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
bool CanSubFrame()
Definition: indiccd.h:489
const char * GUIDE_HEAD_TAB
Definition: indiccd.cpp:50
CCDChip PrimaryCCD
Definition: indiccd.h:794
const char * RAPIDGUIDE_TAB
Definition: indiccd.cpp:52
bool GuiderShowMarker
Definition: indiccd.h:773
friend class StreamRecoder
Definition: indiccd.h:409
INumberVectorProperty CCDRotationNP
Definition: indiccd.h:845
One switch descriptor.
Definition: indiapi.h:329
bool GuiderAutoLoop
Definition: indiccd.h:769
ITextVectorProperty BayerTP
Definition: indiccd.h:815
int getXRes()
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition: indiccd.h:73
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
Definition: indiccd.cpp:237
bool SendImage
Definition: indiccd.h:770
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
INumberVectorProperty * getCCDInfo()
Return CCD Info Property.
Definition: indiccd.h:203
bool CanAbort()
Definition: indiccd.h:479
CCDChip GuideCCD
Definition: indiccd.h:795
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
Definition: indiccd.cpp:268
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:451
void setFrameBufferSize(int nbuf, bool allocMem=true)
setFrameBufferSize Set desired frame buffer size. The function will allocate memory accordingly...
Definition: indiccd.cpp:210
ISwitchVectorProperty TelescopeTypeSP
Definition: indiccd.h:832
void ISGetProperties(const char *dev)
Get Device Properties.
double RotatorAngle
Definition: indiccd.h:782
CCD_FRAME getFrameType()
getFrameType
Definition: indiccd.h:191
Number vector property descriptor.
Definition: indiapi.h:299
double getExposureDuration()
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
Definition: indiccd.h:151
One text descriptor.
Definition: indiapi.h:206
ISwitchVectorProperty UploadSP
Definition: indiccd.h:821
void setFrame(int subx, int suby, int subw, int subh)
setFrame Set desired frame resolutoin for an exposure.
Definition: indiccd.cpp:135
double MPSAS
Definition: indiccd.h:779
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
Definition: indiccd.h:163
INDI_EQ_AXIS
Definition: indibasetypes.h:32
bool InExposure
Definition: indiccd.h:763
#define INDI_UNUSED(x)
Definition: indidevapi.h:797
float ExposureTime
Definition: indiccd.h:775
ISState
Switch state.
Definition: indiapi.h:134
ITextVectorProperty UploadSettingsTP
Definition: indiccd.h:824
void setBPP(int bpp)
setBPP Set depth of CCD chip.
Definition: indiccd.cpp:201
bool HasST4Port()
Definition: indiccd.h:504
int getSubX()
getSubX Get the starting left coordinates (X) of the frame.
Definition: indiccd.h:85
ITextVectorProperty ActiveDeviceTP
Definition: indiccd.h:801
bool AutoLoop
Definition: indiccd.h:768
bool ShowMarker
Definition: indiccd.h:772
void setBin(int hor, int ver)
setBin Set CCD Chip binnig
Definition: indiccd.cpp:150
void setCompressed(bool cmp)
setCompressed Set whether a frame is compressed after exposure?
ISwitchVectorProperty WorldCoordSP
Definition: indiccd.h:841
bool GuiderRapidGuideEnabled
Definition: indiccd.h:766
friend class CCD
Definition: indiccd.h:408
double min(void)
Text vector property descriptor.
Definition: indiapi.h:226
double J2000RA
Definition: indiccd.h:759
bool isInterlaced()
isInterlaced
Definition: indiccd.h:185
void setResolution(int x, int y)
setResolution set CCD Chip resolution
Definition: indiccd.cpp:113
float getPixelSizeY()
getPixelSizeY Get vertical pixel size in microns.
Definition: indiccd.h:127
float GuiderExposureTime
Definition: indiccd.h:776
__le16 type
Definition: pwc-ioctl.h:53
int getBinY()
getBinY Get vertical binning of the CCD chip.
Definition: indiccd.h:115
bool GuiderSendImage
Definition: indiccd.h:771
ITextVectorProperty FileNameTP
Definition: indiccd.h:818
char * getImageExtension()
Definition: indiccd.h:322
uint32_t GetCCDCapability() const
GetCCDCapability returns the CCD capabilities.
Definition: indiccd.h:468
float getPixelSizeX()
getPixelSizeX Get horizontal pixel size in microns.
Definition: indiccd.h:121
void binFrame()
binFrame Perform softwre binning on the CCD frame. Only use this function if hardware binning is not ...
Definition: indiccd.cpp:289
bool CanBin()
Definition: indiccd.h:484
double Airmass
Definition: indiccd.h:785
void addFITSKeywords(fitsfile *fptr, IMAGE_INFO *image_info)
Definition: stv.c:1597
void uploadFile(const char *filename)
Definition: stv.c:1710
void setPixelSize(float x, float y)
setPixelSize Set CCD Chip pixel size
Definition: indiccd.cpp:189
double value
Definition: indiapi.h:271