diff --git a/hive/client/hive_client/hive_client.pro b/hive/client/hive_client/hive_client.pro index 4d6dd3ad..8125ebad 100644 --- a/hive/client/hive_client/hive_client.pro +++ b/hive/client/hive_client/hive_client.pro @@ -16,11 +16,13 @@ QML_IMPORT_PATH = # The .cpp file which was generated for your project. Feel free to hack it. SOURCES += main.cpp \ hiveclientcore.cpp \ - settings.cpp + settings.cpp \ + sensormodel.cpp HEADERS += \ hiveclientcore.h \ - settings.h + settings.h \ + sensormodel.h # Installation path diff --git a/hive/client/hive_client/hiveclientcore.cpp b/hive/client/hive_client/hiveclientcore.cpp index c59deb84..54e83aec 100644 --- a/hive/client/hive_client/hiveclientcore.cpp +++ b/hive/client/hive_client/hiveclientcore.cpp @@ -7,9 +7,9 @@ HiveClientCore::HiveClientCore(QObject *parent) : QObject(parent) { - m_id = 0; m_client = new Client(this); + // QML Typs qmlRegisterType("hive",1,0,"Settings"); @@ -26,33 +26,3 @@ HiveClientCore::HiveClientCore(QObject *parent) : } -void HiveClientCore::onConnected() -{ - //sendSomething("device", "getAll"); - sendSomething("device", "add"); - -} - -void HiveClientCore::sendSomething(QString deviceName, QString method) -{ - QVariantMap responseMap; - responseMap.insert("device", deviceName); - responseMap.insert("method", method); - responseMap.insert("id", m_id++); - - QVariantMap params; - params.insert("deviceType","actor"); - params.insert("name","Schreibtisch On"); - params.insert("protocol","RF433"); - params.insert("linecode","remote"); - params.insert("code","000000000000010101010001"); - - responseMap.insert("params", params); - - QJsonDocument doc = QJsonDocument::fromVariant(responseMap); - qDebug() << "_______________________________________"; - qDebug() << "send to hive:"; - QByteArray json = doc.toJson(); - qDebug() << json; - m_client->sendData(json); -} diff --git a/hive/client/hive_client/hiveclientcore.h b/hive/client/hive_client/hiveclientcore.h index c6f4458f..597bdbdf 100644 --- a/hive/client/hive_client/hiveclientcore.h +++ b/hive/client/hive_client/hiveclientcore.h @@ -20,11 +20,7 @@ private: QQmlApplicationEngine *m_engine; QObject *topLevel; - int m_id; - private slots: - void onConnected(); - void sendSomething(QString deviceName, QString method); signals: diff --git a/hive/client/hive_client/main.cpp b/hive/client/hive_client/main.cpp index 6f4e9eeb..dce16a59 100644 --- a/hive/client/hive_client/main.cpp +++ b/hive/client/hive_client/main.cpp @@ -1,5 +1,6 @@ #include #include "hiveclientcore.h" +#include "usb.h" int main(int argc, char *argv[]) { diff --git a/hive/client/hive_client/qml/hive_client/AddDevicePage.qml b/hive/client/hive_client/qml/hive_client/AddDevicePage.qml index edbcfba7..3cea9a7d 100644 --- a/hive/client/hive_client/qml/hive_client/AddDevicePage.qml +++ b/hive/client/hive_client/qml/hive_client/AddDevicePage.qml @@ -5,26 +5,33 @@ import QtQuick.Layouts 1.0 Component { Rectangle{ - anchors.fill: parent - + color: "black" ColumnLayout{ id: addDeviceColumn - - anchors.horizontalCenter: parent.horizontalCenter - + anchors.left: parent.left + anchors.leftMargin: 30 + anchors.right: parent.right + anchors.rightMargin: 30 GroupBox{ id: nameGroupBox + anchors.left: parent.left + anchors.right: parent.right title: "Name" Row{ + id: row1 spacing: 5 - Text{ + + Label{ + id: nameLabel anchors.verticalCenter: parent.verticalCenter text: "Name:" + color: "white" } TextField{ - id: nameText + id: nameTextField + implicitWidth: 300 anchors.verticalCenter: parent.verticalCenter placeholderText: "Device Name" } @@ -33,15 +40,23 @@ Component { } GroupBox{ id: deviceTypeGroupBox + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.right: parent.right + anchors.rightMargin: 0 title: "Device Type" ComboBox { id: deviceComboBox - model: ["actor","sensor"] + model: ["device","actor","sensor"] } } GroupBox{ id: communicationTypeGroupBox + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.right: parent.right + anchors.rightMargin: 0 title: "Communication Type" ComboBox { @@ -51,6 +66,10 @@ Component { } GroupBox{ id: linecodeGroupBox + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.right: parent.right + anchors.rightMargin: 0 title: "Linecode" visible: communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433" ? true : false @@ -61,29 +80,35 @@ Component { } GroupBox{ id: switchGroupBox + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.right: parent.right + anchors.rightMargin: 0 title: "Switchsettings" visible: (linecodeComboBox.currentText == "Switch") && (communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433") ? true : false RowLayout{ GridLayout{ - columns: 6 + columns: 5 Label{ text: "1" + color: "white" } Label{ text: "2" + color: "white" } Label{ text: "3" + color: "white" } Label{ text: "4" + color: "white" } Label{ text: "5" - } - Label{ - text: "6" + color: "white" } CheckBox{ id: channel1 @@ -100,9 +125,6 @@ Component { CheckBox{ id: channel5 } - CheckBox{ - id: channel6 - } } ComboBox { id: switchComboBox @@ -111,5 +133,31 @@ Component { } } } + Button{ + id: cancelButton + anchors.left: parent.left + anchors.leftMargin: 30 + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 + + text: "Cancel" + onClicked: stackView.pop(this) + + } + Button{ + id: saveButton + anchors.right: parent.right + anchors.rightMargin: 30 + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 + + text: "Save" + onClicked: { + var deviceType = deviceComboBox.currentText + var method = "add" + // TODO: variant map...to send hive the correct add command with all parameters + stackView.pop(this) + } + } } } diff --git a/hive/client/hive_client/qml/hive_client/ConnectionPage.qml b/hive/client/hive_client/qml/hive_client/ConnectionPage.qml index 400366ae..12c194f4 100644 --- a/hive/client/hive_client/qml/hive_client/ConnectionPage.qml +++ b/hive/client/hive_client/qml/hive_client/ConnectionPage.qml @@ -4,7 +4,8 @@ import QtQuick.Layouts 1.0 Component { Rectangle{ - anchors.fill: parent + focus: connectButton.forceActiveFocus() + color: "black" GroupBox { id: connectionGroupBox @@ -26,6 +27,7 @@ Component { Text { id: ipLable text: "IP:" + color: "white" horizontalAlignment: Text.AlignHCenter } TextField { @@ -37,6 +39,7 @@ Component { Text { id: portLable text: "Port:" + color: "white" wrapMode: Text.NoWrap verticalAlignment: Text.AlignTop horizontalAlignment: Text.AlignHCenter @@ -49,5 +52,6 @@ Component { } } } + } } diff --git a/hive/client/hive_client/qml/hive_client/MainMenuButton.qml b/hive/client/hive_client/qml/hive_client/MainMenuButton.qml new file mode 100644 index 00000000..4b86ec72 --- /dev/null +++ b/hive/client/hive_client/qml/hive_client/MainMenuButton.qml @@ -0,0 +1,89 @@ +import QtQuick 2.0 +import QtGraphicalEffects 1.0 +Rectangle { + id: buttonRectangle + + width: 300 + height: 200 + + property string text + signal clicked() + + color: "black" + + RectangularGlow { + id: effect + anchors.fill: rect + glowRadius: rectMouseArea.pressed ? 18 : 10 + spread: 0.4 + color: "steelblue" + cornerRadius: rect.radius + glowRadius + } + + Rectangle { + id: rect + color: "#ed000000" + anchors.centerIn: parent + anchors.fill: parent + anchors.margins: 20 + radius: 25 + border.width: 5 + border.color: "#000000" + opacity: 1 + + Text{ + id: buttonText + anchors.centerIn: parent + + color: "#ffffff" + styleColor: "#ffffff" + horizontalAlignment: Text.AlignHCenter + font.pointSize: 20 + font.family: "Arial" + font.bold: true + text: buttonRectangle.text + } + + MouseArea{ + id: rectMouseArea + anchors.fill: parent + onClicked: { + buttonRectangle.clicked() + } + } + } + +} + + + + +//import QtQuick 2.0 + +//Rectangle{ +// id: buttonRectangle + +// property string text +// signal clicked() + +// color: buttonMousArea.pressed ? "lightsteelblue" : "steelblue" +// border.width: buttonMousArea.pressed ? 4 : 2 +// border.color: "black" +// radius: 10 + +// Text{ +// id: buttonText +// anchors.centerIn: parent +// text: buttonRectangle.text +// } +// MouseArea{ +// id: buttonMousArea +// anchors.fill: parent +// onClicked: { +// buttonRectangle.clicked() +// } +// } + +//} + + diff --git a/hive/client/hive_client/qml/hive_client/MainPage.qml b/hive/client/hive_client/qml/hive_client/MainPage.qml index 0f0b7450..67147bfe 100644 --- a/hive/client/hive_client/qml/hive_client/MainPage.qml +++ b/hive/client/hive_client/qml/hive_client/MainPage.qml @@ -5,39 +5,27 @@ import QtQuick.Layouts 1.0 Component { Rectangle{ - anchors.fill: parent - + color: "black" Column{ anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top anchors.topMargin: 30 + spacing: 20 - Rectangle{ - id: addDeviceButton - width: 150 - height: 70 - color: "#c8c8c8" - border.color: "black" - radius: 10 - Text{ - anchors.centerIn: parent - text: "Add Device" - } - MouseArea{ - id: addDeviceButtonMousArea - anchors.fill: parent - onPressed: addDeviceButton.color = "steelblue" - onReleased: addDeviceButton.color = "#c8c8c8" - onClicked: stackView.push(addDevicePage) - } + MainMenuButton{ + text: "Add device" + onClicked: stackView.push(addDevicePage) } + MainMenuButton{ + text: "Temperatur" + onClicked: stackView.push(temperaturPage) + } + } } - } - diff --git a/hive/client/hive_client/qml/hive_client/SensorField.qml b/hive/client/hive_client/qml/hive_client/SensorField.qml new file mode 100644 index 00000000..6db8d9bf --- /dev/null +++ b/hive/client/hive_client/qml/hive_client/SensorField.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 +import QtGraphicalEffects 1.0 + +Rectangle { + + RectangularGlow { + id: effect + anchors.fill: rect + glowRadius: rectMouseArea.pressed ? 18 : 10 + spread: 0.4 + color: "steelblue" + cornerRadius: rect.radius + glowRadius + } + + Rectangle { + id: rect + color: "black" + anchors.centerIn: parent + anchors.fill: parent + anchors.margins: 20 + radius: 25 + + MouseArea{ + id: rectMouseArea + anchors.fill: parent + } + } + +} diff --git a/hive/client/hive_client/qml/hive_client/TemperaturePage.qml b/hive/client/hive_client/qml/hive_client/TemperaturePage.qml new file mode 100644 index 00000000..180ba516 --- /dev/null +++ b/hive/client/hive_client/qml/hive_client/TemperaturePage.qml @@ -0,0 +1,63 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.0 +import QtGraphicalEffects 1.0 + +Component { + + Rectangle{ + color: "black" + + RectangularGlow { + id: effect + anchors.fill: rect + glowRadius: 18 + spread: 0.4 + color: "steelblue" + cornerRadius: rect.radius + glowRadius + } + + Rectangle{ + id: rect + anchors.fill: parent + anchors.margins: 70 + color: "black" + radius: 30 + Canvas { + anchors.fill: parent + contextType: "2d" + + Path{ + id: myPath + startX: 0; startY: 100 + + PathCurve { x: 75; y: 75 } + PathCurve { x: 200; y: 150 } + PathCurve { x: 325; y: 25 } + PathCurve { x: 400; y: 100 } + PathCurve { x: 500; y: 100 } + PathCurve { x: 600; y: 100 } + PathCurve { x: 700; y: 300 } + } + onPaint: { + context.strokeStyle = Qt.rgba(.4,.6,.8); + context.path = myPath; + context.stroke(); + } + } + + } + + Button{ + id: cancelButton + anchors.left: parent.left + anchors.leftMargin: 30 + anchors.bottom: parent.bottom + anchors.bottomMargin: 10 + + text: "Cancel" + onClicked: stackView.pop(this) + + } + + } +} diff --git a/hive/client/hive_client/qml/hive_client/main.qml b/hive/client/hive_client/qml/hive_client/main.qml index 9e2c6b12..7c179bda 100644 --- a/hive/client/hive_client/qml/hive_client/main.qml +++ b/hive/client/hive_client/qml/hive_client/main.qml @@ -29,8 +29,9 @@ ApplicationWindow{ anchors.bottom: parent.bottom } title: "Hive Client" - width: 600 - height: 500 + minimumWidth: 800 + minimumHeight: 600 + StackView { id: stackView @@ -66,6 +67,10 @@ ApplicationWindow{ AddDevicePage{ id: addDevicePage } + TemperaturePage{ + id: temperaturPage + } + } diff --git a/hive/client/hive_client/sensormodel.cpp b/hive/client/hive_client/sensormodel.cpp new file mode 100644 index 00000000..7b69a95a --- /dev/null +++ b/hive/client/hive_client/sensormodel.cpp @@ -0,0 +1,6 @@ +#include "sensormodel.h" + +SensorModel::SensorModel(QObject *parent) : + QAbstractListModel(parent) +{ +} diff --git a/hive/client/hive_client/sensormodel.h b/hive/client/hive_client/sensormodel.h new file mode 100644 index 00000000..af300a6c --- /dev/null +++ b/hive/client/hive_client/sensormodel.h @@ -0,0 +1,23 @@ +#ifndef SENSORMODEL_H +#define SENSORMODEL_H + +#include +#include + +class SensorModel : public QAbstractListModel +{ + Q_OBJECT +public: + explicit SensorModel(QObject *parent = 0); + +private: + + + +signals: + +public slots: + +}; + +#endif // SENSORMODEL_H diff --git a/hive/libhive/client.cpp b/hive/libhive/client.cpp index 88e5130a..675b61f4 100644 --- a/hive/libhive/client.cpp +++ b/hive/libhive/client.cpp @@ -29,8 +29,7 @@ void Client::readData() QByteArray dataLine = m_tcpSocket->readLine(); message.append(dataLine); if(dataLine == "}\n"){ - emit jsonDataAvailable(message); - message.clear(); + emit dataAvailable(message); } } } @@ -49,6 +48,61 @@ void Client::disconneted() emit connectionChanged(); } +void Client::processData(const QByteArray &data) +{ + QJsonParseError error; + QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error); + + if(error.error != QJsonParseError::NoError) { + qDebug() << "failed to parse data" << data << ":" << error.errorString(); + } + qDebug() << "-------------------------\n" << jsonDoc.toJson(); + + QVariantMap command = jsonDoc.toVariant().toMap(); + QVariantMap params = jsonDoc.toVariant().toMap().value("params").toMap(); + + if(command.contains("signal")){ + handleSignal(params); + }else{ + handleResponse(params); + } + +} + +void Client::handleResponse(const QVariantMap &rsp) +{ + qDebug() << "handling response" << rsp; + if(!rsp.contains("id")) { + qDebug() << "packet does not contain an id. discarding..."; + return; + } + int id = rsp.value("id").toInt(); + if(m_requestMap.contains(id)) { + switch(m_requestMap.value(id)){ + case RequestAddDevice: + qDebug() << "add device response received"; + break; + case RequestEditDevice: + qDebug() << "edit device response received"; + break; + case RequestRemoveDevice: + qDebug() << "add device response received"; + break; + + } + m_requestMap.remove(id); + } + + + + +} + +void Client::handleSignal(const QVariantMap &signal) +{ + +} + void Client::connectToHost(QString ipAddress, QString port) { qDebug() << "connecting to" << ipAddress << ":" << port; diff --git a/hive/libhive/client.h b/hive/libhive/client.h index bd585ec3..99ed60a6 100644 --- a/hive/libhive/client.h +++ b/hive/libhive/client.h @@ -13,18 +13,27 @@ class Client : public QObject public: explicit Client(QObject *parent = 0); - bool isConnected(); + enum Request { + RequestAddDevice, + RequestEditDevice, + RequestRemoveDevice + }; + + bool isConnected(); private: QTcpSocket *m_tcpSocket; QString m_tcpBuffer; bool m_connectionStatus; + int m_commandId; + + QMap m_requestMap; signals: - void jsonDataAvailable(const QByteArray &data); + void dataAvailable(const QByteArray &data); void connectionChanged(); @@ -34,6 +43,11 @@ private slots: void connected(); void disconneted(); + void processData(const QByteArray &data); + void handleResponse(const QVariantMap &rsp); + void handleSignal(const QVariantMap &signal); + + public slots: void connectToHost(QString ipAddress, QString port); void disconnectFromHost(); diff --git a/hive/libhive/jsonhandler.h b/hive/libhive/jsonhandler.h index e530d564..049cb943 100644 --- a/hive/libhive/jsonhandler.h +++ b/hive/libhive/jsonhandler.h @@ -12,7 +12,9 @@ class JsonHandler : public QObject Q_OBJECT public: explicit JsonHandler(QObject *parent = 0); - + QByteArray addRemote(QString deviceType, QString method, QString name, QString protocol, QString Linecode, QString m); + + signals: void notifyAll(const QByteArray &data); @@ -23,7 +25,6 @@ public slots: private: DeviceJsonPlugin *m_device; - QByteArray formatResponse(const QVariantMap &command, const QVariantMap &responseParams); QByteArray formatErrorResponse(const QVariantMap &command, const QString &error); diff --git a/hive/libhive/jsonplugin/devicejsonplugin.cpp b/hive/libhive/jsonplugin/devicejsonplugin.cpp index 7e488b32..ebed9c15 100644 --- a/hive/libhive/jsonplugin/devicejsonplugin.cpp +++ b/hive/libhive/jsonplugin/devicejsonplugin.cpp @@ -51,7 +51,7 @@ void DeviceJsonPlugin::add(QVariantMap parameters) void DeviceJsonPlugin::remove() { - + } void DeviceJsonPlugin::editValue(QString value, QVariant key) diff --git a/hive/libhive/jsonplugin/jsonplugin.h b/hive/libhive/jsonplugin/jsonplugin.h index 49c0d0a0..87ee319c 100644 --- a/hive/libhive/jsonplugin/jsonplugin.h +++ b/hive/libhive/jsonplugin/jsonplugin.h @@ -8,7 +8,7 @@ class JsonPlugin : public QObject Q_OBJECT public: explicit JsonPlugin(QObject *parent = 0); - //virtual ~JsonPlugin(); + virtual ~JsonPlugin(){} virtual QString deviceName() = 0; virtual QByteArray process(const QVariantMap & command, const QVariantMap & parameters) = 0; diff --git a/hive/server/hive_pi/hive_pi.pro b/hive/server/hive_pi/hive_pi.pro index e28f4b70..98d96eb5 100644 --- a/hive/server/hive_pi/hive_pi.pro +++ b/hive/server/hive_pi/hive_pi.pro @@ -29,10 +29,16 @@ DEPENDPATH += $$PWD/../../libhive SOURCES += main.cpp \ hivecore.cpp \ radio/radioreciver.cpp \ - radio/radiosender.cpp + radio/radiosender.cpp \ + radio/plugins/radioplugin.cpp \ + radio/plugins/rfthermometer.cpp \ + radio/plugins/rfswitch.cpp HEADERS += \ hivecore.h \ radio/radioreciver.h \ - radio/radiosender.h + radio/radiosender.h \ + radio/plugins/radioplugin.h \ + radio/plugins/rfthermometer.h \ + radio/plugins/rfswitch.h diff --git a/hive/server/hive_pi/hivecore.cpp b/hive/server/hive_pi/hivecore.cpp index 09392aa2..d85faa3f 100644 --- a/hive/server/hive_pi/hivecore.cpp +++ b/hive/server/hive_pi/hivecore.cpp @@ -18,16 +18,16 @@ HiveCore::HiveCore(QObject *parent) : // // create 433.92 MHz sender -// m_sender = new RadioSender(this); -// m_sender->setFrequency(RadioSender::RF433MHz); -// m_sender->setLineCode(RadioSender::REMOTE); -// m_sender->setPulseLength(320); + m_sender = new RadioSender(this); + m_sender->setFrequency(RadioSender::RF433MHz); + m_sender->setLineCode(RadioSender::REMOTE); + m_sender->setPulseLength(320); // //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->enableReceiver(); + // create 433.92 MHz receiver + m_reciver = new RadioReciver(this); + m_reciver->setFrequency(RadioReciver::RF433MHz); + m_reciver->setPin(2); + m_reciver->enableReceiver(); } diff --git a/hive/server/hive_pi/hivecore.h b/hive/server/hive_pi/hivecore.h index d704c43b..5e9b96fc 100644 --- a/hive/server/hive_pi/hivecore.h +++ b/hive/server/hive_pi/hivecore.h @@ -16,8 +16,8 @@ public: private: Server *m_server; - //RadioReciver *m_reciver; - //RadioSender *m_sender; + RadioReciver *m_reciver; + RadioSender *m_sender; DeviceManager *m_deviceManager; JsonHandler *m_jsonHandler; diff --git a/hive/server/hive_pi/radio/plugins/radioplugin.cpp b/hive/server/hive_pi/radio/plugins/radioplugin.cpp new file mode 100644 index 00000000..c8c8bbfc --- /dev/null +++ b/hive/server/hive_pi/radio/plugins/radioplugin.cpp @@ -0,0 +1,6 @@ +#include "radioplugin.h" + +RadioPlugin::RadioPlugin(QObject *parent) : + QObject(parent) +{ +} diff --git a/hive/server/hive_pi/radio/plugins/radioplugin.h b/hive/server/hive_pi/radio/plugins/radioplugin.h new file mode 100644 index 00000000..32c581af --- /dev/null +++ b/hive/server/hive_pi/radio/plugins/radioplugin.h @@ -0,0 +1,18 @@ +#ifndef RADIOPLUGIN_H +#define RADIOPLUGIN_H + +#include + +class RadioPlugin : public QObject +{ + Q_OBJECT +public: + explicit RadioPlugin(QObject *parent = 0); + virtual ~RadioPlugin(){} + + virtual bool isValid(QList rawData) = 0; + virtual QByteArray getBinCode() = 0; + +}; + +#endif // RADIOPLUGIN_H diff --git a/hive/server/hive_pi/radio/plugins/rfswitch.cpp b/hive/server/hive_pi/radio/plugins/rfswitch.cpp new file mode 100644 index 00000000..a0c7c4e2 --- /dev/null +++ b/hive/server/hive_pi/radio/plugins/rfswitch.cpp @@ -0,0 +1,118 @@ +#include +#include + +#include "rfswitch.h" + +RFSwitch::RFSwitch(QObject *parent) + :RadioPlugin(parent) +{ + m_delay = 0; + m_binCode = 0; +} + +QByteArray RFSwitch::getBinCode() +{ + if(m_binCode.isEmpty()){ + return NULL; + }else{ + return m_binCode; + } +} + +bool RFSwitch::isValid(QList rawData) +{ + + m_delay = rawData.first()/31; + QByteArray binCode; + if(m_delay > 310 && m_delay < 340){ + // go trough all 48 timings + for(int i = 1; i <= 48; i+=2 ){ + int div; + int divNext; + + // if short + if(rawData.at(i) < 500){ + div = 1; + }else{ + div = 3; + } + // if long + if(rawData.at(i+1) < 500){ + 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 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'; + } + + 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; + } +} + diff --git a/hive/server/hive_pi/radio/plugins/rfswitch.h b/hive/server/hive_pi/radio/plugins/rfswitch.h new file mode 100644 index 00000000..5bbd2fce --- /dev/null +++ b/hive/server/hive_pi/radio/plugins/rfswitch.h @@ -0,0 +1,26 @@ +#ifndef RFSWITCH_H +#define RFSWITCH_H + +#include +#include + +#define RFSwitchDelay 320 + +class RFSwitch : public RadioPlugin +{ +public: + explicit RFSwitch(QObject *parent = 0); + + QByteArray getBinCode(); + bool isValid(QList rawData); + +private: + int m_delay; + QByteArray m_binCode; + +signals: + void switchSignalReceived(const QByteArray &channel, const char &button, const bool &buttonStatus); + +}; + +#endif // RFSWITCH_H diff --git a/hive/server/hive_pi/radio/plugins/rfthermometer.cpp b/hive/server/hive_pi/radio/plugins/rfthermometer.cpp new file mode 100644 index 00000000..5f6b7e7b --- /dev/null +++ b/hive/server/hive_pi/radio/plugins/rfthermometer.cpp @@ -0,0 +1,122 @@ +#include +#include +#include +#include + +#include "rfthermometer.h" + +RFThermometer::RFThermometer(QObject *parent) : + RadioPlugin(parent) +{ + m_lastTemperature = -1111; + m_delay = 0; + m_binCode = 0; + +} + +QByteArray RFThermometer::getBinCode() +{ + if(m_binCode.isEmpty()){ + return NULL; + }else{ + return m_binCode; + } +} + + +bool RFThermometer::isValid(QList rawData) +{ + m_delay = rawData.first()/31; + QByteArray binCode; + + if(m_delay > 250 && m_delay < 260){ + + // __ + // | |________ = 0 1100000000 + // __ + // | |________________ = 1 110000000000000000 + + for(int i = 1; i <= 48; i+=2 ){ + if(rawData.at(i) < 1000 && rawData.at(i+1) < 3000 && rawData.at(i+1) > 1000){ + binCode.append('0'); + }else if(rawData.at(i) < 1000 && rawData.at(i+1) > 3000){ + binCode.append('1'); + }else{ + return false; + } + } + m_binCode = binCode; + return true; + }else{ + m_binCode = 0; + return false; + } +} + +float RFThermometer::getTemperature() +{ + // { ID },{-+}{ temp, },{Batt},{,temp} + // "XXXX","XXXX","X XXX","XXXX","XXXX","XXXX", + + QByteArray binCode = m_binCode; + + QList byteList; + for(int i = 4; i <= 24; i+=4){ + byteList.append(binCode.left(4)); + binCode = binCode.right(binCode.length() -4); + } + + QByteArray temperatureBin(byteList.at(2) + byteList.at(3)); + QByteArray batteryBin(byteList.at(4)); + QByteArray temperatureTenthBin(byteList.at(5)); + + + // check sign of temperature -> if first bit of temperature byte is 1 -> temp is negativ + int sign = 0; + if(temperatureBin.left(1).toInt() == 1){ + sign = -1; + }else{ + sign = 1; + } + + //qDebug() << temperatureBin << "=" << temperatureBin.left(1) << temperatureBin.right(7) << temperatureBin.right(7).toInt(0,2) << "," << temperatureTenthBin.toInt(0,2) ; + + // calc temperature + float temperature = sign*(temperatureBin.right(7).toInt(0,2) + (float)temperatureTenthBin.toInt(0,2)/10); + + // check if the battery is low + bool batteryStatus; + if(batteryBin.toInt(0,2) == 0){ + batteryStatus = true; + }else{ + batteryStatus = false; + } + + if(temperature == m_lastTemperature){ + return temperature; + }else{ + + m_lastTemperature = temperature; + QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm:ss");; + //qDebug() << timeStamp; + + QFile file("/root/temperature_log.ods"); + file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); + QTextStream out(&file); + + QByteArray id = byteList.at(0)+byteList.at(1); + + out << timeStamp << "," << temperature << "," << batteryStatus << "\n"; + file.close(); + qDebug() << "-----------------------------------------------------------"; + qDebug() << "| THERMOMETER signal |"; + qDebug() << "-----------------------------------------------------------"; + qDebug() << "delay :" << m_delay; + qDebug() << "bin CODE :" << m_binCode; + qDebug() << byteList; + qDebug() << timeStamp << " ID:" << id << " Temperature:" << temperature << " Battery OK: " << batteryStatus; + + //emit temperatureSignalReceived(id,temperature,batteryStatus); + return temperature; + } +} diff --git a/hive/server/hive_pi/radio/plugins/rfthermometer.h b/hive/server/hive_pi/radio/plugins/rfthermometer.h new file mode 100644 index 00000000..cdabda69 --- /dev/null +++ b/hive/server/hive_pi/radio/plugins/rfthermometer.h @@ -0,0 +1,31 @@ +#ifndef RFTHERMOMETER_H +#define RFTHERMOMETER_H + +#include +#include + +#define RFThermometerDelay 250 + +class RFThermometer : public RadioPlugin +{ +public: + explicit RFThermometer(QObject *parent = 0); + + QByteArray getBinCode(); + bool isValid(QList rawData); + float getTemperature(); + +private: + float m_lastTemperature; + int m_delay; + QByteArray m_binCode; + +signals: + void temperatureSignalReceived(const QByteArray &id, const float &temperature, const bool &batteryStatus); + +public slots: + + +}; + +#endif // RFTHERMOMETER_H diff --git a/hive/server/hive_pi/radio/radioreciver.cpp b/hive/server/hive_pi/radio/radioreciver.cpp index 1e1e373e..78ea5e0f 100644 --- a/hive/server/hive_pi/radio/radioreciver.cpp +++ b/hive/server/hive_pi/radio/radioreciver.cpp @@ -1,12 +1,10 @@ -#include "radioreciver.h" -#include "wiringPi.h" -#include #include #include #include #include -static float lastTemperature = 0; +#include "radioreciver.h" +#include "wiringPi.h" // ##################################################################################################### @@ -109,6 +107,9 @@ RadioReciver::RadioReciver(QObject *parent) : m_lastTime = 0; m_repeatCount = 0; + m_thermometer = new RFThermometer(this); + m_switch = new RFSwitch(this); + for(int i = 0; i < RC_MAX_CHANGES; i++ ){ m_timings[i] = 0; } @@ -178,212 +179,20 @@ void RadioReciver::handleInterrupt() void RadioReciver::detectProtocol(QList rawData) { - qDebug() << "==========================================================================="; - qDebug() <<"VALID SIGNAL (48 bit)" << " --> pulse width =" << rawData.first()/31; - qDebug() << rawData; - -// int pulseWidth = rawData.first()/31; - -// QList rawDataKGV; -// foreach (int timing, rawData){ -// int kgv = ((float)timing/pulseWidth)+0.5; -// rawDataKGV.append(kgv); -// } -// qDebug() << "-------= " << rawDataKGV; + // check if we have a valid signal, 1 sync + 48 data + if(rawData.length() != 49){ + return; + } + // check plugins + if(m_thermometer->isValid(rawData)){ + m_thermometer->getTemperature(); + } + if(m_switch->isValid(rawData)){ + m_switch->getBinCode(); + } } - -//void RadioReciver::detectProtocol(int signalCount) -//{ -// if(signalCount < 49){ -// //qDebug() << "ERROR: got a signal with just" << signalCount << "signals"; -// return; -// } -// qDebug() << "==========================================================================="; -// QList rawData; - -// // go trough all 49 timings -// for(int i = 0; i <= 48; i+=1 ){ -// rawData.append(timings[i]); -// } -// qDebug() << "raw data:" << rawData; - -// unsigned long delay = timings[0] / 31; - -// // ######################################################################### -// if(delay > 250 && delay < 260){ -// qDebug() << "-----------------------------------------------------------"; -// qDebug() << " seems to be a TERMOMETER signal"; -// qDebug() << "-----------------------------------------------------------"; -// qDebug() << "delay :" << delay; -// qDebug() << "bits :" << signalCount-1; - -// QByteArray binCode; - -// // __ -// // | |________ = 0 1100000000 -// // __ -// // | |________________ = 1 110000000000000000 - -// for(int i = 1; i <= 48; i+=2 ){ -// if(timings[i] < 1000 && timings[i+1] < 3000 && timings[i+1] > 1000){ -// binCode.append('0'); -// }else if(timings[i] < 1000 && timings[i+1] > 3000){ -// binCode.append('1'); -// }else{ -// qDebug() << "ERROR: could not read code...error in transmission"; -// return; -// } -// } - -// qDebug() << "bin CODE :" << binCode; -// parseTemperature(binCode); - -// return; -// } - -// // ######################################################################### -// if(delay > 310 && delay < 340){ - -// qDebug() << "-----------------------------------------------------------"; -// qDebug() << " seems to be a REMOTE signal"; -// qDebug() << "-----------------------------------------------------------"; -// qDebug() << "delay :" << delay; -// qDebug() << "bits :" << signalCount-1; - -// QByteArray binCode; -// QList rawData; - -// // go trough all 48 timings -// for(int i = 1; i <= 48; i+=2 ){ -// rawData.append(timings[i]); -// rawData.append(timings[i+1]); -// int div; -// int divNext; - -// // if short -// if(timings[i] / delay < 2){ -// div = 1; -// }else{ -// div = 3; -// } -// // if long -// if(timings[i+1] / delay < 2){ -// 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{ -// qDebug() << "ERROR: could not read code...error in transmission"; -// return; -// } -// } - -// //qDebug() << "raw data:" << rawData; -// qDebug() << "bin CODE :" << binCode; -// QStringList byteList; -// for(int i = 4; i <= 24; i+=4){ -// byteList.append(binCode.left(4)); -// binCode = binCode.right(binCode.length() -4); -// } -// qDebug() << byteList; - - -// }else{ -// // ######################################################################### -// qDebug() << "-----------------------------------------------------------"; -// qDebug() << " seems to be a GENERIC signal"; -// qDebug() << "-----------------------------------------------------------"; -// qDebug() << "delay :" << delay; -// qDebug() << "bits : " << signalCount-1; - -// QList rawData; - -// QFile file("/root/rc433_log_data.ods"); -// file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); -// QTextStream out(&file); - -// for(int i = 0; i < signalCount; i+=1 ){ -// out << timings[i] << ","; -// rawData.append(timings[i]); -// } -// out << ";\n"; -// file.close(); -// qDebug() << "raw data:" << rawData; - - -// } -//} - -//float RadioReciver::parseTemperature(QByteArray codeBin) -//{ -// // { ID },{-+}{ temp, },{Batt},{,temp} -// // "XXXX","XXXX","X XXX","XXXX","XXXX","XXXX", - -// QList byteList; -// for(int i = 4; i <= 24; i+=4){ -// byteList.append(codeBin.left(4)); -// codeBin = codeBin.right(codeBin.length() -4); -// } -// qDebug() << byteList; - -// QByteArray temperatureBin(byteList.at(2) + byteList.at(3)); -// QByteArray batteryBin(byteList.at(4)); -// QByteArray temperatureTenthBin(byteList.at(5)); - - -// // check sign of temperature -> if first bit of temperature byte is 1 -> temp is negativ -// int sign = 0; -// if(temperatureBin.left(1).toInt() == 1){ -// sign = -1; -// }else{ -// sign = 1; -// } - -// //qDebug() << temperatureBin << "=" << temperatureBin.left(1) << temperatureBin.right(7) << temperatureBin.right(7).toInt(0,2) << "," << temperatureTenthBin.toInt(0,2) ; - -// // calc temperature -// float temperature = sign*(temperatureBin.right(7).toInt(0,2) + (float)temperatureTenthBin.toInt(0,2)/10); - -// // check if the battery is low -// QString batteryStatus; -// if(batteryBin.toInt(0,2) == 0){ -// batteryStatus = "ok"; -// }else{ -// batteryStatus = "low"; -// } - -// qDebug() << "Temperature:" << temperature << "Battery: " << batteryStatus; - -// if(temperature == lastTemperature){ -// return temperature; -// }else{ -// lastTemperature = temperature; -// QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm");; -// qDebug() << timeStamp; - -// QFile file("/root/temperature_log.ods"); -// file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); -// QTextStream out(&file); - -// out << timeStamp << "," << temperature << "," << batteryStatus << "\n"; -// file.close(); -// } - -// return temperature; -//} - void RadioReciver::enableReceiver() { // check if we have all needed info...pin, freq... diff --git a/hive/server/hive_pi/radio/radioreciver.h b/hive/server/hive_pi/radio/radioreciver.h index 97bbb16c..a63e92a7 100644 --- a/hive/server/hive_pi/radio/radioreciver.h +++ b/hive/server/hive_pi/radio/radioreciver.h @@ -4,6 +4,8 @@ #define RC_MAX_CHANGES 49 #include +#include "radio/plugins/rfthermometer.h" +#include "radio/plugins/rfswitch.h" class ISRHandler; @@ -28,7 +30,6 @@ public: private: void handleInterrupt(); void detectProtocol(QList rawData); - float parseTemperature(QByteArray codeBin); bool m_enable; int m_pin; @@ -39,8 +40,13 @@ private: unsigned long m_lastTime; unsigned int m_repeatCount; + RFThermometer *m_thermometer; + RFSwitch *m_switch; + signals: - + void temperatureSignalReceived(const QByteArray &id, const float &temperature, const bool &batteryStatus); + void switchSignalReceived(const QByteArray &channel, const char &button, const bool &buttonStatus); + public slots: void enableReceiver(); void disableReceiver();