From 7ebe5933794f828aab8832417896ae209ca66404 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sat, 15 Oct 2022 00:46:05 +0200 Subject: [PATCH] Register the OTA server cluster on the TI backend This is required by some devices (at least Tradfri) in order to query us for images. --- .../backends/ti/zigbeebridgecontrollerti.cpp | 14 +++++++++----- .../backends/ti/zigbeebridgecontrollerti.h | 2 +- libnymea-zigbee/backends/ti/zigbeenetworkti.cpp | 16 ++++++++++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/libnymea-zigbee/backends/ti/zigbeebridgecontrollerti.cpp b/libnymea-zigbee/backends/ti/zigbeebridgecontrollerti.cpp index 86666b8..8ea6679 100644 --- a/libnymea-zigbee/backends/ti/zigbeebridgecontrollerti.cpp +++ b/libnymea-zigbee/backends/ti/zigbeebridgecontrollerti.cpp @@ -605,7 +605,7 @@ ZigbeeInterfaceTiReply *ZigbeeBridgeControllerTi::start() return sendCommand(Ti::SubSystemZDO, Ti::ZDOCommandStartupFromApp, payload); } -ZigbeeInterfaceTiReply *ZigbeeBridgeControllerTi::registerEndpoint(quint8 endpointId, Zigbee::ZigbeeProfile profile, quint16 deviceId, quint8 deviceVersion) +ZigbeeInterfaceTiReply *ZigbeeBridgeControllerTi::registerEndpoint(quint8 endpointId, Zigbee::ZigbeeProfile profile, quint16 deviceId, quint8 deviceVersion, const QList &inputClusters, const QList &outputClusters) { if (m_registeredEndpointIds.contains(endpointId)) { ZigbeeInterfaceTiReply *reply = new ZigbeeInterfaceTiReply(this); @@ -621,10 +621,14 @@ ZigbeeInterfaceTiReply *ZigbeeBridgeControllerTi::registerEndpoint(quint8 endpoi stream << deviceId; stream << deviceVersion; stream << static_cast(0x00); // latency requirement - stream << static_cast(0x00); // num input clusters -// stream << static_cast(0x0000); // input clusters - stream << static_cast(0x00); // num outout clusters -// stream << static_cast(0x0000); // output clusters + stream << static_cast(inputClusters.count()); + foreach (quint16 inputCluster, inputClusters) { + stream << inputCluster; + } + stream << static_cast(outputClusters.count()); + foreach (quint16 outputCluster, outputClusters) { + stream << static_cast(outputCluster); + } ZigbeeInterfaceTiReply *reply = sendCommand(Ti::SubSystemAF, Ti::AFCommandRegister, payload); diff --git a/libnymea-zigbee/backends/ti/zigbeebridgecontrollerti.h b/libnymea-zigbee/backends/ti/zigbeebridgecontrollerti.h index ecb410a..afdaa12 100644 --- a/libnymea-zigbee/backends/ti/zigbeebridgecontrollerti.h +++ b/libnymea-zigbee/backends/ti/zigbeebridgecontrollerti.h @@ -87,7 +87,7 @@ public: ZigbeeInterfaceTiReply *setLed(bool on); ZigbeeInterfaceTiReply *requestPermitJoin(quint8 seconds, const quint16 &networkAddress); - ZigbeeInterfaceTiReply *registerEndpoint(quint8 endpointId, Zigbee::ZigbeeProfile profile, quint16 deviceId, quint8 deviceVersion); + ZigbeeInterfaceTiReply *registerEndpoint(quint8 endpointId, Zigbee::ZigbeeProfile profile, quint16 deviceId, quint8 deviceVersion, const QList &inputClusters = QList(), const QList &outputClusters = QList()); ZigbeeInterfaceTiReply *addEndpointToGroup(quint8 endpointId, quint16 groupId); // Send APS request data diff --git a/libnymea-zigbee/backends/ti/zigbeenetworkti.cpp b/libnymea-zigbee/backends/ti/zigbeenetworkti.cpp index 8439507..3ec2975 100644 --- a/libnymea-zigbee/backends/ti/zigbeenetworkti.cpp +++ b/libnymea-zigbee/backends/ti/zigbeenetworkti.cpp @@ -382,7 +382,7 @@ void ZigbeeNetworkTi::onControllerStateChanged(ZigbeeBridgeControllerTi::Control // TODO: This should be public API of libnymea-zigbee so that the application layer (e.g. nymea-plugins) // can register the endpoints it needs for the particular application/device. // Fow now we're registering HomeAutomation, LightLink and GreenPower endpoints. - m_controller->registerEndpoint(1, Zigbee::ZigbeeProfileHomeAutomation, 5, 0); + m_controller->registerEndpoint(1, Zigbee::ZigbeeProfileHomeAutomation, 5, 0, {ZigbeeClusterLibrary::ClusterIdOtaUpgrade}); m_controller->registerEndpoint(12, Zigbee::ZigbeeProfileLightLink, 5, 0); // The Green Power endpoing is a bit special, it also needs to be added to a group @@ -411,14 +411,22 @@ void ZigbeeNetworkTi::onControllerStateChanged(ZigbeeBridgeControllerTi::Control m_coordinatorNode = coordinatorNode; addUnitializedNode(coordinatorNode); } - // Introspecing ourselves on every start. Most of the times this wouldn't be needed, but if the above - // endpoints are changed (e.g. on a future upgrade), we'll want to refresh. - m_coordinatorNode->startInitialization(); + ZigbeeInterfaceTiReply *ledReply = m_controller->setLed(false); connect(ledReply, &ZigbeeInterfaceTiReply::finished, this, [=]() { + setState(StateRunning); + // Introspecing ourselves on every start. Most of the times this wouldn't be needed, but if the above + // endpoints are changed (e.g. on a future upgrade), we'll want to refresh. + m_coordinatorNode->startInitialization(); + connect(m_coordinatorNode, &ZigbeeNode::stateChanged, this, [=](ZigbeeNode::State state){ + if (state == ZigbeeNode::StateInitialized) { + setNodeInformation(m_coordinatorNode, "z-Stack", "", bridgeController()->firmwareVersion()); + } + }); + while (!m_requestQueue.isEmpty()) { ZigbeeNetworkReply *reply = m_requestQueue.takeFirst(); ZigbeeInterfaceTiReply *interfaceReply = m_controller->requestSendRequest(reply->request());