diff --git a/debian/control b/debian/control index 0581cb77..825ff765 100644 --- a/debian/control +++ b/debian/control @@ -26,6 +26,7 @@ Build-Depends: debhelper (>= 9.0.0), qttools5-dev-tools, qtconnectivity5-dev, qtdeclarative5-dev, + | libqt5serialbus5-dev (>= 5.8~) Package: nymea Architecture: any diff --git a/libnymea-core/hardware/modbus/modbusrtuhardwareresourceimplementation.cpp b/libnymea-core/hardware/modbus/modbusrtuhardwareresourceimplementation.cpp new file mode 100644 index 00000000..26d347ec --- /dev/null +++ b/libnymea-core/hardware/modbus/modbusrtuhardwareresourceimplementation.cpp @@ -0,0 +1,97 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "modbusrtuhardwareresourceimplementation.h" +#include "loggingcategories.h" +#include "nymeasettings.h" + +NYMEA_LOGGING_CATEGORY(dcModbusRtuResource, "ModbusRtuResource") + +namespace nymeaserver { + +ModbusRtuHardwareResourceImplementation::ModbusRtuHardwareResourceImplementation(QObject *parent) : + ModbusRtuHardwareResource(parent) +{ + +} + +bool ModbusRtuHardwareResourceImplementation::available() const +{ + return m_available; +} + +bool ModbusRtuHardwareResourceImplementation::enabled() const +{ + return m_enabled; +} + +bool ModbusRtuHardwareResourceImplementation::enable() +{ + qCWarning(dcModbusRtuResource()) << "Enable hardware resource. Not implemented yet."; + + // TODO: enable all modbus clients + + return true; +} + +bool ModbusRtuHardwareResourceImplementation::disable() +{ + qCWarning(dcModbusRtuResource()) << "Disable hardware resource. Not implemented yet."; + + // TODO: disable all modbus clients + + return true; +} + +void ModbusRtuHardwareResourceImplementation::setEnabled(bool enabled) +{ + qCDebug(dcModbusRtuResource()) << "Set" << (enabled ? "enabled" : "disabled"); + if (m_enabled && enabled) { + qCDebug(dcModbusRtuResource()) << "Already enabled."; + return; + } else if (!m_enabled && !enabled) { + qCDebug(dcModbusRtuResource()) << "Already disabled."; + return; + } + + bool success = false; + if (enabled) { + success = enable(); + } else { + success = disable(); + } + + if (success) { + m_enabled = enabled; + emit enabledChanged(m_enabled); + } +} + +} diff --git a/libnymea-core/hardware/modbus/modbusrtuhardwareresourceimplementation.h b/libnymea-core/hardware/modbus/modbusrtuhardwareresourceimplementation.h new file mode 100644 index 00000000..8fd10b2d --- /dev/null +++ b/libnymea-core/hardware/modbus/modbusrtuhardwareresourceimplementation.h @@ -0,0 +1,65 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef MODBUSRTUHARDWARERESOURCEIMPLEMENTATION_H +#define MODBUSRTUHARDWARERESOURCEIMPLEMENTATION_H + +#include + +#include "hardware/modbus/modbusrtuhardwareresource.h" + +namespace nymeaserver { + +class ModbusRtuHardwareResourceImplementation : public ModbusRtuHardwareResource +{ + Q_OBJECT +public: + explicit ModbusRtuHardwareResourceImplementation(QObject *parent = nullptr); + + bool available() const override; + bool enabled() const override; + +public slots: + bool enable(); + bool disable(); + + +protected: + void setEnabled(bool enabled) override; + +private: + bool m_available = false; + bool m_enabled = false; + +}; + +} + +#endif // MODBUSRTUHARDWARERESOURCEIMPLEMENTATION_H diff --git a/libnymea-core/jsonrpc/modbusrtuhandler.cpp b/libnymea-core/jsonrpc/modbusrtuhandler.cpp new file mode 100644 index 00000000..535deb6b --- /dev/null +++ b/libnymea-core/jsonrpc/modbusrtuhandler.cpp @@ -0,0 +1,45 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "modbusrtuhandler.h" + +namespace nymeaserver { + +ModbusRtuHandler::ModbusRtuHandler(QObject *parent) : JsonHandler(parent) +{ + +} + +QString ModbusRtuHandler::name() const +{ + return "ModbusRtu"; +} + +} diff --git a/libnymea-core/jsonrpc/modbusrtuhandler.h b/libnymea-core/jsonrpc/modbusrtuhandler.h new file mode 100644 index 00000000..a0242525 --- /dev/null +++ b/libnymea-core/jsonrpc/modbusrtuhandler.h @@ -0,0 +1,54 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef MODBUSRTUHANDLER_H +#define MODBUSRTUHANDLER_H + +#include + +#include "jsonrpc/jsonhandler.h" + +namespace nymeaserver { + +class ModbusRtuHandler : public JsonHandler +{ + Q_OBJECT +public: + explicit ModbusRtuHandler(QObject *parent = nullptr); + + QString name() const override; + +signals: + +}; + +} + +#endif // MODBUSRTUHANDLER_H diff --git a/libnymea-core/libnymea-core.pro b/libnymea-core/libnymea-core.pro index 1d2d0197..6847069d 100644 --- a/libnymea-core/libnymea-core.pro +++ b/libnymea-core/libnymea-core.pro @@ -35,6 +35,17 @@ CONFIG(withoutpython) { CONFIG -= python } +# Qt serial bus module is officially available since Qt 5.8 +# but not all platforms host the qt serialbus package. +# Let's check if the package exists, not the qt version +packagesExist(Qt5SerialBus) { + DEFINES += WITH_QTSERIALBUS + Qt += serialbus +} else { + message("Qt5SerialBus not available") +} + + target.path = $$[QT_INSTALL_LIBS] INSTALLS += target @@ -44,6 +55,7 @@ RESOURCES += $$top_srcdir/icons.qrc \ HEADERS += nymeacore.h \ + hardware/modbus/modbusrtuhardwareresourceimplementation.h \ integrations/apikeysprovidersloader.h \ integrations/plugininfocache.h \ integrations/python/pyapikeystorage.h \ @@ -55,7 +67,10 @@ HEADERS += nymeacore.h \ integrations/thingmanagerimplementation.h \ integrations/translator.h \ experiences/experiencemanager.h \ + jsonrpc/modbusrtuhandler.h \ jsonrpc/zigbeehandler.h \ + modbus/modbusrtumanager.h \ + modbus/modbusrtumaster.h \ ruleengine/ruleengine.h \ ruleengine/rule.h \ ruleengine/stateevaluator.h \ @@ -138,12 +153,16 @@ HEADERS += nymeacore.h \ SOURCES += nymeacore.cpp \ + hardware/modbus/modbusrtuhardwareresourceimplementation.cpp \ integrations/apikeysprovidersloader.cpp \ integrations/plugininfocache.cpp \ integrations/thingmanagerimplementation.cpp \ integrations/translator.cpp \ experiences/experiencemanager.cpp \ + jsonrpc/modbusrtuhandler.cpp \ jsonrpc/zigbeehandler.cpp \ + modbus/modbusrtumanager.cpp \ + modbus/modbusrtumaster.cpp \ ruleengine/ruleengine.cpp \ ruleengine/rule.cpp \ ruleengine/stateevaluator.cpp \ diff --git a/libnymea-core/modbus/modbusrtumanager.cpp b/libnymea-core/modbus/modbusrtumanager.cpp new file mode 100644 index 00000000..af2edba9 --- /dev/null +++ b/libnymea-core/modbus/modbusrtumanager.cpp @@ -0,0 +1,44 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "modbusrtumanager.h" +#include "nymeasettings.h" +#include "loggingcategories.h" + +NYMEA_LOGGING_CATEGORY(dcModbusRtu, "ModbusRtu") + +namespace nymeaserver { + +ModbusRtuManager::ModbusRtuManager(QObject *parent) : QObject(parent) +{ + +} + +} diff --git a/libnymea-core/modbus/modbusrtumanager.h b/libnymea-core/modbus/modbusrtumanager.h new file mode 100644 index 00000000..47ddfdbb --- /dev/null +++ b/libnymea-core/modbus/modbusrtumanager.h @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef MODBUSRTUMANAGER_H +#define MODBUSRTUMANAGER_H + +#include + +namespace nymeaserver { + +class ModbusRtuManager : public QObject +{ + Q_OBJECT +public: + explicit ModbusRtuManager(QObject *parent = nullptr); + +signals: + +}; + +} + +#endif // MODBUSRTUMANAGER_H diff --git a/libnymea-core/modbus/modbusrtumaster.cpp b/libnymea-core/modbus/modbusrtumaster.cpp new file mode 100644 index 00000000..69f98b13 --- /dev/null +++ b/libnymea-core/modbus/modbusrtumaster.cpp @@ -0,0 +1,40 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "modbusrtumaster.h" + +namespace nymeaserver { + +ModbusRtuMaster::ModbusRtuMaster(QObject *parent) : QObject(parent) +{ + +} + +} diff --git a/libnymea-core/modbus/modbusrtumaster.h b/libnymea-core/modbus/modbusrtumaster.h new file mode 100644 index 00000000..8cc42e52 --- /dev/null +++ b/libnymea-core/modbus/modbusrtumaster.h @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef MODBUSRTUMASTER_H +#define MODBUSRTUMASTER_H + +#include + +namespace nymeaserver { + +class ModbusRtuMaster : public QObject +{ + Q_OBJECT +public: + explicit ModbusRtuMaster(QObject *parent = nullptr); + +signals: + +}; + +} + +#endif // MODBUSRTUMASTER_H diff --git a/libnymea/hardware/modbus/modbusrtuhardwareresource.cpp b/libnymea/hardware/modbus/modbusrtuhardwareresource.cpp new file mode 100644 index 00000000..2b9be8a4 --- /dev/null +++ b/libnymea/hardware/modbus/modbusrtuhardwareresource.cpp @@ -0,0 +1,37 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "modbusrtuhardwareresource.h" + +ModbusRtuHardwareResource::ModbusRtuHardwareResource(QObject *parent) : + HardwareResource("Modbus RTU client resource", parent) +{ + +} diff --git a/libnymea/hardware/modbus/modbusrtuhardwareresource.h b/libnymea/hardware/modbus/modbusrtuhardwareresource.h new file mode 100644 index 00000000..a6cfc497 --- /dev/null +++ b/libnymea/hardware/modbus/modbusrtuhardwareresource.h @@ -0,0 +1,48 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2021, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU Lesser General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU Lesser General Public License as published by the Free +* Software Foundation; version 3. This project is distributed in the hope that +* it will be useful, but WITHOUT ANY WARRANTY; without even the implied +* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef MODBUSRTUHARDWARERESOURCE_H +#define MODBUSRTUHARDWARERESOURCE_H + +#include +#include "hardwareresource.h" + +class ModbusRtuHardwareResource : public HardwareResource +{ + Q_OBJECT +public: + explicit ModbusRtuHardwareResource(QObject *parent = nullptr); + virtual ~ModbusRtuHardwareResource() = default; + +signals: + +}; + +#endif // MODBUSRTUHARDWARERESOURCE_H diff --git a/libnymea/libnymea.pro b/libnymea/libnymea.pro index 02e7b57f..b9de355e 100644 --- a/libnymea/libnymea.pro +++ b/libnymea/libnymea.pro @@ -13,6 +13,7 @@ PKGCONFIG += nymea-zigbee nymea-mqtt QMAKE_LFLAGS += -fPIC HEADERS += \ + hardware/modbus/modbusrtuhardwareresource.h \ hardware/zigbee/zigbeehandler.h \ hardware/zigbee/zigbeehardwareresource.h \ integrations/browseractioninfo.h \ @@ -108,6 +109,7 @@ HEADERS += \ experiences/experienceplugin.h \ SOURCES += \ + hardware/modbus/modbusrtuhardwareresource.cpp \ hardware/zigbee/zigbeehandler.cpp \ hardware/zigbee/zigbeehardwareresource.cpp \ integrations/browseractioninfo.cpp \