Introduce adapter and improve network manager

This commit is contained in:
Simon Stürz 2020-10-28 09:56:46 +01:00
parent 531d8075d4
commit 6ffd8a61db
9 changed files with 253 additions and 12 deletions

View File

@ -31,6 +31,7 @@ SOURCES += \
zdo/zigbeedeviceobject.cpp \ zdo/zigbeedeviceobject.cpp \
zdo/zigbeedeviceobjectreply.cpp \ zdo/zigbeedeviceobjectreply.cpp \
zdo/zigbeedeviceprofile.cpp \ zdo/zigbeedeviceprofile.cpp \
zigbeeadapter.cpp \
zigbeeadpu.cpp \ zigbeeadpu.cpp \
zigbeebridgecontroller.cpp \ zigbeebridgecontroller.cpp \
zigbeechannelmask.cpp \ zigbeechannelmask.cpp \
@ -88,6 +89,7 @@ HEADERS += \
zdo/zigbeedeviceobject.h \ zdo/zigbeedeviceobject.h \
zdo/zigbeedeviceobjectreply.h \ zdo/zigbeedeviceobjectreply.h \
zdo/zigbeedeviceprofile.h \ zdo/zigbeedeviceprofile.h \
zigbeeadapter.h \
zigbeeadpu.h \ zigbeeadpu.h \
zigbeebridgecontroller.h \ zigbeebridgecontroller.h \
zigbeechannelmask.h \ zigbeechannelmask.h \

View File

@ -40,6 +40,12 @@ class Zigbee
Q_GADGET Q_GADGET
public: public:
enum BackendType {
BackendTypeDeconz,
BackendTypeNxp
};
Q_ENUM(BackendType)
enum ZigbeeProfile { enum ZigbeeProfile {
ZigbeeProfileDevice = 0x0000, ZigbeeProfileDevice = 0x0000,
ZigbeeProfileIndustrialPlantMonitoring = 0x0101, ZigbeeProfileIndustrialPlantMonitoring = 0x0101,

View File

@ -0,0 +1,106 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea-zigbee.
* 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 Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation; 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 "zigbeeadapter.h"
ZigbeeAdapter::ZigbeeAdapter()
{
}
QString ZigbeeAdapter::name() const
{
return m_name;
}
void ZigbeeAdapter::setName(const QString &name)
{
m_name = name;
}
QString ZigbeeAdapter::description() const
{
return m_description;
}
void ZigbeeAdapter::setDescription(const QString &description)
{
m_description = description;
}
QString ZigbeeAdapter::systemLocation() const
{
return m_systemLocation;
}
void ZigbeeAdapter::setSystemLocation(const QString &systemLocation)
{
m_systemLocation = systemLocation;
}
bool ZigbeeAdapter::backendSuggestionAvailable() const
{
return m_backendSuggestionAvailable;
}
void ZigbeeAdapter::setBackendSuggestionAvailable(bool backendSuggestionAvailable)
{
m_backendSuggestionAvailable = backendSuggestionAvailable;
}
Zigbee::BackendType ZigbeeAdapter::suggestedBackendType() const
{
return m_suggestedBackendType;
}
void ZigbeeAdapter::setSuggestedBackendType(Zigbee::BackendType backendType)
{
m_suggestedBackendType = backendType;
}
qint32 ZigbeeAdapter::suggestedBaudRate() const
{
return m_suggestedBaudRate;
}
void ZigbeeAdapter::setSuggestedBaudRate(qint32 baudRate)
{
m_suggestedBaudRate = baudRate;
}
QDebug operator<<(QDebug debug, const ZigbeeAdapter &adapter)
{
debug.nospace() << "ZigbeeAdapter(" << adapter.name() << " - " << adapter.description();
debug.nospace() << ", " << adapter.systemLocation();
if (adapter.backendSuggestionAvailable()) {
debug.nospace() << "Suggested backend: " << adapter.suggestedBackendType();
debug.nospace() << ", " << adapter.suggestedBaudRate();
}
debug.nospace() << ")";
return debug.space();
}

View File

@ -0,0 +1,77 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea-zigbee.
* 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 Lesser General Public License Usage
* Alternatively, this project may be redistributed and/or modified under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation; 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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 ZIGBEEADAPTER_H
#define ZIGBEEADAPTER_H
#include <QObject>
#include <QDebug>
#include "zigbee.h"
class ZigbeeAdapter
{
Q_GADGET
Q_PROPERTY(QString name READ name)
Q_PROPERTY(QString description READ description)
Q_PROPERTY(QString systemLocation READ systemLocation)
public:
explicit ZigbeeAdapter();
QString name() const;
void setName(const QString &name);
QString description() const;
void setDescription(const QString &description);
QString systemLocation() const;
void setSystemLocation(const QString &systemLocation);
bool backendSuggestionAvailable() const;
void setBackendSuggestionAvailable(bool backendSuggestionAvailable);
Zigbee::BackendType suggestedBackendType() const;
void setSuggestedBackendType(Zigbee::BackendType backendType);
qint32 suggestedBaudRate() const;
void setSuggestedBaudRate(qint32 baudRate);
private:
QString m_name;
QString m_description;
QString m_systemLocation;
bool m_backendSuggestionAvailable = false;
Zigbee::BackendType m_suggestedBackendType = Zigbee::BackendTypeDeconz;
qint32 m_suggestedBaudRate = 38400;
};
QDebug operator<<(QDebug debug, const ZigbeeAdapter &adapter);
#endif // ZIGBEEADAPTER_H

View File

@ -30,7 +30,7 @@
ZigbeeBridgeController::ZigbeeBridgeController(QObject *parent) : QObject(parent) ZigbeeBridgeController::ZigbeeBridgeController(QObject *parent) : QObject(parent)
{ {
qRegisterMetaType<QSerialPort::SerialPortError>();
} }
QString ZigbeeBridgeController::firmwareVersion() const QString ZigbeeBridgeController::firmwareVersion() const

View File

@ -29,6 +29,7 @@
#include "zigbeenetwork.h" #include "zigbeenetwork.h"
#include "loggingcategory.h" #include "loggingcategory.h"
#include "zdo/zigbeedeviceprofile.h" #include "zdo/zigbeedeviceprofile.h"
#include "zigbeebridgecontroller.h"
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>

View File

@ -38,9 +38,10 @@
#include "zigbeechannelmask.h" #include "zigbeechannelmask.h"
#include "zigbeenodeendpoint.h" #include "zigbeenodeendpoint.h"
#include "zigbeenetworkdatabase.h" #include "zigbeenetworkdatabase.h"
#include "zigbeebridgecontroller.h"
#include "zigbeesecurityconfiguration.h" #include "zigbeesecurityconfiguration.h"
class ZigbeeBridgeController;
class ZigbeeNetwork : public QObject class ZigbeeNetwork : public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@ -32,21 +32,73 @@
#include "backends/deconz/zigbeenetworkdeconz.h" #include "backends/deconz/zigbeenetworkdeconz.h"
#include <QDateTime> #include <QDateTime>
#include <QSerialPortInfo>
QList<ZigbeeAdapter> ZigbeeNetworkManager::availableAdapters()
{
QList<ZigbeeAdapter> adapters;
qCDebug(dcZigbeeNetwork()) << "Loading available adapters" ;
foreach (const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()) {
qCDebug(dcZigbeeNetwork()) << "Adapter candidate" << serialPortInfo.portName();
qCDebug(dcZigbeeNetwork()) << " Description:" << serialPortInfo.description();
qCDebug(dcZigbeeNetwork()) << " System location:" << serialPortInfo.systemLocation();
qCDebug(dcZigbeeNetwork()) << " Manufacturer:" << serialPortInfo.manufacturer();
qCDebug(dcZigbeeNetwork()) << " Serialnumber:" << serialPortInfo.serialNumber();
if (serialPortInfo.hasProductIdentifier()) {
qCDebug(dcZigbeeNetwork()) << " Product identifier:" << serialPortInfo.productIdentifier();
}
if (serialPortInfo.hasVendorIdentifier()) {
qCDebug(dcZigbeeNetwork()) << " Vendor identifier:" << serialPortInfo.vendorIdentifier();
}
// Check if we recognize this controller
ZigbeeAdapter adapter;
if (serialPortInfo.portName().isEmpty()) {
adapter.setName("Zigbee adapter");
} else {
adapter.setName(serialPortInfo.portName());
}
if (serialPortInfo.description().isEmpty()) {
adapter.setDescription("Unknown");
} else {
adapter.setDescription(serialPortInfo.description());
}
adapter.setSystemLocation(serialPortInfo.systemLocation());
// Check if we recognize this adapter from USB information
if (serialPortInfo.manufacturer().toLower().contains("dresden elektronik")) {
adapter.setBackendSuggestionAvailable(true);
adapter.setSuggestedBackendType(Zigbee::BackendTypeDeconz);
adapter.setSuggestedBaudRate(38400);
} else if (serialPortInfo.manufacturer().toLower().contains("nxp")) {
adapter.setBackendSuggestionAvailable(true);
adapter.setSuggestedBackendType(Zigbee::BackendTypeNxp);
adapter.setSuggestedBaudRate(115200);
}
adapters.append(adapter);
}
return adapters;
}
QStringList ZigbeeNetworkManager::availableBackendTypes() QStringList ZigbeeNetworkManager::availableBackendTypes()
{ {
return {"deCONZ", "NXP"}; return {"deCONZ", "NXP"};
} }
ZigbeeNetwork *ZigbeeNetworkManager::createZigbeeNetwork(ZigbeeNetworkManager::BackendType backend, QObject *parent) ZigbeeNetwork *ZigbeeNetworkManager::createZigbeeNetwork(Zigbee::BackendType backend, QObject *parent)
{ {
// Note: required for generating random PAN ID // Note: required for generating random PAN ID
srand(static_cast<uint>(QDateTime::currentMSecsSinceEpoch() / 1000)); srand(static_cast<uint>(QDateTime::currentMSecsSinceEpoch() / 1000));
switch (backend) { switch (backend) {
case BackendTypeNxp: case Zigbee::BackendTypeNxp:
return qobject_cast<ZigbeeNetwork *>(new ZigbeeNetworkNxp(parent)); return qobject_cast<ZigbeeNetwork *>(new ZigbeeNetworkNxp(parent));
case BackendTypeDeconz: case Zigbee::BackendTypeDeconz:
return qobject_cast<ZigbeeNetwork *>(new ZigbeeNetworkDeconz(parent)); return qobject_cast<ZigbeeNetwork *>(new ZigbeeNetworkDeconz(parent));
} }

View File

@ -30,20 +30,16 @@
#include <QObject> #include <QObject>
#include "zigbeeadapter.h"
#include "zigbeenetwork.h" #include "zigbeenetwork.h"
class ZigbeeNetworkManager class ZigbeeNetworkManager
{ {
Q_GADGET Q_GADGET
public: public:
enum BackendType { static QList<ZigbeeAdapter> availableAdapters();
BackendTypeDeconz,
BackendTypeNxp
};
Q_ENUM(BackendType)
static QStringList availableBackendTypes(); static QStringList availableBackendTypes();
static ZigbeeNetwork *createZigbeeNetwork(BackendType backend, QObject *parent = nullptr); static ZigbeeNetwork *createZigbeeNetwork(Zigbee::BackendType backend, QObject *parent = nullptr);
}; };
Q_DECLARE_METATYPE(ZigbeeNetworkManager) Q_DECLARE_METATYPE(ZigbeeNetworkManager)