Kstars

indistd.h
1/*
2 SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
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
26class ClientManager;
27class DriverInfo;
28class DeviceInfo;
29class QTimer;
30class QFile;
31
32using Properties = INDI::BaseDevice::Properties;
33
34// INDI Standard Device Namespace
35namespace ISD
36{
37
38typedef enum { PARK_UNKNOWN, PARK_PARKED, PARK_PARKING, PARK_UNPARKING, PARK_UNPARKED, PARK_ERROR } ParkStatus;
39
40// Create instances as per driver interface.
41class ConcreteDevice;
42class Mount;
43class Camera;
44class Guider;
45class Focuser;
46class FilterWheel;
47class Dome;
48class GPS;
49class Weather;
50class AdaptiveOptics;
51class DustCap;
52class LightBox;
53class Detector;
54class Rotator;
55class Spectrograph;
56class Correlator;
57class Auxiliary;
58
59class GDSetCommand : public QObject
60{
62
63 public:
64 GDSetCommand(INDI_PROPERTY_TYPE inPropertyType, const QString &inProperty, const QString &inElement,
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 */
83class GDInterface : public QObject
84{
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(INDI::Property prop) = 0;
93 virtual void updateProperty(INDI::Property prop) = 0;
94
95 // Property updates
96 virtual void processSwitch(INDI::Property prop) = 0;
97 virtual void processText(INDI::Property prop) = 0;
98 virtual void processNumber(INDI::Property prop) = 0;
99 virtual void processLight(INDI::Property prop) = 0;
100 virtual bool processBLOB(INDI::Property prop) = 0;
101
102 // Messages
103 virtual void processMessage(int messageID) = 0;
104};
105
106/**
107 * @class GenericDevice
108 * 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
109 * 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
110 * the device is extended via the Decorator Pattern.
111 *
112 * GenericDevice handles common functions shared across many devices such as time and location handling, configuration processing, retrieving information about properties, driver info..etc.
113 *
114 * @author Jasem Mutlaq
115 */
117{
119 Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.INDI.GenericDevice")
120 Q_PROPERTY(QString name READ getDeviceName)
121 Q_PROPERTY(uint32_t driverInterface READ getDriverInterface)
122 Q_PROPERTY(QString driverVersion READ getDriverVersion)
123 Q_PROPERTY(bool connected READ isConnected)
124
125 public:
126 explicit GenericDevice(DeviceInfo &idv, ClientManager *cm, QObject *parent = nullptr);
127 virtual ~GenericDevice() override;
128
129 virtual void registerProperty(INDI::Property prop) override;
130 virtual void removeProperty(INDI::Property prop) override;
131 virtual void updateProperty(INDI::Property prop) override;
132
133 virtual void processSwitch(INDI::Property prop) override;
134 virtual void processText(INDI::Property prop) override;
135 virtual void processNumber(INDI::Property prop) override;
136 virtual void processLight(INDI::Property prop) override;
137
138 /**
139 * @brief processBLOB Process Binary BLOB
140 * @param bp pointer to binary blob.
141 * @return Return true of BLOB was successfully processed. If a concrete device does not process the blob, it should
142 * return false to allow sibling or parent devices to process the blob.
143 */
144 virtual bool processBLOB(INDI::Property prop) override;
145 virtual void processMessage(int messageID) override;
146
147 virtual const QString &getDeviceName() const;
148 virtual const QSharedPointer<DriverInfo> &getDriverInfo() const
149 {
150 return m_DriverInfo;
151 }
152 virtual DeviceInfo *getDeviceInfo() const
153 {
154 return m_DeviceInfo;
155 }
156 virtual Properties getProperties()
157 {
158 return m_BaseDevice.getProperties();
159 }
160 virtual uint32_t getDriverInterface()
161 {
162 return m_DriverInterface;
163 }
164 virtual QString getDriverVersion()
165 {
166 return m_DriverVersion;
167 }
168
169 virtual bool setConfig(INDIConfig tConfig);
170 virtual bool isConnected() const
171 {
172 return m_Connected;
173 }
174 virtual bool isReady() const
175 {
176 return m_Ready;
177 }
178 virtual INDI::BaseDevice getBaseDevice() const
179 {
180 return m_BaseDevice;
181 }
182 ClientManager *getClientManager() const
183 {
184 return m_ClientManager;
185 }
186 virtual bool getMinMaxStep(const QString &propName, const QString &elementName, double *min, double *max,
187 double *step);
188 virtual IPState getState(const QString &propName);
189 virtual IPerm getPermission(const QString &propName);
190 virtual INDI::Property getProperty(const QString &propName);
191 virtual bool getJSONProperty(const QString &propName, QJsonObject &propObject, bool compact);
192 virtual bool getJSONBLOB(const QString &propName, const QString &elementName, QJsonObject &blobObject);
193 virtual bool setJSONProperty(const QString &propName, const QJsonArray &propElements);
194
195 bool findConcreteDevice(uint32_t interface, QSharedPointer<ConcreteDevice> &device);
196
197 void sendNewProperty(INDI::Property prop);
198 /** @brief Send new Text command to server */
199 void sendNewText(INDI::Property prop);
200 /** @brief Send new Number command to server */
201 void sendNewNumber(INDI::Property prop);
202 /** @brief Send new Switch command to server */
203 void sendNewSwitch(INDI::Property prop);
204
205 // Convinence functions
206 ISD::Mount *getMount();
207 ISD::Camera *getCamera();
208 ISD::Guider *getGuider();
209 ISD::Focuser *getFocuser();
210 ISD::FilterWheel *getFilterWheel();
211 ISD::Dome *getDome();
212 ISD::GPS *getGPS();
213 ISD::Weather *getWeather();
214 ISD::AdaptiveOptics *getAdaptiveOptics();
215 ISD::DustCap *getDustCap();
216 ISD::LightBox *getLightBox();
217 ISD::Detector *getDetector();
218 ISD::Rotator *getRotator();
219 ISD::Spectrograph *getSpectrograph();
220 ISD::Correlator *getCorrelator();
221 ISD::Auxiliary *getAuxiliary();
222
223 Q_SCRIPTABLE Q_NOREPLY void Connect();
224 Q_SCRIPTABLE Q_NOREPLY void Disconnect();
225 bool setProperty(QObject *);
226
227 protected slots:
228 virtual void resetWatchdog();
229
230 protected:
231 void createDeviceInit();
232 void updateTime();
233 void updateLocation();
234 /**
235 * @brief generateDevices Generate concrete devices based on DRIVER_INTERFACE
236 * @return True if at least one device is generated, false otherwise.
237 */
238 bool generateDevices();
239 void handleTimeout();
240 void checkTimeUpdate();
241 void checkLocationUpdate();
242
243 protected:
244 uint32_t m_DriverInterface { 0 };
245 QString m_DriverVersion;
247
248 signals:
249 void Connected();
250 void Disconnected();
251
252 void propertyUpdated(INDI::Property prop);
253 void messageUpdated(int messageID);
254
255 void interfaceDefined();
256 void systemPortDetected();
257 void propertyDefined(INDI::Property prop);
258 void propertyDeleted(INDI::Property prop);
259 void ready();
260
261 // These are emitted as soon as the driver interface defines them
262 void newMount(Mount *device);
263 void newCamera(Camera *device);
264 void newGuider(Guider *device);
265 void newFocuser(Focuser *device);
266 void newFilterWheel(FilterWheel *device);
267 void newDome(Dome *device);
268 void newGPS(GPS *device);
269 void newWeather(Weather *device);
270 void newAdaptiveOptics(AdaptiveOptics *device);
271 void newDustCap(DustCap *device);
272 void newLightBox(LightBox *device);
273 void newDetector(Detector *device);
274 void newRotator(Rotator *device);
275 void newSpectrograph(Spectrograph *device);
276 void newCorrelator(Correlator *device);
277 void newAuxiliary(Auxiliary *device);
278
279 private:
280
281 class StreamFileMetadata
282 {
283 public:
284 QString device;
285 QString property;
286 QString element;
287 QFile *file { nullptr};
288 };
289
290 static void registerDBusType();
291 bool m_Connected { false };
292 bool m_Ready {false};
293 QString m_Name;
294 QSharedPointer<DriverInfo> m_DriverInfo;
295 DeviceInfo *m_DeviceInfo { nullptr };
296 INDI::BaseDevice m_BaseDevice;
297 ClientManager *m_ClientManager { nullptr };
298 QTimer *watchDogTimer { nullptr };
299 QTimer *m_ReadyTimer {nullptr};
300 QTimer *m_TimeUpdateTimer {nullptr};
301 QTimer *m_LocationUpdateTimer {nullptr};
302 QList<StreamFileMetadata> streamFileMetadata;
303
304 static uint8_t getID()
305 {
306 return m_ID++;
307 }
308 static uint8_t m_ID;
309};
310
311void switchToJson(INDI::Property prop, QJsonObject &propObject, bool compact = true);
312void textToJson(INDI::Property prop, QJsonObject &propObject, bool compact = true);
313void numberToJson(INDI::Property prop, QJsonObject &propObject, bool compact = true);
314void lightToJson(INDI::Property prop, QJsonObject &propObject, bool compact = true);
315void propertyToJson(INDI::Property prop, QJsonObject &propObject, bool compact = true);
316
317}
318
319
320#ifndef KSTARS_LITE
321Q_DECLARE_METATYPE(ISD::ParkStatus)
322QDBusArgument &operator<<(QDBusArgument &argument, const ISD::ParkStatus &source);
323const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::ParkStatus &dest);
324#endif
ClientManager manages connection to INDI server, creation of devices, and receiving/sending propertie...
DeviceInfo is simple class to hold DriverInfo and INDI::BaseDevice associated with a particular devic...
Definition deviceinfo.h:21
DriverInfo holds all metadata associated with a particular INDI driver.
Definition driverinfo.h:46
AdaptiveOptics class handles control of INDI AdaptiveOptics devices.
Auxiliary class handles control of INDI Auxiliary devices.
Camera class controls an INDI Camera device.
Definition indicamera.h:47
Correlator class handles control of INDI Correlator devices.
Detector class handles control of INDI Detector devices.
Class handles control of INDI dome devices.
Definition indidome.h:23
Handles operation of a remotely controlled dust cover cap.
Definition indidustcap.h:23
Focuser class handles control of INDI focuser devices.
Definition indifocuser.h:21
GDInterface is the Generic Device Interface for INDI devices.
Definition indistd.h:84
GenericDevice is the Generic Device for INDI devices.
Definition indistd.h:117
void sendNewSwitch(INDI::Property prop)
Send new Switch command to server.
void sendNewNumber(INDI::Property prop)
Send new Number command to server.
virtual bool processBLOB(INDI::Property prop) override
processBLOB Process Binary BLOB
Definition indistd.cpp:534
void sendNewText(INDI::Property prop)
Send new Text command to server.
bool generateDevices()
generateDevices Generate concrete devices based on DRIVER_INTERFACE
Definition indistd.cpp:1153
Handles operation of a remotely controlled light box.
device handle controlling Mounts.
Definition indimount.h:27
Rotator class handles control of INDI Rotator devices.
Definition indirotator.h:20
Spectrograph class handles control of INDI Spectrograph devices.
Focuser class handles control of INDI Weather devices.
Definition indiweather.h:24
ISD is a collection of INDI Standard Devices.
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QObject(QObject *parent)
Q_CLASSINFO(Name, Value)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.