diff options
author | Arseniy-Movshev <dodoradio@outlook.com> | 2023-07-02 12:11:28 +0100 |
---|---|---|
committer | Arseniy-Movshev <dodoradio@outlook.com> | 2023-07-02 12:12:53 +0100 |
commit | 162c92bc3b3a7dbe3d1484f7efc812aa36b23bcb (patch) | |
tree | eb4c4fe2638229f03adb220b5f0b2090ce670514 /common.cpp | |
parent | e1617431b4d1ef72c96d89d0754d42ed0e2cdb24 (diff) |
Move fileaddrecord to common.h so that it can be used from qml plugin
Diffstat (limited to '')
-rw-r--r-- | common.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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(); +} |