Add GetAvailableAdapters to zigbee handler
This commit is contained in:
parent
4a520d8ba1
commit
61d0b96b42
@ -30,6 +30,9 @@
|
||||
|
||||
#include "zigbeehandler.h"
|
||||
#include "zigbee/zigbeemanager.h"
|
||||
#include "zigbee/zigbeeadapters.h"
|
||||
|
||||
#include <zigbeeadapter.h>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
@ -40,12 +43,14 @@ ZigbeeHandler::ZigbeeHandler(ZigbeeManager *zigbeeManager, QObject *parent) :
|
||||
registerEnum<ZigbeeManager::ZigbeeNetworkState>();
|
||||
registerEnum<Zigbee::ZigbeeBackendType>();
|
||||
|
||||
registerObject<ZigbeeAdapter, ZigbeeAdapters>();
|
||||
|
||||
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<ZigbeeManager::ZigbeeNetworkState>());
|
||||
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<ZigbeeSerialPortList>());
|
||||
// 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<ZigbeeAdapters>());
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
56
libnymea-core/zigbee/zigbeeadapters.cpp
Normal file
56
libnymea-core/zigbee/zigbeeadapters.cpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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<ZigbeeAdapter> &other) :
|
||||
QList<ZigbeeAdapter>(other)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant ZigbeeAdapters::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
void ZigbeeAdapters::put(const QVariant &variant)
|
||||
{
|
||||
append(variant.value<ZigbeeAdapter>());
|
||||
}
|
||||
|
||||
}
|
||||
55
libnymea-core/zigbee/zigbeeadapters.h
Normal file
55
libnymea-core/zigbee/zigbeeadapters.h
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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 <QObject>
|
||||
#include <zigbeeadapter.h>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class ZigbeeAdapters : public QList<ZigbeeAdapter>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
|
||||
public:
|
||||
ZigbeeAdapters();
|
||||
ZigbeeAdapters(const QList<ZigbeeAdapter> &other);
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
Q_INVOKABLE void put(const QVariant &variant);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(nymeaserver::ZigbeeAdapters)
|
||||
|
||||
#endif // ZIGBEEADAPTERS_H
|
||||
@ -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) {
|
||||
|
||||
@ -35,6 +35,8 @@
|
||||
|
||||
#include <zigbeenetworkmanager.h>
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user