moved radioplugins to lib
This commit is contained in:
parent
3bf97a7e0d
commit
cdb1e942bc
@ -25,5 +25,4 @@ Rectangle {
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,48 +6,82 @@ DeviceManager::DeviceManager(QObject *parent) :
|
||||
{
|
||||
}
|
||||
|
||||
void DeviceManager::saveDeviceValue(QString deviceType, QString deviceName, QString key, QVariant value)
|
||||
bool DeviceManager::saveDevice(QString deviceType, QUuid uuid, QVariantMap paramters)
|
||||
{
|
||||
QSettings settings("hive");
|
||||
settings.beginGroup(deviceType);
|
||||
settings.beginGroup(deviceName);
|
||||
settings.setValue(key,value);
|
||||
qDebug() << "safed device value:" << deviceType << "->" << deviceName << "->" << key << ":" << value << ".";
|
||||
settings.beginGroup(uuid.toString());
|
||||
QVariantMap::iterator i = paramters.begin();
|
||||
while (i!= paramters.end()){
|
||||
settings.setValue(i.key(),i.value());
|
||||
++i;
|
||||
}
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeviceManager::deleteDeviceValue(QString deviceType, QString deviceName, QString key)
|
||||
bool DeviceManager::deleteDevice(QString deviceType, QUuid uuid)
|
||||
{
|
||||
QSettings settings("hive");
|
||||
settings.beginGroup(deviceType);
|
||||
settings.beginGroup(deviceName);
|
||||
settings.remove(key);
|
||||
qDebug() << "delete key of" << deviceName << key;
|
||||
|
||||
|
||||
// controll if we have a stored device with this uuid
|
||||
if(!settings.childGroups().contains(uuid.toString())){
|
||||
qDebug() << "no device with uuid" << uuid.toString() << "found.";
|
||||
return false;
|
||||
}
|
||||
settings.remove(uuid.toString());
|
||||
settings.endGroup();
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//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;
|
||||
//}
|
||||
|
||||
@ -4,30 +4,26 @@
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
#include <QUuid>
|
||||
|
||||
class DeviceManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DeviceManager(QObject *parent = 0);
|
||||
enum DeviceType {
|
||||
Sensor,
|
||||
Actor
|
||||
};
|
||||
enum DeviceName {
|
||||
Light,
|
||||
Switch
|
||||
|
||||
};
|
||||
/* deviceType
|
||||
* radio
|
||||
* ...
|
||||
*/
|
||||
|
||||
bool saveDevice(QString deviceType, QUuid uuid, QVariantMap paramters);
|
||||
bool deleteDevice(QString deviceType, QUuid uuid);
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void saveDeviceValue(QString deviceType, QString deviceName, QString key, QVariant value);
|
||||
void deleteDeviceValue(QString deviceType, QString deviceName, QString key);
|
||||
void deleteDevice(QString deviceType, QString deviceName);
|
||||
QStringList getDevices(QString deviceType);
|
||||
QStringList getDeviceKeys(QString deviceType, QString deviceName);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -18,52 +18,46 @@ QString DeviceJsonPlugin::deviceName()
|
||||
|
||||
QByteArray DeviceJsonPlugin::process(const QVariantMap &command, const QVariantMap ¶meters)
|
||||
{
|
||||
|
||||
m_command = command;
|
||||
m_parameters = parameters;
|
||||
|
||||
// check if we have a id
|
||||
if(!command.contains("id")){
|
||||
if(!m_command.contains("id")){
|
||||
qDebug() << "request contains no id..";
|
||||
}
|
||||
|
||||
// check the methods
|
||||
if(command.value("method").toString() == "add"){
|
||||
if(m_command.value("method").toString() == "add"){
|
||||
qDebug() << "got a ADD DEVICE command";
|
||||
add(parameters);
|
||||
add();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DeviceJsonPlugin::add(QVariantMap parameters)
|
||||
bool DeviceJsonPlugin::add()
|
||||
{
|
||||
QUuid uuid = QUuid::createUuid();
|
||||
//qDebug() << uuid;
|
||||
if(parameters.value("deviceType").toString() == "actor"){
|
||||
QSettings settings("hive");
|
||||
settings.beginGroup(uuid.toString());
|
||||
QMapIterator<QString, QVariant> i(parameters);
|
||||
while(i.hasNext()){
|
||||
i.next();
|
||||
qDebug() << i.key() << "=" << i.value().toString();
|
||||
settings.setValue(i.key(),i.value());
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
// QUuid uuid = QUuid::createUuid();
|
||||
// //qDebug() << uuid;
|
||||
// if(parameters.value("deviceType").toString() == "actor"){
|
||||
// QSettings settings("hive");
|
||||
// settings.beginGroup(uuid.toString());
|
||||
// QMapIterator<QString, QVariant> i(parameters);
|
||||
// while(i.hasNext()){
|
||||
// i.next();
|
||||
// qDebug() << i.key() << "=" << i.value().toString();
|
||||
// settings.setValue(i.key(),i.value());
|
||||
// }
|
||||
// settings.endGroup();
|
||||
// }
|
||||
}
|
||||
|
||||
void DeviceJsonPlugin::remove()
|
||||
bool DeviceJsonPlugin::remove()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DeviceJsonPlugin::editValue(QString value, QVariant key)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DeviceJsonPlugin::getAll()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QByteArray DeviceJsonPlugin::formatResponse()
|
||||
{
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
class DeviceJsonPlugin : public JsonPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DeviceJsonPlugin(QObject *parent = 0);
|
||||
QString deviceName();
|
||||
@ -16,10 +17,14 @@ public:
|
||||
private:
|
||||
DeviceManager *m_deviceManager;
|
||||
|
||||
void add(QVariantMap parameters);
|
||||
void remove();
|
||||
void editValue(QString value, QVariant key);
|
||||
void getAll();
|
||||
bool add();
|
||||
bool remove();
|
||||
bool edit();
|
||||
bool execute();
|
||||
|
||||
QVariantMap m_command;
|
||||
QVariantMap m_parameters;
|
||||
|
||||
|
||||
QByteArray formatResponse();
|
||||
QByteArray formatErrorResponse();
|
||||
|
||||
@ -12,8 +12,12 @@ public:
|
||||
virtual QString deviceName() = 0;
|
||||
virtual QByteArray process(const QVariantMap & command, const QVariantMap & parameters) = 0;
|
||||
|
||||
private:
|
||||
QByteArray formatResponse();
|
||||
QByteArray formatErrorResponse();
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
109
hive/libhive/jsonplugin/radiojsonplugin.cpp
Normal file
109
hive/libhive/jsonplugin/radiojsonplugin.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
#include "radiojsonplugin.h"
|
||||
#include <QDebug>
|
||||
#include <QUuid>
|
||||
|
||||
RadioJsonPlugin::RadioJsonPlugin(QObject *parent) :
|
||||
JsonPlugin(parent)
|
||||
{
|
||||
m_deviceManager = new DeviceManager(this);
|
||||
}
|
||||
|
||||
QString RadioJsonPlugin::deviceName()
|
||||
{
|
||||
QString deviceName = "radio";
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
QStringList RadioJsonPlugin::devicePropertys()
|
||||
{
|
||||
QStringList propertys;
|
||||
propertys.append("name");
|
||||
propertys.append("uuid");
|
||||
propertys.append("channel");
|
||||
propertys.append("button");
|
||||
propertys.append("buttonState");
|
||||
propertys.append("location");
|
||||
return propertys;
|
||||
}
|
||||
|
||||
QStringList RadioJsonPlugin::deviceMethods()
|
||||
{
|
||||
QStringList methods;
|
||||
methods.append("add");
|
||||
methods.append("remove");
|
||||
methods.append("edit");
|
||||
methods.append("execute");
|
||||
methods.append("getAll");
|
||||
return methods;
|
||||
}
|
||||
|
||||
QByteArray RadioJsonPlugin::process(const QVariantMap &command, const QVariantMap ¶meters)
|
||||
{
|
||||
m_command = command;
|
||||
m_parameters = parameters;
|
||||
|
||||
if(!m_command.contains("id")){
|
||||
qDebug() << "request contains no id..";
|
||||
}
|
||||
|
||||
// check if we have a valid method
|
||||
if(deviceMethods().contains(m_command.value("method").toString())){
|
||||
// check the methods
|
||||
if(m_command.value("method").toString() == "add"){
|
||||
qDebug() << "got a ADD DEVICE command";
|
||||
if(add()){
|
||||
//TODO: return response
|
||||
}else{
|
||||
// TODO: return error response
|
||||
}
|
||||
}
|
||||
if(m_command.value("method").toString() == "execut"){
|
||||
qDebug() << "got a EXECUTE DEVICE command";
|
||||
execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}else{
|
||||
// TODO: return error respnonse
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool RadioJsonPlugin::add()
|
||||
{
|
||||
QUuid uuid = QUuid::createUuid();
|
||||
//qDebug() << uuid;
|
||||
return m_deviceManager->saveDevice(m_command.value("deviceType").toString(),uuid,m_parameters);
|
||||
|
||||
}
|
||||
|
||||
bool RadioJsonPlugin::remove()
|
||||
{
|
||||
if(m_parameters.contains("uuid")){
|
||||
QUuid uuid = m_parameters.value("uuid").toUuid();
|
||||
return m_deviceManager->deleteDevice(m_command.value("deviceType").toString(),uuid);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool RadioJsonPlugin::edit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool RadioJsonPlugin::execute()
|
||||
{
|
||||
if(m_parameters.contains("uuid")){
|
||||
QUuid uuid = m_parameters.value("uuid").toUuid();
|
||||
|
||||
// load paramters (bincode, linecode, frequency ecc.) and execute
|
||||
|
||||
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
38
hive/libhive/jsonplugin/radiojsonplugin.h
Normal file
38
hive/libhive/jsonplugin/radiojsonplugin.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef RADIOJSONPLUGIN_H
|
||||
#define RADIOJSONPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QVariantMap>
|
||||
#include <jsonplugin/jsonplugin.h>
|
||||
#include <devicemanager.h>
|
||||
|
||||
class RadioJsonPlugin : public JsonPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RadioJsonPlugin(QObject *parent = 0);
|
||||
|
||||
QString deviceName();
|
||||
QStringList devicePropertys();
|
||||
QByteArray process(const QVariantMap & command, const QVariantMap & parameters);
|
||||
|
||||
private:
|
||||
// methods
|
||||
bool add();
|
||||
bool remove();
|
||||
bool edit();
|
||||
bool execute();
|
||||
|
||||
QVariantMap m_command;
|
||||
QVariantMap m_parameters;
|
||||
|
||||
DeviceManager *m_deviceManager;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // RADIOJSONPLUGIN_H
|
||||
@ -21,7 +21,11 @@ SOURCES += libhive.cpp \
|
||||
client.cpp \
|
||||
jsonhandler.cpp \
|
||||
jsonplugin/jsonplugin.cpp \
|
||||
jsonplugin/devicejsonplugin.cpp
|
||||
jsonplugin/devicejsonplugin.cpp \
|
||||
jsonplugin/radiojsonplugin.cpp \
|
||||
radioplugin/radioplugin.cpp \
|
||||
radioplugin/radioswitch.cpp \
|
||||
radioplugin/radiothermometer.cpp
|
||||
|
||||
HEADERS += libhive.h\
|
||||
libhive_global.h \
|
||||
@ -31,7 +35,11 @@ HEADERS += libhive.h\
|
||||
client.h \
|
||||
jsonhandler.h \
|
||||
jsonplugin/jsonplugin.h \
|
||||
jsonplugin/devicejsonplugin.h
|
||||
jsonplugin/devicejsonplugin.h \
|
||||
jsonplugin/radiojsonplugin.h \
|
||||
radioplugin/radioplugin.h \
|
||||
radioplugin/radioswitch.h \
|
||||
radioplugin/radiothermometer.h
|
||||
|
||||
#unix:!symbian {
|
||||
# maemo5 {
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
class RadioPlugin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit RadioPlugin(QObject *parent = 0);
|
||||
virtual ~RadioPlugin(){}
|
||||
@ -14,5 +15,4 @@ public:
|
||||
virtual QByteArray getBinCode() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // RADIOPLUGIN_H
|
||||
@ -1,16 +1,16 @@
|
||||
#include "radioswitch.h"
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
|
||||
#include "rfswitch.h"
|
||||
|
||||
RFSwitch::RFSwitch(QObject *parent)
|
||||
:RadioPlugin(parent)
|
||||
RadioSwitch::RadioSwitch(QObject *parent) :
|
||||
RadioPlugin(parent)
|
||||
{
|
||||
m_delay = 0;
|
||||
m_binCode = 0;
|
||||
}
|
||||
|
||||
QByteArray RFSwitch::getBinCode()
|
||||
QByteArray RadioSwitch::getBinCode()
|
||||
{
|
||||
if(m_binCode.isEmpty()){
|
||||
return NULL;
|
||||
@ -19,13 +19,12 @@ QByteArray RFSwitch::getBinCode()
|
||||
}
|
||||
}
|
||||
|
||||
bool RFSwitch::isValid(QList<int> rawData)
|
||||
bool RadioSwitch::isValid(QList<int> rawData)
|
||||
{
|
||||
|
||||
m_delay = rawData.first()/31;
|
||||
QByteArray binCode;
|
||||
if(m_delay > 310 && m_delay < 340){
|
||||
// go trough all 48 timings
|
||||
// go trough all 48 timings (without sync signal)
|
||||
for(int i = 1; i <= 48; i+=2 ){
|
||||
int div;
|
||||
int divNext;
|
||||
@ -109,10 +108,53 @@ bool RFSwitch::isValid(QList<int> rawData)
|
||||
qDebug() << "bin CODE :" << m_binCode;
|
||||
qDebug() << byteList;
|
||||
qDebug() << "Channels:" << channelSettings << "Button:" << button << "=" << buttonStatus;
|
||||
//emit switchSignalReceived(channelSettings,button,buttonStatus);
|
||||
emit switchSignalReceived(channelSettings,button,buttonStatus);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray RadioSwitch::calcBinCode(const QByteArray &channel, const RadioSwitch::RadioRemoteButton &button, const bool &buttonStatus)
|
||||
{
|
||||
QByteArray binCode;
|
||||
|
||||
// channels
|
||||
for(int i = 0; i < channel.length(); i++){
|
||||
if(channel.at(i) == '0'){
|
||||
binCode.append("01");
|
||||
}else{
|
||||
binCode.append("00");
|
||||
}
|
||||
}
|
||||
|
||||
// Buttons
|
||||
switch (button) {
|
||||
case RadioSwitch::A :
|
||||
binCode.append("0001010101");
|
||||
break;
|
||||
case RadioSwitch::B:
|
||||
binCode.append("0100010101");
|
||||
break;
|
||||
case RadioSwitch::C:
|
||||
binCode.append("0101000101");
|
||||
break;
|
||||
case RadioSwitch::D:
|
||||
binCode.append("0101010001");
|
||||
break;
|
||||
case RadioSwitch::E:
|
||||
binCode.append("0101010100");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// ON/OFF
|
||||
if(buttonStatus){
|
||||
binCode.append("0001");
|
||||
}else{
|
||||
binCode.append("0100");
|
||||
}
|
||||
|
||||
return binCode;
|
||||
}
|
||||
38
hive/libhive/radioplugin/radioswitch.h
Normal file
38
hive/libhive/radioplugin/radioswitch.h
Normal file
@ -0,0 +1,38 @@
|
||||
#ifndef RADIOSWITCH_H
|
||||
#define RADIOSWITCH_H
|
||||
|
||||
#include <QObject>
|
||||
#include <radioplugin/radioplugin.h>
|
||||
|
||||
#define RadioSwitchDelay 350
|
||||
|
||||
class RadioSwitch : public RadioPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RadioSwitch(QObject *parent = 0);
|
||||
|
||||
QByteArray getBinCode();
|
||||
bool isValid(QList<int> rawData);
|
||||
|
||||
enum RadioRemoteButton{
|
||||
A = 0x0,
|
||||
B = 0x1,
|
||||
C = 0x2,
|
||||
D = 0x3,
|
||||
E = 0x4
|
||||
};
|
||||
|
||||
private:
|
||||
int m_delay;
|
||||
QByteArray m_binCode;
|
||||
|
||||
signals:
|
||||
void switchSignalReceived(const QByteArray &channel, const char &button, const bool &buttonStatus);
|
||||
|
||||
public slots:
|
||||
QByteArray calcBinCode(const QByteArray &channel, const RadioRemoteButton &button, const bool &buttonStatus);
|
||||
|
||||
};
|
||||
|
||||
#endif // RADIOSWITCH_H
|
||||
@ -1,20 +1,17 @@
|
||||
#include "radiothermometer.h"
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
#include <QStringList>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "rfthermometer.h"
|
||||
|
||||
RFThermometer::RFThermometer(QObject *parent) :
|
||||
RadioThermometer::RadioThermometer(QObject *parent) :
|
||||
RadioPlugin(parent)
|
||||
{
|
||||
m_lastTemperature = -1111;
|
||||
m_delay = 0;
|
||||
m_binCode = 0;
|
||||
|
||||
}
|
||||
|
||||
QByteArray RFThermometer::getBinCode()
|
||||
QByteArray RadioThermometer::getBinCode()
|
||||
{
|
||||
if(m_binCode.isEmpty()){
|
||||
return NULL;
|
||||
@ -23,8 +20,7 @@ QByteArray RFThermometer::getBinCode()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool RFThermometer::isValid(QList<int> rawData)
|
||||
bool RadioThermometer::isValid(QList<int> rawData)
|
||||
{
|
||||
m_delay = rawData.first()/31;
|
||||
QByteArray binCode;
|
||||
@ -48,12 +44,12 @@ bool RFThermometer::isValid(QList<int> rawData)
|
||||
m_binCode = binCode;
|
||||
return true;
|
||||
}else{
|
||||
m_binCode = 0;
|
||||
m_binCode.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
float RFThermometer::getTemperature()
|
||||
float RadioThermometer::getTemperature()
|
||||
{
|
||||
// { ID },{-+}{ temp, },{Batt},{,temp}
|
||||
// "XXXX","XXXX","X XXX","XXXX","XXXX","XXXX",
|
||||
@ -70,6 +66,13 @@ float RFThermometer::getTemperature()
|
||||
QByteArray batteryBin(byteList.at(4));
|
||||
QByteArray temperatureTenthBin(byteList.at(5));
|
||||
|
||||
QByteArray id = byteList.at(0)+byteList.at(1);
|
||||
|
||||
// check if we have a sync signal (id = 11111111)
|
||||
if(id.contains("11111111")){
|
||||
qDebug() << "temperatursensor sync signal";
|
||||
return 0;
|
||||
}
|
||||
|
||||
// check sign of temperature -> if first bit of temperature byte is 1 -> temp is negativ
|
||||
int sign = 0;
|
||||
@ -104,10 +107,9 @@ float RFThermometer::getTemperature()
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
|
||||
QTextStream out(&file);
|
||||
|
||||
QByteArray id = byteList.at(0)+byteList.at(1);
|
||||
|
||||
out << timeStamp << "," << temperature << "," << batteryStatus << "\n";
|
||||
out << id << "," << timeStamp << "," << batteryStatus << "," << temperature << "," << "\n";
|
||||
file.close();
|
||||
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "| THERMOMETER signal |";
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
@ -116,7 +118,7 @@ float RFThermometer::getTemperature()
|
||||
qDebug() << byteList;
|
||||
qDebug() << timeStamp << " ID:" << id << " Temperature:" << temperature << " Battery OK: " << batteryStatus;
|
||||
|
||||
//emit temperatureSignalReceived(id,temperature,batteryStatus);
|
||||
emit temperatureSignalReceived(id,temperature,batteryStatus);
|
||||
return temperature;
|
||||
}
|
||||
}
|
||||
@ -1,15 +1,16 @@
|
||||
#ifndef RFTHERMOMETER_H
|
||||
#define RFTHERMOMETER_H
|
||||
#ifndef RADIOTHERMOMETER_H
|
||||
#define RADIOTHERMOMETER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <radio/plugins/radioplugin.h>
|
||||
#include <radioplugin/radioplugin.h>
|
||||
|
||||
#define RFThermometerDelay 250
|
||||
#define RadioThermometerDelay 250
|
||||
|
||||
class RFThermometer : public RadioPlugin
|
||||
class RadioThermometer : public RadioPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RFThermometer(QObject *parent = 0);
|
||||
explicit RadioThermometer(QObject *parent = 0);
|
||||
|
||||
QByteArray getBinCode();
|
||||
bool isValid(QList<int> rawData);
|
||||
@ -25,7 +26,6 @@ signals:
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // RFTHERMOMETER_H
|
||||
#endif // RADIOTHERMOMETER_H
|
||||
@ -29,16 +29,10 @@ DEPENDPATH += $$PWD/../../libhive
|
||||
SOURCES += main.cpp \
|
||||
hivecore.cpp \
|
||||
radio/radioreciver.cpp \
|
||||
radio/radiosender.cpp \
|
||||
radio/plugins/radioplugin.cpp \
|
||||
radio/plugins/rfthermometer.cpp \
|
||||
radio/plugins/rfswitch.cpp
|
||||
radio/radiosender.cpp
|
||||
|
||||
HEADERS += \
|
||||
hivecore.h \
|
||||
radio/radioreciver.h \
|
||||
radio/radiosender.h \
|
||||
radio/plugins/radioplugin.h \
|
||||
radio/plugins/rfthermometer.h \
|
||||
radio/plugins/rfswitch.h
|
||||
radio/radiosender.h
|
||||
|
||||
|
||||
@ -8,11 +8,8 @@ HiveCore::HiveCore(QObject *parent) :
|
||||
m_server = new Server(this);
|
||||
m_server->startServer();
|
||||
|
||||
//m_deviceManager = new DeviceManager(this);
|
||||
|
||||
m_jsonHandler = new JsonHandler(this);
|
||||
|
||||
|
||||
connect(m_server,SIGNAL(jsonDataAvailable(QByteArray)),m_jsonHandler,SLOT(process(QByteArray)));
|
||||
|
||||
|
||||
@ -20,7 +17,7 @@ HiveCore::HiveCore(QObject *parent) :
|
||||
// // create 433.92 MHz sender
|
||||
m_sender = new RadioSender(this);
|
||||
m_sender->setFrequency(RadioSender::RF433MHz);
|
||||
m_sender->setLineCode(RadioSender::REMOTE);
|
||||
m_sender->setLineCode(RadioSender::SWITCH);
|
||||
m_sender->setPulseLength(320);
|
||||
// //m_sender->sendBin("000000000000010101010001");
|
||||
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
#ifndef RFSWITCH_H
|
||||
#define RFSWITCH_H
|
||||
|
||||
#include <QObject>
|
||||
#include <radio/plugins/radioplugin.h>
|
||||
|
||||
#define RFSwitchDelay 320
|
||||
|
||||
class RFSwitch : public RadioPlugin
|
||||
{
|
||||
public:
|
||||
explicit RFSwitch(QObject *parent = 0);
|
||||
|
||||
QByteArray getBinCode();
|
||||
bool isValid(QList<int> rawData);
|
||||
|
||||
private:
|
||||
int m_delay;
|
||||
QByteArray m_binCode;
|
||||
|
||||
signals:
|
||||
void switchSignalReceived(const QByteArray &channel, const char &button, const bool &buttonStatus);
|
||||
|
||||
};
|
||||
|
||||
#endif // RFSWITCH_H
|
||||
@ -107,13 +107,15 @@ RadioReciver::RadioReciver(QObject *parent) :
|
||||
m_lastTime = 0;
|
||||
m_repeatCount = 0;
|
||||
|
||||
m_thermometer = new RFThermometer(this);
|
||||
m_switch = new RFSwitch(this);
|
||||
m_thermometer = new RadioThermometer(this);
|
||||
m_switch = new RadioSwitch(this);
|
||||
|
||||
for(int i = 0; i < RC_MAX_CHANGES; i++ ){
|
||||
m_timings[i] = 0;
|
||||
}
|
||||
|
||||
connect(m_thermometer,SIGNAL(temperatureSignalReceived(QByteArray,float,bool)),this,SIGNAL(temperatureSignalReceived(QByteArray,float,bool)));
|
||||
connect(m_switch,SIGNAL(switchSignalReceived(QByteArray,char,bool)),this,SIGNAL(switchSignalReceived(QByteArray,char,bool)));
|
||||
}
|
||||
|
||||
void RadioReciver::setFrequency(RadioReciver::Frequency frequency)
|
||||
@ -186,9 +188,15 @@ void RadioReciver::detectProtocol(QList<int> rawData)
|
||||
// check plugins
|
||||
if(m_thermometer->isValid(rawData)){
|
||||
m_thermometer->getTemperature();
|
||||
}
|
||||
}else
|
||||
if(m_switch->isValid(rawData)){
|
||||
m_switch->getBinCode();
|
||||
}else{
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "| GENERIC signal |";
|
||||
qDebug() << "-----------------------------------------------------------";
|
||||
qDebug() << "delay :" << rawData.first() /31;
|
||||
qDebug() << rawData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,8 +4,8 @@
|
||||
#define RC_MAX_CHANGES 49
|
||||
|
||||
#include <QObject>
|
||||
#include "radio/plugins/rfthermometer.h"
|
||||
#include "radio/plugins/rfswitch.h"
|
||||
#include "radioplugin/radioswitch.h"
|
||||
#include "radioplugin/radiothermometer.h"
|
||||
|
||||
class ISRHandler;
|
||||
|
||||
@ -40,8 +40,8 @@ private:
|
||||
unsigned long m_lastTime;
|
||||
unsigned int m_repeatCount;
|
||||
|
||||
RFThermometer *m_thermometer;
|
||||
RFSwitch *m_switch;
|
||||
RadioThermometer *m_thermometer;
|
||||
RadioSwitch *m_switch;
|
||||
|
||||
signals:
|
||||
void temperatureSignalReceived(const QByteArray &id, const float &temperature, const bool &batteryStatus);
|
||||
|
||||
@ -28,8 +28,8 @@ void RadioSender::sendSync()
|
||||
if(m_lineCode == RadioSender::DMANCHESTER){
|
||||
|
||||
}
|
||||
// sync for REMOTE: 1 high 31 low
|
||||
if(m_lineCode == RadioSender::REMOTE){
|
||||
// sync for SWITCH: 1 high 31 low
|
||||
if(m_lineCode == RadioSender::SWITCH){
|
||||
digitalWrite(m_pin,HIGH);
|
||||
delayMicroseconds(m_pulseLength);
|
||||
digitalWrite(m_pin,LOW);
|
||||
@ -64,8 +64,8 @@ void RadioSender::send0()
|
||||
if(m_lineCode == RadioSender::DMANCHESTER){
|
||||
|
||||
}
|
||||
// 0 in REMOTE encoding
|
||||
if(m_lineCode == RadioSender::REMOTE){
|
||||
// 0 in SWITCH encoding
|
||||
if(m_lineCode == RadioSender::SWITCH){
|
||||
digitalWrite(m_pin,HIGH);
|
||||
delayMicroseconds(m_pulseLength);
|
||||
digitalWrite(m_pin,LOW);
|
||||
@ -99,8 +99,8 @@ void RadioSender::send1()
|
||||
if(m_lineCode == RadioSender::DMANCHESTER){
|
||||
|
||||
}
|
||||
// 1 in REMOTE encoding
|
||||
if(m_lineCode == RadioSender::REMOTE){
|
||||
// 1 in SWITCH encoding
|
||||
if(m_lineCode == RadioSender::SWITCH){
|
||||
digitalWrite(m_pin,HIGH);
|
||||
delayMicroseconds(m_pulseLength*3);
|
||||
digitalWrite(m_pin,LOW);
|
||||
|
||||
@ -18,7 +18,7 @@ public:
|
||||
UNIPOLAR = 0x2,
|
||||
MANCHESTER = 0x3,
|
||||
DMANCHESTER = 0x4,
|
||||
REMOTE = 0x5,
|
||||
SWITCH = 0x5,
|
||||
THERMOMETER = 0x6,
|
||||
WEATHERSTATION = 0x7
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user