diff --git a/hive/libhive/client.cpp b/hive/libhive/client.cpp index 675b61f4..a4b35f60 100644 --- a/hive/libhive/client.cpp +++ b/hive/libhive/client.cpp @@ -93,9 +93,6 @@ void Client::handleResponse(const QVariantMap &rsp) m_requestMap.remove(id); } - - - } void Client::handleSignal(const QVariantMap &signal) diff --git a/hive/libhive/devicemanager.cpp b/hive/libhive/devicemanager.cpp index d4bb8a24..07dbec85 100644 --- a/hive/libhive/devicemanager.cpp +++ b/hive/libhive/devicemanager.cpp @@ -38,50 +38,3 @@ bool DeviceManager::deleteDevice(QString deviceType, QUuid uuid) - - -//void DeviceManager::saveDeviceValue(QString deviceType, QString deviceName, QString key, QVariant value) -//{ -// QSettings settings("hive"); -// settings.beginGroup(deviceType); -// settings.beginGroup(deviceName); -// settings.setValue(key,value); -// qDebug() << "safed device value:" << deviceType << "->" << deviceName << "->" << key << ":" << value << "."; -//} - -//void DeviceManager::deleteDeviceValue(QString deviceType, QString deviceName, QString key) -//{ -// QSettings settings("hive"); -// settings.beginGroup(deviceType); -// settings.beginGroup(deviceName); -// settings.remove(key); -// qDebug() << "delete key of" << deviceName << key; - - -//} - -//void DeviceManager::deleteDevice(QString deviceType, QString deviceName) -//{ -// QSettings settings("hive"); -// settings.beginGroup(deviceType); -// settings.remove(deviceName); -// qDebug() << "delete device" << deviceName; -//} - -//QStringList DeviceManager::getDevices(QString deviceType) -//{ -// QSettings settings("hive"); -// settings.beginGroup(deviceType); -// QStringList devices = settings.childGroups(); -// return devices; - -//} - -//QStringList DeviceManager::getDeviceKeys(QString deviceType, QString deviceName) -//{ -// QSettings settings("hive"); -// settings.beginGroup(deviceType); -// settings.beginGroup(deviceName); -// QStringList keys = settings.childKeys(); -// return keys; -//} diff --git a/hive/libhive/jsonhandler.cpp b/hive/libhive/jsonhandler.cpp index 2b31b17b..22e1b37d 100644 --- a/hive/libhive/jsonhandler.cpp +++ b/hive/libhive/jsonhandler.cpp @@ -8,6 +8,7 @@ JsonHandler::JsonHandler(QObject *parent) : QObject(parent) { m_device = new DeviceJsonPlugin(this); + m_radio = new RadioJsonPlugin(this); } @@ -30,6 +31,9 @@ QByteArray JsonHandler::process(const QByteArray &data) if(command.value("device").toString() == m_device->deviceName()){ return m_device->process(command,params); + } + if(command.value("device").toString() == m_radio->deviceName()){ + return m_radio->process(command,params); }else{ return NULL; } diff --git a/hive/libhive/jsonhandler.h b/hive/libhive/jsonhandler.h index 049cb943..2a5c18d8 100644 --- a/hive/libhive/jsonhandler.h +++ b/hive/libhive/jsonhandler.h @@ -5,6 +5,7 @@ #include #include #include +#include class JsonHandler : public QObject @@ -24,6 +25,7 @@ public slots: private: DeviceJsonPlugin *m_device; + RadioJsonPlugin *m_radio; QByteArray formatResponse(const QVariantMap &command, const QVariantMap &responseParams); QByteArray formatErrorResponse(const QVariantMap &command, const QString &error); diff --git a/hive/libhive/jsonplugin/radiojsonplugin.cpp b/hive/libhive/jsonplugin/radiojsonplugin.cpp index 5f7b6fc8..c119edc2 100644 --- a/hive/libhive/jsonplugin/radiojsonplugin.cpp +++ b/hive/libhive/jsonplugin/radiojsonplugin.cpp @@ -107,3 +107,13 @@ bool RadioJsonPlugin::execute() return false; } } + +QByteArray RadioJsonPlugin::formatResponse() +{ + +} + +QByteArray RadioJsonPlugin::formatErrorResponse() +{ + +} diff --git a/hive/libhive/jsonplugin/radiojsonplugin.h b/hive/libhive/jsonplugin/radiojsonplugin.h index 6225a72a..ec75b0dc 100644 --- a/hive/libhive/jsonplugin/radiojsonplugin.h +++ b/hive/libhive/jsonplugin/radiojsonplugin.h @@ -15,6 +15,8 @@ public: QString deviceName(); QStringList devicePropertys(); + QStringList deviceMethods(); + QByteArray process(const QVariantMap & command, const QVariantMap & parameters); private: @@ -26,9 +28,11 @@ private: QVariantMap m_command; QVariantMap m_parameters; - DeviceManager *m_deviceManager; + QByteArray formatResponse(); + QByteArray formatErrorResponse(); + signals: public slots: diff --git a/hive/libhive/logwriter.cpp b/hive/libhive/logwriter.cpp index c71c1e5f..fa105f55 100644 --- a/hive/libhive/logwriter.cpp +++ b/hive/libhive/logwriter.cpp @@ -12,5 +12,4 @@ void LogWriter::write(LogWriter::MessageType messageType, QString logMessage) QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm");; qDebug() << timeStamp; - } diff --git a/hive/libhive/radioplugin/radioswitch.cpp b/hive/libhive/radioplugin/radioswitch.cpp index 6c2e87cc..1d0f7631 100644 --- a/hive/libhive/radioplugin/radioswitch.cpp +++ b/hive/libhive/radioplugin/radioswitch.cpp @@ -23,20 +23,22 @@ bool RadioSwitch::isValid(QList rawData) { m_delay = rawData.first()/31; QByteArray binCode; - if(m_delay > 310 && m_delay < 340){ + + // new Remote -> average 314 + if(m_delay > 300 && m_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) < 500){ + if(rawData.at(i) < 700){ div = 1; }else{ div = 3; } // if long - if(rawData.at(i+1) < 500){ + if(rawData.at(i+1) < 700){ divNext = 1; }else{ divNext = 3; @@ -48,71 +50,70 @@ bool RadioSwitch::isValid(QList rawData) // if we have ___| | = 1 -> in 4 delays => 0001 if(div == 1 && divNext == 3){ - binCode.append("0"); + binCode.append('0'); }else if(div == 3 && divNext == 1){ - binCode.append("1"); + binCode.append('1'); }else{ return false; } } + } - m_binCode = binCode; - // get the channel of the remote signal (5 channels, 1=on, 0 = off) - QByteArray channelSettings; - for(int i = 1; i < 10; i+=2){ - if(m_binCode.at(i-1) == '0' && m_binCode.at(i) == '1'){ - channelSettings.append("0"); - }else{ - channelSettings.append("1"); - } - } - // get the button letter - char button; - if(m_binCode.at(10) == '0' && m_binCode.at(11) == '0'){ - button = 'A'; - } - if(m_binCode.at(12) == '0' && m_binCode.at(13) == '0'){ - button = 'B'; - } - if(m_binCode.at(14) == '0' && m_binCode.at(15) == '0'){ - button = 'C'; - } - if(m_binCode.at(16) == '0' && m_binCode.at(17) == '0'){ - button = 'D'; - } - if(m_binCode.at(18) == '0' && m_binCode.at(19) == '0'){ - button = 'E'; - } + m_binCode = binCode; - QStringList byteList; - for(int i = 4; i <= 24; i+=4){ - byteList.append(binCode.left(4)); - binCode = binCode.right(binCode.length() -4); + // get the channel of the remote signal (5 channels, 1=on, 0 = off) + QByteArray channelSettings; + for(int i = 1; i < 10; i+=2){ + if(m_binCode.at(i-1) == '0' && m_binCode.at(i) == '1'){ + channelSettings.append("0"); + }else{ + channelSettings.append("1"); } + } + // get the button letter + char button; + if(m_binCode.at(10) == '0' && m_binCode.at(11) == '0'){ + button = 'A'; + } + if(m_binCode.at(12) == '0' && m_binCode.at(13) == '0'){ + button = 'B'; + } + if(m_binCode.at(14) == '0' && m_binCode.at(15) == '0'){ + button = 'C'; + } + if(m_binCode.at(16) == '0' && m_binCode.at(17) == '0'){ + button = 'D'; + } + if(m_binCode.at(18) == '0' && m_binCode.at(19) == '0'){ + button = 'E'; + } - bool buttonStatus; - if(byteList.last().toInt(0,2) == 1){ - buttonStatus = true; - }else + QStringList byteList; + for(int i = 4; i <= 24; i+=4){ + byteList.append(binCode.left(4)); + binCode = binCode.right(binCode.length() -4); + } + + bool buttonStatus; + if(byteList.last().toInt(0,2) == 1){ + buttonStatus = true; + }else if(byteList.last().toInt(0,2) == 4){ buttonStatus = false; }else{ return false; } - qDebug() << "-----------------------------------------------------------"; - qDebug() << "| REMOTE signal |"; - qDebug() << "-----------------------------------------------------------"; - qDebug() << "delay :" << m_delay; - qDebug() << "bin CODE :" << m_binCode; - qDebug() << byteList; - qDebug() << "Channels:" << channelSettings << "Button:" << button << "=" << buttonStatus; - emit switchSignalReceived(channelSettings,button,buttonStatus); - return true; - }else{ - return false; - } + qDebug() << "-----------------------------------------------------------"; + qDebug() << "| REMOTE signal |"; + qDebug() << "-----------------------------------------------------------"; + qDebug() << "delay :" << m_delay; + qDebug() << "bin CODE :" << m_binCode; + qDebug() << byteList; + qDebug() << "Channels:" << channelSettings << "Button:" << button << "=" << buttonStatus; + emit switchSignalReceived(channelSettings,button,buttonStatus); + return true; } QByteArray RadioSwitch::calcBinCode(const QByteArray &channel, const RadioSwitch::RadioRemoteButton &button, const bool &buttonStatus) diff --git a/hive/libhive/radioplugin/radiothermometer.cpp b/hive/libhive/radioplugin/radiothermometer.cpp index 7ec75dbf..3c15ec0e 100644 --- a/hive/libhive/radioplugin/radiothermometer.cpp +++ b/hive/libhive/radioplugin/radiothermometer.cpp @@ -96,11 +96,12 @@ float RadioThermometer::getTemperature() } if(temperature == m_lastTemperature){ + qDebug() << "received same temperature from " << QString(id) << " - " << QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm:ss"); return temperature; }else{ m_lastTemperature = temperature; - QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm:ss");; + QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm:ss"); //qDebug() << timeStamp; QFile file("/root/temperature_log.ods"); diff --git a/hive/server/hive_pi/hive_pi.pro b/hive/server/hive_pi/hive_pi.pro index e28f4b70..d23bac9d 100644 --- a/hive/server/hive_pi/hive_pi.pro +++ b/hive/server/hive_pi/hive_pi.pro @@ -12,7 +12,7 @@ TARGET = hive CONFIG += console CONFIG -= app_bundle -target.path = /root/bin +target.path = /usr/bin INSTALLS += target TEMPLATE = app diff --git a/hive/server/hive_pi/hivecore.cpp b/hive/server/hive_pi/hivecore.cpp index 15653079..d0ce8ab2 100644 --- a/hive/server/hive_pi/hivecore.cpp +++ b/hive/server/hive_pi/hivecore.cpp @@ -8,23 +8,22 @@ HiveCore::HiveCore(QObject *parent) : m_server = new Server(this); m_server->startServer(); - m_jsonHandler = new JsonHandler(this); - - connect(m_server,SIGNAL(jsonDataAvailable(QByteArray)),m_jsonHandler,SLOT(process(QByteArray))); +// m_jsonHandler = new JsonHandler(this); +// connect(m_server,SIGNAL(jsonDataAvailable(QByteArray)),m_jsonHandler,SLOT(process(QByteArray))); // // create 433.92 MHz sender - m_sender = new RadioSender(this); - m_sender->setFrequency(RadioSender::RF433MHz); - m_sender->setLineCode(RadioSender::SWITCH); - m_sender->setPulseLength(320); -// //m_sender->sendBin("000000000000010101010001"); +// m_sender = new RadioSender(this); +// m_sender->setFrequency(RadioSender::RF433MHz); +// m_sender->setLineCode(RadioSender::SWITCH); +// m_sender->setPulseLength(320); // pin number 13 +// m_sender->sendBin("000000000000010101010001"); // create 433.92 MHz receiver m_reciver = new RadioReciver(this); m_reciver->setFrequency(RadioReciver::RF433MHz); - m_reciver->setPin(2); + m_reciver->setPin(2); // pin number 13 m_reciver->enableReceiver(); } diff --git a/hive/server/hive_pi/radio/radioreciver.cpp b/hive/server/hive_pi/radio/radioreciver.cpp index cabbc55c..8d3afc84 100644 --- a/hive/server/hive_pi/radio/radioreciver.cpp +++ b/hive/server/hive_pi/radio/radioreciver.cpp @@ -141,6 +141,7 @@ int RadioReciver::getPin() const void RadioReciver::handleInterrupt() { + if(!m_enable){ return; } @@ -149,7 +150,9 @@ void RadioReciver::handleInterrupt() m_duration = currentTime - m_lastTime; // filter nois - if (m_duration > 5000 && m_duration > m_timings[0] - 200 && m_duration < m_timings[0] + 200) { + if (m_duration > 5000 && m_timings[0] - 200 && m_duration < m_timings[0] + 200){ + //qDebug() << "dt " << m_duration; + m_repeatCount++; m_changeCount--; @@ -163,6 +166,8 @@ void RadioReciver::handleInterrupt() m_timings[i] = 0; } detectProtocol(rawData); + }else{ + //qDebug() << "changes: " << m_changeCount; } m_repeatCount = 0; } @@ -170,8 +175,9 @@ void RadioReciver::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; } @@ -179,26 +185,29 @@ void RadioReciver::handleInterrupt() m_lastTime = currentTime; } -void RadioReciver::detectProtocol(QList rawData) +bool RadioReciver::detectProtocol(QList rawData) { // check if we have a valid signal, 1 sync + 48 data if(rawData.length() != 49){ - return; + qDebug() << rawData; + return false; } // check plugins if(m_thermometer->isValid(rawData)){ m_thermometer->getTemperature(); + return true; }else - if(m_switch->isValid(rawData)){ - m_switch->getBinCode(); - }else{ - qDebug() << "-----------------------------------------------------------"; - qDebug() << "| GENERIC signal |"; - qDebug() << "-----------------------------------------------------------"; - qDebug() << "delay :" << rawData.first() /31; - qDebug() << rawData; - } - + if(m_switch->isValid(rawData)){ + m_switch->getBinCode(); + return true; + }else{ + qDebug() << "-----------------------------------------------------------"; + qDebug() << "| GENERIC signal |"; + qDebug() << "-----------------------------------------------------------"; + qDebug() << "delay :" << rawData.first() /31; + qDebug() << rawData; + } + return false; } void RadioReciver::enableReceiver() diff --git a/hive/server/hive_pi/radio/radioreciver.h b/hive/server/hive_pi/radio/radioreciver.h index 6cba6b6f..06f7ef3b 100644 --- a/hive/server/hive_pi/radio/radioreciver.h +++ b/hive/server/hive_pi/radio/radioreciver.h @@ -29,7 +29,7 @@ public: private: void handleInterrupt(); - void detectProtocol(QList rawData); + bool detectProtocol(QList rawData); bool m_enable; int m_pin;