Add zigbee serial port for api
This commit is contained in:
parent
fb74df8f81
commit
7cb995767c
@ -28,7 +28,7 @@
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "zigbeemanagerimplementation.h"
|
||||
#include "zigbeehardwareresourceimplementation.h"
|
||||
#include "loggingcategories.h"
|
||||
#include "nymeasettings.h"
|
||||
|
||||
|
||||
@ -29,40 +29,70 @@
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "zigbeehandler.h"
|
||||
#include "zigbee/zigbeemanager.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
ZigbeeHandler::ZigbeeHandler(QObject *parent) :
|
||||
JsonHandler(parent)
|
||||
ZigbeeHandler::ZigbeeHandler(ZigbeeManager *zigbeeManager, QObject *parent) :
|
||||
JsonHandler(parent),
|
||||
m_zigbeeManager(zigbeeManager)
|
||||
{
|
||||
registerEnum<ZigbeeNetwork::State>();
|
||||
registerEnum<ZigbeeNetworkManager::BackendType>();
|
||||
|
||||
registerObject<ZigbeeSerialPort>();
|
||||
registerObject<ZigbeeSerialPort, ZigbeeSerialPortList>();
|
||||
|
||||
QVariantMap params, returns;
|
||||
QString description;
|
||||
|
||||
/* 1. GetNetworkStatus
|
||||
* 2. Setup network if the is no network configured
|
||||
* - GetUartInterfaces
|
||||
* - Setup network with given UART interface and backend type
|
||||
* -
|
||||
*/
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Get the status of the current network.";
|
||||
returns.insert("available", enumValueName(Bool));
|
||||
returns.insert("enabled", enumValueName(Bool));
|
||||
returns.insert("configured", enumValueName(Bool));
|
||||
returns.insert("state", enumRef<ZigbeeNetwork::State>());
|
||||
returns.insert("serialPort", enumValueName(String));
|
||||
returns.insert("baudRate", enumValueName(Uint));
|
||||
returns.insert("backend", enumRef<ZigbeeNetworkManager::BackendType>());
|
||||
returns.insert("firmwareVersion", enumValueName(String));
|
||||
returns.insert("networkIeeeeAddress", enumValueName(String));
|
||||
returns.insert("networkPanId", enumValueName(Uint));
|
||||
returns.insert("channel", enumValueName(Uint));
|
||||
returns.insert("permitJoin", enumValueName(Bool));
|
||||
returns.insert("networkState", enumRef<ZigbeeNetwork::State>());
|
||||
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("available", enumValueName(Bool));
|
||||
returns.insert("enabled", enumValueName(Bool));
|
||||
returns.insert("configured", enumValueName(Bool));
|
||||
returns.insert("state", enumRef<ZigbeeNetwork::State>());
|
||||
returns.insert("uartInterfaces", objectRef<ZigbeeSerialPortList>());
|
||||
registerMethod("GetUartInterfaces", description, params, returns);
|
||||
|
||||
// GetNetworkStatus
|
||||
// NetworkStatusChanged
|
||||
// SetupNetwork(network, uart, baudrate, backendtype)
|
||||
// PermitJoin(time, o:nwk address)
|
||||
// FactoryResetNetwork
|
||||
|
||||
// Setup network, uart, baudrate, backendtype
|
||||
|
||||
// GetNodes [Node(mac, nwkAddress, name, manufacturer, type, descriptors, associacted device, state, reachable)]
|
||||
// NodeAdded
|
||||
// NodeChanged (state, node base information, associated deviceId)
|
||||
// RemoveNode
|
||||
// NodeRemoved
|
||||
|
||||
// GetGroups
|
||||
// GroupChanged
|
||||
// AddGroup
|
||||
// GroupAdded
|
||||
// RemoveGroup
|
||||
// GroupRemoved
|
||||
|
||||
}
|
||||
|
||||
@ -71,4 +101,36 @@ QString ZigbeeHandler::name() const
|
||||
return "Zigbee";
|
||||
}
|
||||
|
||||
JsonReply *ZigbeeHandler::GetNetworkStatus(const QVariantMap ¶ms)
|
||||
{
|
||||
Q_UNUSED(params)
|
||||
|
||||
QVariantMap ret;
|
||||
// if (m_zigbeeManager->zigbeeNetwork()) {
|
||||
// ret.insert("available", m_zigbeeManager->available());
|
||||
// ret.insert("enabled", m_zigbeeManager->enabled());
|
||||
// ret.insert("configured", true);
|
||||
// ret.insert("networkState", m_zigbeeManager->zigbeeNetwork()->state());
|
||||
// } else {
|
||||
// ret.insert("available", m_zigbeeManager->available());
|
||||
// ret.insert("enabled", m_zigbeeManager->enabled());
|
||||
// ret.insert("configured", false);
|
||||
// ret.insert("state", ZigbeeNetwork::StateUninitialized);
|
||||
// }
|
||||
|
||||
return createReply(ret);
|
||||
}
|
||||
|
||||
JsonReply *ZigbeeHandler::GetUartInterfaces(const QVariantMap ¶ms)
|
||||
{
|
||||
Q_UNUSED(params)
|
||||
QVariantMap ret;
|
||||
QVariantList portList;
|
||||
foreach (const ZigbeeSerialPort &serialPort, m_zigbeeManager->availablePorts()) {
|
||||
portList << pack(serialPort);
|
||||
}
|
||||
ret.insert("uartInterfaces", portList);
|
||||
return createReply(ret);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -39,14 +39,23 @@
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class ZigbeeManager;
|
||||
|
||||
class ZigbeeHandler : public JsonHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ZigbeeHandler(QObject *parent = nullptr);
|
||||
explicit ZigbeeHandler(ZigbeeManager *zigbeeManager, QObject *parent = nullptr);
|
||||
|
||||
QString name() const override;
|
||||
|
||||
Q_INVOKABLE JsonReply *GetNetworkStatus(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetUartInterfaces(const QVariantMap ¶ms);
|
||||
|
||||
|
||||
private:
|
||||
ZigbeeManager *m_zigbeeManager = nullptr;
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
@ -3,7 +3,7 @@ TARGET = nymea-core
|
||||
|
||||
include(../nymea.pri)
|
||||
|
||||
QT += sql qml
|
||||
QT += sql qml serialport
|
||||
INCLUDEPATH += $$top_srcdir/libnymea $$top_builddir
|
||||
LIBS += -L$$top_builddir/libnymea/ -lnymea -lssl -lcrypto
|
||||
|
||||
@ -129,7 +129,8 @@ HEADERS += nymeacore.h \
|
||||
cloud/cloudtransport.h \
|
||||
debugreportgenerator.h \
|
||||
platform/platform.h \ \
|
||||
zigbee/zigbeemanager.h
|
||||
zigbee/zigbeemanager.h \
|
||||
zigbee/zigbeeserialport.h
|
||||
|
||||
|
||||
SOURCES += nymeacore.cpp \
|
||||
@ -214,7 +215,8 @@ SOURCES += nymeacore.cpp \
|
||||
cloud/cloudtransport.cpp \
|
||||
debugreportgenerator.cpp \
|
||||
platform/platform.cpp \ \
|
||||
zigbee/zigbeemanager.cpp
|
||||
zigbee/zigbeemanager.cpp \
|
||||
zigbee/zigbeeserialport.cpp
|
||||
|
||||
|
||||
versionAtLeast(QT_VERSION, 5.12.0) {
|
||||
|
||||
@ -29,6 +29,10 @@
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#include "zigbeemanager.h"
|
||||
#include "nymeasettings.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include <QSerialPortInfo>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
@ -42,9 +46,58 @@ bool ZigbeeManager::available() const
|
||||
return m_zigbeeNetwork != nullptr;
|
||||
}
|
||||
|
||||
void ZigbeeManager::setupNetwork(const QString serialPort, qint32 baudrate, ZigbeeNetworkManager::BackendType)
|
||||
bool ZigbeeManager::enabled() const
|
||||
{
|
||||
return m_zigbeeNetwork && m_zigbeeNetwork->state() != ZigbeeNetwork::StateUninitialized;
|
||||
}
|
||||
|
||||
ZigbeeNetwork *ZigbeeManager::zigbeeNetwork() const
|
||||
{
|
||||
return m_zigbeeNetwork;
|
||||
}
|
||||
|
||||
ZigbeeSerialPortList ZigbeeManager::availablePorts()
|
||||
{
|
||||
ZigbeeSerialPortList ports;
|
||||
foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()) {
|
||||
qCDebug(dcZigbee()) << "Found serial port" << serialPortInfo.portName();
|
||||
qCDebug(dcZigbee()) << " Description:" << serialPortInfo.description();
|
||||
qCDebug(dcZigbee()) << " System location:" << serialPortInfo.systemLocation();
|
||||
qCDebug(dcZigbee()) << " Manufacturer:" << serialPortInfo.manufacturer();
|
||||
qCDebug(dcZigbee()) << " Serialnumber:" << serialPortInfo.serialNumber();
|
||||
|
||||
if (serialPortInfo.hasProductIdentifier()) {
|
||||
qCDebug(dcZigbee()) << " Product identifier:" << serialPortInfo.productIdentifier();
|
||||
}
|
||||
if (serialPortInfo.hasVendorIdentifier()) {
|
||||
qCDebug(dcZigbee()) << " Vendor identifier:" << serialPortInfo.vendorIdentifier();
|
||||
}
|
||||
|
||||
ZigbeeSerialPort port;
|
||||
port.setName(serialPortInfo.portName());
|
||||
port.setDescription(serialPortInfo.description());
|
||||
port.setSystemLocation(serialPortInfo.systemLocation());
|
||||
ports.append(port);
|
||||
}
|
||||
|
||||
return ports;
|
||||
}
|
||||
|
||||
void ZigbeeManager::createZigbeeNetwork(const QString &serialPort, qint32 baudrate, ZigbeeNetworkManager::BackendType backend)
|
||||
{
|
||||
if (m_zigbeeNetwork) {
|
||||
delete m_zigbeeNetwork;
|
||||
m_zigbeeNetwork = nullptr;
|
||||
}
|
||||
|
||||
m_zigbeeNetwork = ZigbeeNetworkManager::createZigbeeNetwork(backend, this);
|
||||
m_zigbeeNetwork->setSerialPortName(serialPort);
|
||||
m_zigbeeNetwork->setSerialBaudrate(baudrate);
|
||||
m_zigbeeNetwork->setSettingsFileName(NymeaSettings(NymeaSettings::SettingsRoleGlobal).fileName());
|
||||
|
||||
m_zigbeeNetwork->startNetwork();
|
||||
|
||||
emit zigbeeNetworkChanged(m_zigbeeNetwork);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -35,6 +35,8 @@
|
||||
|
||||
#include <nymea-zigbee/zigbeenetworkmanager.h>
|
||||
|
||||
#include "zigbeeserialport.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class ZigbeeManager : public QObject
|
||||
@ -44,8 +46,13 @@ public:
|
||||
explicit ZigbeeManager(QObject *parent = nullptr);
|
||||
|
||||
bool available() const;
|
||||
bool enabled() const;
|
||||
|
||||
void setupNetwork(const QString serialPort, qint32 baudrate, ZigbeeNetworkManager::BackendType);
|
||||
ZigbeeNetwork *zigbeeNetwork() const;
|
||||
|
||||
ZigbeeSerialPortList availablePorts();
|
||||
|
||||
void createZigbeeNetwork(const QString &serialPort, qint32 baudrate, ZigbeeNetworkManager::BackendType backend);
|
||||
|
||||
private:
|
||||
ZigbeeNetwork *m_zigbeeNetwork = nullptr;
|
||||
|
||||
80
libnymea-core/zigbee/zigbeeserialport.cpp
Normal file
80
libnymea-core/zigbee/zigbeeserialport.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* 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 "zigbeeserialport.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
ZigbeeSerialPort::ZigbeeSerialPort()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString ZigbeeSerialPort::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void ZigbeeSerialPort::setName(const QString &name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QString ZigbeeSerialPort::description() const
|
||||
{
|
||||
return m_description;
|
||||
}
|
||||
|
||||
void ZigbeeSerialPort::setDescription(const QString &description)
|
||||
{
|
||||
m_description = description;
|
||||
}
|
||||
|
||||
QString ZigbeeSerialPort::systemLocation() const
|
||||
{
|
||||
return m_systemLocation;
|
||||
}
|
||||
|
||||
void ZigbeeSerialPort::setSystemLocation(const QString &systemLocation)
|
||||
{
|
||||
m_systemLocation = systemLocation;
|
||||
}
|
||||
|
||||
QVariant ZigbeeSerialPortList::get(int index) const
|
||||
{
|
||||
return QVariant::fromValue(at(index));
|
||||
}
|
||||
|
||||
void ZigbeeSerialPortList::put(const QVariant &variant)
|
||||
{
|
||||
append(variant.value<ZigbeeSerialPort>());
|
||||
}
|
||||
|
||||
}
|
||||
77
libnymea-core/zigbee/zigbeeserialport.h
Normal file
77
libnymea-core/zigbee/zigbeeserialport.h
Normal file
@ -0,0 +1,77 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* 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 ZIGBEESERIALPORT_H
|
||||
#define ZIGBEESERIALPORT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
namespace nymeaserver {
|
||||
|
||||
class ZigbeeSerialPort
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString name READ name)
|
||||
Q_PROPERTY(QString description READ description)
|
||||
Q_PROPERTY(QString systemLocation READ systemLocation)
|
||||
|
||||
public:
|
||||
ZigbeeSerialPort();
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QString description() const;
|
||||
void setDescription(const QString &description);
|
||||
|
||||
QString systemLocation() const;
|
||||
void setSystemLocation(const QString &systemLocation);
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_description;
|
||||
QString m_systemLocation;
|
||||
};
|
||||
|
||||
class ZigbeeSerialPortList: public QList<ZigbeeSerialPort>
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(int count READ count)
|
||||
public:
|
||||
Q_INVOKABLE QVariant get(int index) const;
|
||||
Q_INVOKABLE void put(const QVariant &variant);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(nymeaserver::ZigbeeSerialPort)
|
||||
Q_DECLARE_METATYPE(nymeaserver::ZigbeeSerialPortList)
|
||||
|
||||
#endif // ZIGBEESERIALPORT_H
|
||||
Reference in New Issue
Block a user