added missing parsing methods
This commit is contained in:
parent
d7a53bd227
commit
e35f157718
@ -180,6 +180,7 @@ void IntegrationPluginSma::onDevicesReceived(int messageId, QList<SunnyWebBox::D
|
|||||||
|
|
||||||
void IntegrationPluginSma::onProcessDataReceived(int messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels)
|
void IntegrationPluginSma::onProcessDataReceived(int messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels)
|
||||||
{
|
{
|
||||||
|
Q_UNUSED(messageId)
|
||||||
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(sender()));
|
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(sender()));
|
||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include "QJsonDocument"
|
#include "QJsonDocument"
|
||||||
#include "QJsonObject"
|
#include "QJsonObject"
|
||||||
|
#include "QJsonArray"
|
||||||
|
|
||||||
SunnyWebBox::SunnyWebBox(SunnyWebBoxCommunication *communication, const QHostAddress &hostAddress, QObject *parrent) :
|
SunnyWebBox::SunnyWebBox(SunnyWebBoxCommunication *communication, const QHostAddress &hostAddress, QObject *parrent) :
|
||||||
QObject(parrent),
|
QObject(parrent),
|
||||||
@ -60,6 +61,25 @@ int SunnyWebBox::getProcessDataChannels(const QString &deviceId)
|
|||||||
return m_communication->sendMessage(m_hostAddresss, "GetProcessDataChannels", params);
|
return m_communication->sendMessage(m_hostAddresss, "GetProcessDataChannels", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SunnyWebBox::setParameters(const QString &deviceKey, const QHash<QString, QVariant> &channels)
|
||||||
|
{
|
||||||
|
QJsonObject paramsObj;
|
||||||
|
QJsonArray devicesArray;
|
||||||
|
QJsonObject deviceObj;
|
||||||
|
deviceObj["key"] = deviceKey;
|
||||||
|
QJsonArray channelsArray;
|
||||||
|
Q_FOREACH(QString key, channels.keys()) {
|
||||||
|
QJsonObject channelObj;
|
||||||
|
channelObj["meta"] = key;
|
||||||
|
channelObj["value"] = channels.value(key).toString();
|
||||||
|
channelsArray.append(channelObj);
|
||||||
|
}
|
||||||
|
deviceObj["channels"] = channelsArray;
|
||||||
|
devicesArray.append(deviceObj);
|
||||||
|
paramsObj["devices"] = devicesArray;
|
||||||
|
return m_communication->sendMessage(m_hostAddresss, "SetParameter", paramsObj);
|
||||||
|
}
|
||||||
|
|
||||||
void SunnyWebBox::onMessageReceived(const QHostAddress &address, int messageId, const QString &messageType, const QVariantMap &result)
|
void SunnyWebBox::onMessageReceived(const QHostAddress &address, int messageId, const QString &messageType, const QVariantMap &result)
|
||||||
{
|
{
|
||||||
if (address != m_hostAddresss) {
|
if (address != m_hostAddresss) {
|
||||||
@ -106,16 +126,52 @@ void SunnyWebBox::onMessageReceived(const QHostAddress &address, int messageId,
|
|||||||
}
|
}
|
||||||
if (!devices.isEmpty())
|
if (!devices.isEmpty())
|
||||||
emit devicesReceived(messageId, devices);
|
emit devicesReceived(messageId, devices);
|
||||||
} else if (messageType == "GetProcessDataChannels") {
|
} else if (messageType == "GetProcessDataChannels" ||
|
||||||
|
messageType == "GetProDataChannels") {
|
||||||
|
Q_FOREACH(QString deviceKey, result.keys()) {
|
||||||
|
QStringList processDataChannels = result.value(deviceKey).toStringList();
|
||||||
|
if (!processDataChannels.isEmpty())
|
||||||
|
emit processDataChannelsReceived(messageId, deviceKey, processDataChannels);
|
||||||
|
}
|
||||||
} else if (messageType == "GetProcessData") {
|
} else if (messageType == "GetProcessData") {
|
||||||
|
QList<Device> devices;
|
||||||
|
QVariantList devicesList = result.value("devices").toList();
|
||||||
|
Q_FOREACH(QVariant value, devicesList) {
|
||||||
|
|
||||||
|
QString key = value.toMap().value("key").toString();
|
||||||
|
QVariantList channelsList = value.toMap().value("channels").toList();
|
||||||
|
QHash<QString, QVariant> channels;
|
||||||
|
Q_FOREACH(QVariant channel, channelsList) {
|
||||||
|
channels.insert(channel.toMap().value("meta").toString(), channel.toMap().value("value"));
|
||||||
|
}
|
||||||
|
emit processDataReceived(messageId, key, channels);
|
||||||
|
}
|
||||||
} else if (messageType == "GetParameterChannels") {
|
} else if (messageType == "GetParameterChannels") {
|
||||||
Q_FOREACH(QString deviceKey, result.keys()) {
|
Q_FOREACH(QString deviceKey, result.keys()) {
|
||||||
QStringList parameterChannels = result.value(deviceKey).toStringList();
|
QStringList parameterChannels = result.value(deviceKey).toStringList();
|
||||||
if (!parameterChannels.isEmpty())
|
if (!parameterChannels.isEmpty())
|
||||||
emit parameterChannelsReceived(messageId, deviceKey, parameterChannels);
|
emit parameterChannelsReceived(messageId, deviceKey, parameterChannels);
|
||||||
}
|
}
|
||||||
} else if (messageType == "GetParameter") {
|
} else if (messageType == "GetParameter"|| messageType == "SetParameter") {
|
||||||
} else if (messageType == "SetParameter") {
|
QList<Device> devices;
|
||||||
|
QVariantList devicesList = result.value("devices").toList();
|
||||||
|
Q_FOREACH(QVariant value, devicesList) {
|
||||||
|
|
||||||
|
QString key = value.toMap().value("key").toString();
|
||||||
|
QVariantList channelsList = value.toMap().value("channels").toList();
|
||||||
|
QList<Parameter> parameters;
|
||||||
|
Q_FOREACH(QVariant channel, channelsList) {
|
||||||
|
Parameter parameter;
|
||||||
|
parameter.meta = channel.toMap().value("meta").toString();
|
||||||
|
parameter.name = channel.toMap().value("name").toString();
|
||||||
|
parameter.unit = channel.toMap().value("unit").toString();
|
||||||
|
parameter.min = channel.toMap().value("min").toDouble();
|
||||||
|
parameter.max = channel.toMap().value("max").toDouble();
|
||||||
|
parameter.value = channel.toMap().value("value").toDouble();
|
||||||
|
parameters.append(parameter);
|
||||||
|
}
|
||||||
|
emit parametersReceived(messageId, key, parameters);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcSma()) << "Unknown message type" << messageType;
|
qCWarning(dcSma()) << "Unknown message type" << messageType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,14 +64,24 @@ public:
|
|||||||
QString unit;
|
QString unit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Parameter {
|
||||||
|
QString meta;
|
||||||
|
QString name;
|
||||||
|
QString unit;
|
||||||
|
double min;
|
||||||
|
double max;
|
||||||
|
double value;
|
||||||
|
};
|
||||||
|
|
||||||
explicit SunnyWebBox(SunnyWebBoxCommunication *communication, const QHostAddress &hostAddress, QObject *parrent = 0);
|
explicit SunnyWebBox(SunnyWebBoxCommunication *communication, const QHostAddress &hostAddress, QObject *parrent = 0);
|
||||||
|
|
||||||
int getPlantOverview();
|
int getPlantOverview(); // Returns an object with the following plant data: PAC, E-TODAY, E-TOTAL, MODE, ERROR
|
||||||
int getDevices();
|
int getDevices(); //Returns a hierarchical list of all detected plant devices.
|
||||||
int getProcessDataChannels(const QString &deviceKey);
|
int getProcessDataChannels(const QString &deviceKey); //Returns a list with the meta names of the available process data channels for a particular device type.
|
||||||
int getProcessData(const QStringList &deviceKeys);
|
int getProcessData(const QStringList &deviceKeys); //Returns process data for up to 5 devices per request.
|
||||||
int getParameterChannels(const QString &deviceKey);
|
int getParameterChannels(const QString &deviceKey); //Returns a list with the meta names of the available parameter channels for a particular device type
|
||||||
int getParameters(const QStringList &deviceKeys);
|
int getParameters(const QStringList &deviceKeys); //Returns the parameter values of up to 5 devices
|
||||||
|
int setParameters(const QString &deviceKeys, const QHash<QString, QVariant> &channels); //Sets parameter values
|
||||||
|
|
||||||
void setHostAddress();
|
void setHostAddress();
|
||||||
QHostAddress hostAddress();
|
QHostAddress hostAddress();
|
||||||
@ -90,8 +100,10 @@ signals:
|
|||||||
|
|
||||||
void plantOverviewReceived(int messageId, Overview overview);
|
void plantOverviewReceived(int messageId, Overview overview);
|
||||||
void devicesReceived(int messageId, QList<Device> devices);
|
void devicesReceived(int messageId, QList<Device> devices);
|
||||||
|
void processDataChannelsReceived(int messageId, const QString &deviceKey, QStringList processDataChanels);
|
||||||
void processDataReceived(int messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels);
|
void processDataReceived(int messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels);
|
||||||
void parameterChannelsReceived(int messageId, const QString &deviceKey, QStringList parameterChannels);
|
void parameterChannelsReceived(int messageId, const QString &deviceKey, QStringList parameterChannels);
|
||||||
|
void parametersReceived(int messageId, const QString &deviceKey, const QList<Parameter> ¶meters);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SUNNYWEBBOX_H
|
#endif // SUNNYWEBBOX_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user