File indexing completed on 2025-02-02 07:09:03
0001 /* 0002 SPDX-FileCopyrightText: 2014 Jasem Mutlaq <mutlaqja@ikarustech.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QObject> 0010 0011 /** 0012 * @class INDIDBus 0013 * 0014 * Collection of INDI DBus functions. 0015 * 0016 * @author Jasem Mutlaq 0017 */ 0018 class INDIDBus : public QObject 0019 { 0020 Q_OBJECT 0021 Q_CLASSINFO("D-Bus Interface", "org.kde.kstars.INDI") 0022 0023 public: 0024 explicit INDIDBus(QObject *parent = nullptr); 0025 0026 /** @defgroup INDIDBusInterface INDI DBus Interface 0027 * INDIDBus interface provides complete scripting capability over INDI servers and devices within KStars. 0028 * 0029 * A Python DBus <a href="http://indilib.org/support/tutorials/148-dbus-scripting-with-kstars-python.html">tutorial</a> demonstrates 0030 * the capabilities of the INDI DBus interface. 0031 */ 0032 0033 /*@{*/ 0034 0035 /** DBUS interface function. Start a local INDI server given a list of drivers on the given port. 0036 * @param port Port used to establish server. If empty, default port 7624 is used. 0037 * @param drivers List of drivers executables to run. 0038 */ 0039 Q_SCRIPTABLE bool start(int port, const QStringList &drivers); 0040 0041 /** DBUS interface function. Stops server running on the given port 0042 @param port Port of existing server to stop 0043 */ 0044 Q_SCRIPTABLE bool stop(const QString &port); 0045 0046 /** DBUS interface function. Connect to an INDI server 0047 * @param host hostname of server to connect to. 0048 * @param port Port of server. 0049 */ 0050 Q_SCRIPTABLE bool connect(const QString &host, int port); 0051 0052 /** DBUS interface function. Disconnect from an INDI server 0053 * @param host hostname of server to disconnect. 0054 * @param port Port of server. 0055 */ 0056 Q_SCRIPTABLE bool disconnect(const QString &host, int port); 0057 0058 /** DBUS interface function. Returns a list of INDI devices 0059 * @returns List of device names 0060 */ 0061 Q_SCRIPTABLE QStringList getDevicesPaths(uint32_t interface); 0062 0063 /** DBUS interface function. Returns a list of INDI devices 0064 * @returns List of device names 0065 */ 0066 Q_SCRIPTABLE QStringList getDevices(); 0067 0068 /** DBUS interface function. Returns a list of INDI properties 0069 * @param device device name 0070 * @returns List of properties in the format DEVICE.PROPERTY.ELEMENT. 0071 */ 0072 Q_SCRIPTABLE QStringList getProperties(const QString &device); 0073 0074 /** DBUS interface function. Returns INDI property state 0075 * @param device device name 0076 * @param property property name 0077 * @returns Idle, Ok, Busy, or Alert. If no property is found, it returns "Invalid" 0078 */ 0079 Q_SCRIPTABLE QString getPropertyState(const QString &device, const QString &property); 0080 0081 /** DBUS interface function. Sends property to INDI server 0082 * @param device device name 0083 * @param property property name 0084 * @returns true if property is found and sent to server, false otherwise. 0085 */ 0086 Q_SCRIPTABLE bool sendProperty(const QString &device, const QString &property); 0087 0088 /** DBUS interface function. Set INDI Switch status 0089 * @param device device name 0090 * @param property property name 0091 * @param switchName switch name 0092 * @param status Either On or Off. 0093 * /note This function ONLY sets the switch status but does not send it to server. Use sendProperty to send a switch to server. 0094 */ 0095 Q_SCRIPTABLE bool setSwitch(const QString &device, const QString &property, const QString &switchName, 0096 const QString &status); 0097 0098 /** DBUS interface function. Returns INDI switch status 0099 * @param device device name 0100 * @param property property name 0101 * @param switchName switch name 0102 * @returns On or Off if switch is found. If no switch is found, it returns "Invalid". 0103 */ 0104 Q_SCRIPTABLE QString getSwitch(const QString &device, const QString &property, const QString &switchName); 0105 0106 /** DBUS interface function. Set INDI Text 0107 * @param device device name 0108 * @param property property name 0109 * @param textName text element name 0110 * @param text text value 0111 * /note This function ONLY sets the text value but does not send it to server. Use sendProperty to send a text to server. 0112 */ 0113 Q_SCRIPTABLE bool setText(const QString &device, const QString &property, const QString &textName, 0114 const QString &text); 0115 0116 /** DBUS interface function. Returns INDI text value 0117 * @param device device name 0118 * @param property property name 0119 * @param textName text element name 0120 * @returns text value. If no text is found, it returns "Invalid". 0121 */ 0122 Q_SCRIPTABLE QString getText(const QString &device, const QString &property, const QString &textName); 0123 0124 /** DBUS interface function. Set INDI Number 0125 * @param device device name 0126 * @param property property name 0127 * @param numberName number element name 0128 * @param value number value 0129 * @returns true if successful, false otherwise. 0130 * /note This function ONLY sets the number value but does not send it to server. Use sendProperty to send a number to server. 0131 */ 0132 Q_SCRIPTABLE bool setNumber(const QString &device, const QString &property, const QString &numberName, 0133 double value); 0134 0135 /** DBUS interface function. Returns INDI number value 0136 * @param device device name 0137 * @param property name 0138 * @param numberName number element name 0139 * @returns number value. If no text is found, it returns NAN. 0140 */ 0141 Q_SCRIPTABLE double getNumber(const QString &device, const QString &property, const QString &numberName); 0142 0143 /** DBUS interface function. Returns INDI Light state 0144 * @param device device name 0145 * @param property name 0146 * @param lightName light element name 0147 * @returns Idle, Ok, Busy, or Alert. If no property is found, it returns "Invalid" 0148 */ 0149 Q_SCRIPTABLE QString getLight(const QString &device, const QString &property, const QString &lightName); 0150 0151 /** DBUS interface function. Returns INDI blob data. It can be extremely inefficient transporting large amount of data via DBUS. 0152 * @param device device name 0153 * @param property property name 0154 * @param blobName blob element name 0155 * @param blobFormat blob element format. It is usually the extension of the blob file. 0156 * @param size blob element size in bytes. If -1, then there is an error. 0157 * @returns array of bytes containing blob. 0158 * @see getBLOBFile 0159 */ 0160 Q_SCRIPTABLE QByteArray getBLOBData(const QString &device, const QString &property, const QString &blobName, 0161 QString &blobFormat, int &size); 0162 0163 /** DBUS interface function. Returns INDI blob filename stored on the local file system. 0164 * @param device device name 0165 * @param property property name 0166 * @param blobName blob element name 0167 * @param blobFormat blob element format. It is usually the extension of a file. 0168 * @param size blob element size in bytes. If -1, then there is an error. 0169 * @returns full file name 0170 */ 0171 Q_SCRIPTABLE QString getBLOBFile(const QString &device, const QString &property, const QString &blobName, 0172 QString &blobFormat, int &size); 0173 0174 /** @}*/ 0175 };