diff options
author | Arseniy-Movshev <dodoradio@outlook.com> | 2023-05-28 14:08:57 +0100 |
---|---|---|
committer | Arseniy-Movshev <dodoradio@outlook.com> | 2023-05-28 15:43:22 +0100 |
commit | e228f65119bef5ba2e0a26c0f9c53d5c3f131463 (patch) | |
tree | cbe6d40a2e4e5b23f1022bc3180d55712c207990 /daemon | |
parent | 521c01825badf77c65a1389109e2f4967cde154d (diff) |
Allow sensorlogd to set up its directory structure
This code sets up all the paths used by sensorlogd before it is started
Diffstat (limited to '')
-rw-r--r-- | daemon/logger.cpp | 6 | ||||
-rw-r--r-- | daemon/logger.h | 1 | ||||
-rw-r--r-- | daemon/sensorPlugins/heartrateSensor.cpp | 2 | ||||
-rw-r--r-- | daemon/sensorPlugins/stepCounter.cpp | 2 |
4 files changed, 11 insertions, 0 deletions
diff --git a/daemon/logger.cpp b/daemon/logger.cpp index 56d1c3c..7222c95 100644 --- a/daemon/logger.cpp +++ b/daemon/logger.cpp @@ -14,6 +14,7 @@ #include <QDBusConnection> #include <QDateTime> #include <QFile> +#include <QDir> #include <QTextStream> #include <QStandardPaths> #include <QTimer> @@ -116,3 +117,8 @@ QStringList fileGetPrevRecord(QString sensorPrefix, QDateTime recordTime) { QString fileNameForDate(QDate date, QString prefix) { return QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/asteroid-healthloggerd/" + prefix + "/" + date.toString("yyyy-MM-dd.log"); } + +void setupFilePath(QString sensorPrefix) { + QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/asteroid-healthloggerd/" + sensorPrefix); +} + diff --git a/daemon/logger.h b/daemon/logger.h index 6047a04..7bfe06b 100644 --- a/daemon/logger.h +++ b/daemon/logger.h @@ -48,5 +48,6 @@ private: bool dayFileExists(QString sensorPrefix, QDateTime date = QDateTime::currentDateTime()); //check if today has a log file for the given sensor QStringList fileGetPrevRecord(QString sensorPrefix, QDateTime recordTime = QDateTime::currentDateTime()); //works backwards to find the last record in today's file before the given time - returns nothing if no file is found. QString fileNameForDate(QDate date, QString prefix); + void setupFilePath(QString sensorPrefix); //sets up the paths for sensors to write into #endif // LOGGER_H diff --git a/daemon/sensorPlugins/heartrateSensor.cpp b/daemon/sensorPlugins/heartrateSensor.cpp index cf3bfb4..8b329b9 100644 --- a/daemon/sensorPlugins/heartrateSensor.cpp +++ b/daemon/sensorPlugins/heartrateSensor.cpp @@ -26,6 +26,8 @@ HeartrateSensorPlugin::HeartrateSensorPlugin(QObject *parent, int initInterval) hrmSensor = new QHrmSensor(this); connect(hrmSensor,SIGNAL(readingChanged()),this,SLOT(finishRecording())); + setupFilePath(sensorPathPrefix); + qDebug() << "heartrate sensor is enabled. interval is (ms) " << interval; recordIntervalTimer = new QTimer(this); connect(recordIntervalTimer,SIGNAL(timeout()),this,SLOT(triggerRecording())); diff --git a/daemon/sensorPlugins/stepCounter.cpp b/daemon/sensorPlugins/stepCounter.cpp index 8bfed03..fe8370c 100644 --- a/daemon/sensorPlugins/stepCounter.cpp +++ b/daemon/sensorPlugins/stepCounter.cpp @@ -33,6 +33,8 @@ StepCounterPlugin::StepCounterPlugin(QObject *parent, int initInterval) : QDateTime currDateTime = QDateTime::currentDateTime(); + setupFilePath(sensorPathPrefix); + if (dayFileExists(sensorPathPrefix)) { QStringList lastLineData = fileGetPrevRecord(sensorPathPrefix); lastRecordTime = QDateTime::fromSecsSinceEpoch(lastLineData[0].toInt()); |