Add basic modbus rtu hardware resource structure

This commit is contained in:
Simon Stürz 2021-02-01 15:21:14 +01:00
parent 1acd8ca808
commit b4d97080bd
13 changed files with 552 additions and 0 deletions

1
debian/control vendored
View File

@ -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

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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);
}
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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 <QObject>
#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

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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";
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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 <QObject>
#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

View File

@ -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 \

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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)
{
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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 <QObject>
namespace nymeaserver {
class ModbusRtuManager : public QObject
{
Q_OBJECT
public:
explicit ModbusRtuManager(QObject *parent = nullptr);
signals:
};
}
#endif // MODBUSRTUMANAGER_H

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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)
{
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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 <QObject>
namespace nymeaserver {
class ModbusRtuMaster : public QObject
{
Q_OBJECT
public:
explicit ModbusRtuMaster(QObject *parent = nullptr);
signals:
};
}
#endif // MODBUSRTUMASTER_H

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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)
{
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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 <QObject>
#include "hardwareresource.h"
class ModbusRtuHardwareResource : public HardwareResource
{
Q_OBJECT
public:
explicit ModbusRtuHardwareResource(QObject *parent = nullptr);
virtual ~ModbusRtuHardwareResource() = default;
signals:
};
#endif // MODBUSRTUHARDWARERESOURCE_H

View File

@ -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 \