Instrument Neutral Distributed Interface INDI  2.0.2
indiccdchip.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2019 Jasem Mutlaq. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 *******************************************************************************/
18 
19 #pragma once
20 
21 #include "indiapi.h"
22 #include "indidriver.h"
23 
24 #include <sys/time.h>
25 #include <stdint.h>
26 #include <fitsio.h>
27 
28 namespace INDI
29 {
30 
34 class CCDChip
35 {
36  public:
37  CCDChip();
38  ~CCDChip();
39 
42  typedef enum { BIN_W, BIN_H } CCD_BIN_INDEX;
43  typedef enum
44  {
52 
59  bool openFITSFile(uint32_t size, int &status);
60 
61 
66  bool finishFITSFile(int &status);
67 
71  void closeFITSFile();
72 
77  inline int getXRes() const
78  {
79  return XRes;
80  }
81 
86  inline int getYRes() const
87  {
88  return YRes;
89  }
90 
95  inline int getSubX() const
96  {
97  return SubX;
98  }
99 
104  inline int getSubY() const
105  {
106  return SubY;
107  }
108 
113  inline int getSubW() const
114  {
115  return SubW;
116  }
117 
122  inline int getSubH() const
123  {
124  return SubH;
125  }
126 
131  inline int getBinX() const
132  {
133  return BinX;
134  }
135 
140  inline int getBinY() const
141  {
142  return BinY;
143  }
144 
149  inline float getPixelSizeX() const
150  {
151  return PixelSizeX;
152  }
153 
158  inline float getPixelSizeY() const
159  {
160  return PixelSizeY;
161  }
162 
167  inline int getBPP() const
168  {
169  return BitsPerPixel;
170  }
171 
176  inline int getFrameBufferSize() const
177  {
178  return RawFrameSize;
179  }
180 
185  inline double getExposureLeft() const
186  {
187  return ImageExposureN[0].value;
188  }
189 
194  inline double getExposureDuration() const
195  {
196  return ExposureDuration;
197  }
198 
203  const char *getExposureStartTime();
204 
209  inline uint8_t *getFrameBuffer()
210  {
211  return RawFrame;
212  }
213 
222  void setFrameBuffer(uint8_t *buffer)
223  {
224  RawFrame = buffer;
225  }
226 
231  inline bool isCompressed() const
232  {
233  return SendCompressed;
234  }
235 
240  // inline bool isInterlaced()
241  // {
242  // return Interlaced;
243  // }
244 
249  inline CCD_FRAME getFrameType() const
250  {
251  return FrameType;
252  }
253 
259  const char *getFrameTypeName(CCD_FRAME fType);
260 
265  {
266  return &ImagePixelSizeNP;
267  }
268 
274  void setResolution(uint32_t x, uint32_t y);
275 
283  void setFrame(uint32_t subx, uint32_t suby, uint32_t subw, uint32_t subh);
284 
290  void setBin(uint8_t hor, uint8_t ver);
291 
302  void setMinMaxStep(const char *property, const char *element, double min, double max, double step,
303  bool sendToClient = true);
304 
310  void setPixelSize(double x, double y);
311 
316  void setCompressed(bool cmp);
317 
318  // /**
319  // * @brief setInterlaced Set whether the CCD chip is interlaced or not?
320  // * @param intr If true, the CCD chip is interlaced.
321  // */
322  // void setInterlaced(bool intr);
323 
332  void setFrameBufferSize(uint32_t nbuf, bool allocMem = true);
333 
338  void setBPP(uint8_t bpp);
339 
345 
352  void setExposureDuration(double duration);
353 
359  void setExposureLeft(double duration);
360 
364  void setExposureComplete();
365 
369  void setExposureFailed();
370 
374  int getNAxis() const;
375 
380  void setNAxis(int value);
381 
386  void setImageExtension(const char *ext);
387 
392  {
393  return ImageExtention;
394  }
395 
399  bool isExposing() const
400  {
401  return (ImageExposureNP.s == IPS_BUSY);
402  }
403 
408  void binFrame();
409 
414  void binBayerFrame();
415 
416  fitsfile **fitsFilePointer()
417  {
418  return &m_FITSFilePointer;
419  }
420 
422  {
423  return &m_FITSMemorySize;
424  }
425 
427  {
428  return &m_FITSMemoryBlock;
429  }
430 
431  private:
435 
437  uint32_t XRes {0};
439  uint32_t YRes {0};
441  uint32_t SubX {0};
443  uint32_t SubY {0};
445  uint32_t SubW {0};
447  uint32_t SubH {0};
449  uint8_t BinX {1};
451  uint32_t BinY {1};
453  uint8_t NAxis {2};
455  double PixelSizeX {0};
457  double PixelSizeY {0};
459  uint8_t BitsPerPixel {8};
460  //bool Interlaced {false};
461  // RAW Frame for image data stored as bytes.
462  uint8_t *RawFrame {nullptr};
463  // RAW Frame size in bytes.
464  uint32_t RawFrameSize {0};
465  // BINNED Frame when software binning is used.
466  uint8_t *BinFrame {nullptr};
467  // Should we compress frame before transmission?
468  bool SendCompressed {false};
469  // Frame Type
470  CCD_FRAME FrameType {LIGHT_FRAME};
471  // Exposure duration in seconds.
472  double ExposureDuration {0};
473  // Exposure startup time
474  timeval StartExposureTime;
475  // Image extension type (e.g. jpg)
476  char ImageExtention[MAXINDIBLOBFMT];
477  void * m_FITSMemoryBlock {nullptr};
478  size_t m_FITSMemorySize {2880};
479  fitsfile * m_FITSFilePointer {nullptr};
480 
484 
488  INumberVectorProperty ImageExposureNP;
489  INumber ImageExposureN[1];
490 
494  ISwitchVectorProperty AbortExposureSP;
495  ISwitch AbortExposureS[1];
496 
500  INumberVectorProperty ImageFrameNP;
501  INumber ImageFrameN[4];
502 
506  INumberVectorProperty ImageBinNP;
507  INumber ImageBinN[2];
508 
512  INumberVectorProperty ImagePixelSizeNP;
513  INumber ImagePixelSizeN[6];
514 
518  ISwitchVectorProperty FrameTypeSP;
519  ISwitch FrameTypeS[4];
520 
524  ISwitchVectorProperty CompressSP;
525  ISwitch CompressS[2];
526 
530  IBLOBVectorProperty FitsBP;
531  IBLOB FitsB;
532 
536  ISwitchVectorProperty ResetSP;
537  ISwitch ResetS[1];
538 
539  friend class CCD;
540  friend class StreamRecoder;
541 
542 #if 0
543  ISwitch RapidGuideS[2];
544  ISwitchVectorProperty RapidGuideSP;
545 
546  ISwitch RapidGuideSetupS[3];
547  ISwitchVectorProperty RapidGuideSetupSP;
548 
549  INumber RapidGuideDataN[3];
550  INumberVectorProperty RapidGuideDataNP;
551 #endif
552 
553 };
554 
555 }
The CCDChip class provides functionality of a CCD Chip within a CCD.
Definition: indiccdchip.h:35
void setExposureComplete()
setExposureComplete Mark exposure as complete by setting ImageExposure property to IPS_OK
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
Definition: indiccdchip.h:209
void setFrameBuffer(uint8_t *buffer)
setFrameBuffer Set raw frame buffer pointer.
Definition: indiccdchip.h:222
int getSubX() const
getSubX Get the starting left coordinates (X) of the frame.
Definition: indiccdchip.h:95
int getSubY() const
getSubY Get the starting top coordinates (Y) of the frame.
Definition: indiccdchip.h:104
bool finishFITSFile(int &status)
Finish any pending write to fits file.
Definition: indiccdchip.cpp:61
float getPixelSizeY() const
getPixelSizeY Get vertical pixel size in microns.
Definition: indiccdchip.h:158
size_t * fitsMemorySizePointer()
Definition: indiccdchip.h:421
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
void setResolution(uint32_t x, uint32_t y)
setResolution set CCD Chip resolution
Definition: indiccdchip.cpp:90
int getSubH() const
getSubH Get the height of the frame
Definition: indiccdchip.h:122
double getExposureDuration() const
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
Definition: indiccdchip.h:194
void setCompressed(bool cmp)
setCompressed Set whether a frame is compressed after exposure?
int getBPP() const
getBPP Get CCD Chip depth (bits per pixel).
Definition: indiccdchip.h:167
const char * getExposureStartTime()
getExposureStartTime
char * getImageExtension()
Definition: indiccdchip.h:391
CCD_FRAME getFrameType() const
isInterlaced
Definition: indiccdchip.h:249
int getBinY() const
getBinY Get vertical binning of the CCD chip.
Definition: indiccdchip.h:140
void closeFITSFile()
closeFITSFile Close the in-memory FITS File.
Definition: indiccdchip.cpp:72
float getPixelSizeX() const
getPixelSizeX Get horizontal pixel size in microns.
Definition: indiccdchip.h:149
friend class StreamRecoder
Definition: indiccdchip.h:540
void setFrame(uint32_t subx, uint32_t suby, uint32_t subw, uint32_t subh)
setFrame Set desired frame resolutoin for an exposure.
void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true)
setMinMaxStep for a number property element
int getXRes() const
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition: indiccdchip.h:77
bool isExposing() const
Definition: indiccdchip.h:399
int getBinX() const
getBinX Get horizontal binning of the CCD chip.
Definition: indiccdchip.h:131
INumberVectorProperty * getCCDInfo()
Return CCD Info Property.
Definition: indiccdchip.h:264
bool isCompressed() const
isCompressed
Definition: indiccdchip.h:231
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
Definition: indiccdchip.cpp:85
void setImageExtension(const char *ext)
setImageExtension Set image exntension
void ** fitsMemoryBlockPointer()
Definition: indiccdchip.h:426
void setPixelSize(double x, double y)
setPixelSize Set CCD Chip pixel size
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value.
int getSubW() const
getSubW Get the width of the frame
Definition: indiccdchip.h:113
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
double getExposureLeft() const
getExposureLeft Get exposure time left in seconds.
Definition: indiccdchip.h:185
void setFrameBufferSize(uint32_t nbuf, bool allocMem=true)
setFrameBufferSize Set desired frame buffer size. The function will allocate memory accordingly....
fitsfile ** fitsFilePointer()
Definition: indiccdchip.h:416
int getFrameBufferSize() const
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
Definition: indiccdchip.h:176
void setBin(uint8_t hor, uint8_t ver)
setBin Set CCD Chip binnig
int getNAxis() const
void binBayerFrame()
binBayerFrame Perform software binning on a 2x2 Bayer matrix CCD frame. Only use this function if har...
int getYRes() const
Get the vertical resolution in pixels of the CCD Chip.
Definition: indiccdchip.h:86
void binFrame()
binFrame Perform software binning on the CCD frame. Only use this function if hardware binning is not...
void setBPP(uint8_t bpp)
setBPP Set depth of CCD chip.
bool openFITSFile(uint32_t size, int &status)
openFITSFile Allocate memory buffer for internal FITS file structure and open
Definition: indiccdchip.cpp:40
void setNAxis(int value)
setNAxis Set FITS number of axis
Class to provide general functionality of CCD cameras with a single CCD sensor, or a primary CCD sens...
Definition: indiccd.h:116
double max(void)
double min(void)
Constants and Data structure definitions for the interface to the reference INDI C API implementation...
#define MAXINDIBLOBFMT
Definition: indiapi.h:196
@ IPS_BUSY
Definition: indiapi.h:163
std::vector< uint8_t > buffer
Namespace to encapsulate INDI client, drivers, and mediator classes.
__le16 type
Definition: pwc-ioctl.h:0
One Blob (Binary Large Object) descriptor.
One number descriptor.
One switch descriptor.
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:471
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367