aktuell
This commit is contained in:
parent
b3bc6a6689
commit
94f1f39070
@ -93,9 +93,6 @@ void Client::handleResponse(const QVariantMap &rsp)
|
||||
m_requestMap.remove(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Client::handleSignal(const QVariantMap &signal)
|
||||
|
||||
@ -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;
|
||||
//}
|
||||
|
||||
@ -8,6 +8,7 @@ JsonHandler::JsonHandler(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
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()){
|
||||
return m_device->process(command,params);
|
||||
}
|
||||
if(command.value("device").toString() == m_radio->deviceName()){
|
||||
return m_radio->process(command,params);
|
||||
}else{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <QVariant>
|
||||
#include <jsonplugin/jsonplugin.h>
|
||||
#include <jsonplugin/devicejsonplugin.h>
|
||||
#include <jsonplugin/radiojsonplugin.h>
|
||||
|
||||
|
||||
class JsonHandler : public QObject
|
||||
@ -24,6 +25,7 @@ public slots:
|
||||
|
||||
private:
|
||||
DeviceJsonPlugin *m_device;
|
||||
RadioJsonPlugin *m_radio;
|
||||
|
||||
QByteArray formatResponse(const QVariantMap &command, const QVariantMap &responseParams);
|
||||
QByteArray formatErrorResponse(const QVariantMap &command, const QString &error);
|
||||
|
||||
@ -107,3 +107,13 @@ bool RadioJsonPlugin::execute()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray RadioJsonPlugin::formatResponse()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QByteArray RadioJsonPlugin::formatErrorResponse()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,8 @@ public:
|
||||
|
||||
QString deviceName();
|
||||
QStringList devicePropertys();
|
||||
QStringList deviceMethods();
|
||||
|
||||
QByteArray process(const QVariantMap & command, const QVariantMap & parameters);
|
||||
|
||||
private:
|
||||
@ -26,9 +28,11 @@ private:
|
||||
|
||||
QVariantMap m_command;
|
||||
QVariantMap m_parameters;
|
||||
|
||||
DeviceManager *m_deviceManager;
|
||||
|
||||
QByteArray formatResponse();
|
||||
QByteArray formatErrorResponse();
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
@ -12,5 +12,4 @@ void LogWriter::write(LogWriter::MessageType messageType, QString logMessage)
|
||||
QString timeStamp = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm");;
|
||||
qDebug() << timeStamp;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -23,20 +23,22 @@ bool RadioSwitch::isValid(QList<int> rawData)
|
||||
{
|
||||
m_delay = rawData.first()/31;
|
||||
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)
|
||||
for(int i = 1; i <= 48; i+=2 ){
|
||||
int div;
|
||||
int divNext;
|
||||
|
||||
// if short
|
||||
if(rawData.at(i) < 500){
|
||||
if(rawData.at(i) < 700){
|
||||
div = 1;
|
||||
}else{
|
||||
div = 3;
|
||||
}
|
||||
// if long
|
||||
if(rawData.at(i+1) < 500){
|
||||
if(rawData.at(i+1) < 700){
|
||||
divNext = 1;
|
||||
}else{
|
||||
divNext = 3;
|
||||
@ -48,71 +50,70 @@ bool RadioSwitch::isValid(QList<int> rawData)
|
||||
// if we have ___| | = 1 -> in 4 delays => 0001
|
||||
|
||||
if(div == 1 && divNext == 3){
|
||||
binCode.append("0");
|
||||
binCode.append('0');
|
||||
}else if(div == 3 && divNext == 1){
|
||||
binCode.append("1");
|
||||
binCode.append('1');
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_binCode = binCode;
|
||||
|
||||
// get the channel of the remote signal (5 channels, 1=on, 0 = off)
|
||||
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';
|
||||
}
|
||||
m_binCode = binCode;
|
||||
|
||||
QStringList byteList;
|
||||
for(int i = 4; i <= 24; i+=4){
|
||||
byteList.append(binCode.left(4));
|
||||
binCode = binCode.right(binCode.length() -4);
|
||||
// get the channel of the remote signal (5 channels, 1=on, 0 = off)
|
||||
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';
|
||||
}
|
||||
|
||||
bool buttonStatus;
|
||||
if(byteList.last().toInt(0,2) == 1){
|
||||
buttonStatus = true;
|
||||
}else
|
||||
QStringList byteList;
|
||||
for(int i = 4; i <= 24; i+=4){
|
||||
byteList.append(binCode.left(4));
|
||||
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){
|
||||
buttonStatus = false;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "| REMOTE signal |";
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "delay :" << m_delay;
|
||||
qDebug() << "bin CODE :" << m_binCode;
|
||||
qDebug() << byteList;
|
||||
qDebug() << "Channels:" << channelSettings << "Button:" << button << "=" << buttonStatus;
|
||||
emit switchSignalReceived(channelSettings,button,buttonStatus);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "| REMOTE signal |";
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "delay :" << m_delay;
|
||||
qDebug() << "bin CODE :" << m_binCode;
|
||||
qDebug() << byteList;
|
||||
qDebug() << "Channels:" << channelSettings << "Button:" << button << "=" << buttonStatus;
|
||||
emit switchSignalReceived(channelSettings,button,buttonStatus);
|
||||
return true;
|
||||
}
|
||||
|
||||
QByteArray RadioSwitch::calcBinCode(const QByteArray &channel, const RadioSwitch::RadioRemoteButton &button, const bool &buttonStatus)
|
||||
|
||||
@ -96,11 +96,12 @@ float RadioThermometer::getTemperature()
|
||||
}
|
||||
|
||||
if(temperature == m_lastTemperature){
|
||||
qDebug() << "received same temperature from " << QString(id) << " - " << QDateTime::currentDateTime().toString("dd.MM.yyyy, hh:mm:ss");
|
||||
return temperature;
|
||||
}else{
|
||||
|
||||
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;
|
||||
|
||||
QFile file("/root/temperature_log.ods");
|
||||
|
||||
@ -12,7 +12,7 @@ TARGET = hive
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
target.path = /root/bin
|
||||
target.path = /usr/bin
|
||||
INSTALLS += target
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
@ -8,23 +8,22 @@ HiveCore::HiveCore(QObject *parent) :
|
||||
m_server = new Server(this);
|
||||
m_server->startServer();
|
||||
|
||||
m_jsonHandler = new JsonHandler(this);
|
||||
|
||||
connect(m_server,SIGNAL(jsonDataAvailable(QByteArray)),m_jsonHandler,SLOT(process(QByteArray)));
|
||||
// m_jsonHandler = new JsonHandler(this);
|
||||
|
||||
// connect(m_server,SIGNAL(jsonDataAvailable(QByteArray)),m_jsonHandler,SLOT(process(QByteArray)));
|
||||
|
||||
|
||||
// // create 433.92 MHz sender
|
||||
m_sender = new RadioSender(this);
|
||||
m_sender->setFrequency(RadioSender::RF433MHz);
|
||||
m_sender->setLineCode(RadioSender::SWITCH);
|
||||
m_sender->setPulseLength(320);
|
||||
// //m_sender->sendBin("000000000000010101010001");
|
||||
// m_sender = new RadioSender(this);
|
||||
// m_sender->setFrequency(RadioSender::RF433MHz);
|
||||
// m_sender->setLineCode(RadioSender::SWITCH);
|
||||
// m_sender->setPulseLength(320); // pin number 13
|
||||
// m_sender->sendBin("000000000000010101010001");
|
||||
|
||||
// create 433.92 MHz receiver
|
||||
m_reciver = new RadioReciver(this);
|
||||
m_reciver->setFrequency(RadioReciver::RF433MHz);
|
||||
m_reciver->setPin(2);
|
||||
m_reciver->setPin(2); // pin number 13
|
||||
m_reciver->enableReceiver();
|
||||
|
||||
}
|
||||
|
||||
@ -141,6 +141,7 @@ int RadioReciver::getPin() const
|
||||
|
||||
void RadioReciver::handleInterrupt()
|
||||
{
|
||||
|
||||
if(!m_enable){
|
||||
return;
|
||||
}
|
||||
@ -149,7 +150,9 @@ void RadioReciver::handleInterrupt()
|
||||
m_duration = currentTime - m_lastTime;
|
||||
|
||||
// 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_changeCount--;
|
||||
|
||||
@ -163,6 +166,8 @@ void RadioReciver::handleInterrupt()
|
||||
m_timings[i] = 0;
|
||||
}
|
||||
detectProtocol(rawData);
|
||||
}else{
|
||||
//qDebug() << "changes: " << m_changeCount;
|
||||
}
|
||||
m_repeatCount = 0;
|
||||
}
|
||||
@ -170,8 +175,9 @@ void RadioReciver::handleInterrupt()
|
||||
|
||||
}else if(m_duration > 5000){
|
||||
m_changeCount = 0;
|
||||
|
||||
}
|
||||
if (m_changeCount > RC_MAX_CHANGES) {
|
||||
if (m_changeCount >= RC_MAX_CHANGES) {
|
||||
m_changeCount = 0;
|
||||
m_repeatCount = 0;
|
||||
}
|
||||
@ -179,26 +185,29 @@ void RadioReciver::handleInterrupt()
|
||||
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
|
||||
if(rawData.length() != 49){
|
||||
return;
|
||||
qDebug() << rawData;
|
||||
return false;
|
||||
}
|
||||
// check plugins
|
||||
if(m_thermometer->isValid(rawData)){
|
||||
m_thermometer->getTemperature();
|
||||
return true;
|
||||
}else
|
||||
if(m_switch->isValid(rawData)){
|
||||
m_switch->getBinCode();
|
||||
}else{
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "| GENERIC signal |";
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "delay :" << rawData.first() /31;
|
||||
qDebug() << rawData;
|
||||
}
|
||||
|
||||
if(m_switch->isValid(rawData)){
|
||||
m_switch->getBinCode();
|
||||
return true;
|
||||
}else{
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "| GENERIC signal |";
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "delay :" << rawData.first() /31;
|
||||
qDebug() << rawData;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void RadioReciver::enableReceiver()
|
||||
|
||||
@ -29,7 +29,7 @@ public:
|
||||
|
||||
private:
|
||||
void handleInterrupt();
|
||||
void detectProtocol(QList<int> rawData);
|
||||
bool detectProtocol(QList<int> rawData);
|
||||
|
||||
bool m_enable;
|
||||
int m_pin;
|
||||
|
||||
Reference in New Issue
Block a user