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

KDE's Doxygen guidelines are available online.