diff --git a/hive/client/client.pro b/hive/client/client.pro new file mode 100644 index 00000000..f6448645 --- /dev/null +++ b/hive/client/client.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs + +CONFIG = ordered + +SUBDIRS += hive_client diff --git a/hive/client/hive_client/hive_client.pro b/hive/client/hive_client/hive_client.pro index 9c02d1d9..feb897fc 100644 --- a/hive/client/hive_client/hive_client.pro +++ b/hive/client/hive_client/hive_client.pro @@ -3,16 +3,19 @@ folder_01.source = qml/hive_client folder_01.target = qml DEPLOYMENTFOLDERS = folder_01 +QT += core qml quick + + # Additional import path used to resolve QML modules in Creator's code model QML_IMPORT_PATH = - # If your application uses the Qt Mobility libraries, uncomment the following # lines and add the respective components to the MOBILITY variable. # CONFIG += mobility # MOBILITY += # The .cpp file which was generated for your project. Feel free to hack it. -SOURCES += main.cpp +SOURCES += main.cpp \ + hiveclientcore.cpp # Installation path # target.path = @@ -20,3 +23,19 @@ SOURCES += main.cpp # Please do not modify the following two lines. Required for deployment. include(qtquick2applicationviewer/qtquick2applicationviewer.pri) qtcAddDeployment() + +HEADERS += \ + hiveclientcore.h + + + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../libhive/release/ -llibhive +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../libhive/debug/ -llibhive +else:unix: LIBS += -L$$OUT_PWD/../../libhive/ -llibhive + +INCLUDEPATH += $$PWD/../../libhive +DEPENDPATH += $$PWD/../../libhive + +win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../libhive/release/libhive.lib +else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../libhive/debug/libhive.lib +else:unix: PRE_TARGETDEPS += $$OUT_PWD/../../libhive/liblibhive.a diff --git a/hive/client/hive_client/hiveclientcore.cpp b/hive/client/hive_client/hiveclientcore.cpp new file mode 100644 index 00000000..05b0da90 --- /dev/null +++ b/hive/client/hive_client/hiveclientcore.cpp @@ -0,0 +1,16 @@ +#include "hiveclientcore.h" +#include +#include +#include + +HiveClientCore::HiveClientCore(QObject *parent) : + QObject(parent) +{ + + m_client = new Client(this); + m_client->connectToHost("10.10.10.40","1234"); + + m_viewer = new QtQuick2ApplicationViewer; + m_viewer->setMainQmlFile(QStringLiteral("qml/hive_client/main.qml")); + m_viewer->showExpanded(); +} diff --git a/hive/client/hive_client/hiveclientcore.h b/hive/client/hive_client/hiveclientcore.h new file mode 100644 index 00000000..269eba43 --- /dev/null +++ b/hive/client/hive_client/hiveclientcore.h @@ -0,0 +1,26 @@ +#ifndef HIVECLIENTCORE_H +#define HIVECLIENTCORE_H + +#include +#include "qtquick2applicationviewer.h" +#include "client.h" + +class HiveClientCore : public QObject +{ + Q_OBJECT +public: + explicit HiveClientCore(QObject *parent = 0); + +private: + Client *m_client; + + + QtQuick2ApplicationViewer *m_viewer; + +signals: + +public slots: + +}; + +#endif // HIVECLIENTCORE_H diff --git a/hive/client/hive_client/main.cpp b/hive/client/hive_client/main.cpp index 3b4b0abf..f3549945 100644 --- a/hive/client/hive_client/main.cpp +++ b/hive/client/hive_client/main.cpp @@ -1,16 +1,13 @@ #include -#include "qtquick2applicationviewer.h" -#include +#include +#include +#include "hiveclientcore.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - //QQmlApplicationEngine engine("qml/hive_client/main.qml"); - - QtQuick2ApplicationViewer viewer; - viewer.setMainQmlFile(QStringLiteral("qml/hive_client/main.qml")); - viewer.showExpanded(); + HiveClientCore core; return app.exec(); } diff --git a/hive/client/hive_client/qml/hive_client/main.qml b/hive/client/hive_client/qml/hive_client/main.qml index c8fe10c9..ec8f31ef 100644 --- a/hive/client/hive_client/qml/hive_client/main.qml +++ b/hive/client/hive_client/qml/hive_client/main.qml @@ -1,16 +1,53 @@ import QtQuick 2.0 import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 +import QtQuick.Window 2.0 -ApplicationWindow{ - id: window +Rectangle{ + id: mainItem + width: 600 height: 360 - statusBar: StatusBar { - RowLayout { - Label { text: "Read Only" } + ColumnLayout { + id: mainLayout + anchors.fill: parent + + GroupBox{ + id: connectionBox + title: "Connection" + anchors.horizontalCenter: parent.horizontalCenter + + RowLayout{ + Button{ + id: connectionButton + text: "Connect" + } + TextInput{ + id: ipText + text: "10.10.10.40" + } + TextInput{ + id: portText + text: "1234" + } + } } } + + + + + StatusBar{ + id: statusBar + width: parent.width + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + + } + + } + + diff --git a/hive/client/hive_client/qml/hive_client/pages/addDevicePage.qml b/hive/client/hive_client/qml/hive_client/pages/addDevicePage.qml new file mode 100644 index 00000000..55c2a4e5 --- /dev/null +++ b/hive/client/hive_client/qml/hive_client/pages/addDevicePage.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.0 +import QtQuick.Layouts 1.0 +import QtQuick.Window 2.0 + +Rectangle{ + +} diff --git a/hive/hive_client.pro b/hive/hive_client.pro new file mode 100644 index 00000000..eccb40d1 --- /dev/null +++ b/hive/hive_client.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +CONFIG = ordered + +SUBDIRS += libhive client diff --git a/hive/libhive/client.cpp b/hive/libhive/client.cpp new file mode 100644 index 00000000..8a8a4776 --- /dev/null +++ b/hive/libhive/client.cpp @@ -0,0 +1,43 @@ +#include "client.h" +#include + +Client::Client(QObject *parent) : + QObject(parent) +{ + m_tcpSocket = new QTcpSocket(this); + + connect(m_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError))); + connect(m_tcpSocket, SIGNAL(connected()),this, SLOT(connectedToHost())); + +} + +void Client::connectionError(QAbstractSocket::SocketError error) +{ + qDebug() << "---> connection error:" << error; +} + +void Client::readData() +{ + +} + +void Client::connectedToHost() +{ + qDebug() << "connected to hive server"; +} + +void Client::connectToHost(QString ipAddress, QString port) +{ + m_tcpSocket->connectToHost(QHostAddress(ipAddress), port.toInt()); +} + +void Client::disconnectFromHost() +{ + m_tcpSocket->close(); + qDebug() << "connection to hive server closed"; +} + +void Client::sendData(QString target, QString command) +{ + +} diff --git a/hive/libhive/client.h b/hive/libhive/client.h new file mode 100644 index 00000000..a4d0d159 --- /dev/null +++ b/hive/libhive/client.h @@ -0,0 +1,34 @@ +#ifndef CLIENT_H +#define CLIENT_H + +#include +#include +#include + +class Client : public QObject +{ + Q_OBJECT + //Q_PROPERTY(QString ipAddress READ ipAddress WRITE setIpAddress NOTIFY ipAddressChanged) + +public: + explicit Client(QObject *parent = 0); + +private: + QTcpSocket *m_tcpSocket; + QString m_tcpBuffer; + + +signals: + +private slots: + void connectionError(QAbstractSocket::SocketError error); + void readData(); + void connectedToHost(); + +public slots: + void connectToHost(QString ipAddress, QString port); + void disconnectFromHost(); + void sendData(QString target, QString command); +}; + +#endif // CLIENT_H diff --git a/hive/libhive/jsonparser.cpp b/hive/libhive/jsonparser.cpp deleted file mode 100644 index cd4669eb..00000000 --- a/hive/libhive/jsonparser.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "jsonparser.h" - -JsonParser::JsonParser(QObject *parent) : - QObject(parent) -{ -} diff --git a/hive/libhive/jsonparser.h b/hive/libhive/jsonparser.h index e0e90269..ac97bf04 100644 --- a/hive/libhive/jsonparser.h +++ b/hive/libhive/jsonparser.h @@ -2,6 +2,7 @@ #define JSONPARSER_H #include +//#include class JsonParser : public QObject { diff --git a/hive/libhive/jsonserializer.cpp b/hive/libhive/jsonserializer.cpp deleted file mode 100644 index 738b324b..00000000 --- a/hive/libhive/jsonserializer.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "jsonserializer.h" - -JsonSerializer::JsonSerializer(QObject *parent) : - QObject(parent) -{ -} diff --git a/hive/libhive/jsonserializer.h b/hive/libhive/jsonserializer.h deleted file mode 100644 index 8218e137..00000000 --- a/hive/libhive/jsonserializer.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef JSONSERIALIZER_H -#define JSONSERIALIZER_H - -#include - -class JsonSerializer : public QObject -{ - Q_OBJECT -public: - explicit JsonSerializer(QObject *parent = 0); - -signals: - -public slots: - -}; - -#endif // JSONSERIALIZER_H diff --git a/hive/libhive/libhive.pro b/hive/libhive/libhive.pro index f5df28b4..0db4bf3d 100644 --- a/hive/libhive/libhive.pro +++ b/hive/libhive/libhive.pro @@ -16,8 +16,7 @@ SOURCES += libhive.cpp \ server.cpp \ devicemanager.cpp \ logwriter.cpp \ - jsonparser.cpp \ - jsonserializer.cpp + client.cpp HEADERS += libhive.h\ libhive_global.h \ @@ -25,7 +24,7 @@ HEADERS += libhive.h\ devicemanager.h \ logwriter.h \ jsonparser.h \ - jsonserializer.h + client.h #unix:!symbian { # maemo5 { diff --git a/hive/libhive/server.cpp b/hive/libhive/server.cpp index 97c8101d..93b4f958 100644 --- a/hive/libhive/server.cpp +++ b/hive/libhive/server.cpp @@ -16,6 +16,33 @@ Server::Server(QObject *parent) : } +void Server::newClientConnected() +{ + // got a new client connected + QTcpServer *server = qobject_cast(sender()); + QTcpSocket *newConnection = server->nextPendingConnection(); + qDebug() << "new client connected:" << newConnection->peerAddress().toString(); + + // append the new client to the client list + m_clientList.append(newConnection); + + connect(newConnection, SIGNAL(readyRead()), SLOT(readPackage())); + connect(newConnection,SIGNAL(disconnected()),this,SLOT(clientDisconnected())); + +} + + +void Server::readPackage() +{ + +} + +void Server::clientDisconnected() +{ + QTcpSocket *client = qobject_cast(sender()); + qDebug() << "client disconnected:" << client->peerAddress().toString(); +} + bool Server::startServer() { // Listen on all Networkinterfaces @@ -23,7 +50,7 @@ bool Server::startServer() QTcpServer *server = new QTcpServer(this); if(server->listen(address, 1234)) { qDebug() << "server listening on" << address.toString(); - connect(server, SIGNAL(newConnection()), SLOT(incomingConnection())); + connect(server, SIGNAL(newConnection()), SLOT(newClientConnected())); m_serverList.append(server); } else { qDebug() << "ERROR: can not listening to" << address.toString(); @@ -50,20 +77,10 @@ bool Server::stopServer() return true; } -void Server::incomingConnection() +void Server::sendToAll(QString data) { - // got a new client connected - QTcpServer *server = qobject_cast(sender()); - QTcpSocket *newConnection = server->nextPendingConnection(); - qDebug() << "new client connected:" << newConnection->peerAddress().toString(); - - // append the new client to the client list - m_clientList.append(newConnection); - - connect(newConnection, SIGNAL(readyRead()), SLOT(readPackage())); + foreach(QTcpSocket *client,m_clientList){ + } } -void Server::readPackage() -{ -} diff --git a/hive/libhive/server.h b/hive/libhive/server.h index 9867f603..f92aaca9 100644 --- a/hive/libhive/server.h +++ b/hive/libhive/server.h @@ -19,13 +19,17 @@ private: signals: +private slots: + void newClientConnected(); + void readPackage(); + void clientDisconnected(); + public slots: bool startServer(); bool stopServer(); + void sendToAll(QString data); -private slots: - void incomingConnection(); - void readPackage(); + }; #endif // SERVER_H diff --git a/hive/server/hive_pi/hivecore.cpp b/hive/server/hive_pi/hivecore.cpp index 824c09d8..ef017d15 100644 --- a/hive/server/hive_pi/hivecore.cpp +++ b/hive/server/hive_pi/hivecore.cpp @@ -8,20 +8,17 @@ HiveCore::HiveCore(QObject *parent) : m_server = new Server(this); m_server->startServer(); - // create Sender + // create 433.92 MHz sender m_sender = new RadioSender(this); m_sender->setFrequency(RadioSender::RF433MHz); - m_sender->setLineCode(RadioSender::THERMOMETER); - m_sender->setPulseLength(250); - m_sender->sendBin("010100101000101111110110"); - m_sender->sendBin("010100101000101111110110"); + 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->enableReceiver(); - m_sender->sendBin("010100101000101111110110"); - } diff --git a/hive/server/hive_pi/radio/radioreciver.cpp b/hive/server/hive_pi/radio/radioreciver.cpp index 919d1a5d..3f44fe08 100644 --- a/hive/server/hive_pi/radio/radioreciver.cpp +++ b/hive/server/hive_pi/radio/radioreciver.cpp @@ -85,10 +85,10 @@ void RadioReciver::detectProtocol(int signalCount) QByteArray binCode; - // __ - // pulse form: | |________ = 0 1100000000 - // __ - // | |________________ = 1 110000000000000000 + // __ + // | |________ = 0 1100000000 + // __ + // | |________________ = 1 110000000000000000 for(int i = 1; i <= 48; i+=2 ){ if(timings[i] < 1000 && timings[i+1] < 3000 && timings[i+1] > 1000){ diff --git a/hive/server/hive_pi/radio/radiosender.h b/hive/server/hive_pi/radio/radiosender.h index aea7d352..dbc91fdc 100644 --- a/hive/server/hive_pi/radio/radiosender.h +++ b/hive/server/hive_pi/radio/radiosender.h @@ -19,7 +19,8 @@ public: MANCHESTER = 0x1, DMANCHESTER = 0x2, REMOTE = 0x4, - THERMOMETER = 0x8 + THERMOMETER = 0x8, + WEATHERSTATION = 0x16 }; @@ -42,7 +43,6 @@ public slots: void setFrequency(Frequency frequency); void setLineCode(LineCode lineCode); void setPulseLength(int pulseLength); - }; #endif // RADIOSENDER_H diff --git a/hive/server/server.pro b/hive/server/server.pro index 8868280b..007500d9 100644 --- a/hive/server/server.pro +++ b/hive/server/server.pro @@ -2,4 +2,6 @@ TEMPLATE = subdirs CONFIG = ordered + + SUBDIRS += hive_pi