diff --git a/libhive/libhive.pro b/libhive/libhive.pro index d91b8d2f..d54a750d 100644 --- a/libhive/libhive.pro +++ b/libhive/libhive.pro @@ -14,10 +14,10 @@ SOURCES += device.cpp \ gpio.cpp \ action.cpp \ actiontype.cpp \ - state.cpp \ - statetype.cpp \ - eventtype.cpp \ - event.cpp + state.cpp \ + statetype.cpp \ + eventtype.cpp \ + event.cpp HEADERS += device.h \ deviceclass.h \ @@ -27,8 +27,8 @@ HEADERS += device.h \ gpio.h \ action.h \ actiontype.h \ - state.h \ - statetype.h \ - eventtype.h \ - event.h + state.h \ + statetype.h \ + eventtype.h \ + event.h diff --git a/libhive/radio433.cpp b/libhive/radio433.cpp index d78f6f31..b7c9700e 100644 --- a/libhive/radio433.cpp +++ b/libhive/radio433.cpp @@ -2,6 +2,8 @@ \class Radio433 \brief The Radio433 class helps to interact with the 433 MHz Receiver and Transmitter. + \l{http://tech.jolowe.se/home-automation-rf-protocols/} + \inmodule libhive */ @@ -90,7 +92,7 @@ void Radio433::delayMicros(int microSeconds) } /*! This method handels an interrupt on the receiver pin and recognizes, if a valid message of - * 48 bit was received. + * 48 bit or 64 bit was received. */ void Radio433::handleInterrupt() { @@ -104,22 +106,44 @@ void Radio433::handleInterrupt() m_changeCount--; if(m_repeatCount == 2) { - - // if we have a regular signal (1 bit sync + 48 bit data) - if(m_changeCount == RC_MAX_CHANGES){ - // write rawdata to a List and reset values to 0 + // if we have a regular signal (1 bit sync + 48 bit data or 1bit sync + 64 bit data) + if(m_changeCount == 49 || m_changeCount == 65){ QList rawData; - for(int i = 0; i < RC_MAX_CHANGES; i++ ){ - rawData.append(m_timings[i]); - m_timings[i] = 0; - } - // qDebug() << "-----------------------------------------------------------"; - // qDebug() << "| GENERIC signal |"; - // qDebug() << "-----------------------------------------------------------"; - // qDebug() << "delay :" << rawData.first() /31; - // qDebug() << rawData; - emit dataReceived(rawData); + switch (m_changeCount) { + case 49: + // write rawdata to a List and reset values to 0 + for(int i = 0; i < 49; i++ ){ + rawData.append(m_timings[i]); + m_timings[i] = 0; + } +// qDebug() << "-----------------------------------------------------------"; +// qDebug() << "| GENERIC signal |"; +// qDebug() << "-----------------------------------------------------------"; +// qDebug() << "signal length :" << 49; +// qDebug() << "delay :" << rawData.first() /31; +// qDebug() << rawData; + + emit dataReceived(rawData); + break; + + case 65: + // write rawdata to a List and reset values to 0 + for(int i = 0; i < 65; i++ ){ + rawData.append(m_timings[i]); + m_timings[i] = 0; + } + qDebug() << "-----------------------------------------------------------"; + qDebug() << "| GENERIC signal |"; + qDebug() << "-----------------------------------------------------------"; + qDebug() << "signal length :" << 65; + qDebug() << "delay :" << rawData.first() /10; + qDebug() << rawData; + + emit dataReceived(rawData); + default: + break; + } } m_repeatCount = 0; } @@ -128,7 +152,7 @@ void Radio433::handleInterrupt() }else if(m_duration > 5000){ m_changeCount = 0; } - if (m_changeCount > RC_MAX_CHANGES) { + if (m_changeCount >= RC_MAX_CHANGES) { m_changeCount = 0; m_repeatCount = 0; } diff --git a/libhive/radio433.h b/libhive/radio433.h index 1ab85edf..ca22a3ab 100644 --- a/libhive/radio433.h +++ b/libhive/radio433.h @@ -5,7 +5,7 @@ #include #include -#define RC_MAX_CHANGES 49 +#define RC_MAX_CHANGES 67 class Radio433: public QObject { @@ -38,7 +38,7 @@ private slots: signals: /*! This signal is emitted whenever a valid signal of 48 bits was recognized over the - * 433 MHz receiver + * 433 MHz receiver. The sync signal and the message are in the integer list \a rawData. */ void dataReceived(QList rawData); }; diff --git a/plugins/deviceplugins/conrad/conrad.pro b/plugins/deviceplugins/conrad/conrad.pro new file mode 100644 index 00000000..7e2fd045 --- /dev/null +++ b/plugins/deviceplugins/conrad/conrad.pro @@ -0,0 +1,11 @@ +include (../../plugins.pri) + +TARGET = $$qtLibraryTarget(hive_devicepluginconrad) + +SOURCES += \ + devicepluginconrad.cpp + +HEADERS += \ + devicepluginconrad.h + + diff --git a/plugins/deviceplugins/conrad/devicepluginconrad.cpp b/plugins/deviceplugins/conrad/devicepluginconrad.cpp new file mode 100644 index 00000000..83863720 --- /dev/null +++ b/plugins/deviceplugins/conrad/devicepluginconrad.cpp @@ -0,0 +1,180 @@ +/*! + \page conrad.html + \title Conrad + + \ingroup plugins + \ingroup rf433 + + This plugin allows to controll RF 433 MHz actors an receive remote signals from Conrad + devices (\l{http://www.conrad.at}). + + Following devices are supported: + + \chapter Supported devices + \section1 Actors + \table + \header + \li Model + \li Device Type + \row + \li + \li + \endtable + + \section1 Remotes + \table + \header + \li Model + \li Device Type + \row + \li + \li + \endtable + */ + +#include "devicepluginconrad.h" + +#include "device.h" +#include "devicemanager.h" +#include "radio433.h" + +#include +#include + + +QUuid conradRemoteId = QUuid("17cd2492-28ab-4827-ba6e-5ef35be23f1b"); + + +DevicePluginConrad::DevicePluginConrad() +{ +} + +QList DevicePluginConrad::supportedDevices() const +{ + // TODO: load list from config with static uuid + QList ret; + + // ======================================= + // Remote + DeviceClass deviceClassConradRemote(pluginId(), conradRemoteId); + deviceClassConradRemote.setName("Conrad Remote"); + + QVariantList deviceParamsRemote; + QVariantMap channelParam; +// channelParam.insert("name", "channel1"); +// channelParam.insert("type", "bool"); +// deviceParamsRemote.append(channelParam); +// channelParam.insert("name", "channel2"); +// channelParam.insert("type", "bool"); +// deviceParamsRemote.append(channelParam); +// channelParam.insert("name", "channel3"); +// channelParam.insert("type", "bool"); +// deviceParamsRemote.append(channelParam); +// channelParam.insert("name", "channel4"); +// channelParam.insert("type", "bool"); +// deviceParamsRemote.append(channelParam); +// channelParam.insert("name", "channel5"); +// channelParam.insert("type", "bool"); +// deviceParamsRemote.append(channelParam); + + deviceClassConradRemote.setParams(deviceParamsRemote); + ret.append(deviceClassConradRemote); + + return ret; +} + +DeviceManager::HardwareResources DevicePluginConrad::requiredHardware() const +{ + return DeviceManager::HardwareResourceRadio433; +} + +QString DevicePluginConrad::pluginName() const +{ + return "Conrad"; +} + +QUuid DevicePluginConrad::pluginId() const +{ + return QUuid("1fd1a076-f229-4ec6-b501-48ddd15935e4"); +} + +void DevicePluginConrad::executeAction(Device *device, const Action &action) +{ + + QList rawData; + QByteArray binCode; + + +} + +void DevicePluginConrad::radioData(QList rawData) +{ + qDebug() << "!!!!!!!!!!!! called conrad radioData"; + // filter right here a wrong signal length + if(rawData.length() != 65){ + return; + } + +// QList deviceList = deviceManager()->findConfiguredDevices(intertechnoRemote); +// if(deviceList.isEmpty()){ +// return; +// } + + int delay = rawData.first()/10; + QByteArray binCode; + + // ======================================= + // average 314 + if(delay > 690 && delay < 750){ + // go trough all 64 timings (without sync signal) + for(int i = 1; i <= 64; i+=2 ){ + int div; + int divNext; + + // if short + if(rawData.at(i) <= 800){ + div = 1; + }else{ + div = 2; + } + // if long + if(rawData.at(i+1) < 800){ + divNext = 1; + }else{ + divNext = 2; + } + + // _ + // if we have | |__ = 0 -> in 4 delays => 100 + // __ + // if we have | |_ = 1 -> in 4 delays => 110 + + if(div == 1 && divNext == 2){ + binCode.append('0'); + }else if(div == 2 && divNext == 1){ + binCode.append('1'); + }else{ + return; + } + } + }else{ + return; + } + + // ======================================= + + qDebug() << "-----------------------------------------------------------"; + qDebug() << "got conrad device..."; + qDebug() << binCode; + +// // FIXME: find a better way to get to the remote DeviceClass +// DeviceClass deviceClass = supportedDevices().first(); +// foreach (const EventType &eventType, deviceClass.events()) { +// if (eventType.name() == buttonCode) { +// qDebug() << "emit event " << pluginName() << familyCode << eventType.name() << power; +// Event event = Event(eventType.id(), device->id(), params); +// emit emitEvent(event); +// return; +// } +// } +} diff --git a/plugins/deviceplugins/conrad/devicepluginconrad.h b/plugins/deviceplugins/conrad/devicepluginconrad.h new file mode 100644 index 00000000..d91e59eb --- /dev/null +++ b/plugins/deviceplugins/conrad/devicepluginconrad.h @@ -0,0 +1,29 @@ +#ifndef DEVICEPLUGINCONRAD_H +#define DEVICEPLUGINCONRAD_H + +#include "deviceplugin.h" + +class DevicePluginConrad : public DevicePlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "org.hiveyourhome.DevicePlugin" FILE "devicepluginconrad.json") + Q_INTERFACES(DevicePlugin) + +public: + explicit DevicePluginConrad(); + + QList supportedDevices() const override; + DeviceManager::HardwareResources requiredHardware() const override; + + QString pluginName() const override; + QUuid pluginId() const override; + + void radioData(QList rawData) override; + +public slots: + void executeAction(Device *device, const Action &action) override; + +}; + +#endif // DEVICEPLUGINCONRAD_H diff --git a/plugins/deviceplugins/conrad/devicepluginconrad.json b/plugins/deviceplugins/conrad/devicepluginconrad.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/plugins/deviceplugins/conrad/devicepluginconrad.json @@ -0,0 +1 @@ +{} diff --git a/plugins/deviceplugins/deviceplugins.pro b/plugins/deviceplugins/deviceplugins.pro index 3eae814f..d97493fe 100644 --- a/plugins/deviceplugins/deviceplugins.pro +++ b/plugins/deviceplugins/deviceplugins.pro @@ -1,6 +1,8 @@ TEMPLATE = subdirs -SUBDIRS += elro \ - intertechno \ - meisteranker \ - wifidetector \ -# boblight \ +SUBDIRS += elro \ + intertechno \ + meisteranker \ + wifidetector \ + conrad \ + +# boblight \ diff --git a/server/main.cpp b/server/main.cpp index e30f3aae..d8198f9f 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -7,6 +7,7 @@ Q_IMPORT_PLUGIN(DevicePluginElro) Q_IMPORT_PLUGIN(DevicePluginIntertechno) Q_IMPORT_PLUGIN(DevicePluginMeisterAnker) Q_IMPORT_PLUGIN(DevicePluginWifiDetector) +Q_IMPORT_PLUGIN(DevicePluginConrad) int main(int argc, char *argv[]) { diff --git a/server/server.pro b/server/server.pro index 833d8eec..b35ab1cf 100644 --- a/server/server.pro +++ b/server/server.pro @@ -19,3 +19,4 @@ LIBS += -L../plugins/deviceplugins/elro/ -lhive_devicepluginelro LIBS += -L../plugins/deviceplugins/intertechno/ -lhive_devicepluginintertechno LIBS += -L../plugins/deviceplugins/meisteranker/ -lhive_devicepluginmeisteranker LIBS += -L../plugins/deviceplugins/wifidetector/ -lhive_devicepluginwifidetector +LIBS += -L../plugins/deviceplugins/conrad -lhive_devicepluginconrad