1
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
2
*
3
- * Copyright 2013 - 2023 , nymea GmbH
3
+ * Copyright 2013 - 2024 , nymea GmbH
4
4
* Contact: contact@nymea.io
5
5
*
6
6
* This file is part of nymea.
@@ -50,12 +50,12 @@ void AmtronECUDiscovery::startDiscovery()
50
50
51
51
NetworkDeviceDiscoveryReply *discoveryReply = m_networkDeviceDiscovery->discover ();
52
52
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);
55
55
connect (discoveryReply, &NetworkDeviceDiscoveryReply::finished, this , [=](){
56
56
qCDebug (dcMennekes ()) << " Discovery: Network discovery finished. Found" << discoveryReply->networkDeviceInfos ().count () << " network devices" ;
57
+ m_networkDeviceInfos = discoveryReply->networkDeviceInfos ();
57
58
m_gracePeriodTimer.start ();
58
- discoveryReply->deleteLater ();
59
59
});
60
60
}
61
61
@@ -64,24 +64,24 @@ QList<AmtronECUDiscovery::Result> AmtronECUDiscovery::discoveryResults() const
64
64
return m_discoveryResults;
65
65
}
66
66
67
- void AmtronECUDiscovery::checkNetworkDevice (const NetworkDeviceInfo &networkDeviceInfo )
67
+ void AmtronECUDiscovery::checkNetworkDevice (const QHostAddress &address )
68
68
{
69
69
int port = 502 ;
70
70
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;
72
72
73
- AmtronECU *connection = new AmtronECU (networkDeviceInfo. address () , port, slaveId, this );
73
+ AmtronECU *connection = new AmtronECU (address, port, slaveId, this );
74
74
m_connections.append (connection);
75
75
76
- connect (connection, &AmtronECU::reachableChanged, this , [= ](bool reachable){
76
+ connect (connection, &AmtronECU::reachableChanged, this , [this , connection, address ](bool reachable){
77
77
if (!reachable) {
78
78
cleanupConnection (connection);
79
79
return ;
80
80
}
81
81
82
82
connect (connection, &AmtronECU::initializationFinished, this , [=](bool success){
83
83
if (!success) {
84
- qCDebug (dcMennekes ()) << " Discovery: Initialization failed on" << networkDeviceInfo. address () .toString ();
84
+ qCDebug (dcMennekes ()) << " Discovery: Initialization failed on" << address.toString ();
85
85
cleanupConnection (connection);
86
86
return ;
87
87
}
@@ -90,40 +90,40 @@ void AmtronECUDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDevi
90
90
result.detectedVersion = connection->detectedVersion ();
91
91
result.firmwareVersion = QString::fromUtf8 (QByteArray::fromHex (QByteArray::number (connection->firmwareVersion (), 16 )));
92
92
result.model = connection->model ();
93
- result.networkDeviceInfo = networkDeviceInfo ;
93
+ result.address = address ;
94
94
95
95
// Note: the model is only known in firmware >= 5.22
96
96
// Some useres have to stay on 5.12 due to calibration law which is not available on 5.22
97
97
switch (connection->detectedVersion ()) {
98
98
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 () ;
100
100
m_discoveryResults.append (result);
101
101
break ;
102
102
case AmtronECU::VersionNew:
103
103
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 ();
105
105
break ;
106
106
}
107
107
108
108
qCDebug (dcMennekes ()) << " Discovery: Found wallbox with new firmware version:" << result.model << result.firmwareVersion << result.networkDeviceInfo ;
109
109
m_discoveryResults.append (result);
110
110
break ;
111
111
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 ();
113
113
break ;
114
114
}
115
115
116
116
cleanupConnection (connection);
117
117
});
118
118
119
119
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 ();
121
121
cleanupConnection (connection);
122
122
}
123
123
});
124
124
125
125
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 ();
127
127
cleanupConnection (connection);
128
128
});
129
129
@@ -141,6 +141,10 @@ void AmtronECUDiscovery::finishDiscovery()
141
141
{
142
142
qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch () - m_startDateTime.toMSecsSinceEpoch ();
143
143
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
+
144
148
// Cleanup any leftovers...we don't care any more
145
149
foreach (AmtronECU *connection, m_connections)
146
150
cleanupConnection (connection);
0 commit comments