diff --git a/sma/integrationpluginsma.cpp b/sma/integrationpluginsma.cpp index 0a79e200..399046e3 100644 --- a/sma/integrationpluginsma.cpp +++ b/sma/integrationpluginsma.cpp @@ -100,7 +100,7 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info) connect(sunnyWebBox, &SunnyWebBox::parameterChannelsReceived, this, &IntegrationPluginSma::onParameterChannelsReceived); m_sunnyWebBoxes.insert(thing, sunnyWebBox); connect(info, &ThingSetupInfo::aborted, this, [thing, this] { m_sunnyWebBoxes.remove(thing);}); - QUuid requestId = sunnyWebBox->getPlantOverview(); + QString requestId = sunnyWebBox->getPlantOverview(); m_asyncSetup.insert(requestId, info); return info->finish(Thing::ThingErrorNoError); @@ -147,7 +147,7 @@ void IntegrationPluginSma::executeAction(ThingActionInfo *info) if (!sunnyWebBox) return; if (action.actionTypeId() == sunnyWebBoxSearchDevicesActionTypeId) { - QUuid requestId = sunnyWebBox->getDevices(); + QString requestId = sunnyWebBox->getDevices(); m_asyncActions.insert(requestId, info); connect(info, &ThingActionInfo::aborted, info, [requestId, this] {m_asyncActions.remove(requestId);}); } else { @@ -177,7 +177,7 @@ void IntegrationPluginSma::onRefreshTimer() } } -void IntegrationPluginSma::onPlantOverviewReceived(const QUuid &messageId, SunnyWebBox::Overview overview) +void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview) { if (m_asyncSetup.contains(messageId)) { ThingSetupInfo *info = m_asyncSetup.value(messageId); @@ -200,7 +200,7 @@ void IntegrationPluginSma::onPlantOverviewReceived(const QUuid &messageId, Sunny } } -void IntegrationPluginSma::onDevicesReceived(const QUuid &messageId, QList devices) +void IntegrationPluginSma::onDevicesReceived(const QString &messageId, QList devices) { if (m_asyncActions.contains(messageId)) { ThingActionInfo *info = m_asyncActions.value(messageId); @@ -221,7 +221,7 @@ void IntegrationPluginSma::onDevicesReceived(const QUuid &messageId, QList &channels) +void IntegrationPluginSma::onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash &channels) { Q_UNUSED(messageId) Thing *thing = m_sunnyWebBoxes.key(static_cast(sender())); @@ -240,7 +240,7 @@ void IntegrationPluginSma::onProcessDataReceived(const QUuid &messageId, const Q } } -void IntegrationPluginSma::onParameterChannelsReceived(const QUuid &messageId, const QString &deviceKey, QStringList parameterChannels) +void IntegrationPluginSma::onParameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels) { Q_UNUSED(messageId) diff --git a/sma/integrationpluginsma.h b/sma/integrationpluginsma.h index 01185063..8d445d31 100644 --- a/sma/integrationpluginsma.h +++ b/sma/integrationpluginsma.h @@ -59,16 +59,16 @@ public: private slots: void onRefreshTimer(); - void onPlantOverviewReceived(const QUuid &messageId, SunnyWebBox::Overview overview); - void onDevicesReceived(const QUuid &messageId, QList devices); - void onProcessDataReceived(const QUuid &messageId, const QString &deviceKey, const QHash &channels); - void onParameterChannelsReceived(const QUuid &messageId, const QString &deviceKey, QStringList parameterChannels); + void onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview); + void onDevicesReceived(const QString &messageId, QList devices); + void onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash &channels); + void onParameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels); private: PluginTimer *m_refreshTimer = nullptr; QHash m_sunnyWebBoxes; - QHash m_asyncSetup; - QHash m_asyncActions; + QHash m_asyncSetup; + QHash m_asyncActions; SunnyWebBoxCommunication *m_sunnyWebBoxCommunication = nullptr; SunnyWebBox *createSunnyWebBoxConnection(Thing *thing); diff --git a/sma/sunnywebbox.cpp b/sma/sunnywebbox.cpp index ad4871c4..c687affb 100644 --- a/sma/sunnywebbox.cpp +++ b/sma/sunnywebbox.cpp @@ -44,31 +44,31 @@ SunnyWebBox::SunnyWebBox(SunnyWebBoxCommunication *communication, const QHostAdd connect(m_communication, &SunnyWebBoxCommunication::messageReceived, this, &SunnyWebBox::onMessageReceived); } -QUuid SunnyWebBox::getPlantOverview() +QString SunnyWebBox::getPlantOverview() { return m_communication->sendMessage(m_hostAddresss, "GetPlantOverview"); } -QUuid SunnyWebBox::getDevices() +QString SunnyWebBox::getDevices() { return m_communication->sendMessage(m_hostAddresss, "GetDevices"); } -QUuid SunnyWebBox::getProcessDataChannels(const QString &deviceId) +QString SunnyWebBox::getProcessDataChannels(const QString &deviceId) { QJsonObject params; params["device"] = deviceId; return m_communication->sendMessage(m_hostAddresss, "GetProcessDataChannels", params); } -QUuid SunnyWebBox::getProcessData(const QStringList &deviceKeys) +QString SunnyWebBox::getProcessData(const QStringList &deviceKeys) { QJsonObject params; params["device"] = deviceKeys.first(); return m_communication->sendMessage(m_hostAddresss, "GetProcessData", params); } -QUuid SunnyWebBox::getParameterChannels(const QString &deviceKey) +QString SunnyWebBox::getParameterChannels(const QString &deviceKey) { QJsonObject paramsObj; QJsonArray devicesArray; @@ -79,7 +79,7 @@ QUuid SunnyWebBox::getParameterChannels(const QString &deviceKey) return m_communication->sendMessage(m_hostAddresss, "GetParameterChannels", paramsObj); } -QUuid SunnyWebBox::getParameters(const QStringList &deviceKeys) +QString SunnyWebBox::getParameters(const QStringList &deviceKeys) { QJsonObject paramsObj; QJsonArray devicesArray; @@ -90,7 +90,7 @@ QUuid SunnyWebBox::getParameters(const QStringList &deviceKeys) return m_communication->sendMessage(m_hostAddresss, "GetParameter", paramsObj); } -QUuid SunnyWebBox::setParameters(const QString &deviceKey, const QHash &channels) +QString SunnyWebBox::setParameters(const QString &deviceKey, const QHash &channels) { QJsonObject paramsObj; QJsonArray devicesArray; @@ -119,7 +119,7 @@ QHostAddress SunnyWebBox::hostAddress() return m_hostAddresss; } -void SunnyWebBox::onMessageReceived(const QHostAddress &address, const QUuid &messageId, const QString &messageType, const QVariantMap &result) +void SunnyWebBox::onMessageReceived(const QHostAddress &address, const QString &messageId, const QString &messageType, const QVariantMap &result) { if (address != m_hostAddresss) { return; diff --git a/sma/sunnywebbox.h b/sma/sunnywebbox.h index 608771d2..ef20e0c4 100644 --- a/sma/sunnywebbox.h +++ b/sma/sunnywebbox.h @@ -75,13 +75,13 @@ public: explicit SunnyWebBox(SunnyWebBoxCommunication *communication, const QHostAddress &hostAddress, QObject *parrent = 0); - QUuid getPlantOverview(); // Returns an object with the following plant data: PAC, E-TODAY, E-TOTAL, MODE, ERROR - QUuid getDevices(); //Returns a hierarchical list of all detected plant devices. - QUuid getProcessDataChannels(const QString &deviceKey); //Returns a list with the meta names of the available process data channels for a particular device type. - QUuid getProcessData(const QStringList &deviceKeys); //Returns process data for up to 5 devices per request. - QUuid getParameterChannels(const QString &deviceKey); //Returns a list with the meta names of the available parameter channels for a particular device type - QUuid getParameters(const QStringList &deviceKeys); //Returns the parameter values of up to 5 devices - QUuid setParameters(const QString &deviceKeys, const QHash &channels); //Sets parameter values + QString getPlantOverview(); // Returns an object with the following plant data: PAC, E-TODAY, E-TOTAL, MODE, ERROR + QString getDevices(); //Returns a hierarchical list of all detected plant devices. + QString getProcessDataChannels(const QString &deviceKey); //Returns a list with the meta names of the available process data channels for a particular device type. + QString getProcessData(const QStringList &deviceKeys); //Returns process data for up to 5 devices per request. + QString getParameterChannels(const QString &deviceKey); //Returns a list with the meta names of the available parameter channels for a particular device type + QString getParameters(const QStringList &deviceKeys); //Returns the parameter values of up to 5 devices + QString setParameters(const QString &deviceKeys, const QHash &channels); //Sets parameter values void setHostAddress(const QHostAddress &address); QHostAddress hostAddress(); @@ -92,17 +92,17 @@ private: SunnyWebBoxCommunication *m_communication = nullptr; public slots: - void onMessageReceived(const QHostAddress &address, const QUuid &messageId, const QString &messageType, const QVariantMap &result); + void onMessageReceived(const QHostAddress &address, const QString &messageId, const QString &messageType, const QVariantMap &result); signals: void connectedChanged(bool connected); - void plantOverviewReceived(const QUuid &messageId, Overview overview); - void devicesReceived(const QUuid &messageId, QList devices); - void processDataChannelsReceived(const QUuid &messageId, const QString &deviceKey, QStringList processDataChanels); - void processDataReceived(const QUuid &messageId, const QString &deviceKey, const QHash &channels); - void parameterChannelsReceived(const QUuid &messageId, const QString &deviceKey, QStringList parameterChannels); - void parametersReceived(const QUuid &messageId, const QString &deviceKey, const QList ¶meters); + void plantOverviewReceived(const QString &messageId, Overview overview); + void devicesReceived(const QString &messageId, QList devices); + void processDataChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList processDataChanels); + void processDataReceived(const QString &messageId, const QString &deviceKey, const QHash &channels); + void parameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels); + void parametersReceived(const QString &messageId, const QString &deviceKey, const QList ¶meters); }; #endif // SUNNYWEBBOX_H diff --git a/sma/sunnywebboxcommunication.cpp b/sma/sunnywebboxcommunication.cpp index de7ef31d..4be38276 100644 --- a/sma/sunnywebboxcommunication.cpp +++ b/sma/sunnywebboxcommunication.cpp @@ -33,6 +33,7 @@ #include "QJsonDocument" #include "QJsonObject" +#include SunnyWebBoxCommunication::SunnyWebBoxCommunication(QObject *parent) : QObject(parent) { @@ -57,14 +58,14 @@ SunnyWebBoxCommunication::SunnyWebBoxCommunication(QObject *parent) : QObject(pa }); } -QUuid SunnyWebBoxCommunication::sendMessage(const QHostAddress &address, const QString &procedure) +QString SunnyWebBoxCommunication::sendMessage(const QHostAddress &address, const QString &procedure) { - QUuid requestId = QUuid::createUuid(); + QString requestId = QUuid::createUuid().toString().remove('{').left(14); QJsonDocument doc; QJsonObject obj; obj["format"] = "JSON"; - obj["id"] = requestId.toString().remove('{').remove('}'); + obj["id"] = requestId; obj["proc"] = procedure; obj["version"] = "1.0"; doc.setObject(obj); @@ -74,9 +75,9 @@ QUuid SunnyWebBoxCommunication::sendMessage(const QHostAddress &address, const Q return requestId; } -QUuid SunnyWebBoxCommunication::sendMessage(const QHostAddress &address, const QString &procedure, const QJsonObject ¶ms) +QString SunnyWebBoxCommunication::sendMessage(const QHostAddress &address, const QString &procedure, const QJsonObject ¶ms) { - QUuid requestId = QUuid::createUuid(); + QString requestId = QUuid::createUuid().toString().remove('{').left(14); QJsonDocument doc; QJsonObject obj; @@ -85,7 +86,7 @@ QUuid SunnyWebBoxCommunication::sendMessage(const QHostAddress &address, const Q obj.insert("params", params); } obj["format"] = "JSON"; - obj["id"] = requestId.toString().remove('{').remove('}'); + obj["id"] = requestId; obj["proc"] = procedure; obj["version"] = "1.0"; doc.setObject(obj); @@ -122,7 +123,7 @@ void SunnyWebBoxCommunication::datagramReceived(const QHostAddress &address, con if (map.contains("proc") && map.contains("result")) { QString requestType = map["proc"].toString(); - QUuid requestId = QUuid(map["id"].toString()); + QString requestId = map["id"].toString(); QVariantMap result = map.value("result").toMap(); emit messageReceived(address, requestId, requestType, result); } else { diff --git a/sma/sunnywebboxcommunication.h b/sma/sunnywebboxcommunication.h index 8ceb6ee9..c6a72a24 100644 --- a/sma/sunnywebboxcommunication.h +++ b/sma/sunnywebboxcommunication.h @@ -33,7 +33,6 @@ #include #include -#include class SunnyWebBoxCommunication : public QObject { @@ -41,8 +40,8 @@ class SunnyWebBoxCommunication : public QObject public: explicit SunnyWebBoxCommunication(QObject *parent = nullptr); - QUuid sendMessage(const QHostAddress &address, const QString &procedure); - QUuid sendMessage(const QHostAddress &address, const QString &procedure, const QJsonObject ¶ms); + QString sendMessage(const QHostAddress &address, const QString &procedure); + QString sendMessage(const QHostAddress &address, const QString &procedure, const QJsonObject ¶ms); private: int m_port = 34268; @@ -52,7 +51,7 @@ private: signals: void socketConnected(bool connected); - void messageReceived(const QHostAddress &address, QUuid messageId, const QString &messageType, const QVariantMap &result); + void messageReceived(const QHostAddress &address, const QString &messageId, const QString &messageType, const QVariantMap &result); };