diff --git a/hive/client/hive_client/hiveclientcore.cpp b/hive/client/hive_client/hiveclientcore.cpp index 05b0da90..ae786b34 100644 --- a/hive/client/hive_client/hiveclientcore.cpp +++ b/hive/client/hive_client/hiveclientcore.cpp @@ -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(); } diff --git a/hive/libhive/devicemanager.h b/hive/libhive/devicemanager.h index e20cebed..32f3920d 100644 --- a/hive/libhive/devicemanager.h +++ b/hive/libhive/devicemanager.h @@ -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: diff --git a/hive/libhive/jsonhandler.cpp b/hive/libhive/jsonhandler.cpp new file mode 100644 index 00000000..6f0d74b6 --- /dev/null +++ b/hive/libhive/jsonhandler.cpp @@ -0,0 +1,25 @@ +#include "jsonhandler.h" + +#include +#include +#include + +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(); + } + + + + +} diff --git a/hive/libhive/jsonhandler.h b/hive/libhive/jsonhandler.h new file mode 100644 index 00000000..56e386e4 --- /dev/null +++ b/hive/libhive/jsonhandler.h @@ -0,0 +1,26 @@ +#ifndef JSONHANDLER_H +#define JSONHANDLER_H + +#include + + +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 diff --git a/hive/libhive/jsonparser.h b/hive/libhive/jsonparser.h deleted file mode 100644 index ac97bf04..00000000 --- a/hive/libhive/jsonparser.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef JSONPARSER_H -#define JSONPARSER_H - -#include -//#include - -class JsonParser : public QObject -{ - Q_OBJECT -public: - explicit JsonParser(QObject *parent = 0); - -signals: - -public slots: - -}; - -#endif // JSONPARSER_H diff --git a/hive/libhive/libhive.pro b/hive/libhive/libhive.pro index 0db4bf3d..28dddfdf 100644 --- a/hive/libhive/libhive.pro +++ b/hive/libhive/libhive.pro @@ -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 { diff --git a/hive/libhive/server.cpp b/hive/libhive/server.cpp index 93b4f958..2ff8e00b 100644 --- a/hive/libhive/server.cpp +++ b/hive/libhive/server.cpp @@ -34,6 +34,12 @@ void Server::newClientConnected() void Server::readPackage() { + QTcpSocket *client = qobject_cast(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); } } diff --git a/hive/libhive/server.h b/hive/libhive/server.h index f92aaca9..add15788 100644 --- a/hive/libhive/server.h +++ b/hive/libhive/server.h @@ -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); }; diff --git a/hive/server/hive_pi/hivecore.cpp b/hive/server/hive_pi/hivecore.cpp index ef017d15..5eb41a56 100644 --- a/hive/server/hive_pi/hivecore.cpp +++ b/hive/server/hive_pi/hivecore.cpp @@ -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); diff --git a/hive/server/hive_pi/hivecore.h b/hive/server/hive_pi/hivecore.h index 4d5cc132..9202b8b4 100644 --- a/hive/server/hive_pi/hivecore.h +++ b/hive/server/hive_pi/hivecore.h @@ -17,6 +17,7 @@ private: Server *m_server; RadioReciver *m_reciver; RadioSender *m_sender; + DeviceManager *m_deviceManager; signals: public slots: diff --git a/hive/server/hive_pi/radio/radioreciver.cpp b/hive/server/hive_pi/radio/radioreciver.cpp index 3f44fe08..252f35f8 100644 --- a/hive/server/hive_pi/radio/radioreciver.cpp +++ b/hive/server/hive_pi/radio/radioreciver.cpp @@ -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){ diff --git a/hive/server/hive_pi/radio/radioreciver.h b/hive/server/hive_pi/radio/radioreciver.h index 4b55a1c0..d7cb1ec2 100644 --- a/hive/server/hive_pi/radio/radioreciver.h +++ b/hive/server/hive_pi/radio/radioreciver.h @@ -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); diff --git a/hive/server/hive_pi/radio/radiosender.h b/hive/server/hive_pi/radio/radiosender.h index dbc91fdc..eef255f3 100644 --- a/hive/server/hive_pi/radio/radiosender.h +++ b/hive/server/hive_pi/radio/radiosender.h @@ -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 };