Instrument Neutral Distributed Interface INDI  1.9.5
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 
23 #include <sys/time.h>
24 #include <stdint.h>
25 
26 namespace INDI
27 {
28 
32 class CCDChip
33 {
34  public:
35  CCDChip();
36  ~CCDChip();
37 
38  typedef enum { LIGHT_FRAME = 0, BIAS_FRAME, DARK_FRAME, FLAT_FRAME } CCD_FRAME;
39  typedef enum { FRAME_X, FRAME_Y, FRAME_W, FRAME_H } CCD_FRAME_INDEX;
40  typedef enum { BIN_W, BIN_H } CCD_BIN_INDEX;
41  typedef enum
42  {
43  CCD_MAX_X,
44  CCD_MAX_Y,
50 
55  inline int getXRes() const
56  {
57  return XRes;
58  }
59 
64  inline int getYRes() const
65  {
66  return YRes;
67  }
68 
73  inline int getSubX() const
74  {
75  return SubX;
76  }
77 
82  inline int getSubY() const
83  {
84  return SubY;
85  }
86 
91  inline int getSubW() const
92  {
93  return SubW;
94  }
95 
100  inline int getSubH() const
101  {
102  return SubH;
103  }
104 
109  inline int getBinX() const
110  {
111  return BinX;
112  }
113 
118  inline int getBinY() const
119  {
120  return BinY;
121  }
122 
127  inline float getPixelSizeX() const
128  {
129  return PixelSizeX;
130  }
131 
136  inline float getPixelSizeY() const
137  {
138  return PixelSizeY;
139  }
140 
145  inline int getBPP() const
146  {
147  return BitsPerPixel;
148  }
149 
154  inline int getFrameBufferSize() const
155  {
156  return RawFrameSize;
157  }
158 
163  inline double getExposureLeft() const
164  {
165  return ImageExposureN[0].value;
166  }
167 
172  inline double getExposureDuration() const
173  {
174  return ExposureDuration;
175  }
176 
181  const char *getExposureStartTime();
182 
187  inline uint8_t *getFrameBuffer()
188  {
189  return RawFrame;
190  }
191 
200  void setFrameBuffer(uint8_t *buffer)
201  {
202  RawFrame = buffer;
203  }
204 
209  inline bool isCompressed() const
210  {
211  return SendCompressed;
212  }
213 
218  // inline bool isInterlaced()
219  // {
220  // return Interlaced;
221  // }
222 
227  inline CCD_FRAME getFrameType() const
228  {
229  return FrameType;
230  }
231 
237  const char *getFrameTypeName(CCD_FRAME fType);
238 
243  {
244  return &ImagePixelSizeNP;
245  }
246 
252  void setResolution(uint32_t x, uint32_t y);
253 
261  void setFrame(uint32_t subx, uint32_t suby, uint32_t subw, uint32_t subh);
262 
268  void setBin(uint8_t hor, uint8_t ver);
269 
280  void setMinMaxStep(const char *property, const char *element, double min, double max, double step,
281  bool sendToClient = true);
282 
288  void setPixelSize(double x, double y);
289 
294  void setCompressed(bool cmp);
295 
296  // /**
297  // * @brief setInterlaced Set whether the CCD chip is interlaced or not?
298  // * @param intr If true, the CCD chip is interlaced.
299  // */
300  // void setInterlaced(bool intr);
301 
310  void setFrameBufferSize(uint32_t nbuf, bool allocMem = true);
311 
316  void setBPP(uint8_t bpp);
317 
323 
330  void setExposureDuration(double duration);
331 
337  void setExposureLeft(double duration);
338 
342  void setExposureComplete();
343 
347  void setExposureFailed();
348 
352  int getNAxis() const;
353 
358  void setNAxis(int value);
359 
364  void setImageExtension(const char *ext);
365 
369  char *getImageExtension()
370  {
371  return ImageExtention;
372  }
373 
377  bool isExposing() const
378  {
379  return (ImageExposureNP.s == IPS_BUSY);
380  }
381 
386  void binFrame();
387 
392  void binBayerFrame();
393 
394  private:
398 
400  uint32_t XRes {0};
402  uint32_t YRes {0};
404  uint32_t SubX {0};
406  uint32_t SubY {0};
408  uint32_t SubW {0};
410  uint32_t SubH {0};
412  uint8_t BinX {1};
414  uint32_t BinY {1};
416  uint8_t NAxis {2};
418  double PixelSizeX {0};
420  double PixelSizeY {0};
422  uint8_t BitsPerPixel {8};
423  //bool Interlaced {false};
424  // RAW Frame for image data stored as bytes.
425  uint8_t *RawFrame {nullptr};
426  // RAW Frame size in bytes.
427  uint32_t RawFrameSize {0};
428  // BINNED Frame when software binning is used.
429  uint8_t *BinFrame {nullptr};
430  // Should we compress frame before transmission?
431  bool SendCompressed {false};
432  // Frame Type
433  CCD_FRAME FrameType {LIGHT_FRAME};
434  // Exposure duration in seconds.
435  double ExposureDuration {0};
436  // Exposure startup time
437  timeval StartExposureTime;
438  // Image extension type (e.g. jpg)
439  char ImageExtention[MAXINDIBLOBFMT];
440 
444 
448  INumberVectorProperty ImageExposureNP;
449  INumber ImageExposureN[1];
450 
454  ISwitchVectorProperty AbortExposureSP;
455  ISwitch AbortExposureS[1];
456 
460  INumberVectorProperty ImageFrameNP;
461  INumber ImageFrameN[4];
462 
466  INumberVectorProperty ImageBinNP;
467  INumber ImageBinN[2];
468 
472  INumberVectorProperty ImagePixelSizeNP;
473  INumber ImagePixelSizeN[6];
474 
478  ISwitchVectorProperty FrameTypeSP;
479  ISwitch FrameTypeS[4];
480 
484  ISwitchVectorProperty CompressSP;
485  ISwitch CompressS[2];
486 
490  IBLOBVectorProperty FitsBP;
491  IBLOB FitsB;
492 
496  ISwitchVectorProperty ResetSP;
497  ISwitch ResetS[1];
498 
499  friend class CCD;
500  friend class StreamRecoder;
501 
502 #if 0
503  ISwitch RapidGuideS[2];
504  ISwitchVectorProperty RapidGuideSP;
505 
506  ISwitch RapidGuideSetupS[3];
507  ISwitchVectorProperty RapidGuideSetupSP;
508 
509  INumber RapidGuideDataN[3];
510  INumberVectorProperty RapidGuideDataNP;
511 #endif
512 
513 };
514 
515 }
INDI::CCDChip::setFrameBufferSize
void setFrameBufferSize(uint32_t nbuf, bool allocMem=true)
setFrameBufferSize Set desired frame buffer size. The function will allocate memory accordingly....
Definition: indiccdchip.cpp:159
INDI::CCDChip::getFrameTypeName
const char * getFrameTypeName(CCD_FRAME fType)
getFrameTypeName returns CCD Frame type name
Definition: indiccdchip.cpp:199
INDI::CCDChip::setBin
void setBin(uint8_t hor, uint8_t ver)
setBin Set CCD Chip binnig
Definition: indiccdchip.cpp:97
INDI::CCDChip::getExposureLeft
double getExposureLeft() const
getExposureLeft Get exposure time left in seconds.
Definition: indiccdchip.h:195
INDI::CCDChip::getBinY
int getBinY() const
getBinY Get vertical binning of the CCD chip.
Definition: indiccdchip.h:150
_INumberVectorProperty::s
IPState s
Definition: indiapi.h:332
min
double min(void)
ISwitch
One switch descriptor.
INDI::CCDChip::setFrameType
void setFrameType(CCD_FRAME type)
setFrameType Set desired frame type for next exposure.
Definition: indiccdchip.cpp:55
indiapi.h
Constants and Data structure definitions for the interface to the reference INDI C API implementation...
INumber
One number descriptor.
INDI::CCDChip::LIGHT_FRAME
@ LIGHT_FRAME
Definition: indiccdchip.h:70
_IBLOBVectorProperty
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:469
INDI::CCDChip::CCD_MAX_Y
@ CCD_MAX_Y
Definition: indiccdchip.h:76
INDI::CCDChip::getPixelSizeY
float getPixelSizeY() const
getPixelSizeY Get vertical pixel size in microns.
Definition: indiccdchip.h:168
INDI::CCDChip::setFrameBuffer
void setFrameBuffer(uint8_t *buffer)
setFrameBuffer Set raw frame buffer pointer.
Definition: indiccdchip.h:232
INDI::CCDChip::getSubH
int getSubH() const
getSubH Get the height of the frame
Definition: indiccdchip.h:132
INDI::CCDChip::getExposureDuration
double getExposureDuration() const
getExposureDuration Get requested exposure duration for the CCD chip in seconds.
Definition: indiccdchip.h:204
INDI::CCDChip::getImageExtension
char * getImageExtension()
Definition: indiccdchip.h:401
INDI::CCDChip::getFrameType
CCD_FRAME getFrameType() const
isInterlaced
Definition: indiccdchip.h:259
MAXINDIBLOBFMT
#define MAXINDIBLOBFMT
Definition: indiapi.h:195
INDI::CCDChip::StreamRecoder
friend class StreamRecoder
Definition: indiccdchip.h:532
INDI::CCDChip::FRAME_X
@ FRAME_X
Definition: indiccdchip.h:71
INDI::CCDChip::DARK_FRAME
@ DARK_FRAME
Definition: indiccdchip.h:70
INDI::CCDChip::CCD
friend class CCD
Definition: indiccdchip.h:531
INDI::CCDChip::setExposureDuration
void setExposureDuration(double duration)
setExposureDuration Set desired CCD frame exposure duration for next exposure. You must call this fun...
Definition: indiccdchip.cpp:193
INDI::CCDChip::getFrameBuffer
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
Definition: indiccdchip.h:219
INDI::CCDChip::getYRes
int getYRes() const
Get the vertical resolution in pixels of the CCD Chip.
Definition: indiccdchip.h:96
INDI::CCDChip::CCD_FRAME
CCD_FRAME
Definition: indiccdchip.h:70
INDI::CCDChip::setExposureLeft
void setExposureLeft(double duration)
setExposureLeft Update exposure time left. Inform the client of the new exposure time left value.
Definition: indiccdchip.cpp:179
max
double max(void)
INDI::CCDChip::setBPP
void setBPP(uint8_t bpp)
setBPP Set depth of CCD chip.
Definition: indiccdchip.cpp:150
INDI::CCDChip::CCD_FRAME_INDEX
CCD_FRAME_INDEX
Definition: indiccdchip.h:71
INDI::CCDChip::setExposureComplete
void setExposureComplete()
setExposureComplete Mark exposure as complete by setting ImageExposure property to IPS_OK
Definition: indiccdchip.cpp:186
INDI::CCDChip::setExposureFailed
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
Definition: indiccdchip.cpp:231
INDI::CCDChip::CCD_INFO_INDEX
CCD_INFO_INDEX
Definition: indiccdchip.h:73
INDI::CCDChip::setCompressed
void setCompressed(bool cmp)
setCompressed Set whether a frame is compressed after exposure?
INDI::CCDChip::BIN_H
@ BIN_H
Definition: indiccdchip.h:72
type
__le16 type
Definition: pwc-ioctl.h:2
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
INDI::CCDChip::getSubX
int getSubX() const
getSubX Get the starting left coordinates (X) of the frame.
Definition: indiccdchip.h:105
INDI::CCDChip::FRAME_W
@ FRAME_W
Definition: indiccdchip.h:71
IPS_BUSY
@ IPS_BUSY
Definition: indiapi.h:162
INDI::CCDChip::CCDChip
CCDChip()
Definition: indiccdchip.cpp:44
INDI::CCDChip::isCompressed
bool isCompressed() const
isCompressed
Definition: indiccdchip.h:241
INDI::CCDChip::getExposureStartTime
const char * getExposureStartTime()
getExposureStartTime
Definition: indiccdchip.cpp:204
INDI::CCDChip::CCD_MAX_X
@ CCD_MAX_X
Definition: indiccdchip.h:75
INDI::CCDChip::getBPP
int getBPP() const
getBPP Get CCD Chip depth (bits per pixel).
Definition: indiccdchip.h:177
INDI::CCDChip::getXRes
int getXRes() const
getXRes Get the horizontal resolution in pixels of the CCD Chip.
Definition: indiccdchip.h:87
INDI::CCDChip::getFrameBufferSize
int getFrameBufferSize() const
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
Definition: indiccdchip.h:186
INDI::CCDChip::setImageExtension
void setImageExtension(const char *ext)
setImageExtension Set image exntension
Definition: indiccdchip.cpp:247
INDI::CCDChip::FLAT_FRAME
@ FLAT_FRAME
Definition: indiccdchip.h:70
INDI::CCDChip::binBayerFrame
void binBayerFrame()
binBayerFrame Perform software binning on a 2x2 Bayer matrix CCD frame. Only use this function if har...
Definition: indiccdchip.cpp:339
INDI::CCDChip::getSubY
int getSubY() const
getSubY Get the starting top coordinates (Y) of the frame.
Definition: indiccdchip.h:114
INDI::CCDChip::setFrame
void setFrame(uint32_t subx, uint32_t suby, uint32_t subw, uint32_t subh)
setFrame Set desired frame resolutoin for an exposure.
Definition: indiccdchip.cpp:82
INDI::CCDChip::FRAME_Y
@ FRAME_Y
Definition: indiccdchip.h:71
INDI::CCDChip::setPixelSize
void setPixelSize(double x, double y)
setPixelSize Set CCD Chip pixel size
Definition: indiccdchip.cpp:138
INDI::CCDChip::getNAxis
int getNAxis() const
Definition: indiccdchip.cpp:237
INDI::CCDChip::CCD_PIXEL_SIZE
@ CCD_PIXEL_SIZE
Definition: indiccdchip.h:77
INDI::CCDChip::CCD_PIXEL_SIZE_X
@ CCD_PIXEL_SIZE_X
Definition: indiccdchip.h:78
INDI::CCDChip::setNAxis
void setNAxis(int value)
setNAxis Set FITS number of axis
Definition: indiccdchip.cpp:242
INDI::CCDChip::isExposing
bool isExposing() const
Definition: indiccdchip.h:409
INDI::CCDChip::BIAS_FRAME
@ BIAS_FRAME
Definition: indiccdchip.h:70
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::CCDChip::getCCDInfo
INumberVectorProperty * getCCDInfo()
Return CCD Info Property.
Definition: indiccdchip.h:274
INDI::CCDChip::~CCDChip
~CCDChip()
Definition: indiccdchip.cpp:49
INDI::CCDChip::setMinMaxStep
void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true)
setMinMaxStep for a number property element
Definition: indiccdchip.cpp:108
INDI::CCDChip::binFrame
void binFrame()
binFrame Perform software binning on the CCD frame. Only use this function if hardware binning is not...
Definition: indiccdchip.cpp:252
INDI::CCDChip::CCD_BIN_INDEX
CCD_BIN_INDEX
Definition: indiccdchip.h:72
INDI::CCDChip::CCD_PIXEL_SIZE_Y
@ CCD_PIXEL_SIZE_Y
Definition: indiccdchip.h:79
INDI::CCDChip::CCD_BITSPERPIXEL
@ CCD_BITSPERPIXEL
Definition: indiccdchip.h:80
INDI::CCDChip::BIN_W
@ BIN_W
Definition: indiccdchip.h:72
INDI::CCDChip::getBinX
int getBinX() const
getBinX Get horizontal binning of the CCD chip.
Definition: indiccdchip.h:141
INDI::CCDChip::getPixelSizeX
float getPixelSizeX() const
getPixelSizeX Get horizontal pixel size in microns.
Definition: indiccdchip.h:159
IBLOB
One Blob (Binary Large Object) descriptor.
Aux::buffer
std::vector< uint8_t > buffer
Definition: celestronauxpacket.h:38
INDI::CCDChip::getSubW
int getSubW() const
getSubW Get the width of the frame
Definition: indiccdchip.h:123
INDI::CCDChip::FRAME_H
@ FRAME_H
Definition: indiccdchip.h:71
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
INDI::CCDChip::setResolution
void setResolution(uint32_t x, uint32_t y)
setResolution set CCD Chip resolution
Definition: indiccdchip.cpp:60