summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--daemon/logger.cpp24
-rw-r--r--daemon/logger.h2
-rw-r--r--daemon/sensorPlugins/stepCounter.cpp5
-rw-r--r--daemon/sensorPlugins/stepCounter.h2
4 files changed, 28 insertions, 5 deletions
diff --git a/daemon/logger.cpp b/daemon/logger.cpp
index 65b5c2b..d4b4d14 100644
--- a/daemon/logger.cpp
+++ b/daemon/logger.cpp
@@ -35,6 +35,7 @@ Logger::Logger(QObject *parent) :
void Logger::setup() {
m_iface = new QDBusInterface("com.nokia.mce","/com/nokia/mce/signal", "com.nokia.mce.signal", QDBusConnection::systemBus());
settings = new QSettings;
+ daemonFresh = getDaemonFresh();
heartrateSensorEnabled = this->settings->value("heartrateSensor/enabled",true).toBool();
stepCounterEnabled = this->settings->value("stepCounter/enabled",true).toBool();
@@ -46,7 +47,7 @@ void Logger::setup() {
//initialise step counter
if (stepCounterEnabled) {
- m_stepCounter = new StepCounterPlugin(this,settings->value("stepCounter/interval",600000).toInt());
+ m_stepCounter = new StepCounterPlugin(this,settings->value("stepCounter/interval",600000).toInt(),daemonFresh);
}
if(!m_iface->isValid()) {
@@ -89,6 +90,26 @@ void Logger::triggerRecording() {
}
}
+bool Logger::getDaemonFresh() {
+ QFile file("/proc/sys/kernel/random/boot_id");
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ qDebug() << "failed to open bootId";
+ return 0;
+ }
+ QTextStream inStream(&file);
+ QString currBootId = inStream.readAll().trimmed();
+ file.close();
+ QSettings settings("asteroid","sensorlogd");
+ if(currBootId == settings.value("lastBootId","")) {
+ qDebug() << "daemon is not starting for first time this boot";
+ return false;
+ } else {
+ settings.setValue("lastBootId",currBootId);
+ qDebug() << "daemon is starting for first time this boot";
+ return true;
+ }
+}
+
void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime) { //adds a record to today's log file for the given sensor
qDebug() << fileNameForDate(recordTime.date(), sensorPrefix);
QFile file(fileNameForDate(recordTime.date(), sensorPrefix));
@@ -135,3 +156,4 @@ void setupFilePath(QString sensorPrefix) {
QDir::root().mkpath(settings.value("loggerRootPath",QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + sensorPrefix);
}
+
diff --git a/daemon/logger.h b/daemon/logger.h
index 515adb2..2eff33f 100644
--- a/daemon/logger.h
+++ b/daemon/logger.h
@@ -42,7 +42,9 @@ private:
HeartrateSensorPlugin *m_heartrateSensor;
bool stepCounterEnabled = false;
StepCounterPlugin *m_stepCounter;
+ bool daemonFresh;
QSettings *settings;
+ bool getDaemonFresh();
};
void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime = QDateTime::currentDateTime()); //adds a record to today's log file for the given sensor
diff --git a/daemon/sensorPlugins/stepCounter.cpp b/daemon/sensorPlugins/stepCounter.cpp
index 7dd8627..f502083 100644
--- a/daemon/sensorPlugins/stepCounter.cpp
+++ b/daemon/sensorPlugins/stepCounter.cpp
@@ -21,7 +21,7 @@
#include "stepCounter.h"
-StepCounterPlugin::StepCounterPlugin(QObject *parent, int initInterval) :
+StepCounterPlugin::StepCounterPlugin(QObject *parent, int initInterval, bool daemonFresh) :
QObject(parent){
interval = initInterval;
@@ -33,13 +33,12 @@ StepCounterPlugin::StepCounterPlugin(QObject *parent, int initInterval) :
connect(recordIntervalTimer,SIGNAL(timeout()),this,SLOT(triggerRecording()));
recordIntervalTimer->setSingleShot(true);
recordIntervalTimer->start(interval);
-
QDateTime currDateTime = QDateTime::currentDateTime();
setupFilePath(sensorPathPrefix);
while (!stepcounterSensor->isActive()) {}
- if (dayFileExists(sensorPathPrefix)) {
+ if (dayFileExists(sensorPathPrefix) && daemonFresh) {
QStringList lastLineData = fileGetPrevRecord(sensorPathPrefix);
lastRecordTime = QDateTime::currentDateTime();
stepcounterSensor->reading()->setSteps(lastLineData[1].toInt() + stepcounterSensor->reading()->steps()); // we add the last recorded value from today to the current value. This 'recovers' the steps from between reboots. I'm not sure how this will work on catfish or medaka.
diff --git a/daemon/sensorPlugins/stepCounter.h b/daemon/sensorPlugins/stepCounter.h
index 27dc01e..a6475f5 100644
--- a/daemon/sensorPlugins/stepCounter.h
+++ b/daemon/sensorPlugins/stepCounter.h
@@ -22,7 +22,7 @@ class StepCounterPlugin : public QObject
{
Q_OBJECT
public:
- explicit StepCounterPlugin(QObject *parent = 0, int initInterval = 600000);
+ explicit StepCounterPlugin(QObject *parent = 0, int initInterval = 600000, bool daemonFresh = false);
virtual ~StepCounterPlugin() {};
void timeUpdate();