Kstars

indiconcretedevice.cpp
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#include "indiconcretedevice.h"
10#include "clientmanager.h"
11
12namespace ISD
13{
14
15uint8_t ConcreteDevice::m_ID = 1;
16
17ConcreteDevice::ConcreteDevice(ISD::GenericDevice *parent) : GDInterface(parent), m_Parent(parent),
18 m_Name(parent->getDeviceName())
19{
20 // Signal --> Signal
21 connect(parent, &GenericDevice::Connected, this, [this]()
22 {
23 m_ReadyTimer.reset(new QTimer(this));
24 m_ReadyTimer->setInterval(250);
25 m_ReadyTimer->setSingleShot(true);
26 connect(m_ReadyTimer.get(), &QTimer::timeout, this, &ConcreteDevice::ready);
28 });
29 connect(parent, &GenericDevice::Disconnected, this, &ConcreteDevice::Disconnected);
30
31 // Signal --> Signal
32 connect(parent, &GenericDevice::propertyDefined, this, &ConcreteDevice::propertyDefined);
33 connect(parent, &GenericDevice::propertyDeleted, this, &ConcreteDevice::propertyDeleted);
34 connect(parent, &GenericDevice::propertyUpdated, this, &ConcreteDevice::propertyUpdated);
35
36 // Signal --> Slots
37 connect(parent, &GenericDevice::propertyDefined, this, [this](INDI::Property value)
38 {
39 if (m_ReadyTimer)
40 m_ReadyTimer->start();
41 registerProperty(value);
42 });
43 connect(parent, &GenericDevice::propertyDeleted, this, &ConcreteDevice::removeProperty);
44 connect(parent, &GenericDevice::propertyUpdated, this, &ConcreteDevice::updateProperty);
45}
46
47void ConcreteDevice::registeProperties()
48{
49 // Register all properties first
50 for (auto &oneProperty : m_Parent->getProperties())
51 registerProperty(oneProperty);
52}
53
54void ConcreteDevice::updateProperty(INDI::Property prop)
55{
56 switch (prop.getType())
57 {
58 case INDI_SWITCH:
59 processSwitch(prop);
60 break;
61 case INDI_NUMBER:
62 processNumber(prop);
63 break;
64 case INDI_TEXT:
65 processText(prop);
66 break;
67 case INDI_LIGHT:
68 processLight(prop);
69 break;
70 case INDI_BLOB:
71 processBLOB(prop);
72 default:
73 break;
74 }
75}
76
77void ConcreteDevice::processProperties()
78{
79 // Register all properties first
80 for (auto &oneProperty : m_Parent->getProperties())
81 {
82 switch (oneProperty.getType())
83 {
84 case INDI_SWITCH:
85 processSwitch(oneProperty);
86 break;
87 case INDI_NUMBER:
88 processNumber(oneProperty);
89 break;
90 case INDI_TEXT:
91 processText(oneProperty);
92 break;
93 case INDI_LIGHT:
94 processLight(oneProperty);
95 break;
96 case INDI_BLOB:
97 processBLOB(oneProperty);
98 break;
99 default:
100 break;
101 }
102 }
103}
104
105INDI::PropertyView<INumber> *ConcreteDevice::getNumber(const QString &name) const
106{
107 return m_Parent->getBaseDevice().getNumber(name.toLatin1().constData());
108}
109
110INDI::PropertyView<IText> *ConcreteDevice::getText(const QString &name) const
111{
112 return m_Parent->getBaseDevice().getText(name.toLatin1().constData());
113}
114
115INDI::PropertyView<ISwitch> *ConcreteDevice::getSwitch(const QString &name) const
116{
117 return m_Parent->getBaseDevice().getSwitch(name.toLatin1().constData());
118}
119
120INDI::PropertyView<ILight> *ConcreteDevice::getLight(const QString &name) const
121{
122 return m_Parent->getBaseDevice().getLight(name.toLatin1().constData());
123}
124
125INDI::PropertyView<IBLOB> *ConcreteDevice::getBLOB(const QString &name) const
126{
127 return m_Parent->getBaseDevice().getBLOB(name.toLatin1().constData());
128}
129
130void ConcreteDevice::sendNewProperty(INDI::Property prop)
131{
132 m_Parent->sendNewProperty(prop);
133}
134
135QString ConcreteDevice::getMessage(int id) const
136{
137 return QString::fromStdString(m_Parent->getBaseDevice().messageQueue(id));
138}
139
140INDI::Property ConcreteDevice::getProperty(const QString &name) const
141{
142 return m_Parent->getProperty(name);
143}
144
145const QSharedPointer<DriverInfo> &ConcreteDevice::getDriverInfo() const
146{
147 return m_Parent->getDriverInfo();
148}
149
150bool ConcreteDevice::setConfig(INDIConfig tConfig)
151{
152 return m_Parent->setConfig(tConfig);
153}
154
155Properties ConcreteDevice::getProperties() const
156{
157 return m_Parent->getProperties();
158}
159
160bool ConcreteDevice::getMinMaxStep(const QString &propName, const QString &elementName, double *min, double *max,
161 double *step) const
162{
163 return m_Parent->getMinMaxStep(propName, elementName, min, max, step);
164}
165
166IPState ConcreteDevice::getState(const QString &propName) const
167{
168 return m_Parent->getState(propName);
169}
170
171IPerm ConcreteDevice::getPermission(const QString &propName) const
172{
173 return m_Parent->getPermission(propName);
174}
175
176}
GenericDevice is the Generic Device for INDI devices.
Definition indistd.h:117
ISD is a collection of INDI Standard Devices.
const char * constData() const const
QString fromStdString(const std::string &str)
QByteArray toLatin1() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void timeout()
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.