Kstars

indistd.h
1 /*
2  SPDX-FileCopyrightText: 2012 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 
6  Handle INDI Standard properties.
7 */
8 
9 #pragma once
10 
11 #include "indicommon.h"
12 
13 #include <indiproperty.h>
14 #include <basedevice.h>
15 
16 #include <QObject>
17 #include <QVariant>
18 #include <QJsonArray>
19 
20 #ifndef KSTARS_LITE
21 #include <QDBusArgument>
22 #endif
23 
24 #define MAXINDIFILENAME 512
25 
26 class ClientManager;
27 class DriverInfo;
28 class DeviceInfo;
29 class QTimer;
30 class QFile;
31 
32 using Properties = INDI::BaseDevice::Properties;
33 
34 // INDI Standard Device Namespace
35 namespace ISD
36 {
37 
38 typedef enum { PARK_UNKNOWN, PARK_PARKED, PARK_PARKING, PARK_UNPARKING, PARK_UNPARKED, PARK_ERROR } ParkStatus;
39 
40 // Create instances as per driver interface.
41 class ConcreteDevice;
42 class Mount;
43 class Camera;
44 class Guider;
45 class Focuser;
46 class FilterWheel;
47 class Dome;
48 class GPS;
49 class Weather;
50 class AdaptiveOptics;
51 class DustCap;
52 class LightBox;
53 class Detector;
54 class Rotator;
55 class Spectrograph;
56 class Correlator;
57 class Auxiliary;
58 
59 class GDSetCommand : public QObject
60 {
61  Q_OBJECT
62 
63  public:
64  GDSetCommand(INDI_PROPERTY_TYPE inPropertyType, const QString &inProperty, const QString &inElement,
65  QVariant qValue, QObject *parent);
66  INDI_PROPERTY_TYPE propType;
67 
68  QString indiProperty;
69  QString indiElement;
70  QVariant elementValue;
71 };
72 
73 /**
74  * @class GDInterface
75  * GDInterface is the Generic Device <i>Interface</i> for INDI devices. It is used as part of the Decorator Pattern when initially a new INDI device is created as a
76  * Generic Device in INDIListener. If the device registers an INDI Standard Property belonging to one specific device type (e.g. Telescope), then the device functionality
77  * is extended to the particular device type.
78  *
79  * DeviceDecorator subclasses GDInterface and calls concrete decorators methods.
80  *
81  * @author Jasem Mutlaq
82  */
83 class GDInterface : public QObject
84 {
85  Q_OBJECT
86 
87  public:
88  explicit GDInterface(QObject *parent) : QObject(parent) {}
89 
90  // Property registration
91  virtual void registerProperty(INDI::Property prop) = 0;
92  virtual void removeProperty(const QString &name) = 0;
93 
94  // Property updates
95  virtual void processSwitch(ISwitchVectorProperty *svp) = 0;
96  virtual void processText(ITextVectorProperty *tvp) = 0;
97  virtual void processNumber(INumberVectorProperty *nvp) = 0;
98  virtual void processLight(ILightVectorProperty *lvp) = 0;
99  virtual bool processBLOB(IBLOB *bp) = 0;
100 
101  // Messages
102  virtual void processMessage(int messageID) = 0;
103 };
104 
105 /**
106  * @class GenericDevice
107  * GenericDevice is the Generic Device for INDI devices. When a new INDI device is created in INDIListener, it gets created as a GenericDevice initially. If the device
108  * registers a standard property that is a key property to a device type family (e.g. Number property EQUATORIAL_EOD_COORD signifies a Telescope device), then the specialized version of
109  * the device is extended via the Decorator Pattern.
110  *
111  * GenericDevice handles common functions shared across many devices such as time and location handling, configuration processing, retrieving information about properties, driver info..etc.
112  *
113  * @author Jasem Mutlaq
114  */
116 {
117  Q_OBJECT
118  Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.INDI.GenericDevice")
119  Q_PROPERTY(QString name READ getDeviceName)
120  Q_PROPERTY(uint32_t driverInterface READ getDriverInterface)
121  Q_PROPERTY(QString driverVersion READ getDriverVersion)
122  Q_PROPERTY(bool connected READ isConnected)
123 
124  public:
125  explicit GenericDevice(DeviceInfo &idv, ClientManager *cm, QObject *parent = nullptr);
126  virtual ~GenericDevice() override;
127 
128  virtual void registerProperty(INDI::Property prop) override;
129  virtual void removeProperty(const QString &name) override;
130  virtual void processSwitch(ISwitchVectorProperty *svp) override;
131  virtual void processText(ITextVectorProperty *tvp) override;
132  virtual void processNumber(INumberVectorProperty *nvp) override;
133  virtual void processLight(ILightVectorProperty *lvp) override;
134 
135  /**
136  * @brief processBLOB Process Binary BLOB
137  * @param bp pointer to binary blob.
138  * @return Return true of BLOB was successfully processed. If a concrete device does not process the blob, it should
139  * return false to allow sibling or parent devices to process the blob.
140  */
141  virtual bool processBLOB(IBLOB *bp) override;
142  virtual void processMessage(int messageID) override;
143 
144  virtual const QString &getDeviceName() const;
145  virtual DriverInfo *getDriverInfo() const
146  {
147  return m_DriverInfo;
148  }
149  virtual DeviceInfo *getDeviceInfo() const
150  {
151  return m_DeviceInfo;
152  }
153  virtual Properties getProperties()
154  {
155  return m_BaseDevice->getProperties();
156  }
157  virtual uint32_t getDriverInterface()
158  {
159  return m_DriverInterface;
160  }
161  virtual QString getDriverVersion()
162  {
163  return m_DriverVersion;
164  }
165 
166  virtual bool setConfig(INDIConfig tConfig);
167  virtual bool isConnected() const
168  {
169  return m_Connected;
170  }
171  virtual INDI::BaseDevice *getBaseDevice() const
172  {
173  return m_BaseDevice;
174  }
175  ClientManager *getClientManager() const
176  {
177  return m_ClientManager;
178  }
179  virtual bool getMinMaxStep(const QString &propName, const QString &elementName, double *min, double *max,
180  double *step);
181  virtual IPState getState(const QString &propName);
182  virtual IPerm getPermission(const QString &propName);
183  virtual INDI::Property getProperty(const QString &propName);
184  virtual bool getJSONProperty(const QString &propName, QJsonObject &propObject, bool compact);
185  virtual bool getJSONBLOB(const QString &propName, const QString &elementName, QJsonObject &blobObject);
186  virtual bool setJSONProperty(const QString &propName, const QJsonArray &propElements);
187 
188  ConcreteDevice *getConcreteDevice(uint32_t interface);
189 
190  Q_SCRIPTABLE Q_NOREPLY void Connect();
191  Q_SCRIPTABLE Q_NOREPLY void Disconnect();
192  bool setProperty(QObject *);
193 
194  protected slots:
195  virtual void resetWatchdog();
196 
197  protected:
198  void createDeviceInit();
199  void updateTime();
200  void updateLocation();
201  void generateDevices();
202 
203  protected:
204  uint32_t m_DriverInterface { 0 };
205  QString m_DriverVersion;
207 
208  signals:
209  void Connected();
210  void Disconnected();
211  void switchUpdated(ISwitchVectorProperty *svp);
212  void textUpdated(ITextVectorProperty *tvp);
213  void numberUpdated(INumberVectorProperty *nvp);
214  void lightUpdated(ILightVectorProperty *lvp);
215  void BLOBUpdated(IBLOB *bp);
216  void messageUpdated(int messageID);
217 
218  void interfaceDefined();
219  void systemPortDetected();
220  void propertyDefined(INDI::Property prop);
221  void propertyDeleted(const QString &name);
222  void ready();
223 
224  // These are emitted as soon as the driver interface defines them
225  void newMount(Mount *device);
226  void newCamera(Camera *device);
227  void newGuider(Guider *device);
228  void newFocuser(Focuser *device);
229  void newFilterWheel(FilterWheel *device);
230  void newDome(Dome *device);
231  void newGPS(GPS *device);
232  void newWeather(Weather *device);
233  void newAdaptiveOptics(AdaptiveOptics *device);
234  void newDustCap(DustCap *device);
235  void newLightBox(LightBox *device);
236  void newDetector(Detector *device);
237  void newRotator(Rotator *device);
238  void newSpectrograph(Spectrograph *device);
239  void newCorrelator(Correlator *device);
240  void newAuxiliary(Auxiliary *device);
241 
242  private:
243 
244  class StreamFileMetadata
245  {
246  public:
247  QString device;
249  QString element;
250  QFile *file { nullptr};
251  };
252 
253  static void registerDBusType();
254  bool m_Connected { false };
255  QString m_Name;
256  DriverInfo *m_DriverInfo { nullptr };
257  DeviceInfo *m_DeviceInfo { nullptr };
258  INDI::BaseDevice *m_BaseDevice { nullptr };
259  ClientManager *m_ClientManager { nullptr };
260  QTimer *watchDogTimer { nullptr };
261  QTimer *m_ReadyTimer {nullptr};
262  QList<StreamFileMetadata> streamFileMetadata;
263 
264  static uint8_t getID()
265  {
266  return m_ID++;
267  }
268  static uint8_t m_ID;
269 };
270 
271 void propertyToJson(ISwitchVectorProperty *svp, QJsonObject &propObject, bool compact = true);
272 void propertyToJson(ITextVectorProperty *tvp, QJsonObject &propObject, bool compact = true);
273 void propertyToJson(INumberVectorProperty *nvp, QJsonObject &propObject, bool compact = true);
274 void propertyToJson(ILightVectorProperty *lvp, QJsonObject &propObject, bool compact = true);
275 void propertyToJson(INDI::Property prop, QJsonObject &propObject, bool compact = true);
276 
277 }
278 
279 
280 #ifndef KSTARS_LITE
281 Q_DECLARE_METATYPE(ISD::ParkStatus)
282 QDBusArgument &operator<<(QDBusArgument &argument, const ISD::ParkStatus &source);
283 const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::ParkStatus &dest);
284 #endif
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
virtual bool processBLOB(IBLOB *bp) override
processBLOB Process Binary BLOB
Definition: indistd.cpp:447
Q_CLASSINFO(Name, Value)
QObject(QObject *parent)
The ConcreteDevice class.
QDebug operator<<(QDebug d, const QCPVector2D &vec)
Definition: qcustomplot.h:450
QDataStream & operator>>(QDataStream &in, KDateTime &dateTime)
QObject * parent() const const
QVariant property(const char *name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.