diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index a4f78c89..d9c90d0a 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -409,9 +409,9 @@ void DeviceManager::loadConfiguredDevices() QList params; foreach (QString paramNameString, settings.childGroups()) { settings.beginGroup(paramNameString); - Param param(paramNameString.remove(QRegExp("^Param-"))); + Param param(paramNameString.remove(QRegExp("Param-"))); param.setValue(settings.value("value")); - param.setOperand((Param::OperandType)settings.value("operand").toInt()); + // param.setOperand((Param::OperandType)settings.value("operand").toInt()); settings.endGroup(); } device->setParams(params); @@ -495,13 +495,20 @@ void DeviceManager::slotDeviceStateValueChanged(const QUuid &stateTypeId, const void DeviceManager::radio433SignalReceived(QList rawData) { - foreach (Device *device, m_configuredDevices) { - DeviceClass deviceClass = m_supportedDevices.value(device->deviceClassId()); - DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId()); + // TODO: this is just temporary for debugging... + foreach (DevicePlugin *plugin, plugins()) { if (plugin->requiredHardware().testFlag(HardwareResourceRadio433)) { plugin->radioData(rawData); } } + + // foreach (Device *device, m_configuredDevices) { + // DeviceClass deviceClass = m_supportedDevices.value(device->deviceClassId()); + // DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId()); + // if (plugin->requiredHardware().testFlag(HardwareResourceRadio433)) { + // plugin->radioData(rawData); + // } + // } } void DeviceManager::timerEvent() diff --git a/libguh/hardware/radio433.cpp b/libguh/hardware/radio433.cpp index f763f64d..c2c36c75 100644 --- a/libguh/hardware/radio433.cpp +++ b/libguh/hardware/radio433.cpp @@ -135,12 +135,12 @@ void Radio433::handleInterrupt() 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; + qDebug() << "-----------------------------------------------------------"; + qDebug() << "| GENERIC signal |"; + qDebug() << "-----------------------------------------------------------"; + qDebug() << "signal length :" << 49; + qDebug() << "delay :" << rawData.first() /31; + qDebug() << rawData; emit dataReceived(rawData); break; diff --git a/plugins/deviceplugins/conrad/devicepluginconrad.cpp b/plugins/deviceplugins/conrad/devicepluginconrad.cpp index da2e3bcb..78d9a5b8 100644 --- a/plugins/deviceplugins/conrad/devicepluginconrad.cpp +++ b/plugins/deviceplugins/conrad/devicepluginconrad.cpp @@ -62,6 +62,7 @@ VendorId conradVendorId = VendorId("986cf06f-3ef1-4271-b2a3-2cc277ebecb6"); DeviceClassId conradRemoteId = DeviceClassId("17cd2492-28ab-4827-ba6e-5ef35be23f1b"); +EventTypeId conradRemoteButtonEventTypeId = EventTypeId("1f4050f5-4c90-4799-8d6d-e4069f3a2519"); DevicePluginConrad::DevicePluginConrad() { @@ -85,25 +86,41 @@ QList DevicePluginConrad::supportedDevices() const DeviceClass deviceClassConradRemote(pluginId(), conradVendorId, 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); + // Params + QList deviceParamsRemote; + + QVariantList deviceParamRemote; + QVariantMap nameParam; + nameParam.insert("name", "name"); + nameParam.insert("type", "string"); + deviceParamRemote.append(nameParam); + + // Events + QList buttonEvents; + + QVariantList paramsRemote; + QVariantMap paramButton; + paramButton.insert("name", "button"); + paramButton.insert("type", "int"); + paramsRemote.append(paramButton); + + QVariantMap paramGroup; + paramGroup.insert("name", "group"); + paramGroup.insert("type", "int"); + paramsRemote.append(paramGroup); + + QVariantMap paramPower; + paramPower.insert("name", "power"); + paramPower.insert("type", "bool"); + paramsRemote.append(paramPower); + + EventType buttonEvent(conradRemoteButtonEventTypeId); + buttonEvent.setName("Button Pressed"); + buttonEvent.setParameters(paramsRemote); + buttonEvents.append(buttonEvent); deviceClassConradRemote.setParams(deviceParamsRemote); + deviceClassConradRemote.setEvents(buttonEvents); ret.append(deviceClassConradRemote); return ret; @@ -135,16 +152,10 @@ DeviceManager::DeviceError DevicePluginConrad::executeAction(Device *device, con 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; @@ -158,13 +169,13 @@ void DevicePluginConrad::radioData(QList rawData) int divNext; // if short - if(rawData.at(i) <= 800){ + if(rawData.at(i) <= 900){ div = 1; }else{ div = 2; } // if long - if(rawData.at(i+1) < 800){ + if(rawData.at(i+1) < 900){ divNext = 1; }else{ divNext = 2; @@ -187,11 +198,11 @@ void DevicePluginConrad::radioData(QList rawData) return; } - // ======================================= + qDebug() << "CONRAD plugin understands this protocol: " << binCode; + + + - qDebug() << "-----------------------------------------------------------"; - qDebug() << "got conrad device..."; - qDebug() << binCode; // // FIXME: find a better way to get to the remote DeviceClass // DeviceClass deviceClass = supportedDevices().first(); diff --git a/plugins/deviceplugins/deviceplugins.pro b/plugins/deviceplugins/deviceplugins.pro index 3fa210b8..fe2650e2 100644 --- a/plugins/deviceplugins/deviceplugins.pro +++ b/plugins/deviceplugins/deviceplugins.pro @@ -3,12 +3,12 @@ SUBDIRS += elro \ intertechno \ # meisteranker \ wifidetector \ -# conrad \ + conrad \ mock \ -# weatherground \ openweathermap \ - lircd \ - googlemail \ + lircd \ + googlemail \ + wakeonlan \ boblight { SUBDIRS += boblight diff --git a/plugins/deviceplugins/elro/devicepluginelro.cpp b/plugins/deviceplugins/elro/devicepluginelro.cpp index bf82c625..8ac80990 100644 --- a/plugins/deviceplugins/elro/devicepluginelro.cpp +++ b/plugins/deviceplugins/elro/devicepluginelro.cpp @@ -64,6 +64,8 @@ VendorId mumbiVendorId = VendorId("5f91c01c-0168-4bdf-a5ed-37cb6971b775"); DeviceClassId elroRemoteId = DeviceClassId("d85c1ef4-197c-4053-8e40-707aa671d302"); DeviceClassId elroSwitchId = DeviceClassId("308ae6e6-38b3-4b3a-a513-3199da2764f8"); +DeviceClassId elroMotionDetectorId = DeviceClassId("4c64aee6-7a4f-41f2-b278-edc55f0da0d3"); + DevicePluginElro::DevicePluginElro() { @@ -141,6 +143,20 @@ QList DevicePluginElro::supportedDevices() const deviceClassElroRemote.setEvents(buttonEvents); ret.append(deviceClassElroRemote); + // ======================================= + // Motion Detector + + DeviceClass deviceClassElroMotionDetector(pluginId(), elroVendorId, elroMotionDetectorId); + deviceClassElroMotionDetector.setName("Elro Motion Detector"); + deviceClassElroMotionDetector.setCreateMethod(DeviceClass::CreateMethodDiscovery); + + QList motionDetectorEvents; + QList deviceParamsMotionDetector; + + + + + // ======================================= // Switch DeviceClass deviceClassElroSwitch(pluginId(), elroVendorId, elroSwitchId); @@ -311,7 +327,7 @@ void DevicePluginElro::radioData(QList rawData) QByteArray binCode; // average 314 - if(delay > 300 && delay < 400){ + if(delay > 290 && delay < 400){ // go trough all 48 timings (without sync signal) for(int i = 1; i <= 48; i+=2 ){ int div; @@ -348,6 +364,15 @@ void DevicePluginElro::radioData(QList rawData) }else{ return; } + qDebug() << "ELRO understands this protocol: " << binCode; + + if(binCode.left(20) == "00000100000000000001"){ + if(binCode.right(4) == "0100"){ + qDebug() << "Motion Detector OFF"; + }else{ + qDebug() << "Motion Detector ON"; + } + } // get the channel of the remote signal (5 channels, true=1, false=0) QList group; @@ -404,7 +429,6 @@ void DevicePluginElro::radioData(QList rawData) } } if (!device) { - qWarning() << "couldn't find any configured device for elro:" << binCode.left(10) ; return; } @@ -416,7 +440,7 @@ void DevicePluginElro::radioData(QList rawData) DeviceClass deviceClass = supportedDevices().first(); foreach (const EventType &eventType, deviceClass.events()) { if (eventType.name() == button) { - qDebug() << "emit event " << pluginName() << group << eventType.name() << power; + //qDebug() << "emit event " << pluginName() << group << eventType.name() << power; Event event = Event(eventType.id(), device->id(), params); emit emitEvent(event); return; diff --git a/plugins/deviceplugins/googlemail/deviceplugingooglemail.cpp b/plugins/deviceplugins/googlemail/deviceplugingooglemail.cpp index c75e3720..b27fc22c 100644 --- a/plugins/deviceplugins/googlemail/deviceplugingooglemail.cpp +++ b/plugins/deviceplugins/googlemail/deviceplugingooglemail.cpp @@ -115,7 +115,6 @@ DeviceManager::DeviceError DevicePluginGoogleMail::executeAction(Device *device, if(!m_smtpClient->login(device->paramValue("user").toString(), device->paramValue("password").toString())){ return DeviceManager::DeviceErrorDeviceParameterError; } - m_smtpClient->sendMail(device->paramValue("user").toString(), device->paramValue("sendTo").toString(), action.param("subject").value().toString(), action.param("body").value().toString()); m_smtpClient->logout(); } diff --git a/plugins/deviceplugins/googlemail/smtpclient.cpp b/plugins/deviceplugins/googlemail/smtpclient.cpp index 58689042..45b0cf1e 100644 --- a/plugins/deviceplugins/googlemail/smtpclient.cpp +++ b/plugins/deviceplugins/googlemail/smtpclient.cpp @@ -29,7 +29,6 @@ SmtpClient::SmtpClient(const QString &host, int port, SmtpClient::ConnectionType m_sendMessageTimeout = 60000; connect(m_socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(socketError(QAbstractSocket::SocketError))); - connect(m_socket,SIGNAL(readyRead()),this,SLOT(readyRead())); connect(m_socket,SIGNAL(connected()),this,SLOT(connected())); connect(m_socket,SIGNAL(disconnected()),this,SLOT(disconnected())); diff --git a/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.cpp b/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.cpp new file mode 100644 index 00000000..4358388b --- /dev/null +++ b/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.cpp @@ -0,0 +1,104 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "devicepluginwakeonlan.h" + +#include "plugin/device.h" +#include "devicemanager.h" + +#include +#include +#include + +extern VendorId guhVendorId; +DeviceClassId wolDeviceClassId = DeviceClassId("3c8f2447-dcd0-4882-8c09-99e579e4d24c"); +ActionTypeId wolActionTypeId = ActionTypeId("fb9b9d87-218f-4f0d-9e16-39f8a105029a"); + +DevicePluginWakeOnLan::DevicePluginWakeOnLan() +{ +} + +QList DevicePluginWakeOnLan::supportedVendors() const +{ + QList ret; + Vendor guh(guhVendorId, "guh"); + ret.append(guh); + return ret; +} + +QList DevicePluginWakeOnLan::supportedDevices() const +{ + QList ret; + + DeviceClass deviceClassWakeOnLan(pluginId(), guhVendorId, wolDeviceClassId); + deviceClassWakeOnLan.setName("Wake On Lan"); + + QList wolParams; + ParamType wolParam("mac", QVariant::String); + wolParams.append(wolParam); + + + QList wolActions; + ActionType wolAction(wolActionTypeId); + wolAction.setName("wakeup"); + wolActions.append(wolAction); + + deviceClassWakeOnLan.setParams(wolParams); + deviceClassWakeOnLan.setActions(wolActions); + + ret.append(deviceClassWakeOnLan); + return ret; +} + +DeviceManager::HardwareResources DevicePluginWakeOnLan::requiredHardware() const +{ + return DeviceManager::HardwareResourceNone; +} + +QString DevicePluginWakeOnLan::pluginName() const +{ + return "Wake On Lan"; +} + +PluginId DevicePluginWakeOnLan::pluginId() const +{ + return PluginId("b5a87848-de56-451e-84a6-edd26ad4958f"); +} + +DeviceManager::DeviceError DevicePluginWakeOnLan::executeAction(Device *device, const Action &action) +{ + qDebug() << "execute action " << action.actionTypeId().toString(); + if(action.actionTypeId() == wolActionTypeId){ + wakeup(device->paramValue("mac").toString()); + } + return DeviceManager::DeviceErrorNoError; +} + +void DevicePluginWakeOnLan::wakeup(QString mac) +{ + const char header[] = {char(0xff), char(0xff), char(0xff), char(0xff), char(0xff), char(0xff)}; + QByteArray packet = QByteArray::fromRawData(header, sizeof(header)); + for(int i = 0; i < 16; ++i) { + packet.append(QByteArray::fromHex(mac.remove(':').toLocal8Bit())); + } + qDebug() << "created magic packet:" << packet.toHex(); + QUdpSocket udpSocket; + udpSocket.writeDatagram(packet.data(), packet.size(), QHostAddress::Broadcast, 9); + +} + diff --git a/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.h b/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.h new file mode 100644 index 00000000..d74c3142 --- /dev/null +++ b/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.h @@ -0,0 +1,50 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef DEVICEPLUGINWAKEONLAN_H +#define DEVICEPLUGINWAKEONLAN_H + +#include "plugin/deviceplugin.h" + +#include + +class DevicePluginWakeOnLan : public DevicePlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID "guru.guh.DevicePlugin" FILE "devicepluginwakeonlan.json") + Q_INTERFACES(DevicePlugin) + +public: + explicit DevicePluginWakeOnLan(); + + QList supportedVendors() const override; + QList supportedDevices() const override; + DeviceManager::HardwareResources requiredHardware() const override; + + QString pluginName() const override; + PluginId pluginId() const override; + DeviceManager::DeviceError executeAction(Device *device, const Action &action) override; + + +private slots: + void wakeup(QString mac); + +}; + +#endif // DEVICEPLUGINWAKEONLAN_H diff --git a/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.json b/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/plugins/deviceplugins/wakeonlan/devicepluginwakeonlan.json @@ -0,0 +1 @@ +{} diff --git a/plugins/deviceplugins/wakeonlan/wakeonlan.pro b/plugins/deviceplugins/wakeonlan/wakeonlan.pro new file mode 100644 index 00000000..519d6e0f --- /dev/null +++ b/plugins/deviceplugins/wakeonlan/wakeonlan.pro @@ -0,0 +1,13 @@ +include(../../plugins.pri) + +TARGET = $$qtLibraryTarget(guh_devicepluginwakeonlan) + +QT += network + +SOURCES += \ + devicepluginwakeonlan.cpp + +HEADERS += \ + devicepluginwakeonlan.h + + diff --git a/server/main.cpp b/server/main.cpp index 2efe21e8..81df9a25 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -25,12 +25,12 @@ Q_IMPORT_PLUGIN(DevicePluginElro) Q_IMPORT_PLUGIN(DevicePluginIntertechno) //Q_IMPORT_PLUGIN(DevicePluginMeisterAnker) Q_IMPORT_PLUGIN(DevicePluginWifiDetector) -//Q_IMPORT_PLUGIN(DevicePluginConrad) +Q_IMPORT_PLUGIN(DevicePluginConrad) Q_IMPORT_PLUGIN(DevicePluginMock) -//Q_IMPORT_PLUGIN(DevicePluginWeatherground) Q_IMPORT_PLUGIN(DevicePluginOpenweathermap) Q_IMPORT_PLUGIN(DevicePluginLircd) Q_IMPORT_PLUGIN(DevicePluginGoogleMail) +Q_IMPORT_PLUGIN(DevicePluginWakeOnLan) #if USE_BOBLIGHT Q_IMPORT_PLUGIN(DevicePluginBoblight) diff --git a/server/server.pro b/server/server.pro index dff563af..bcdf0e7b 100644 --- a/server/server.pro +++ b/server/server.pro @@ -19,12 +19,12 @@ LIBS += -L../plugins/deviceplugins/elro/ -lguh_devicepluginelro LIBS += -L../plugins/deviceplugins/intertechno/ -lguh_devicepluginintertechno #LIBS += -L../plugins/deviceplugins/meisteranker/ -lguh_devicepluginmeisteranker LIBS += -L../plugins/deviceplugins/wifidetector/ -lguh_devicepluginwifidetector -#LIBS += -L../plugins/deviceplugins/conrad -lguh_devicepluginconrad +LIBS += -L../plugins/deviceplugins/conrad -lguh_devicepluginconrad LIBS += -L../plugins/deviceplugins/mock -lguh_devicepluginmock -#LIBS += -L../plugins/deviceplugins/weatherground -lguh_devicepluginweatherground LIBS += -L../plugins/deviceplugins/openweathermap -lguh_devicepluginopenweathermap LIBS += -L../plugins/deviceplugins/lircd -lguh_devicepluginlircd LIBS += -L../plugins/deviceplugins/googlemail -lguh_deviceplugingooglemail +LIBS += -L../plugins/deviceplugins/wakeonlan -lguh_devicepluginwakeonlan boblight { xcompile { diff --git a/tests/scripts/addconfigureddevice.sh b/tests/scripts/addconfigureddevice.sh index dde5c6b2..57efd1dd 100755 --- a/tests/scripts/addconfigureddevice.sh +++ b/tests/scripts/addconfigureddevice.sh @@ -10,7 +10,7 @@ elif [ -z $2 ]; then else if [ $2 == "elroremote" ]; then # Adds an ELRO remote control on channel 00000 - (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClassId": "{d85c1ef4-197c-4053-8e40-707aa671d302}","deviceParams":{"channel1":"true", "channel2":"false", "channel3":"false", "channel4": "false", "channel5":"false" }}}'; sleep 1) | nc $1 1234 + (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClassId": "{d85c1ef4-197c-4053-8e40-707aa671d302}","deviceParams":{"channel1":"false", "channel2":"false", "channel3":"false", "channel4": "false", "channel5":"false" }}}'; sleep 1) | nc $1 1234 elif [ $2 == "elroswitch" ]; then # Adds a ELRO power switch on channel 00000 and group E (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClassId": "{308ae6e6-38b3-4b3a-a513-3199da2764f8}","deviceParams":{"channel1":"false","channel2":"false", "channel3":"false", "channel4": "false","channel5":"false","A":"false","B":"true","C":"false","D":"false","E":"false" }}}'; sleep 1) | nc $1 1234 @@ -30,8 +30,9 @@ else # Adds a Mock device (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClassId": "{753f0d32-0468-4d08-82ed-1964aab03298}","deviceParams":{"httpport":"8082"}}}'; sleep 1) | nc $1 1234 elif [ $2 == "openweathermap" ]; then - # Adds a openweathermap device (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClassId": "{985195aa-17ad-4530-88a4-cdd753d747d7}","deviceDescriptorId":"'$4'"}}'; sleep 1) | nc $1 1234 + elif [ $2 == "wol" ]; then + (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClassId": "{3c8f2447-dcd0-4882-8c09-99e579e4d24c}","deviceParams":{"mac":"'$3'"}}}'; sleep 1) | nc $1 1234 elif [ $2 == "lirc" ]; then (echo '{"id":1, "method":"Devices.AddConfiguredDevice", "params":{"deviceClassId": "{5c2bc4cd-ba6c-4052-b6cd-1db83323ea22}","deviceParams":{"remoteName":"'$3'"}}}'; sleep 1) | nc $1 1234 elif [ $2 == "discovered" ]; then