Skip to content

Commit

Permalink
- Fixes for downsampling
Browse files Browse the repository at this point in the history
 - Refactoring
  • Loading branch information
Antti Virtanen committed Mar 15, 2011
1 parent 98bd5b2 commit 196a9cc
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 58 deletions.
4 changes: 2 additions & 2 deletions adaptors/accelerometeradaptor/accelerometeradaptor.cpp
Expand Up @@ -51,8 +51,8 @@ AccelerometerAdaptor::AccelerometerAdaptor(const QString& id) :
// Set Metadata
setDescription("Input device accelerometer adaptor (lis302d)");
introduceAvailableDataRange(DataRange(-2048, 2048, 1));
//int ranges[] = {0, 10, 20, 25, 40, 50, 100, 200, 250, 500, 1000};
int ranges[] = {0, 10, 20, 100, 500, 1000};
int ranges[] = {0, 10, 20, 25, 40, 50, 100, 200, 250, 500, 1000};
//int ranges[] = {0, 10, 20, 100, 500, 1000};
for(size_t i = 0; i < sizeof(ranges); ++i)
{
introduceAvailableInterval(DataRange(ranges[i], ranges[i], 0));
Expand Down
12 changes: 4 additions & 8 deletions adaptors/magnetometeradaptor/magnetometeradaptor.cpp
Expand Up @@ -42,10 +42,8 @@ struct ak8974_data {
}; //__attribute__((packed)); <-- documentation states that this is a nogo for c++

MagnetometerAdaptor::MagnetometerAdaptor(const QString& id) :
SysfsAdaptor(id, SysfsAdaptor::IntervalMode, false),
originalPollingRate_(1000)
SysfsAdaptor(id, SysfsAdaptor::IntervalMode, false)
{

driverHandle_ = getDriverHandle();
if (driverHandle_.size() == 0) {
sensordLogW() << "Input device not found.";
Expand Down Expand Up @@ -74,7 +72,7 @@ MagnetometerAdaptor::~MagnetometerAdaptor()
delete magnetometerBuffer_;
}

QString MagnetometerAdaptor::getDriverHandle()
QString MagnetometerAdaptor::getDriverHandle() const
{
QString magFile = Config::configuration()->value("mag_ak8974_dev_path").toString();
if (magFile.size() > 0 && QFile::exists(magFile)) {
Expand Down Expand Up @@ -118,16 +116,14 @@ void MagnetometerAdaptor::processSample(int pathId, int fd)

magnetometerBuffer_->commit();
magnetometerBuffer_->wakeUpReaders();

}

bool MagnetometerAdaptor::setInterval(const unsigned int value, const int sessionId)
{
if(driverHandle_.contains("8975"))
{
// Driver spends approximately 16ms between starting the read to returning
// Compensating here.
return SysfsAdaptor::setInterval(value>16 ? value-16 : 0, sessionId);
// Driver spends approximately 16ms between starting the read to returning.
return SysfsAdaptor::setInterval(value > 16 ? value - 16 : 0, sessionId);
}
return SysfsAdaptor::setInterval(value, sessionId);
}
10 changes: 2 additions & 8 deletions adaptors/magnetometeradaptor/magnetometeradaptor.h
Expand Up @@ -30,15 +30,13 @@
#include "sysfsadaptor.h"
#include "deviceadaptorringbuffer.h"
#include "datatypes/genericdata.h"
#include <QTime>
#include <QString>

/**
* @brief Adaptor for internal magnetometer.
*
* Uses Input Device system as driver interface. Measures values from the magnetometer
* with sysfsadaptor IntervalMode.
*
*/
class MagnetometerAdaptor : public SysfsAdaptor
{
Expand All @@ -62,7 +60,6 @@ class MagnetometerAdaptor : public SysfsAdaptor
MagnetometerAdaptor(const QString& id);
~MagnetometerAdaptor();


bool setInterval(const unsigned int value, const int sessionId);

private:
Expand All @@ -81,13 +78,10 @@ class MagnetometerAdaptor : public SysfsAdaptor
*
* @return Location of magnetometer driver handle.
*/
QString getDriverHandle();
QString getDriverHandle() const;

QTime time;
DeviceAdaptorRingBuffer<TimedXyzData>* magnetometerBuffer_;
int originalPollingRate_;
QString driverHandle_;
DeviceAdaptorRingBuffer<TimedXyzData>* magnetometerBuffer_;
};

#endif

2 changes: 1 addition & 1 deletion config/90-sensord-default.conf
Expand Up @@ -37,7 +37,7 @@ orientation_threshold_landscape = 25
orientation_threshold_portrait = 20
orientation_overflow_min = 800
orientation_overflow_max = 1250
orientation_poll_interval = 150
orientation_poll_interval = 200
orientation_buffer_size = 2

# Offset for Screen.TopEdge. If 0, Screen.TopEdge equals side edges from
Expand Down
31 changes: 20 additions & 11 deletions core/abstractsensor.cpp
Expand Up @@ -9,6 +9,7 @@
@author Joep van Gassel <joep.van.gassel@nokia.com>
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down Expand Up @@ -46,15 +47,16 @@ AbstractSensorChannel::AbstractSensorChannel(const QString& id) :

void AbstractSensorChannel::setError(SensorError errorCode, const QString& errorString)
{
sensordLogC() << "SensorError:" << errorString;
sensordLogC() << "SensorError: " << errorString;

errorCode_ = errorCode;
errorString_ = errorString;

emit errorSignal(errorCode);
}

bool AbstractSensorChannel::start(int sessionId) {
bool AbstractSensorChannel::start(int sessionId)
{
if (!(activeSessions_.contains(sessionId))) {
activeSessions_.append(sessionId);
}
Expand Down Expand Up @@ -102,20 +104,21 @@ bool AbstractSensorChannel::writeToClients(const void* source, int size)

bool AbstractSensorChannel::downsampleAndPropagate(const TimedXyzData& data, TimedXyzDownsampleBuffer& buffer)
{
bool ret = true;
foreach(const int& sessionId, activeSessions_)
{
if(!downsamplingEnabled(sessionId))
{
if (!(SensorManager::instance().write(sessionId, (const void*)(&data), sizeof(data))))
{
sensordLogD() << "AbstractSensor failed to write to session " << sessionId;
return false;
ret = false;
}
return true;
continue;
}
unsigned int currentInterval = interval();
unsigned int currentInterval = getInterval();
unsigned int sessionInterval = getInterval(sessionId);
int bufferSize = currentInterval / sessionInterval;
int bufferSize = sessionInterval / currentInterval;
if(!bufferSize)
bufferSize = 1;
QList<TimedXyzData>& samples(buffer[sessionId]);
Expand All @@ -124,7 +127,8 @@ bool AbstractSensorChannel::downsampleAndPropagate(const TimedXyzData& data, Tim
{
for(QList<TimedXyzData>::iterator it = samples.begin(); it != samples.end(); ++it)
{
if(samples.size() > bufferSize)
if(samples.size() > bufferSize ||
data.timestamp_ - it->timestamp_ > 2000000)
{
it = samples.erase(it);
if(it == samples.end())
Expand All @@ -133,7 +137,7 @@ bool AbstractSensorChannel::downsampleAndPropagate(const TimedXyzData& data, Tim
}
}
if(samples.size() < bufferSize)
return false;
continue;
long x = 0;
long y = 0;
long z = 0;
Expand All @@ -151,16 +155,21 @@ bool AbstractSensorChannel::downsampleAndPropagate(const TimedXyzData& data, Tim
if (!(SensorManager::instance().write(sessionId, (const void*)(&downsampled), sizeof(downsampled))))
{
sensordLogD() << "AbstractSensor failed to write to session " << sessionId;
return false;
ret = false;
continue;
}
samples.clear();
}
return true;
return ret;
}

void AbstractSensorChannel::setDownsamplingEnabled(int sessionId, bool value)
{
downsampling_[sessionId] = value;
if(downsamplingSupported())
{
sensordLogT() << "Downsampling state for session " << sessionId << ": " << value;
downsampling_[sessionId] = value;
}
}

bool AbstractSensorChannel::downsamplingEnabled(int sessionId)
Expand Down
4 changes: 3 additions & 1 deletion core/abstractsensor.h
Expand Up @@ -9,6 +9,7 @@
@author Joep van Gassel <joep.van.gassel@nokia.com>
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down Expand Up @@ -39,7 +40,8 @@
#include "datarange.h"
#include "genericdata.h"

class AbstractSensorChannel : public NodeBase {
class AbstractSensorChannel : public NodeBase
{
Q_OBJECT

Q_PROPERTY(bool isValid READ isValid)
Expand Down
2 changes: 1 addition & 1 deletion core/abstractsensor_a.cpp
Expand Up @@ -206,5 +206,5 @@ bool AbstractSensorChannelAdaptor::setDataRangeIndex(int sessionId, int rangeInd

void AbstractSensorChannelAdaptor::setDownsampling(int sessionId, bool value)
{
SensorManager::instance().socketHandler().setDownsampling(sessionId, value);
node()->setDownsamplingEnabled(sessionId, value);
}
5 changes: 3 additions & 2 deletions core/calibrationhandler.cpp
Expand Up @@ -67,7 +67,8 @@ bool CalibrationHandler::initiateSession()
if (m_sessionId <= 0)
{
sensordLogW() << "Failed to get session for magnetometersensor.";
} else
}
else
{
m_sensor = reinterpret_cast<MagnetometerSensorChannel*>(sm.getSensorInstance(m_sensorName).sensor_);
}
Expand Down Expand Up @@ -113,7 +114,7 @@ void CalibrationHandler::calibrationTimeout()

void CalibrationHandler::resumeCalibration()
{
sensordLogD() << "Resuming magnetometer background calibration.";
sensordLogD() << "Resuming magnetometer background calibration";
if (m_sensor && !m_timer.isActive())
{
m_sensor->start();
Expand Down
8 changes: 7 additions & 1 deletion core/nodebase.cpp
Expand Up @@ -213,9 +213,15 @@ unsigned int NodeBase::getInterval() const

unsigned int NodeBase::getInterval(int sessionId) const
{
if (!hasLocalInterval())
{
return m_intervalSource->getInterval(sessionId);
}
QMap<int, unsigned int>::const_iterator it(m_intervalMap.find(sessionId));
if(it == m_intervalMap.end())
{
return 0;
}
return it.value();
}

Expand All @@ -230,7 +236,7 @@ bool NodeBase::setIntervalRequest(const int sessionId, const unsigned int value)
// Validate interval request
if (!isValidIntervalRequest(value))
{
sensordLogD() << "Invalid interval requested.";
sensordLogW() << "Invalid interval requested for node '" << description() << "' by session '" << sessionId << "': " << value;
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions core/sockethandler.cpp
Expand Up @@ -42,7 +42,7 @@ SessionData::SessionData(QLocalSocket* socket, QObject* parent) : QObject(parent
count(0),
bufferSize(1),
bufferInterval(0),
downsampling(true)
downsampling(false)
{
lastWrite.tv_sec = 0;
lastWrite.tv_usec = 0;
Expand Down Expand Up @@ -104,7 +104,7 @@ bool SessionData::write(const void* source, int size)
if(bufferSize <= 1)
{
memcpy(buffer + sizeof(unsigned int), source, size);
if(downsampling && since >= interval)
if(!downsampling || (downsampling && since >= interval))
{
sensordLogT() << "[SocketHandler]: writing, since > interval or downsampling disabled";
gettimeofday(&lastWrite, 0);
Expand Down
1 change: 0 additions & 1 deletion core/sysfsadaptor.cpp
Expand Up @@ -433,7 +433,6 @@ void SysfsAdaptorReader::run()

// Read through all fds.
for (int i = 0; i < parent_->sysfsDescriptors_.size(); ++i) {

parent_->processSample(parent_->pathIds_.at(i), parent_->sysfsDescriptors_.at(i));

if (parent_->doSeek_)
Expand Down
7 changes: 2 additions & 5 deletions debian/changelog
Expand Up @@ -28,16 +28,13 @@ sensord (0.6.41) unstable; urgency=low
- AccelerometerAdaptor interval rangelist has been limited to certain sizes.
- AccelerometerSensorChannel downsamples data before propagating it.

[ Shenghua Liu ]
[Shenghua Liu]
* Make sensortestapp thread safe in exiting
* Fix sensord-tests-install
* Fix sensordtestapp for qt apt to print out proximity reflectance data
* Fix the Proximity metatype registration problem

[ shenghua ]
*

-- shenghua <shenghua@shenghua-ThinkPad-T43> Tue, 15 Mar 2011 17:53:25 +0200
-- Antti Virtanen <antti.i.virtanen@nokia.com> Tue, 15 Mar 2011 17:53:25 +0200

sensord (0.6.40) unstable; urgency=low

Expand Down
1 change: 1 addition & 0 deletions qt-api/abstractsensor_i.cpp
Expand Up @@ -332,6 +332,7 @@ void AbstractSensorChannelInterface::clearError()

void AbstractSensorChannelInterface::dataReceived()
{
qDebug() << "dataReceived";
do
{
if(!dataReceivedImpl())
Expand Down
1 change: 1 addition & 0 deletions sensors/accelerometersensor/accelerometersensor.cpp
Expand Up @@ -7,6 +7,7 @@
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down
1 change: 1 addition & 0 deletions sensors/accelerometersensor/accelerometersensor.h
Expand Up @@ -7,6 +7,7 @@
@author Timo Rongas <ext-timo.2.rongas@nokia.com>
@author Ustun Ergenoglu <ext-ustun.ergenoglu@nokia.com>
@author Antti Virtanen <antti.i.virtanen@nokia.com>
This file is part of Sensord.
Expand Down
7 changes: 5 additions & 2 deletions tests/testapp/abstractsensorhandler.cpp
Expand Up @@ -25,6 +25,7 @@

#include "abstractsensorhandler.h"
#include "config.h"
#include "logging.h"

AbstractSensorHandler::AbstractSensorHandler(const QString& sensorName, QObject *parent) :
QThread(parent),
Expand All @@ -34,14 +35,16 @@ AbstractSensorHandler::AbstractSensorHandler(const QString& sensorName, QObject
standbyoverride_(false),
buffersize_(0),
dataCount_(0),
frameCount_(0)
frameCount_(0),
downsample_(false)
{
if (Config::configuration() != NULL)
{
interval_ = Config::configuration()->value(sensorName_ + "/interval", "100").toInt();
bufferinterval_ = Config::configuration()->value(sensorName_ + "/bufferinterval", "0").toInt();
standbyoverride_ = Config::configuration()->value(sensorName_ + "/standbyoverride", "false").toBool();
standbyoverride_ = Config::configuration()->value(sensorName_ + "/standbyoverride", "0").toBool();
buffersize_ = Config::configuration()->value(sensorName_ + "/buffersize", "0").toInt();
downsample_ = Config::configuration()->value(sensorName_ + "/downsample", "0").toBool();
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/abstractsensorhandler.h
Expand Up @@ -28,7 +28,6 @@

#include <QThread>
#include <QString>
#include "qt-api/abstractsensor_i.h"

class AbstractSensorHandler : public QThread
{
Expand All @@ -52,6 +51,7 @@ class AbstractSensorHandler : public QThread
int buffersize_;
int dataCount_;
int frameCount_;
bool downsample_;
};

#endif // ABSTRACTSENSORHANDLER_H

0 comments on commit 196a9cc

Please sign in to comment.