diff --git a/libnymea-core/jsonrpc/zigbeehandler.cpp b/libnymea-core/jsonrpc/zigbeehandler.cpp index 9f4091ef..61976a74 100644 --- a/libnymea-core/jsonrpc/zigbeehandler.cpp +++ b/libnymea-core/jsonrpc/zigbeehandler.cpp @@ -30,6 +30,9 @@ #include "zigbeehandler.h" #include "zigbee/zigbeemanager.h" +#include "zigbee/zigbeeadapters.h" + +#include namespace nymeaserver { @@ -40,12 +43,14 @@ ZigbeeHandler::ZigbeeHandler(ZigbeeManager *zigbeeManager, QObject *parent) : registerEnum(); registerEnum(); + registerObject(); + QVariantMap params, returns; QString description; /* 1. GetNetworkStatus * 2. Setup network if the is no network configured - * - GetUartInterfaces + * - GetAvailableAdapters * - Setup network with given UART interface and backend type * - */ @@ -66,11 +71,11 @@ ZigbeeHandler::ZigbeeHandler(ZigbeeManager *zigbeeManager, QObject *parent) : returns.insert("networkState", enumRef()); registerMethod("GetNetworkStatus", description, params, returns); - // GetUartInterfaces -// params.clear(); returns.clear(); -// description = "Get the available UART interfaces in order to set up the zigbee network on the approriate serial interface."; -// returns.insert("uartInterfaces", objectRef()); -// registerMethod("GetUartInterfaces", description, params, returns); + // GetAvailableAdapters + params.clear(); returns.clear(); + description = "Get the available ZigBee adapters in order to set up the zigbee network on the approriate serial interface. If the adapter has been recognized correctly, the \"backendSuggestionAvailable\" will be true and the configurations can be used as they where given, otherwise the user might set the backend type and baud rate manually."; + returns.insert("zigbeeAdapters", objectRef()); + registerMethod("GetAvailableAdapters", description, params, returns); // GetNetworkStatus // NetworkStatusChanged @@ -118,15 +123,15 @@ JsonReply *ZigbeeHandler::GetNetworkStatus(const QVariantMap ¶ms) return createReply(ret); } -JsonReply *ZigbeeHandler::GetUartInterfaces(const QVariantMap ¶ms) +JsonReply *ZigbeeHandler::GetAvailableAdapters(const QVariantMap ¶ms) { Q_UNUSED(params) - QVariantMap ret; -// QVariantList portList; -// foreach (const ZigbeeSerialPort &serialPort, m_zigbeeManager->availablePorts()) { -// portList << pack(serialPort); -// } -// ret.insert("uartInterfaces", portList); + + QVariantMap ret; QVariantList adapterList; + foreach (const ZigbeeAdapter &adapter, m_zigbeeManager->availableAdapters()) { + adapterList << pack(adapter); + } + ret.insert("zigbeeAdapters", adapterList); return createReply(ret); } diff --git a/libnymea-core/jsonrpc/zigbeehandler.h b/libnymea-core/jsonrpc/zigbeehandler.h index 376eb24f..c94c9d07 100644 --- a/libnymea-core/jsonrpc/zigbeehandler.h +++ b/libnymea-core/jsonrpc/zigbeehandler.h @@ -50,7 +50,7 @@ public: QString name() const override; Q_INVOKABLE JsonReply *GetNetworkStatus(const QVariantMap ¶ms); - Q_INVOKABLE JsonReply *GetUartInterfaces(const QVariantMap ¶ms); + Q_INVOKABLE JsonReply *GetAvailableAdapters(const QVariantMap ¶ms); private: diff --git a/libnymea-core/libnymea-core.pro b/libnymea-core/libnymea-core.pro index 430a50fe..52370808 100644 --- a/libnymea-core/libnymea-core.pro +++ b/libnymea-core/libnymea-core.pro @@ -130,6 +130,7 @@ HEADERS += nymeacore.h \ cloud/cloudtransport.h \ debugreportgenerator.h \ platform/platform.h \ \ + zigbee/zigbeeadapters.h \ zigbee/zigbeemanager.h @@ -216,6 +217,7 @@ SOURCES += nymeacore.cpp \ cloud/cloudtransport.cpp \ debugreportgenerator.cpp \ platform/platform.cpp \ + zigbee/zigbeeadapters.cpp \ zigbee/zigbeemanager.cpp diff --git a/libnymea-core/zigbee/zigbeeadapters.cpp b/libnymea-core/zigbee/zigbeeadapters.cpp new file mode 100644 index 00000000..7379fd2a --- /dev/null +++ b/libnymea-core/zigbee/zigbeeadapters.cpp @@ -0,0 +1,56 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU General Public License as published by the Free Software +* Foundation, GNU version 3. This project is distributed in the hope that it +* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +* Public License for more details. +* +* You should have received a copy of the GNU General Public License along with +* this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "zigbeeadapters.h" + +namespace nymeaserver { + +ZigbeeAdapters::ZigbeeAdapters() +{ + +} + +ZigbeeAdapters::ZigbeeAdapters(const QList &other) : + QList(other) +{ + +} + +QVariant ZigbeeAdapters::get(int index) const +{ + return QVariant::fromValue(at(index)); +} + +void ZigbeeAdapters::put(const QVariant &variant) +{ + append(variant.value()); +} + +} diff --git a/libnymea-core/zigbee/zigbeeadapters.h b/libnymea-core/zigbee/zigbeeadapters.h new file mode 100644 index 00000000..7d400f33 --- /dev/null +++ b/libnymea-core/zigbee/zigbeeadapters.h @@ -0,0 +1,55 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU General Public License as published by the Free Software +* Foundation, GNU version 3. This project is distributed in the hope that it +* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +* Public License for more details. +* +* You should have received a copy of the GNU General Public License along with +* this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef ZIGBEEADAPTERS_H +#define ZIGBEEADAPTERS_H + +#include +#include + +namespace nymeaserver { + +class ZigbeeAdapters : public QList +{ + Q_GADGET + Q_PROPERTY(int count READ count) + +public: + ZigbeeAdapters(); + ZigbeeAdapters(const QList &other); + Q_INVOKABLE QVariant get(int index) const; + Q_INVOKABLE void put(const QVariant &variant); +}; + +} + +Q_DECLARE_METATYPE(nymeaserver::ZigbeeAdapters) + +#endif // ZIGBEEADAPTERS_H diff --git a/libnymea-core/zigbee/zigbeemanager.cpp b/libnymea-core/zigbee/zigbeemanager.cpp index 645d4bae..568a9d2e 100644 --- a/libnymea-core/zigbee/zigbeemanager.cpp +++ b/libnymea-core/zigbee/zigbeemanager.cpp @@ -59,6 +59,11 @@ ZigbeeNetwork *ZigbeeManager::zigbeeNetwork() const return m_zigbeeNetwork; } +ZigbeeAdapters ZigbeeManager::availableAdapters() +{ + return ZigbeeNetworkManager::availableAdapters(); +} + void ZigbeeManager::createZigbeeNetwork(const QString &serialPort, qint32 baudrate, Zigbee::ZigbeeBackendType backend) { if (m_zigbeeNetwork) { diff --git a/libnymea-core/zigbee/zigbeemanager.h b/libnymea-core/zigbee/zigbeemanager.h index 0ca56680..45dd5f9c 100644 --- a/libnymea-core/zigbee/zigbeemanager.h +++ b/libnymea-core/zigbee/zigbeemanager.h @@ -35,6 +35,8 @@ #include +#include "zigbeeadapters.h" + namespace nymeaserver { class ZigbeeManager : public QObject @@ -55,6 +57,7 @@ public: bool enabled() const; ZigbeeNetwork *zigbeeNetwork() const; + ZigbeeAdapters availableAdapters(); void createZigbeeNetwork(const QString &serialPort, qint32 baudrate, Zigbee::ZigbeeBackendType backend);