106 lines
1.8 KiB
C++
106 lines
1.8 KiB
C++
#include "Manager.h"
|
|
|
|
#ifdef ANDROID
|
|
#include <QtAndroidExtras/QAndroidJniObject>
|
|
#endif
|
|
|
|
#include <iostream>
|
|
#include <QDebug>
|
|
#include <sstream>
|
|
|
|
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";
|
|
|
|
Manager::Manager() {
|
|
|
|
|
|
}
|
|
|
|
void Manager::trigger() {
|
|
|
|
#ifdef ANDROID
|
|
|
|
QAndroidJniObject::callStaticMethod<int>("android/net/wifi/RTT", "start", "()I");
|
|
|
|
#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");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
void Manager::onData(std::string str) {
|
|
|
|
qDebug() << QString(str.c_str());
|
|
|
|
std::stringstream lineStream(str);
|
|
std::string cell;
|
|
|
|
std::string mac;
|
|
|
|
int distIndex = 0;
|
|
int i = 0;
|
|
const float alpha = 0.7f;
|
|
|
|
while (std::getline(lineStream, cell, ';')) {
|
|
|
|
switch(i) {
|
|
|
|
case 0: {
|
|
if(NUC1 == cell) {distIndex = 0;}
|
|
if(NUC2 == cell) {distIndex = 1;}
|
|
if(NUC3 == cell) {distIndex = 2;}
|
|
if(NUC4 == cell) {distIndex = 3;}
|
|
break;
|
|
}
|
|
|
|
case 1: {
|
|
if ("FAILED" == cell) {
|
|
_dist[distIndex] = 0;
|
|
} else {
|
|
//_dist[distIndex] = std::stoi(cell);
|
|
_dist[distIndex] = _dist[distIndex] * alpha + atoi(cell.c_str()) * (1-alpha);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 2: {
|
|
_stdDev[distIndex] = atoi(cell.c_str());
|
|
break;
|
|
}
|
|
|
|
}
|
|
++i;
|
|
}
|
|
|
|
emit distChanged();
|
|
|
|
}
|
|
|
|
Manager mgmt;
|
|
|
|
#ifdef ANDROID
|
|
extern "C" {
|
|
|
|
JNIEXPORT void JNICALL Java_android_net_wifi_RTT_onRTTComplete(JNIEnv* env, jobject jobj, jbyteArray arrayID) {
|
|
(void) env; (void) jobj;
|
|
jsize length = env->GetArrayLength(arrayID);
|
|
jbyte* data = env->GetByteArrayElements(arrayID, 0);
|
|
std::string str((char*)data, length);
|
|
env->ReleaseByteArrayElements(arrayID, data, JNI_ABORT);
|
|
mgmt.onData(str);
|
|
}
|
|
|
|
}
|
|
#endif
|