File indexing completed on 2024-04-14 03:42:38

0001 /*
0002     SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 
0006     Handle INDI Standard properties.
0007 */
0008 
0009 #include "indiconcretedevice.h"
0010 #include "clientmanager.h"
0011 
0012 namespace ISD
0013 {
0014 
0015 uint8_t ConcreteDevice::m_ID = 1;
0016 
0017 ConcreteDevice::ConcreteDevice(ISD::GenericDevice *parent) : GDInterface(parent), m_Parent(parent),
0018     m_Name(parent->getDeviceName())
0019 {
0020     // Signal --> Signal
0021     connect(parent, &GenericDevice::Connected, this, [this]()
0022     {
0023         m_ReadyTimer.reset(new QTimer(this));
0024         m_ReadyTimer->setInterval(250);
0025         m_ReadyTimer->setSingleShot(true);
0026         connect(m_ReadyTimer.get(), &QTimer::timeout, this, &ConcreteDevice::ready);
0027         emit Connected();
0028     });
0029     connect(parent, &GenericDevice::Disconnected, this, &ConcreteDevice::Disconnected);
0030 
0031     // Signal --> Signal
0032     connect(parent, &GenericDevice::propertyDefined, this, &ConcreteDevice::propertyDefined);
0033     connect(parent, &GenericDevice::propertyDeleted, this, &ConcreteDevice::propertyDeleted);
0034     connect(parent, &GenericDevice::propertyUpdated, this, &ConcreteDevice::propertyUpdated);
0035 
0036     // Signal --> Slots
0037     connect(parent, &GenericDevice::propertyDefined, this, [this](INDI::Property value)
0038     {
0039         if (m_ReadyTimer)
0040             m_ReadyTimer->start();
0041         registerProperty(value);
0042     });
0043     connect(parent, &GenericDevice::propertyDeleted, this, &ConcreteDevice::removeProperty);
0044     connect(parent, &GenericDevice::propertyUpdated, this, &ConcreteDevice::updateProperty);
0045 }
0046 
0047 void ConcreteDevice::registeProperties()
0048 {
0049     // Register all properties first
0050     for (auto &oneProperty : m_Parent->getProperties())
0051         registerProperty(oneProperty);
0052 }
0053 
0054 void ConcreteDevice::updateProperty(INDI::Property prop)
0055 {
0056     switch (prop.getType())
0057     {
0058         case INDI_SWITCH:
0059             processSwitch(prop);
0060             break;
0061         case INDI_NUMBER:
0062             processNumber(prop);
0063             break;
0064         case INDI_TEXT:
0065             processText(prop);
0066             break;
0067         case INDI_LIGHT:
0068             processLight(prop);
0069             break;
0070         case INDI_BLOB:
0071             processBLOB(prop);
0072         default:
0073             break;
0074     }
0075 }
0076 
0077 void ConcreteDevice::processProperties()
0078 {
0079     // Register all properties first
0080     for (auto &oneProperty : m_Parent->getProperties())
0081     {
0082         switch (oneProperty.getType())
0083         {
0084             case INDI_SWITCH:
0085                 processSwitch(oneProperty);
0086                 break;
0087             case INDI_NUMBER:
0088                 processNumber(oneProperty);
0089                 break;
0090             case INDI_TEXT:
0091                 processText(oneProperty);
0092                 break;
0093             case INDI_LIGHT:
0094                 processLight(oneProperty);
0095                 break;
0096             case INDI_BLOB:
0097                 processBLOB(oneProperty);
0098                 break;
0099             default:
0100                 break;
0101         }
0102     }
0103 }
0104 
0105 INDI::PropertyView<INumber> *ConcreteDevice::getNumber(const QString &name) const
0106 {
0107     return m_Parent->getBaseDevice().getNumber(name.toLatin1().constData());
0108 }
0109 
0110 INDI::PropertyView<IText>   *ConcreteDevice::getText(const QString &name) const
0111 {
0112     return m_Parent->getBaseDevice().getText(name.toLatin1().constData());
0113 }
0114 
0115 INDI::PropertyView<ISwitch> *ConcreteDevice::getSwitch(const QString &name) const
0116 {
0117     return m_Parent->getBaseDevice().getSwitch(name.toLatin1().constData());
0118 }
0119 
0120 INDI::PropertyView<ILight>  *ConcreteDevice::getLight(const QString &name) const
0121 {
0122     return m_Parent->getBaseDevice().getLight(name.toLatin1().constData());
0123 }
0124 
0125 INDI::PropertyView<IBLOB>   *ConcreteDevice::getBLOB(const QString &name) const
0126 {
0127     return m_Parent->getBaseDevice().getBLOB(name.toLatin1().constData());
0128 }
0129 
0130 void ConcreteDevice::sendNewProperty(INDI::Property prop)
0131 {
0132     m_Parent->sendNewProperty(prop);
0133 }
0134 
0135 QString ConcreteDevice::getMessage(int id) const
0136 {
0137     return QString::fromStdString(m_Parent->getBaseDevice().messageQueue(id));
0138 }
0139 
0140 INDI::Property ConcreteDevice::getProperty(const QString &name) const
0141 {
0142     return m_Parent->getProperty(name);
0143 }
0144 
0145 const QSharedPointer<DriverInfo> &ConcreteDevice::getDriverInfo() const
0146 {
0147     return m_Parent->getDriverInfo();
0148 }
0149 
0150 bool ConcreteDevice::setConfig(INDIConfig tConfig)
0151 {
0152     return m_Parent->setConfig(tConfig);
0153 }
0154 
0155 Properties ConcreteDevice::getProperties() const
0156 {
0157     return m_Parent->getProperties();
0158 }
0159 
0160 bool ConcreteDevice::getMinMaxStep(const QString &propName, const QString &elementName, double *min, double *max,
0161                                    double *step) const
0162 {
0163     return m_Parent->getMinMaxStep(propName, elementName, min, max, step);
0164 }
0165 
0166 IPState ConcreteDevice::getState(const QString &propName) const
0167 {
0168     return m_Parent->getState(propName);
0169 }
0170 
0171 IPerm ConcreteDevice::getPermission(const QString &propName) const
0172 {
0173     return m_Parent->getPermission(propName);
0174 }
0175 
0176 }