Kstars

indiweather.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Jasem Mutlaq <mutlaqja@ikarustech.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "indiweather.h"
8#include "weatheradaptor.h"
9
10#include <basedevice.h>
11#include <QJsonObject>
12#include <QtDBus/qdbusmetatype.h>
13
14namespace ISD
15{
16
17Weather::Weather(GenericDevice *parent) : ConcreteDevice(parent)
18{
19 qRegisterMetaType<ISD::Weather::Status>("ISD::Weather::Status");
20 qDBusRegisterMetaType<ISD::Weather::Status>();
21
22 new WeatherAdaptor(this);
23 m_DBusObjectPath = QString("/KStars/INDI/Weather/%1").arg(getID());
24 QDBusConnection::sessionBus().registerObject(m_DBusObjectPath, this);
25}
26
27void Weather::processLight(INDI::Property prop)
28{
29 auto lvp = prop.getLight();
30 if (lvp->isNameMatch("WEATHER_STATUS"))
31 {
32 Status currentStatus = static_cast<Status>(lvp->s);
33 if (currentStatus != m_WeatherStatus)
34 {
35 m_WeatherStatus = currentStatus;
36 emit newStatus(m_WeatherStatus);
37 }
38 }
39}
40
41void Weather::processNumber(INDI::Property prop)
42{
43 auto nvp = prop.getNumber();
44
45 if (nvp->isNameMatch("WEATHER_PARAMETERS"))
46 {
47 m_Data = QJsonArray();
48
49 // read all sensor values received
50 for (int i = 0; i < nvp->nnp; i++)
51 {
52 auto number = nvp->at(i);
53 QJsonObject sensor =
54 {
55 {"name", number->getName()},
56 {"label", number->getLabel()},
57 {"value", number->getValue()}
58 };
59 m_Data.push_back(sensor);
60 }
61 emit newData(m_Data);
62 emit newJSONData(QJsonDocument(m_Data).toJson());
63 }
64}
65
66Weather::Status Weather::status()
67{
68 auto weatherLP = getLight("WEATHER_STATUS");
69
70 if (!weatherLP)
71 return WEATHER_IDLE;
72
73 m_WeatherStatus = static_cast<Status>(weatherLP->getState());
74
75 return static_cast<Status>(weatherLP->getState());
76}
77
78int Weather::refreshPeriod()
79{
80 auto updateNP = getNumber("WEATHER_UPDATE");
81
82 if (!updateNP)
83 return 0;
84
85 return static_cast<int>(updateNP->at(0)->getValue());
86}
87
88void Weather::setRefreshPeriod(int value)
89{
90 auto updateNP = getNumber("WEATHER_UPDATE");
91
92 if (!updateNP)
93 return;
94
95 updateNP->at(0)->setValue(value);
96 sendNewProperty(updateNP);
97}
98
99bool Weather::refresh()
100{
101 auto refreshSP = getSwitch("WEATHER_REFRESH");
102
103 if (refreshSP == nullptr)
104 return false;
105
106 auto refreshSW = refreshSP->findWidgetByName("REFRESH");
107
108 if (refreshSW == nullptr)
109 return false;
110
111 refreshSP->reset();
112 refreshSW->setState(ISS_ON);
113 sendNewProperty(refreshSP);
114
115 return true;
116
117}
118}
119
120#ifndef KSTARS_LITE
121QDBusArgument &operator<<(QDBusArgument &argument, const ISD::Weather::Status &source)
122{
123 argument.beginStructure();
124 argument << static_cast<int>(source);
125 argument.endStructure();
126 return argument;
127}
128
129const QDBusArgument &operator>>(const QDBusArgument &argument, ISD::Weather::Status &dest)
130{
131 int a;
132 argument.beginStructure();
133 argument >> a;
134 argument.endStructure();
135 dest = static_cast<ISD::Weather::Status>(a);
136 return argument;
137}
138#endif
ISD is a collection of INDI Standard Devices.
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
KIOCORE_EXPORT QString number(KIO::filesize_t size)
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
void beginStructure()
void endStructure()
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
QString arg(Args &&... args) const const
const QChar at(qsizetype position) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.