Merge pull request #5 from OpenZWave/mqtt

Merge in MQTT Work into master
This commit is contained in:
Justin Hammond 2020-01-03 12:36:35 +08:00 committed by GitHub
commit 05b0ebad7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
119 changed files with 5910 additions and 191 deletions

2
.gitignore vendored
View file

@ -41,3 +41,5 @@ target_wrapper.*
# QtCreator CMake
CMakeLists.txt.user*
.vscode

48
Docker/Dockerfile Normal file
View file

@ -0,0 +1,48 @@
############################################################
# Dockerfile to build OpenZWave Library container images
# Based on CentOS7
############################################################
# Set the base image to Alpine
FROM debian:buster-slim as builder
# File Author / Maintainer
MAINTAINER Justin Hammond
WORKDIR /opt
RUN echo 'APT::Default-Release "stable";' > /etc/apt/apt.conf.d/99defaultrelease && echo 'deb http://ftp.uk.debian.org/debian/ unstable main contrib non-free' > /etc/apt/sources.list.d/unstable.list && echo 'deb http://ftp.uk.debian.org/debian/ experimental main contrib non-free' >> /etc/apt/sources.list.d/unstable.list && apt update
RUN apt-get -y install rapidjson-dev git g++ cmake make pkgconf bash python wget joe mc libunwind-dev libcurl4-openssl-dev && apt-get -y -t unstable install qt5-default && apt-get -y -t unstable install qtbase5-private-dev && apt-get -y -t unstable install g++ && apt-get -y -t experimental install libqt5remoteobjects5-dev libqt5remoteobjects5-bin
ENV PATH=$PATH:/opt/depot_tools/
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git && mkdir breakpad && cd breakpad && fetch breakpad && cd src && ./configure && make && make install
RUN git clone https://github.com/qt/qtmqtt.git && cd qtmqtt && git checkout 5.12 && /usr/lib/qt5/bin/qmake && make && make install
RUN git clone https://github.com/OpenZWave/open-zwave.git && cd open-zwave && make -j4 && make install
RUN git clone https://github.com/Fishwaldo/qt-openzwave.git && cd qt-openzwave && git checkout mqtt && /usr/lib/qt5/bin/qmake "CONFIG += BreakPad" && make -j4 && make install
FROM debian:buster-slim
MAINTAINER Justin Hammond
WORKDIR /opt
RUN echo 'APT::Default-Release "stable";' > /etc/apt/apt.conf.d/99defaultrelease && echo 'deb http://ftp.uk.debian.org/debian/ unstable main contrib non-free' > /etc/apt/sources.list.d/unstable.list && echo 'deb http://ftp.uk.debian.org/debian/ experimental main contrib non-free' >> /etc/apt/sources.list.d/unstable.list && apt update
RUN apt-get -y install libunwind8 libcurl4
RUN apt-get -y -t unstable install libqt5core5a libqt5network5
RUN apt-get -y -t experimental install libqt5remoteobjects5
COPY --from=builder /usr/local/bin/* /usr/local/bin/
COPY --from=builder /usr/local/lib/libqt* /usr/local/lib/
COPY --from=builder /usr/local/lib*/libopenzwave* /usr/local/lib/
COPY --from=builder /usr/lib/*/libQt5Mqtt* /usr/local/lib/
COPY --from=builder /opt/qt-openzwave/tools/* /usr/local/bin/
RUN mkdir -p /opt/ozw/config/crashes/
ENV LD_LIBRARY_PATH="/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATH"
ENV USBPATH="/dev/ttyUSB0"
ENV MQTT_SERVER="localhost"
ENV MQTT_PORT="1883"
ENV OZW_INSTANCE="1"
ENV BP_DB_PATH="/opt/ozw/config/crashes/"
WORKDIR /opt/ozw/
EXPOSE 1983
VOLUME ["/opt/ozw/config/"]
ENTRYPOINT /usr/local/bin/ozwdaemon -s $USBPATH -c /opt/ozw/config/ -u /opt/ozw/config/ --mqtt-server $MQTT_SERVER --mqtt-port $MQTT_PORT --stop-on-failure --mqtt-instance $OZW_INSTANCE

View file

@ -1,2 +1,6 @@
# qt-openzwave
A QT5 Wrapper for OpenZWave. Exposes
A QT5 Wrapper for OpenZWave.
## HASS MQTT Client Adapter
Please see [docs/MQTT.md](docs/MQTT.md) for further information

1179
docs/MQTT.md Executable file

File diff suppressed because it is too large Load diff

0
makeosxbundle.sh Executable file → Normal file
View file

View file

@ -55,7 +55,7 @@ win32 {
} else {
equals(BUILDTYPE, "debug") {
exists ( $$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL/OpenZWaved.dll )) {
LIBS += -L$$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL) -lopenzwaved
LIBS += -L$$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/DebugDLL) -lOpenZWaved
OZW_LIB_PATH = $$absolute_path($$top_srcdir/../open-zwave/cpp/build/windows/vs2010/ReleaseDLL)
} else {
error("Can't find a copy of OpenZWaved.dll in the DebugDLL Directory");

View file

@ -114,6 +114,7 @@ public:
*/
QTOZWManager *GetManager();
QString getVersion();
private:
QTOZWManager *m_manager;
QDir m_ozwdbpath;

View file

@ -52,8 +52,8 @@ struct NodeStatistics {
quint32 receivedPackets; /**< Number of received Packets from the Node */
quint32 receivedDupPackets; /**< Number of Duplicate Packets received from the Node */
quint32 receivedUnsolicited; /**< Number of Unsolicited Packets received from the Node */
QString lastSentTimeStamp; /**< TimeStamp of the Last time we sent a packet to the Node */
QString lastReceivedTimeStamp; /**< Timestamp of the last time we received a packet from the Node */
QDateTime lastSentTimeStamp; /**< TimeStamp of the Last time we sent a packet to the Node */
QDateTime lastReceivedTimeStamp; /**< Timestamp of the last time we received a packet from the Node */
quint32 lastRequestRTT; /**< Last Round-Trip Time when we made a request to the Node */
quint32 averageRequestRTT; /**< Average Round-Trip Time when we make requests to a Node */
quint32 lastResponseRTT; /**< Last Round-Trip Time when we got a Response from a Node */
@ -180,6 +180,87 @@ inline QDataStream &operator>>(QDataStream &ds, NodeStatistics &obj) {
/** \endcond
*/
/** \brief Statistics Relating to Communications with the Network
*/
struct DriverStatistics {
quint32 m_SOFCnt;
quint32 m_ACKWaiting;
quint32 m_readAborts;
quint32 m_badChecksum;
quint32 m_readCnt;
quint32 m_writeCnt;
quint32 m_CANCnt;
quint32 m_NAKCnt;
quint32 m_ACKCnt;
quint32 m_OOFCnt;
quint32 m_dropped;
quint32 m_retries;
quint32 m_callbacks;
quint32 m_badroutes;
quint32 m_noack;
quint32 m_netbusy;
quint32 m_notidle;
quint32 m_txverified;
quint32 m_nondelivery;
quint32 m_routedbusy;
quint32 m_broadcastReadCnt;
quint32 m_broadcastWriteCnt;
};
Q_DECLARE_METATYPE(DriverStatistics)
inline QDataStream &operator<<(QDataStream &ds, const DriverStatistics &obj) {
ds << static_cast<quint32>(obj.m_SOFCnt);
ds << static_cast<quint32>(obj.m_ACKWaiting);
ds << static_cast<quint32>(obj.m_readAborts);
ds << static_cast<quint32>(obj.m_badChecksum);
ds << static_cast<quint32>(obj.m_readCnt);
ds << static_cast<quint32>(obj.m_writeCnt);
ds << static_cast<quint32>(obj.m_CANCnt);
ds << static_cast<quint32>(obj.m_NAKCnt);
ds << static_cast<quint32>(obj.m_ACKCnt);
ds << static_cast<quint32>(obj.m_OOFCnt);
ds << static_cast<quint32>(obj.m_dropped);
ds << static_cast<quint32>(obj.m_retries);
ds << static_cast<quint32>(obj.m_callbacks);
ds << static_cast<quint32>(obj.m_badroutes);
ds << static_cast<quint32>(obj.m_noack);
ds << static_cast<quint32>(obj.m_netbusy);
ds << static_cast<quint32>(obj.m_notidle);
ds << static_cast<quint32>(obj.m_txverified);
ds << static_cast<quint32>(obj.m_nondelivery);
ds << static_cast<quint32>(obj.m_routedbusy);
ds << static_cast<quint32>(obj.m_broadcastReadCnt);
ds << static_cast<quint32>(obj.m_broadcastWriteCnt);
return ds;
}
inline QDataStream &operator>>(QDataStream &ds, DriverStatistics &obj) {
ds >> obj.m_SOFCnt;
ds >> obj.m_ACKWaiting;
ds >> obj.m_readAborts;
ds >> obj.m_badChecksum;
ds >> obj.m_readCnt;
ds >> obj.m_writeCnt;
ds >> obj.m_CANCnt;
ds >> obj.m_NAKCnt;
ds >> obj.m_ACKCnt;
ds >> obj.m_OOFCnt;
ds >> obj.m_dropped;
ds >> obj.m_retries;
ds >> obj.m_callbacks;
ds >> obj.m_badroutes;
ds >> obj.m_noack;
ds >> obj.m_netbusy;
ds >> obj.m_notidle;
ds >> obj.m_txverified;
ds >> obj.m_nondelivery;
ds >> obj.m_routedbusy;
ds >> obj.m_broadcastReadCnt;
ds >> obj.m_broadcastWriteCnt;
return ds;
}
/** \brief Represents a ENUM list for a Single Option
*
* Some of the Options available in the QTOZW_Options class are
@ -269,5 +350,153 @@ inline QDataStream &operator>>(QDataStream &ds, OptionList &obj) {
/** \endcond
*/
class NotificationTypes : public QObject {
Q_OBJECT;
public:
enum QTOZW_Notification_Code {
Notification_Code_MsgComplete = 0,
Notification_Code_MsgTimeout = 1,
Notification_Code_NoOperation = 2,
Notification_Code_NodeAwake = 3,
Notification_Code_NodeAsleep = 4,
Notification_Code_NodeDead = 5,
Notification_Code_NodeAlive = 6,
Notification_Code_count
};
Q_ENUM(QTOZW_Notification_Code);
enum QTOZW_Notification_User {
Notification_User_None = 0,
Notification_User_ConfigOutOfDate = 1,
Notification_User_MFSOutOfDate = 2,
Notification_User_ConfigFileDownloadFailed = 3,
Notification_User_DNSError = 4,
Notification_User_NodeReloadRequired = 5,
Notification_User_UnsupportedController = 6,
Notification_User_ApplicationStatus_Retry = 7,
Notification_User_ApplicationStatus_Queued = 8,
Notification_User_ApplicationStatus_Rejected = 9,
Notification_User_count
};
Q_ENUM(QTOZW_Notification_User);
enum QTOZW_Notification_Controller_Error {
Ctrl_Error_None = 0,
Ctrl_Error_ButtonNotFound = 1,
Ctrl_Error_NodeNotFound = 2,
Ctrl_Error_NotBridge = 3,
Ctrl_Error_NotSUC = 4,
Ctrl_Error_NotSecondary = 5,
Ctrl_Error_NotPrimary = 6,
Ctrl_Error_IsPrimary = 7,
Ctrl_Error_NotFound = 8,
Ctrl_Error_Busy = 9,
Ctrl_Error_Failed = 10,
Ctrl_Error_Disabled = 11,
Ctrl_Error_OverFlow = 12,
Ctrl_Error_count
};
Q_ENUM(QTOZW_Notification_Controller_Error);
enum QTOZW_Notification_Controller_State {
Ctrl_State_Normal = 0,
Ctrl_State_Starting = 1,
Ctrl_State_Cancel = 2,
Ctrl_State_Error = 3,
Ctrl_State_Waiting = 4,
Ctrl_State_Sleeping = 5,
Ctrl_State_InProgress = 6,
Ctrl_State_Completed = 7,
Ctrl_State_Failed = 8,
Ctrl_State_NodeOk = 9,
Ctrl_State_NodeFailed = 10,
Ctrl_State_count
};
Q_ENUM(QTOZW_Notification_Controller_State);
enum QTOZW_Notification_Controller_Cmd {
Ctrl_Cmd_None = 0,
Ctrl_Cmd_AddNode = 1,
Ctrl_Cmd_CreateNewPrimary = 2,
Ctrl_Cmd_ReceiveConfiguration = 3,
Ctrl_Cmd_RemoveNode = 4,
Ctrl_Cmd_RemoveFailedNode = 5,
Ctrl_Cmd_HasNodeFailed = 6,
Ctrl_Cmd_ReplaceFailedNode = 7,
Ctrl_Cmd_TransferPrimaryRole = 8,
Ctrl_Cmd_RequestNetworkUpdate = 9,
Ctrl_Cmd_RequestNodeNeighborUpdate = 10,
Ctrl_Cmd_AssignReturnRoute = 11,
Ctrl_Cmd_DeleteAllReturnRoute = 12,
Ctrl_Cmd_SendNodeInformation = 13,
Ctrl_Cmd_ReplicationSend = 14,
Ctrl_Cmd_CreateButton = 15,
Ctrl_Cmd_DeleteButton = 16,
Ctrl_Cmd_count
};
Q_ENUM(QTOZW_Notification_Controller_Cmd);
};
Q_DECLARE_METATYPE(NotificationTypes::QTOZW_Notification_Code)
inline QDataStream &operator<<(QDataStream &ds, const NotificationTypes::QTOZW_Notification_Code &obj) {
ds << static_cast<qint32>(obj);
return ds;
}
inline QDataStream &operator>>(QDataStream &ds, NotificationTypes::QTOZW_Notification_Code &obj) {
ds >> obj;
return ds;
}
Q_DECLARE_METATYPE(NotificationTypes::QTOZW_Notification_User)
inline QDataStream &operator<<(QDataStream &ds, const NotificationTypes::QTOZW_Notification_User &obj) {
ds << static_cast<qint32>(obj);
return ds;
}
inline QDataStream &operator>>(QDataStream &ds, NotificationTypes::QTOZW_Notification_User &obj) {
ds >> obj;
return ds;
}
Q_DECLARE_METATYPE(NotificationTypes::QTOZW_Notification_Controller_Error)
inline QDataStream &operator<<(QDataStream &ds, const NotificationTypes::QTOZW_Notification_Controller_Error &obj) {
ds << static_cast<qint32>(obj);
return ds;
}
inline QDataStream &operator>>(QDataStream &ds, NotificationTypes::QTOZW_Notification_Controller_Error &obj) {
ds >> obj;
return ds;
}
Q_DECLARE_METATYPE(NotificationTypes::QTOZW_Notification_Controller_State)
inline QDataStream &operator<<(QDataStream &ds, const NotificationTypes::QTOZW_Notification_Controller_State &obj) {
ds << static_cast<qint32>(obj);
return ds;
}
inline QDataStream &operator>>(QDataStream &ds, NotificationTypes::QTOZW_Notification_Controller_State &obj) {
ds >> obj;
return ds;
}
Q_DECLARE_METATYPE(NotificationTypes::QTOZW_Notification_Controller_Cmd)
inline QDataStream &operator<<(QDataStream &ds, const NotificationTypes::QTOZW_Notification_Controller_Cmd &obj) {
ds << static_cast<qint32>(obj);
return ds;
}
inline QDataStream &operator>>(QDataStream &ds, NotificationTypes::QTOZW_Notification_Controller_Cmd &obj) {
ds >> obj;
return ds;
}
#endif // QTOZW_PODS_H

View file

@ -76,6 +76,7 @@ public:
/* OpenZWave::Manager methods */
bool open(QString serialPort);
bool close();
bool refreshNodeInfo(quint8 _node);
bool requestNodeState(quint8 _node);
bool requestNodeDynamic(quint8 _node);
@ -100,7 +101,7 @@ public:
bool requestNodeNeighborUpdate(quint8 _node);
bool assignReturnRoute(quint8 _node);
bool deleteAllReturnRoute(quint8 _node);
bool sendNodeInfomation(quint8 _node);
bool sendNodeInformation(quint8 _node);
bool replaceFailedNode(quint8 _node);
bool requestNetworkUpdate(quint8 _node);
QString GetMetaData(quint8 _node, QTOZWManagerSource::QTOZWMetaDataField _field);
@ -108,6 +109,8 @@ public:
QString GetNodeQueryStage(quint8 const _node);
NodeStatistics GetNodeStatistics(quint8 const node);
DriverStatistics GetDriverStatistics();
QVector<quint8> GetNodeNeighbors(quint8 const node);
bool IsNodeFailed(const quint8 _node);
bool checkLatestConfigFileRevision(quint8 const _node);
@ -115,6 +118,30 @@ public:
bool downloadLatestConfigFileRevision(quint8 const _node);
bool downloadLatestMFSRevision();
QString getCommandClassString(quint8 const _cc);
QString getVersionAsString();
QString getVersionLongAsString();
quint8 getControllerNodeId();
quint8 getSucNodeId();
bool isPrimaryController();
bool isStaticUpdateController();
bool isBridgeController();
bool hasExtendedTXStatus();
QString getLibraryVersion();
QString getLibraryTypeName();
quint32 getSendQueueCount();
QString getControllerPath();
qint32 getPollInterval();
void setPollInterval(qint32 interval, bool intervalBetweenPolls);
void syncroniseNodeNeighbors(quint8 node);
bool refreshValue(quint64);
/* Property Methods */
QDir OZWDatabasePath() { return this->m_ozwdatabasepath; }
QDir OZWUserPath() { return this->m_ozwuserpath; }
@ -137,6 +164,7 @@ Q_SIGNALS:
void nodeProtocolInfo(quint8 node);
void nodeEssentialNodeQueriesComplete(quint8 node);
void nodeQueriesComplete(quint8 node);
void nodeGroupChanged(quint8 node, quint8 group);
void driverReady(quint32 homeID);
void driverFailed(quint32 homeID);
void driverReset(quint32 homeID);
@ -144,9 +172,9 @@ Q_SIGNALS:
void driverAllNodesQueriedSomeDead();
void driverAllNodesQueried();
void driverAwakeNodesQueried();
void controllerCommand(quint8 command);
// void ozwNotification(OpenZWave::Notification::NotificationCode event);
// void ozwUserAlert(OpenZWave::Notification::UserAlertNotification event);
void controllerCommand(quint8 node, NotificationTypes::QTOZW_Notification_Controller_Cmd command, NotificationTypes::QTOZW_Notification_Controller_State state, NotificationTypes::QTOZW_Notification_Controller_Error error);
void ozwNotification(quint8 node, NotificationTypes::QTOZW_Notification_Code event);
void ozwUserAlert(quint8 node, NotificationTypes::QTOZW_Notification_User event, quint8 retry);
void manufacturerSpecificDBReady();
void starting();

View file

@ -75,6 +75,7 @@ class QTOZWManager {
SIGNAL(nodeProtocolInfo(quint8 node))
SIGNAL(nodeEssentialNodeQueriesComplete(quint8 node))
SIGNAL(nodeQueriesComplete(quint8 node))
SIGNAL(nodeGroupChanged(quint8 node, quint8 group))
SIGNAL(driverReady(quint32 homeID))
SIGNAL(driverFailed(quint32 homeID))
SIGNAL(driverReset(quint32 homeID))
@ -82,9 +83,9 @@ class QTOZWManager {
SIGNAL(driverAllNodesQueriedSomeDead())
SIGNAL(driverAllNodesQueried())
SIGNAL(driverAwakeNodesQueried())
SIGNAL(controllerCommand(quint8 command))
// SIGNAL(ozwNotification(OpenZWave::Notification::NotificationCode event))
// SIGNAL(ozwUserAlert(OpenZWave::Notification::UserAlertNotification event))
SIGNAL(controllerCommand(quint8 node, NotificationTypes::QTOZW_Notification_Controller_Cmd command, NotificationTypes::QTOZW_Notification_Controller_State state, NotificationTypes::QTOZW_Notification_Controller_Error error))
SIGNAL(ozwNotification(quint8 node, NotificationTypes::QTOZW_Notification_Code event))
SIGNAL(ozwUserAlert(quint8 node, NotificationTypes::QTOZW_Notification_User event, quint8 retry))
SIGNAL(manufacturerSpecificDBReady())
SIGNAL(starting());
@ -93,6 +94,7 @@ class QTOZWManager {
SIGNAL(error(QTOZWManagerErrorCodes errorcode))
SLOT(bool open(QString serialPort))
SLOT(bool close())
SLOT(bool refreshNodeInfo(quint8 _node))
SLOT(bool requestNodeState(quint8 _node))
SLOT(bool requestNodeDynamic(quint8 _node))
@ -115,7 +117,7 @@ class QTOZWManager {
SLOT(bool requestNodeNeighborUpdate(quint8 _node))
SLOT(bool assignReturnRoute(quint8 _node))
SLOT(bool deleteAllReturnRoute(quint8 _node))
SLOT(bool sendNodeInfomation(quint8 _node))
SLOT(bool sendNodeInformation(quint8 _node))
SLOT(bool replaceFailedNode(quint8 _node))
SLOT(bool requestNetworkUpdate(quint8 _node))
@ -124,10 +126,32 @@ class QTOZWManager {
SLOT(QString GetNodeQueryStage(quint8 _node))
SLOT(NodeStatistics GetNodeStatistics(quint8 _node))
SLOT(DriverStatistics GetDriverStatistics())
SLOT(QVector<quint8> GetNodeNeighbors(quint8 const _node))
SLOT(bool IsNodeFailed(quint8 _node))
SLOT(bool checkLatestConfigFileRevision(quint8 const _node))
SLOT(bool checkLatestMFSRevision())
SLOT(bool downloadLatestConfigFileRevision(quint8 const _node))
SLOT(bool downloadLatestMFSRevision())
SLOT(QString getCommandClassString(quint8 const _cc))
}
SLOT(QString getVersionAsString())
SLOT(QString getVersionLongAsString())
SLOT(quint8 getControllerNodeId())
SLOT(quint8 getSucNodeId())
SLOT(bool isPrimaryController())
SLOT(bool isStaticUpdateController())
SLOT(bool isBridgeController())
SLOT(bool hasExtendedTXStatus())
SLOT(QString getLibraryVersion())
SLOT(QString getLibraryTypeName())
SLOT(quint32 getSendQueueCount())
SLOT(QString getControllerPath())
SLOT(bool refreshValue(quint64))
SLOT(qint32 getPollInterval())
SLOT(void setPollInterval(qint32 interval, bool intervalBetweenPolls))
SLOT(void syncroniseNodeNeighbors(quint8 node))
}

View file

@ -93,6 +93,6 @@ protected:
QVariant getNodeData(quint8, NodeColumns);
int32_t getNodeRow(quint8 _node);
QMap<int32_t, QMap<NodeColumns, QVariant> > m_nodeData;
QVector< QMap<NodeColumns, QVariant> > m_nodeData;
};
#endif // QTOZWNODEMODEL_H

View file

@ -120,7 +120,7 @@ protected:
QVariant getValueData(quint64, ValueIdColumns);
int32_t getValueRow(quint64 _node);
QMap<int32_t, QMap<ValueIdColumns, QVariant> > m_valueData;
QVector< QMap<ValueIdColumns, QVariant> > m_valueData;
};
#endif // QTOZWVALUEIDMODEL_H

View file

@ -49,6 +49,8 @@
#include "Notification.h"
#include "platform/Log.h"
#include "OZWException.h"
#include "command_classes/CommandClasses.h"
class QTOZWManager_Internal : public QTOZWManagerSimpleSource
@ -67,6 +69,7 @@ public:
public Q_SLOTS:
bool open(QString serialPort);
bool close();
bool refreshNodeInfo(quint8 _node);
bool requestNodeState(quint8 _node);
bool requestNodeDynamic(quint8 _node);
@ -91,7 +94,7 @@ public Q_SLOTS:
bool requestNodeNeighborUpdate(quint8 _node);
bool assignReturnRoute(quint8 _node);
bool deleteAllReturnRoute(quint8 _node);
bool sendNodeInfomation(quint8 _node);
bool sendNodeInformation(quint8 _node);
bool replaceFailedNode(quint8 _node);
bool requestNetworkUpdate(quint8 _node);
QString GetMetaData(quint8 _node, QTOZWManagerSource::QTOZWMetaDataField _field);
@ -99,7 +102,10 @@ public Q_SLOTS:
QString GetNodeQueryStage(quint8 const node);
NodeStatistics GetNodeStatistics(quint8 const node);
DriverStatistics GetDriverStatistics();
QVector<quint8> GetNodeNeighbors(quint8 const node);
bool IsNodeFailed(quint8 const _node);
bool checkLatestConfigFileRevision(quint8 const _node);
@ -107,6 +113,27 @@ public Q_SLOTS:
bool downloadLatestConfigFileRevision(quint8 const _node);
bool downloadLatestMFSRevision();
QString getCommandClassString(quint8 const _cc);
QString getVersionAsString();
QString getVersionLongAsString();
quint8 getControllerNodeId();
quint8 getSucNodeId();
bool isPrimaryController();
bool isStaticUpdateController();
bool isBridgeController();
bool hasExtendedTXStatus();
QString getLibraryVersion();
QString getLibraryTypeName();
quint32 getSendQueueCount();
QString getControllerPath();
qint32 getPollInterval();
void setPollInterval(qint32 interval, bool intervalBetweenPolls);
void syncroniseNodeNeighbors(quint8 node);
bool refreshValue(quint64);
/* these slots are called from our OZWNotification Class. Applications should not call them */
void pvt_valueAdded(quint64 vidKey);
@ -132,9 +159,9 @@ public Q_SLOTS:
void pvt_driverAllNodesQueriedSomeDead();
void pvt_driverAllNodesQueried();
void pvt_driverAwakeNodesQueried();
void pvt_controllerCommand(quint8 command);
void pvt_ozwNotification(OpenZWave::Notification::NotificationCode event);
void pvt_ozwUserAlert(OpenZWave::Notification::UserAlertNotification event);
void pvt_controllerCommand(quint8 node, quint32 cmd, quint32 state, quint32 error);
void pvt_ozwNotification(quint8 node, quint32 event);
void pvt_ozwUserAlert(quint8 node, quint32 event, quint8 retry);
void pvt_manufacturerSpecificDBReady();
void pvt_nodeModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
@ -157,7 +184,7 @@ private:
QVector<quint8> m_validNodes;
QVector<quint64> m_validValues;
QMap<quint8, QMap<quint8, bool > > m_associationDefaultsSet;
QString m_SerialPort;
};

View file

@ -44,6 +44,7 @@ public Q_SLOTS:
void delNode(quint8 _nodeID);
void resetModel();
void finishTransaction(quint8 _nodeID);
};

View file

@ -32,6 +32,7 @@
#include <QObject>
#include "Notification.h"
#include "Driver.h"
class OZWNotification : public QObject {
Q_OBJECT
@ -64,9 +65,9 @@ signals:
void driverAllNodesQueriedSomeDead();
void driverAwakeNodesQueried();
void driverAllNodesQueried();
void controllerCommand(quint8 command);
void ozwNotification(OpenZWave::Notification::NotificationCode event);
void ozwUserAlert(OpenZWave::Notification::UserAlertNotification event);
void controllerCommand(quint8 node, quint32 cmd, quint32 state, quint32 error);
void ozwNotification(quint8 node, quint32 event);
void ozwUserAlert(quint8 node, quint32 event, quint8 retry);
void manufacturerSpecificDBReady();
//-----------------------------------------------------------------------------
// <OZWNotification::processNotification>

View file

@ -45,6 +45,8 @@ public Q_SLOTS:
void delNodeValues(quint8 _node);
void resetModel();
void finishTransaction(quint64 _vidKey);
QVariant getValueData(quint64, ValueIdColumns);
};

View file

@ -13,7 +13,7 @@ TEMPLATE = lib
VERSION = 1.0.0
CONFIG += silent file_copies
CONFIG += silent file_copies force_debug_info
!versionAtLeast(QT_VERSION, 5.11.2):error("Use at least Qt version 5.11.2")
include(../qt-openzwave.pri)
@ -30,7 +30,7 @@ DEFINES += QTOPENZWAVE_LIBRARY
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DEPRECATED_WARNINGS QT_MESSAGELOGCONTEXT LIB_VERSION=$$VERSION
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
@ -87,6 +87,10 @@ COPIES += copyrepheaders
unix {
target.path = /usr/local/lib
INSTALLS += target
QMAKE_CXXFLAGS += -g
QMAKE_CFLAGS += -g
QMAKE_LFLAGS += -rdynamic
QMAKE_STRIP = echo
}
#LIBS += -L../../open-zwave -lopenzwave
@ -95,6 +99,13 @@ macx {
QMAKE_POST_LINK=$$top_srcdir/updaterpath.sh $(TARGET)
}
QMAKE_CFLAGS_RELEASE -= -O
QMAKE_CFLAGS_RELEASE -= -O1
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE -= -O
QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE -= -O2
message(" ")
message("Summary:")
message(" OpenZWave Path: $$OZW_LIB_PATH")

View file

@ -37,7 +37,24 @@ QTOpenZwave::QTOpenZwave
qRegisterMetaType<OptionList>("OptionList");
qRegisterMetaTypeStreamOperators<OptionList>("OptionList");
qSetMessagePattern("%{category} %{message}");
qRegisterMetaType<NotificationTypes::QTOZW_Notification_Code>("NotificationTypes::QTOZW_Notification_Code");
qRegisterMetaTypeStreamOperators<NotificationTypes::QTOZW_Notification_Code>("NotificationTypes::QTOZW_Notification_Code");
qRegisterMetaType<NotificationTypes::QTOZW_Notification_User>("NotificationTypes::QTOZW_Notification_User>");
qRegisterMetaTypeStreamOperators<NotificationTypes::QTOZW_Notification_User>("NotificationTypes::QTOZW_Notification_User>");
qRegisterMetaType<NotificationTypes::QTOZW_Notification_Controller_Error>("NotificationTypes::QTOZW_Notification_Controller_Error");
qRegisterMetaTypeStreamOperators<NotificationTypes::QTOZW_Notification_Controller_Error>("NotificationTypes::QTOZW_Notification_Controller_Error");
qRegisterMetaType<NotificationTypes::QTOZW_Notification_Controller_State>("NotificationTypes::QTOZW_Notification_Controller_State");
qRegisterMetaTypeStreamOperators<NotificationTypes::QTOZW_Notification_Controller_State>("NotificationTypes::QTOZW_Notification_Controller_State");
qRegisterMetaType<NotificationTypes::QTOZW_Notification_Controller_Cmd>("NotificationTypes::QTOZW_Notification_Controller_Cmd");
qRegisterMetaTypeStreamOperators<NotificationTypes::QTOZW_Notification_Controller_Cmd>("NotificationTypes::QTOZW_Notification_Controller_Cmd");
// qSetMessagePattern("[%{time yyyyMMdd h:mm:ss.zzz t}] %{category} %{file}:%{line}:%{function}: %{message}");
qSetMessagePattern("[%{time yyyyMMdd h:mm:ss.zzz t}] [%{category}] [%{type}]: %{message}");
}
QTOZWManager *QTOpenZwave::GetManager
@ -51,3 +68,10 @@ QTOZWManager *QTOpenZwave::GetManager
}
return this->m_manager;
}
#define VAL(str) #str
#define TOSTRING(str) VAL(str)
QString QTOpenZwave::getVersion() {
return TOSTRING(LIB_VERSION);
}

View file

@ -94,17 +94,15 @@ void QTOZW_Associations_internal::setGroupFlags(quint8 _nodeID, quint8 _groupIDX
};
void QTOZW_Associations_internal::delNode(quint8 _nodeID) {
for (int i = 0; i <= rowCount(QModelIndex()); i++) {
if (this->m_associationData[i][associationColumns::NodeID] == _nodeID) {
qCDebug(associationModel) << "Removing Node " << this->m_associationData[i][associationColumns::NodeID] << i;
this->beginRemoveRows(QModelIndex(), i, i);
this->m_associationData.remove(i);
for (int j = i+1; i <= rowCount(QModelIndex()); j++) {
this->m_associationData[i] = this->m_associationData[j];
}
this->m_associationData.remove(rowCount(QModelIndex()));
QMap<qint32, QMap<QTOZW_Associations::associationColumns, QVariant> >::Iterator it;
for (it = this->m_associationData.begin(); it != this->m_associationData.end();) {
if (it.value()[associationColumns::NodeID] == _nodeID) {
qCDebug(associationModel) << "Removing Node " << it.value()[associationColumns::NodeID] << it.key();
this->beginRemoveRows(QModelIndex(), it.key(), it.key());
it = this->m_associationData.erase(it);
this->endRemoveRows();
continue;
} else {
it++;
}
}
}
@ -116,7 +114,7 @@ void QTOZW_Associations_internal::addAssociation(quint8 _nodeID, quint8 _groupID
return;
}
QString target;
target.append(QString::number(_targetNode)).append(":").append(QString::number(_targetInstance));
target.append(QString::number(_targetNode)).append(".").append(QString::number(_targetInstance));
QStringList targetlist = this->m_associationData[row][associationColumns::Members].toStringList();
if (targetlist.contains(target)) {
qCWarning(associationModel) << "addAssociation: Target " << target << "already exists in Group " << _groupIDX << "for node " << _nodeID;
@ -136,7 +134,7 @@ void QTOZW_Associations_internal::delAssociation(quint8 _nodeID, quint8 _groupID
return;
}
QString target;
target.append(QString::number(_targetNode)).append(":").append(QString::number(_targetInstance));
target.append(QString::number(_targetNode)).append(".").append(QString::number(_targetInstance));
QStringList targetlist = this->m_associationData[row][associationColumns::Members].toStringList();
if (!targetlist.contains(target)) {
qCWarning(associationModel) << "delAssociation: Target " << target << "does not exist in Group " << _groupIDX << "for node " << _nodeID;
@ -156,7 +154,7 @@ bool QTOZW_Associations_internal::findAssociation(quint8 _nodeID, quint8 _groupI
return false;
}
QString target;
target.append(QString::number(_targetNode)).append(":").append(QString::number(_targetInstance));
target.append(QString::number(_targetNode)).append(".").append(QString::number(_targetInstance));
QStringList targetlist = this->m_associationData[row][associationColumns::Members].toStringList();
if (!targetlist.contains(target)) {
return false;

View file

@ -92,12 +92,12 @@ void QTOZW_Log_Internal::Write(OpenZWave::LogLevel _level, uint8 const _nodeId,
}
case OpenZWave::LogLevel_Warning: {
qtozwlevel = LogLevels::Warning;
qCCritical(libopenzwave) << "Warning - Node:" << _nodeId << lineBuf;
qCWarning(libopenzwave) << "Warning - Node:" << _nodeId << lineBuf;
break;
}
case OpenZWave::LogLevel_Alert: {
qtozwlevel = LogLevels::Alert;
qCCritical(libopenzwave) << "Alert - Node:" << _nodeId << lineBuf;
qCWarning(libopenzwave) << "Alert - Node:" << _nodeId << lineBuf;
break;
}
case OpenZWave::LogLevel_Info: {

View file

@ -249,6 +249,7 @@ void QTOZWManager::connectSignals() {
CONNECT_DPTR(nodeProtocolInfo);
CONNECT_DPTR(nodeEssentialNodeQueriesComplete);
CONNECT_DPTR(nodeQueriesComplete);
CONNECT_DPTR(nodeGroupChanged);
CONNECT_DPTR(driverReady);
CONNECT_DPTR(driverFailed);
CONNECT_DPTR(driverReset);
@ -257,8 +258,8 @@ void QTOZWManager::connectSignals() {
CONNECT_DPTR(driverAllNodesQueried);
CONNECT_DPTR(driverAwakeNodesQueried);
CONNECT_DPTR(controllerCommand);
// CONNECT_DPTR(ozwNotification);
// CONNECT_DPTR(ozwUserAlert);
CONNECT_DPTR(ozwNotification);
CONNECT_DPTR(ozwUserAlert);
CONNECT_DPTR(manufacturerSpecificDBReady);
CONNECT_DPTR(starting);
CONNECT_DPTR(started);
@ -284,6 +285,9 @@ void QTOZWManager::connectSignals() {
bool QTOZWManager::open(QString serialPort) {
CALL_DPTR_RTN(open(serialPort), bool);
}
bool QTOZWManager::close() {
CALL_DPTR_RTN(close(), bool);
}
bool QTOZWManager::refreshNodeInfo(quint8 _node) {
CALL_DPTR_RTN(refreshNodeInfo(_node), bool);
}
@ -344,8 +348,8 @@ bool QTOZWManager::assignReturnRoute(quint8 _node) {
bool QTOZWManager::deleteAllReturnRoute(quint8 _node) {
CALL_DPTR_RTN(deleteAllReturnRoute(_node), bool);
}
bool QTOZWManager::sendNodeInfomation(quint8 _node) {
CALL_DPTR_RTN(sendNodeInfomation(_node), bool);
bool QTOZWManager::sendNodeInformation(quint8 _node) {
CALL_DPTR_RTN(sendNodeInformation(_node), bool);
}
bool QTOZWManager::replaceFailedNode(quint8 _node) {
CALL_DPTR_RTN(replaceFailedNode(_node), bool)
@ -373,6 +377,15 @@ QString QTOZWManager::GetNodeQueryStage(const quint8 _node) {
NodeStatistics QTOZWManager::GetNodeStatistics(const quint8 _node) {
CALL_DPTR_RTN(GetNodeStatistics(_node), NodeStatistics);
}
DriverStatistics QTOZWManager::GetDriverStatistics() {
CALL_DPTR_RTN(GetDriverStatistics(), DriverStatistics);
}
QVector<quint8> QTOZWManager::GetNodeNeighbors(quint8 const _node) {
CALL_DPTR_RTN(GetNodeNeighbors(_node), QVector<quint8>);
}
bool QTOZWManager::IsNodeFailed(const quint8 _node) {
CALL_DPTR_RTN(IsNodeFailed(_node), bool);
}
@ -389,6 +402,58 @@ bool QTOZWManager::downloadLatestMFSRevision() {
CALL_DPTR_RTN(downloadLatestMFSRevision(), bool);
}
QString QTOZWManager::getCommandClassString(quint8 const _cc) {
CALL_DPTR_RTN(getCommandClassString(_cc), QString);
}
QString QTOZWManager::getVersionAsString() {
CALL_DPTR_RTN(getVersionAsString(), QString);
}
QString QTOZWManager::getVersionLongAsString() {
CALL_DPTR_RTN(getVersionLongAsString(), QString);
}
quint8 QTOZWManager::getControllerNodeId() {
CALL_DPTR_RTN(getControllerNodeId(), quint8);
}
quint8 QTOZWManager::getSucNodeId() {
CALL_DPTR_RTN(getSucNodeId(), quint8);
}
bool QTOZWManager::isPrimaryController() {
CALL_DPTR_RTN(isPrimaryController(), bool);
}
bool QTOZWManager::isStaticUpdateController() {
CALL_DPTR_RTN(isStaticUpdateController(), bool);
}
bool QTOZWManager::isBridgeController() {
CALL_DPTR_RTN(isBridgeController(), bool);
}
bool QTOZWManager::hasExtendedTXStatus() {
CALL_DPTR_RTN(hasExtendedTXStatus(), bool);
}
QString QTOZWManager::getLibraryVersion() {
CALL_DPTR_RTN(getLibraryVersion(), QString);
}
QString QTOZWManager::getLibraryTypeName() {
CALL_DPTR_RTN(getLibraryTypeName(), QString);
}
quint32 QTOZWManager::getSendQueueCount() {
CALL_DPTR_RTN(getSendQueueCount(), quint32);
}
QString QTOZWManager::getControllerPath() {
CALL_DPTR_RTN(getControllerPath(), QString);
}
qint32 QTOZWManager::getPollInterval() {
CALL_DPTR_RTN(getPollInterval(), qint32);
}
void QTOZWManager::setPollInterval(qint32 interval, bool intervalBetweenPolls) {
CALL_DPTR(setPollInterval(interval, intervalBetweenPolls))
}
void QTOZWManager::syncroniseNodeNeighbors(quint8 node) {
CALL_DPTR(syncroniseNodeNeighbors(node));
}
bool QTOZWManager::refreshValue(quint64 vidKey) {
CALL_DPTR_RTN(refreshValue(vidKey), bool);
}
void QTOZWManager::setOZWDatabasePath(QDir path) {
if (path.exists())
this->m_ozwdatabasepath = path;

View file

@ -29,22 +29,6 @@
#include "qtozwmanager_p.h"
#include "qt-openzwave/qtozwmanager.h"
/* XXX TODO: this needs to go into OZW */
QString nodeBasicStr (uint8 basic)
{
switch (basic) {
case 1:
return "Controller";
case 2:
return "Static Controller";
case 3:
return "Slave";
case 4:
return "Routing Slave";
}
return "unknown";
}
QTOZWManager_Internal::QTOZWManager_Internal(QObject *parent)
: QTOZWManagerSimpleSource (parent)
@ -144,7 +128,44 @@ bool QTOZWManager_Internal::open(QString SerialPort)
return false;
}
qCDebug(manager) << "AddDriver Completed";
this->m_SerialPort = SerialPort;
return true;
}
bool QTOZWManager_Internal::close() {
try {
if (this->m_manager->RemoveDriver(this->m_SerialPort.toStdString())) {
qCDebug(manager) << "Driver Removed for " << this->m_SerialPort;
} else {
qCWarning(manager) << "Couldn't Remove Driver for " << this->m_SerialPort;
}
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
qCWarning(manager) << "Failed to Remove Driver: " << QString(e.GetMsg().c_str());
return false;
}
try {
if (this->m_manager->RemoveWatcher(OZWNotification::processNotification, this ) != true) {
emit this->error(QTOZWManagerErrorCodes::setupFailed);
this->setErrorString("Failed to Remove Notification Callback");
qCWarning(manager) << "Failed to Remove Notification Callback";
return false;
}
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
qCWarning(manager) << "Failed to Remove Notification Callback " << QString(e.GetMsg().c_str());
return false;
}
if (OZWNotification::Get()->disconnect() != true) {
emit this->error(QTOZWManagerErrorCodes::setupFailed);
this->setErrorString("Failed to Disconnect Notification Signals");
qCWarning(manager) << "Failed to Disconnect Notification Signals";
return false;
}
qCDebug(manager) << "OZW Serial Port Closed";
this->m_SerialPort = QString();
return true;
}
@ -379,7 +400,7 @@ bool QTOZWManager_Internal::deleteAllReturnRoute(quint8 _node) {
}
return false;
}
bool QTOZWManager_Internal::sendNodeInfomation(quint8 _node) {
bool QTOZWManager_Internal::sendNodeInformation(quint8 _node) {
if (!this->checkHomeId() || !this->checkNodeId(_node))
return false;
try {
@ -494,13 +515,14 @@ NodeStatistics QTOZWManager_Internal::GetNodeStatistics(quint8 const _node) {
ns.receivedPackets = nd.m_receivedCnt;
ns.lastFailedLinkTo = nd.m_lastFailedLinkTo;
ns.averageRequestRTT = nd.m_averageRequestRTT;
ns.lastSentTimeStamp = nd.m_sentTS.c_str();
/* 2019-11-06 21:11:02:549 */
ns.lastSentTimeStamp = QDateTime::fromString(QString::fromStdString(nd.m_sentTS).trimmed(), "yyyy-MM-dd HH:mm:ss:zzz");
ns.lastReceivedTimeStamp = QDateTime::fromString(QString::fromStdString(nd.m_receivedTS).trimmed(), "yyyy-MM-dd HH:mm:ss:zzz");
ns.averageResponseRTT = nd.m_averageResponseRTT;
ns.lastFailedLinkFrom = nd.m_lastFailedLinkFrom;
ns.receivedDupPackets = nd.m_receivedDups;
ns.extendedTXSupported = nd.m_txStatusReportSupported;
ns.receivedUnsolicited = nd.m_receivedUnsolicited;
ns.lastReceivedTimeStamp = nd.m_receivedTS.c_str();
return ns;
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
@ -510,6 +532,65 @@ NodeStatistics QTOZWManager_Internal::GetNodeStatistics(quint8 const _node) {
}
DriverStatistics QTOZWManager_Internal::GetDriverStatistics() {
if (!this->checkHomeId())
return DriverStatistics();
try {
OpenZWave::Driver::DriverData dd;
DriverStatistics ds;
this->m_manager->GetDriverStatistics(this->homeId(), &dd);
/* copy */
ds.m_SOFCnt = dd.m_SOFCnt;
ds.m_ACKWaiting = dd.m_ACKWaiting;
ds.m_readAborts = dd.m_readAborts;
ds.m_badChecksum = dd.m_badChecksum;
ds.m_readCnt = dd.m_readCnt;
ds.m_writeCnt = dd.m_writeCnt;
ds.m_CANCnt = dd.m_CANCnt;
ds.m_NAKCnt = dd.m_NAKCnt;
ds.m_ACKCnt = dd.m_ACKCnt;
ds.m_OOFCnt = dd.m_OOFCnt;
ds.m_dropped = dd.m_dropped;
ds.m_retries = dd.m_retries;
ds.m_callbacks = dd.m_callbacks;
ds.m_badroutes = dd.m_badroutes;
ds.m_noack = dd.m_noack;
ds.m_netbusy = dd.m_netbusy;
ds.m_notidle = dd.m_notidle;
ds.m_txverified = dd.m_txverified;
ds.m_nondelivery = dd.m_nondelivery;
ds.m_routedbusy = dd.m_routedbusy;
ds.m_broadcastReadCnt = dd.m_broadcastReadCnt;
ds.m_broadcastWriteCnt = dd.m_broadcastWriteCnt;
return ds;
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return DriverStatistics();
}
QVector<quint8> QTOZWManager_Internal::GetNodeNeighbors(quint8 const _node) {
if (!this->checkHomeId() || !this->checkNodeId(_node))
return QVector<quint8>();
try {
uint8 *neighbours;
int size = this->m_manager->GetNodeNeighbors(this->homeId(), _node, &neighbours);
QVector<quint8> data;
for (int i = 0; i < size; i++) {
data.append(neighbours[i]);
}
delete[] neighbours;
return data;
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return QVector<quint8>();
}
bool QTOZWManager_Internal::IsNodeFailed(quint8 const _node) {
if (!this->checkHomeId() || !this->checkNodeId(_node))
return false;
@ -571,6 +652,197 @@ bool QTOZWManager_Internal::downloadLatestMFSRevision() {
return false;
}
QString QTOZWManager_Internal::getCommandClassString(quint8 const _cc) {
try {
return this->m_manager->GetCommandClassName(_cc).c_str();
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return QString();
}
QString QTOZWManager_Internal::getVersionAsString() {
try {
return this->m_manager->getVersionAsString().c_str();
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return QString();
}
QString QTOZWManager_Internal::getVersionLongAsString() {
try {
return this->m_manager->getVersionLongAsString().c_str();
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return QString();
}
quint8 QTOZWManager_Internal::getControllerNodeId() {
if (!this->checkHomeId())
return 0;
try {
return this->m_manager->GetControllerNodeId(this->homeId());
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return 0;
}
quint8 QTOZWManager_Internal::getSucNodeId() {
if (!this->checkHomeId())
return 0;
try {
return this->m_manager->GetSUCNodeId(this->homeId());
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return 0;
}
bool QTOZWManager_Internal::isPrimaryController() {
if (!this->checkHomeId())
return false;
try {
return this->m_manager->IsPrimaryController(this->homeId());
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return false;
}
bool QTOZWManager_Internal::isStaticUpdateController() {
if (!this->checkHomeId())
return false;
try {
return this->m_manager->IsStaticUpdateController(this->homeId());
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return false;
}
bool QTOZWManager_Internal::isBridgeController() {
if (!this->checkHomeId())
return false;
try {
return this->m_manager->IsBridgeController(this->homeId());
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return false;
}
bool QTOZWManager_Internal::hasExtendedTXStatus() {
if (!this->checkHomeId())
return false;
try {
return this->m_manager->HasExtendedTxStatus(this->homeId());
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return false;
}
QString QTOZWManager_Internal::getLibraryVersion() {
if (!this->checkHomeId())
return QString();
try {
return this->m_manager->GetLibraryVersion(this->homeId()).c_str();
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return QString();
}
QString QTOZWManager_Internal::getLibraryTypeName() {
if (!this->checkHomeId())
return QString();
try {
return this->m_manager->GetLibraryTypeName(this->homeId()).c_str();
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return QString();
}
quint32 QTOZWManager_Internal::getSendQueueCount() {
if (!this->checkHomeId())
return 0;
try {
return this->m_manager->GetSendQueueCount(this->homeId());
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return 0;
}
QString QTOZWManager_Internal::getControllerPath() {
if (!this->checkHomeId())
return QString();
try {
return this->m_manager->GetControllerPath(this->homeId()).c_str();
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return QString();
}
qint32 QTOZWManager_Internal::getPollInterval() {
try {
return this->m_manager->GetPollInterval();
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return 0;
}
void QTOZWManager_Internal::setPollInterval(qint32 interval, bool intervalBetweenPolls) {
if (!this->checkHomeId())
return;
try {
this->m_manager->SetPollInterval(interval, intervalBetweenPolls);
return;
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return;
}
void QTOZWManager_Internal::syncroniseNodeNeighbors(quint8 node) {
if (!this->checkHomeId())
return;
if (!this->checkNodeId(node))
return;
try {
this->m_manager->SyncronizeNodeNeighbors(this->homeId(), node);
return;
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return;
}
bool QTOZWManager_Internal::refreshValue(quint64 vidKey) {
if (!this->checkHomeId())
return false;
if (!this->checkValueKey(vidKey))
return false;
try {
OpenZWave::ValueID vid(this->homeId(), vidKey);
return this->m_manager->RefreshValue(vid);
} catch (OpenZWave::OZWException &e) {
emit this->error(QTOZWManagerErrorCodes::OZWException);
this->setErrorString(e.GetMsg().c_str());
}
return false;
}
QTOZW_Nodes *QTOZWManager_Internal::getNodeModel() {
return static_cast<QTOZW_Nodes *>(this->m_nodeModel);
}
@ -697,6 +969,7 @@ bool QTOZWManager_Internal::convertValueID(quint64 vidKey) {
}
case OpenZWave::ValueID::ValueType_Schedule:
{
qCWarning(manager) << "ValueType_Schedule Not Implemented for convertValueID";
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Type, QTOZW_ValueIds::ValueIdTypes::Schedule, true);
this->m_valueModel->finishTransaction(vidKey);
return true;
@ -721,14 +994,23 @@ bool QTOZWManager_Internal::convertValueID(quint64 vidKey) {
}
case OpenZWave::ValueID::ValueType_Button:
{
bool value;
this->m_manager->GetValueAsBool(vid, &value);
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Value, QVariant::fromValue(value), true);
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Type, QTOZW_ValueIds::ValueIdTypes::Button, true);
this->m_valueModel->finishTransaction(vidKey);
return true;
}
case OpenZWave::ValueID::ValueType_Raw:
{
uint8* rawval;
uint8 length; // strangely GetValueAsRaw wants uint8
this->m_manager->GetValueAsRaw(vid, &rawval, &length);
QByteArray value(value, length);
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Value, QVariant::fromValue(value), true);
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Type, QTOZW_ValueIds::ValueIdTypes::Raw, true);
this->m_valueModel->finishTransaction(vidKey);
delete[] rawval;
return true;
}
case OpenZWave::ValueID::ValueType_BitSet:
@ -771,7 +1053,21 @@ void QTOZWManager_Internal::pvt_valueAdded(quint64 vidKey)
this->m_validValues.push_back(vidKey);
this->m_valueModel->addValue(vidKey);
#if 0
/* XXX TODO: Need to check/implement these functions on ValueModel */
bool enablePoll(quint64 vidKey, uint8 intensity);
bool disablePoll(quint64 vidKey);
bool isPolled(quint64 vidKey);
bool setPollIntensity(quint64 vidKey, quint8 intensity);
quint8 getPollIntensity(quint64 vidKey);
QString getInstanceLabel(quint64 vidKey);
QString getInstanceLabel(quint8 node, quint8 cc, quint8 instance);
bool refreshValue(quint64 vidKey);
bool setChangedVerified(quint64 vidKey);
bool getChangedVerified(quint64 vidKey);
#endif
try {
OpenZWave::ValueID vid(this->homeId(), vidKey);
this->m_valueModel->setValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Label, this->m_manager->GetValueLabel(vid).c_str(), true);
@ -801,10 +1097,10 @@ void QTOZWManager_Internal::pvt_valueAdded(quint64 vidKey)
void QTOZWManager_Internal::pvt_valueRemoved(quint64 vidKey)
{
qCDebug(notifications) << "Notification pvt_valueRemoved: " << vidKey;
emit this->valueRemoved(vidKey);
if (this->m_validValues.contains(vidKey))
this->m_validValues.removeAll(vidKey);
this->m_valueModel->delValue(vidKey);
emit this->valueRemoved(vidKey);
}
void QTOZWManager_Internal::pvt_valueChanged(quint64 vidKey)
{
@ -856,8 +1152,8 @@ void QTOZWManager_Internal::pvt_nodeGroupChanged(quint8 node, quint8 group)
QStringList removeitems;
for (int i = 0; i < list.size(); ++i) {
QString member = list.at(i);
int targetnode = member.split(":")[0].toInt();
int targetinstance = member.split(":")[1].toInt();
int targetnode = member.split(".")[0].toInt();
int targetinstance = member.split(".")[1].toInt();
bool found = false;
for (quint32 j = 0; j < count; j++) {
if (targetnode == ia[i].m_nodeId && targetinstance == ia[i].m_instance)
@ -870,6 +1166,8 @@ void QTOZWManager_Internal::pvt_nodeGroupChanged(quint8 node, quint8 group)
if (ia != nullptr)
delete [] ia;
emit this->nodeGroupChanged(node, group);
}
void QTOZWManager_Internal::pvt_nodeNew(quint8 node)
{
@ -924,18 +1222,33 @@ void QTOZWManager_Internal::pvt_nodeAdded(quint8 node)
void QTOZWManager_Internal::pvt_nodeRemoved(quint8 node)
{
qCDebug(notifications) << "Notification pvt_nodeRemoved " << node;
QVector<quint64> valueList(this->m_validValues);
for (QVector<quint64>::Iterator it = valueList.begin(); it != valueList.end(); it++) {
if (this->m_valueModel->getValueData(*it, QTOZW_ValueIds::ValueIdColumns::Node).toInt() == node)
this->pvt_valueRemoved(*it);
}
emit this->nodeRemoved(node);
if (this->m_validNodes.contains(node))
this->m_validNodes.removeAll(node);
this->m_associationsModel->delNode(node);
/* technically, this shouldn't be required... but just in case */
this->m_valueModel->delNodeValues(node);
this->m_nodeModel->delNode(node);
emit this->nodeRemoved(node);
}
void QTOZWManager_Internal::pvt_nodeReset(quint8 node)
{
qCDebug(notifications) << "Notification pvt_nodeReset " << node;
QVector<quint64> valueList(this->m_validValues);
for (QVector<quint64>::Iterator it = valueList.begin(); it != valueList.end(); it++) {
if (this->m_valueModel->getValueData(*it, QTOZW_ValueIds::ValueIdColumns::Node).toInt() == node)
this->pvt_valueRemoved(*it);
}
emit this->nodeReset(node);
if (this->m_validNodes.contains(node))
this->m_validNodes.removeAll(node);
@ -943,7 +1256,6 @@ void QTOZWManager_Internal::pvt_nodeReset(quint8 node)
/* technically, this shouldn't be required... but just in case */
this->m_valueModel->delNodeValues(node);
this->m_nodeModel->delNode(node);
emit this->nodeReset(node);
}
void QTOZWManager_Internal::pvt_nodeNaming(quint8 node)
@ -1016,13 +1328,13 @@ void QTOZWManager_Internal::pvt_nodeProtocolInfo(quint8 node)
data = this->m_manager->GetNodeProductType(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeProductType, data, true);
data = nodeBasicStr(this->m_manager->GetNodeBasic(this->homeId(), node));
data = this->m_manager->GetNodeBasicString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeBasicString, data, true);
data = this->m_manager->GetNodeBasic(this->homeId(), node);
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeBasic, data, true);
data = this->m_manager->GetNodeDeviceTypeString(this->homeId(), node).c_str();
data = this->m_manager->GetNodeGenericString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeGenericString, data, true);
data = this->m_manager->GetNodeGeneric(this->homeId(), node);
@ -1031,8 +1343,7 @@ void QTOZWManager_Internal::pvt_nodeProtocolInfo(quint8 node)
data = this->m_manager->GetNodeSpecific(this->homeId(), node);
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeSpecific, data, true);
/* XXX TODO: Need a OZW SpecificString function */
data = this->m_manager->GetNodeSpecific(this->homeId(), node);
data = this->m_manager->GetNodeSpecificString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeSpecificString, data, true);
data = this->m_manager->GetNodeMaxBaudRate(this->homeId(), node);
@ -1095,13 +1406,13 @@ void QTOZWManager_Internal::pvt_nodeEssentialNodeQueriesComplete(quint8 node)
data = this->m_manager->GetNodeProductType(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeProductType, data, true);
data = nodeBasicStr(this->m_manager->GetNodeBasic(this->homeId(), node));
data = this->m_manager->GetNodeBasicString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeBasicString, data, true);
data = this->m_manager->GetNodeBasic(this->homeId(), node);
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeBasic, data, true);
data = this->m_manager->GetNodeDeviceTypeString(this->homeId(), node).c_str();
data = this->m_manager->GetNodeGenericString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeGenericString, data, true);
data = this->m_manager->GetNodeGeneric(this->homeId(), node);
@ -1110,8 +1421,7 @@ void QTOZWManager_Internal::pvt_nodeEssentialNodeQueriesComplete(quint8 node)
data = this->m_manager->GetNodeSpecific(this->homeId(), node);
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeSpecific, data, true);
/* XXX TODO: Need a OZW SpecificString function */
data = this->m_manager->GetNodeSpecific(this->homeId(), node);
data = this->m_manager->GetNodeSpecificString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeSpecificString, data, true);
data = this->m_manager->GetNodeMaxBaudRate(this->homeId(), node);
@ -1193,13 +1503,13 @@ void QTOZWManager_Internal::pvt_nodeQueriesComplete(quint8 node)
data = this->m_manager->GetNodeProductType(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeProductType, data, true);
data = nodeBasicStr(this->m_manager->GetNodeBasic(this->homeId(), node));
data = this->m_manager->GetNodeBasicString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeBasicString, data, true);
data = this->m_manager->GetNodeBasic(this->homeId(), node);
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeBasic, data, true);
data = this->m_manager->GetNodeDeviceTypeString(this->homeId(), node).c_str();
data = this->m_manager->GetNodeGenericString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeGenericString, data, true);
data = this->m_manager->GetNodeGeneric(this->homeId(), node);
@ -1208,8 +1518,7 @@ void QTOZWManager_Internal::pvt_nodeQueriesComplete(quint8 node)
data = this->m_manager->GetNodeSpecific(this->homeId(), node);
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeSpecific, data, true);
/* XXX TODO: Need a OZW SpecificString function */
data = this->m_manager->GetNodeSpecific(this->homeId(), node);
data = this->m_manager->GetNodeSpecificString(this->homeId(), node).c_str();
this->m_nodeModel->setNodeData(node, QTOZW_Nodes::NodeSpecificString, data, true);
data = this->m_manager->GetNodeMaxBaudRate(this->homeId(), node);
@ -1247,6 +1556,10 @@ void QTOZWManager_Internal::pvt_driverReady(quint32 _homeID)
void QTOZWManager_Internal::pvt_driverFailed(quint32 _homeID)
{
qCDebug(notifications) << "Notification pvt_driverFailed " << _homeID;
QVector<quint8> nodeList(this->m_validNodes);
for (QVector<quint8>::iterator it = nodeList.begin(); it != nodeList.end(); it++)
this->pvt_nodeRemoved(*it);
this->m_associationsModel->resetModel();
this->m_valueModel->resetModel();
this->m_nodeModel->resetModel();
@ -1257,6 +1570,10 @@ void QTOZWManager_Internal::pvt_driverFailed(quint32 _homeID)
void QTOZWManager_Internal::pvt_driverReset(quint32 _homeID)
{
qCDebug(notifications) << "Notification pvt_driverReset " << _homeID;
QVector<quint8> nodeList(this->m_validNodes);
for (QVector<quint8>::iterator it = nodeList.begin(); it != nodeList.end(); it++)
this->pvt_nodeRemoved(*it);
this->m_associationsModel->resetModel();
this->m_valueModel->resetModel();
this->m_nodeModel->resetModel();
@ -1267,6 +1584,10 @@ void QTOZWManager_Internal::pvt_driverReset(quint32 _homeID)
void QTOZWManager_Internal::pvt_driverRemoved(quint32 _homeID)
{
qCDebug(notifications) << "Notification pvt_driverRemoved " << _homeID;
QVector<quint8> nodeList(this->m_validNodes);
for (QVector<quint8>::iterator it = nodeList.begin(); it != nodeList.end(); it++)
this->pvt_nodeRemoved(*it);
this->m_associationsModel->resetModel();
this->m_valueModel->resetModel();
this->m_nodeModel->resetModel();
@ -1289,19 +1610,25 @@ void QTOZWManager_Internal::pvt_driverAwakeNodesQueried()
qCDebug(notifications) << "Notification pvt_driverAwakeNodesQueried";
emit this->driverAllNodesQueried();
}
void QTOZWManager_Internal::pvt_controllerCommand(quint8 command)
void QTOZWManager_Internal::pvt_controllerCommand(quint8 node, quint32 cmd, quint32 state, quint32 error)
{
qCDebug(notifications) << "Notification pvt_controllerCommand " << command;
emit this->controllerCommand(command);
NotificationTypes::QTOZW_Notification_Controller_Cmd qtozwcmd = static_cast<NotificationTypes::QTOZW_Notification_Controller_Cmd>(cmd);
NotificationTypes::QTOZW_Notification_Controller_State qtozwstate = static_cast<NotificationTypes::QTOZW_Notification_Controller_State>(state);
NotificationTypes::QTOZW_Notification_Controller_Error qtozwerror = static_cast<NotificationTypes::QTOZW_Notification_Controller_Error>(error);
qCDebug(notifications) << "Notification pvt_controllerCommand " << cmd << state << error;
emit this->controllerCommand(node, qtozwcmd, qtozwstate, qtozwerror );
}
void QTOZWManager_Internal::pvt_ozwNotification(OpenZWave::Notification::NotificationCode event)
void QTOZWManager_Internal::pvt_ozwNotification(quint8 node, quint32 event)
{
qCDebug(notifications) << "Notification pvt_ozwNotification" << event;
NotificationTypes::QTOZW_Notification_Code qtozwevent = static_cast<NotificationTypes::QTOZW_Notification_Code>(event);
qCDebug(notifications) << "Notification pvt_ozwNotification" << qtozwevent;
emit this->ozwNotification(node, qtozwevent);
}
void QTOZWManager_Internal::pvt_ozwUserAlert(OpenZWave::Notification::UserAlertNotification event)
void QTOZWManager_Internal::pvt_ozwUserAlert(quint8 node, quint32 event, quint8 retry)
{
qCDebug(notifications) << "Notification pvt_ozwUserAlert" << event;
NotificationTypes::QTOZW_Notification_User qtozwuser = static_cast<NotificationTypes::QTOZW_Notification_User>(event);
qCDebug(notifications) << "Notification pvt_ozwUserAlert" << qtozwuser;
emit this->ozwUserAlert(node, qtozwuser, retry);
}
void QTOZWManager_Internal::pvt_manufacturerSpecificDBReady()
@ -1345,9 +1672,11 @@ void QTOZWManager_Internal::pvt_valueModelDataChanged(const QModelIndex &topLeft
if (!roles.contains(QTOZW_UserRoles::ModelDataChanged)) {
return;
}
qCDebug(valueModel) << "valueModel Changed!" << static_cast<QTOZW_ValueIds::ValueIdColumns>(topLeft.column()) << ": "<< topLeft.data();
qCDebug(valueModel) << "valueModel Changed!" << static_cast<QTOZW_ValueIds::ValueIdColumns>(topLeft.column())<< "-" << topLeft.row() << ": "<< topLeft.data();
/* get the Node Number */
quint64 vidKey = this->m_valueModel->data(topLeft.siblingAtColumn(QTOZW_ValueIds::ValueIdColumns::ValueIDKey), Qt::DisplayRole).value<quint64>();
QVariant data = this->m_valueModel->data(topLeft.siblingAtColumn(QTOZW_ValueIds::ValueIdColumns::Value), Qt::DisplayRole);
qCDebug(valueModel) << "valueModel Changed! vidKey:" << vidKey << data;
try {
OpenZWave::ValueID vid(this->homeId(), vidKey);
switch (static_cast<OpenZWave::ValueID::ValueType>(vid.GetType())) {
@ -1394,12 +1723,13 @@ void QTOZWManager_Internal::pvt_valueModelDataChanged(const QModelIndex &topLeft
}
case OpenZWave::ValueID::ValueType_Button:
{
qCWarning(valueModel) << "ValueType_Button TODO";
this->m_manager->SetValue(vid, topLeft.data().toBool());
return;
}
case OpenZWave::ValueID::ValueType_Raw:
{
qCWarning(valueModel) << "ValueType_Raw TODO";
QByteArray val = topLeft.data().toByteArray();
this->m_manager->SetValue(vid, (uint8 const*)val.data(), val.length());
return;
}
case OpenZWave::ValueID::ValueType_BitSet:

View file

@ -56,7 +56,7 @@ QVariant QTOZW_Nodes::data(const QModelIndex &index, int role) const {
return QVariant();
if (role == Qt::DisplayRole) {
QMap<NodeColumns, QVariant> node = this->m_nodeData[index.row()];
QMap<NodeColumns, QVariant> node = this->m_nodeData.at(index.row());
if (node.size() == 0) {
qCWarning(nodeModel) << "data: Cant find any Node on Row " << index.row();
return QVariant();
@ -142,7 +142,7 @@ QVariant QTOZW_Nodes::headerData(int section, Qt::Orientation orientation, int r
return tr("Node Version");
case NodeGroups:
return tr("Node Groups Supported");
return tr("Node Groups Supported");
case NodeFlags:
return tr("Node Flags");
@ -171,7 +171,7 @@ bool QTOZW_Nodes::setData(const QModelIndex &index, const QVariant &value, int r
switch (static_cast<NodeColumns>(index.column())) {
case NodeName:
case NodeLocation:
if (this->m_nodeData[index.row()][static_cast<NodeColumns>(index.column())] != value) {
if (this->m_nodeData.at(index.row())[static_cast<NodeColumns>(index.column())] != value) {
this->m_nodeData[index.row()][static_cast<NodeColumns>(index.column())] = value;
QVector<int> roles;
roles << Qt::DisplayRole << QTOZW_UserRoles::ModelDataChanged;
@ -187,7 +187,7 @@ bool QTOZW_Nodes::setData(const QModelIndex &index, const QVariant &value, int r
QVariant QTOZW_Nodes::getNodeData(quint8 _node, QTOZW_Nodes::NodeColumns _column) {
int32_t row = this->getNodeRow(_node);
if (row >= 0)
return this->m_nodeData[row][_column];
return this->m_nodeData.at(row)[_column];
qCWarning(nodeModel) << "Can't find NodeData for Node " << _node;
return QVariant();
}
@ -196,13 +196,15 @@ int32_t QTOZW_Nodes::getNodeRow(quint8 _node) {
if (this->m_nodeData.count() == 0) {
return -1;
}
QMap<int32_t, QMap<NodeColumns, QVariant> >::iterator it;
QVector< QMap<NodeColumns, QVariant> >::iterator it;
int i = 0;
for (it = m_nodeData.begin(); it != m_nodeData.end(); ++it) {
QMap<NodeColumns, QVariant> node = it.value();
QMap<NodeColumns, QVariant> node = (*it);
if (node.value(QTOZW_Nodes::NodeID) == _node) {
return it.key();
return i;
}
i++;
}
qCWarning(nodeModel) << "Can't Find NodeID " << _node << " in NodeData";
//qCWarning(nodeModel) << "Can't Find NodeID " << _node << " in NodeData";
return -1;
}

View file

@ -48,8 +48,9 @@ void QTOZW_Nodes_internal::addNode(quint8 _nodeID)
newNode[QTOZW_Nodes::NodeFlags] = flags;
this->beginInsertRows(QModelIndex(), this->rowCount(QModelIndex()), this->rowCount(QModelIndex()));
this->m_nodeData[this->rowCount(QModelIndex())] = newNode;
this->m_nodeData.push_back(newNode);
this->endInsertRows();
qCInfo(nodeModel) << "Adding Node " << _nodeID << "At Row " << this->getNodeRow(_nodeID);
}
void QTOZW_Nodes_internal::setNodeData(quint8 _nodeID, QTOZW_Nodes::NodeColumns column, QVariant data, bool transaction)
@ -59,11 +60,13 @@ void QTOZW_Nodes_internal::setNodeData(quint8 _nodeID, QTOZW_Nodes::NodeColumns
qCWarning(nodeModel) << "setNodeData: Node " << _nodeID << " does not exist";
return;
}
if (this->m_nodeData[row][column] != data) {
if (this->m_nodeData.at(row)[column] != data) {
this->m_nodeData[row][column] = data;
QVector<int> roles;
roles << Qt::DisplayRole;
if (!transaction) this->dataChanged(this->createIndex(row, column), this->createIndex(row, column), roles);
qCDebug(nodeModel) << "setNodeData " << _nodeID << ": " << column << ":" << data << " Transaction:" << transaction;
}
}
@ -74,7 +77,7 @@ void QTOZW_Nodes_internal::setNodeFlags(quint8 _nodeID, QTOZW_Nodes::nodeFlags _
qCWarning(nodeModel) << "setNodeData: Node " << _nodeID << " does not exist";
return;
}
QBitArray flag = this->m_nodeData[row][QTOZW_Nodes::NodeFlags].toBitArray();
QBitArray flag = this->m_nodeData.at(row)[QTOZW_Nodes::NodeFlags].toBitArray();
if (flag.at(_flags) != _value) {
flag.setBit(_flags, _value);
this->m_nodeData[row][QTOZW_Nodes::NodeFlags] = flag;
@ -84,22 +87,20 @@ void QTOZW_Nodes_internal::setNodeFlags(quint8 _nodeID, QTOZW_Nodes::nodeFlags _
}
}
void QTOZW_Nodes_internal::delNode(quint8 _nodeID) {
QMap<int32_t, QMap<NodeColumns, QVariant> >::iterator it;
QMap<int32_t, QMap<NodeColumns, QVariant> > newNodeMap;
int32_t newrow = 0;
for (it = this->m_nodeData.begin(); it != this->m_nodeData.end(); ++it) {
if (it.value()[QTOZW_Nodes::NodeColumns::NodeID] == _nodeID) {
qCDebug(nodeModel) << "Removing Node " << it.value()[QTOZW_Nodes::NodeColumns::NodeID] << it.key();
this->beginRemoveRows(QModelIndex(), it.key(), it.key());
this->m_nodeData.erase(it);
QVector< QMap<NodeColumns, QVariant> >::iterator it;
int i = 0;
for (it = this->m_nodeData.begin(); it != this->m_nodeData.end();) {
if ((*it)[QTOZW_Nodes::NodeColumns::NodeID] == _nodeID) {
qCDebug(nodeModel) << "Removing Node " << (*it)[QTOZW_Nodes::NodeColumns::NodeID] << i;
this->beginRemoveRows(QModelIndex(), i, i);
it = this->m_nodeData.erase(it);
this->endRemoveRows();
continue;
} else {
newNodeMap[newrow] = it.value();
newrow++;
it++;
}
i++;
}
this->m_nodeData.swap(newNodeMap);
}
void QTOZW_Nodes_internal::resetModel() {

View file

@ -51,15 +51,6 @@ void OZWNotification::processNotification
Q_UNUSED(_context);
//qDebug() << QString(_notification->GetAsString().c_str());
//qDebug() << _notification;
#if 0
void valueAdded(quint64 vidKey);
void valueRemoved(quint64 vidKey);
void valueChanged(quint64 vidKey);
void valueRefreshed(quint64 vidKey);
void valuePollingEnabled(quint64 vidKey);
void valuePollingDisabled(quint64 vidKey);
#endif
switch( _notification->GetType() )
{
case OpenZWave::Notification::Type_ValueAdded:
@ -160,7 +151,7 @@ void OZWNotification::processNotification
case OpenZWave::Notification::Type_ControllerCommand:
{
emit Get()->controllerCommand(_notification->GetEvent());
emit Get()->controllerCommand(_notification->GetNodeId(), _notification->GetCommand(), _notification->GetEvent(), _notification->GetNotification());
break;
}
@ -190,7 +181,7 @@ void OZWNotification::processNotification
case OpenZWave::Notification::Type_Notification:
{
//emit Get()->ozwNotification(_notification->GetNotification());
emit Get()->ozwNotification(_notification->GetNodeId(), _notification->GetNotification());
break;
}
@ -214,7 +205,10 @@ void OZWNotification::processNotification
case OpenZWave::Notification::Type_UserAlerts:
{
quint8 retry = 0;
if (static_cast<OpenZWave::Notification::UserAlertNotification>(_notification->GetUserAlertType()) == OpenZWave::Notification::Alert_ApplicationStatus_Retry)
retry = _notification->GetRetry();
emit Get()->ozwUserAlert(_notification->GetNodeId(), _notification->GetUserAlertType(), retry);
break;
}

View file

@ -75,26 +75,29 @@ int QTOZW_ValueIds::columnCount(const QModelIndex &parent) const {
QVariant QTOZW_ValueIds::data(const QModelIndex &index, int role) const {
if (!index.isValid())
return QVariant();
//qDebug() << "data" << index.row() << this->rowCount(index.parent());
if (index.row() >= this->rowCount(index.parent()) || index.row() < 0)
return QVariant();
if (role == Qt::DisplayRole) {
QMap<ValueIdColumns, QVariant> value = this->m_valueData[index.row()];
//qDebug() << "Doing Display Data";
QMap<ValueIdColumns, QVariant> value = this->m_valueData.at(index.row());
if (value.size() == 0) {
qCWarning(valueModel) << "data: Cant find any Node on Row " << index.row();
return QVariant();
}
//qDebug() << value[ValueIdColumns::ValueIDKey] << QMetaEnum::fromType<ValueIdColumns>().valueToKey(index.column()) << value;
return value[static_cast<ValueIdColumns>(index.column())];
}
if (role == Qt::ToolTipRole) {
QMap<ValueIdColumns, QVariant> value = this->m_valueData[index.row()];
QMap<ValueIdColumns, QVariant> value = this->m_valueData.at(index.row());
if (value.size() == 0) {
qCWarning(valueModel) << "data: Cant find any Node on Row " << index.row();
return QVariant();
}
return value[static_cast<ValueIdColumns>(ValueIdColumns::Help)];
}
//qDebug() << "Returning Invalid";
return QVariant();
}
@ -172,17 +175,18 @@ bool QTOZW_ValueIds::setData(const QModelIndex &index, const QVariant &value, in
if (role != Qt::EditRole) {
return false;
}
switch (static_cast<ValueIdColumns>(index.column())) {
case Value:
if (this->m_valueData[index.row()][static_cast<ValueIdColumns>(index.column())] != value) {
if (this->m_valueData.at(index.row())[static_cast<ValueIdColumns>(index.column())] != value) {
qCDebug(valueModel) << "setData Called for Row" << index.row() << " With Value" << value;
this->m_valueData[index.row()][static_cast<ValueIdColumns>(index.column())] = value;
QVector<int> roles;
roles << Qt::DisplayRole << QTOZW_UserRoles::ModelDataChanged;
this->dataChanged(index, index, roles);
}
break;
default:
default:
qCWarning(valueModel) << "got a setData for a Column other than Value. Ignoring" << index.column();
return false;
}
return true;
@ -190,8 +194,8 @@ bool QTOZW_ValueIds::setData(const QModelIndex &index, const QVariant &value, in
QVariant QTOZW_ValueIds::getValueData(quint64 _vidKey, ValueIdColumns _column) {
int32_t row = this->getValueRow(_vidKey);
if (row >= 0)
return this->m_valueData[row][_column];
if (row != -1)
return this->m_valueData.at(row)[_column];
qCWarning(valueModel) << "Can't find ValueData for ValueID " << _vidKey;
return QVariant();
}
@ -200,13 +204,17 @@ int32_t QTOZW_ValueIds::getValueRow(quint64 _vidKey) {
if (this->m_valueData.count() == 0) {
return -1;
}
QMap<int32_t, QMap<ValueIdColumns, QVariant> >::iterator it;
//qDebug() << "ValueModel Size:" << m_valueData.count();
QVector< QMap<ValueIdColumns, QVariant> >::iterator it;
int i = 0;
for (it = m_valueData.begin(); it != m_valueData.end(); ++it) {
QMap<ValueIdColumns, QVariant> node = it.value();
QMap<ValueIdColumns, QVariant> node = (*it);
//qDebug() << node.value(ValueIdColumns::ValueIDKey) << _vidKey;
if (node.value(ValueIdColumns::ValueIDKey) == _vidKey) {
return it.key();
return i;
}
i++;
}
qCWarning(valueModel) << "Can't Find ValueID " << _vidKey << " in valueData";
//qCWarning(valueModel) << "Can't Find ValueID " << _vidKey << " in valueData";
return -1;
}

View file

@ -46,7 +46,7 @@ void QTOZW_ValueIds_internal::addValue(quint64 _vidKey)
newValue[QTOZW_ValueIds::ValueFlags] = flags;
this->beginInsertRows(QModelIndex(), this->rowCount(QModelIndex()), this->rowCount(QModelIndex()));
this->m_valueData[this->rowCount(QModelIndex())] = newValue;
this->m_valueData.push_back(newValue);
this->endInsertRows();
}
@ -57,11 +57,12 @@ void QTOZW_ValueIds_internal::setValueData(quint64 _vidKey, QTOZW_ValueIds::Valu
qCWarning(valueModel) << "setValueData: Value " << _vidKey << " does not exist";
return;
}
if (this->m_valueData[row][column] != data) {
if (this->m_valueData.at(row)[column] != data) {
this->m_valueData[row][column] = data;
QVector<int> roles;
roles << Qt::DisplayRole;
if (!transaction) this->dataChanged(this->createIndex(row, column), this->createIndex(row, column), roles);
//qDebug() << "Setting Data " << _vidKey << row << QMetaEnum::fromType<ValueIdColumns>().valueToKey(column) << data << this->m_valueData.value(row)[column] << this->m_valueData.at(row)[ValueIdColumns::ValueIDKey];
}
}
@ -72,10 +73,10 @@ void QTOZW_ValueIds_internal::setValueFlags(quint64 _vidKey, QTOZW_ValueIds::Val
qCWarning(valueModel) << "setValueFlags: Value " << _vidKey << " does not exist";
return;
}
if (this->m_valueData[row][QTOZW_ValueIds::ValueFlags].toBitArray().at(_flags) != _value) {
QBitArray flags = this->m_valueData[row][QTOZW_ValueIds::ValueFlags].value<QBitArray>();
if (this->m_valueData.at(row)[QTOZW_ValueIds::ValueFlags].toBitArray().at(_flags) != _value) {
QBitArray flags = this->m_valueData.value(row)[QTOZW_ValueIds::ValueFlags].value<QBitArray>();
flags.setBit(_flags, _value);
this->m_valueData[row][QTOZW_ValueIds::ValueFlags] = flags;
this->m_valueData.value(row)[QTOZW_ValueIds::ValueFlags] = flags;
QVector<int> roles;
roles << Qt::DisplayRole;
if (!transaction) this->dataChanged(this->createIndex(row, QTOZW_ValueIds::ValueFlags), this->createIndex(row, QTOZW_ValueIds::ValueFlags), roles);
@ -83,41 +84,36 @@ void QTOZW_ValueIds_internal::setValueFlags(quint64 _vidKey, QTOZW_ValueIds::Val
}
void QTOZW_ValueIds_internal::delValue(quint64 _vidKey) {
QMap<int32_t, QMap<ValueIdColumns, QVariant> >::iterator it;
QMap<int32_t, QMap<ValueIdColumns, QVariant> > newValueMap;
int32_t newrow = 0;
for (it = this->m_valueData.begin(); it != this->m_valueData.end(); ++it) {
if (it.value()[QTOZW_ValueIds::ValueIdColumns::ValueIDKey] == _vidKey) {
qCDebug(valueModel) << "Removing Value " << it.value()[QTOZW_ValueIds::ValueIdColumns::Label] << it.key();
this->beginRemoveRows(QModelIndex(), it.key(), it.key());
this->m_valueData.erase(it);
QVector< QMap<ValueIdColumns, QVariant> >::iterator it;
int i = 0;
for (it = this->m_valueData.begin(); it != this->m_valueData.end();) {
if ((*it)[QTOZW_ValueIds::ValueIdColumns::ValueIDKey] == _vidKey) {
qCDebug(valueModel) << "delValue: Removing Value " << (*it)[QTOZW_ValueIds::ValueIdColumns::Label] << (*it)[QTOZW_ValueIds::ValueIdColumns::ValueIDKey] << i;
this->beginRemoveRows(QModelIndex(), i, i);
it = this->m_valueData.erase(it);
this->endRemoveRows();
continue;
} else {
newValueMap[newrow] = it.value();
newrow++;
it++;
}
i++;
}
this->m_valueData.swap(newValueMap);
}
void QTOZW_ValueIds_internal::delNodeValues(quint8 _node) {
QMap<int32_t, QMap<ValueIdColumns, QVariant> >::iterator it;
QMap<int32_t, QMap<ValueIdColumns, QVariant> > newValueMap;
qint32 newrow = 0;
for (it = this->m_valueData.begin(); it != this->m_valueData.end(); ++it) {
if (it.value()[QTOZW_ValueIds::ValueIdColumns::Node] == _node) {
qCDebug(valueModel) << "Removing Value " << it.value()[QTOZW_ValueIds::ValueIdColumns::Label] << it.key();
this->beginRemoveRows(QModelIndex(), it.key(), it.key());
this->m_valueData.erase(it);
QVector< QMap<ValueIdColumns, QVariant> >::iterator it;
int i = 0;
for (it = this->m_valueData.begin(); it != this->m_valueData.end();) {
if ((*it)[QTOZW_ValueIds::ValueIdColumns::Node] == _node) {
qCDebug(valueModel) << "delNodeValue: Removing Value " << (*it)[QTOZW_ValueIds::ValueIdColumns::Label] << (*it)[QTOZW_ValueIds::ValueIdColumns::ValueIDKey] << i;
this->beginRemoveRows(QModelIndex(), i, i);
it = this->m_valueData.erase(it);
this->endRemoveRows();
continue;
} else {
newValueMap[newrow] = it.value();
newrow++;
it++;
}
i++;
}
this->m_valueData.swap(newValueMap);
}
void QTOZW_ValueIds_internal::resetModel() {
@ -135,6 +131,9 @@ void QTOZW_ValueIds_internal::finishTransaction(quint64 _vidKey) {
this->dataChanged(this->createIndex(row, 0), this->createIndex(row, QTOZW_ValueIds::ValueIdColumns::ValueIdCount -1));
}
QVariant QTOZW_ValueIds_internal::getValueData(quint64 node, ValueIdColumns column) {
return QTOZW_ValueIds::getValueData(node, column);
}
QString BitSettoQString(QBitArray ba) {

View file

@ -26,4 +26,10 @@ ozwconfig.commands=cp -R ../../open-zwave/config config/ && cd config && $$[QT_I
include/qt-openzwave/qt-openzwavedatabase.h
INCLUDEPATH += include/
QMAKE_CXXFLAGS += -g1
target.path = /usr/local/lib/
INSTALLS += target
QMAKE_CXXFLAGS += -g1
QMAKE_LFLAGS += -rdynamic
}

View file

@ -1,13 +1,115 @@
#ifdef BP_LINUX
#include "client/linux/handler/exception_handler.h"
#include "common/linux/http_upload.h"
#define HAVE_BP
#endif
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <QCoreApplication>
#include <QLoggingCategory>
#include <QCommandLineParser>
#include <qt-openzwave/qt-openzwavedatabase.h>
#include "qtozwdaemon.h"
#ifdef HAVE_MQTT
#include "mqttpublisher.h"
#endif
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <cxxabi.h>
void backtrace(int sig = 0)
{
Q_UNUSED(sig);
unw_cursor_t cursor;
unw_context_t context;
qWarning() << "=============================";
qWarning() << "CRASH!!! - Dumping Backtrace:";
qWarning() << "=============================";
unw_getcontext(&context);
unw_init_local(&cursor, &context);
int n=0;
while ( unw_step(&cursor) ) {
unw_word_t ip, sp, off;
unw_get_reg(&cursor, UNW_REG_IP, &ip);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
char symbol[256] = {"<unknown>"};
char *name = symbol;
if ( !unw_get_proc_name(&cursor, symbol, sizeof(symbol), &off) ) {
int status;
if ( (name = abi::__cxa_demangle(symbol, NULL, NULL, &status)) == 0 )
name = symbol;
}
char message[1024];
snprintf(message, sizeof(message), "#%-2d 0x%016" PRIxPTR " sp=0x%016" PRIxPTR " %s + 0x%" PRIxPTR,
++n,
static_cast<uintptr_t>(ip),
static_cast<uintptr_t>(sp),
name,
static_cast<uintptr_t>(off));
qWarning() << message;
if ( name != symbol )
free(name);
}
#ifndef HAVE_BP
qWarning("Exiting....");
exit(-1);
#endif
}
void crash() { volatile int* a = (int*)(NULL); *a = 1; }
#ifdef HAVE_BP
static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
void* context, bool succeeded) {
backtrace();
qWarning() << "dumpCallback Succeeded: " << succeeded << " at " << descriptor.path();
if (succeeded == true) {
std::map<string, string> parameters;
std::map<string, string> files;
std::string proxy_host;
std::string proxy_userpasswd;
std::string url("https://sentry.io/api/1868130/minidump/?sentry_key=e086ba93030843199aab391947d205da");
// Add any attributes to the parameters map.
// Note that several attributes are automatically extracted.
parameters["product_name"] = QCoreApplication::applicationName().toStdString();
parameters["release"] = QCoreApplication::applicationVersion().toStdString();
qtozwdaemon *daemon = static_cast<qtozwdaemon *>(context);
parameters["OpenZWave_Version"] = daemon->getManager()->getVersionAsString().toStdString();
parameters["QTOpenZWave_Version"] = daemon->getQTOpenZWave()->getVersion().toStdString();
parameters["QT_Version"] = qVersion();
files["upload_file_minidump"] = descriptor.path();
std::string response, error;
bool success = google_breakpad::HTTPUpload::SendRequest(url, parameters, files, proxy_host, proxy_userpasswd, "", &response, NULL, &error);
if (success)
qWarning() << "Uploaded Crash minidump With ID: " << response.c_str();
else
qWarning() << "Failed to Upload Crash MiniDump in " << descriptor.path();
}
return succeeded;
}
#endif
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("qt-ozwdaemon");
QCoreApplication::setApplicationVersion("1.0");
QCoreApplication::setApplicationName("ozwdaemon");
QCoreApplication::setApplicationVersion("0.1");
QCoreApplication::setOrganizationName("OpenZWave");
QCoreApplication::setOrganizationDomain("openzwave.com");
@ -36,6 +138,42 @@ int main(int argc, char *argv[])
parser.addOption(userDir);
#ifdef HAVE_MQTT
QCommandLineOption MQTTServer(QStringList() << "mqtt-server",
"MQTT Server Hostname/IP Address",
"IP/Hostname"
);
parser.addOption(MQTTServer);
QCommandLineOption MQTTPort(QStringList() << "mqtt-port",
"MQTT Server Port",
"Port"
);
parser.addOption(MQTTPort);
QCommandLineOption MQTTInstance(QStringList() << "mqtt-instance",
"OpenZWave Instance Number - Defaults to 1",
"Number"
);
parser.addOption(MQTTInstance);
QCommandLineOption MQTTTLS(QStringList() << "mqtt-tls",
"Enable TLS Encryption to MQTT Server"
);
parser.addOption(MQTTTLS);
#endif
QCommandLineOption StopOnFailure(QStringList() << "stop-on-failure",
"Exit on Driver Failure"
);
parser.addOption(StopOnFailure);
parser.process(a);
if (!parser.isSet(serialPort)) {
fputs(qPrintable("Serial Port is Required\n"), stderr);
@ -44,8 +182,7 @@ int main(int argc, char *argv[])
exit(-1);
}
#if 1
#if 0
QLoggingCategory::setFilterRules("qt.remoteobjects.debug=true\n"
"qt.remoteobjects.warning=true\n"
"qt.remoteobjects.models.debug=true\n"
@ -53,10 +190,117 @@ int main(int argc, char *argv[])
"qt.remoteobjects.io.debug=true\n"
"default.debug=true");
#else
QLoggingCategory::setFilterRules("default.debug=true");
QLoggingCategory::setFilterRules("*.debug=true");
#endif
QStringList PossibleDBPaths;
if (parser.isSet(configDir))
PossibleDBPaths << parser.value(configDir);
PossibleDBPaths << "./config/";
PossibleDBPaths << QDir::toNativeSeparators("../../../config/");
//PossibleDBPaths << settings.value("openzwave/ConfigPath", QDir::toNativeSeparators("../../../config/")).toString().append("/");
PossibleDBPaths << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
QString path, dbPath, userPath;
foreach(path, PossibleDBPaths) {
qDebug() << "Checking " << QFileInfo(QDir::toNativeSeparators(path+"/config/manufacturer_specific.xml")).absoluteFilePath() << " for manufacturer_specific.xml";
if (QFileInfo(QDir::toNativeSeparators(path+"/config/manufacturer_specific.xml")).exists()) {
dbPath = QFileInfo(QDir::toNativeSeparators(path+"/config/manufacturer_specific.xml")).absoluteFilePath();
break;
}
qDebug() << "Checking " << QFileInfo(QDir::toNativeSeparators(path+"../config/manufacturer_specific.xml")).absoluteFilePath() << " for manufacturer_specific.xml";
if (QFile(QDir::toNativeSeparators(path+"/../config/manufacturer_specific.xml")).exists()) {
dbPath = QFileInfo(QDir::toNativeSeparators(path+"/../config/manufacturer_specific.xml")).absoluteFilePath();
break;
}
}
PossibleDBPaths.clear();
if (parser.isSet(userDir))
PossibleDBPaths << parser.value(userDir);
PossibleDBPaths << "./config/";
PossibleDBPaths << QDir::toNativeSeparators("../../../config/");
// PossibleDBPaths << settings.value("openzwave/UserPath", QDir::toNativeSeparators("../../../config/")).toString().append("/");
PossibleDBPaths << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
foreach(path, PossibleDBPaths) {
qDebug() << "Checking " << QFileInfo(QDir::toNativeSeparators(path+"/config/Options.xml")).absoluteFilePath() << " for options.xml";
if (QFileInfo(QDir::toNativeSeparators(path+"/config/options.xml")).exists()) {
userPath = QFileInfo(QDir::toNativeSeparators(path+"/config/options.xml")).absoluteFilePath();
break;
}
qDebug() << "Checking " << QFileInfo(QDir::toNativeSeparators(path+"/../config/options.xml")).absoluteFilePath() << " for options.xml";
if (QFile(QDir::toNativeSeparators(path+"/../config/options.xml")).exists()) {
userPath = QFileInfo(QDir::toNativeSeparators(path+"/../config/options.xml")).absoluteFilePath();
break;
}
}
// if (userPath.isEmpty()) {
// fputs(qPrintable("userPath is Not Set or Missing\n"), stderr);
// exit(-1);
// }
if (dbPath.isEmpty()) {
copyConfigDatabase(QFileInfo("./").absoluteFilePath().append("/"));
dbPath = "./config/";
userPath = "./config/";
}
qDebug() << "DBPath: " << dbPath;
qDebug() << "userPath: " << userPath;
QSettings settings(userPath.append("/ozwdaemon.ini"), QSettings::IniFormat);
#ifdef HAVE_MQTT
if (parser.isSet(MQTTServer)) {
settings.setValue("MQTTServer", parser.value(MQTTServer));
}
if (parser.isSet(MQTTPort)) {
settings.setValue("MQTTPort", parser.value(MQTTPort).toInt());
}
if (parser.isSet(MQTTInstance)) {
settings.setValue("Instance", parser.value(MQTTInstance).toInt());
}
if (parser.isSet(MQTTTLS)) {
qDebug() << "mqtt tls set";
settings.setValue("MQTTTLS", true);
} else {
settings.setValue("MQTTTLS", false);
}
#endif
if (parser.isSet(StopOnFailure)) {
settings.setValue("StopOnFailure", true);
}
QTOZWOptions options(QTOZWOptions::Local);
options.setUserPath(userPath);
options.setConfigPath(dbPath);
qtozwdaemon daemon;
#ifdef HAVE_MQTT
mqttpublisher mqttpublisher(&settings);
mqttpublisher.setOZWDaemon(&daemon);
#endif
#ifdef HAVE_BP
QString bppath = QString::fromLocal8Bit(qgetenv("BP_DB_PATH"));
if (bppath.isEmpty())
bppath = QStandardPaths::standardLocations(QStandardPaths::TempLocation).at(0);
qInfo() << "Using BreakPad - Crash Directory: " << bppath;
google_breakpad::MinidumpDescriptor descriptor(bppath.toStdString());
google_breakpad::ExceptionHandler eh(descriptor, NULL, dumpCallback, static_cast<void *>(&daemon), true, -1);
#else
signal(SIGSEGV, backtrace);
signal(SIGABRT, backtrace);
#endif
daemon.setSerialPort(parser.value(serialPort));
daemon.startOZW();
// assert(0);
// crash();
return a.exec();
}

View file

@ -0,0 +1,32 @@
#include "qt-openzwave/qtozwmanager.h"
#include "mqttAssociations.h"
#include "qtrj.h"
Q_LOGGING_CATEGORY(ozwmpassociation, "ozw.mqtt.publisher.association");
mqttAssociationModel::mqttAssociationModel(QObject *parent)
{
}
bool mqttAssociationModel::populateJsonObject(rapidjson::Document &jsonobject, quint8 node, quint8 group, QTOZWManager *mgr) {
Q_UNUSED(mgr);
if (jsonobject.IsNull())
jsonobject.SetObject();
QT2JS::SetString(jsonobject, "Name", getassocationData(node, group, QTOZW_Associations::associationColumns::GroupName).toString());
QT2JS::SetString(jsonobject, "Help", getassocationData(node, group, QTOZW_Associations::associationColumns::GroupHelp).toString());
QT2JS::SetUint(jsonobject, "MaxAssociations", getassocationData(node, group, QTOZW_Associations::associationColumns::MaxAssocations).toInt());
QStringList members = getassocationData(node, group, QTOZW_Associations::associationColumns::Members).toStringList();
rapidjson::Value N(rapidjson::kArrayType);
for (int i = 0; i < members.size(); i++) {
rapidjson::Value strVal;
strVal.SetString(members.at(i).toStdString().c_str(), jsonobject.GetAllocator());
N.PushBack(strVal, jsonobject.GetAllocator());
}
jsonobject.AddMember(rapidjson::Value("Members").Move(), N, jsonobject.GetAllocator());
return true;
}

View file

@ -0,0 +1,17 @@
#ifndef MQTTASSOC_H
#define MQTTASSOC_H
#include <QObject>
#include <QVariant>
#include <rapidjson/document.h>
#include "qt-openzwave/qtozwassociationmodel.h"
class mqttAssociationModel : public QTOZW_Associations {
Q_OBJECT
public:
explicit mqttAssociationModel(QObject *parent = nullptr);
bool populateJsonObject(rapidjson::Document &, quint8, quint8, QTOZWManager *);
};
#endif

View file

@ -0,0 +1,93 @@
#include "qt-openzwave/qtozwmanager.h"
#include "mqttNodes.h"
#include "qtrj.h"
Q_LOGGING_CATEGORY(ozwmpnode, "ozw.mqtt.publisher.node");
mqttNodeModel::mqttNodeModel(QObject *parent)
{
}
QVariant mqttNodeModel::getNodeData(quint8 node, NodeColumns col) {
int row = this->getNodeRow(node);
return this->data(this->index(row, col), Qt::DisplayRole);
}
bool mqttNodeModel::isValidNode(quint8 node) {
if (this->getNodeRow(node) == -1)
return false;
return true;
}
bool mqttNodeModel::populateJsonObject(rapidjson::Document &jsonobject, quint8 node, QTOZWManager *mgr) {
if (jsonobject.IsNull())
jsonobject.SetObject();
for (int i = 0; i < this->columnCount(QModelIndex()); i++) {
QVariant data = this->getNodeData(node, static_cast<NodeColumns>(i));
if (data.type() == QVariant::Invalid) {
continue;
}
switch (static_cast<NodeColumns>(i)) {
case NodeColumns::NodeFlags: {
QBitArray flag = data.toBitArray();
QMetaEnum metaEnum = QMetaEnum::fromType<nodeFlags>();
for (int j = 0; j < nodeFlags::flagCount; j++) {
QT2JS::SetBool(jsonobject, metaEnum.valueToKey(j), flag.at(j));
}
break;
}
default: {
QMetaEnum metaEnum = QMetaEnum::fromType<NodeColumns>();
if (static_cast<QMetaType::Type>(data.type()) == QMetaType::QString) {
QT2JS::SetString(jsonobject, metaEnum.valueToKey(i), data.toString());
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::Bool) {
QT2JS::SetBool(jsonobject, metaEnum.valueToKey(i), data.toBool());
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::Int) {
QT2JS::SetInt(jsonobject, metaEnum.valueToKey(i), data.toInt());
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::UInt) {
QT2JS::SetUint(jsonobject, metaEnum.valueToKey(i), data.toUInt());
} else {
qCWarning(ozwmpnode) << "Can't Convert " << data.type() << "(" << metaEnum.valueToKey(i) << ") to store in JsonObject: " << node;
}
break;
}
}
}
/* MetaData */
rapidjson::Value metadata;
if (!jsonobject.HasMember("MetaData")) {
rapidjson::Value metadata;
metadata.SetObject();
QMetaEnum metaEnum = QMetaEnum::fromType<QTOZWManagerSource::QTOZWMetaDataField>();
if (metadata.IsNull()) {
metadata.SetObject();
}
for (int i = 0; i < QTOZWManagerSource::Identifier; i++) {
metadata.AddMember(
rapidjson::Value(metaEnum.valueToKey(i), jsonobject.GetAllocator()).Move(),
rapidjson::Value(mgr->GetMetaData(node, static_cast<QTOZWManagerSource::QTOZWMetaDataField>(i)).toStdString().c_str(), jsonobject.GetAllocator()).Move(),
jsonobject.GetAllocator());
}
metadata.AddMember(rapidjson::Value("ProductPicBase64").Move(),
rapidjson::Value(QString(mgr->GetMetaDataProductPic(node).toBase64()).toStdString().c_str(), jsonobject.GetAllocator()).Move(),
jsonobject.GetAllocator());
jsonobject.AddMember(rapidjson::Value("MetaData"), metadata, jsonobject.GetAllocator());
}
/* Neighbors */
QVector<quint8> neighbors = mgr->GetNodeNeighbors(node);
if (neighbors.size() > 0) {
rapidjson::Value N(rapidjson::kArrayType);
for (int i = 0; i < neighbors.count(); i++) {
N.PushBack(neighbors[i], jsonobject.GetAllocator());
}
jsonobject.AddMember(rapidjson::Value("Neighbors").Move(), N, jsonobject.GetAllocator());
}
return true;
}

19
qt-ozwdaemon/mqttNodes.h Normal file
View file

@ -0,0 +1,19 @@
#ifndef MQTTNODES_H
#define MQTTNODES_H
#include <QObject>
#include <QVariant>
#include <rapidjson/document.h>
#include "qt-openzwave/qtozwnodemodel.h"
class mqttNodeModel : public QTOZW_Nodes {
Q_OBJECT
public:
explicit mqttNodeModel(QObject *parent = nullptr);
QVariant getNodeData(quint8, NodeColumns);
bool populateJsonObject(rapidjson::Document &, quint8, QTOZWManager *);
bool isValidNode(quint8);
};
#endif

243
qt-ozwdaemon/mqttValues.cpp Normal file
View file

@ -0,0 +1,243 @@
#include "qt-openzwave/qtozwmanager.h"
#include "mqttValues.h"
#include "qtrj.h"
Q_LOGGING_CATEGORY(ozwmpvalue, "ozw.mqtt.publisher.value");
mqttValueIDModel::mqttValueIDModel(QObject *parent) {
}
QVariant mqttValueIDModel::getValueData(quint64 vidKey, ValueIdColumns col) {
int row = this->getValueRow(vidKey);
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(rapidjson::Document &jsonobject, quint64 vidKey, QTOZWManager *mgr) {
for (int i = 0; i < ValueIdColumns::ValueIdCount; i++) {
QVariant data = this->getValueData(vidKey, static_cast<ValueIdColumns>(i));
switch (static_cast<ValueIdColumns>(i)) {
case ValueFlags: {
QBitArray flag = data.toBitArray();
QMetaEnum metaEnum = QMetaEnum::fromType<ValueIDFlags>();
for (int j = 0; j < ValueIDFlags::FlagCount; j++) {
QT2JS::SetBool(jsonobject, metaEnum.valueToKey(j), flag.at(j));
}
break;
}
case Value: {
this->encodeValue(jsonobject, vidKey);
break;
}
case Genre: {
QMetaEnum metaEnum = QMetaEnum::fromType<ValueIdGenres>();
QT2JS::SetString(jsonobject, "Genre", metaEnum.valueToKey(data.toInt()));
break;
}
case Type: {
QMetaEnum metaEnum = QMetaEnum::fromType<ValueIdTypes>();
QT2JS::SetString(jsonobject, "Type", metaEnum.valueToKey(data.toInt()));
break;
}
case CommandClass: {
QT2JS::SetString(jsonobject, "CommandClass", mgr->getCommandClassString(data.toInt()));
break;
}
default: {
QMetaEnum metaEnum = QMetaEnum::fromType<ValueIdColumns>();
if (static_cast<QMetaType::Type>(data.type()) == QMetaType::QString) {
QT2JS::SetString(jsonobject, metaEnum.valueToKey(i), data.toString());
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::Bool) {
QT2JS::SetBool(jsonobject, metaEnum.valueToKey(i), data.toBool());
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::Int) {
QT2JS::SetInt(jsonobject, metaEnum.valueToKey(i), data.toInt());
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::UInt) {
QT2JS::SetUint(jsonobject, metaEnum.valueToKey(i), data.toUInt());
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::Float) {
QT2JS::SetDouble(jsonobject, metaEnum.valueToKey(i), data.toDouble());
} else if (static_cast<QMetaType::Type>(data.type()) == QMetaType::ULongLong) {
QT2JS::SetUInt64(jsonobject, metaEnum.valueToKey(i), static_cast<qint64>(data.toULongLong()));
} else {
qCWarning(ozwmpvalue) << "mqttValueIDModel::populateJsonObject: Can't Convert " << data.type() << "(" << metaEnum.valueToKey(i) << ") to store in JsonObject: " << vidKey;
}
break;
}
}
}
return true;
}
bool mqttValueIDModel::encodeValue(rapidjson::Document &value, quint64 vidKey) {
QVariant data = this->getValueData(vidKey, mqttValueIDModel::ValueIdColumns::Value);
QTOZW_ValueIds::ValueIdTypes type = this->getValueData(vidKey, mqttValueIDModel::ValueIdColumns::Type).value<QTOZW_ValueIds::ValueIdTypes>();
bool changed = false;
switch (type) {
case QTOZW_ValueIds::ValueIdTypes::BitSet: {
if (!value.HasMember("Value")) {
rapidjson::Value bitsets(rapidjson::kArrayType);
bitsets.SetArray();
QTOZW_ValueIDBitSet vidbs = data.value<QTOZW_ValueIDBitSet>();
int size = vidbs.mask.size();
for (int i = 0; i < size; i++) {
if (vidbs.mask[i] == 1) {
rapidjson::Value bitset;
bitset.SetObject();
bitset.AddMember(
rapidjson::Value("Label", value.GetAllocator()).Move(),
rapidjson::Value(vidbs.label[i].toStdString().c_str(), value.GetAllocator()).Move(),
value.GetAllocator()
);
bitset.AddMember(
rapidjson::Value("Help", value.GetAllocator()).Move(),
rapidjson::Value(vidbs.help[i].toStdString().c_str(), value.GetAllocator()).Move(),
value.GetAllocator()
);
bitset.AddMember(
rapidjson::Value("Value", value.GetAllocator()).Move(),
rapidjson::Value(vidbs.values[i]),
value.GetAllocator()
);
bitset.AddMember(
rapidjson::Value("Position", value.GetAllocator()).Move(),
rapidjson::Value(i),
value.GetAllocator()
);
bitsets.PushBack(bitset, value.GetAllocator());
}
}
value.AddMember(
rapidjson::Value("Value", value.GetAllocator()).Move(),
bitsets,
value.GetAllocator()
);
changed = true;
} else {
/* Value Already Exists, Just Check for Changes */
rapidjson::Value bitsets = value["Value"].GetArray();
QTOZW_ValueIDBitSet vidbs = data.value<QTOZW_ValueIDBitSet>();
for (unsigned int i = 0; i < bitsets.Size(); i++) {
rapidjson::Value bitset = bitsets[i].GetObject();
if (bitset.HasMember("Position") && bitset.HasMember("Value") && bitset["Position"].IsInt() && bitset["Value"].IsBool()) {
int pos = bitset["Position"].GetInt();
bool val = bitset["Value"].GetBool();
if (vidbs.values[pos] != val) {
bitset["Value"].SetBool(val);
changed = true;
}
} else {
qCWarning(ozwmpvalue) << "Bitset is Missing Position or Value Members, or Incorrect Types: " << QT2JS::getJSON(value);
}
}
}
break;
}
case QTOZW_ValueIds::ValueIdTypes::Bool: {
changed = QT2JS::SetBool(value, "Value", data.toBool());
break;
}
case QTOZW_ValueIds::ValueIdTypes::Button: {
changed = QT2JS::SetBool(value, "Value", data.toBool());
break;
}
case QTOZW_ValueIds::ValueIdTypes::Byte: {
changed = QT2JS::SetInt(value, "Value", data.toInt());
break;
}
case QTOZW_ValueIds::ValueIdTypes::Decimal: {
changed = QT2JS::SetDouble(value, "Value", data.toDouble());
break;
}
case QTOZW_ValueIds::ValueIdTypes::Int:{
changed = QT2JS::SetInt(value, "Value", data.toInt());
break;
}
case QTOZW_ValueIds::ValueIdTypes::List: {
QTOZW_ValueIDList vidlist = data.value<QTOZW_ValueIDList>();
int size = vidlist.values.count();
rapidjson::Value list(rapidjson::kArrayType);
list.SetArray();
if (!value.HasMember("Value")) {
for (int i = 0; i < size; i++) {
rapidjson::Value entry;
entry.SetObject();
entry.AddMember(
rapidjson::Value("Value", value.GetAllocator()).Move(),
vidlist.values[i],
value.GetAllocator()
);
entry.AddMember(
rapidjson::Value("Label", value.GetAllocator()).Move(),
rapidjson::Value(vidlist.labels[i].toStdString().c_str(), value.GetAllocator()),
value.GetAllocator()
);
list.PushBack(entry, value.GetAllocator());
}
rapidjson::Value var(rapidjson::kObjectType);
var.SetObject();
var.AddMember(
rapidjson::Value("List", value.GetAllocator()).Move(),
list,
value.GetAllocator()
);
var.AddMember(
rapidjson::Value("Selected", value.GetAllocator()).Move(),
rapidjson::Value(vidlist.selectedItem.toStdString().c_str(), value.GetAllocator()).Move(),
value.GetAllocator()
);
value.AddMember(
rapidjson::Value("Value", value.GetAllocator()).Move(),
var,
value.GetAllocator()
);
changed = true;
} else {
/* Value Array exists, so just check/update the Values */
QString selected = value["Value"]["Selected"].GetString();
if (selected != vidlist.selectedItem) {
value["Value"]["Selected"].SetString(vidlist.selectedItem.toStdString().c_str(), value.GetAllocator());
changed = true;
} else {
qCDebug(ozwmpvalue) << "List Selected Value has Not Changed: " << vidlist.selectedItem;
}
}
break;
}
case QTOZW_ValueIds::ValueIdTypes::Raw: {
QByteArray ba = data.value<QByteArray>();
changed = QT2JS::SetString(value, "Value", ba.toHex());
break;
}
case QTOZW_ValueIds::ValueIdTypes::Schedule: {
qCWarning(ozwmpvalue) << "Schedule ValueType not handled in mqttValueIdModel::encodeValue yet";
break;
}
case QTOZW_ValueIds::ValueIdTypes::Short: {
changed = QT2JS::SetInt(value, "Value" ,data.toInt());
break;
}
case QTOZW_ValueIds::ValueIdTypes::String: {
changed = QT2JS::SetString(value, "Value", data.toString());
break;
}
case QTOZW_ValueIds::ValueIdTypes::TypeCount: {
qCWarning(ozwmpvalue) << "Unhandled ValueID Type" << type << "in mqttValueIdModel::encodeValue" << vidKey << this->getValueData(vidKey, mqttValueIDModel::ValueIdColumns::Label).toString();
break;
}
}
return changed;
}
bool mqttValueIDModel::setData(quint64 vidKey, QVariant data) {
return QTOZW_ValueIds::setData(this->index(this->getValueRow(vidKey), QTOZW_ValueIds::ValueIdColumns::Value), data);
}

22
qt-ozwdaemon/mqttValues.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef MQTTVALUES_H
#define MQTTVALUES_H
#include <QObject>
#include <QVariant>
#include <rapidjson/document.h>
#include "qt-openzwave/qtozwvalueidmodel.h"
class mqttValueIDModel : public QTOZW_ValueIds {
Q_OBJECT
public:
explicit mqttValueIDModel(QObject *parent = nullptr);
QVariant getValueData(quint64, ValueIdColumns);
bool populateJsonObject(rapidjson::Document &, quint64, QTOZWManager *);
bool encodeValue(rapidjson::Document &, quint64);
bool isValidValueID(quint64);
bool setData(quint64, QVariant);
};
#endif

View file

@ -0,0 +1,18 @@
#include "mqttcommands/IsNodeFailed.h"
MqttCommand_IsNodeFailed::MqttCommand_IsNodeFailed(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_IsNodeFailed::Create(QObject *parent) {
return new MqttCommand_IsNodeFailed(parent);
}
bool MqttCommand_IsNodeFailed::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->IsNodeFailed(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef ISNODEFAILED_H
#define ISNODEFAILED_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_IsNodeFailed : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "IsNodeFailed";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_IsNodeFailed(QObject *parent = nullptr);
};
#endif // ISNODEFAILED_H

View file

@ -0,0 +1,15 @@
#include "mqttcommands/addNode.h"
MqttCommand_AddNode::MqttCommand_AddNode(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredBoolFields << "secure";
}
MqttCommand* MqttCommand_AddNode::Create(QObject *parent) {
return new MqttCommand_AddNode(parent);
}
bool MqttCommand_AddNode::processMessage(rapidjson::Document &msg) {
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->addNode(msg["secure"].GetBool()));
}

View file

@ -0,0 +1,17 @@
#ifndef ADDNODE_H
#define ADDNODE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_AddNode : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "AddNode";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_AddNode(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/assignReturnRoute.h"
MqttCommand_AssignReturnRoute::MqttCommand_AssignReturnRoute(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_AssignReturnRoute::Create(QObject *parent) {
return new MqttCommand_AssignReturnRoute(parent);
}
bool MqttCommand_AssignReturnRoute::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->assignReturnRoute(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef ASSIGNRETURNROUTE_H
#define ASSIGNRETURNROUTE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_AssignReturnRoute : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "AssignReturnRoute";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_AssignReturnRoute(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,15 @@
#include "mqttcommands/cancelControllerCommand.h"
MqttCommand_CancelControllerCommand::MqttCommand_CancelControllerCommand(QObject *parent) :
MqttCommand(parent)
{
}
MqttCommand* MqttCommand_CancelControllerCommand::Create(QObject *parent) {
return new MqttCommand_CancelControllerCommand(parent);
}
bool MqttCommand_CancelControllerCommand::processMessage(rapidjson::Document &msg) {
Q_UNUSED(msg);
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->cancelControllerCommand());
}

View file

@ -0,0 +1,17 @@
#ifndef CANCELCONTROLLERCOMMAND_H
#define CANCELCONTROLLERCOMMAND_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_CancelControllerCommand : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "CancelControllerCommand";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_CancelControllerCommand(QObject *parent = nullptr);
};
#endif // CANCELCONTROLLERCOMMAND_H

View file

@ -0,0 +1,19 @@
#include "mqttcommands/checkLatestConfigFileRevision.h"
MqttCommand_CheckLatestConfigFileRevision::MqttCommand_CheckLatestConfigFileRevision(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_CheckLatestConfigFileRevision::Create(QObject *parent) {
return new MqttCommand_CheckLatestConfigFileRevision(parent);
}
bool MqttCommand_CheckLatestConfigFileRevision::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->checkLatestConfigFileRevision(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef CHECKLATESTCONFIGFILEREVISION_H
#define CHECKLATESTCONFIGFILEREVISION_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_CheckLatestConfigFileRevision : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "CheckLatestConfigFileRevision";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_CheckLatestConfigFileRevision(QObject *parent = nullptr);
};
#endif // CHECKLATESTCONFIGFILEREVISION_H

View file

@ -0,0 +1,16 @@
#include "mqttcommands/checkLatestMFSRevision.h"
MqttCommand_CheckLatestMFSRevision::MqttCommand_CheckLatestMFSRevision(QObject *parent) :
MqttCommand(parent)
{
}
MqttCommand* MqttCommand_CheckLatestMFSRevision::Create(QObject *parent) {
return new MqttCommand_CheckLatestMFSRevision(parent);
}
bool MqttCommand_CheckLatestMFSRevision::processMessage(rapidjson::Document &msg) {
Q_UNUSED(msg);
QTOZWManager *mgr = getOZWManager();
mgr->checkLatestMFSRevision();
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef CHECKLATESTMFSREVISION_H
#define CHECKLATESTMFSREVISION_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_CheckLatestMFSRevision : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "CheckLatestMFSRevision";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_CheckLatestMFSRevision(QObject *parent = nullptr);
};
#endif // CHECKLATESTMFSREVISION_H

View file

@ -0,0 +1,15 @@
#include "mqttcommands/close.h"
MqttCommand_Close::MqttCommand_Close(QObject *parent) :
MqttCommand(parent)
{
}
MqttCommand* MqttCommand_Close::Create(QObject *parent) {
return new MqttCommand_Close(parent);
}
bool MqttCommand_Close::processMessage(rapidjson::Document &msg) {
Q_UNUSED(msg);
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->close());
}

View file

@ -0,0 +1,17 @@
#ifndef CLOSE_H
#define CLOSE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_Close : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "Close";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_Close(QObject *parent = nullptr);
};
#endif // CLOSE_H

View file

@ -0,0 +1,19 @@
#include "mqttcommands/deleteAllReturnRoute.h"
MqttCommand_DeleteAllReturnRoute::MqttCommand_DeleteAllReturnRoute(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_DeleteAllReturnRoute::Create(QObject *parent) {
return new MqttCommand_DeleteAllReturnRoute(parent);
}
bool MqttCommand_DeleteAllReturnRoute::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->deleteAllReturnRoute(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef DELETEALLRETURNROUTE_H
#define DELETEALLRETURNROUTE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_DeleteAllReturnRoute : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "DeleteAllReturnRoute";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_DeleteAllReturnRoute(QObject *parent = nullptr);
};
#endif // DELETEALLRETURNROUTE_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/downloadLatestConfigFileRevision.h"
MqttCommand_DownloadLatestConfigFileRevision::MqttCommand_DownloadLatestConfigFileRevision(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_DownloadLatestConfigFileRevision::Create(QObject *parent) {
return new MqttCommand_DownloadLatestConfigFileRevision(parent);
}
bool MqttCommand_DownloadLatestConfigFileRevision::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->downloadLatestConfigFileRevision(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef DOWNLOADLATESTCONFIGFILEREVISION_H
#define DOWNLOADLATESTCONFIGFILEREVISION_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_DownloadLatestConfigFileRevision : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "DownloadLatestConfigFileRevision";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_DownloadLatestConfigFileRevision(QObject *parent = nullptr);
};
#endif // DOWNLOADLATESTCONFIGFILEREVISION_H

View file

@ -0,0 +1,15 @@
#include "mqttcommands/downloadLatestMFSRevision.h"
MqttCommand_DownloadLatestMFSRevision::MqttCommand_DownloadLatestMFSRevision(QObject *parent) :
MqttCommand(parent)
{
}
MqttCommand* MqttCommand_DownloadLatestMFSRevision::Create(QObject *parent) {
return new MqttCommand_DownloadLatestMFSRevision(parent);
}
bool MqttCommand_DownloadLatestMFSRevision::processMessage(rapidjson::Document &msg) {
Q_UNUSED(msg);
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->downloadLatestMFSRevision());
}

View file

@ -0,0 +1,17 @@
#ifndef DOWNLOADLATESTMFSREVISION_H
#define DOWNLOADLATESTMFSREVISION_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_DownloadLatestMFSRevision : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "DownloadLatestMFSRevision";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_DownloadLatestMFSRevision(QObject *parent = nullptr);
};
#endif // DOWNLOADLATESTMFSREVISION_H

View file

@ -0,0 +1,20 @@
#include "mqttcommands/enablePoll.h"
MqttCommand_EnablePoll::MqttCommand_EnablePoll(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "ValueIDKey";
}
MqttCommand* MqttCommand_EnablePoll::Create(QObject *parent) {
return new MqttCommand_SyncroniseNodeNeighbors(parent);
}
bool MqttCommand_EnablePoll::processMessage(rapidjson::Document &msg) {
if (!this->checkValue(msg, "ValueIDKey")) {
return this->sendSimpleStatus(false, "Invalid ValueIDKey Number");
}
QTOZWManager *mgr = getOZWManager();
//mgr->syncroniseNodeNeighbors(msg["node"].GetInt());
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef ENABLEPOLL_H
#define ENABLEPOLL_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_EnablePoll : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "enablePoll";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_EnablePoll(QObject *parent = nullptr);
};
#endif // ENABLEPOLL_H

View file

@ -0,0 +1,19 @@
#include "mqttcommands/getPollInterval.h"
MqttCommand_GetPollInterval::MqttCommand_GetPollInterval(QObject *parent) :
MqttCommand(parent)
{
}
MqttCommand* MqttCommand_GetPollInterval::Create(QObject *parent) {
return new MqttCommand_GetPollInterval(parent);
}
bool MqttCommand_GetPollInterval::processMessage(rapidjson::Document &msg) {
Q_UNUSED(msg);
QTOZWManager *mgr = getOZWManager();
rapidjson::Document js;
QT2JS::SetString(js, "status", "ok");
QT2JS::SetInt64(js, "pollInterval", mgr->getPollInterval());
emit sendCommandUpdate(GetCommand(), js);
return true;
}

View file

@ -0,0 +1,17 @@
#ifndef GETPOLLINTERVAL_H
#define GETPOLLINTERVAL_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_GetPollInterval : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "getPollInterval";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_GetPollInterval(QObject *parent = nullptr);
};
#endif // GETPOLLINTERVAL_H

View file

@ -0,0 +1,16 @@
#include "mqttcommands/hardResetController.h"
MqttCommand_HardResetController::MqttCommand_HardResetController(QObject *parent) :
MqttCommand(parent)
{
}
MqttCommand* MqttCommand_HardResetController::Create(QObject *parent) {
return new MqttCommand_HardResetController(parent);
}
bool MqttCommand_HardResetController::processMessage(rapidjson::Document &msg) {
Q_UNUSED(msg);
QTOZWManager *mgr = getOZWManager();
mgr->hardResetController();
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef HARDRESETCONTROLLER_H
#define HARDRESETCONTROLLER_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_HardResetController : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "HardResetController";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_HardResetController(QObject *parent = nullptr);
};
#endif // HARDRESETCONTROLLER_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/hasNodeFailed.h"
MqttCommand_HasNodeFailed::MqttCommand_HasNodeFailed(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_HasNodeFailed::Create(QObject *parent) {
return new MqttCommand_HasNodeFailed(parent);
}
bool MqttCommand_HasNodeFailed::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->hasNodeFailed(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef HASNODEFAILED_H
#define HASNODEFAILED_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_HasNodeFailed : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "HasNodeFailed";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_HasNodeFailed(QObject *parent = nullptr);
};
#endif // HASNODEFAILED_H

View file

@ -0,0 +1,16 @@
#include "mqttcommands/healNetwork.h"
MqttCommand_HealNetwork::MqttCommand_HealNetwork(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredBoolFields << "doreturnroute";
}
MqttCommand* MqttCommand_HealNetwork::Create(QObject *parent) {
return new MqttCommand_HealNetwork(parent);
}
bool MqttCommand_HealNetwork::processMessage(rapidjson::Document &msg) {
QTOZWManager *mgr = getOZWManager();
mgr->healNetwork(msg["doreturnroute"].GetBool());
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef HEALNETWORK_H
#define HEALNETWORK_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_HealNetwork : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "HealNetwork";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_HealNetwork(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,20 @@
#include "mqttcommands/healNetworkNode.h"
MqttCommand_HealNetworkNode::MqttCommand_HealNetworkNode(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
this->m_requiredBoolFields << "doreturnroute";
}
MqttCommand* MqttCommand_HealNetworkNode::Create(QObject *parent) {
return new MqttCommand_HealNetworkNode(parent);
}
bool MqttCommand_HealNetworkNode::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
mgr->healNetworkNode(msg["node"].GetUint(), msg["doreturnroute"].GetBool());
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef HEALNETWORKNODE_H
#define HEALNETWORKNODE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_HealNetworkNode : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "HealNetworkNode";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_HealNetworkNode(QObject *parent = nullptr);
};
#endif // HEALNETWORKNODE_H

View file

@ -0,0 +1,270 @@
#include <rapidjson/error/en.h>
#include "mqttcommands/mqttcommands.h"
#include "mqttcommands/ping.h"
#include "mqttcommands/open.h"
#include "mqttcommands/close.h"
#include "mqttcommands/refreshnodeinfo.h"
#include "mqttcommands/requestNodeState.h"
#include "mqttcommands/requestNodeDynamic.h"
#include "mqttcommands/requestConfigParam.h"
#include "mqttcommands/requestAllConfigParam.h"
#include "mqttcommands/softResetController.h"
#include "mqttcommands/hardResetController.h"
#include "mqttcommands/cancelControllerCommand.h"
#include "mqttcommands/testNetworkNode.h"
#include "mqttcommands/testNetwork.h"
#include "mqttcommands/healNetworkNode.h"
#include "mqttcommands/healNetwork.h"
#include "mqttcommands/addNode.h"
#include "mqttcommands/removeNode.h"
#include "mqttcommands/removeFailedNode.h"
#include "mqttcommands/hasNodeFailed.h"
#include "mqttcommands/requestNodeNeighborUpdate.h"
#include "mqttcommands/assignReturnRoute.h"
#include "mqttcommands/deleteAllReturnRoute.h"
#include "mqttcommands/sendNodeInformation.h"
#include "mqttcommands/replaceFailedNode.h"
#include "mqttcommands/requestNetworkUpdate.h"
#include "mqttcommands/IsNodeFailed.h"
#include "mqttcommands/checkLatestConfigFileRevision.h"
#include "mqttcommands/checkLatestMFSRevision.h"
#include "mqttcommands/downloadLatestConfigFileRevision.h"
#include "mqttcommands/downloadLatestMFSRevision.h"
#include "mqttcommands/setValue.h"
#include "mqttcommands/getPollInterval.h"
#include "mqttcommands/setPollInterval.h"
#include "mqttcommands/syncroniseNodeNeighbors.h"
#include "mqttcommands/enablePoll.h"
#include "mqttcommands/refreshValue.h"
Q_LOGGING_CATEGORY(ozwmc, "ozw.mqtt.commands");
MqttCommand::MqttCommand(QObject *parent) :
QObject(parent)
{
}
void MqttCommand::Setup(QMqttSubscription *subscription) {
this->m_subscription = subscription;
qCDebug(ozwmc) << "Subscription Setup for " << this->m_subscription->topic();
connect(this->m_subscription, &QMqttSubscription::messageReceived, this, &MqttCommand::messageReceived);
connect(this, &MqttCommand::sendCommandUpdate, getMqttPublisher(), &mqttpublisher::sendCommandUpdate);
}
QTOZWManager *MqttCommand::getOZWManager() {
mqttpublisher *mqttp = getMqttPublisher();
if (mqttp) {
return mqttp->getQTOZWManager();
}
return nullptr;
}
mqttpublisher *MqttCommand::getMqttPublisher() {
if (this->parent()) {
mqttpublisher *mqttp = qobject_cast<mqttpublisher*>(this->parent());
return mqttp;
}
return nullptr;
}
void MqttCommand::messageReceived(QMqttMessage msg) {
qCDebug(ozwmc) << "Got "<< msg.topic().name()<< " Message: " << msg.payload();
rapidjson::Document jmsg;
jmsg.Parse(msg.payload());
if (jmsg.HasParseError()) {
rapidjson::Document js;
QT2JS::SetString(js, "error", rapidjson::GetParseError_En(jmsg.GetParseError()));
emit sendCommandUpdate(GetCommand(), js);
qCWarning(ozwmc) << "Json Parse Error for " << GetCommand() << ": " << rapidjson::GetParseError_En(jmsg.GetParseError()) << ": " << msg.payload();
return;
}
QString field;
foreach (field, this->m_requiredIntFields) {
if (!jmsg.HasMember(field.toStdString().c_str())) {
rapidjson::Document js;
QT2JS::SetString(js, "error", QString("Missing Field ").append(field).toStdString().c_str());
emit sendCommandUpdate(GetCommand(), js);
qCWarning(ozwmc) << "Missing Field for " << GetCommand() << ": " << field << ": " << msg.payload();
return;
}
if (!jmsg[field.toStdString().c_str()].IsNumber()) {
rapidjson::Document js;
QT2JS::SetString(js, "error", QString("Incorrect Field Type: ").append(field).append(": Not Integer").toStdString().c_str());
emit sendCommandUpdate(GetCommand(), js);
qCWarning(ozwmc) << "Incorrect Field Type (Int) for " << GetCommand() << ": " << field << ": " << jmsg[field.toStdString().c_str()].GetType() << msg.payload();
return;
}
}
foreach (field, this->m_requiredStringFields) {
if (!jmsg.HasMember(field.toStdString().c_str())) {
rapidjson::Document js;
QT2JS::SetString(js, "error", QString("Missing Field ").append(field).toStdString().c_str());
emit sendCommandUpdate(GetCommand(), js);
qCWarning(ozwmc) << "Missing Field for " << GetCommand() << ": " << field << ": " << msg.payload();
return;
}
if (!jmsg[field.toStdString().c_str()].IsString()) {
rapidjson::Document js;
QT2JS::SetString(js, "error", QString("Incorrect Field Type: ").append(field).append(": Not String").toStdString().c_str());
emit sendCommandUpdate(GetCommand(), js);
qCWarning(ozwmc) << "Incorrect Field Type (String) for " << GetCommand() << ": " << field << ": " << jmsg[field.toStdString().c_str()].GetType() << msg.payload();
return;
}
}
foreach (field, this->m_requiredBoolFields) {
if (!jmsg.HasMember(field.toStdString().c_str())) {
rapidjson::Document js;
QT2JS::SetString(js, "error", QString("Missing Field ").append(field).toStdString().c_str());
emit sendCommandUpdate(GetCommand(), js);
qCWarning(ozwmc) << "Missing Field for " << GetCommand() << ": " << field << ": " << msg.payload();
return;
}
if (!jmsg[field.toStdString().c_str()].IsBool()) {
rapidjson::Document js;
QT2JS::SetString(js, "error", QString("Incorrect Field Type: ").append(field).append(": Not Bool").toStdString().c_str());
emit sendCommandUpdate(GetCommand(), js);
qCWarning(ozwmc) << "Incorrect Field Type (Bool) for " << GetCommand() << ": " << field << ": " << jmsg[field.toStdString().c_str()].GetType() << msg.payload();
return;
}
}
if (this->processMessage(jmsg)) {
qCInfo(ozwmc) << "Processed Message for " << GetCommand() << ": " << msg.payload();
return;
} else {
qCWarning(ozwmc) << "Message Processing for " << GetCommand() << " failed: " << msg.payload();
}
}
bool MqttCommand::checkNode(rapidjson::Document &jmsg, QString field) {
if (!jmsg.HasMember(field.toStdString().c_str())) {
qCWarning(ozwmc) << "Node " << field <<" Is Missing from Message";
return false;
}
if (!jmsg[field.toStdString().c_str()].IsUint()) {
qCWarning(ozwmc) << "Node " << field << "is not a Uint32";
return false;
}
quint8 node = jmsg[field.toStdString().c_str()].GetInt();
if (node == 0 || node == 255) {
qCWarning(ozwmc) << "Invalid Node in field " << field << " for message";
return false;
}
if (this->getMqttPublisher()->isValidNode(node)) {
return true;
}
qCWarning(ozwmc) << "Invalid Node in field " << field << " for message ";
return false;
}
bool MqttCommand::checkValue(rapidjson::Document &jmsg, QString field) {
if (!jmsg.HasMember(field.toStdString().c_str())) {
qCWarning(ozwmc) << "ValueIDKey " << field <<" Is Missing from Message";
return false;
}
if (!jmsg[field.toStdString().c_str()].IsUint64()) {
qCWarning(ozwmc) << "ValueIDKey " << field << " Is not a uint64";
return false;
}
quint64 vidKey = jmsg[field.toStdString().c_str()].GetUint64();
if (vidKey == 0) {
qCWarning(ozwmc) << "Invalid VidKey in field " << field << " for message ";
return false;
}
if (this->getMqttPublisher()->isValidValueID(vidKey)) {
return true;
}
qCWarning(ozwmc) << "Invalid VidKey in field " << field << " for message ";
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);
}
bool MqttCommand::sendSimpleStatus(bool status, QString error) {
rapidjson::Document js;
if (status == true) {
QT2JS::SetString(js, "status", "ok");
} else {
QT2JS::SetString(js, "status", "failed");
if (!error.isEmpty())
QT2JS::SetString(js, "error", error);
}
emit sendCommandUpdate(GetCommand(), js);
return status;
}
MqttCommands::MqttCommands(QObject *parent) :
QObject(parent)
{
}
void MqttCommands::Register(QString command, pfnCreateCommand_t _create) {
qCDebug(ozwmc) << "Registering Command " << command;
this->m_commands.insert(command, _create);
}
void MqttCommands::setupCommands() {
this->Register(MqttCommand_Ping::StaticGetCommand(), &MqttCommand_Ping::Create);
this->Register(MqttCommand_Open::StaticGetCommand(), &MqttCommand_Open::Create);
this->Register(MqttCommand_Close::StaticGetCommand(), &MqttCommand_Close::Create);
this->Register(MqttCommand_RefreshNodeInfo::StaticGetCommand(), &MqttCommand_RefreshNodeInfo::Create);
this->Register(MqttCommand_RequestNodeState::StaticGetCommand(), &MqttCommand_RequestNodeState::Create);
this->Register(MqttCommand_RequestNodeDynamic::StaticGetCommand(), &MqttCommand_RequestNodeDynamic::Create);
this->Register(MqttCommand_RequestConfigParam::StaticGetCommand(), &MqttCommand_RequestConfigParam::Create);
this->Register(MqttCommand_RequestAllConfigParam::StaticGetCommand(), &MqttCommand_RequestAllConfigParam::Create);
this->Register(MqttCommand_SoftResetController::StaticGetCommand(), &MqttCommand_SoftResetController::Create);
this->Register(MqttCommand_HardResetController::StaticGetCommand(), &MqttCommand_HardResetController::Create);
this->Register(MqttCommand_CancelControllerCommand::StaticGetCommand(), &MqttCommand_CancelControllerCommand::Create);
this->Register(MqttCommand_TestNetworkNode::StaticGetCommand(), &MqttCommand_TestNetworkNode::Create);
this->Register(MqttCommand_TestNetwork::StaticGetCommand(), &MqttCommand_TestNetwork::Create);
this->Register(MqttCommand_HealNetworkNode::StaticGetCommand(), &MqttCommand_HealNetworkNode::Create);
this->Register(MqttCommand_HealNetwork::StaticGetCommand(), &MqttCommand_HealNetwork::Create);
this->Register(MqttCommand_AddNode::StaticGetCommand(), &MqttCommand_AddNode::Create);
this->Register(MqttCommand_RemoveNode::StaticGetCommand(), &MqttCommand_RemoveNode::Create);
this->Register(MqttCommand_RemoveFailedNode::StaticGetCommand(), &MqttCommand_RemoveFailedNode::Create);
this->Register(MqttCommand_HasNodeFailed::StaticGetCommand(), &MqttCommand_HasNodeFailed::Create);
this->Register(MqttCommand_RequestNodeNeighborUpdate::StaticGetCommand(), &MqttCommand_RequestNodeNeighborUpdate::Create);
this->Register(MqttCommand_AssignReturnRoute::StaticGetCommand(), &MqttCommand_AssignReturnRoute::Create);
this->Register(MqttCommand_DeleteAllReturnRoute::StaticGetCommand(), &MqttCommand_DeleteAllReturnRoute::Create);
this->Register(MqttCommand_SendNodeInformation::StaticGetCommand(), &MqttCommand_SendNodeInformation::Create);
this->Register(MqttCommand_ReplaceFailedNode::StaticGetCommand(), &MqttCommand_ReplaceFailedNode::Create);
this->Register(MqttCommand_RequestNetworkUpdate::StaticGetCommand(), &MqttCommand_RequestNetworkUpdate::Create);
this->Register(MqttCommand_IsNodeFailed::StaticGetCommand(), &MqttCommand_IsNodeFailed::Create);
this->Register(MqttCommand_CheckLatestConfigFileRevision::StaticGetCommand(), &MqttCommand_CheckLatestConfigFileRevision::Create);
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);
this->Register(MqttCommand_GetPollInterval::StaticGetCommand(), &MqttCommand_GetPollInterval::Create);
this->Register(MqttCommand_SetPollInterval::StaticGetCommand(), &MqttCommand_SetPollInterval::Create);
this->Register(MqttCommand_SyncroniseNodeNeighbors::StaticGetCommand(), &MqttCommand_SyncroniseNodeNeighbors::Create);
// this->Register(MqttCommand_EnablePoll::StaticGetCommand(), &MqttCommand_EnablePoll::Create);
this->Register(MqttCommand_RefreshValue::StaticGetCommand(), &MqttCommand_RefreshValue::Create);
}
void MqttCommands::setupSubscriptions(QMqttClient *mqttclient, QString topTopic) {
QMap<QString, pfnCreateCommand_t>::iterator it;
for (it = this->m_commands.begin(); it != this->m_commands.end(); it++) {
qCDebug(ozwmc) << "Creating Subscription for " << it.key();
pfnCreateCommand_t cmd = it.value();
MqttCommand *command = cmd(this->parent());
QMqttSubscription *subscription = mqttclient->subscribe(QMqttTopicFilter(topTopic.arg(it.key().toLower())));
command->Setup(subscription);
}
}

View file

@ -0,0 +1,62 @@
#ifndef MQTTCOMMANDS_H
#define MQTTCOMMANDS_H
#include <QObject>
#include <QString>
#include <QMap>
#include <QtMqtt/QMqttClient>
#include <QtMqtt/QMqttSubscription>
#include <qt-openzwave/qtopenzwave.h>
#include <qt-openzwave/qtozwmanager.h>
#include <qt-openzwave/qtozwvalueidmodel.h>
#include "mqttpublisher.h"
#include "qtrj.h"
class mqttpublisher;
class MqttCommand : public QObject {
Q_OBJECT
public:
void Setup(QMqttSubscription *);
void messageReceived(QMqttMessage msg);
virtual bool processMessage(rapidjson::Document &) = 0;
virtual QString GetCommand() = 0;
signals:
void sendCommandUpdate(QString, rapidjson::Document &);
protected:
MqttCommand(QObject *parent = nullptr);
QTOZWManager *getOZWManager();
mqttpublisher *getMqttPublisher();
bool checkNode(rapidjson::Document &, QString);
bool checkValue(rapidjson::Document &, QString);
QVariant getValueData(quint64, QTOZW_ValueIds::ValueIdColumns);
bool setValue(quint64, QVariant);
QVector<QString> m_requiredStringFields;
QVector<QString> m_requiredIntFields;
QVector<QString> m_requiredBoolFields;
bool sendSimpleStatus(bool, QString error = QString());
private:
QMqttSubscription *m_subscription;
};
typedef MqttCommand* (*pfnCreateCommand_t)(QObject *);
class MqttCommands : public QObject {
Q_OBJECT
public:
MqttCommands(QObject *parent = nullptr);
void Register(QString command, pfnCreateCommand_t _create);
void setupCommands();
void setupSubscriptions(QMqttClient *, QString);
private:
QMap<QString, pfnCreateCommand_t> m_commands;
};
#endif

View file

@ -0,0 +1,15 @@
#include "mqttcommands/open.h"
MqttCommand_Open::MqttCommand_Open(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredStringFields << "serialport";
}
MqttCommand* MqttCommand_Open::Create(QObject *parent) {
return new MqttCommand_Open(parent);
}
bool MqttCommand_Open::processMessage(rapidjson::Document &msg) {
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->open(msg["serialport"].GetString()));
}

View file

@ -0,0 +1,17 @@
#ifndef OPEN_H
#define OPEN_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_Open : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "Open";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_Open(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,17 @@
#include "mqttcommands/ping.h"
MqttCommand_Ping::MqttCommand_Ping(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredStringFields << "ping";
}
MqttCommand* MqttCommand_Ping::Create(QObject *parent) {
return new MqttCommand_Ping(parent);
}
bool MqttCommand_Ping::processMessage(rapidjson::Document &msg) {
rapidjson::Document js;
QT2JS::SetString(js, "pong", msg["ping"].GetString());
emit sendCommandUpdate(MqttCommand_Ping::GetCommand(), js);
return true;
}

View file

@ -0,0 +1,17 @@
#ifndef PING_H
#define PING_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_Ping : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "Ping";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_Ping(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,19 @@
#include "mqttcommands/refreshValue.h"
MqttCommand_RefreshValue::MqttCommand_RefreshValue(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "ValueIDKey";
}
MqttCommand* MqttCommand_RefreshValue::Create(QObject *parent) {
return new MqttCommand_RefreshValue(parent);
}
bool MqttCommand_RefreshValue::processMessage(rapidjson::Document &msg) {
if (!this->checkValue(msg, "ValueIDKey")) {
return this->sendSimpleStatus(false, "Invalid ValueIDKey Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->refreshValue(msg["ValueIDKey"].GetUint64()));
}

View file

@ -0,0 +1,17 @@
#ifndef REFRESHVALUE_H
#define REFRESHVALUE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RefreshValue : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "refreshValue";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RefreshValue(QObject *parent = nullptr);
};
#endif // REFRESHVALUE_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/refreshnodeinfo.h"
MqttCommand_RefreshNodeInfo::MqttCommand_RefreshNodeInfo(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_RefreshNodeInfo::Create(QObject *parent) {
return new MqttCommand_RefreshNodeInfo(parent);
}
bool MqttCommand_RefreshNodeInfo::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->refreshNodeInfo(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef REFRESHNODEINFO_H
#define REFRESHNODEINFO_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RefreshNodeInfo : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RefreshNodeInfo";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RefreshNodeInfo(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/removeFailedNode.h"
MqttCommand_RemoveFailedNode::MqttCommand_RemoveFailedNode(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_RemoveFailedNode::Create(QObject *parent) {
return new MqttCommand_RemoveFailedNode(parent);
}
bool MqttCommand_RemoveFailedNode::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->removeFailedNode(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef REMOVEFAILEDNODE_H
#define REMOVEFAILEDNODE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RemoveFailedNode : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RemoveFailedNode";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RemoveFailedNode(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,16 @@
#include "mqttcommands/removeNode.h"
MqttCommand_RemoveNode::MqttCommand_RemoveNode(QObject *parent) :
MqttCommand(parent)
{
}
MqttCommand* MqttCommand_RemoveNode::Create(QObject *parent) {
return new MqttCommand_RemoveNode(parent);
}
bool MqttCommand_RemoveNode::processMessage(rapidjson::Document &msg) {
Q_UNUSED(msg);
QTOZWManager *mgr = getOZWManager();
mgr->removeNode();
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef REMOVENODE_H
#define REMOVENODE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RemoveNode : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RemoveNode";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RemoveNode(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/replaceFailedNode.h"
MqttCommand_ReplaceFailedNode::MqttCommand_ReplaceFailedNode(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_ReplaceFailedNode::Create(QObject *parent) {
return new MqttCommand_ReplaceFailedNode(parent);
}
bool MqttCommand_ReplaceFailedNode::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->replaceFailedNode(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef REPLACEFAILEDNODE_H
#define REPLACEFAILEDNODE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_ReplaceFailedNode : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "ReplaceFailedNode";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_ReplaceFailedNode(QObject *parent = nullptr);
};
#endif // REPLACEFAILEDNODE_H

View file

@ -0,0 +1,19 @@
#include "mqttcommands/requestAllConfigParam.h"
MqttCommand_RequestAllConfigParam::MqttCommand_RequestAllConfigParam(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_RequestAllConfigParam::Create(QObject *parent) {
return new MqttCommand_RequestAllConfigParam(parent);
}
bool MqttCommand_RequestAllConfigParam::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
mgr->requestAllConfigParam(msg["node"].GetUint());
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef REQUESTALLCONFIGPARAM_H
#define REQUESTALLCONFIGPARAM_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RequestAllConfigParam : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RequestAllConfigParam";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RequestAllConfigParam(QObject *parent = nullptr);
};
#endif // REQUESTALLCONFIGPARAM_H

View file

@ -0,0 +1,19 @@
#include "mqttcommands/requestConfigParam.h"
MqttCommand_RequestConfigParam::MqttCommand_RequestConfigParam(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node" << "param";
}
MqttCommand* MqttCommand_RequestConfigParam::Create(QObject *parent) {
return new MqttCommand_RequestConfigParam(parent);
}
bool MqttCommand_RequestConfigParam::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
mgr->requestConfigParam(msg["node"].GetUint(), msg["param"].GetUint());
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef REQUESTCONFIGPARAM_H
#define REQUESTCONFIGPARAM_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RequestConfigParam : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RequestConfigParam";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RequestConfigParam(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/requestNetworkUpdate.h"
MqttCommand_RequestNetworkUpdate::MqttCommand_RequestNetworkUpdate(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_RequestNetworkUpdate::Create(QObject *parent) {
return new MqttCommand_RequestNetworkUpdate(parent);
}
bool MqttCommand_RequestNetworkUpdate::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->requestNetworkUpdate(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef REQUESTNETWORKUPDATE_H
#define REQUESTNETWORKUPDATE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RequestNetworkUpdate : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RequestNetworkUpdate";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RequestNetworkUpdate(QObject *parent = nullptr);
};
#endif // REQUESTNETWORKUPDATE_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/requestNodeDynamic.h"
MqttCommand_RequestNodeDynamic::MqttCommand_RequestNodeDynamic(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_RequestNodeDynamic::Create(QObject *parent) {
return new MqttCommand_RequestNodeDynamic(parent);
}
bool MqttCommand_RequestNodeDynamic::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->requestNodeDynamic(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef REQUESTNODEDYNAMIC_H
#define REQUESTNODEDYNAMIC_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RequestNodeDynamic : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RequestNodeDynamic";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RequestNodeDynamic(QObject *parent = nullptr);
};
#endif // REQUESTNODEDYNAMIC_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/requestNodeNeighborUpdate.h"
MqttCommand_RequestNodeNeighborUpdate::MqttCommand_RequestNodeNeighborUpdate(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_RequestNodeNeighborUpdate::Create(QObject *parent) {
return new MqttCommand_RequestNodeNeighborUpdate(parent);
}
bool MqttCommand_RequestNodeNeighborUpdate::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->requestNodeNeighborUpdate(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef REQUESTNODENEIGHBORUPDATE_H
#define REQUESTNODENEIGHBORUPDATE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RequestNodeNeighborUpdate : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RequestNodeNeighborUpdate";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RequestNodeNeighborUpdate(QObject *parent = nullptr);
};
#endif // REQUESTNODENEIGHBORUPDATE_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/requestNodeState.h"
MqttCommand_RequestNodeState::MqttCommand_RequestNodeState(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_RequestNodeState::Create(QObject *parent) {
return new MqttCommand_RequestNodeState(parent);
}
bool MqttCommand_RequestNodeState::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->requestNodeState(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef REQUESTNODESTATE_H
#define REQUESTNODESTATE_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_RequestNodeState : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "RequestNodeState";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_RequestNodeState(QObject *parent = nullptr);
};
#endif // REQUESTNODESTATE_H

View file

@ -0,0 +1,18 @@
#include "mqttcommands/sendNodeInformation.h"
MqttCommand_SendNodeInformation::MqttCommand_SendNodeInformation(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "node";
}
MqttCommand* MqttCommand_SendNodeInformation::Create(QObject *parent) {
return new MqttCommand_SendNodeInformation(parent);
}
bool MqttCommand_SendNodeInformation::processMessage(rapidjson::Document &msg) {
if (!this->checkNode(msg, "node")) {
return this->sendSimpleStatus(false, "Invalid Node Number");
}
QTOZWManager *mgr = getOZWManager();
return this->sendSimpleStatus(mgr->sendNodeInformation(msg["node"].GetUint()));
}

View file

@ -0,0 +1,17 @@
#ifndef SENTNODEINFORMATION_H
#define SENTNODEINFORMATION_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_SendNodeInformation : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "SendNodeInformation";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_SendNodeInformation(QObject *parent = nullptr);
};
#endif // PING_H

View file

@ -0,0 +1,17 @@
#include "mqttcommands/setPollInterval.h"
MqttCommand_SetPollInterval::MqttCommand_SetPollInterval(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "interval";
this->m_requiredBoolFields << "intervalBetweenPoll";
}
MqttCommand* MqttCommand_SetPollInterval::Create(QObject *parent) {
return new MqttCommand_SetPollInterval(parent);
}
bool MqttCommand_SetPollInterval::processMessage(rapidjson::Document &msg) {
QTOZWManager *mgr = getOZWManager();
mgr->setPollInterval(msg["interval"].GetUint(), msg["intervalBetweenPoll"].GetBool());
return this->sendSimpleStatus(true);
}

View file

@ -0,0 +1,17 @@
#ifndef SETPOLLINTERVAL_H
#define SETPOLLINTERVAL_H
#include "mqttcommands/mqttcommands.h"
class MqttCommand_SetPollInterval : public MqttCommand {
Q_OBJECT
public:
static MqttCommand *Create(QObject *parent = nullptr);
static QString StaticGetCommand() { return "setPollInterval";};
QString GetCommand() override { return StaticGetCommand(); };
bool processMessage(rapidjson::Document &) override;
private:
MqttCommand_SetPollInterval(QObject *parent = nullptr);
};
#endif // SETPOLLINTERVAL_H

View file

@ -0,0 +1,187 @@
#include "mqttcommands/setValue.h"
Q_LOGGING_CATEGORY(ozwmcsv, "ozw.mqtt.commands.setValue");
MqttCommand_SetValue::MqttCommand_SetValue(QObject *parent) :
MqttCommand(parent)
{
this->m_requiredIntFields << "ValueIDKey";
}
MqttCommand* MqttCommand_SetValue::Create(QObject *parent) {
return new MqttCommand_SetValue(parent);
}
bool MqttCommand_SetValue::processMessage(rapidjson::Document &msg) {
if (!this->checkValue(msg, "ValueIDKey")) {
return this->sendSimpleStatus(false, "Invalid ValueIDKey Number");
}
/* check that the Value Field exists */
if (!msg.HasMember("Value")) {
return this->sendSimpleStatus(false, "Missing Field Value");
}
quint64 vidKey = msg["ValueIDKey"].GetUint();
QBitArray flags = this->getValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::ValueFlags).value<QBitArray>();
if (flags[QTOZW_ValueIds::ValueIDFlags::ReadOnly] == true) {
return this->sendSimpleStatus(false, "ValueID is Read Only");
}
QTOZW_ValueIds::ValueIdTypes types = this->getValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Type).value<QTOZW_ValueIds::ValueIdTypes>();
QVariant data;
switch (types) {
case QTOZW_ValueIds::ValueIdTypes::BitSet: {
if (!msg["Value"].IsArray()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Array: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (Array) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
rapidjson::Value bitsets = msg["Value"].GetArray();
QTOZW_ValueIDBitSet bits = this->getValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Value).value<QTOZW_ValueIDBitSet>();
for (rapidjson::SizeType i = 0; i < bitsets.Size(); i++) {
qint32 pos = -1;
if (bitsets[i].HasMember("Label")) {
QString label = bitsets[i]["Label"].GetString();
pos = bits.label.key(label, -1);
} else if (bitsets[i].HasMember("Position")) {
pos = bitsets[i]["Position"].GetUint();
} else {
this->sendSimpleStatus(false, QString("BitSet Array Does not have a Label or Position Value: "));
qCWarning(ozwmcsv) << "BitSet Array does not have a Label or Position Value:" << GetCommand() << ": Value: " << msg["Value"].GetString();
return false;
}
if (pos < 0) {
this->sendSimpleStatus(false, QString("BitSet Array Does not have a Valid Label or Position Value: "));
qCWarning(ozwmcsv) << "BitSet Array does not have a Valid Label or Position Value:" << GetCommand() << ": Value: " << msg["Value"].GetString();
return false;
}
if (bits.values[pos] != bitsets[i]["Value"].GetBool()) {
bits.values.setBit(pos, bitsets[i]["Value"].GetBool());
}
}
data = QVariant::fromValue<QTOZW_ValueIDBitSet>(bits);
break;
}
case QTOZW_ValueIds::ValueIdTypes::Bool: {
if (!msg["Value"].IsBool()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Bool: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (Bool) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
data = msg["Value"].GetBool();
break;
}
case QTOZW_ValueIds::ValueIdTypes::Button: {
if (!msg["Value"].IsBool()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Bool: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (Bool) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
data = msg["Value"].GetBool();
break;
}
case QTOZW_ValueIds::ValueIdTypes::Byte: {
if (!msg["Value"].IsUint()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Byte: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (Byte) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
if (msg["Value"].GetUint() > UCHAR_MAX) {
this->sendSimpleStatus(false, QString("Value is Larger than Byte Field: ").append(msg["Value"].GetUint()));
qCWarning(ozwmcsv) << "Value is Larger than Byte Field for " << GetCommand() << ": Value: " << msg["Value"].GetUint();
return false;
}
data = msg["Value"].GetUint();
break;
}
case QTOZW_ValueIds::ValueIdTypes::Decimal: {
if (!msg["Value"].IsDouble()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Decimal: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (Decimal) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
data = msg["Value"].GetDouble();
break;
}
case QTOZW_ValueIds::ValueIdTypes::Int: {
if (!msg["Value"].IsUint()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Integer: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (Integer) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
if (static_cast<uint>(msg["Value"].GetUint()) > UINT_MAX) {
this->sendSimpleStatus(false, QString("Value is Larger than Integer Field: ").append(msg["Value"].GetUint()));
qCWarning(ozwmcsv) << "Value is Larger than Integer Field for " << GetCommand() << ": Value: " << msg["Value"].GetUint();
return false;
}
data = msg["Value"].GetUint();
break;
}
case QTOZW_ValueIds::ValueIdTypes::List: {
if (!msg["Value"].IsUint()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Integer: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (Integer) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
QTOZW_ValueIDList list = this->getValueData(vidKey, QTOZW_ValueIds::ValueIdColumns::Value).value<QTOZW_ValueIDList>();
int index = list.values.indexOf(msg["Value"].GetUint());
if (index < 0) {
this->sendSimpleStatus(false, QString("Selected List Value is not in Lists: ").append(msg["Value"].GetUint()));
qCWarning(ozwmcsv) << "Selected List Value is Not In List for " << GetCommand() << ": Value: " << msg["Value"].GetUint() << "List:" << list.labels;
return false;
}
list.selectedItem = list.labels[index];
data.fromValue<QTOZW_ValueIDList>(list);
break;
}
case QTOZW_ValueIds::ValueIdTypes::Raw: {
if (!msg["Value"].IsString()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not String: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (String) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
data = QByteArray::fromHex(msg["Value"].GetString());
break;
}
case QTOZW_ValueIds::ValueIdTypes::Schedule: {
qCWarning(ozwmcsv) << "Raw/Schedule Not Done Yet";
return false;
}
case QTOZW_ValueIds::ValueIdTypes::Short: {
if (!msg["Value"].IsUint()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not Short: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (Short) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
if (msg["Value"].GetUint() > USHRT_MAX) {
this->sendSimpleStatus(false, QString("Value is Larger than Short Field: ").append(msg["Value"].GetUint()));
qCWarning(ozwmcsv) << "Value is Larger than Short Field for " << GetCommand() << ": Value: " << msg["Value"].GetUint();
return false;
}
data = msg["Value"].GetUint();
break;
}
case QTOZW_ValueIds::ValueIdTypes::String: {
if (!msg["Value"].IsString()) {
this->sendSimpleStatus(false, QString("Incorrect Field Type for Value: Not String: ").append(msg["Value"].GetType()));
qCWarning(ozwmcsv) << "Incorrect Field Type (String) for " << GetCommand() << ": Value: " << msg["Value"].GetType();
return false;
}
data = msg["Value"].GetString();
break;
}
case QTOZW_ValueIds::ValueIdTypes::TypeCount: {
qCWarning(ozwmcsv) << "Invalid ValueID Type " << types << "for setValue";
return this->sendSimpleStatus(false, "Unknown ValueID Type");
break;
}
}
if (data.isNull()) {
qCWarning(ozwmcsv) << "Data is undefined for setValue... Json Conversion Failed?";
return this->sendSimpleStatus(false, "JSON Conversion Failed");
}
qCInfo(ozwmcsv) << "Setting " << vidKey << " to Value " << data;
return this->sendSimpleStatus(this->setValue(vidKey, data));
}

Some files were not shown because too many files have changed in this diff Show more