handle hardware a bit better
This commit is contained in:
parent
31b1f9b08e
commit
42d2489334
@ -22,6 +22,11 @@ QUuid DeviceClass::pluginId() const
|
|||||||
return m_pluginId;
|
return m_pluginId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DeviceClass::isValid() const
|
||||||
|
{
|
||||||
|
return !m_id.isNull() && !m_pluginId.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
QString DeviceClass::name() const
|
QString DeviceClass::name() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
|
|||||||
@ -10,11 +10,12 @@
|
|||||||
class DeviceClass
|
class DeviceClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DeviceClass(const QUuid &pluginId, const QUuid &id);
|
DeviceClass(const QUuid &pluginId = QUuid(), const QUuid &id = QUuid());
|
||||||
virtual ~DeviceClass();
|
virtual ~DeviceClass();
|
||||||
|
|
||||||
QUuid id() const;
|
QUuid id() const;
|
||||||
QUuid pluginId() const;
|
QUuid pluginId() const;
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|||||||
@ -28,7 +28,7 @@ DeviceManager::DeviceManager(QObject *parent) :
|
|||||||
|
|
||||||
QList<DeviceClass> DeviceManager::supportedDevices()
|
QList<DeviceClass> DeviceManager::supportedDevices()
|
||||||
{
|
{
|
||||||
return m_supportedDevices;
|
return m_supportedDevices.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const QUuid &deviceClassId, const QVariantMap ¶ms)
|
DeviceManager::DeviceError DeviceManager::addConfiguredDevice(const QUuid &deviceClassId, const QVariantMap ¶ms)
|
||||||
@ -88,11 +88,6 @@ DeviceClass DeviceManager::findDeviceClass(const QUuid &deviceClassId)
|
|||||||
return DeviceClass(QUuid(), QUuid());
|
return DeviceClass(QUuid(), QUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
Radio433 *DeviceManager::radio433() const
|
|
||||||
{
|
|
||||||
return m_radio433;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceManager::DeviceError DeviceManager::executeAction(const Action &action)
|
DeviceManager::DeviceError DeviceManager::executeAction(const Action &action)
|
||||||
{
|
{
|
||||||
foreach (Device *device, m_configuredDevices) {
|
foreach (Device *device, m_configuredDevices) {
|
||||||
@ -113,7 +108,7 @@ void DeviceManager::loadPlugins()
|
|||||||
pluginIface->initPlugin(this);
|
pluginIface->initPlugin(this);
|
||||||
foreach (const DeviceClass &deviceClass, pluginIface->supportedDevices()) {
|
foreach (const DeviceClass &deviceClass, pluginIface->supportedDevices()) {
|
||||||
qDebug() << "* Loaded device class:" << deviceClass.name();
|
qDebug() << "* Loaded device class:" << deviceClass.name();
|
||||||
m_supportedDevices.append(deviceClass);
|
m_supportedDevices.insert(deviceClass.id(), deviceClass);
|
||||||
}
|
}
|
||||||
m_devicePlugins.insert(pluginIface->pluginId(), pluginIface);
|
m_devicePlugins.insert(pluginIface->pluginId(), pluginIface);
|
||||||
connect(pluginIface, &DevicePlugin::emitTrigger, this, &DeviceManager::emitTrigger);
|
connect(pluginIface, &DevicePlugin::emitTrigger, this, &DeviceManager::emitTrigger);
|
||||||
@ -149,3 +144,14 @@ void DeviceManager::storeConfiguredDevices()
|
|||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceManager::radio433SignalReceived(QList<int> rawData)
|
||||||
|
{
|
||||||
|
foreach (Device *device, m_configuredDevices) {
|
||||||
|
DeviceClass deviceClass = m_supportedDevices.value(device->deviceClassId());
|
||||||
|
DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
|
||||||
|
if (plugin->requiredHardware() == HardwareResourceRadio433) {
|
||||||
|
plugin->receiveData(rawData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -15,6 +15,11 @@ class DeviceManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum HardwareResource {
|
||||||
|
HardwareResourceRadio433 = 0x01,
|
||||||
|
HardwareResourceRadio868 = 0x02
|
||||||
|
};
|
||||||
|
|
||||||
enum DeviceError {
|
enum DeviceError {
|
||||||
DeviceErrorNoError,
|
DeviceErrorNoError,
|
||||||
DeviceErrorDeviceNotFound,
|
DeviceErrorDeviceNotFound,
|
||||||
@ -33,8 +38,6 @@ public:
|
|||||||
QList<Device*> findConfiguredDevices(const QUuid &deviceClassId);
|
QList<Device*> findConfiguredDevices(const QUuid &deviceClassId);
|
||||||
DeviceClass findDeviceClass(const QUuid &deviceClassId);
|
DeviceClass findDeviceClass(const QUuid &deviceClassId);
|
||||||
|
|
||||||
Radio433 *radio433() const;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void emitTrigger(const Trigger &trigger);
|
void emitTrigger(const Trigger &trigger);
|
||||||
|
|
||||||
@ -46,13 +49,17 @@ private slots:
|
|||||||
void loadConfiguredDevices();
|
void loadConfiguredDevices();
|
||||||
void storeConfiguredDevices();
|
void storeConfiguredDevices();
|
||||||
|
|
||||||
|
void radio433SignalReceived(QList<int> rawData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<DeviceClass> m_supportedDevices;
|
QHash<QUuid, DeviceClass> m_supportedDevices;
|
||||||
QList<Device*> m_configuredDevices;
|
QList<Device*> m_configuredDevices;
|
||||||
|
|
||||||
QHash<QUuid, DevicePlugin*> m_devicePlugins;
|
QHash<QUuid, DevicePlugin*> m_devicePlugins;
|
||||||
|
|
||||||
Radio433* m_radio433;
|
Radio433* m_radio433;
|
||||||
|
|
||||||
|
friend class DevicePlugin;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEMANAGER_H
|
#endif // DEVICEMANAGER_H
|
||||||
|
|||||||
@ -1,6 +1,14 @@
|
|||||||
#include "deviceplugin.h"
|
#include "deviceplugin.h"
|
||||||
|
|
||||||
#include "devicemanager.h"
|
#include "devicemanager.h"
|
||||||
|
#include "radio433.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DevicePlugin::DevicePlugin()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
DevicePlugin::~DevicePlugin()
|
DevicePlugin::~DevicePlugin()
|
||||||
{
|
{
|
||||||
@ -18,7 +26,17 @@ DeviceManager *DevicePlugin::deviceManager() const
|
|||||||
return m_deviceManager;
|
return m_deviceManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicePlugin::DevicePlugin()
|
void DevicePlugin::transmitData(QList<int> rawData)
|
||||||
{
|
{
|
||||||
|
switch (requiredHardware()) {
|
||||||
|
case DeviceManager::HardwareResourceRadio433:
|
||||||
|
deviceManager()->m_radio433->sendData(rawData);
|
||||||
|
break;
|
||||||
|
case DeviceManager::HardwareResourceRadio868:
|
||||||
|
qDebug() << "Radio868 not connected yet";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
qWarning() << "Unknown harware type. Cannot send.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#ifndef DEVICEPLUGIN_H
|
#ifndef DEVICEPLUGIN_H
|
||||||
#define DEVICEPLUGIN_H
|
#define DEVICEPLUGIN_H
|
||||||
|
|
||||||
|
#include "devicemanager.h"
|
||||||
#include "deviceclass.h"
|
#include "deviceclass.h"
|
||||||
#include "trigger.h"
|
#include "trigger.h"
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
@ -25,6 +26,10 @@ public:
|
|||||||
virtual QUuid pluginId() const = 0;
|
virtual QUuid pluginId() const = 0;
|
||||||
|
|
||||||
virtual QList<DeviceClass> supportedDevices() const = 0;
|
virtual QList<DeviceClass> supportedDevices() const = 0;
|
||||||
|
virtual DeviceManager::HardwareResource requiredHardware() const = 0;
|
||||||
|
|
||||||
|
// Hardware input
|
||||||
|
virtual void receiveData(QList<int> rawData) = 0;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void executeAction(Device *device, const Action &action) = 0;
|
virtual void executeAction(Device *device, const Action &action) = 0;
|
||||||
@ -35,6 +40,8 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
DeviceManager *deviceManager() const;
|
DeviceManager *deviceManager() const;
|
||||||
|
|
||||||
|
void transmitData(QList<int> rawData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceManager *m_deviceManager;
|
DeviceManager *m_deviceManager;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,7 +13,7 @@ SOURCES += device.cpp \
|
|||||||
trigger.cpp \
|
trigger.cpp \
|
||||||
triggertype.cpp \
|
triggertype.cpp \
|
||||||
action.cpp \
|
action.cpp \
|
||||||
actiontype.cpp
|
actiontype.cpp \
|
||||||
|
|
||||||
HEADERS += device.h \
|
HEADERS += device.h \
|
||||||
deviceclass.h \
|
deviceclass.h \
|
||||||
@ -24,5 +24,5 @@ HEADERS += device.h \
|
|||||||
trigger.h \
|
trigger.h \
|
||||||
triggertype.h \
|
triggertype.h \
|
||||||
action.h \
|
action.h \
|
||||||
actiontype.h
|
actiontype.h \
|
||||||
|
|
||||||
|
|||||||
@ -14,11 +14,6 @@ DevicePluginElro::DevicePluginElro()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginElro::init()
|
|
||||||
{
|
|
||||||
connect(deviceManager()->radio433(), &Radio433::dataReceived, this, &DevicePluginElro::dataReceived);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
||||||
{
|
{
|
||||||
// TODO: load list from config with static uuid
|
// TODO: load list from config with static uuid
|
||||||
@ -140,6 +135,11 @@ QList<DeviceClass> DevicePluginElro::supportedDevices() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceManager::HardwareResource DevicePluginElro::requiredHardware() const
|
||||||
|
{
|
||||||
|
return DeviceManager::HardwareResourceRadio433;
|
||||||
|
}
|
||||||
|
|
||||||
QString DevicePluginElro::pluginName() const
|
QString DevicePluginElro::pluginName() const
|
||||||
{
|
{
|
||||||
return QStringLiteral("Elro");
|
return QStringLiteral("Elro");
|
||||||
@ -241,10 +241,10 @@ void DevicePluginElro::executeAction(Device *device, const Action &action)
|
|||||||
// =======================================
|
// =======================================
|
||||||
// send data to driver
|
// send data to driver
|
||||||
qDebug() << "rawData" << rawData;
|
qDebug() << "rawData" << rawData;
|
||||||
deviceManager()->radio433()->sendData(rawData);
|
transmitData(rawData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginElro::dataReceived(QList<int> rawData)
|
void DevicePluginElro::receiveData(QList<int> rawData)
|
||||||
{
|
{
|
||||||
// filter right here a wrong signal length
|
// filter right here a wrong signal length
|
||||||
if(rawData.length() != 49){
|
if(rawData.length() != 49){
|
||||||
|
|||||||
@ -13,17 +13,17 @@ class DevicePluginElro : public DevicePlugin
|
|||||||
public:
|
public:
|
||||||
explicit DevicePluginElro();
|
explicit DevicePluginElro();
|
||||||
|
|
||||||
void init() override;
|
|
||||||
QList<DeviceClass> supportedDevices() const override;
|
QList<DeviceClass> supportedDevices() const override;
|
||||||
|
DeviceManager::HardwareResource requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const;
|
QString pluginName() const;
|
||||||
QUuid pluginId() const;
|
QUuid pluginId() const;
|
||||||
|
|
||||||
|
void receiveData(QList<int> rawData);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void executeAction(Device *device, const Action &action) override;
|
void executeAction(Device *device, const Action &action) override;
|
||||||
|
|
||||||
private slots:
|
|
||||||
void dataReceived(QList<int> rawData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEPLUGINELRO_H
|
#endif // DEVICEPLUGINELRO_H
|
||||||
|
|||||||
@ -14,11 +14,6 @@ DevicePluginIntertechno::DevicePluginIntertechno()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginIntertechno::init()
|
|
||||||
{
|
|
||||||
connect(deviceManager()->radio433(), &Radio433::dataReceived, this, &DevicePluginIntertechno::dataReceived);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
||||||
{
|
{
|
||||||
QList<DeviceClass> ret;
|
QList<DeviceClass> ret;
|
||||||
@ -179,6 +174,11 @@ QList<DeviceClass> DevicePluginIntertechno::supportedDevices() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceManager::HardwareResource DevicePluginIntertechno::requiredHardware() const
|
||||||
|
{
|
||||||
|
return DeviceManager::HardwareResourceRadio433;
|
||||||
|
}
|
||||||
|
|
||||||
QString DevicePluginIntertechno::pluginName() const
|
QString DevicePluginIntertechno::pluginName() const
|
||||||
{
|
{
|
||||||
return "Intertechno";
|
return "Intertechno";
|
||||||
@ -194,7 +194,7 @@ void DevicePluginIntertechno::executeAction(Device *device, const Action &action
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginIntertechno::dataReceived(QList<int> rawData)
|
void DevicePluginIntertechno::receiveData(QList<int> rawData)
|
||||||
{
|
{
|
||||||
// filter right here a wrong signal length
|
// filter right here a wrong signal length
|
||||||
if(rawData.length() != 49){
|
if(rawData.length() != 49){
|
||||||
|
|||||||
@ -13,17 +13,17 @@ class DevicePluginIntertechno : public DevicePlugin
|
|||||||
public:
|
public:
|
||||||
explicit DevicePluginIntertechno();
|
explicit DevicePluginIntertechno();
|
||||||
|
|
||||||
void init() override;
|
|
||||||
QList<DeviceClass> supportedDevices() const override;
|
QList<DeviceClass> supportedDevices() const override;
|
||||||
|
DeviceManager::HardwareResource requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const;
|
QString pluginName() const;
|
||||||
QUuid pluginId() const;
|
QUuid pluginId() const;
|
||||||
|
|
||||||
|
void receiveData(QList<int> rawData);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void executeAction(Device *device, const Action &action) override;
|
void executeAction(Device *device, const Action &action) override;
|
||||||
|
|
||||||
private slots:
|
|
||||||
void dataReceived(QList<int> rawData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEPLUGININTERTECHNO_H
|
#endif // DEVICEPLUGININTERTECHNO_H
|
||||||
|
|||||||
@ -13,11 +13,6 @@ DevicePluginMeisterAnker::DevicePluginMeisterAnker()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginMeisterAnker::init()
|
|
||||||
{
|
|
||||||
connect(deviceManager()->radio433(), &Radio433::dataReceived, this, &DevicePluginMeisterAnker::dataReceived);
|
|
||||||
}
|
|
||||||
|
|
||||||
QList<DeviceClass> DevicePluginMeisterAnker::supportedDevices() const
|
QList<DeviceClass> DevicePluginMeisterAnker::supportedDevices() const
|
||||||
{
|
{
|
||||||
QList<DeviceClass> ret;
|
QList<DeviceClass> ret;
|
||||||
@ -67,6 +62,11 @@ QList<DeviceClass> DevicePluginMeisterAnker::supportedDevices() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeviceManager::HardwareResource DevicePluginMeisterAnker::requiredHardware() const
|
||||||
|
{
|
||||||
|
return DeviceManager::HardwareResourceRadio433;
|
||||||
|
}
|
||||||
|
|
||||||
QString DevicePluginMeisterAnker::pluginName() const
|
QString DevicePluginMeisterAnker::pluginName() const
|
||||||
{
|
{
|
||||||
return "Meister Anker";
|
return "Meister Anker";
|
||||||
@ -82,7 +82,7 @@ void DevicePluginMeisterAnker::executeAction(Device *device, const Action &actio
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginMeisterAnker::dataReceived(QList<int> rawData)
|
void DevicePluginMeisterAnker::receiveData(QList<int> rawData)
|
||||||
{
|
{
|
||||||
// filter right here a wrong signal length
|
// filter right here a wrong signal length
|
||||||
if(rawData.length() != 49){
|
if(rawData.length() != 49){
|
||||||
|
|||||||
@ -14,17 +14,16 @@ class DevicePluginMeisterAnker : public DevicePlugin
|
|||||||
public:
|
public:
|
||||||
explicit DevicePluginMeisterAnker();
|
explicit DevicePluginMeisterAnker();
|
||||||
|
|
||||||
void init() override;
|
|
||||||
QList<DeviceClass> supportedDevices() const override;
|
QList<DeviceClass> supportedDevices() const override;
|
||||||
|
DeviceManager::HardwareResource requiredHardware() const override;
|
||||||
|
|
||||||
QString pluginName() const;
|
QString pluginName() const;
|
||||||
QUuid pluginId() const;
|
QUuid pluginId() const;
|
||||||
|
|
||||||
|
void receiveData(QList<int> rawData);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void executeAction(Device *device, const Action &action) override;
|
void executeAction(Device *device, const Action &action) override;
|
||||||
|
|
||||||
private slots:
|
|
||||||
void dataReceived(QList<int> rawData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICEPLUGINMEISTERANKER_H
|
#endif // DEVICEPLUGINMEISTERANKER_H
|
||||||
|
|||||||
@ -36,15 +36,9 @@ QList<Action> RuleEngine::evaluateTrigger(const Trigger &trigger)
|
|||||||
{
|
{
|
||||||
QList<Action> actions;
|
QList<Action> actions;
|
||||||
for (int i = 0; i < m_rules.count(); ++i) {
|
for (int i = 0; i < m_rules.count(); ++i) {
|
||||||
<<<<<<< HEAD
|
if (m_rules.at(i).triggerTypeId() == trigger.triggerTypeId()) {
|
||||||
// if (m_rules.at(i).triggerTypeId() == trigger.) {
|
|
||||||
// actions << m_rules.at(i).action();
|
|
||||||
// }
|
|
||||||
=======
|
|
||||||
if (m_rules.at(i).triggerTypeId() == trigger.deviceClassId()) {
|
|
||||||
actions << m_rules.at(i).action();
|
actions << m_rules.at(i).action();
|
||||||
}
|
}
|
||||||
>>>>>>> meister anker plugin added
|
|
||||||
}
|
}
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
@ -57,12 +51,7 @@ RuleEngine::RuleError RuleEngine::addRule(const QUuid &triggerTypeId, const Acti
|
|||||||
|
|
||||||
QSettings settings(rulesFileName);
|
QSettings settings(rulesFileName);
|
||||||
settings.beginGroup(rule.id().toString());
|
settings.beginGroup(rule.id().toString());
|
||||||
<<<<<<< HEAD
|
|
||||||
settings.setValue("triggerTypeId", rule.triggerTypeId());
|
settings.setValue("triggerTypeId", rule.triggerTypeId());
|
||||||
=======
|
|
||||||
settings.setValue("triggerId", rule.triggerTypeId());
|
|
||||||
>>>>>>> meister anker plugin added
|
|
||||||
|
|
||||||
settings.beginGroup("action");
|
settings.beginGroup("action");
|
||||||
settings.setValue("id", rule.action().id());
|
settings.setValue("id", rule.action().id());
|
||||||
settings.setValue("deviceId", rule.action().deviceId());
|
settings.setValue("deviceId", rule.action().deviceId());
|
||||||
|
|||||||
Reference in New Issue
Block a user