Merge PR #557: OneWire: Make owfs more robust against occational read errors
This commit is contained in:
commit
20c51eea0c
@ -185,8 +185,12 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info)
|
||||
qCDebug(dcOneWire) << "Setup one wire switch" << thing->params();
|
||||
if (m_owfsInterface) {
|
||||
QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray();
|
||||
thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A));
|
||||
thing->setStateValue(singleChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
bool ok;
|
||||
bool output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, output);
|
||||
}
|
||||
}
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
|
||||
@ -194,9 +198,16 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info)
|
||||
qCDebug(dcOneWire) << "Setup one wire dual switch" << thing->params();
|
||||
if (m_owfsInterface) {
|
||||
QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray();
|
||||
thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A));
|
||||
thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B));
|
||||
thing->setStateValue(dualChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
bool ok;
|
||||
bool output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, output);
|
||||
}
|
||||
}
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
|
||||
@ -204,15 +215,40 @@ void IntegrationPluginOneWire::setupThing(ThingSetupInfo *info)
|
||||
qCDebug(dcOneWire) << "Setup one wire eight channel switch" << thing->params();
|
||||
if (m_owfsInterface) {
|
||||
QByteArray address = thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray();
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_C));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_D));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_E));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H));
|
||||
thing->setStateValue(eightChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
bool ok;
|
||||
bool output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_C, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_D, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_E, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, output);
|
||||
}
|
||||
}
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
} else {
|
||||
@ -323,7 +359,11 @@ void IntegrationPluginOneWire::setupOwfsTemperatureSensor(ThingSetupInfo *info)
|
||||
QByteArray address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray();
|
||||
if (m_owfsInterface) {
|
||||
thing->setStateValue(temperatureSensorConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
thing->setStateValue(temperatureSensorTemperatureStateTypeId, m_owfsInterface->getTemperature(address));
|
||||
bool ok;
|
||||
double temp = m_owfsInterface->getTemperature(address, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(temperatureSensorTemperatureStateTypeId, temp);
|
||||
}
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
} else {
|
||||
qCWarning(dcOneWire()) << "OWFS interface is not available";
|
||||
@ -337,8 +377,15 @@ void IntegrationPluginOneWire::setupOwfsTemperatureHumiditySensor(ThingSetupInfo
|
||||
QByteArray address = thing->paramValue(temperatureHumiditySensorThingAddressParamTypeId).toByteArray();
|
||||
if (m_owfsInterface) {
|
||||
thing->setStateValue(temperatureHumiditySensorConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
thing->setStateValue(temperatureHumiditySensorTemperatureStateTypeId, m_owfsInterface->getTemperature(address));
|
||||
thing->setStateValue(temperatureHumiditySensorHumidityStateTypeId, m_owfsInterface->getHumidity(address));
|
||||
bool ok;
|
||||
double temp = m_owfsInterface->getTemperature(address, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(temperatureHumiditySensorTemperatureStateTypeId, temp);
|
||||
}
|
||||
double humidity = m_owfsInterface->getHumidity(address, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(temperatureHumiditySensorHumidityStateTypeId, humidity);
|
||||
}
|
||||
return info->finish(Thing::ThingErrorNoError);
|
||||
} else {
|
||||
qCWarning(dcOneWire()) << "OWFS interface is not available";
|
||||
@ -354,13 +401,15 @@ void IntegrationPluginOneWire::onPluginTimer()
|
||||
|
||||
} else if (thing->thingClassId() == temperatureSensorThingClassId) {
|
||||
QByteArray address = thing->paramValue(temperatureSensorThingAddressParamTypeId).toByteArray();
|
||||
bool ok = true;
|
||||
double temperature = 0;
|
||||
bool connected = false;
|
||||
|
||||
if (!thing->parentId().isNull()) {
|
||||
if (m_owfsInterface) {
|
||||
temperature = m_owfsInterface->getTemperature(address);
|
||||
connected = m_owfsInterface->isConnected(address);
|
||||
bool ok;
|
||||
temperature = m_owfsInterface->getTemperature(address, &ok);
|
||||
} else {
|
||||
qCWarning(dcOneWire()) << "onPlugInTimer: OWFS interface not setup for thing" << thing->name();
|
||||
}
|
||||
@ -370,40 +419,85 @@ void IntegrationPluginOneWire::onPluginTimer()
|
||||
connected = m_w1Interface->deviceAvailable(address);
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
thing->setStateValue(temperatureSensorTemperatureStateTypeId, temperature);
|
||||
}
|
||||
thing->setStateValue(temperatureSensorConnectedStateTypeId, connected);
|
||||
} else if (thing->thingClassId() == temperatureHumiditySensorThingClassId) {
|
||||
if (!m_owfsInterface)
|
||||
continue;
|
||||
QByteArray address = thing->paramValue(temperatureHumiditySensorThingAddressParamTypeId).toByteArray();
|
||||
thing->setStateValue(temperatureHumiditySensorTemperatureStateTypeId, m_owfsInterface->getTemperature(address));
|
||||
thing->setStateValue(temperatureHumiditySensorHumidityStateTypeId, m_owfsInterface->getHumidity(address));
|
||||
bool ok;
|
||||
double temp = m_owfsInterface->getTemperature(address, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(temperatureHumiditySensorTemperatureStateTypeId, temp);
|
||||
}
|
||||
double humidity = m_owfsInterface->getHumidity(address, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(temperatureHumiditySensorHumidityStateTypeId, humidity);
|
||||
}
|
||||
thing->setStateValue(temperatureHumiditySensorConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
} else if (thing->thingClassId() == singleChannelSwitchThingClassId) {
|
||||
if (!m_owfsInterface)
|
||||
continue;
|
||||
QByteArray address = thing->paramValue(singleChannelSwitchThingAddressParamTypeId).toByteArray();
|
||||
thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A));
|
||||
bool ok;
|
||||
bool output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(singleChannelSwitchDigitalOutputStateTypeId, output);
|
||||
}
|
||||
thing->setStateValue(singleChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
} else if (thing->thingClassId() == dualChannelSwitchThingClassId) {
|
||||
if (!m_owfsInterface)
|
||||
continue;
|
||||
QByteArray address = thing->paramValue(dualChannelSwitchThingAddressParamTypeId).toByteArray();
|
||||
thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A));
|
||||
thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B));
|
||||
bool ok;
|
||||
bool output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(dualChannelSwitchDigitalOutput1StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(dualChannelSwitchDigitalOutput2StateTypeId, output);
|
||||
}
|
||||
thing->setStateValue(dualChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
} else if (thing->thingClassId() == eightChannelSwitchThingClassId) {
|
||||
if (!m_owfsInterface)
|
||||
continue;
|
||||
QByteArray address = thing->paramValue(eightChannelSwitchThingAddressParamTypeId).toByteArray();
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_C));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_D));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_E));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G));
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H));
|
||||
bool ok;
|
||||
bool output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_A, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput1StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_B, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput2StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_C, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput3StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_D, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput4StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_E, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput5StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_F, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput6StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_G, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput7StateTypeId, output);
|
||||
}
|
||||
output = m_owfsInterface->getSwitchOutput(address, Owfs::SwitchChannel::PIO_H, &ok);
|
||||
if (ok) {
|
||||
thing->setStateValue(eightChannelSwitchDigitalOutput8StateTypeId, output);
|
||||
}
|
||||
thing->setStateValue(eightChannelSwitchConnectedStateTypeId, m_owfsInterface->isConnected(address));
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,8 @@
|
||||
#include "owfs.h"
|
||||
#include "w1.h"
|
||||
|
||||
#include "extern-plugininfo.h"
|
||||
|
||||
#include <QHash>
|
||||
|
||||
class IntegrationPluginOneWire : public IntegrationPlugin
|
||||
|
||||
@ -175,18 +175,18 @@ void Owfs::setValue(const QByteArray &address, const QByteArray &type, const QBy
|
||||
}
|
||||
}
|
||||
|
||||
double Owfs::getTemperature(const QByteArray &address)
|
||||
double Owfs::getTemperature(const QByteArray &address, bool *ok)
|
||||
{
|
||||
QByteArray temperature = getValue(address, "temperature");
|
||||
qDebug(dcOneWire()) << "Temperature" << temperature << temperature.replace(',','.').toDouble();
|
||||
return temperature.toDouble();
|
||||
return temperature.toDouble(ok);
|
||||
}
|
||||
|
||||
double Owfs::getHumidity(const QByteArray &address)
|
||||
double Owfs::getHumidity(const QByteArray &address, bool *ok)
|
||||
{
|
||||
QByteArray humidity = getValue(address, "humidity");
|
||||
qDebug(dcOneWire()) << "Humidity" << humidity << humidity.replace(',','.').toDouble();
|
||||
return humidity.toDouble();
|
||||
return humidity.toDouble(ok);
|
||||
}
|
||||
|
||||
QByteArray Owfs::getType(const QByteArray &address)
|
||||
@ -195,7 +195,7 @@ QByteArray Owfs::getType(const QByteArray &address)
|
||||
return type;
|
||||
}
|
||||
|
||||
bool Owfs::getSwitchOutput(const QByteArray &address, SwitchChannel channel)
|
||||
bool Owfs::getSwitchOutput(const QByteArray &address, SwitchChannel channel, bool *ok)
|
||||
{
|
||||
QByteArray c;
|
||||
c.append("PIO.");
|
||||
@ -227,10 +227,10 @@ bool Owfs::getSwitchOutput(const QByteArray &address, SwitchChannel channel)
|
||||
}
|
||||
QByteArray state = getValue(address, c);
|
||||
qDebug(dcOneWire()) << "Switch state" << state.toInt();
|
||||
return state.toInt();
|
||||
return state.toInt(ok);
|
||||
}
|
||||
|
||||
bool Owfs::getSwitchInput(const QByteArray &address, SwitchChannel channel)
|
||||
bool Owfs::getSwitchInput(const QByteArray &address, SwitchChannel channel, bool *ok)
|
||||
{
|
||||
QByteArray c;
|
||||
c.append("sensed.");
|
||||
@ -262,7 +262,7 @@ bool Owfs::getSwitchInput(const QByteArray &address, SwitchChannel channel)
|
||||
}
|
||||
QByteArray state = getValue(address, c);
|
||||
qDebug(dcOneWire()) << "Switch state" << state.toInt();
|
||||
return state.toInt();
|
||||
return state.toInt(ok);
|
||||
}
|
||||
|
||||
void Owfs::setSwitchOutput(const QByteArray &address, SwitchChannel channel, bool state)
|
||||
|
||||
@ -75,12 +75,12 @@ public:
|
||||
bool interfaceIsAvailable();
|
||||
bool isConnected(const QByteArray &address);
|
||||
|
||||
double getTemperature(const QByteArray &address);
|
||||
double getHumidity(const QByteArray &address);
|
||||
double getTemperature( const QByteArray &address, bool *ok);
|
||||
double getHumidity(const QByteArray &address, bool *ok);
|
||||
QByteArray getType(const QByteArray &address);
|
||||
bool getSwitchOutput(const QByteArray &address, SwitchChannel channel);
|
||||
bool getSwitchOutput(const QByteArray &address, SwitchChannel channel, bool *ok);
|
||||
void setSwitchOutput(const QByteArray &address, SwitchChannel channel, bool state);
|
||||
bool getSwitchInput(const QByteArray &address, SwitchChannel channel);
|
||||
bool getSwitchInput(const QByteArray &address, SwitchChannel channel, bool *ok);
|
||||
|
||||
private:
|
||||
QByteArray m_path;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user