summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArseniy-Movshev <dodoradio@outlook.com>2023-07-02 12:11:28 +0100
committerArseniy-Movshev <dodoradio@outlook.com>2023-07-02 12:12:53 +0100
commit162c92bc3b3a7dbe3d1484f7efc812aa36b23bcb (patch)
treeeb4c4fe2638229f03adb220b5f0b2090ce670514
parente1617431b4d1ef72c96d89d0754d42ed0e2cdb24 (diff)
Move fileaddrecord to common.h so that it can be used from qml plugin
Diffstat (limited to '')
-rw-r--r--common.cpp15
-rw-r--r--common.h1
-rw-r--r--daemon/logger.cpp12
-rw-r--r--daemon/logger.h1
-rw-r--r--daemon/sensorPlugins/heartrateSensor.cpp1
-rw-r--r--daemon/sensorPlugins/stepCounter.cpp1
6 files changed, 18 insertions, 13 deletions
diff --git a/common.cpp b/common.cpp
index 077bc4d..4c0f252 100644
--- a/common.cpp
+++ b/common.cpp
@@ -10,9 +10,24 @@
#include <QSettings>
#include <QStandardPaths>
+#include <QFile>
+#include <QDebug>
#include "common.h"
QString fileNameForDate(QDate date, QString prefix) {
QSettings settings("asteroid", "sensorlogd"); // this should be moved out of here at some point TODO
return settings.value("loggerRootPath", QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.asteroid-sensorlogd/").toString() + prefix + "/" + date.toString("yyyy-MM-dd.log");
}
+
+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));
+ if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
+ qDebug() << "failed to open file";
+ return;
+ }
+ file.seek(file.size());
+ QTextStream out(&file);
+ out << QString::number(recordTime.currentSecsSinceEpoch()) + ":" + logdata + "\n";
+ file.close();
+}
diff --git a/common.h b/common.h
index 573b006..a6b3197 100644
--- a/common.h
+++ b/common.h
@@ -15,5 +15,6 @@
#include <QString>
QString fileNameForDate(QDate date, QString prefix);
+void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime = QDateTime::currentDateTime()); //adds a record to today's log file for the given sensor
#endif //SENSORLOGD_COMMON_H
diff --git a/daemon/logger.cpp b/daemon/logger.cpp
index e8f75ba..7e06c63 100644
--- a/daemon/logger.cpp
+++ b/daemon/logger.cpp
@@ -111,18 +111,6 @@ bool Logger::getDaemonFresh() {
}
}
-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));
- if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) {
- qDebug() << "failed to open file";
- return;
- }
- file.seek(file.size());
- QTextStream out(&file);
- out << QString::number(recordTime.currentSecsSinceEpoch()) + ":" + logdata + "\n";
- file.close();
-}
bool dayFileExists(QString sensorPrefix, QDateTime dateTime) {
return QFile::exists(fileNameForDate(dateTime.date(), sensorPrefix));
}
diff --git a/daemon/logger.h b/daemon/logger.h
index 328c0d7..c16908d 100644
--- a/daemon/logger.h
+++ b/daemon/logger.h
@@ -47,7 +47,6 @@ private:
bool getDaemonFresh();
};
- void fileAddRecord(QString sensorPrefix, QString logdata, QDateTime recordTime = QDateTime::currentDateTime()); //adds a record to today's log file for the given sensor
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.
void setupFilePath(QString sensorPrefix); //sets up the paths for sensors to write into
diff --git a/daemon/sensorPlugins/heartrateSensor.cpp b/daemon/sensorPlugins/heartrateSensor.cpp
index 8b329b9..d03703c 100644
--- a/daemon/sensorPlugins/heartrateSensor.cpp
+++ b/daemon/sensorPlugins/heartrateSensor.cpp
@@ -16,6 +16,7 @@
#include <QString>
#include "../logger.h"
+#include "../../common.h"
#include "heartrateSensor.h"
diff --git a/daemon/sensorPlugins/stepCounter.cpp b/daemon/sensorPlugins/stepCounter.cpp
index fd09e81..87c1c3c 100644
--- a/daemon/sensorPlugins/stepCounter.cpp
+++ b/daemon/sensorPlugins/stepCounter.cpp
@@ -19,6 +19,7 @@
#include <time.h>
#include "../logger.h"
+#include "../../common.h"
#include "stepCounter.h"