RF plugins added and made more stable
played with the client gui
This commit is contained in:
parent
ea11aae5c9
commit
3bf97a7e0d
@ -16,11 +16,13 @@ QML_IMPORT_PATH =
|
|||||||
# The .cpp file which was generated for your project. Feel free to hack it.
|
# The .cpp file which was generated for your project. Feel free to hack it.
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
hiveclientcore.cpp \
|
hiveclientcore.cpp \
|
||||||
settings.cpp
|
settings.cpp \
|
||||||
|
sensormodel.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
hiveclientcore.h \
|
hiveclientcore.h \
|
||||||
settings.h
|
settings.h \
|
||||||
|
sensormodel.h
|
||||||
|
|
||||||
|
|
||||||
# Installation path
|
# Installation path
|
||||||
|
|||||||
@ -7,9 +7,9 @@ HiveClientCore::HiveClientCore(QObject *parent) :
|
|||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
m_id = 0;
|
|
||||||
m_client = new Client(this);
|
m_client = new Client(this);
|
||||||
|
|
||||||
|
|
||||||
// QML Typs
|
// QML Typs
|
||||||
qmlRegisterType<Settings>("hive",1,0,"Settings");
|
qmlRegisterType<Settings>("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);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -20,11 +20,7 @@ private:
|
|||||||
QQmlApplicationEngine *m_engine;
|
QQmlApplicationEngine *m_engine;
|
||||||
QObject *topLevel;
|
QObject *topLevel;
|
||||||
|
|
||||||
int m_id;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onConnected();
|
|
||||||
void sendSomething(QString deviceName, QString method);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include <QtGui/QGuiApplication>
|
#include <QtGui/QGuiApplication>
|
||||||
#include "hiveclientcore.h"
|
#include "hiveclientcore.h"
|
||||||
|
#include "usb.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,26 +5,33 @@ import QtQuick.Layouts 1.0
|
|||||||
Component {
|
Component {
|
||||||
|
|
||||||
Rectangle{
|
Rectangle{
|
||||||
anchors.fill: parent
|
color: "black"
|
||||||
|
|
||||||
ColumnLayout{
|
ColumnLayout{
|
||||||
id: addDeviceColumn
|
id: addDeviceColumn
|
||||||
|
anchors.left: parent.left
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.leftMargin: 30
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 30
|
||||||
GroupBox{
|
GroupBox{
|
||||||
id: nameGroupBox
|
id: nameGroupBox
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
title: "Name"
|
title: "Name"
|
||||||
|
|
||||||
Row{
|
Row{
|
||||||
|
id: row1
|
||||||
spacing: 5
|
spacing: 5
|
||||||
Text{
|
|
||||||
|
Label{
|
||||||
|
id: nameLabel
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
text: "Name:"
|
text: "Name:"
|
||||||
|
color: "white"
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField{
|
TextField{
|
||||||
id: nameText
|
id: nameTextField
|
||||||
|
implicitWidth: 300
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
placeholderText: "Device Name"
|
placeholderText: "Device Name"
|
||||||
}
|
}
|
||||||
@ -33,15 +40,23 @@ Component {
|
|||||||
}
|
}
|
||||||
GroupBox{
|
GroupBox{
|
||||||
id: deviceTypeGroupBox
|
id: deviceTypeGroupBox
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 0
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 0
|
||||||
title: "Device Type"
|
title: "Device Type"
|
||||||
|
|
||||||
ComboBox {
|
ComboBox {
|
||||||
id: deviceComboBox
|
id: deviceComboBox
|
||||||
model: ["actor","sensor"]
|
model: ["device","actor","sensor"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GroupBox{
|
GroupBox{
|
||||||
id: communicationTypeGroupBox
|
id: communicationTypeGroupBox
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 0
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 0
|
||||||
title: "Communication Type"
|
title: "Communication Type"
|
||||||
|
|
||||||
ComboBox {
|
ComboBox {
|
||||||
@ -51,6 +66,10 @@ Component {
|
|||||||
}
|
}
|
||||||
GroupBox{
|
GroupBox{
|
||||||
id: linecodeGroupBox
|
id: linecodeGroupBox
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 0
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 0
|
||||||
title: "Linecode"
|
title: "Linecode"
|
||||||
visible: communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433" ? true : false
|
visible: communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433" ? true : false
|
||||||
|
|
||||||
@ -61,29 +80,35 @@ Component {
|
|||||||
}
|
}
|
||||||
GroupBox{
|
GroupBox{
|
||||||
id: switchGroupBox
|
id: switchGroupBox
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 0
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: 0
|
||||||
title: "Switchsettings"
|
title: "Switchsettings"
|
||||||
visible: (linecodeComboBox.currentText == "Switch") && (communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433") ? true : false
|
visible: (linecodeComboBox.currentText == "Switch") && (communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433") ? true : false
|
||||||
|
|
||||||
RowLayout{
|
RowLayout{
|
||||||
GridLayout{
|
GridLayout{
|
||||||
columns: 6
|
columns: 5
|
||||||
Label{
|
Label{
|
||||||
text: "1"
|
text: "1"
|
||||||
|
color: "white"
|
||||||
}
|
}
|
||||||
Label{
|
Label{
|
||||||
text: "2"
|
text: "2"
|
||||||
|
color: "white"
|
||||||
}
|
}
|
||||||
Label{
|
Label{
|
||||||
text: "3"
|
text: "3"
|
||||||
|
color: "white"
|
||||||
}
|
}
|
||||||
Label{
|
Label{
|
||||||
text: "4"
|
text: "4"
|
||||||
|
color: "white"
|
||||||
}
|
}
|
||||||
Label{
|
Label{
|
||||||
text: "5"
|
text: "5"
|
||||||
}
|
color: "white"
|
||||||
Label{
|
|
||||||
text: "6"
|
|
||||||
}
|
}
|
||||||
CheckBox{
|
CheckBox{
|
||||||
id: channel1
|
id: channel1
|
||||||
@ -100,9 +125,6 @@ Component {
|
|||||||
CheckBox{
|
CheckBox{
|
||||||
id: channel5
|
id: channel5
|
||||||
}
|
}
|
||||||
CheckBox{
|
|
||||||
id: channel6
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ComboBox {
|
ComboBox {
|
||||||
id: switchComboBox
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,8 @@ import QtQuick.Layouts 1.0
|
|||||||
|
|
||||||
Component {
|
Component {
|
||||||
Rectangle{
|
Rectangle{
|
||||||
anchors.fill: parent
|
focus: connectButton.forceActiveFocus()
|
||||||
|
color: "black"
|
||||||
|
|
||||||
GroupBox {
|
GroupBox {
|
||||||
id: connectionGroupBox
|
id: connectionGroupBox
|
||||||
@ -26,6 +27,7 @@ Component {
|
|||||||
Text {
|
Text {
|
||||||
id: ipLable
|
id: ipLable
|
||||||
text: "IP:"
|
text: "IP:"
|
||||||
|
color: "white"
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
}
|
}
|
||||||
TextField {
|
TextField {
|
||||||
@ -37,6 +39,7 @@ Component {
|
|||||||
Text {
|
Text {
|
||||||
id: portLable
|
id: portLable
|
||||||
text: "Port:"
|
text: "Port:"
|
||||||
|
color: "white"
|
||||||
wrapMode: Text.NoWrap
|
wrapMode: Text.NoWrap
|
||||||
verticalAlignment: Text.AlignTop
|
verticalAlignment: Text.AlignTop
|
||||||
horizontalAlignment: Text.AlignHCenter
|
horizontalAlignment: Text.AlignHCenter
|
||||||
@ -49,5 +52,6 @@ Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
89
hive/client/hive_client/qml/hive_client/MainMenuButton.qml
Normal file
89
hive/client/hive_client/qml/hive_client/MainMenuButton.qml
Normal file
@ -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()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
@ -5,39 +5,27 @@ import QtQuick.Layouts 1.0
|
|||||||
Component {
|
Component {
|
||||||
|
|
||||||
Rectangle{
|
Rectangle{
|
||||||
anchors.fill: parent
|
color: "black"
|
||||||
|
|
||||||
Column{
|
Column{
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.topMargin: 30
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
29
hive/client/hive_client/qml/hive_client/SensorField.qml
Normal file
29
hive/client/hive_client/qml/hive_client/SensorField.qml
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
63
hive/client/hive_client/qml/hive_client/TemperaturePage.qml
Normal file
63
hive/client/hive_client/qml/hive_client/TemperaturePage.qml
Normal file
@ -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)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,8 +29,9 @@ ApplicationWindow{
|
|||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
}
|
}
|
||||||
title: "Hive Client"
|
title: "Hive Client"
|
||||||
width: 600
|
minimumWidth: 800
|
||||||
height: 500
|
minimumHeight: 600
|
||||||
|
|
||||||
|
|
||||||
StackView {
|
StackView {
|
||||||
id: stackView
|
id: stackView
|
||||||
@ -66,6 +67,10 @@ ApplicationWindow{
|
|||||||
AddDevicePage{
|
AddDevicePage{
|
||||||
id: addDevicePage
|
id: addDevicePage
|
||||||
}
|
}
|
||||||
|
TemperaturePage{
|
||||||
|
id: temperaturPage
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
hive/client/hive_client/sensormodel.cpp
Normal file
6
hive/client/hive_client/sensormodel.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "sensormodel.h"
|
||||||
|
|
||||||
|
SensorModel::SensorModel(QObject *parent) :
|
||||||
|
QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
23
hive/client/hive_client/sensormodel.h
Normal file
23
hive/client/hive_client/sensormodel.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef SENSORMODEL_H
|
||||||
|
#define SENSORMODEL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
class SensorModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit SensorModel(QObject *parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SENSORMODEL_H
|
||||||
@ -29,8 +29,7 @@ void Client::readData()
|
|||||||
QByteArray dataLine = m_tcpSocket->readLine();
|
QByteArray dataLine = m_tcpSocket->readLine();
|
||||||
message.append(dataLine);
|
message.append(dataLine);
|
||||||
if(dataLine == "}\n"){
|
if(dataLine == "}\n"){
|
||||||
emit jsonDataAvailable(message);
|
emit dataAvailable(message);
|
||||||
message.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,6 +48,61 @@ void Client::disconneted()
|
|||||||
emit connectionChanged();
|
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)
|
void Client::connectToHost(QString ipAddress, QString port)
|
||||||
{
|
{
|
||||||
qDebug() << "connecting to" << ipAddress << ":" << port;
|
qDebug() << "connecting to" << ipAddress << ":" << port;
|
||||||
|
|||||||
@ -13,18 +13,27 @@ class Client : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Client(QObject *parent = 0);
|
explicit Client(QObject *parent = 0);
|
||||||
bool isConnected();
|
|
||||||
|
|
||||||
|
enum Request {
|
||||||
|
RequestAddDevice,
|
||||||
|
RequestEditDevice,
|
||||||
|
RequestRemoveDevice
|
||||||
|
};
|
||||||
|
|
||||||
|
bool isConnected();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTcpSocket *m_tcpSocket;
|
QTcpSocket *m_tcpSocket;
|
||||||
QString m_tcpBuffer;
|
QString m_tcpBuffer;
|
||||||
|
|
||||||
bool m_connectionStatus;
|
bool m_connectionStatus;
|
||||||
|
int m_commandId;
|
||||||
|
|
||||||
|
QMap<int, Request> m_requestMap;
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void jsonDataAvailable(const QByteArray &data);
|
void dataAvailable(const QByteArray &data);
|
||||||
void connectionChanged();
|
void connectionChanged();
|
||||||
|
|
||||||
|
|
||||||
@ -34,6 +43,11 @@ private slots:
|
|||||||
void connected();
|
void connected();
|
||||||
void disconneted();
|
void disconneted();
|
||||||
|
|
||||||
|
void processData(const QByteArray &data);
|
||||||
|
void handleResponse(const QVariantMap &rsp);
|
||||||
|
void handleSignal(const QVariantMap &signal);
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void connectToHost(QString ipAddress, QString port);
|
void connectToHost(QString ipAddress, QString port);
|
||||||
void disconnectFromHost();
|
void disconnectFromHost();
|
||||||
|
|||||||
@ -12,6 +12,8 @@ class JsonHandler : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit JsonHandler(QObject *parent = 0);
|
explicit JsonHandler(QObject *parent = 0);
|
||||||
|
QByteArray addRemote(QString deviceType, QString method, QString name, QString protocol, QString Linecode, QString m);
|
||||||
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void notifyAll(const QByteArray &data);
|
void notifyAll(const QByteArray &data);
|
||||||
@ -23,7 +25,6 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
DeviceJsonPlugin *m_device;
|
DeviceJsonPlugin *m_device;
|
||||||
|
|
||||||
|
|
||||||
QByteArray formatResponse(const QVariantMap &command, const QVariantMap &responseParams);
|
QByteArray formatResponse(const QVariantMap &command, const QVariantMap &responseParams);
|
||||||
QByteArray formatErrorResponse(const QVariantMap &command, const QString &error);
|
QByteArray formatErrorResponse(const QVariantMap &command, const QString &error);
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ class JsonPlugin : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit JsonPlugin(QObject *parent = 0);
|
explicit JsonPlugin(QObject *parent = 0);
|
||||||
//virtual ~JsonPlugin();
|
virtual ~JsonPlugin(){}
|
||||||
virtual QString deviceName() = 0;
|
virtual QString deviceName() = 0;
|
||||||
virtual QByteArray process(const QVariantMap & command, const QVariantMap & parameters) = 0;
|
virtual QByteArray process(const QVariantMap & command, const QVariantMap & parameters) = 0;
|
||||||
|
|
||||||
|
|||||||
@ -29,10 +29,16 @@ DEPENDPATH += $$PWD/../../libhive
|
|||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
hivecore.cpp \
|
hivecore.cpp \
|
||||||
radio/radioreciver.cpp \
|
radio/radioreciver.cpp \
|
||||||
radio/radiosender.cpp
|
radio/radiosender.cpp \
|
||||||
|
radio/plugins/radioplugin.cpp \
|
||||||
|
radio/plugins/rfthermometer.cpp \
|
||||||
|
radio/plugins/rfswitch.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
hivecore.h \
|
hivecore.h \
|
||||||
radio/radioreciver.h \
|
radio/radioreciver.h \
|
||||||
radio/radiosender.h
|
radio/radiosender.h \
|
||||||
|
radio/plugins/radioplugin.h \
|
||||||
|
radio/plugins/rfthermometer.h \
|
||||||
|
radio/plugins/rfswitch.h
|
||||||
|
|
||||||
|
|||||||
@ -18,16 +18,16 @@ HiveCore::HiveCore(QObject *parent) :
|
|||||||
|
|
||||||
|
|
||||||
// // create 433.92 MHz sender
|
// // create 433.92 MHz sender
|
||||||
// m_sender = new RadioSender(this);
|
m_sender = new RadioSender(this);
|
||||||
// m_sender->setFrequency(RadioSender::RF433MHz);
|
m_sender->setFrequency(RadioSender::RF433MHz);
|
||||||
// m_sender->setLineCode(RadioSender::REMOTE);
|
m_sender->setLineCode(RadioSender::REMOTE);
|
||||||
// m_sender->setPulseLength(320);
|
m_sender->setPulseLength(320);
|
||||||
// //m_sender->sendBin("000000000000010101010001");
|
// //m_sender->sendBin("000000000000010101010001");
|
||||||
|
|
||||||
// // create 433.92 MHz receiver
|
// create 433.92 MHz receiver
|
||||||
// m_reciver = new RadioReciver(this);
|
m_reciver = new RadioReciver(this);
|
||||||
// m_reciver->setFrequency(RadioReciver::RF433MHz);
|
m_reciver->setFrequency(RadioReciver::RF433MHz);
|
||||||
// m_reciver->setPin(2);
|
m_reciver->setPin(2);
|
||||||
// m_reciver->enableReceiver();
|
m_reciver->enableReceiver();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,8 +16,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Server *m_server;
|
Server *m_server;
|
||||||
//RadioReciver *m_reciver;
|
RadioReciver *m_reciver;
|
||||||
//RadioSender *m_sender;
|
RadioSender *m_sender;
|
||||||
DeviceManager *m_deviceManager;
|
DeviceManager *m_deviceManager;
|
||||||
JsonHandler *m_jsonHandler;
|
JsonHandler *m_jsonHandler;
|
||||||
|
|
||||||
|
|||||||
6
hive/server/hive_pi/radio/plugins/radioplugin.cpp
Normal file
6
hive/server/hive_pi/radio/plugins/radioplugin.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "radioplugin.h"
|
||||||
|
|
||||||
|
RadioPlugin::RadioPlugin(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
18
hive/server/hive_pi/radio/plugins/radioplugin.h
Normal file
18
hive/server/hive_pi/radio/plugins/radioplugin.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef RADIOPLUGIN_H
|
||||||
|
#define RADIOPLUGIN_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class RadioPlugin : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit RadioPlugin(QObject *parent = 0);
|
||||||
|
virtual ~RadioPlugin(){}
|
||||||
|
|
||||||
|
virtual bool isValid(QList<int> rawData) = 0;
|
||||||
|
virtual QByteArray getBinCode() = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RADIOPLUGIN_H
|
||||||
118
hive/server/hive_pi/radio/plugins/rfswitch.cpp
Normal file
118
hive/server/hive_pi/radio/plugins/rfswitch.cpp
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
#include <QDebug>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
#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<int> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
26
hive/server/hive_pi/radio/plugins/rfswitch.h
Normal file
26
hive/server/hive_pi/radio/plugins/rfswitch.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef RFSWITCH_H
|
||||||
|
#define RFSWITCH_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <radio/plugins/radioplugin.h>
|
||||||
|
|
||||||
|
#define RFSwitchDelay 320
|
||||||
|
|
||||||
|
class RFSwitch : public RadioPlugin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit RFSwitch(QObject *parent = 0);
|
||||||
|
|
||||||
|
QByteArray getBinCode();
|
||||||
|
bool isValid(QList<int> rawData);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_delay;
|
||||||
|
QByteArray m_binCode;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void switchSignalReceived(const QByteArray &channel, const char &button, const bool &buttonStatus);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RFSWITCH_H
|
||||||
122
hive/server/hive_pi/radio/plugins/rfthermometer.cpp
Normal file
122
hive/server/hive_pi/radio/plugins/rfthermometer.cpp
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
#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<int> 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<QByteArray> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
hive/server/hive_pi/radio/plugins/rfthermometer.h
Normal file
31
hive/server/hive_pi/radio/plugins/rfthermometer.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef RFTHERMOMETER_H
|
||||||
|
#define RFTHERMOMETER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <radio/plugins/radioplugin.h>
|
||||||
|
|
||||||
|
#define RFThermometerDelay 250
|
||||||
|
|
||||||
|
class RFThermometer : public RadioPlugin
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit RFThermometer(QObject *parent = 0);
|
||||||
|
|
||||||
|
QByteArray getBinCode();
|
||||||
|
bool isValid(QList<int> 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
|
||||||
@ -1,12 +1,10 @@
|
|||||||
#include "radioreciver.h"
|
|
||||||
#include "wiringPi.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
||||||
static float lastTemperature = 0;
|
#include "radioreciver.h"
|
||||||
|
#include "wiringPi.h"
|
||||||
|
|
||||||
|
|
||||||
// #####################################################################################################
|
// #####################################################################################################
|
||||||
@ -109,6 +107,9 @@ RadioReciver::RadioReciver(QObject *parent) :
|
|||||||
m_lastTime = 0;
|
m_lastTime = 0;
|
||||||
m_repeatCount = 0;
|
m_repeatCount = 0;
|
||||||
|
|
||||||
|
m_thermometer = new RFThermometer(this);
|
||||||
|
m_switch = new RFSwitch(this);
|
||||||
|
|
||||||
for(int i = 0; i < RC_MAX_CHANGES; i++ ){
|
for(int i = 0; i < RC_MAX_CHANGES; i++ ){
|
||||||
m_timings[i] = 0;
|
m_timings[i] = 0;
|
||||||
}
|
}
|
||||||
@ -178,212 +179,20 @@ void RadioReciver::handleInterrupt()
|
|||||||
|
|
||||||
void RadioReciver::detectProtocol(QList<int> rawData)
|
void RadioReciver::detectProtocol(QList<int> rawData)
|
||||||
{
|
{
|
||||||
qDebug() << "===========================================================================";
|
// check if we have a valid signal, 1 sync + 48 data
|
||||||
qDebug() <<"VALID SIGNAL (48 bit)" << " --> pulse width =" << rawData.first()/31;
|
if(rawData.length() != 49){
|
||||||
qDebug() << rawData;
|
return;
|
||||||
|
}
|
||||||
// int pulseWidth = rawData.first()/31;
|
// check plugins
|
||||||
|
if(m_thermometer->isValid(rawData)){
|
||||||
// QList<int> rawDataKGV;
|
m_thermometer->getTemperature();
|
||||||
// foreach (int timing, rawData){
|
}
|
||||||
// int kgv = ((float)timing/pulseWidth)+0.5;
|
if(m_switch->isValid(rawData)){
|
||||||
// rawDataKGV.append(kgv);
|
m_switch->getBinCode();
|
||||||
// }
|
}
|
||||||
// qDebug() << "-------= " << rawDataKGV;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//void RadioReciver::detectProtocol(int signalCount)
|
|
||||||
//{
|
|
||||||
// if(signalCount < 49){
|
|
||||||
// //qDebug() << "ERROR: got a signal with just" << signalCount << "signals";
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// qDebug() << "===========================================================================";
|
|
||||||
// QList <int> 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 <int> 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 <int> 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<QByteArray> 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()
|
void RadioReciver::enableReceiver()
|
||||||
{
|
{
|
||||||
// check if we have all needed info...pin, freq...
|
// check if we have all needed info...pin, freq...
|
||||||
|
|||||||
@ -4,6 +4,8 @@
|
|||||||
#define RC_MAX_CHANGES 49
|
#define RC_MAX_CHANGES 49
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include "radio/plugins/rfthermometer.h"
|
||||||
|
#include "radio/plugins/rfswitch.h"
|
||||||
|
|
||||||
class ISRHandler;
|
class ISRHandler;
|
||||||
|
|
||||||
@ -28,7 +30,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
void handleInterrupt();
|
void handleInterrupt();
|
||||||
void detectProtocol(QList<int> rawData);
|
void detectProtocol(QList<int> rawData);
|
||||||
float parseTemperature(QByteArray codeBin);
|
|
||||||
|
|
||||||
bool m_enable;
|
bool m_enable;
|
||||||
int m_pin;
|
int m_pin;
|
||||||
@ -39,7 +40,12 @@ private:
|
|||||||
unsigned long m_lastTime;
|
unsigned long m_lastTime;
|
||||||
unsigned int m_repeatCount;
|
unsigned int m_repeatCount;
|
||||||
|
|
||||||
|
RFThermometer *m_thermometer;
|
||||||
|
RFSwitch *m_switch;
|
||||||
|
|
||||||
signals:
|
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:
|
public slots:
|
||||||
void enableReceiver();
|
void enableReceiver();
|
||||||
|
|||||||
Reference in New Issue
Block a user