lib added devicemanager, working on raspberry pi
This commit is contained in:
parent
d9014bcb8f
commit
f15e495c39
@ -1,3 +1,3 @@
|
|||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
|
|
||||||
SUBDIRS += hive hive_pi
|
SUBDIRS += hive_client
|
||||||
|
|||||||
53
hive/libhive/devicemanager.cpp
Normal file
53
hive/libhive/devicemanager.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "devicemanager.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DeviceManager::DeviceManager(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceManager::saveDeviceValue(QString deviceType, QString deviceName, QString key, QVariant value)
|
||||||
|
{
|
||||||
|
QSettings settings("hive");
|
||||||
|
settings.beginGroup(deviceType);
|
||||||
|
settings.beginGroup(deviceName);
|
||||||
|
settings.setValue(key,value);
|
||||||
|
qDebug() << "safed device value:" << deviceType << "->" << deviceName << "->" << key << ":" << value << ".";
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceManager::deleteDeviceValue(QString deviceType, QString deviceName, QString key)
|
||||||
|
{
|
||||||
|
QSettings settings("hive");
|
||||||
|
settings.beginGroup(deviceType);
|
||||||
|
settings.beginGroup(deviceName);
|
||||||
|
settings.remove(key);
|
||||||
|
qDebug() << "delete key of" << deviceName << key;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceManager::deleteDevice(QString deviceType, QString deviceName)
|
||||||
|
{
|
||||||
|
QSettings settings("hive");
|
||||||
|
settings.beginGroup(deviceType);
|
||||||
|
settings.remove(deviceName);
|
||||||
|
qDebug() << "delete device" << deviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList DeviceManager::getDevices(QString deviceType)
|
||||||
|
{
|
||||||
|
QSettings settings("hive");
|
||||||
|
settings.beginGroup(deviceType);
|
||||||
|
QStringList devices = settings.childGroups();
|
||||||
|
return devices;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList DeviceManager::getDeviceKeys(QString deviceType, QString deviceName)
|
||||||
|
{
|
||||||
|
QSettings settings("hive");
|
||||||
|
settings.beginGroup(deviceType);
|
||||||
|
settings.beginGroup(deviceName);
|
||||||
|
QStringList keys = settings.childKeys();
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
25
hive/libhive/devicemanager.h
Normal file
25
hive/libhive/devicemanager.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef DEVICEMANAGER_H
|
||||||
|
#define DEVICEMANAGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class DeviceManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DeviceManager(QObject *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void saveDeviceValue(QString deviceType, QString deviceName, QString key, QVariant value);
|
||||||
|
void deleteDeviceValue(QString deviceType, QString deviceName, QString key);
|
||||||
|
void deleteDevice(QString deviceType, QString deviceName);
|
||||||
|
QStringList getDevices(QString deviceType);
|
||||||
|
QStringList getDeviceKeys(QString deviceType, QString deviceName);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICEMANAGER_H
|
||||||
1
hive/libhive/libhive.includes
Normal file
1
hive/libhive/libhive.includes
Normal file
@ -0,0 +1 @@
|
|||||||
|
/home/timon/development/hive/hive/libhive
|
||||||
@ -8,21 +8,24 @@ QT += core network
|
|||||||
|
|
||||||
TARGET = libhive
|
TARGET = libhive
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
|
CONFIG += static
|
||||||
|
|
||||||
DEFINES += LIBHIVE_LIBRARY
|
DEFINES += LIBHIVE_LIBRARY
|
||||||
|
|
||||||
SOURCES += libhive.cpp \
|
SOURCES += libhive.cpp \
|
||||||
server.cpp
|
server.cpp \
|
||||||
|
devicemanager.cpp
|
||||||
|
|
||||||
HEADERS += libhive.h\
|
HEADERS += libhive.h\
|
||||||
libhive_global.h \
|
libhive_global.h \
|
||||||
server.h
|
server.h \
|
||||||
|
devicemanager.h
|
||||||
|
|
||||||
unix:!symbian {
|
#unix:!symbian {
|
||||||
maemo5 {
|
# maemo5 {
|
||||||
target.path = /opt/usr/lib
|
# target.path = /opt/usr/lib
|
||||||
} else {
|
# } else {
|
||||||
target.path = /usr/lib
|
# target.path = /usr/lib
|
||||||
}
|
# }
|
||||||
INSTALLS += target
|
# INSTALLS += target
|
||||||
}
|
#}
|
||||||
|
|||||||
@ -14,6 +14,10 @@ Server::Server(QObject *parent) :
|
|||||||
}
|
}
|
||||||
qDebug() << "----------------------------";
|
qDebug() << "----------------------------";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Server::startServer()
|
||||||
|
{
|
||||||
// Listen on all Networkinterfaces
|
// Listen on all Networkinterfaces
|
||||||
foreach(const QHostAddress &address, QNetworkInterface::allAddresses()){
|
foreach(const QHostAddress &address, QNetworkInterface::allAddresses()){
|
||||||
QTcpServer *server = new QTcpServer(this);
|
QTcpServer *server = new QTcpServer(this);
|
||||||
@ -26,6 +30,24 @@ Server::Server(QObject *parent) :
|
|||||||
delete server;
|
delete server;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(m_serverList.empty()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Server::stopServer()
|
||||||
|
{
|
||||||
|
// Listen on all Networkinterfaces
|
||||||
|
foreach(QTcpServer *server, m_serverList){
|
||||||
|
qDebug() << "close server " << server->serverAddress().toString();
|
||||||
|
server->close();
|
||||||
|
delete server;
|
||||||
|
}
|
||||||
|
if(!m_serverList.empty()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::incomingConnection()
|
void Server::incomingConnection()
|
||||||
|
|||||||
@ -20,6 +20,8 @@ private:
|
|||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
bool startServer();
|
||||||
|
bool stopServer();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void incomingConnection();
|
void incomingConnection();
|
||||||
|
|||||||
@ -4,8 +4,7 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
QT += core network
|
QT += core
|
||||||
|
|
||||||
QT -= gui
|
QT -= gui
|
||||||
|
|
||||||
TARGET = hive
|
TARGET = hive
|
||||||
|
|||||||
@ -4,5 +4,5 @@
|
|||||||
HiveCore::HiveCore(QObject *parent) :
|
HiveCore::HiveCore(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
m_server = new Server(this);
|
// m_server = new Server(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#define HIVECORE_H
|
#define HIVECORE_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "server.h"
|
//#include "server.h"
|
||||||
|
|
||||||
class HiveCore : public QObject
|
class HiveCore : public QObject
|
||||||
{
|
{
|
||||||
@ -11,7 +11,7 @@ public:
|
|||||||
explicit HiveCore(QObject *parent = 0);
|
explicit HiveCore(QObject *parent = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Server *m_server;
|
// Server *m_server;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|||||||
@ -15,17 +15,21 @@ CONFIG -= app_bundle
|
|||||||
target.path = /root/bin
|
target.path = /root/bin
|
||||||
INSTALLS += target
|
INSTALLS += target
|
||||||
|
|
||||||
|
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|
||||||
|
|
||||||
|
LIBS += -L$$OUT_PWD/../../libhive/ -llibhive
|
||||||
|
LIBS += -L/home/timon/opt/rasp-pi-rootfs/usr/local/lib -lwiringPi
|
||||||
|
INCLUDEPATH += /home/timon/opt/rasp-pi-rootfs/usr/local/include
|
||||||
|
INCLUDEPATH += $$PWD/../../libhive
|
||||||
|
|
||||||
|
DEPENDPATH += $$PWD/../../libhive
|
||||||
|
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
hivecore.cpp
|
hivecore.cpp \
|
||||||
|
radio/radioreciver.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
hivecore.h
|
hivecore.h \
|
||||||
|
radio/radioreciver.h
|
||||||
|
|
||||||
LIBS += -L$$OUT_PWD/../../libhive/ -llibhive
|
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/../../libhive
|
|
||||||
DEPENDPATH += $$PWD/../../libhive
|
|
||||||
|
|||||||
@ -4,4 +4,33 @@ HiveCore::HiveCore(QObject *parent) :
|
|||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
m_server = new Server(this);
|
m_server = new Server(this);
|
||||||
|
m_server->startServer();
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
#include "devicemanager.h"
|
||||||
|
|
||||||
class HiveCore : public QObject
|
class HiveCore : public QObject
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <hivecore.h>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
HiveCore core;
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
15
hive/server/hive_pi/radio/radioreciver.cpp
Normal file
15
hive/server/hive_pi/radio/radioreciver.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "radioreciver.h"
|
||||||
|
#include "wiringPi.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
RadioReciver::RadioReciver(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
pinMode(2,INPUT);
|
||||||
|
wiringPiISR(2, INT_EDGE_BOTH, &handleInterrupt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RadioReciver::handleInterrupt()
|
||||||
|
{
|
||||||
|
qDebug() << "interrupt";
|
||||||
|
}
|
||||||
21
hive/server/hive_pi/radio/radioreciver.h
Normal file
21
hive/server/hive_pi/radio/radioreciver.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef RADIORECIVER_H
|
||||||
|
#define RADIORECIVER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class RadioReciver : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit RadioReciver(QObject *parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void handleInterrupt();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RADIORECIVER_H
|
||||||
@ -1,3 +1,5 @@
|
|||||||
TEMPLATE = subdirs
|
TEMPLATE = subdirs
|
||||||
|
|
||||||
SUBDIRS += hive hive_pi
|
CONFIG = ordered
|
||||||
|
|
||||||
|
SUBDIRS += hive_pi
|
||||||
|
|||||||
Reference in New Issue
Block a user