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