Instrument Neutral Distributed Interface INDI  1.9.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 
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 setExposureFailed();
343 
347  int getNAxis() const;
348 
353  void setNAxis(int value);
354 
359  void setImageExtension(const char *ext);
360 
364  char *getImageExtension()
365  {
366  return ImageExtention;
367  }
368 
372  bool isExposing() const
373  {
374  return (ImageExposureNP.s == IPS_BUSY);
375  }
376 
381  void binFrame();
382 
383  private:
387 
389  uint32_t XRes {0};
391  uint32_t YRes {0};
393  uint32_t SubX {0};
395  uint32_t SubY {0};
397  uint32_t SubW {0};
399  uint32_t SubH {0};
401  uint8_t BinX {1};
403  uint32_t BinY {1};
405  uint8_t NAxis {2};
407  double PixelSizeX {0};
409  double PixelSizeY {0};
411  uint8_t BitsPerPixel {8};
412  //bool Interlaced {false};
413  // RAW Frame for image data stored as bytes.
414  uint8_t *RawFrame {nullptr};
415  // RAW Frame size in bytes.
416  uint32_t RawFrameSize {0};
417  // BINNED Frame when software binning is used.
418  uint8_t *BinFrame {nullptr};
419  // Should we compress frame before transmission?
420  bool SendCompressed {false};
421  // Frame Type
422  CCD_FRAME FrameType {LIGHT_FRAME};
423  // Exposure duration in seconds.
424  double ExposureDuration {0};
425  // Exposure startup time
426  timeval StartExposureTime;
427  // Image extension type (e.g. jpg)
428  char ImageExtention[MAXINDIBLOBFMT];
429 
433 
437  INumberVectorProperty ImageExposureNP;
438  INumber ImageExposureN[1];
439 
443  ISwitchVectorProperty AbortExposureSP;
444  ISwitch AbortExposureS[1];
445 
449  INumberVectorProperty ImageFrameNP;
450  INumber ImageFrameN[4];
451 
455  INumberVectorProperty ImageBinNP;
456  INumber ImageBinN[2];
457 
461  INumberVectorProperty ImagePixelSizeNP;
462  INumber ImagePixelSizeN[6];
463 
467  ISwitchVectorProperty FrameTypeSP;
468  ISwitch FrameTypeS[4];
469 
473  ISwitchVectorProperty CompressSP;
474  ISwitch CompressS[2];
475 
479  IBLOBVectorProperty FitsBP;
480  IBLOB FitsB;
481 
485  ISwitchVectorProperty ResetSP;
486  ISwitch ResetS[1];
487 
488  friend class CCD;
489  friend class StreamRecoder;
490 
491 #if 0
492  ISwitch RapidGuideS[2];
493  ISwitchVectorProperty RapidGuideSP;
494 
495  ISwitch RapidGuideSetupS[3];
496  ISwitchVectorProperty RapidGuideSetupSP;
497 
498  INumber RapidGuideDataN[3];
499  INumberVectorProperty RapidGuideDataNP;
500 #endif
501 
502 };
503 
504 }
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:193
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:396
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:521
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:520
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:187
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::setExposureFailed
void setExposureFailed()
setExposureFailed Alert the client that the exposure failed.
Definition: indiccdchip.cpp:225
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:198
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:241
INDI::CCDChip::FLAT_FRAME
@ FLAT_FRAME
Definition: indiccdchip.h:70
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:231
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:236
INDI::CCDChip::isExposing
bool isExposing() const
Definition: indiccdchip.h:404
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 softwre binning on the CCD frame. Only use this function if hardware binning is not ...
Definition: indiccdchip.cpp:246
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