diff --git a/libhive/devicemanager.cpp b/libhive/devicemanager.cpp index 20d98fb1..73390810 100644 --- a/libhive/devicemanager.cpp +++ b/libhive/devicemanager.cpp @@ -13,6 +13,8 @@ #include Q_IMPORT_PLUGIN(RfRemoteMumbi) +Q_IMPORT_PLUGIN(RfRemoteIntertechno) + DeviceManager::DeviceManager(QObject *parent) : QObject(parent) diff --git a/libhive/radio433.cpp b/libhive/radio433.cpp index 2cf8a62b..a77c8c33 100644 --- a/libhive/radio433.cpp +++ b/libhive/radio433.cpp @@ -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; } diff --git a/plugins/deviceplugins/deviceplugins.pro b/plugins/deviceplugins/deviceplugins.pro index 8f3c7f41..b376bacf 100644 --- a/plugins/deviceplugins/deviceplugins.pro +++ b/plugins/deviceplugins/deviceplugins.pro @@ -1,2 +1,3 @@ TEMPLATE = subdirs -SUBDIRS += rfremotemumbi +SUBDIRS += rfremotemumbi rfremoteintertechno + diff --git a/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.cpp b/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.cpp new file mode 100644 index 00000000..4789cf84 --- /dev/null +++ b/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.cpp @@ -0,0 +1,345 @@ +#include "rfremoteintertechno.h" + +#include "device.h" +#include "devicemanager.h" +#include "radio433.h" + +#include +#include + +QUuid intertechnoRemote = QUuid("ab73ad2f-6594-45a3-9063-8f72d365c5e5"); + +RfRemoteIntertechno::RfRemoteIntertechno() +{ +} + +void RfRemoteIntertechno::init() +{ + connect(deviceManager()->radio433(), &Radio433::dataReceived, this, &RfRemoteIntertechno::dataReceived); +} + +QList RfRemoteIntertechno::supportedDevices() const +{ + QList 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 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 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 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 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; + // } + // } +} diff --git a/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.h b/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.h new file mode 100644 index 00000000..a8e034a0 --- /dev/null +++ b/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.h @@ -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 supportedDevices() const override; + + QString pluginName() const; + +private slots: + void dataReceived(QList rawData); +}; + +#endif // RFREMOTEINTERTECHNO_H diff --git a/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.json b/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.json @@ -0,0 +1 @@ +{} diff --git a/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.pro b/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.pro new file mode 100644 index 00000000..218ed603 --- /dev/null +++ b/plugins/deviceplugins/rfremoteintertechno/rfremoteintertechno.pro @@ -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 + + diff --git a/plugins/deviceplugins/rfremotemumbi/rfremotemumbi.cpp b/plugins/deviceplugins/rfremotemumbi/rfremotemumbi.cpp index e5a9e191..8afdf1e9 100644 --- a/plugins/deviceplugins/rfremotemumbi/rfremotemumbi.cpp +++ b/plugins/deviceplugins/rfremotemumbi/rfremotemumbi.cpp @@ -5,6 +5,7 @@ #include "radio433.h" #include +#include QUuid mumbiRemote = QUuid("d85c1ef4-197c-4053-8e40-707aa671d302"); QUuid mumbiRfRemoteMumbi = QUuid("308ae6e6-38b3-4b3a-a513-3199da2764f8"); @@ -87,7 +88,6 @@ QList 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 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 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 rawData) divNext = 3; } + // _ // if we have | |___ = 0 -> in 4 delays => 1000 // _ @@ -143,8 +144,9 @@ void RfRemoteMumbi::dataReceived(QList rawData) return; } } + }else{ + return; } - //qDebug() << "bincode" << binCode; // get the channel of the remote signal (5 channels, true=1, false=0) QList group; @@ -209,6 +211,7 @@ void RfRemoteMumbi::dataReceived(QList 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; diff --git a/server/hivecore.cpp b/server/hivecore.cpp index 5e852715..51bb620f 100644 --- a/server/hivecore.cpp +++ b/server/hivecore.cpp @@ -36,6 +36,7 @@ HiveCore::HiveCore(QObject *parent) : void HiveCore::gotSignal(const QUuid &triggerId, const QVariantMap ¶ms) { + qDebug() << "##################################################"; qDebug() << "id: " << triggerId; qDebug() << params; diff --git a/server/server.pro b/server/server.pro index 2259e13c..ced8679c 100644 --- a/server/server.pro +++ b/server/server.pro @@ -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 diff --git a/tests/getsupporteddevices.sh b/tests/getsupporteddevices.sh index 4211f95f..7e2d9c34 100755 --- a/tests/getsupporteddevices.sh +++ b/tests/getsupporteddevices.sh @@ -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