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;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
|
||||
class Manager : public QObject {
|
||||
|
||||
@@ -12,6 +13,8 @@ private:
|
||||
float _dist[4];
|
||||
float _stdDev[4];
|
||||
|
||||
std::shared_ptr<QFile> dataLogger;
|
||||
|
||||
public:
|
||||
|
||||
Q_PROPERTY(float dist1 READ getDist1() NOTIFY distChanged)
|
||||
@@ -26,6 +29,7 @@ public:
|
||||
|
||||
|
||||
Q_INVOKABLE void trigger();
|
||||
Q_INVOKABLE void stop();
|
||||
|
||||
void onData(std::string str);
|
||||
|
||||
|
||||
6
RTT.pro
6
RTT.pro
@@ -1,5 +1,8 @@
|
||||
QT += quick
|
||||
QT += androidextras
|
||||
|
||||
android {
|
||||
QT += androidextras
|
||||
}
|
||||
CONFIG += c++11
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
@@ -28,6 +31,7 @@ OTHER_FILES += \
|
||||
|
||||
# use files in ./_android for the project as well
|
||||
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/_android
|
||||
#ANDROID_PACKAGE_SOURCE_DIR =
|
||||
|
||||
|
||||
# Additional import path used to resolve QML modules in Qt Creator's code model
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package de.plinzen.android.rttmanager.permission;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.support.annotation.NonNull;
|
||||
//import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
//import android.Manifest;
|
||||
//import android.app.Activity;
|
||||
//import android.content.Context;
|
||||
//import android.content.pm.PackageManager;
|
||||
//import android.support.annotation.NonNull;
|
||||
////import android.support.design.widget.Snackbar;
|
||||
//import android.support.v4.app.ActivityCompat;
|
||||
//import android.support.v4.content.ContextCompat;
|
||||
//import android.view.View;
|
||||
|
||||
//import de.plinzen.android.rttmanager.R;
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.app.Activity;
|
||||
import android.util.Log;
|
||||
import android.content.Context;
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -30,6 +32,8 @@ public class RTT {
|
||||
private static Activity act;
|
||||
private static WifiRttManager rttManager;
|
||||
private static Executor mainExecutor;
|
||||
private static Thread ftmThread;
|
||||
private static boolean ftmRunning;
|
||||
|
||||
// called when a RTT is completed successfully
|
||||
public static native void onRTTComplete(final byte[] result);
|
||||
@@ -68,16 +72,27 @@ public class RTT {
|
||||
private static byte[] serialize(final RangingResult res) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
|
||||
char delim = ';';
|
||||
boolean success = res.getStatus() == RangingResult.STATUS_SUCCESS;
|
||||
|
||||
if (success) {
|
||||
baos.write(("" + res.getRangingTimestampMillis()).getBytes());
|
||||
baos.write(delim);
|
||||
} else {
|
||||
baos.write(("" + System.currentTimeMillis()).getBytes());
|
||||
baos.write(delim);
|
||||
}
|
||||
|
||||
baos.write(res.getMacAddress().toString().getBytes());
|
||||
baos.write(delim);
|
||||
|
||||
if (res.getStatus() == RangingResult.STATUS_SUCCESS) {
|
||||
if (success) {
|
||||
baos.write( ("" + res.getDistanceMm()).getBytes() );
|
||||
baos.write(delim);
|
||||
baos.write( ("" + res.getDistanceStdDevMm()).getBytes() );
|
||||
baos.write(delim);
|
||||
baos.write( ("" + res.getRssi()).getBytes() );
|
||||
|
||||
} else {
|
||||
baos.write( "FAILED".getBytes() );
|
||||
}
|
||||
@@ -89,6 +104,9 @@ public class RTT {
|
||||
|
||||
public static int start() {
|
||||
|
||||
if (ftmRunning)
|
||||
return 0;
|
||||
|
||||
Log.d("RTT", "start()");
|
||||
|
||||
MyActivity act = MyActivity.act;
|
||||
@@ -102,20 +120,32 @@ public class RTT {
|
||||
macs.add(MacAddress.fromString("1c:1b:b5:ef:a2:9a")); // NUC 3
|
||||
macs.add(MacAddress.fromString("1c:1b:b5:ec:d1:82")); // NUC 4
|
||||
|
||||
new Thread() {
|
||||
ftmRunning = true;
|
||||
|
||||
ftmThread = new Thread() {
|
||||
public void run() {
|
||||
while(true) {
|
||||
while(ftmRunning) {
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {;}
|
||||
startRangingOnMacs(macs);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
};
|
||||
|
||||
ftmThread.start();
|
||||
|
||||
return 1337;
|
||||
}
|
||||
|
||||
public static int stop() {
|
||||
Log.d("RTT", "stop()");
|
||||
|
||||
if (ftmRunning) {
|
||||
ftmRunning = false;
|
||||
}
|
||||
|
||||
return 1337*2;
|
||||
}
|
||||
|
||||
public static void startRangingOnMacs(final ArrayList<MacAddress> macs) {
|
||||
|
||||
Reference in New Issue
Block a user