client added, connection over tcp works
to do now: communication protocoll for json
This commit is contained in:
parent
6aca4fd108
commit
59c1157e57
5
hive/client/client.pro
Normal file
5
hive/client/client.pro
Normal file
@ -0,0 +1,5 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
CONFIG = ordered
|
||||
|
||||
SUBDIRS += hive_client
|
||||
@ -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
|
||||
|
||||
16
hive/client/hive_client/hiveclientcore.cpp
Normal file
16
hive/client/hive_client/hiveclientcore.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "hiveclientcore.h"
|
||||
#include <QtQml>
|
||||
#include <QQmlEngine>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
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();
|
||||
}
|
||||
26
hive/client/hive_client/hiveclientcore.h
Normal file
26
hive/client/hive_client/hiveclientcore.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef HIVECLIENTCORE_H
|
||||
#define HIVECLIENTCORE_H
|
||||
|
||||
#include <QObject>
|
||||
#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
|
||||
@ -1,16 +1,13 @@
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include "qtquick2applicationviewer.h"
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlEngine>
|
||||
#include <QQmlComponent>
|
||||
#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();
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Layouts 1.0
|
||||
import QtQuick.Window 2.0
|
||||
|
||||
Rectangle{
|
||||
|
||||
}
|
||||
4
hive/hive_client.pro
Normal file
4
hive/hive_client.pro
Normal file
@ -0,0 +1,4 @@
|
||||
TEMPLATE = subdirs
|
||||
CONFIG = ordered
|
||||
|
||||
SUBDIRS += libhive client
|
||||
43
hive/libhive/client.cpp
Normal file
43
hive/libhive/client.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "client.h"
|
||||
#include <QDebug>
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
34
hive/libhive/client.h
Normal file
34
hive/libhive/client.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
#include <QHostAddress>
|
||||
|
||||
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
|
||||
@ -1,6 +0,0 @@
|
||||
#include "jsonparser.h"
|
||||
|
||||
JsonParser::JsonParser(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
#define JSONPARSER_H
|
||||
|
||||
#include <QObject>
|
||||
//#include <qjson/serializer.h>
|
||||
|
||||
class JsonParser : public QObject
|
||||
{
|
||||
|
||||
@ -1,6 +0,0 @@
|
||||
#include "jsonserializer.h"
|
||||
|
||||
JsonSerializer::JsonSerializer(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
#ifndef JSONSERIALIZER_H
|
||||
#define JSONSERIALIZER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class JsonSerializer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit JsonSerializer(QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // JSONSERIALIZER_H
|
||||
@ -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 {
|
||||
|
||||
@ -16,6 +16,33 @@ Server::Server(QObject *parent) :
|
||||
|
||||
}
|
||||
|
||||
void Server::newClientConnected()
|
||||
{
|
||||
// got a new client connected
|
||||
QTcpServer *server = qobject_cast<QTcpServer*>(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<QTcpSocket*>(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<QTcpServer*>(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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -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){
|
||||
|
||||
@ -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
|
||||
|
||||
@ -2,4 +2,6 @@ TEMPLATE = subdirs
|
||||
|
||||
CONFIG = ordered
|
||||
|
||||
|
||||
|
||||
SUBDIRS += hive_pi
|
||||
|
||||
Reference in New Issue
Block a user