diff --git a/qt-ozwdaemon/mqttcommands/mqttcommands.cpp b/qt-ozwdaemon/mqttcommands/mqttcommands.cpp index f029b65..3d6d2bd 100644 --- a/qt-ozwdaemon/mqttcommands/mqttcommands.cpp +++ b/qt-ozwdaemon/mqttcommands/mqttcommands.cpp @@ -28,6 +28,7 @@ #include "mqttcommands/checkLatestMFSRevision.h" #include "mqttcommands/downloadLatestConfigFileRevision.h" #include "mqttcommands/downloadLatestMFSRevision.h" +#include "mqttcommands/setValue.h" Q_LOGGING_CATEGORY(ozwmc, "ozw.mqtt.commands"); @@ -140,7 +141,26 @@ bool MqttCommand::checkNode(QJsonDocument jmsg, QString field) { return false; } +bool MqttCommand::checkValue(QJsonDocument jmsg, QString field) { + quint64 vidKey = jmsg[field].toInt(); + if (vidKey == 0) { + qCWarning(ozwmc) << "Invalid VidKey in field " << field << " for message " << jmsg.toJson(); + return false; + } + if (this->getMqttPublisher()->isValidValueID(vidKey)) { + return true; + } + qCWarning(ozwmc) << "Invalid VidKey in field " << field << " for message " << jmsg.toJson(); + return false; +} +QVariant MqttCommand::getValueData(quint64 vidKey, QTOZW_ValueIds::ValueIdColumns col) { + return this->getMqttPublisher()->getValueData(vidKey, col); +} + +bool MqttCommand::setValue(quint64 vidKey, QVariant data) { + return this->getMqttPublisher()->setValue(vidKey, data); +} MqttCommands::MqttCommands(QObject *parent) : @@ -184,6 +204,7 @@ void MqttCommands::setupCommands() { this->Register(MqttCommand_CheckLatestMFSRevision::StaticGetCommand(), &MqttCommand_CheckLatestMFSRevision::Create); this->Register(MqttCommand_DownloadLatestConfigFileRevision::StaticGetCommand(), &MqttCommand_DownloadLatestConfigFileRevision::Create); this->Register(MqttCommand_DownloadLatestMFSRevision::StaticGetCommand(), &MqttCommand_DownloadLatestMFSRevision::Create); + this->Register(MqttCommand_SetValue::StaticGetCommand(), &MqttCommand_SetValue::Create); } void MqttCommands::setupSubscriptions(QMqttClient *mqttclient, QString topTopic) { diff --git a/qt-ozwdaemon/mqttcommands/mqttcommands.h b/qt-ozwdaemon/mqttcommands/mqttcommands.h index 9f44639..4f6b0db 100644 --- a/qt-ozwdaemon/mqttcommands/mqttcommands.h +++ b/qt-ozwdaemon/mqttcommands/mqttcommands.h @@ -9,6 +9,7 @@ #include #include +#include #include "mqttpublisher.h" @@ -29,6 +30,9 @@ protected: QTOZWManager *getOZWManager(); mqttpublisher *getMqttPublisher(); bool checkNode(QJsonDocument, QString); + bool checkValue(QJsonDocument, QString); + QVariant getValueData(quint64, QTOZW_ValueIds::ValueIdColumns); + bool setValue(quint64, QVariant); QVector m_requiredStringFields; QVector m_requiredIntFields; QVector m_requiredBoolFields; diff --git a/qt-ozwdaemon/mqttpublisher.cpp b/qt-ozwdaemon/mqttpublisher.cpp index 8836514..3b2185d 100644 --- a/qt-ozwdaemon/mqttpublisher.cpp +++ b/qt-ozwdaemon/mqttpublisher.cpp @@ -89,6 +89,12 @@ QVariant mqttValueIDModel::getValueData(quint64 vidKey, ValueIdColumns col) { return this->data(this->index(row, col), Qt::DisplayRole); } +bool mqttValueIDModel::isValidValueID(quint64 vidKey) { + if (this->getValueRow(vidKey) == -1) + return false; + return true; +} + bool mqttValueIDModel::populateJsonObject(QJsonObject *jsonobject, quint64 vidKey, QTOZWManager *mgr) { for (int i = 0; i < ValueIdColumns::ValueIdCount; i++) { @@ -143,8 +149,6 @@ bool mqttValueIDModel::populateJsonObject(QJsonObject *jsonobject, quint64 vidKe } } - - return true; } @@ -230,6 +234,10 @@ QJsonValue mqttValueIDModel::encodeValue(quint64 vidKey) { return value; } +bool mqttValueIDModel::setData(quint64 vidKey, QVariant data) { + return QTOZW_ValueIds::setData(this->index(this->getValueRow(vidKey), QTOZW_ValueIds::ValueIdColumns::Value), data, Qt::EditRole); +} + mqttpublisher::mqttpublisher(QObject *parent) : QObject(parent) @@ -344,6 +352,16 @@ void mqttpublisher::doStats() { bool mqttpublisher::isValidNode(quint8 node) { return this->m_nodeModel->isValidNode(node); } +bool mqttpublisher::isValidValueID(quint64 vidKey) { + return this->m_valueModel->isValidValueID(vidKey); +} +QVariant mqttpublisher::getValueData(quint64 vidKey, mqttValueIDModel::ValueIdColumns col) { + return this->m_valueModel->getValueData(vidKey, col); +} + +bool mqttpublisher::setValue(quint64 vidKey, QVariant data) { + return this->m_valueModel->setData(vidKey, data); +} QString mqttpublisher::getTopic(QString topic) { diff --git a/qt-ozwdaemon/mqttpublisher.h b/qt-ozwdaemon/mqttpublisher.h index 0e56723..5078224 100644 --- a/qt-ozwdaemon/mqttpublisher.h +++ b/qt-ozwdaemon/mqttpublisher.h @@ -38,6 +38,8 @@ public: QVariant getValueData(quint64, ValueIdColumns); bool populateJsonObject(QJsonObject *, quint64, QTOZWManager *); QJsonValue encodeValue(quint64); + bool isValidValueID(quint64); + bool setData(quint64, QVariant); }; class mqttpublisher : public QObject @@ -49,6 +51,9 @@ public: QTOZWManager *getQTOZWManager(); void sendCommandUpdate(QString, QJsonObject); bool isValidNode(quint8 node); + bool isValidValueID(quint64 vidKey); + QVariant getValueData(quint64, mqttValueIDModel::ValueIdColumns); + bool setValue(quint64, QVariant); signals: public slots: diff --git a/qt-ozwdaemon/qt-ozwdaemon.pro b/qt-ozwdaemon/qt-ozwdaemon.pro index 79d7bd5..acfaa64 100644 --- a/qt-ozwdaemon/qt-ozwdaemon.pro +++ b/qt-ozwdaemon/qt-ozwdaemon.pro @@ -51,12 +51,13 @@ qtHaveModule(mqtt) { mqttcommands/checkLatestConfigFileRevision.cpp \ mqttcommands/checkLatestMFSRevision.cpp \ mqttcommands/downloadLatestConfigFileRevision.cpp \ - mqttcommands/downloadLatestMFSRevision.cpp + mqttcommands/downloadLatestMFSRevision.cpp \ + mqttcommands/setValue.cpp HEADERS += mqttpublisher.h \ - mqttcommands/mqttcommands.h \ - mqttcommands/ping.h \ - mqttcommands/open.h \ + mqttcommands/mqttcommands.h \ + mqttcommands/ping.h \ + mqttcommands/open.h \ mqttcommands/refreshnodeinfo.h \ mqttcommands/requestNodeState.h \ mqttcommands/requestNodeDynamic.h \ @@ -74,7 +75,7 @@ qtHaveModule(mqtt) { mqttcommands/removeFailedNode.h \ mqttcommands/hasNodeFailed.h \ mqttcommands/requestNodeNeighborUpdate.h \ - mqttcommands/assignReturnRoute.h \ + mqttcommands/assignReturnRoute.h \ mqttcommands/deleteAllReturnRoute.h \ mqttcommands/sendNodeInformation.h \ mqttcommands/replaceFailedNode.h \ @@ -83,7 +84,8 @@ qtHaveModule(mqtt) { mqttcommands/checkLatestConfigFileRevision.h \ mqttcommands/CheckLatestMFSRevision.h \ mqttcommands/downloadLatestConfigFileRevision.h \ - mqttcommands/downloadLatestMFSRevision.h + mqttcommands/downloadLatestMFSRevision.h \ + mqttcommands/setValue.h } else { warning("MQTT Qt Module Not Found. Not Building MQTT Client Capabilities") }