Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c2c063f

Browse files
author
jenkins
committedDec 19, 2024
Merge PR #193: Mennekes: Update to networkdevice interface
2 parents c729e73 + 9afe65d commit c2c063f

6 files changed

+187
-208
lines changed
 

‎mennekes/amtronecudiscovery.cpp

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
22
*
3-
* Copyright 2013 - 2023, nymea GmbH
3+
* Copyright 2013 - 2024, nymea GmbH
44
* Contact: contact@nymea.io
55
*
66
* This file is part of nymea.
@@ -50,12 +50,12 @@ void AmtronECUDiscovery::startDiscovery()
5050

5151
NetworkDeviceDiscoveryReply *discoveryReply = m_networkDeviceDiscovery->discover();
5252

53-
connect(discoveryReply, &NetworkDeviceDiscoveryReply::networkDeviceInfoAdded, this, &AmtronECUDiscovery::checkNetworkDevice);
54-
53+
connect(discoveryReply, &NetworkDeviceDiscoveryReply::hostAddressDiscovered, this, &AmtronECUDiscovery::checkNetworkDevice);
54+
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater);
5555
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
5656
qCDebug(dcMennekes()) << "Discovery: Network discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "network devices";
57+
m_networkDeviceInfos = discoveryReply->networkDeviceInfos();
5758
m_gracePeriodTimer.start();
58-
discoveryReply->deleteLater();
5959
});
6060
}
6161

@@ -64,24 +64,24 @@ QList<AmtronECUDiscovery::Result> AmtronECUDiscovery::discoveryResults() const
6464
return m_discoveryResults;
6565
}
6666

67-
void AmtronECUDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo)
67+
void AmtronECUDiscovery::checkNetworkDevice(const QHostAddress &address)
6868
{
6969
int port = 502;
7070
int slaveId = 0xff;
71-
qCDebug(dcMennekes()) << "Discovery: Checking network device:" << networkDeviceInfo << "Port:" << port << "Slave ID:" << slaveId;
71+
qCDebug(dcMennekes()) << "Discovery: Checking network device:" << address.toString() << "Port:" << port << "Slave ID:" << slaveId;
7272

73-
AmtronECU *connection = new AmtronECU(networkDeviceInfo.address(), port, slaveId, this);
73+
AmtronECU *connection = new AmtronECU(address, port, slaveId, this);
7474
m_connections.append(connection);
7575

76-
connect(connection, &AmtronECU::reachableChanged, this, [=](bool reachable){
76+
connect(connection, &AmtronECU::reachableChanged, this, [this, connection, address](bool reachable){
7777
if (!reachable) {
7878
cleanupConnection(connection);
7979
return;
8080
}
8181

8282
connect(connection, &AmtronECU::initializationFinished, this, [=](bool success){
8383
if (!success) {
84-
qCDebug(dcMennekes()) << "Discovery: Initialization failed on" << networkDeviceInfo.address().toString();
84+
qCDebug(dcMennekes()) << "Discovery: Initialization failed on" << address.toString();
8585
cleanupConnection(connection);
8686
return;
8787
}
@@ -90,40 +90,40 @@ void AmtronECUDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevi
9090
result.detectedVersion = connection->detectedVersion();
9191
result.firmwareVersion = QString::fromUtf8(QByteArray::fromHex(QByteArray::number(connection->firmwareVersion(), 16)));
9292
result.model = connection->model();
93-
result.networkDeviceInfo = networkDeviceInfo;
93+
result.address = address;
9494

9595
// Note: the model is only known in firmware >= 5.22
9696
// Some useres have to stay on 5.12 due to calibration law which is not available on 5.22
9797
switch(connection->detectedVersion()) {
9898
case AmtronECU::VersionOld:
99-
qCDebug(dcMennekes()) << "Discovery: Found wallbox with old firmware version:" << result.firmwareVersion << result.networkDeviceInfo;
99+
qCDebug(dcMennekes()) << "Discovery: Found wallbox with old firmware version:" << result.firmwareVersion << address.toString();
100100
m_discoveryResults.append(result);
101101
break;
102102
case AmtronECU::VersionNew:
103103
if (connection->model().isEmpty()) {
104-
qCDebug(dcMennekes()) << "Discovery: Firmware version is >= 5.22 but the model could not be fetched. Skipping" << networkDeviceInfo.address();
104+
qCDebug(dcMennekes()) << "Discovery: Firmware version is >= 5.22 but the model could not be fetched. Skipping" << address.toString();
105105
break;
106106
}
107107

108108
qCDebug(dcMennekes()) << "Discovery: Found wallbox with new firmware version:" << result.model << result.firmwareVersion << result.networkDeviceInfo;
109109
m_discoveryResults.append(result);
110110
break;
111111
case AmtronECU::VersionUnknown:
112-
qCDebug(dcMennekes()) << "Discovery: Firmware version or model invalid. Skipping" << networkDeviceInfo.address();
112+
qCDebug(dcMennekes()) << "Discovery: Firmware version or model invalid. Skipping" << address.toString();
113113
break;
114114
}
115115

116116
cleanupConnection(connection);
117117
});
118118

119119
if (!connection->initialize()) {
120-
qCDebug(dcMennekes()) << "Discovery: Unable to initialize connection on" << networkDeviceInfo.address().toString();
120+
qCDebug(dcMennekes()) << "Discovery: Unable to initialize connection on" << address.toString();
121121
cleanupConnection(connection);
122122
}
123123
});
124124

125125
connect(connection, &AmtronECU::checkReachabilityFailed, this, [=](){
126-
qCDebug(dcMennekes()) << "Discovery: Checking reachability failed on" << networkDeviceInfo.address().toString();
126+
qCDebug(dcMennekes()) << "Discovery: Checking reachability failed on" << address.toString();
127127
cleanupConnection(connection);
128128
});
129129

@@ -141,6 +141,10 @@ void AmtronECUDiscovery::finishDiscovery()
141141
{
142142
qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch() - m_startDateTime.toMSecsSinceEpoch();
143143

144+
// Fill in all network device infos we have
145+
for (int i = 0; i < m_discoveryResults.count(); i++)
146+
m_discoveryResults[i].networkDeviceInfo = m_networkDeviceInfos.get(m_discoveryResults.at(i).address);
147+
144148
// Cleanup any leftovers...we don't care any more
145149
foreach (AmtronECU *connection, m_connections)
146150
cleanupConnection(connection);

‎mennekes/amtronecudiscovery.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
22
*
3-
* Copyright 2013 - 2023, nymea GmbH
3+
* Copyright 2013 - 2024, nymea GmbH
44
* Contact: contact@nymea.io
55
*
66
* This file is part of nymea.
@@ -42,14 +42,16 @@ class AmtronECUDiscovery : public QObject
4242
{
4343
Q_OBJECT
4444
public:
45-
explicit AmtronECUDiscovery(NetworkDeviceDiscovery *networkDeviceDiscovery, QObject *parent = nullptr);
4645
struct Result {
4746
AmtronECU::Version detectedVersion;
4847
QString firmwareVersion;
4948
QString model;
49+
QHostAddress address;
5050
NetworkDeviceInfo networkDeviceInfo;
5151
};
5252

53+
explicit AmtronECUDiscovery(NetworkDeviceDiscovery *networkDeviceDiscovery, QObject *parent = nullptr);
54+
5355
void startDiscovery();
5456

5557
QList<Result> discoveryResults() const;
@@ -59,15 +61,13 @@ class AmtronECUDiscovery : public QObject
5961

6062
private:
6163
NetworkDeviceDiscovery *m_networkDeviceDiscovery = nullptr;
62-
6364
QTimer m_gracePeriodTimer;
6465
QDateTime m_startDateTime;
65-
66+
NetworkDeviceInfos m_networkDeviceInfos;
6667
QList<AmtronECU *> m_connections;
67-
6868
QList<Result> m_discoveryResults;
6969

70-
void checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo);
70+
void checkNetworkDevice(const QHostAddress &address);
7171
void cleanupConnection(AmtronECU *connection);
7272

7373
void finishDiscovery();

‎mennekes/amtronhcc3discovery.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
22
*
3-
* Copyright 2013 - 2022, nymea GmbH
3+
* Copyright 2013 - 2024, nymea GmbH
44
* Contact: contact@nymea.io
55
*
66
* This file is part of nymea.
@@ -48,12 +48,12 @@ void AmtronHCC3Discovery::startDiscovery()
4848
qCInfo(dcMennekes()) << "Discovery: Searching for AMTRON wallboxes in the network...";
4949
NetworkDeviceDiscoveryReply *discoveryReply = m_networkDeviceDiscovery->discover();
5050

51-
connect(discoveryReply, &NetworkDeviceDiscoveryReply::networkDeviceInfoAdded, this, &AmtronHCC3Discovery::checkNetworkDevice);
52-
51+
connect(discoveryReply, &NetworkDeviceDiscoveryReply::hostAddressDiscovered, this, &AmtronHCC3Discovery::checkNetworkDevice);
52+
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater);
5353
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
5454
qCDebug(dcMennekes()) << "Discovery: Network discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "network devices";
55+
m_networkDeviceInfos = discoveryReply->networkDeviceInfos();
5556
m_gracePeriodTimer.start();
56-
discoveryReply->deleteLater();
5757
});
5858
}
5959

@@ -62,13 +62,13 @@ QList<AmtronHCC3Discovery::AmtronDiscoveryResult> AmtronHCC3Discovery::discovery
6262
return m_discoveryResults;
6363
}
6464

65-
void AmtronHCC3Discovery::checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo)
65+
void AmtronHCC3Discovery::checkNetworkDevice(const QHostAddress &address)
6666
{
6767
int port = 502;
6868
int slaveId = 0xff;
69-
qCDebug(dcMennekes()) << "Checking network device:" << networkDeviceInfo << "Port:" << port << "Slave ID:" << slaveId;
7069

71-
AmtronHCC3ModbusTcpConnection *connection = new AmtronHCC3ModbusTcpConnection(networkDeviceInfo.address(), port, slaveId, this);
70+
qCDebug(dcMennekes()) << "Checking network device:" << address << "Port:" << port << "Slave ID:" << slaveId;
71+
AmtronHCC3ModbusTcpConnection *connection = new AmtronHCC3ModbusTcpConnection(address, port, slaveId, this);
7272
m_connections.append(connection);
7373

7474
connect(connection, &AmtronHCC3ModbusTcpConnection::reachableChanged, this, [=](bool reachable){
@@ -81,40 +81,39 @@ void AmtronHCC3Discovery::checkNetworkDevice(const NetworkDeviceInfo &networkDev
8181
// Modbus TCP connected...ok, let's try to initialize it!
8282
connect(connection, &AmtronHCC3ModbusTcpConnection::initializationFinished, this, [=](bool success){
8383
if (!success) {
84-
qCDebug(dcMennekes()) << "Discovery: Initialization failed on" << networkDeviceInfo.address().toString();
84+
qCDebug(dcMennekes()) << "Discovery: Initialization failed on" << address.toString();
8585
cleanupConnection(connection);
8686
return;
8787
}
8888
if (connection->serialNumber() == 0 || connection->name().isEmpty()) {
89-
qCDebug(dcMennekes()) << "Serial number or name invalid. Skipping" << networkDeviceInfo.address();
89+
qCDebug(dcMennekes()) << "Serial number or name invalid. Skipping" << address.toString();
9090
cleanupConnection(connection);
9191
return;
9292
}
9393

9494
AmtronDiscoveryResult result;
9595
result.wallboxName = connection->name();
9696
result.serialNumber = connection->serialNumber();
97-
result.networkDeviceInfo = networkDeviceInfo;
97+
result.address = address;
9898
m_discoveryResults.append(result);
9999

100100
qCDebug(dcMennekes()) << "Discovery: --> Found" << result.wallboxName
101101
<< "Serial number:" << result.serialNumber
102-
<< result.networkDeviceInfo;
103-
102+
<< result.address.toString();
104103

105104
// Done with this connection
106105
cleanupConnection(connection);
107106
});
108107

109108
if (!connection->initialize()) {
110-
qCDebug(dcMennekes()) << "Discovery: Unable to initialize connection on" << networkDeviceInfo.address().toString();
109+
qCDebug(dcMennekes()) << "Discovery: Unable to initialize connection on" << address.toString();
111110
cleanupConnection(connection);
112111
}
113112
});
114113

115114
// If check reachability failed...skip this host...
116115
connect(connection, &AmtronHCC3ModbusTcpConnection::checkReachabilityFailed, this, [=](){
117-
qCDebug(dcMennekes()) << "Discovery: Checking reachability failed on" << networkDeviceInfo.address().toString();
116+
qCDebug(dcMennekes()) << "Discovery: Checking reachability failed on" << address.toString();
118117
cleanupConnection(connection);
119118
});
120119

@@ -133,12 +132,16 @@ void AmtronHCC3Discovery::finishDiscovery()
133132
{
134133
qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch() - m_startDateTime.toMSecsSinceEpoch();
135134

135+
// Fill in all network device infos we have
136+
for (int i = 0; i < m_discoveryResults.count(); i++)
137+
m_discoveryResults[i].networkDeviceInfo = m_networkDeviceInfos.get(m_discoveryResults.at(i).address);
138+
136139
// Cleanup any leftovers...we don't care any more
137140
foreach (AmtronHCC3ModbusTcpConnection *connection, m_connections)
138141
cleanupConnection(connection);
139142

140143
qCInfo(dcMennekes()) << "Discovery: Finished the discovery process. Found" << m_discoveryResults.count()
141-
<< "AMTRON wallboxes in" << QTime::fromMSecsSinceStartOfDay(durationMilliSeconds).toString("mm:ss.zzz");
144+
<< "AMTRON HCC3 wallboxes in" << QTime::fromMSecsSinceStartOfDay(durationMilliSeconds).toString("mm:ss.zzz");
142145
m_gracePeriodTimer.stop();
143146

144147
emit discoveryFinished();

‎mennekes/amtronhcc3discovery.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
22
*
3-
* Copyright 2013 - 2022, nymea GmbH
3+
* Copyright 2013 - 2024, nymea GmbH
44
* Contact: contact@nymea.io
55
*
66
* This file is part of nymea.
@@ -42,13 +42,15 @@ class AmtronHCC3Discovery : public QObject
4242
{
4343
Q_OBJECT
4444
public:
45-
explicit AmtronHCC3Discovery(NetworkDeviceDiscovery *networkDeviceDiscovery, QObject *parent = nullptr);
4645
typedef struct AmtronDiscoveryResult {
4746
QString wallboxName;
4847
QString serialNumber;
48+
QHostAddress address;
4949
NetworkDeviceInfo networkDeviceInfo;
5050
} AmtronDiscoveryResult;
5151

52+
explicit AmtronHCC3Discovery(NetworkDeviceDiscovery *networkDeviceDiscovery, QObject *parent = nullptr);
53+
5254
void startDiscovery();
5355

5456
QList<AmtronDiscoveryResult> discoveryResults() const;
@@ -58,15 +60,13 @@ class AmtronHCC3Discovery : public QObject
5860

5961
private:
6062
NetworkDeviceDiscovery *m_networkDeviceDiscovery = nullptr;
61-
6263
QTimer m_gracePeriodTimer;
6364
QDateTime m_startDateTime;
64-
65+
NetworkDeviceInfos m_networkDeviceInfos;
6566
QList<AmtronHCC3ModbusTcpConnection *> m_connections;
66-
6767
QList<AmtronDiscoveryResult> m_discoveryResults;
6868

69-
void checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo);
69+
void checkNetworkDevice(const QHostAddress &address);
7070
void cleanupConnection(AmtronHCC3ModbusTcpConnection *connection);
7171

7272
void finishDiscovery();
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)