Remove node initializer since init process will be handled by the plugins
This commit is contained in:
parent
8749789322
commit
66dbcc03af
@ -131,8 +131,7 @@ HEADERS += nymeacore.h \
|
|||||||
platform/platform.h \
|
platform/platform.h \
|
||||||
zigbee/zigbeeadapter.h \
|
zigbee/zigbeeadapter.h \
|
||||||
zigbee/zigbeeadapters.h \
|
zigbee/zigbeeadapters.h \
|
||||||
zigbee/zigbeemanager.h \
|
zigbee/zigbeemanager.h
|
||||||
zigbee/zigbeenodeinitializer.h
|
|
||||||
|
|
||||||
|
|
||||||
SOURCES += nymeacore.cpp \
|
SOURCES += nymeacore.cpp \
|
||||||
@ -219,8 +218,7 @@ SOURCES += nymeacore.cpp \
|
|||||||
platform/platform.cpp \
|
platform/platform.cpp \
|
||||||
zigbee/zigbeeadapter.cpp \
|
zigbee/zigbeeadapter.cpp \
|
||||||
zigbee/zigbeeadapters.cpp \
|
zigbee/zigbeeadapters.cpp \
|
||||||
zigbee/zigbeemanager.cpp \
|
zigbee/zigbeemanager.cpp
|
||||||
zigbee/zigbeenodeinitializer.cpp
|
|
||||||
|
|
||||||
|
|
||||||
versionAtLeast(QT_VERSION, 5.12.0) {
|
versionAtLeast(QT_VERSION, 5.12.0) {
|
||||||
|
|||||||
@ -474,11 +474,6 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ZigbeeNodeInitializer *nodeInitializer = m_zigbeeNodeInitializers.value(network->networkUuid());
|
|
||||||
// nodeInitializer->initializeNode(node);
|
|
||||||
//TODO: emit node added once initialized so the plugins can use it
|
|
||||||
|
|
||||||
emit nodeAdded(network->networkUuid(), node);
|
emit nodeAdded(network->networkUuid(), node);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -499,13 +494,6 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network)
|
|||||||
m_zigbeeNetworks.insert(network->networkUuid(), network);
|
m_zigbeeNetworks.insert(network->networkUuid(), network);
|
||||||
emit zigbeeNetworkAdded(network);
|
emit zigbeeNetworkAdded(network);
|
||||||
|
|
||||||
// Create node initializer when a new node joins the network
|
|
||||||
ZigbeeNodeInitializer *nodeInitializer = new ZigbeeNodeInitializer(network, this);
|
|
||||||
connect(nodeInitializer, &ZigbeeNodeInitializer::nodeInitialized, this, [this, network](ZigbeeNode *node){
|
|
||||||
qCDebug(dcZigbee()) << "Node initialied from nymea" << node;
|
|
||||||
emit nodeAdded(network->networkUuid(), node);
|
|
||||||
});
|
|
||||||
|
|
||||||
qCDebug(dcZigbee()) << "Network added" << network;
|
qCDebug(dcZigbee()) << "Network added" << network;
|
||||||
foreach (ZigbeeNode *node, network->nodes()) {
|
foreach (ZigbeeNode *node, network->nodes()) {
|
||||||
qCDebug(dcZigbee()) << "-->" << node;
|
qCDebug(dcZigbee()) << "-->" << node;
|
||||||
@ -533,8 +521,6 @@ void ZigbeeManager::addNetwork(ZigbeeNetwork *network)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_zigbeeNodeInitializers.insert(network->networkUuid(), nodeInitializer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZigbeeAdapter ZigbeeManager::convertUartAdapterToAdapter(const ZigbeeUartAdapter &uartAdapter)
|
ZigbeeAdapter ZigbeeManager::convertUartAdapterToAdapter(const ZigbeeUartAdapter &uartAdapter)
|
||||||
|
|||||||
@ -37,7 +37,6 @@
|
|||||||
#include <zigbeeuartadaptermonitor.h>
|
#include <zigbeeuartadaptermonitor.h>
|
||||||
|
|
||||||
#include "zigbeeadapters.h"
|
#include "zigbeeadapters.h"
|
||||||
#include "zigbeenodeinitializer.h"
|
|
||||||
|
|
||||||
namespace nymeaserver {
|
namespace nymeaserver {
|
||||||
|
|
||||||
@ -82,7 +81,6 @@ private:
|
|||||||
ZigbeeAdapters m_adapters;
|
ZigbeeAdapters m_adapters;
|
||||||
ZigbeeUartAdapterMonitor *m_adapterMonitor = nullptr;
|
ZigbeeUartAdapterMonitor *m_adapterMonitor = nullptr;
|
||||||
QHash<QUuid, ZigbeeNetwork *> m_zigbeeNetworks;
|
QHash<QUuid, ZigbeeNetwork *> m_zigbeeNetworks;
|
||||||
QHash<QUuid, ZigbeeNodeInitializer *> m_zigbeeNodeInitializers;
|
|
||||||
|
|
||||||
bool m_available = false;
|
bool m_available = false;
|
||||||
|
|
||||||
|
|||||||
@ -1,130 +0,0 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* 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 "zigbeenodeinitializer.h"
|
|
||||||
#include "loggingcategories.h"
|
|
||||||
|
|
||||||
#include <zigbeenetwork.h>
|
|
||||||
|
|
||||||
Q_DECLARE_LOGGING_CATEGORY(dcZigbee)
|
|
||||||
|
|
||||||
ZigbeeNodeInitializer::ZigbeeNodeInitializer(ZigbeeNetwork *network, QObject *parent) :
|
|
||||||
QObject(parent),
|
|
||||||
m_network(network)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZigbeeNodeInitializer::initializeNode(ZigbeeNode *node)
|
|
||||||
{
|
|
||||||
qCDebug(dcZigbee()) << "Start initializing node internally" << node;
|
|
||||||
|
|
||||||
// Bind the coordinator to group 0x0000
|
|
||||||
//m_network->coordinatorNode()->deviceObject()->requestBindShortAddress(0x01, ZigbeeClusterLibrary::ClusterIdOnOff, 0x0000);
|
|
||||||
|
|
||||||
// Initialize and configure server clusters
|
|
||||||
foreach (ZigbeeNodeEndpoint *endpoint, node->endpoints()) {
|
|
||||||
// Configure attribute reporting
|
|
||||||
if (endpoint->hasInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)) {
|
|
||||||
|
|
||||||
// Read current battery remaining
|
|
||||||
qCDebug(dcZigbee()) << "Read power configuration cluster attributes" << node;
|
|
||||||
ZigbeeClusterReply *readAttributeReply = endpoint->getInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)->readAttributes({ZigbeeClusterPowerConfiguration::AttributeBatteryPercentageRemaining});
|
|
||||||
connect(readAttributeReply, &ZigbeeClusterReply::finished, node, [=](){
|
|
||||||
if (readAttributeReply->error() != ZigbeeClusterReply::ErrorNoError) {
|
|
||||||
qCWarning(dcZigbee()) << "Failed to read power cluster attributes" << readAttributeReply->error();
|
|
||||||
//emit nodeInitialized(node);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
qCDebug(dcZigbee()) << "Read power configuration cluster attributes finished successfully";
|
|
||||||
|
|
||||||
// Bind the cluster to the coordinator
|
|
||||||
qCDebug(dcZigbee()) << "Bind power configuration cluster to coordinaotr";
|
|
||||||
ZigbeeDeviceObjectReply * zdoReply = node->deviceObject()->requestBindIeeeAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdPowerConfiguration, m_network->coordinatorNode()->extendedAddress(), 0x01);
|
|
||||||
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, node, [=](){
|
|
||||||
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
|
|
||||||
qCWarning(dcZigbee()) << "Failed to bind power cluster to coordinator" << readAttributeReply->error();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
qCDebug(dcZigbee()) << "Bind power configuration cluster to coordinaotr finished successfully";
|
|
||||||
|
|
||||||
// Configure attribute rporting for battery remaining
|
|
||||||
ZigbeeClusterLibrary::AttributeReportingConfiguration reportingConfig;
|
|
||||||
reportingConfig.attributeId = ZigbeeClusterPowerConfiguration::AttributeBatteryPercentageRemaining;
|
|
||||||
reportingConfig.dataType = Zigbee::Uint8;
|
|
||||||
reportingConfig.minReportingInterval = 300;
|
|
||||||
reportingConfig.maxReportingInterval = 2700;
|
|
||||||
reportingConfig.reportableChange = ZigbeeDataType(static_cast<quint8>(14)).data();
|
|
||||||
|
|
||||||
qCDebug(dcZigbee()) << "Configure attribute reporting for power configuration cluster to coordinator";
|
|
||||||
ZigbeeClusterReply *reportingReply = endpoint->getInputCluster(ZigbeeClusterLibrary::ClusterIdPowerConfiguration)->configureReporting({reportingConfig});
|
|
||||||
connect(reportingReply, &ZigbeeClusterReply::finished, this, [reportingReply](){
|
|
||||||
if (reportingReply->error() != ZigbeeClusterReply::ErrorNoError) {
|
|
||||||
qCWarning(dcZigbee()) << "Failed to read power cluster attributes" << reportingReply->error();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
qCDebug(dcZigbee()) << "Reporting config finished" << ZigbeeClusterLibrary::parseAttributeReportingStatusRecords(reportingReply->responseFrame().payload);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Initialize and configure client clusters
|
|
||||||
foreach (ZigbeeNodeEndpoint *endpoint, node->endpoints()) {
|
|
||||||
|
|
||||||
if (endpoint->hasOutputCluster(ZigbeeClusterLibrary::ClusterIdOnOff)) {
|
|
||||||
// Bind command
|
|
||||||
ZigbeeDeviceObjectReply *zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdOnOff, m_network->coordinatorNode()->shortAddress());
|
|
||||||
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, this, [zdoReply](){
|
|
||||||
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
|
|
||||||
qCWarning(dcZigbee()) << "Failed to bind OnOff cluster attributes" << zdoReply->error();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (endpoint->hasOutputCluster(ZigbeeClusterLibrary::ClusterIdLevelControl)) {
|
|
||||||
// Bind command
|
|
||||||
ZigbeeDeviceObjectReply *zdoReply = node->deviceObject()->requestBindShortAddress(endpoint->endpointId(), ZigbeeClusterLibrary::ClusterIdLevelControl, m_network->coordinatorNode()->shortAddress());
|
|
||||||
connect(zdoReply, &ZigbeeDeviceObjectReply::finished, this, [this, node, zdoReply](){
|
|
||||||
if (zdoReply->error() != ZigbeeDeviceObjectReply::ErrorNoError) {
|
|
||||||
qCWarning(dcZigbee()) << "Failed to bind Level cluster attributes" << zdoReply->error();
|
|
||||||
//emit nodeInitialized(node);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//emit nodeInitialized(node);
|
|
||||||
}
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*
|
|
||||||
* 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 ZIGBEENODEINITIALIZER_H
|
|
||||||
#define ZIGBEENODEINITIALIZER_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class ZigbeeNode;
|
|
||||||
class ZigbeeNetwork;
|
|
||||||
|
|
||||||
class ZigbeeNodeInitializer : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit ZigbeeNodeInitializer(ZigbeeNetwork *network, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
void initializeNode(ZigbeeNode *node);
|
|
||||||
|
|
||||||
private:
|
|
||||||
ZigbeeNetwork *m_network = nullptr;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void nodeInitialized(ZigbeeNode *node);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // ZIGBEENODEINITIALIZER_H
|
|
||||||
Reference in New Issue
Block a user