From 0cdb1fd1df4df9fafe872de087d5f20e331a186a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Mon, 14 Apr 2025 13:50:49 +0200 Subject: [PATCH] SMA: Improve datetime performance --- sma/speedwire/speedwiremeter.cpp | 6 +++--- sma/sunnywebbox/sunnywebbox.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sma/speedwire/speedwiremeter.cpp b/sma/speedwire/speedwiremeter.cpp index 03b167f..492adc3 100644 --- a/sma/speedwire/speedwiremeter.cpp +++ b/sma/speedwire/speedwiremeter.cpp @@ -152,7 +152,7 @@ void SpeedwireMeter::evaluateReachable() // Note: the meter sends every second the data on the multicast // If the meter has not sent data within the last 5 seconds it seems not to be reachable bool reachable = false; - if (QDateTime::currentDateTime().toMSecsSinceEpoch() - m_lastSeenTimestamp < 5000) { + if (QDateTime::currentMSecsSinceEpoch() - m_lastSeenTimestamp < 5000) { reachable = true; } @@ -200,7 +200,7 @@ void SpeedwireMeter::processData(const QHostAddress &senderAddress, quint16 send qCDebug(dcSma()).noquote() << "Meter: Measurements received from" << QString("%1:%2").arg(senderAddress.toString()).arg(senderPort) << "Serial number:" << serialNumber << "Model ID:" << modelId; // Make sure the rate is at max 1Hz, some meters send much more data, which creates an uneccessary load - if (QDateTime::currentDateTime().toMSecsSinceEpoch() - m_lastSeenTimestamp < 1000) + if (QDateTime::currentMSecsSinceEpoch() - m_lastSeenTimestamp < 1000) return; // Parse the packet data @@ -319,7 +319,7 @@ void SpeedwireMeter::processData(const QHostAddress &senderAddress, quint16 send } // Save the current timestamp for reachable evaluation - m_lastSeenTimestamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); + m_lastSeenTimestamp = QDateTime::currentMSecsSinceEpoch(); evaluateReachable(); emit valuesUpdated(); diff --git a/sma/sunnywebbox/sunnywebbox.cpp b/sma/sunnywebbox/sunnywebbox.cpp index d6d4db2..ae9dbd5 100644 --- a/sma/sunnywebbox/sunnywebbox.cpp +++ b/sma/sunnywebbox/sunnywebbox.cpp @@ -54,7 +54,7 @@ QString SunnyWebBox::getPlantOverview() if (!m_lastRequest.isNull()) { // According to the documentation, the interval between 2 requests should not be less than 30 seconds. - if (QDateTime::currentDateTime().toMSecsSinceEpoch() - m_lastRequest.toMSecsSinceEpoch() < 30000) { + if (QDateTime::currentMSecsSinceEpoch() - m_lastRequest.toMSecsSinceEpoch() < 30000) { return QString(); } }