Kstars

indicamera.h
1 /*
2  SPDX-FileCopyrightText: 2012 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "indiconcretedevice.h"
10 #include "indicamerachip.h"
11 
12 #include "wsmedia.h"
13 #include "auxiliary/imageviewer.h"
14 #include "fitsviewer/fitscommon.h"
15 #include "fitsviewer/fitsview.h"
16 #include "fitsviewer/fitsviewer.h"
17 #include "ekos/capture/placeholderpath.h"
18 
19 #include <QStringList>
20 #include <QPointer>
21 #include <QtConcurrent>
22 
23 #include <memory>
24 
25 class FITSData;
26 class FITSView;
27 class QTimer;
28 class StreamWG;
29 
30 /**
31  * \namespace ISD
32  *
33  * ISD is a collection of INDI Standard Devices. It encapsulates common types of INDI devices such as telescopes and CCDs.
34  *
35  */
36 namespace ISD
37 {
38 class CameraChip;
39 
40 /**
41  * @class Camera
42  * Camera class controls an INDI Camera device. It can be used to issue and abort capture commands, receive and process BLOBs,
43  * and return information on the capabilities of the camera.
44  *
45  * @author Jasem Mutlaq
46  */
47 class Camera : public ConcreteDevice
48 {
49  Q_OBJECT
50 
51  public:
52  explicit Camera(ISD::GenericDevice *parent);
53  virtual ~Camera() override;
54 
55  typedef enum { UPLOAD_CLIENT, UPLOAD_LOCAL, UPLOAD_BOTH } UploadMode;
56  enum BlobType
57  {
58  BLOB_IMAGE,
59  BLOB_FITS,
60  BLOB_RAW,
61  BLOB_OTHER
62  } BType;
63  typedef enum { TELESCOPE_PRIMARY, TELESCOPE_GUIDE, TELESCOPE_UNKNOWN } TelescopeType;
64  typedef enum
65  {
66  ERROR_CAPTURE, /** INDI Camera error */
67  ERROR_SAVE, /** Saving to disk error */
68  ERROR_LOAD, /** Loading image buffer error */
69  ERROR_VIEWER /** Loading in FITS Viewer Error */
70  } ErrorType;
71 
72  void registerProperty(INDI::Property prop) override;
73  void removeProperty(const QString &name) override;
74  void processSwitch(ISwitchVectorProperty *svp) override;
75  void processText(ITextVectorProperty *tvp) override;
76  void processNumber(INumberVectorProperty *nvp) override;
77  bool processBLOB(IBLOB *bp) override;
78 
79  // Does it an on-chip dedicated guide head?
80  bool hasGuideHead();
81  // Does it report temperature?
82  bool hasCooler();
83  // Can temperature be controlled?
84  bool canCool()
85  {
86  return CanCool;
87  }
88  // Does it have active cooler on/off controls?
89  bool hasCoolerControl();
90  bool setCoolerControl(bool enable);
91  bool isCoolerOn();
92  // Does it have a video stream?
93  bool hasVideoStream()
94  {
95  return HasVideoStream;
96  }
97 
98  // Temperature controls
99  bool getTemperature(double *value);
100  bool setTemperature(double value);
101 
102  // Temperature Regulation
103  bool getTemperatureRegulation(double &ramp, double &threshold);
104  bool setTemperatureRegulation(double ramp, double threshold);
105 
106  bool setScopeInfo(double focalLength, double aperture);
107 
108  // Utility functions
109  void setISOMode(bool enable)
110  {
111  ISOMode = enable;
112  }
113  void setSeqPrefix(const QString &preFix)
114  {
115  seqPrefix = preFix;
116  }
117  void setPlaceholderPath(Ekos::PlaceholderPath php)
118  {
119  placeholderPath = php;
120  }
121  void setNextSequenceID(int count)
122  {
123  nextSequenceID = count;
124  }
125 
126  // Gain controls
127  bool hasGain()
128  {
129  return gainN != nullptr;
130  }
131  bool getGain(double *value);
132  IPerm getGainPermission() const
133  {
134  return gainPerm;
135  }
136  bool setGain(double value);
137  bool getGainMinMaxStep(double *min, double *max, double *step);
138 
139  // offset controls
140  bool hasOffset()
141  {
142  return offsetN != nullptr;
143  }
144  bool getOffset(double *value);
145  IPerm getOffsetPermission() const
146  {
147  return offsetPerm;
148  }
149  bool setOffset(double value);
150  bool getOffsetMinMaxStep(double *min, double *max, double *step);
151 
152  // Rapid Guide
153  bool configureRapidGuide(CameraChip *targetChip, bool autoLoop, bool sendImage = false, bool showMarker = false);
154  bool setRapidGuide(CameraChip *targetChip, bool enable);
155 
156  // Upload Settings
157  void updateUploadSettings(const QString &remoteDir);
158  UploadMode getUploadMode();
159  bool setUploadMode(UploadMode mode);
160 
161  // Encoding Format
162  const QString &getEncodingFormat() const
163  {
164  return m_EncodingFormat;
165  }
166  bool setEncodingFormat(const QString &value);
167  const QStringList &getEncodingFormats() const
168  {
169  return m_EncodingFormats;
170  }
171 
172  // Capture Format
173  const QStringList &getCaptureFormats() const
174  {
175  return m_CaptureFormats;
176  }
177  QString getCaptureFormat() const;
178  bool setCaptureFormat(const QString &format);
179 
180  // BLOB control
181  bool isBLOBEnabled();
182  bool setBLOBEnabled(bool enable, const QString &prop = QString());
183 
184  // Video Stream
185  bool setVideoStreamEnabled(bool enable);
186  bool resetStreamingFrame();
187  bool setStreamingFrame(int x, int y, int w, int h);
188  bool isStreamingEnabled();
189  bool setStreamExposure(double duration);
190  bool getStreamExposure(double *duration);
191  bool setStreamLimits(uint16_t maxBufferSize, uint16_t maxPreviewFPS);
192 
193  // Video Recording
194  bool setSERNameDirectory(const QString &filename, const QString &directory);
195  bool getSERNameDirectory(QString &filename, QString &directory);
196  bool startRecording();
197  bool startDurationRecording(double duration);
198  bool startFramesRecording(uint32_t frames);
199  bool stopRecording();
200 
201  // Telescope type
202  TelescopeType getTelescopeType()
203  {
204  return telescopeType;
205  }
206  bool setTelescopeType(TelescopeType type);
207 
208  // Update FITS Header
209  bool setFITSHeader(const QMap<QString, QString> &values);
210 
211  CameraChip *getChip(CameraChip::ChipType cType);
212 
213  bool setFastExposureEnabled(bool enable);
214  bool isFastExposureEnabled() const
215  {
216  return m_FastExposureEnabled;
217  }
218  bool setFastCount(uint32_t count);
219 
220  const QMap<QString, double> &getExposurePresets() const
221  {
222  return m_ExposurePresets;
223  }
224  const QPair<double, double> getExposurePresetsMinMax() const
225  {
226  return m_ExposurePresetsMinMax;
227  }
228 
229  public slots:
230  //void FITSViewerDestroyed();
231  void StreamWindowHidden();
232  // Blob manager
233  void setBLOBManager(const char *device, INDI::Property prop);
234 
235  protected slots:
236  void setWSBLOB(const QByteArray &message, const QString &extension);
237 
238  signals:
239  void newTemperatureValue(double value);
240  void newExposureValue(ISD::CameraChip *chip, double value, IPState state);
241  void newGuideStarData(ISD::CameraChip *chip, double dx, double dy, double fit);
242  void newBLOBManager(INDI::Property prop);
243  void newRemoteFile(QString);
244  void videoStreamToggled(bool enabled);
245  void videoRecordToggled(bool enabled);
246  void newFPS(double instantFPS, double averageFPS);
247  void newVideoFrame(const QSharedPointer<QImage> &frame);
248  void coolerToggled(bool enabled);
249  void error(ErrorType type);
250  void newImage(const QSharedPointer<FITSData> &data);
251 
252  private:
253  void processStream(IBLOB *bp);
254  bool generateFilename(bool batch_mode, const QString &extension, QString *filename);
255  // Saves an image to disk on a separate thread.
256  bool writeImageFile(const QString &filename, IBLOB *bp, bool is_fits);
257  bool WriteImageFileInternal(const QString &filename, char *buffer, const size_t size);
258  // Creates or finds the FITSViewer.
259  QPointer<FITSViewer> getFITSViewer();
260  void handleImage(CameraChip *targetChip, const QString &filename, IBLOB *bp, QSharedPointer<FITSData> data);
261 
262  bool ISOMode { true };
263  bool HasGuideHead { false };
264  bool HasCooler { false };
265  bool CanCool { false };
266  bool HasCoolerControl { false };
267  bool HasVideoStream { false };
268  bool m_FastExposureEnabled { false };
269  QString seqPrefix;
270  Ekos::PlaceholderPath placeholderPath;
271 
272  int nextSequenceID { 0 };
273  std::unique_ptr<StreamWG> streamWindow;
274  int streamW { 0 };
275  int streamH { 0 };
276  int normalTabID { -1 };
277  int calibrationTabID { -1 };
278  int focusTabID { -1 };
279  int guideTabID { -1 };
280  int alignTabID { -1 };
281 
282  //char BLOBFilename[MAXINDIFILENAME + 1];
283  IBLOB *primaryCCDBLOB { nullptr };
284 
285  std::unique_ptr<CameraChip> primaryChip;
286  std::unique_ptr<CameraChip> guideChip;
287  std::unique_ptr<WSMedia> m_Media;
288  QString m_EncodingFormat {"FITS"};
289  QStringList m_EncodingFormats;
290  QStringList m_CaptureFormats;
291  int m_CaptureFormatIndex;
292  TelescopeType telescopeType { TELESCOPE_UNKNOWN };
293 
294  // Gain, since it is spread among different vector properties, let's try to find the property itself.
295  INumber *gainN { nullptr };
296  IPerm gainPerm { IP_RO };
297 
298  INumber *offsetN { nullptr };
299  IPerm offsetPerm { IP_RO };
300 
301  QPointer<FITSViewer> m_FITSViewerWindow;
302  QPointer<ImageViewer> m_ImageViewerWindow;
303 
304  QDateTime m_LastNotificationTS;
305 
306  // Typically for DSLRs
307  QMap<QString, double> m_ExposurePresets;
308  QPair<double, double> m_ExposurePresetsMinMax;
309 
310  // Used when writing the image fits file to disk in a separate thread.
311  char *fileWriteBuffer { nullptr };
312  int fileWriteBufferSize { 0 };
313  QString fileWriteFilename;
314  QFuture<void> fileWriteThread;
315 };
316 }
Q_OBJECTQ_OBJECT
@ ERROR_VIEWER
Loading image buffer error.
Definition: indicamera.h:69
The ConcreteDevice class.
@ ERROR_LOAD
Saving to disk error.
Definition: indicamera.h:68
@ ERROR_SAVE
INDI Camera error.
Definition: indicamera.h:67
QObject * parent() const const
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 03:58:10 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.