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 setISOMode(bool enable)
112  {
113  ISOMode = enable;
114  }
115  void setSeqPrefix(const QString &preFix)
116  {
117  seqPrefix = preFix;
118  }
119  void setPlaceholderPath(const Ekos::PlaceholderPath &php)
120  {
121  placeholderPath = php;
122  }
123  void setNextSequenceID(int count)
124  {
125  nextSequenceID = count;
126  }
127 
128  // Gain controls
129  bool hasGain()
130  {
131  return gainN != nullptr;
132  }
133  bool getGain(double *value);
134  IPerm getGainPermission() const
135  {
136  return gainPerm;
137  }
138  bool setGain(double value);
139  bool getGainMinMaxStep(double *min, double *max, double *step);
140 
141  // offset controls
142  bool hasOffset()
143  {
144  return offsetN != nullptr;
145  }
146  bool getOffset(double *value);
147  IPerm getOffsetPermission() const
148  {
149  return offsetPerm;
150  }
151  bool setOffset(double value);
152  bool getOffsetMinMaxStep(double *min, double *max, double *step);
153 
154  // Rapid Guide
155  bool configureRapidGuide(CameraChip *targetChip, bool autoLoop, bool sendImage = false, bool showMarker = false);
156  bool setRapidGuide(CameraChip *targetChip, bool enable);
157 
158  // Upload Settings
159  void updateUploadSettings(const QString &remoteDir);
160  UploadMode getUploadMode();
161  bool setUploadMode(UploadMode mode);
162 
163  // Encoding Format
164  const QString &getEncodingFormat() const
165  {
166  return m_EncodingFormat;
167  }
168  bool setEncodingFormat(const QString &value);
169  const QStringList &getEncodingFormats() const
170  {
171  return m_EncodingFormats;
172  }
173 
174  // Capture Format
175  const QStringList &getCaptureFormats() const
176  {
177  return m_CaptureFormats;
178  }
179  QString getCaptureFormat() const;
180  bool setCaptureFormat(const QString &format);
181 
182  // BLOB control
183  bool isBLOBEnabled();
184  bool setBLOBEnabled(bool enable, const QString &prop = QString());
185 
186  // Video Stream
187  bool setVideoStreamEnabled(bool enable);
188  bool resetStreamingFrame();
189  bool setStreamingFrame(int x, int y, int w, int h);
190  bool isStreamingEnabled();
191  bool setStreamExposure(double duration);
192  bool getStreamExposure(double *duration);
193  bool setStreamLimits(uint16_t maxBufferSize, uint16_t maxPreviewFPS);
194 
195  // Video Recording
196  bool setSERNameDirectory(const QString &filename, const QString &directory);
197  bool getSERNameDirectory(QString &filename, QString &directory);
198  bool startRecording();
199  bool startDurationRecording(double duration);
200  bool startFramesRecording(uint32_t frames);
201  bool stopRecording();
202 
203  // Telescope type
204  TelescopeType getTelescopeType()
205  {
206  return telescopeType;
207  }
208  bool setTelescopeType(TelescopeType type);
209 
210  // Update FITS Header
211  bool setFITSHeaders(const QList<FITSData::Record> &values);
212 
213  CameraChip *getChip(CameraChip::ChipType cType);
214 
215  bool setFastExposureEnabled(bool enable);
216  bool isFastExposureEnabled() const
217  {
218  return m_FastExposureEnabled;
219  }
220  bool setFastCount(uint32_t count);
221 
222  const QMap<QString, double> &getExposurePresets() const
223  {
224  return m_ExposurePresets;
225  }
226  const QPair<double, double> getExposurePresetsMinMax() const
227  {
228  return m_ExposurePresetsMinMax;
229  }
230 
231  public slots:
232  //void FITSViewerDestroyed();
233  void StreamWindowHidden();
234  // Blob manager
235  void setBLOBManager(const char *device, INDI::Property prop);
236 
237  protected slots:
238  void setWSBLOB(const QByteArray &message, const QString &extension);
239 
240  signals:
241  void newTemperatureValue(double value);
242  void newExposureValue(ISD::CameraChip *chip, double value, IPState state);
243  void newGuideStarData(ISD::CameraChip *chip, double dx, double dy, double fit);
244  void newBLOBManager(INDI::Property prop);
245  void newRemoteFile(QString);
246  void videoStreamToggled(bool enabled);
247  void videoRecordToggled(bool enabled);
248  void newFPS(double instantFPS, double averageFPS);
249  void newVideoFrame(const QSharedPointer<QImage> &frame);
250  void coolerToggled(bool enabled);
251  void error(ErrorType type);
252  void newImage(const QSharedPointer<FITSData> &data);
253 
254  private:
255  void processStream(INDI::Property prop);
256  bool generateFilename(bool batch_mode, const QString &extension, QString *filename);
257  // Saves an image to disk on a separate thread.
258  bool writeImageFile(const QString &filename, INDI::Property prop, bool is_fits);
259  bool WriteImageFileInternal(const QString &filename, char *buffer, const size_t size);
260  // Creates or finds the FITSViewer.
261  QPointer<FITSViewer> getFITSViewer();
262  void handleImage(CameraChip *targetChip, const QString &filename, INDI::Property prop, QSharedPointer<FITSData> data);
263 
264  bool ISOMode { true };
265  bool HasGuideHead { false };
266  bool HasCooler { false };
267  bool CanCool { false };
268  bool HasCoolerControl { false };
269  bool HasVideoStream { false };
270  bool m_FastExposureEnabled { false };
271  QString seqPrefix;
272  Ekos::PlaceholderPath placeholderPath;
273 
274  int nextSequenceID { 0 };
275  std::unique_ptr<StreamWG> streamWindow;
276  int streamW { 0 };
277  int streamH { 0 };
278  int normalTabID { -1 };
279  int calibrationTabID { -1 };
280  int focusTabID { -1 };
281  int guideTabID { -1 };
282  int alignTabID { -1 };
283 
284  INDI::Property primaryCCDBLOB;
285 
286  std::unique_ptr<CameraChip> primaryChip;
287  std::unique_ptr<CameraChip> guideChip;
288  std::unique_ptr<WSMedia> m_Media;
289  QString m_EncodingFormat {"FITS"};
290  QStringList m_EncodingFormats;
291  QStringList m_CaptureFormats;
292  bool m_StreamingEnabled {true};
293  int m_CaptureFormatIndex;
294  TelescopeType telescopeType { TELESCOPE_UNKNOWN };
295 
296  // Gain, since it is spread among different vector properties, let's try to find the property itself.
297  INumber *gainN { nullptr };
298  IPerm gainPerm { IP_RO };
299 
300  INumber *offsetN { nullptr };
301  IPerm offsetPerm { IP_RO };
302 
303  QPointer<FITSViewer> m_FITSViewerWindow;
304  QPointer<ImageViewer> m_ImageViewerWindow;
305 
306  QDateTime m_LastNotificationTS;
307 
308  // Typically for DSLRs
309  QMap<QString, double> m_ExposurePresets;
310  QPair<double, double> m_ExposurePresetsMinMax;
311 
312  // Used when writing the image fits file to disk in a separate thread.
313  char *fileWriteBuffer { nullptr };
314  int fileWriteBufferSize { 0 };
315  QString fileWriteFilename;
316  QFuture<void> fileWriteThread;
317 };
318 }
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 Mon May 8 2023 03:57:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.