added conrad plugin and support for radio433 devices with 64 bit length

pull/1/head
Simon Stürz 2014-02-12 23:33:49 +01:00
parent 76d3ca424d
commit 90f69c10fc
10 changed files with 280 additions and 31 deletions

View File

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

View File

@ -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<int> 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;
}

View File

@ -5,7 +5,7 @@
#include <QThread>
#include <gpio.h>
#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<int> rawData);
};

View File

@ -0,0 +1,11 @@
include (../../plugins.pri)
TARGET = $$qtLibraryTarget(hive_devicepluginconrad)
SOURCES += \
devicepluginconrad.cpp
HEADERS += \
devicepluginconrad.h

View File

@ -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 <QDebug>
#include <QStringList>
QUuid conradRemoteId = QUuid("17cd2492-28ab-4827-ba6e-5ef35be23f1b");
DevicePluginConrad::DevicePluginConrad()
{
}
QList<DeviceClass> DevicePluginConrad::supportedDevices() const
{
// TODO: load list from config with static uuid
QList<DeviceClass> 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<int> rawData;
QByteArray binCode;
}
void DevicePluginConrad::radioData(QList<int> rawData)
{
qDebug() << "!!!!!!!!!!!! called conrad radioData";
// filter right here a wrong signal length
if(rawData.length() != 65){
return;
}
// QList<Device*> 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;
// }
// }
}

View File

@ -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<DeviceClass> supportedDevices() const override;
DeviceManager::HardwareResources requiredHardware() const override;
QString pluginName() const override;
QUuid pluginId() const override;
void radioData(QList<int> rawData) override;
public slots:
void executeAction(Device *device, const Action &action) override;
};
#endif // DEVICEPLUGINCONRAD_H

View File

@ -0,0 +1 @@
{}

View File

@ -1,6 +1,8 @@
TEMPLATE = subdirs
SUBDIRS += elro \
intertechno \
meisteranker \
wifidetector \
# boblight \
SUBDIRS += elro \
intertechno \
meisteranker \
wifidetector \
conrad \
# boblight \

View File

@ -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[])
{

View File

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