added optional repetition value for rf433 transmitting
This commit is contained in:
parent
a4b51ccdcc
commit
25fd83e648
@ -117,18 +117,18 @@ void Radio433::brennenstuhlAvailableChanged(const bool &available)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Returns true, if the \a rawData with a certain \a delay (pulse length) can be sent. */
|
/*! Returns true, if the \a rawData with a certain \a delay (pulse length) could be sent \a repetitions times. */
|
||||||
bool Radio433::sendData(int delay, QList<int> rawData)
|
bool Radio433::sendData(int delay, QList<int> rawData, int repetitions)
|
||||||
{
|
{
|
||||||
bool sendGpio = false;
|
bool sendGpio = false;
|
||||||
bool sendBrennenstuhl = false;
|
bool sendBrennenstuhl = false;
|
||||||
|
|
||||||
if (m_brennenstuhlTransmitter->available()) {
|
if (m_brennenstuhlTransmitter->available()) {
|
||||||
sendBrennenstuhl = m_brennenstuhlTransmitter->sendData(delay, rawData);
|
sendBrennenstuhl = m_brennenstuhlTransmitter->sendData(delay, rawData, repetitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_transmitter->available()) {
|
if (m_transmitter->available()) {
|
||||||
m_transmitter->sendData(delay, rawData);
|
m_transmitter->sendData(delay, rawData, repetitions);
|
||||||
sendGpio = true;
|
sendGpio = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,7 +48,7 @@ private slots:
|
|||||||
void brennenstuhlAvailableChanged(const bool &available);
|
void brennenstuhlAvailableChanged(const bool &available);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool sendData(int delay, QList<int> rawData);
|
bool sendData(int delay, QList<int> rawData, int repetitions);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -36,11 +36,11 @@ Radio433BrennenstuhlGateway::Radio433BrennenstuhlGateway(QObject *parent) :
|
|||||||
// Timer to detect discovery timeout
|
// Timer to detect discovery timeout
|
||||||
m_timeout = new QTimer(this);
|
m_timeout = new QTimer(this);
|
||||||
m_timeout->setSingleShot(true);
|
m_timeout->setSingleShot(true);
|
||||||
m_timeout->setInterval(1000);
|
m_timeout->setInterval(1500);
|
||||||
connect(m_timeout, &QTimer::timeout, this, &Radio433BrennenstuhlGateway::timeout);
|
connect(m_timeout, &QTimer::timeout, this, &Radio433BrennenstuhlGateway::timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Radio433BrennenstuhlGateway::sendData(int delay, QList<int> rawData)
|
bool Radio433BrennenstuhlGateway::sendData(int delay, QList<int> rawData, int repetitions)
|
||||||
{
|
{
|
||||||
QByteArray data;
|
QByteArray data;
|
||||||
QByteArray message;
|
QByteArray message;
|
||||||
@ -64,7 +64,7 @@ bool Radio433BrennenstuhlGateway::sendData(int delay, QList<int> rawData)
|
|||||||
* ; | end of command
|
* ; | end of command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
message.append("TXP:0,0,20,0," + QString::number(delay) + "," + QString::number(rawData.count()/2) + "," + data + ";");
|
message.append("TXP:0,0," + QString::number(repetitions) + ",0," + QString::number(delay) + "," + QString::number(rawData.count()/2) + "," + data + ";");
|
||||||
|
|
||||||
if (m_gateway->writeDatagram(message, m_gatewayAddress, m_port) > 0) {
|
if (m_gateway->writeDatagram(message, m_gatewayAddress, m_port) > 0) {
|
||||||
m_available = true;
|
m_available = true;
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class Radio433BrennenstuhlGateway : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit Radio433BrennenstuhlGateway(QObject *parent = 0);
|
explicit Radio433BrennenstuhlGateway(QObject *parent = 0);
|
||||||
|
|
||||||
bool sendData(int delay, QList<int> rawData);
|
bool sendData(int delay, QList<int> rawData, int repetitions);
|
||||||
bool enable();
|
bool enable();
|
||||||
bool disable();
|
bool disable();
|
||||||
bool available();
|
bool available();
|
||||||
|
|||||||
@ -53,15 +53,13 @@ void Radio433Trasmitter::run()
|
|||||||
m_gpio->setValue(LOW);
|
m_gpio->setValue(LOW);
|
||||||
int flag=1;
|
int flag=1;
|
||||||
|
|
||||||
// send raw data 10 times
|
foreach (int delay, rawData) {
|
||||||
for(int i = 0; i < 10; i++){
|
// 1 = High, 0 = Low
|
||||||
foreach (int delay, rawData) {
|
m_gpio->setValue(flag %2);
|
||||||
// 1 = High, 0 = Low
|
flag++;
|
||||||
m_gpio->setValue(flag %2);
|
usleep(delay);
|
||||||
flag++;
|
|
||||||
usleep(delay);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_gpio->setValue(LOW);
|
m_gpio->setValue(LOW);
|
||||||
}
|
}
|
||||||
m_queueMutex.unlock();
|
m_queueMutex.unlock();
|
||||||
@ -86,11 +84,13 @@ bool Radio433Trasmitter::setUpGpio()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Radio433Trasmitter::sendData(int delay, QList<int> rawData)
|
void Radio433Trasmitter::sendData(int delay, QList<int> rawData, int repetitions)
|
||||||
{
|
{
|
||||||
QList<int> timings;
|
QList<int> timings;
|
||||||
foreach (int data, rawData) {
|
for (int i = 0; i < repetitions; i++) {
|
||||||
timings.append(delay*data);
|
foreach (int data, rawData) {
|
||||||
|
timings.append(delay*data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_queueMutex.lock();
|
m_queueMutex.lock();
|
||||||
|
|||||||
@ -38,7 +38,7 @@ public:
|
|||||||
bool startTransmitter();
|
bool startTransmitter();
|
||||||
bool available();
|
bool available();
|
||||||
|
|
||||||
void sendData(int delay, QList<int> rawData);
|
void sendData(int delay, QList<int> rawData, int repetitions);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void run();
|
void run();
|
||||||
|
|||||||
@ -493,11 +493,11 @@ Device *DevicePlugin::findDeviceByParams(const ParamList ¶ms) const
|
|||||||
|
|
||||||
\sa Radio433, requiredHardware()
|
\sa Radio433, requiredHardware()
|
||||||
*/
|
*/
|
||||||
bool DevicePlugin::transmitData(int delay, QList<int> rawData)
|
bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
|
||||||
{
|
{
|
||||||
switch (requiredHardware()) {
|
switch (requiredHardware()) {
|
||||||
case DeviceManager::HardwareResourceRadio433:
|
case DeviceManager::HardwareResourceRadio433:
|
||||||
return deviceManager()->m_radio433->sendData(delay, rawData);
|
return deviceManager()->m_radio433->sendData(delay, rawData, repetitions);
|
||||||
case DeviceManager::HardwareResourceRadio868:
|
case DeviceManager::HardwareResourceRadio868:
|
||||||
qDebug() << "Radio868 not connected yet";
|
qDebug() << "Radio868 not connected yet";
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -89,7 +89,7 @@ protected:
|
|||||||
QList<Device*> myDevices() const;
|
QList<Device*> myDevices() const;
|
||||||
Device* findDeviceByParams(const ParamList ¶ms) const;
|
Device* findDeviceByParams(const ParamList ¶ms) const;
|
||||||
|
|
||||||
bool transmitData(int delay, QList<int> rawData);
|
bool transmitData(int delay, QList<int> rawData, int repetitions = 10);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initPlugin(const QJsonObject &metaData, DeviceManager *deviceManager);
|
void initPlugin(const QJsonObject &metaData, DeviceManager *deviceManager);
|
||||||
|
|||||||
@ -78,7 +78,7 @@ DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, con
|
|||||||
QByteArray binCode;
|
QByteArray binCode;
|
||||||
|
|
||||||
|
|
||||||
// TODO: find out how ID will be calculated to bin code or make it discoverable
|
// TODO: find out how the ID will be calculated to bin code or make it discoverable
|
||||||
// =======================================
|
// =======================================
|
||||||
// bincode depending on the ID
|
// bincode depending on the ID
|
||||||
if (device->paramValue("ID") == "0115"){
|
if (device->paramValue("ID") == "0115"){
|
||||||
@ -104,6 +104,8 @@ DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, con
|
|||||||
//create rawData timings list
|
//create rawData timings list
|
||||||
int delay = 200;
|
int delay = 200;
|
||||||
|
|
||||||
|
int repetitions = 20;
|
||||||
|
|
||||||
// sync signal (starting with ON)
|
// sync signal (starting with ON)
|
||||||
rawData.append(1);
|
rawData.append(1);
|
||||||
rawData.append(10);
|
rawData.append(10);
|
||||||
@ -124,15 +126,15 @@ DeviceManager::DeviceError DevicePluginLeynew::executeAction(Device *device, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << binCode;
|
qDebug() << binCode;
|
||||||
qDebug() << rawData;
|
qDebug() << delay << "*" << rawData;
|
||||||
|
|
||||||
// =======================================
|
// =======================================
|
||||||
// send data to hardware resource
|
// send data to hardware resource
|
||||||
if(transmitData(delay, rawData)){
|
if(transmitData(delay, rawData, repetitions)){
|
||||||
qDebug() << "transmitted" << pluginName() << device->name() << action.param("name").name();
|
qDebug() << "transmitted" << pluginName() << device->name() << action.id();
|
||||||
return DeviceManager::DeviceErrorNoError;
|
return DeviceManager::DeviceErrorNoError;
|
||||||
}else{
|
}else{
|
||||||
qDebug() << "could not transmitt" << pluginName() << device->name() << action.param("name").name();
|
qDebug() << "could not transmitt" << pluginName() << device->name() << action.id();
|
||||||
return DeviceManager::DeviceErrorHardwareNotAvailable;
|
return DeviceManager::DeviceErrorHardwareNotAvailable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user