Added data logging
This commit is contained in:
71
Manager.cpp
71
Manager.cpp
@@ -7,12 +7,29 @@
|
||||
#include <iostream>
|
||||
#include <QDebug>
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
#include <iomanip>
|
||||
|
||||
#include <QStandardPaths>
|
||||
#include <QtGlobal>
|
||||
#include <QDir>
|
||||
|
||||
const std::string NUC1 = "38:de:ad:6d:77:25";
|
||||
const std::string NUC2 = "38:de:ad:6d:60:ff";
|
||||
const std::string NUC3 = "1c:1b:b5:ef:a2:9a";
|
||||
const std::string NUC4 = "1c:1b:b5:ec:d1:82";
|
||||
|
||||
|
||||
static QString GetCurrentTimeForFileName()
|
||||
{
|
||||
auto time = std::time(nullptr);
|
||||
std::stringstream ss;
|
||||
ss << std::put_time(std::localtime(&time), "%F_%T"); // ISO 8601 without timezone information.
|
||||
auto s = ss.str();
|
||||
std::replace(s.begin(), s.end(), ':', '-');
|
||||
return QString::fromStdString(s);
|
||||
}
|
||||
|
||||
Manager::Manager() {
|
||||
|
||||
|
||||
@@ -20,6 +37,26 @@ Manager::Manager() {
|
||||
|
||||
void Manager::trigger() {
|
||||
|
||||
QString folder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/ftm/";
|
||||
|
||||
dataLogger = std::make_shared<QFile>(folder+"/ftm_"+GetCurrentTimeForFileName()+".txt");
|
||||
|
||||
if (!dataLogger->exists()) {
|
||||
// create the folder, if necessary
|
||||
QDir dir(folder);
|
||||
if (!dir.exists()) {
|
||||
qWarning("creating new folder");
|
||||
if (!dir.mkpath(".")) {
|
||||
qWarning() << "Failed to create new folder";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!dataLogger->open(QIODevice::ReadWrite)) {
|
||||
qWarning() << "Failed to create data logger file" << dataLogger->fileName();
|
||||
dataLogger = nullptr;
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
|
||||
QAndroidJniObject::callStaticMethod<int>("android/net/wifi/RTT", "start", "()I");
|
||||
@@ -27,22 +64,32 @@ void Manager::trigger() {
|
||||
#else
|
||||
|
||||
//onData("38:de:ad:6d:77:25;FAILED");
|
||||
onData(NUC1+";6230;1231");
|
||||
onData(NUC2+";3430;3423");
|
||||
onData(NUC3+";5630;2341");
|
||||
onData(NUC4+";8830;2241");
|
||||
onData("1337;"+NUC1+";6230;1231");
|
||||
onData("1337;"+NUC2+";3430;3423");
|
||||
onData("1337;"+NUC3+";5630;2341");
|
||||
onData("1337;"+NUC4+";8830;2241");
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void Manager::stop() {
|
||||
#ifdef ANDROID
|
||||
QAndroidJniObject::callStaticMethod<int>("android/net/wifi/RTT", "stop", "()I");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
dataLogger->flush();
|
||||
dataLogger->close();
|
||||
}
|
||||
|
||||
void Manager::onData(std::string str) {
|
||||
|
||||
qDebug() << QString(str.c_str());
|
||||
|
||||
if (dataLogger) {
|
||||
dataLogger->write(str.c_str());
|
||||
dataLogger->write("\n");
|
||||
}
|
||||
|
||||
std::stringstream lineStream(str);
|
||||
std::string cell;
|
||||
|
||||
@@ -57,6 +104,10 @@ void Manager::onData(std::string str) {
|
||||
switch(i) {
|
||||
|
||||
case 0: {
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
if(NUC1 == cell) {distIndex = 0;}
|
||||
if(NUC2 == cell) {distIndex = 1;}
|
||||
if(NUC3 == cell) {distIndex = 2;}
|
||||
@@ -64,7 +115,7 @@ void Manager::onData(std::string str) {
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: {
|
||||
case 2: {
|
||||
if ("FAILED" == cell) {
|
||||
_dist[distIndex] = 0;
|
||||
} else {
|
||||
@@ -74,11 +125,15 @@ void Manager::onData(std::string str) {
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
case 3: {
|
||||
_stdDev[distIndex] = atoi(cell.c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
case 4: {
|
||||
// RSSI
|
||||
}
|
||||
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user