This commit is contained in:
Simon Stürz 2013-12-30 02:35:59 +01:00
parent b3bc6a6689
commit 94f1f39070
13 changed files with 109 additions and 130 deletions

View File

@ -93,9 +93,6 @@ void Client::handleResponse(const QVariantMap &rsp)
m_requestMap.remove(id); m_requestMap.remove(id);
} }
} }
void Client::handleSignal(const QVariantMap &signal) void Client::handleSignal(const QVariantMap &signal)

View File

@ -38,50 +38,3 @@ bool DeviceManager::deleteDevice(QString deviceType, QUuid uuid)
//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;
//}

View File

@ -8,6 +8,7 @@ JsonHandler::JsonHandler(QObject *parent) :
QObject(parent) QObject(parent)
{ {
m_device = new DeviceJsonPlugin(this); m_device = new DeviceJsonPlugin(this);
m_radio = new RadioJsonPlugin(this);
} }
@ -30,6 +31,9 @@ QByteArray JsonHandler::process(const QByteArray &data)
if(command.value("device").toString() == m_device->deviceName()){ if(command.value("device").toString() == m_device->deviceName()){
return m_device->process(command,params); return m_device->process(command,params);
}
if(command.value("device").toString() == m_radio->deviceName()){
return m_radio->process(command,params);
}else{ }else{
return NULL; return NULL;
} }

View File

@ -5,6 +5,7 @@
#include <QVariant> #include <QVariant>
#include <jsonplugin/jsonplugin.h> #include <jsonplugin/jsonplugin.h>
#include <jsonplugin/devicejsonplugin.h> #include <jsonplugin/devicejsonplugin.h>
#include <jsonplugin/radiojsonplugin.h>
class JsonHandler : public QObject class JsonHandler : public QObject
@ -24,6 +25,7 @@ public slots:
private: private:
DeviceJsonPlugin *m_device; DeviceJsonPlugin *m_device;
RadioJsonPlugin *m_radio;
QByteArray formatResponse(const QVariantMap &command, const QVariantMap &responseParams); QByteArray formatResponse(const QVariantMap &command, const QVariantMap &responseParams);
QByteArray formatErrorResponse(const QVariantMap &command, const QString &error); QByteArray formatErrorResponse(const QVariantMap &command, const QString &error);

View File

@ -107,3 +107,13 @@ bool RadioJsonPlugin::execute()
return false; return false;
} }
} }
QByteArray RadioJsonPlugin::formatResponse()
{
}
QByteArray RadioJsonPlugin::formatErrorResponse()
{
}

View File

@ -15,6 +15,8 @@ public:
QString deviceName(); QString deviceName();
QStringList devicePropertys(); QStringList devicePropertys();
QStringList deviceMethods();
QByteArray process(const QVariantMap & command, const QVariantMap & parameters); QByteArray process(const QVariantMap & command, const QVariantMap & parameters);
private: private:
@ -26,9 +28,11 @@ private:
QVariantMap m_command; QVariantMap m_command;
QVariantMap m_parameters; QVariantMap m_parameters;
DeviceManager *m_deviceManager; DeviceManager *m_deviceManager;
QByteArray formatResponse();
QByteArray formatErrorResponse();
signals: signals:
public slots: public slots:

View File

@ -12,5 +12,4 @@ void LogWriter::write(LogWriter::MessageType messageType, QString logMessage)
QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm");; QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm");;
qDebug() << timeStamp; qDebug() << timeStamp;
} }

View File

@ -23,20 +23,22 @@ bool RadioSwitch::isValid(QList<int> rawData)
{ {
m_delay = rawData.first()/31; m_delay = rawData.first()/31;
QByteArray binCode; QByteArray binCode;
if(m_delay > 310 && m_delay < 340){
// new Remote -> average 314
if(m_delay > 300 && m_delay < 400){
// go trough all 48 timings (without sync signal) // go trough all 48 timings (without sync signal)
for(int i = 1; i <= 48; i+=2 ){ for(int i = 1; i <= 48; i+=2 ){
int div; int div;
int divNext; int divNext;
// if short // if short
if(rawData.at(i) < 500){ if(rawData.at(i) < 700){
div = 1; div = 1;
}else{ }else{
div = 3; div = 3;
} }
// if long // if long
if(rawData.at(i+1) < 500){ if(rawData.at(i+1) < 700){
divNext = 1; divNext = 1;
}else{ }else{
divNext = 3; divNext = 3;
@ -48,71 +50,70 @@ bool RadioSwitch::isValid(QList<int> rawData)
// if we have ___| | = 1 -> in 4 delays => 0001 // if we have ___| | = 1 -> in 4 delays => 0001
if(div == 1 && divNext == 3){ if(div == 1 && divNext == 3){
binCode.append("0"); binCode.append('0');
}else if(div == 3 && divNext == 1){ }else if(div == 3 && divNext == 1){
binCode.append("1"); binCode.append('1');
}else{ }else{
return false; return false;
} }
} }
}
m_binCode = binCode;
// get the channel of the remote signal (5 channels, 1=on, 0 = off) m_binCode = binCode;
QByteArray channelSettings;
for(int i = 1; i < 10; i+=2){
if(m_binCode.at(i-1) == '0' && m_binCode.at(i) == '1'){
channelSettings.append("0");
}else{
channelSettings.append("1");
}
}
// get the button letter
char button;
if(m_binCode.at(10) == '0' && m_binCode.at(11) == '0'){
button = 'A';
}
if(m_binCode.at(12) == '0' && m_binCode.at(13) == '0'){
button = 'B';
}
if(m_binCode.at(14) == '0' && m_binCode.at(15) == '0'){
button = 'C';
}
if(m_binCode.at(16) == '0' && m_binCode.at(17) == '0'){
button = 'D';
}
if(m_binCode.at(18) == '0' && m_binCode.at(19) == '0'){
button = 'E';
}
QStringList byteList; // get the channel of the remote signal (5 channels, 1=on, 0 = off)
for(int i = 4; i <= 24; i+=4){ QByteArray channelSettings;
byteList.append(binCode.left(4)); for(int i = 1; i < 10; i+=2){
binCode = binCode.right(binCode.length() -4); if(m_binCode.at(i-1) == '0' && m_binCode.at(i) == '1'){
channelSettings.append("0");
}else{
channelSettings.append("1");
} }
}
// get the button letter
char button;
if(m_binCode.at(10) == '0' && m_binCode.at(11) == '0'){
button = 'A';
}
if(m_binCode.at(12) == '0' && m_binCode.at(13) == '0'){
button = 'B';
}
if(m_binCode.at(14) == '0' && m_binCode.at(15) == '0'){
button = 'C';
}
if(m_binCode.at(16) == '0' && m_binCode.at(17) == '0'){
button = 'D';
}
if(m_binCode.at(18) == '0' && m_binCode.at(19) == '0'){
button = 'E';
}
bool buttonStatus; QStringList byteList;
if(byteList.last().toInt(0,2) == 1){ for(int i = 4; i <= 24; i+=4){
buttonStatus = true; byteList.append(binCode.left(4));
}else binCode = binCode.right(binCode.length() -4);
}
bool buttonStatus;
if(byteList.last().toInt(0,2) == 1){
buttonStatus = true;
}else
if(byteList.last().toInt(0,2) == 4){ if(byteList.last().toInt(0,2) == 4){
buttonStatus = false; buttonStatus = false;
}else{ }else{
return false; return false;
} }
qDebug() << "-----------------------------------------------------------"; qDebug() << "-----------------------------------------------------------";
qDebug() << "| REMOTE signal |"; qDebug() << "| REMOTE signal |";
qDebug() << "-----------------------------------------------------------"; qDebug() << "-----------------------------------------------------------";
qDebug() << "delay :" << m_delay; qDebug() << "delay :" << m_delay;
qDebug() << "bin CODE :" << m_binCode; qDebug() << "bin CODE :" << m_binCode;
qDebug() << byteList; qDebug() << byteList;
qDebug() << "Channels:" << channelSettings << "Button:" << button << "=" << buttonStatus; qDebug() << "Channels:" << channelSettings << "Button:" << button << "=" << buttonStatus;
emit switchSignalReceived(channelSettings,button,buttonStatus); emit switchSignalReceived(channelSettings,button,buttonStatus);
return true; return true;
}else{
return false;
}
} }
QByteArray RadioSwitch::calcBinCode(const QByteArray &channel, const RadioSwitch::RadioRemoteButton &button, const bool &buttonStatus) QByteArray RadioSwitch::calcBinCode(const QByteArray &channel, const RadioSwitch::RadioRemoteButton &button, const bool &buttonStatus)

View File

@ -96,11 +96,12 @@ float RadioThermometer::getTemperature()
} }
if(temperature == m_lastTemperature){ if(temperature == m_lastTemperature){
qDebug() << "received same temperature from " << QString(id) << " - " << QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm:ss");
return temperature; return temperature;
}else{ }else{
m_lastTemperature = temperature; m_lastTemperature = temperature;
QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm:ss");; QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm:ss");
//qDebug() << timeStamp; //qDebug() << timeStamp;
QFile file("/root/temperature_log.ods"); QFile file("/root/temperature_log.ods");

View File

@ -12,7 +12,7 @@ TARGET = hive
CONFIG += console CONFIG += console
CONFIG -= app_bundle CONFIG -= app_bundle
target.path = /root/bin target.path = /usr/bin
INSTALLS += target INSTALLS += target
TEMPLATE = app TEMPLATE = app

View File

@ -8,23 +8,22 @@ HiveCore::HiveCore(QObject *parent) :
m_server = new Server(this); m_server = new Server(this);
m_server->startServer(); m_server->startServer();
m_jsonHandler = new JsonHandler(this); // m_jsonHandler = new JsonHandler(this);
connect(m_server,SIGNAL(jsonDataAvailable(QByteArray)),m_jsonHandler,SLOT(process(QByteArray)));
// connect(m_server,SIGNAL(jsonDataAvailable(QByteArray)),m_jsonHandler,SLOT(process(QByteArray)));
// // create 433.92 MHz sender // // create 433.92 MHz sender
m_sender = new RadioSender(this); // m_sender = new RadioSender(this);
m_sender->setFrequency(RadioSender::RF433MHz); // m_sender->setFrequency(RadioSender::RF433MHz);
m_sender->setLineCode(RadioSender::SWITCH); // m_sender->setLineCode(RadioSender::SWITCH);
m_sender->setPulseLength(320); // m_sender->setPulseLength(320); // pin number 13
// //m_sender->sendBin("000000000000010101010001"); // m_sender->sendBin("000000000000010101010001");
// create 433.92 MHz receiver // create 433.92 MHz receiver
m_reciver = new RadioReciver(this); m_reciver = new RadioReciver(this);
m_reciver->setFrequency(RadioReciver::RF433MHz); m_reciver->setFrequency(RadioReciver::RF433MHz);
m_reciver->setPin(2); m_reciver->setPin(2); // pin number 13
m_reciver->enableReceiver(); m_reciver->enableReceiver();
} }

View File

@ -141,6 +141,7 @@ int RadioReciver::getPin() const
void RadioReciver::handleInterrupt() void RadioReciver::handleInterrupt()
{ {
if(!m_enable){ if(!m_enable){
return; return;
} }
@ -149,7 +150,9 @@ void RadioReciver::handleInterrupt()
m_duration = currentTime - m_lastTime; m_duration = currentTime - m_lastTime;
// filter nois // filter nois
if (m_duration > 5000 && m_duration > m_timings[0] - 200 && m_duration < m_timings[0] + 200) { if (m_duration > 5000 && m_timings[0] - 200 && m_duration < m_timings[0] + 200){
//qDebug() << "dt " << m_duration;
m_repeatCount++; m_repeatCount++;
m_changeCount--; m_changeCount--;
@ -163,6 +166,8 @@ void RadioReciver::handleInterrupt()
m_timings[i] = 0; m_timings[i] = 0;
} }
detectProtocol(rawData); detectProtocol(rawData);
}else{
//qDebug() << "changes: " << m_changeCount;
} }
m_repeatCount = 0; m_repeatCount = 0;
} }
@ -170,8 +175,9 @@ void RadioReciver::handleInterrupt()
}else if(m_duration > 5000){ }else if(m_duration > 5000){
m_changeCount = 0; m_changeCount = 0;
} }
if (m_changeCount > RC_MAX_CHANGES) { if (m_changeCount >= RC_MAX_CHANGES) {
m_changeCount = 0; m_changeCount = 0;
m_repeatCount = 0; m_repeatCount = 0;
} }
@ -179,26 +185,29 @@ void RadioReciver::handleInterrupt()
m_lastTime = currentTime; m_lastTime = currentTime;
} }
void RadioReciver::detectProtocol(QList<int> rawData) bool RadioReciver::detectProtocol(QList<int> rawData)
{ {
// check if we have a valid signal, 1 sync + 48 data // check if we have a valid signal, 1 sync + 48 data
if(rawData.length() != 49){ if(rawData.length() != 49){
return; qDebug() << rawData;
return false;
} }
// check plugins // check plugins
if(m_thermometer->isValid(rawData)){ if(m_thermometer->isValid(rawData)){
m_thermometer->getTemperature(); m_thermometer->getTemperature();
return true;
}else }else
if(m_switch->isValid(rawData)){ if(m_switch->isValid(rawData)){
m_switch->getBinCode(); m_switch->getBinCode();
}else{ return true;
qDebug() << "-----------------------------------------------------------"; }else{
qDebug() << "| GENERIC signal |"; qDebug() << "-----------------------------------------------------------";
qDebug() << "-----------------------------------------------------------"; qDebug() << "| GENERIC signal |";
qDebug() << "delay :" << rawData.first() /31; qDebug() << "-----------------------------------------------------------";
qDebug() << rawData; qDebug() << "delay :" << rawData.first() /31;
} qDebug() << rawData;
}
return false;
} }
void RadioReciver::enableReceiver() void RadioReciver::enableReceiver()

View File

@ -29,7 +29,7 @@ public:
private: private:
void handleInterrupt(); void handleInterrupt();
void detectProtocol(QList<int> rawData); bool detectProtocol(QList<int> rawData);
bool m_enable; bool m_enable;
int m_pin; int m_pin;