From 162c92bc3b3a7dbe3d1484f7efc812aa36b23bcb Mon Sep 17 00:00:00 2001 From: Arseniy-Movshev Date: Sun, 2 Jul 2023 12:11:28 +0100 Subject: Move fileaddrecord to common.h so that it can be used from qml plugin --- common.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'common.cpp') diff --git a/common.cpp b/common.cpp index 077bc4d..4c0f252 100644 --- a/common.cpp +++ b/common.cpp @@ -10,9 +10,24 @@ #include #include +#include +#include #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(); +} -- cgit v1.2.3-54-g00ecf