added intertechno plugin

pull/1/head
Simon Stürz 2014-01-01 21:22:14 +01:00
parent 8c00fece89
commit 91c8c488b5
11 changed files with 407 additions and 12 deletions

View File

@ -13,6 +13,8 @@
#include <QStringList>
Q_IMPORT_PLUGIN(RfRemoteMumbi)
Q_IMPORT_PLUGIN(RfRemoteIntertechno)
DeviceManager::DeviceManager(QObject *parent) :
QObject(parent)

View File

@ -97,6 +97,7 @@ 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
@ -105,11 +106,11 @@ void Radio433::handleInterrupt()
rawData.append(m_timings[i]);
m_timings[i] = 0;
}
qDebug() << "-----------------------------------------------------------";
qDebug() << "| GENERIC signal |";
qDebug() << "-----------------------------------------------------------";
qDebug() << "delay :" << rawData.first() /31;
qDebug() << rawData;
// qDebug() << "-----------------------------------------------------------";
// qDebug() << "| GENERIC signal |";
// qDebug() << "-----------------------------------------------------------";
// qDebug() << "delay :" << rawData.first() /31;
// qDebug() << rawData;
emit dataReceived(rawData);
}
@ -120,7 +121,7 @@ void Radio433::handleInterrupt()
}else if(m_duration > 5000){
m_changeCount = 0;
}
if (m_changeCount >= RC_MAX_CHANGES+1) {
if (m_changeCount > RC_MAX_CHANGES) {
m_changeCount = 0;
m_repeatCount = 0;
}

View File

@ -1,2 +1,3 @@
TEMPLATE = subdirs
SUBDIRS += rfremotemumbi
SUBDIRS += rfremotemumbi rfremoteintertechno

View File

@ -0,0 +1,345 @@
#include "rfremoteintertechno.h"
#include "device.h"
#include "devicemanager.h"
#include "radio433.h"
#include <QDebug>
#include <QStringList>
QUuid intertechnoRemote = QUuid("ab73ad2f-6594-45a3-9063-8f72d365c5e5");
RfRemoteIntertechno::RfRemoteIntertechno()
{
}
void RfRemoteIntertechno::init()
{
connect(deviceManager()->radio433(), &Radio433::dataReceived, this, &RfRemoteIntertechno::dataReceived);
}
QList<DeviceClass> RfRemoteIntertechno::supportedDevices() const
{
QList<DeviceClass> ret;
DeviceClass deviceClassRfRemote(intertechnoRemote);
deviceClassRfRemote.setName("Intertechno Remote");
QVariantList deviceParams;
QVariantMap channelParam;
// family code = A-P
channelParam.insert("name", "familycode");
channelParam.insert("type", "string");
deviceClassRfRemote.setParams(deviceParams);
QList<TriggerType> buttonTriggers;
QVariantList params;
QVariantMap param;
// on = true
// off = false
param.insert("name", "power");
param.insert("type", "bool");
params.append(param);
/* 1-16
* ________________
* | I | II|III| IV |
* |---|---|---|----|
* 1 | 1 | 5 | 9 | 13 |
* 2 | 2 | 6 | 10| 14 |
* 3 | 3 | 7 | 11| 15 |
* 4 | 4 | 8 | 12| 16 |
* |___|___|___|____|
*/
param.insert("name", "button");
param.insert("type", "int");
params.append(param);
TriggerType button1Trigger("785c1b30-a3f2-4696-af7c-d532acf3d6f7");
button1Trigger.setName("1");
button1Trigger.setParameters(params);
buttonTriggers.append(button1Trigger);
TriggerType button2Trigger("1d42c850-7b43-452f-b205-e1aac14eb3ee");
button2Trigger.setName("2");
button2Trigger.setParameters(params);
buttonTriggers.append(button2Trigger);
deviceClassRfRemote.setTriggers(buttonTriggers);
ret.append(deviceClassRfRemote);
return ret;
}
QString RfRemoteIntertechno::pluginName() const
{
return "RF Remote Intertechno";
}
void RfRemoteIntertechno::dataReceived(QList<int> rawData)
{
// filter right here a wrong signal length
if(rawData.length() != 49){
return;
}
int delay = rawData.first()/31;
QByteArray binCode;
// average 314
if(delay > 300 && delay < 400){
// go trough all 48 timings (without sync signal)
for(int i = 1; i <= 48; i+=2 ){
int div;
int divNext;
// if short
if(rawData.at(i) <= 700){
div = 1;
}else{
div = 3;
}
// if long
if(rawData.at(i+1) < 700){
divNext = 1;
}else{
divNext = 3;
}
// _
// if we have | |___ = 0 -> in 4 delays => 1000
// _
// if we have ___| | = 1 -> in 4 delays => 0001
if(div == 1 && divNext == 3){
binCode.append('0');
}else if(div == 3 && divNext == 1){
binCode.append('1');
}else{
return;
}
}
}else{
return;
}
// Check nibble 16-19, must be 0001
if(binCode.mid(16,4) != "0001"){
return;
}
// Get family code
QString familyCode;
bool ok;
QByteArray familyCodeBin = binCode.left(8);
int famiyCodeInt = familyCodeBin.toInt(&ok,2);
if(!ok){
return;
}
switch (famiyCodeInt) {
case 0b00000000:
familyCode = "A";
break;
case 0b01000000:
familyCode = "B";
break;
case 0b00010000:
familyCode = "C";
break;
case 0b01010000:
familyCode = "D";
break;
case 0b00000100:
familyCode = "E";
break;
case 0b01000100:
familyCode = "F";
break;
case 0b00010100:
familyCode = "G";
break;
case 0b01010100:
familyCode = "H";
break;
case 0b00000001:
familyCode = "I";
break;
case 0b01000001:
familyCode = "J";
break;
case 0b00010001:
familyCode = "K";
break;
case 0b01010001:
familyCode = "L";
break;
case 0b00000101:
familyCode = "M";
break;
case 0b01000101:
familyCode = "N";
break;
case 0b00010101:
familyCode = "O";
break;
case 0b01010101:
familyCode = "P";
break;
default:
return;
}
// Get button code
QString buttonCode;
QByteArray buttonCodeBin = binCode.mid(8,8);
int buttonCodeInt = buttonCodeBin.toInt(&ok,2);
if(!ok){
return;
}
switch (buttonCodeInt) {
case 0b00000000:
buttonCode = "1";
break;
case 0b01000000:
buttonCode = "2";
break;
case 0b00010000:
buttonCode = "3";
break;
case 0b01010000:
buttonCode = "4";
break;
case 0b00000100:
buttonCode = "5";
break;
case 0b01000100:
buttonCode = "6";
break;
case 0b00010100:
buttonCode = "7";
break;
case 0b01010100:
buttonCode = "8";
break;
case 0b00000001:
buttonCode = "9";
break;
case 0b01000001:
buttonCode = "10";
break;
case 0b00010001:
buttonCode = "11";
break;
case 0b01010001:
buttonCode = "12";
break;
case 0b00000101:
buttonCode = "13";
break;
case 0b01000101:
buttonCode = "14";
break;
case 0b00010101:
buttonCode = "15";
break;
case 0b01010101:
buttonCode = "16";
break;
default:
return;
}
// get power status -> On = 0100, Off = 0001
bool power;
if(binCode.right(4).toInt(0,2) == 5){
power = true;
}else if(binCode.right(4).toInt(0,2) == 4){
power = false;
}else{
return;
}
qDebug() << "family code = " << familyCode << "button code =" << buttonCode << power;
return;
// // get the channel of the remote signal (5 channels, true=1, false=0)
// QList<bool> group;
// for(int i = 1; i < 10; i+=2){
// if(binCode.at(i-1) == '0' && binCode.at(i) == '1'){
// group << false;
// }else if(binCode.at(i-1) == '0' && binCode.at(i) == '0'){
// group << true;
// }else {
// return;
// }
// }
// // get the button letter
// QString button;
// QByteArray buttonCode = binCode.mid(10,10);
// if(buttonCode == "0001010101"){
// button = "A";
// }else if(buttonCode == "0100010101"){
// button = "B";
// }else if(buttonCode == "0101000101"){
// button = "C";
// }else if(buttonCode == "0101010001"){
// button = "D";
// }else if(buttonCode == "0101010100"){
// button = "E";
// }else{
// return;
// }
// // get power status -> On = 0100, Off = 0001
// bool power;
// if(binCode.right(4).toInt(0,2) == 1){
// power = true;
// }else if(binCode.right(4).toInt(0,2) == 4){
// power = false;
// }else{
// return;
// }
// Device *device = 0;
// QList<Device*> deviceList = deviceManager()->findConfiguredDevices(intertechnoRemote);
// foreach (Device *dev, deviceList) {
// if (dev->params().contains("channel1") && dev->params().value("channel1").toBool() == group.at(0) &&
// dev->params().contains("channel2") && dev->params().value("channel2").toBool() == group.at(1) &&
// dev->params().contains("channel3") && dev->params().value("channel3").toBool() == group.at(2) &&
// dev->params().contains("channel4") && dev->params().value("channel4").toBool() == group.at(3) &&
// dev->params().contains("channel5") && dev->params().value("channel5").toBool() == group.at(4)
// ) {
// // Yippie! We found the device.
// device = dev;
// break;
// }
// }
// if (!device) {
// qWarning() << "couldn't find any configured device for mumbi:" << binCode.left(10) ;
// return;
// }
// QVariantMap params;
// params.insert("button", button);
// params.insert("power", power);
// foreach (const Trigger &trigger, device->triggers()) {
// //qDebug() << "got trigger" << trigger.name();
// if (trigger.name() == button) {
// emit emitTrigger(trigger.id(), params);
// return;
// }
// }
}

View File

@ -0,0 +1,25 @@
#ifndef RFREMOTEINTERTECHNO_H
#define RFREMOTEINTERTECHNO_H
#include "deviceplugin.h"
class RfRemoteIntertechno : public DevicePlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.hiveyourhome.DevicePlugin" FILE "rfremoteintertechno.json")
Q_INTERFACES(DevicePlugin)
public:
explicit RfRemoteIntertechno();
void init() override;
QList<DeviceClass> supportedDevices() const override;
QString pluginName() const;
private slots:
void dataReceived(QList<int> rawData);
};
#endif // RFREMOTEINTERTECHNO_H

View File

@ -0,0 +1,15 @@
TEMPLATE = lib
CONFIG += plugin static
TARGET = $$qtLibraryTarget(hive_rfremoteintertechno)
INCLUDEPATH += ../../../libhive
LIBS += -L../../../libhive -lhive
SOURCES += \
rfremoteintertechno.cpp
HEADERS += \
rfremoteintertechno.h

View File

@ -5,6 +5,7 @@
#include "radio433.h"
#include <QDebug>
#include <QStringList>
QUuid mumbiRemote = QUuid("d85c1ef4-197c-4053-8e40-707aa671d302");
QUuid mumbiRfRemoteMumbi = QUuid("308ae6e6-38b3-4b3a-a513-3199da2764f8");
@ -87,7 +88,6 @@ QList<DeviceClass> RfRemoteMumbi::supportedDevices() const
ret.append(deviceClassRfRemote);
DeviceClass deviceClassRfRemoteMumbi(mumbiRfRemoteMumbi);
deviceClassRfRemoteMumbi.setName("Mumbi Power Switch");
ret.append(deviceClassRfRemoteMumbi);
@ -110,7 +110,7 @@ void RfRemoteMumbi::dataReceived(QList<int> rawData)
int delay = rawData.first()/31;
QByteArray binCode;
// new Remote -> average 314
// average 314
if(delay > 300 && delay < 400){
// go trough all 48 timings (without sync signal)
for(int i = 1; i <= 48; i+=2 ){
@ -118,7 +118,7 @@ void RfRemoteMumbi::dataReceived(QList<int> rawData)
int divNext;
// if short
if(rawData.at(i) < 700){
if(rawData.at(i) <= 700){
div = 1;
}else{
div = 3;
@ -130,6 +130,7 @@ void RfRemoteMumbi::dataReceived(QList<int> rawData)
divNext = 3;
}
// _
// if we have | |___ = 0 -> in 4 delays => 1000
// _
@ -143,8 +144,9 @@ void RfRemoteMumbi::dataReceived(QList<int> rawData)
return;
}
}
}else{
return;
}
//qDebug() << "bincode" << binCode;
// get the channel of the remote signal (5 channels, true=1, false=0)
QList<bool> group;
@ -209,6 +211,7 @@ void RfRemoteMumbi::dataReceived(QList<int> rawData)
params.insert("button", button);
params.insert("power", power);
foreach (const Trigger &trigger, device->triggers()) {
//qDebug() << "got trigger" << trigger.name();
if (trigger.name() == button) {
emit emitTrigger(trigger.id(), params);
return;

View File

@ -36,6 +36,7 @@ HiveCore::HiveCore(QObject *parent) :
void HiveCore::gotSignal(const QUuid &triggerId, const QVariantMap &params)
{
qDebug() << "##################################################";
qDebug() << "id: " << triggerId;
qDebug() << params;

View File

@ -21,3 +21,4 @@ HEADERS += hivecore.h \
# FIXME: Drop this and link them dynamically
LIBS += -L../plugins/deviceplugins/rfremotemumbi/ -lhive_rfremotemumbi
LIBS += -L../plugins/deviceplugins/rfremoteintertechno/ -lhive_rfremoteintertechno

View File

@ -1,3 +1,3 @@
#!/bin/bash
(echo '{"id":1, "method":"Devices.GetSupportedDevices"}'; sleep 1) | nc localhost 1234
(echo '{"id":1, "method":"Devices.GetSupportedDevices"}'; sleep 1) | nc 10.10.10.114 1234