Instrument Neutral Distributed Interface INDI  1.0.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 
44 class CCDChip
45 {
46 
47 public:
48  CCDChip();
49  ~CCDChip();
50 
51  typedef enum { LIGHT_FRAME=0, BIAS_FRAME, DARK_FRAME, FLAT_FRAME } CCD_FRAME;
52  typedef enum { FRAME_X, FRAME_Y, FRAME_W, FRAME_H} CCD_FRAME_INDEX;
53  typedef enum { BIN_W, BIN_H} CCD_BIN_INDEX;
54  typedef enum { CCD_MAX_X, CCD_MAX_Y, CCD_PIXEL_SIZE, CCD_PIXEL_SIZE_X, CCD_PIXEL_SIZE_Y, CCD_BITSPERPIXEL} CCD_INFO_INDEX;
55 
60  inline int getXRes() { return XRes; }
61 
66  inline int getYRes() { return YRes; }
67 
72  inline int getSubX() { return SubX; }
73 
78  inline int getSubY() { return SubY; }
79 
84  inline int getSubW() { return SubW; }
85 
90  inline int getSubH() { return SubH; }
91 
96  inline int getBinX() { return BinX; }
97 
102  inline int getBinY() { return BinY; }
103 
108  inline float getPixelSizeX() { return PixelSizex; }
109 
114  inline float getPixelSizeY() { return PixelSizey; }
115 
120  inline int getBPP() { return BPP; }
121 
126  inline int getFrameBufferSize() { return RawFrameSize; }
127 
132  inline double getExposureLeft() { return ImageExposureN[0].value; }
133 
138  inline double getExposureDuration() { return exposureDuration; }
139 
144  const char *getExposureStartTime();
145 
150  inline char *getFrameBuffer() { return RawFrame; }
151 
158  void setFrameBuffer(char *buffer) { RawFrame = buffer; }
159 
164  inline bool isCompressed() { return SendCompressed; }
165 
170  inline bool isInterlaced() { return Interlaced; }
171 
176  inline CCD_FRAME getFrameType() { return FrameType; }
177 
183  const char *getFrameTypeName(CCD_FRAME fType);
184 
188  INumberVectorProperty * getCCDInfo() { return &ImagePixelSizeNP; }
189 
195  void setResolution(int x, int y);
196 
204  void setFrame(int subx, int suby, int subw, int subh);
205 
211  void setBin(int hor, int ver);
212 
222  void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true);
223 
229  void setPixelSize(float x, float y);
230 
235  void setCompressed (bool cmp);
236 
241  void setInterlaced(bool intr);
242 
250  void setFrameBufferSize(int nbuf, bool allocMem=true);
251 
256  void setBPP(int bpp);
257 
262  void setFrameType(CCD_FRAME type);
263 
269  void setExposureDuration(double duration);
270 
275  void setExposureLeft(double duration);
276 
280  void setExposureFailed();
281 
285  int getNAxis() const;
286 
291  void setNAxis(int value);
292 
297  void setImageExtension(const char *ext);
298 
302  char *getImageExtension() { return imageExtention;}
303 
307  bool isExposing() { return (ImageExposureNP.s == IPS_BUSY); }
308 
309 private:
310 
311  int XRes; // native resolution of the ccd
312  int YRes; // ditto
313  int SubX; // left side of the subframe we are requesting
314  int SubY; // top of the subframe requested
315  int SubW; // UNBINNED width of the subframe
316  int SubH; // UNBINNED height of the subframe
317  int BinX; // Binning requested in the x direction
318  int BinY; // Binning requested in the Y direction
319  int NAxis; // # of Axis
320  float PixelSizex; // pixel size in microns, x direction
321  float PixelSizey; // pixel size in microns, y direction
322  int BPP; // Bytes per Pixel
323  bool Interlaced;
324  char *RawFrame;
325  int RawFrameSize;
326  bool SendCompressed;
327  CCD_FRAME FrameType;
328  double exposureDuration;
329  timeval startExposureTime;
330  int lastRapidX;
331  int lastRapidY;
332  char imageExtention[MAXINDIBLOBFMT];
333 
334  INumberVectorProperty ImageExposureNP;
335  INumber ImageExposureN[1];
336 
337  ISwitchVectorProperty AbortExposureSP;
338  ISwitch AbortExposureS[1];
339 
340  INumberVectorProperty ImageFrameNP;
341  INumber ImageFrameN[4];
342 
343  INumberVectorProperty ImageBinNP;
344  INumber ImageBinN[2];
345 
346  INumberVectorProperty ImagePixelSizeNP;
347  INumber ImagePixelSizeN[6];
348 
349  ISwitch FrameTypeS[5];
350  ISwitchVectorProperty FrameTypeSP;
351 
352  ISwitch CompressS[2];
353  ISwitchVectorProperty CompressSP;
354 
355  IBLOB FitsB;
356  IBLOBVectorProperty FitsBP;
357 
358  ISwitch RapidGuideS[2];
359  ISwitchVectorProperty RapidGuideSP;
360 
361  ISwitch RapidGuideSetupS[3];
362  ISwitchVectorProperty RapidGuideSetupSP;
363 
364  INumber RapidGuideDataN[3];
365  INumberVectorProperty RapidGuideDataNP;
366 
367  ISwitch ResetS[1];
368  ISwitchVectorProperty ResetSP;
369 
370  friend class INDI::CCD;
371 };
372 
383 {
384  public:
385  CCD();
386  virtual ~CCD();
387 
391  typedef struct
392  {
400  bool hasCooler;
402  bool canBin;
406  bool canAbort;
408  bool hasBayer;
409  } CCDCapability;
410 
411  virtual bool initProperties();
412  virtual bool updateProperties();
413  virtual void ISGetProperties (const char *dev);
414  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
415  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
416  virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n);
417  virtual bool ISSnoopDevice (XMLEle *root);
418 
419  protected:
420 
424  CCDCapability GetCCDCapability() const { return capability;}
425 
430  void SetCCDCapability(CCDCapability * cap);
431 
435  bool CanAbort() { return capability.canAbort;}
436 
440  bool CanBin() { return capability.canBin;}
441 
445  bool CanSubFrame() { return capability.canSubFrame;}
446 
450  bool HasGuideHead() { return capability.hasGuideHead; }
451 
455  bool HasShutter() { return capability.hasShutter;}
456 
460  bool HasST4Port() { return capability.hasST4Port;}
461 
465  bool HasCooler() { return capability.hasCooler;}
466 
470  bool HasBayer() { return capability.hasBayer;}
471 
481  virtual int SetTemperature(double temperature);
482 
488  virtual bool StartExposure(float duration);
489 
494  virtual bool ExposureComplete(CCDChip *targetChip);
495 
500  virtual bool AbortExposure();
501 
507  virtual bool StartGuideExposure(float duration);
508 
513  virtual bool AbortGuideExposure();
514 
524  virtual bool UpdateCCDFrame(int x, int y, int w, int h);
525 
526 
536  virtual bool UpdateGuiderFrame(int x, int y, int w, int h);
537 
538 
545  virtual bool UpdateCCDBin(int hor, int ver);
546 
547 
554  virtual bool UpdateGuiderBin(int hor, int ver);
555 
562  virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType);
563 
570  virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType);
571 
579  virtual void SetCCDParams(int x,int y,int bpp,float xf,float yf);
580 
588  virtual void SetGuiderParams(int x,int y,int bpp,float xf,float yf);
589 
590 
596  virtual bool GuideNorth(float ms);
597 
603  virtual bool GuideSouth(float ms);
604 
610  virtual bool GuideEast(float ms);
611 
617  virtual bool GuideWest(float ms);
618 
638  virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip);
639 
640  /* A function to just remove GCC warnings about deprecated conversion */
641  void fits_update_key_s(fitsfile* fptr, int type, std::string name, void* p, std::string explanation, int* status);
642 
646  virtual void activeDevicesUpdated() {}
647 
648  virtual bool saveConfigItems(FILE *fp);
649 
650 
651  double RA, Dec;
652  bool InExposure;
653  bool InGuideExposure;
654  bool RapidGuideEnabled;
655  bool GuiderRapidGuideEnabled;
656 
657  bool AutoLoop;
658  bool GuiderAutoLoop;
659  bool SendImage;
660  bool GuiderSendImage;
661  bool ShowMarker;
662  bool GuiderShowMarker;
663 
664  float ExposureTime;
665  float GuiderExposureTime;
666 
667  std::vector<std::string> FilterNames;
668  int CurrentFilterSlot;
669 
670  CCDChip PrimaryCCD;
671  CCDChip GuideCCD;
672 
673  // We are going to snoop these from a telescope
675  INumber EqN[2];
676 
677  ITextVectorProperty ActiveDeviceTP;
678  IText ActiveDeviceT[3];
679 
680  INumber TemperatureN[1];
681  INumberVectorProperty TemperatureNP;
682 
683  IText BayerT[3];
684  ITextVectorProperty BayerTP;
685 
686  ISwitch UploadS[3];
687  ISwitchVectorProperty UploadSP;
688 
689  IText UploadSettingsT[2];
690  ITextVectorProperty UploadSettingsTP;
691 
692  private:
693  CCDCapability capability;
694 
695  bool uploadFile(CCDChip * targetChip, const void *fitsData, size_t totalBytes, bool sendImage, bool saveImage);
696  void getMinMax(double *min, double *max, CCDChip *targetChip);
697  int getFileIndex(const char *dir, const char *prefix, const char *ext);
698 
699 
700 };
701 
702 #endif // INDI:CCD_H
CCDCapability GetCCDCapability() const
GetCCDCapability returns the CCD capabilities.
Definition: indiccd.h:424
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver...
Definition: indiccd.cpp:458
void setPixelSize(float x, float y)
setPixelSize Set CCD Chip pixel size
Definition: indiccd.cpp:150
int getSubH()
getSubH Get the height of the frame
Definition: indiccd.h:90
void setFrameBufferSize(int nbuf, bool allocMem=true)
setFrameBufferSize Set desired frame buffer size. The function will allocate memory accordingly...
Definition: indiccd.cpp:172
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition: indiccd.h:382
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:110
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
Definition: indiccd.cpp:68
bool isExposing()
Definition: indiccd.h:307
virtual void addFITSKeywords(fitsfile *fptr, CCDChip *targetChip)
Add FITS keywords to a fits file.
Definition: indiccd.cpp:1219
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition: indiccd.cpp:680
virtual bool UpdateCCDFrame(int x, int y, int w, int h)
INDI::CCD calls this function when CCD Frame dimension needs to be updated in the hardware...
Definition: indiccd.cpp:1178
bool HasCooler()
Definition: indiccd.h:465
virtual bool StartExposure(float duration)
Start exposing primary CCD chip.
Definition: indiccd.cpp:1154
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
Definition: indiccd.cpp:192
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value...
Definition: indiccd.cpp:185
virtual bool GuideEast(float ms)
Guide easward for ms milliseconds.
Definition: indiccd.cpp:1773
void SetCCDCapability(CCDCapability *cap)
SetCCDCapability Set the CCD capabilities. Al fields must be initilized.
Definition: indiccd.cpp:278
void setImageExtension(const char *ext)
setImageExtension Set image exntension
Definition: indiccd.cpp:236
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:73
bool isCompressed()
isCompressed
Definition: indiccd.h:164
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
Definition: indiccd.cpp:198
bool HasShutter()
Definition: indiccd.h:455
One number descriptor.
Definition: indiapi.h:224
bool isInterlaced()
isInterlaced
Definition: indiccd.h:170
Provides interface to implement guider (ST4) port functionality.
One Blob (Binary Large Object) descriptor.
Definition: indiapi.h:356
virtual bool StartGuideExposure(float duration)
Start exposing guide CCD chip.
Definition: indiccd.cpp:1160
int getYRes()
Get the vertical resolution in pixels of the CCD Chip.
Definition: indiccd.h:66
bool HasGuideHead()
Definition: indiccd.h:450
bool HasBayer()
Definition: indiccd.h:470
double getExposureDuration()
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
Definition: indiccd.h:138
int getNAxis() const
Definition: indiccd.cpp:226
void setFrameBuffer(char *buffer)
setFrameBuffer Set raw frame buffer pointer.
Definition: indiccd.h:158
virtual bool GuideNorth(float ms)
Guide northward for ms milliseconds.
Definition: indiccd.cpp:1763
virtual int SetTemperature(double temperature)
Set CCD temperature.
Definition: indiccd.cpp:1147
int getFrameBufferSize()
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
Definition: indiccd.h:126
float getPixelSizeY()
getPixelSizeY Get vertical pixel size in microns.
Definition: indiccd.h:114
virtual bool GuideWest(float ms)
Guide westward for ms milliseconds.
Definition: indiccd.cpp:1778
virtual bool UpdateGuiderFrameType(CCDChip::CCD_FRAME fType)
INDI::CCD calls this function when Guide frame type is updated by the client.
Definition: indiccd.cpp:1212
float getPixelSizeX()
getPixelSizeX Get horizontal pixel size in microns.
Definition: indiccd.h:108
Switch vector property descriptor.
Definition: indiapi.h:291
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
Definition: indiccd.cpp:220
virtual void SetCCDParams(int x, int y, int bpp, float xf, float yf)
Setup CCD paramters for primary CCD. Child classes call this function to update CCD paramaters...
Definition: indiccd.cpp:1718
virtual void activeDevicesUpdated()
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
Definition: indiccd.h:646
bool CanSubFrame()
Definition: indiccd.h:445
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:122
One switch descriptor.
Definition: indiapi.h:280
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function...
Definition: indiccd.cpp:290
void setNAxis(int value)
setNAxis Set FITS number of axis
Definition: indiccd.cpp:231
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition: indiccd.h:44
virtual bool UpdateCCDFrameType(CCDChip::CCD_FRAME fType)
INDI::CCD calls this function when CCD frame type needs to be updated in the hardware.
Definition: indiccd.cpp:1205
bool CanAbort()
Definition: indiccd.h:435
char * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
Definition: indiccd.h:150
void setFrame(int subx, int suby, int subw, int subh)
setFrame Set desired frame resolutoin for an exposure.
Definition: indiccd.cpp:95
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:379
void setInterlaced(bool intr)
setInterlaced Set whether the CCD chip is interlaced or not?
Definition: indiccd.cpp:215
char * getImageExtension()
Definition: indiccd.h:302
Number vector property descriptor.
Definition: indiapi.h:252
One text descriptor.
Definition: indiapi.h:178
virtual bool GuideSouth(float ms)
Guide southward for ms milliseconds.
Definition: indiccd.cpp:1768
int getXRes()
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition: indiccd.h:60
int getBinX()
getBinX Get horizontal binning of the CCD chip.
Definition: indiccd.h:96
virtual void SetGuiderParams(int x, int y, int bpp, float xf, float yf)
Setup CCD paramters for guide head CCD. Child classes call this function to update CCD paramaters...
Definition: indiccd.cpp:1729
int getSubW()
getSubW Get the width of the frame
Definition: indiccd.h:84
virtual bool UpdateCCDBin(int hor, int ver)
INDI::CCD calls this function when CCD Binning needs to be updated in the hardware. Derived classes should implement this function.
Definition: indiccd.cpp:1191
double getExposureLeft()
getExposureLeft Get exposure time left in seconds.
Definition: indiccd.h:132
const char * getExposureStartTime()
getExposureStartTime
Definition: indiccd.cpp:203
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: indiccd.cpp:597
Holds the capabilities of the CCD. All fields must be initialized.
Definition: indiccd.h:391
CCD_FRAME getFrameType()
getFrameType
Definition: indiccd.h:176
ISState
Switch state.
Definition: indiapi.h:106
bool HasST4Port()
Definition: indiccd.h:460
virtual bool AbortExposure()
Abort ongoing exposure.
Definition: indiccd.cpp:1166
int getBinY()
getBinY Get vertical binning of the CCD chip.
Definition: indiccd.h:102
void setBPP(int bpp)
setBPP Set depth of CCD chip.
Definition: indiccd.cpp:163
Text vector property descriptor.
Definition: indiapi.h:196
int getSubX()
getSubX Get the starting left coordinates (X) of the frame.
Definition: indiccd.h:72
int getSubY()
getSubY Get the starting top coordinates (Y) of the frame.
Definition: indiccd.h:78
virtual bool AbortGuideExposure()
Abort ongoing exposure.
Definition: indiccd.cpp:1172
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
Definition: indiccd.cpp:631
virtual bool UpdateGuiderBin(int hor, int ver)
INDI::CCD calls this function when Guide head binning is updated by the client. Derived classes shoul...
Definition: indiccd.cpp:1198
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minumum set of properties are defined t...
Definition: indiccd.cpp:447
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition: indiccd.cpp:906
virtual bool UpdateGuiderFrame(int x, int y, int w, int h)
INDI::CCD calls this function when Guide head frame dimension is updated by the client. Derived classes should implement this function.
Definition: indiccd.cpp:1185
int getBPP()
getBPP Get CCD Chip depth (bits per pixel).
Definition: indiccd.h:120
bool CanBin()
Definition: indiccd.h:440
INumberVectorProperty * getCCDInfo()
Return CCD Info Property.
Definition: indiccd.h:188
virtual bool ExposureComplete(CCDChip *targetChip)
Uploads target Chip exposed buffer as FITS to the client. Dervied classes should class this functon w...
Definition: indiccd.cpp:1317
double value
Definition: indiapi.h:230