begin of json implementation

This commit is contained in:
Simon Stuerz 2013-08-24 12:52:38 +02:00
parent 59c1157e57
commit 823907d34e
13 changed files with 99 additions and 35 deletions

View File

@ -11,6 +11,5 @@ HiveClientCore::HiveClientCore(QObject *parent) :
m_client->connectToHost("10.10.10.40","1234");
m_viewer = new QtQuick2ApplicationViewer;
m_viewer->setMainQmlFile(QStringLiteral("qml/hive_client/main.qml"));
m_viewer->showExpanded();
}

View File

@ -10,7 +10,18 @@ class DeviceManager : public QObject
Q_OBJECT
public:
explicit DeviceManager(QObject *parent = 0);
enum DeviceType {
Sensor,
Actor
};
enum DeviceName {
Light,
Switch
};
signals:
public slots:

View File

@ -0,0 +1,25 @@
#include "jsonhandler.h"
#include <QJsonDocument>
#include <QVariantMap>
#include <QDebug>
JsonHandler::JsonHandler(QObject *parent) :
QObject(parent)
{
}
QByteArray JsonHandler::process(const QByteArray &data)
{
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
if(error.error != QJsonParseError::NoError) {
qDebug() << "failed to parse data" << data << ":" << error.errorString();
}
}

View File

@ -0,0 +1,26 @@
#ifndef JSONHANDLER_H
#define JSONHANDLER_H
#include <QObject>
class JsonHandler : public QObject
{
Q_OBJECT
public:
explicit JsonHandler(QObject *parent = 0);
private:
signals:
void notifyAll(const QByteArray &data);
public slots:
QByteArray process(const QByteArray &data);
};
#endif // JSONHANDLER_H

View File

@ -1,19 +0,0 @@
#ifndef JSONPARSER_H
#define JSONPARSER_H
#include <QObject>
//#include <qjson/serializer.h>
class JsonParser : public QObject
{
Q_OBJECT
public:
explicit JsonParser(QObject *parent = 0);
signals:
public slots:
};
#endif // JSONPARSER_H

View File

@ -12,19 +12,22 @@ CONFIG += static
DEFINES += LIBHIVE_LIBRARY
LIBS += -lqjson
SOURCES += libhive.cpp \
server.cpp \
devicemanager.cpp \
logwriter.cpp \
client.cpp
client.cpp \
jsonhandler.cpp
HEADERS += libhive.h\
libhive_global.h \
server.h \
devicemanager.h \
logwriter.h \
jsonparser.h \
client.h
client.h \
jsonhandler.h
#unix:!symbian {
# maemo5 {

View File

@ -34,6 +34,12 @@ void Server::newClientConnected()
void Server::readPackage()
{
QTcpSocket *client = qobject_cast<QTcpSocket*>(sender());
while(client->canReadLine()){
QByteArray data = client->readLine();
qDebug() << "data to parse:" << data.remove(data.length() - 1, 1);
emit dataLineAvailable(data);
}
}
@ -77,9 +83,10 @@ bool Server::stopServer()
return true;
}
void Server::sendToAll(QString data)
void Server::sendToAll(QByteArray data)
{
foreach(QTcpSocket *client,m_clientList){
client->write(data);
}
}

View File

@ -18,6 +18,7 @@ private:
signals:
void dataLineAvailable(const QByteArray &dataLine);
private slots:
void newClientConnected();
@ -27,7 +28,7 @@ private slots:
public slots:
bool startServer();
bool stopServer();
void sendToAll(QString data);
void sendToAll(QByteArray data);
};

View File

@ -8,6 +8,9 @@ HiveCore::HiveCore(QObject *parent) :
m_server = new Server(this);
m_server->startServer();
m_deviceManager = new DeviceManager(this);
// create 433.92 MHz sender
m_sender = new RadioSender(this);
m_sender->setFrequency(RadioSender::RF433MHz);

View File

@ -17,6 +17,7 @@ private:
Server *m_server;
RadioReciver *m_reciver;
RadioSender *m_sender;
DeviceManager *m_deviceManager;
signals:
public slots:

View File

@ -17,7 +17,7 @@ RadioReciver::RadioReciver(QObject *parent) :
}
void RadioReciver::handleInterrupt()
void RadioReciver::handleRC433Interrupt()
{
if(!m_enable){
return;
@ -58,6 +58,11 @@ void RadioReciver::handleInterrupt()
lastTime = time;
}
void RadioReciver::handleRC868Interrupt()
{
}
void RadioReciver::detectProtocol(int signalCount)
{
if(signalCount < 49){
@ -265,7 +270,7 @@ void RadioReciver::setFrequency(RadioReciver::Frequency frequency)
qDebug() << "ERROR: GPIO setup for 433.92 MHz receiver failed.";
}
pinMode(2,INPUT);
wiringPiISR(2, INT_EDGE_BOTH, &handleInterrupt);
wiringPiISR(2, INT_EDGE_BOTH, &handleRC433Interrupt);
qDebug() << "GPIO setup for 433.92 MHz receiver ok.";
}
if(frequency == RadioReciver::RF868MHz){

View File

@ -17,7 +17,9 @@ public:
};
private:
static void handleInterrupt();
static void handleRC433Interrupt();
static void handleRC868Interrupt();
static void detectProtocol(int signalCount);
static float parseTemperature(QByteArray codeBin);

View File

@ -15,12 +15,12 @@ public:
};
enum LineCode{
UNIPOLAR = 0x0,
MANCHESTER = 0x1,
DMANCHESTER = 0x2,
REMOTE = 0x4,
THERMOMETER = 0x8,
WEATHERSTATION = 0x16
UNIPOLAR = 0x2,
MANCHESTER = 0x3,
DMANCHESTER = 0x4,
REMOTE = 0x5,
THERMOMETER = 0x6,
WEATHERSTATION = 0x7
};