-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #204: Webasto: Update to networkdevice interface
- Loading branch information
Showing
7 changed files
with
273 additions
and
156 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* | ||
* Copyright 2013 - 2023, nymea GmbH | ||
* Copyright 2013 - 2024, nymea GmbH | ||
* Contact: [email protected] | ||
* | ||
* This file is part of nymea. | ||
|
@@ -69,6 +69,7 @@ class IntegrationPluginWebasto : public IntegrationPlugin | |
QHash<Thing *, Webasto *> m_webastoLiveConnections; | ||
QHash<Thing *, WebastoNextModbusTcpConnection *> m_webastoNextConnections; | ||
QHash<Thing *, EVC04ModbusTcpConnection *> m_evc04Connections; | ||
|
||
QHash<Thing *, NetworkDeviceMonitor *> m_monitors; | ||
|
||
void setupWebastoNextConnection(ThingSetupInfo *info); | ||
|
@@ -88,7 +89,6 @@ class IntegrationPluginWebasto : public IntegrationPlugin | |
void executeWebastoUnitePhaseCountAction(ThingActionInfo *info); | ||
|
||
private slots: | ||
void onConnectionChanged(bool connected); | ||
void onWriteRequestExecuted(const QUuid &requestId, bool success); | ||
void onWriteRequestError(const QUuid &requestId, const QString &error); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* | ||
* Copyright 2013 - 2023, nymea GmbH | ||
* Copyright 2013 - 2024, nymea GmbH | ||
* Contact: [email protected] | ||
* | ||
* This file is part of nymea. | ||
|
@@ -40,21 +40,24 @@ WebastoDiscovery::WebastoDiscovery(NetworkDeviceDiscovery *networkDeviceDiscover | |
|
||
void WebastoDiscovery::startDiscovery() | ||
{ | ||
// TODO: add parameter for searching WebastoNext or WebastoLive, for now the discovery searches only for WebastoNext | ||
|
||
// TODO: add parameter for searching WebastoNext or WebastoLive, for now the discovery searches only for WebastoNext | ||
qCInfo(dcWebasto()) << "Discovery: Starting to search for WebastoNext wallboxes in the network..."; | ||
m_startDateTime = QDateTime::currentDateTime(); | ||
|
||
qCInfo(dcWebasto()) << "Discovery: Starting to search for WebastoNext wallboxes in the network..."; | ||
m_networkDeviceInfos.clear(); | ||
m_temporaryResults.clear(); | ||
m_results.clear(); | ||
|
||
NetworkDeviceDiscoveryReply *discoveryReply = m_networkDeviceDiscovery->discover(); | ||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::networkDeviceInfoAdded, this, &WebastoDiscovery::checkNetworkDevice); | ||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::hostAddressDiscovered, this, &WebastoDiscovery::checkNetworkDevice); | ||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); | ||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ | ||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [this, discoveryReply](){ | ||
qCDebug(dcWebasto()) << "Discovery: Network discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "network devices"; | ||
m_networkDeviceInfos = discoveryReply->networkDeviceInfos(); | ||
|
||
// Give the last connections added right before the network discovery finished a chance to check the device... | ||
QTimer::singleShot(3000, this, [this](){ | ||
qCDebug(dcWebasto()) << "Discovery: Grace period timer triggered."; | ||
finishDiscovery(); | ||
}); | ||
QTimer::singleShot(3000, this, &WebastoDiscovery::finishDiscovery); | ||
}); | ||
} | ||
|
||
|
@@ -63,9 +66,9 @@ QList<WebastoDiscovery::Result> WebastoDiscovery::results() const | |
return m_results; | ||
} | ||
|
||
void WebastoDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo) | ||
void WebastoDiscovery::checkNetworkDevice(const QHostAddress &address) | ||
{ | ||
WebastoNextModbusTcpConnection *connection = new WebastoNextModbusTcpConnection(networkDeviceInfo.address(), 502, 1, this); | ||
WebastoNextModbusTcpConnection *connection = new WebastoNextModbusTcpConnection(address, 502, 1, this); | ||
m_connections.append(connection); | ||
|
||
connect(connection, &WebastoNextModbusTcpConnection::reachableChanged, this, [=](bool reachable){ | ||
|
@@ -77,7 +80,7 @@ void WebastoDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevice | |
|
||
// Read some well known registers to verify if the register exist and make sense... | ||
QModbusReply *reply = connection->readCableState(); | ||
connect(reply, &QModbusReply::finished, this, [=](){ | ||
connect(reply, &QModbusReply::finished, this, [this, reply, connection, address](){ | ||
|
||
reply->deleteLater(); | ||
|
||
|
@@ -92,12 +95,12 @@ void WebastoDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevice | |
quint16 rawValue = ModbusDataUtils::convertToUInt16(unit.values()); | ||
QMetaEnum valueEnum = WebastoNextModbusTcpConnection::staticMetaObject.enumerator(WebastoNextModbusTcpConnection::staticMetaObject.indexOfEnumerator("CableState")); | ||
if (!valueEnum.valueToKey(rawValue)) { | ||
qCDebug(dcWebasto()) << "Discovery: invalid enum value for cable state on connection on" << networkDeviceInfo.address().toString() << "Continue...";; | ||
qCDebug(dcWebasto()) << "Discovery: invalid enum value for cable state on connection on" << address.toString() << "Continue...";; | ||
cleanupConnection(connection); | ||
} | ||
|
||
QModbusReply *reply = connection->readChargerState(); | ||
connect(reply, &QModbusReply::finished, this, [=](){ | ||
connect(reply, &QModbusReply::finished, this, [this, reply, connection, address](){ | ||
|
||
reply->deleteLater(); | ||
|
||
|
@@ -112,15 +115,14 @@ void WebastoDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevice | |
quint16 rawValue = ModbusDataUtils::convertToUInt16(unit.values()); | ||
QMetaEnum valueEnum = WebastoNextModbusTcpConnection::staticMetaObject.enumerator(WebastoNextModbusTcpConnection::staticMetaObject.indexOfEnumerator("ChargerState")); | ||
if (!valueEnum.valueToKey(rawValue)) { | ||
qCDebug(dcWebasto()) << "Discovery: invalid enum value for charger state on connection on" << networkDeviceInfo.address().toString() << "Continue...";; | ||
qCDebug(dcWebasto()) << "Discovery: invalid enum value for charger state on connection on" << address.toString() << "Continue...";; | ||
cleanupConnection(connection); | ||
} | ||
|
||
|
||
// Read some registers distributed over the range... | ||
|
||
QModbusReply *reply = connection->readTotalActivePower(); | ||
connect(reply, &QModbusReply::finished, this, [=](){ | ||
connect(reply, &QModbusReply::finished, this, [this, reply, connection, address](){ | ||
|
||
reply->deleteLater(); | ||
|
||
|
@@ -143,28 +145,13 @@ void WebastoDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevice | |
|
||
// All values good so far, let's assume this is a Webasto NEXT | ||
|
||
// Final check if there is a hostname available for this network device, if so it shouls contain the string "NEXT_". | ||
// This is neccessary since Wallboxes from Vestel EVC04 aka. Webasto Unite wallboxes would also match | ||
// the creteria up to here get detected as positiv Webasto NEXT. | ||
|
||
// Example hostname: NEXT-WS10XXXX | ||
|
||
if (!networkDeviceInfo.hostName().isEmpty() && | ||
(!networkDeviceInfo.hostName().contains("NEXT_") || networkDeviceInfo.hostName().contains("VESTEL"))) { | ||
qCDebug(dcWebasto()) << "Discovery: network device has a hostname and it does match kriteria for Webasto next:" << networkDeviceInfo.hostName() << "on" << networkDeviceInfo.address().toString() << "Continue...";; | ||
cleanupConnection(connection); | ||
return; | ||
} | ||
|
||
// Hostname verification also OK, let's assume this is a Webasto NEXT | ||
// The final check regarding the hostname will be done when all network device infos are available in the finishDiscovery slot | ||
|
||
Result result; | ||
result.productName = "Webasto NEXT"; | ||
result.type = TypeWebastoNext; | ||
result.networkDeviceInfo = networkDeviceInfo; | ||
m_results.append(result); | ||
|
||
qCDebug(dcWebasto()) << "Discovery: --> Found" << result.productName << result.networkDeviceInfo; | ||
result.address = address; | ||
m_temporaryResults.append(result); | ||
|
||
// Done with this connection | ||
cleanupConnection(connection); | ||
|
@@ -177,14 +164,14 @@ void WebastoDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevice | |
// If we get any error...skip this host... | ||
connect(connection->modbusTcpMaster(), &ModbusTcpMaster::connectionErrorOccurred, this, [=](QModbusDevice::Error error){ | ||
if (error != QModbusDevice::NoError) { | ||
qCDebug(dcWebasto()) << "Discovery: Connection error on" << networkDeviceInfo.address().toString() << "Continue...";; | ||
qCDebug(dcWebasto()) << "Discovery: Connection error on" << address.toString() << "Continue...";; | ||
cleanupConnection(connection); | ||
} | ||
}); | ||
|
||
// If check reachability failed...skip this host... | ||
connect(connection, &WebastoNextModbusTcpConnection::checkReachabilityFailed, this, [=](){ | ||
qCDebug(dcWebasto()) << "Discovery: Check reachability failed on" << networkDeviceInfo.address().toString() << "Continue...";; | ||
qCDebug(dcWebasto()) << "Discovery: Check reachability failed on" << address.toString() << "Continue...";; | ||
cleanupConnection(connection); | ||
}); | ||
|
||
|
@@ -203,6 +190,27 @@ void WebastoDiscovery::finishDiscovery() | |
{ | ||
qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch() - m_startDateTime.toMSecsSinceEpoch(); | ||
|
||
for (int i = 0; i < m_temporaryResults.count(); i++) { | ||
// Fill in all network device infos we have | ||
m_temporaryResults[i].networkDeviceInfo = m_networkDeviceInfos.get(m_temporaryResults.at(i).address); | ||
|
||
// Final check if there is a hostname available for this network device, if so it shouls contain the string "NEXT_". | ||
// This is neccessary since Wallboxes from Vestel EVC04 aka. Webasto Unite wallboxes would also match | ||
// the creteria up to here get detected as positiv Webasto NEXT. | ||
|
||
// Example hostname: NEXT-WS10XXXX | ||
QString hostName = m_temporaryResults.at(i).networkDeviceInfo.hostName(); | ||
if (!hostName.isEmpty() && (!hostName.contains("NEXT_") || hostName.contains("VESTEL"))) { | ||
qCDebug(dcWebasto()) << "Discovery: network device has a hostname and it does match kriteria for Webasto next:" << hostName << "on" << m_temporaryResults.at(i).networkDeviceInfo.address().toString() << "Continue...";; | ||
continue; | ||
} | ||
|
||
// Hostname verification also OK, let's assume this is a Webasto NEXT | ||
|
||
qCDebug(dcWebasto()) << "Discovery: --> Found" << m_temporaryResults.at(i).productName << m_temporaryResults.at(i).networkDeviceInfo; | ||
m_results.append(m_temporaryResults.at(i)); | ||
} | ||
|
||
// Cleanup any leftovers...we don't care any more | ||
foreach (WebastoNextModbusTcpConnection *connection, m_connections) | ||
cleanupConnection(connection); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* | ||
* Copyright 2013 - 2023, nymea GmbH | ||
* Copyright 2013 - 2024, nymea GmbH | ||
* Contact: [email protected] | ||
* | ||
* This file is part of nymea. | ||
|
@@ -34,7 +34,6 @@ | |
#include <QObject> | ||
|
||
#include <network/networkdevicediscovery.h> | ||
|
||
#include "webastonextmodbustcpconnection.h" | ||
|
||
class WebastoDiscovery : public QObject | ||
|
@@ -50,6 +49,7 @@ class WebastoDiscovery : public QObject | |
typedef struct Result { | ||
QString productName; | ||
Type type; | ||
QHostAddress address; | ||
NetworkDeviceInfo networkDeviceInfo; | ||
} Result; | ||
|
||
|
@@ -64,14 +64,14 @@ class WebastoDiscovery : public QObject | |
|
||
private: | ||
NetworkDeviceDiscovery *m_networkDeviceDiscovery = nullptr; | ||
QDateTime m_startDateTime; | ||
|
||
NetworkDeviceInfos m_networkDeviceInfos; | ||
QList<WebastoNextModbusTcpConnection *> m_connections; | ||
|
||
QList<Result> m_temporaryResults; | ||
QList<Result> m_results; | ||
|
||
QDateTime m_startDateTime; | ||
|
||
void checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo); | ||
void checkNetworkDevice(const QHostAddress &address); | ||
void cleanupConnection(WebastoNextModbusTcpConnection *connection); | ||
|
||
void finishDiscovery(); | ||
|