rc 433 receiver working
lib added logWriter
This commit is contained in:
parent
f15e495c39
commit
42027c8cd0
@ -1,3 +1,4 @@
|
||||
TEMPLATE = subdirs
|
||||
CONFIG = ordered
|
||||
|
||||
SUBDIRS += hive_client
|
||||
|
||||
@ -1,16 +1,23 @@
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Layouts 1.0
|
||||
|
||||
Rectangle {
|
||||
width: 360
|
||||
id: mainWindow
|
||||
//title: "Hive Client"
|
||||
width: 500
|
||||
height: 360
|
||||
Text {
|
||||
text: qsTr("Hello World")
|
||||
color: "#776262"
|
||||
|
||||
RowLayout{
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
Qt.quit();
|
||||
Button{
|
||||
text: "Button 1"
|
||||
}
|
||||
Button{
|
||||
text: "Button 1"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -14,12 +14,14 @@ DEFINES += LIBHIVE_LIBRARY
|
||||
|
||||
SOURCES += libhive.cpp \
|
||||
server.cpp \
|
||||
devicemanager.cpp
|
||||
devicemanager.cpp \
|
||||
logwriter.cpp
|
||||
|
||||
HEADERS += libhive.h\
|
||||
libhive_global.h \
|
||||
server.h \
|
||||
devicemanager.h
|
||||
devicemanager.h \
|
||||
logwriter.h
|
||||
|
||||
#unix:!symbian {
|
||||
# maemo5 {
|
||||
|
||||
16
hive/libhive/logwriter.cpp
Normal file
16
hive/libhive/logwriter.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "logwriter.h"
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
||||
LogWriter::LogWriter(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void LogWriter::write(LogWriter::MessageType messageType, QString logMessage)
|
||||
{
|
||||
QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm");;
|
||||
qDebug() << timeStamp;
|
||||
|
||||
|
||||
}
|
||||
26
hive/libhive/logwriter.h
Normal file
26
hive/libhive/logwriter.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef LOGWRITER_H
|
||||
#define LOGWRITER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
|
||||
class LogWriter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LogWriter(QObject *parent = 0);
|
||||
enum MessageType{
|
||||
INFO = 0x1,
|
||||
ERROR = 0x2
|
||||
};
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void write(MessageType messageType, QString logMessage);
|
||||
|
||||
};
|
||||
|
||||
#endif // LOGWRITER_H
|
||||
@ -19,7 +19,8 @@ TEMPLATE = app
|
||||
|
||||
|
||||
LIBS += -L$$OUT_PWD/../../libhive/ -llibhive
|
||||
LIBS += -L/home/timon/opt/rasp-pi-rootfs/usr/local/lib -lwiringPi
|
||||
LIBS += -L$$RPI_SYSROOT/usr/local/lib -lwiringPi
|
||||
|
||||
INCLUDEPATH += /home/timon/opt/rasp-pi-rootfs/usr/local/include
|
||||
INCLUDEPATH += $$PWD/../../libhive
|
||||
|
||||
@ -27,9 +28,11 @@ DEPENDPATH += $$PWD/../../libhive
|
||||
|
||||
SOURCES += main.cpp \
|
||||
hivecore.cpp \
|
||||
radio/radioreciver.cpp
|
||||
radio/radioreciver.cpp \
|
||||
radio/radiosender.cpp
|
||||
|
||||
HEADERS += \
|
||||
hivecore.h \
|
||||
radio/radioreciver.h
|
||||
radio/radioreciver.h \
|
||||
radio/radiosender.h
|
||||
|
||||
|
||||
@ -1,36 +1,19 @@
|
||||
#include "hivecore.h"
|
||||
#include <QDebug>
|
||||
|
||||
HiveCore::HiveCore(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
// start the server
|
||||
m_server = new Server(this);
|
||||
m_server->startServer();
|
||||
|
||||
m_sender = new RadioSender(this);
|
||||
|
||||
m_reciver = new RadioReciver(this);
|
||||
m_reciver->setFrequence(RadioReciver::RC433MHz);
|
||||
m_reciver->enableReceiver();
|
||||
|
||||
DeviceManager deviceManager;
|
||||
deviceManager.saveDeviceValue("sensor","light","A-ON",1361);
|
||||
deviceManager.saveDeviceValue("sensor","light","A-OFF",1364);
|
||||
deviceManager.saveDeviceValue("sensor","light","B-ON",4433);
|
||||
deviceManager.saveDeviceValue("sensor","light","B-OFF",4436);
|
||||
deviceManager.saveDeviceValue("sensor","light","C-ON",5393);
|
||||
deviceManager.saveDeviceValue("sensor","light","C-OFF",5204);
|
||||
deviceManager.saveDeviceValue("sensor","light","D-ON",5393);
|
||||
deviceManager.saveDeviceValue("sensor","light","D-OFF",5396);
|
||||
deviceManager.saveDeviceValue("sensor","weatherStation","temperature",20);
|
||||
deviceManager.saveDeviceValue("sensor","weatherStation","humidity",20);
|
||||
|
||||
|
||||
deviceManager.saveDeviceValue("actor","window","open",true);
|
||||
deviceManager.saveDeviceValue("actor","door","open",false);
|
||||
|
||||
qDebug() << "get sensors" << deviceManager.getDevices("sensor");
|
||||
qDebug() << "get actors" << deviceManager.getDevices("actor");
|
||||
qDebug() << "get light keys" << deviceManager.getDeviceKeys("sensor","light");
|
||||
qDebug() << "get weatherStation keys" << deviceManager.getDeviceKeys("sensor","weatherStation");
|
||||
|
||||
deviceManager.deleteDeviceValue("sensor","light","C-OFF");
|
||||
qDebug() << "get light keys" << deviceManager.getDeviceKeys("sensor","light");
|
||||
deviceManager.deleteDevice("sensor","weatherStation");
|
||||
qDebug() << "get sensors" << deviceManager.getDevices("sensor");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
#include <QObject>
|
||||
#include "server.h"
|
||||
#include "devicemanager.h"
|
||||
#include "radio/radioreciver.h"
|
||||
#include "radio/radiosender.h"
|
||||
|
||||
class HiveCore : public QObject
|
||||
{
|
||||
@ -13,7 +15,8 @@ public:
|
||||
|
||||
private:
|
||||
Server *m_server;
|
||||
|
||||
RadioReciver *m_reciver;
|
||||
RadioSender *m_sender;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
@ -1,15 +1,201 @@
|
||||
#include "radioreciver.h"
|
||||
#include "wiringPi.h"
|
||||
#include <stdio.h>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
||||
static bool m_enable = false;
|
||||
static unsigned int timings[RC_MAX_CHANGES];
|
||||
static unsigned long m_receivedValue;
|
||||
static unsigned int m_receivedBitlength;
|
||||
static unsigned int m_receivedDelay;
|
||||
static unsigned int m_receiveToleranceThermometer;
|
||||
static unsigned int m_receiveToleranceRemote;
|
||||
|
||||
RadioReciver::RadioReciver(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
pinMode(2,INPUT);
|
||||
wiringPiISR(2, INT_EDGE_BOTH, &handleInterrupt);
|
||||
m_receivedBitlength = 0;
|
||||
m_receivedDelay = 0;
|
||||
m_receivedValue = 0;
|
||||
m_receiveToleranceThermometer = 10;
|
||||
m_receiveToleranceRemote = 60;
|
||||
}
|
||||
|
||||
void RadioReciver::handleInterrupt()
|
||||
{
|
||||
qDebug() << "interrupt";
|
||||
if(!m_enable){
|
||||
return;
|
||||
}
|
||||
|
||||
static unsigned int duration;
|
||||
static unsigned int changeCount;
|
||||
static unsigned long lastTime;
|
||||
static unsigned int repeatCount;
|
||||
|
||||
long time = micros();
|
||||
duration = time - lastTime;
|
||||
|
||||
// filter nois
|
||||
if (duration > 5000 && duration > timings[0] - 200 && duration < timings[0] + 200) {
|
||||
repeatCount++;
|
||||
changeCount--;
|
||||
//qDebug() << "change count" << changeCount;
|
||||
|
||||
if(repeatCount == 2) {
|
||||
//qDebug() << "got a pulse with pulselength:" << duration;
|
||||
detectProtocol(changeCount);
|
||||
|
||||
for(int i = 0; i < RC_MAX_CHANGES; i++ ){
|
||||
timings[i] = 0;
|
||||
}
|
||||
|
||||
repeatCount = 0;
|
||||
}
|
||||
changeCount = 0;
|
||||
|
||||
}else if(duration > 5000){
|
||||
changeCount = 0;
|
||||
}
|
||||
if (changeCount >= RC_MAX_CHANGES) {
|
||||
changeCount = 0;
|
||||
repeatCount = 0;
|
||||
}
|
||||
timings[changeCount++] = duration;
|
||||
lastTime = time;
|
||||
}
|
||||
|
||||
void RadioReciver::detectProtocol(int signalCount)
|
||||
{
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
//qDebug() << "detect protocoll";
|
||||
unsigned long delay = timings[0] / 31;
|
||||
//qDebug() << "delay:" << delay;
|
||||
|
||||
// #########################################################################
|
||||
// if(delay > 250 && delay < 260){
|
||||
|
||||
// QFile file("/root/data.ods");
|
||||
// file.open(QIODevice::WriteOnly | QIODevice::Text);
|
||||
|
||||
// for(int i = 0; i <= 48; i++){
|
||||
// //file.write << timings[i] << ";\n";
|
||||
// }
|
||||
|
||||
// file.close();
|
||||
// qDebug() << "-------> got TERMOMETER signal";
|
||||
|
||||
// QString code = 0;
|
||||
|
||||
// unsigned long delayTolerance = delay * m_receiveToleranceThermometer * 0.01;
|
||||
// qDebug() << "delay:" << delay << "=" << timings[0] << "/31" << " delayTolerance = " << delayTolerance << " , signals = " << changeCount;
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
// #########################################################################
|
||||
if(delay > 310 && delay < 320){
|
||||
|
||||
qDebug() << "-------> got REMOTE Signal";
|
||||
qDebug() << "delay:" << delay << " bits = " << signalCount-1;
|
||||
|
||||
QString 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
|
||||
// _
|
||||
// if we have ___| | = 1 -> in 4 delays
|
||||
|
||||
if(div == 1 && divNext == 3){
|
||||
binCode.append("0");
|
||||
}else if(div == 3 && divNext == 1){
|
||||
binCode.append("1");
|
||||
}else{
|
||||
//qDebug() << "could not read code...error in transmission";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
qDebug() << "raw data:" << rawData;
|
||||
qDebug() << "bin CODE:" << binCode;
|
||||
qDebug() << "dec CODE:" << binCode;
|
||||
qDebug() << "hex CODE:" << binCode;
|
||||
|
||||
}else{
|
||||
// #########################################################################
|
||||
qDebug() << "-------> got GENERIC Signal";
|
||||
|
||||
unsigned long delayTolerance = delay * m_receiveToleranceRemote * 0.01;
|
||||
qDebug() << "delay:" << delay << " bits = " << signalCount-1;
|
||||
|
||||
QString binCode;
|
||||
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] << ",";
|
||||
}
|
||||
out << ";\n";
|
||||
file.close();
|
||||
|
||||
// go trough all 48 timings
|
||||
for(int i = 0; i <= 48; i+=1 ){
|
||||
rawData.append(timings[i]);
|
||||
rawData.append(timings[i+1]);
|
||||
}
|
||||
|
||||
qDebug() << "raw data:" << rawData;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void RadioReciver::enableReceiver()
|
||||
{
|
||||
m_enable = true;
|
||||
}
|
||||
|
||||
void RadioReciver::disableReceiver()
|
||||
{
|
||||
m_enable = false;
|
||||
}
|
||||
|
||||
void RadioReciver::setFrequence(RadioReciver::Frequenze frequenze)
|
||||
{
|
||||
if(frequenze == RadioReciver::RC433MHz){
|
||||
if(wiringPiSetup() == -1){
|
||||
qDebug() << "ERROR: GPIO setup failed.";
|
||||
}
|
||||
qDebug() << "GPIO setup ok.";
|
||||
pinMode(2,INPUT);
|
||||
wiringPiISR(2, INT_EDGE_BOTH, &handleInterrupt);
|
||||
}
|
||||
if(frequenze == RadioReciver::RC868MHz){
|
||||
qDebug() << "ERROR: 868 MHz Module not connected yet";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#ifndef RADIORECIVER_H
|
||||
#define RADIORECIVER_H
|
||||
|
||||
#define RC_MAX_CHANGES 50
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class RadioReciver : public QObject
|
||||
@ -9,12 +11,22 @@ class RadioReciver : public QObject
|
||||
public:
|
||||
explicit RadioReciver(QObject *parent = 0);
|
||||
|
||||
enum Frequenze{
|
||||
RC433MHz = 0x0,
|
||||
RC868MHz = 0x1
|
||||
};
|
||||
|
||||
private:
|
||||
static void handleInterrupt();
|
||||
static void detectProtocol(int signalCount);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void enableReceiver();
|
||||
void disableReceiver();
|
||||
void setFrequence(Frequenze frequenze);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
39
hive/server/hive_pi/radio/radiosender.cpp
Normal file
39
hive/server/hive_pi/radio/radiosender.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "radiosender.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include "wiringPi.h"
|
||||
|
||||
RadioSender::RadioSender(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
m_pulseLength = 350;
|
||||
|
||||
}
|
||||
|
||||
void RadioSender::sendSync()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RadioSender::transmit(int high, int low)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void RadioSender::sendBin(QString codeBin)
|
||||
{
|
||||
|
||||
if(wiringPiSetup() == -1){
|
||||
qDebug() << "ERROR: GPIO setup failed.";
|
||||
}
|
||||
qDebug() << "GPIO setup ok.";
|
||||
pinMode(0,OUTPUT);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void RadioSender::setPulseLength(int pulseLength)
|
||||
{
|
||||
m_pulseLength = pulseLength;
|
||||
}
|
||||
27
hive/server/hive_pi/radio/radiosender.h
Normal file
27
hive/server/hive_pi/radio/radiosender.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef RADIOSENDER_H
|
||||
#define RADIOSENDER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class RadioSender : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RadioSender(QObject *parent = 0);
|
||||
|
||||
private:
|
||||
// [us]
|
||||
int m_pulseLength;
|
||||
|
||||
void sendSync();
|
||||
void transmit(int high, int low);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void sendBin(QString codeBin);
|
||||
void setPulseLength(int pulseLength);
|
||||
|
||||
};
|
||||
|
||||
#endif // RADIOSENDER_H
|
||||
Reference in New Issue
Block a user