moved from qrand to Quuid

master
bernhard.trinnes 2020-08-18 15:06:46 +02:00 committed by Simon Stürz
parent 837751c06c
commit f2a401aedf
6 changed files with 45 additions and 45 deletions

View File

@ -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<SunnyWebBox::Device> devices)
void IntegrationPluginSma::onDevicesReceived(const QString &messageId, QList<SunnyWebBox::Device> devices)
{
if (m_asyncActions.contains(messageId)) {
ThingActionInfo *info = m_asyncActions.value(messageId);
@ -221,7 +221,7 @@ void IntegrationPluginSma::onDevicesReceived(const QUuid &messageId, QList<Sunny
emit autoThingsAppeared(descriptors);
}
void IntegrationPluginSma::onProcessDataReceived(const QUuid &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels)
void IntegrationPluginSma::onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels)
{
Q_UNUSED(messageId)
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(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)

View File

@ -59,16 +59,16 @@ public:
private slots:
void onRefreshTimer();
void onPlantOverviewReceived(const QUuid &messageId, SunnyWebBox::Overview overview);
void onDevicesReceived(const QUuid &messageId, QList<SunnyWebBox::Device> devices);
void onProcessDataReceived(const QUuid &messageId, const QString &deviceKey, const QHash<QString, QVariant> &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<SunnyWebBox::Device> devices);
void onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels);
void onParameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels);
private:
PluginTimer *m_refreshTimer = nullptr;
QHash<Thing *, SunnyWebBox *> m_sunnyWebBoxes;
QHash<QUuid, ThingSetupInfo *> m_asyncSetup;
QHash<QUuid, ThingActionInfo *> m_asyncActions;
QHash<QString, ThingSetupInfo *> m_asyncSetup;
QHash<QString, ThingActionInfo *> m_asyncActions;
SunnyWebBoxCommunication *m_sunnyWebBoxCommunication = nullptr;
SunnyWebBox *createSunnyWebBoxConnection(Thing *thing);

View File

@ -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<QString, QVariant> &channels)
QString SunnyWebBox::setParameters(const QString &deviceKey, const QHash<QString, QVariant> &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;

View File

@ -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<QString, QVariant> &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<QString, QVariant> &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<Device> devices);
void processDataChannelsReceived(const QUuid &messageId, const QString &deviceKey, QStringList processDataChanels);
void processDataReceived(const QUuid &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels);
void parameterChannelsReceived(const QUuid &messageId, const QString &deviceKey, QStringList parameterChannels);
void parametersReceived(const QUuid &messageId, const QString &deviceKey, const QList<Parameter> &parameters);
void plantOverviewReceived(const QString &messageId, Overview overview);
void devicesReceived(const QString &messageId, QList<Device> devices);
void processDataChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList processDataChanels);
void processDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels);
void parameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels);
void parametersReceived(const QString &messageId, const QString &deviceKey, const QList<Parameter> &parameters);
};
#endif // SUNNYWEBBOX_H

View File

@ -33,6 +33,7 @@
#include "QJsonDocument"
#include "QJsonObject"
#include <QUuid>
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 &params)
QString SunnyWebBoxCommunication::sendMessage(const QHostAddress &address, const QString &procedure, const QJsonObject &params)
{
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 {

View File

@ -33,7 +33,6 @@
#include <QObject>
#include <QUdpSocket>
#include <QUuid>
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 &params);
QString sendMessage(const QHostAddress &address, const QString &procedure);
QString sendMessage(const QHostAddress &address, const QString &procedure, const QJsonObject &params);
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);
};