initial version
This commit is contained in:
49
_android/AndroidManifest.xml
Normal file
49
_android/AndroidManifest.xml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<manifest package="java.indoor" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
|
||||||
|
|
||||||
|
<uses-sdk android:minSdkVersion="16"/>
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||||
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
<uses-permission android:name="android.permission.BODY_SENSORS"/>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
|
||||||
|
|
||||||
|
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
|
||||||
|
|
||||||
|
<application android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="@string/app_name">
|
||||||
|
|
||||||
|
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="our.java.stuff.MyActivity" android:label="TEST" android:screenOrientation="unspecified">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
|
||||||
|
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
|
||||||
|
<meta-data android:name="android.app.repository" android:value="default"/>
|
||||||
|
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
|
||||||
|
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
|
||||||
|
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
|
||||||
|
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
|
||||||
|
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
|
||||||
|
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
|
||||||
|
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
|
||||||
|
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
|
||||||
|
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
|
||||||
|
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
|
||||||
|
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
|
||||||
|
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
|
||||||
|
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
23
_android/src/MyActivity.java
Normal file
23
_android/src/MyActivity.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package our.java.stuff;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import org.qtproject.qt5.android.bindings.QtActivity;
|
||||||
|
|
||||||
|
public class MyActivity extends QtActivity {
|
||||||
|
|
||||||
|
public static MyActivity act;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedState) {
|
||||||
|
MyActivity.act = this;
|
||||||
|
super.onCreate(savedState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
MyActivity.act = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
101
_android/src/WiFi.java
Normal file
101
_android/src/WiFi.java
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
package java.indoor;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.net.wifi.ScanResult;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Debug;
|
||||||
|
import android.util.Log;
|
||||||
|
import java.util.List;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
|
public class WiFi {
|
||||||
|
|
||||||
|
private static Activity act;
|
||||||
|
private static WifiManager manager;
|
||||||
|
private static BroadcastReceiver receiver;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** called when a scan is completed successfully */
|
||||||
|
public static native void onScanComplete(final byte[] result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* start WiFi scanning in the background.
|
||||||
|
* will call onScanComplete() once a scan is available
|
||||||
|
*/
|
||||||
|
public static int start() {
|
||||||
|
|
||||||
|
Log.d("wifi", "start()");
|
||||||
|
|
||||||
|
MyActivity act = MyActivity.act;
|
||||||
|
manager = (WifiManager) act.getSystemService(Context.WIFI_SERVICE);
|
||||||
|
|
||||||
|
reset();
|
||||||
|
|
||||||
|
WiFi.receiver = new BroadcastReceiver() {
|
||||||
|
public final void onReceive(final Context context, final Intent intent) {
|
||||||
|
final byte[] result = serialize(manager.getScanResults());
|
||||||
|
WiFi.onScanComplete(result);
|
||||||
|
triggerOneScan();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// register scan callback
|
||||||
|
act.registerReceiver(WiFi.receiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
|
||||||
|
|
||||||
|
// start the first scan
|
||||||
|
triggerOneScan();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** convert the given scan-result to a binary byte[] representation */
|
||||||
|
private static byte[] serialize(final List<ScanResult> lst) {
|
||||||
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
try {
|
||||||
|
for (final ScanResult res : lst) {
|
||||||
|
baos.write(res.BSSID.getBytes());
|
||||||
|
baos.write((byte)res.level);
|
||||||
|
baos.write((byte)0);
|
||||||
|
baos.write((byte)0);
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {;}
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** reset the WiFi subsystem (better scanning) */
|
||||||
|
private static void reset() {
|
||||||
|
WiFi.manager.disconnect();
|
||||||
|
WiFi.manager.createWifiLock(manager.WIFI_MODE_SCAN_ONLY, "Indoor");
|
||||||
|
//WiFi.manager.setWifiEnabled(false);
|
||||||
|
//WiFi.manager.setWifiEnabled(true);
|
||||||
|
WiFi.manager.disconnect();
|
||||||
|
WiFi.manager.disconnect();
|
||||||
|
WiFi.manager.disconnect();
|
||||||
|
WiFi.manager.disconnect();
|
||||||
|
WiFi.manager.disconnect();
|
||||||
|
WiFi.manager.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** try to trigger one scan process */
|
||||||
|
private static void triggerOneScan() {
|
||||||
|
|
||||||
|
Log.d("wifi", "triggerOneScan()");
|
||||||
|
|
||||||
|
try {
|
||||||
|
if(!manager.startScan()) {throw new RuntimeException("Cant start WiFi!");}
|
||||||
|
}catch (final Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
13
deployment.pri
Normal file
13
deployment.pri
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
unix:!android {
|
||||||
|
isEmpty(target.path) {
|
||||||
|
qnx {
|
||||||
|
target.path = /tmp/$${TARGET}/bin
|
||||||
|
} else {
|
||||||
|
target.path = /opt/$${TARGET}/bin
|
||||||
|
}
|
||||||
|
export(target.path)
|
||||||
|
}
|
||||||
|
INSTALLS += target
|
||||||
|
}
|
||||||
|
|
||||||
|
export(INSTALLS)
|
||||||
51
main.cpp
Normal file
51
main.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
|
||||||
|
|
||||||
|
#include "sensors/SensorFactory.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class LeListener : public SensorListener<WiFiSensorData>, public SensorListener<AccelerometerData>, public SensorListener<StepData> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void onSensorData(const WiFiSensorData& data) override {
|
||||||
|
const std::string str = "\n" + data.asString();
|
||||||
|
qDebug(str.c_str());
|
||||||
|
}
|
||||||
|
void onSensorData(const AccelerometerData& data) override {
|
||||||
|
const std::string str = data.asString();
|
||||||
|
qDebug(str.c_str());
|
||||||
|
}
|
||||||
|
void onSensorData(const StepData& data) override {
|
||||||
|
qDebug("STEP!");
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
// test();
|
||||||
|
LeListener listener;
|
||||||
|
WiFiSensor& wifi = SensorFactory::getWiFi();
|
||||||
|
wifi.addListener(&listener);
|
||||||
|
wifi.start();
|
||||||
|
|
||||||
|
// AccelerometerSensor& acc = SensorFactory::getAccelerometer();
|
||||||
|
// acc.addListener(&listener);
|
||||||
|
// acc.start();
|
||||||
|
|
||||||
|
StepSensor& steps = SensorFactory::getSteps();
|
||||||
|
steps.addListener(&listener);
|
||||||
|
steps.start();;
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(10000));
|
||||||
|
|
||||||
|
// QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
|
// QQmlApplicationEngine engine;
|
||||||
|
// engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||||
|
|
||||||
|
// return app.exec();
|
||||||
|
|
||||||
|
}
|
||||||
16
misc/Debug.h
Normal file
16
misc/Debug.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef DEBUG_H
|
||||||
|
#define DEBUG_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
class Debug {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static void error(const std::string& err) {
|
||||||
|
qDebug(err.c_str());
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEBUG_H
|
||||||
13
misc/fixc11.h
Normal file
13
misc/fixc11.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef FIXC11_H
|
||||||
|
#define FIXC11_H
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
//namespace std {
|
||||||
|
|
||||||
|
// template <typename T> T sqrt(const T val) {return ::sqrt(val);}
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FIXC11_H
|
||||||
6
qml.qrc
Normal file
6
qml.qrc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>main.qml</file>
|
||||||
|
<file>MainForm.ui.qml</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
22
sensors/AccelerometerSensor.h
Normal file
22
sensors/AccelerometerSensor.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#ifndef ACCELEROMETERSENSOR_H
|
||||||
|
#define ACCELEROMETERSENSOR_H
|
||||||
|
|
||||||
|
#include "Sensor.h"
|
||||||
|
|
||||||
|
struct AccelerometerData {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
AccelerometerData(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
|
||||||
|
std::string asString() const {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "(" << x << "," << y << "," << z << ")";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class AccelerometerSensor : public Sensor<AccelerometerData> {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ACCELEROMETERSENSOR_H
|
||||||
50
sensors/Sensor.h
Normal file
50
sensors/Sensor.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#ifndef SENSOR_H
|
||||||
|
#define SENSOR_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
/** listen for sensor events */
|
||||||
|
template <typename T> class SensorListener {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** incoming sensor data */
|
||||||
|
virtual void onSensorData(const T& data) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/** base-class for all sensors */
|
||||||
|
template <typename T> class Sensor {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector<SensorListener<T>*> listeners;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** start this sensor */
|
||||||
|
virtual void start() = 0;
|
||||||
|
|
||||||
|
/** stop this sensor */
|
||||||
|
virtual void stop() = 0;
|
||||||
|
|
||||||
|
/** add the given listener to the sensor */
|
||||||
|
void addListener(SensorListener<T>* l) {
|
||||||
|
listeners.push_back(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/** inform all attached listeners */
|
||||||
|
void informListeners(const T& sensorData) const {
|
||||||
|
for (SensorListener<T>* l : listeners) {
|
||||||
|
l->onSensorData(sensorData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SENSOR_H
|
||||||
47
sensors/SensorFactory.h
Normal file
47
sensors/SensorFactory.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#ifndef SENSORFACTORY_H
|
||||||
|
#define SENSORFACTORY_H
|
||||||
|
|
||||||
|
#include "Sensor.h"
|
||||||
|
|
||||||
|
#include "WiFiSensor.h"
|
||||||
|
#include "dummy/WiFiSensorDummy.h"
|
||||||
|
#include "linux/WiFiSensorLinux.h"
|
||||||
|
#include "android/WiFiSensorAndroid.h"
|
||||||
|
|
||||||
|
#include "AccelerometerSensor.h"
|
||||||
|
#include "dummy/AccelerometerSensorDummy.h"
|
||||||
|
#include "android/AccelerometerSensorAndroid.h"
|
||||||
|
|
||||||
|
#include "StepSensor.h"
|
||||||
|
|
||||||
|
class SensorFactory {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** get the WiFi sensor */
|
||||||
|
static WiFiSensor& getWiFi() {
|
||||||
|
#ifdef ANDROID
|
||||||
|
return WiFiSensorAndroid::get();
|
||||||
|
#else
|
||||||
|
return WiFiSensorDummy::get();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/** get the Accelerometer sensor */
|
||||||
|
static AccelerometerSensor& getAccelerometer() {
|
||||||
|
#ifdef ANDROID
|
||||||
|
return AccelerometerSensor::get();
|
||||||
|
#else
|
||||||
|
return AccelerometerSensorDummy::get();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/** get the Step sensor */
|
||||||
|
static StepSensor& getSteps() {
|
||||||
|
static StepSensor steps(getAccelerometer());
|
||||||
|
return steps;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SENSORFACTORY_H
|
||||||
66
sensors/StepSensor.h
Normal file
66
sensors/StepSensor.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#ifndef STEPSENSOR_H
|
||||||
|
#define STEPSENSOR_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "../misc/fixc11.h"
|
||||||
|
#include "AccelerometerSensor.h"
|
||||||
|
#include "Sensor.h"
|
||||||
|
|
||||||
|
struct StepData {
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
|
class StepSensor : public Sensor<StepData>, public SensorListener<AccelerometerData> {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
AccelerometerSensor& acc;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** hidden ctor. use singleton */
|
||||||
|
StepSensor(AccelerometerSensor& acc) : acc(acc) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() override {
|
||||||
|
acc.addListener(this);
|
||||||
|
acc.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() override {
|
||||||
|
throw "todo";
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void onSensorData(const AccelerometerData& data) override {
|
||||||
|
parse(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
const float threshold = 11.0;
|
||||||
|
const int blockTime = 25;
|
||||||
|
int block = 0;
|
||||||
|
|
||||||
|
void parse(const AccelerometerData& data) {
|
||||||
|
|
||||||
|
const float x = data.x;
|
||||||
|
const float y = data.y;
|
||||||
|
const float z = data.z;
|
||||||
|
|
||||||
|
const float mag = std::sqrt( (x*x) + (y*y) + (z*z) );
|
||||||
|
|
||||||
|
if (block > 0) {
|
||||||
|
--block;
|
||||||
|
} else if (mag > threshold) {
|
||||||
|
informListeners(StepData());
|
||||||
|
block = blockTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // STEPSENSOR_H
|
||||||
43
sensors/WiFiSensor.h
Normal file
43
sensors/WiFiSensor.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#ifndef WIFISENSOR_H
|
||||||
|
#define WIFISENSOR_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include "Sensor.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct WiFiSensorDataEntry {
|
||||||
|
std::string bssid;
|
||||||
|
float rssi;
|
||||||
|
WiFiSensorDataEntry(const std::string& bssid, const float rssi) : bssid(bssid), rssi(rssi) {;}
|
||||||
|
std::string asString() const {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << bssid << '\t' << (int)rssi;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct WiFiSensorData {
|
||||||
|
std::vector<WiFiSensorDataEntry> entries;
|
||||||
|
std::string asString() const {
|
||||||
|
std::stringstream ss;
|
||||||
|
for(const WiFiSensorDataEntry& e : entries) {ss << e.asString() << '\n';}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/** interface for all wifi sensors */
|
||||||
|
class WiFiSensor : public Sensor<WiFiSensorData> {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
/** hidden ctor. use SensorFactory */
|
||||||
|
WiFiSensor() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WIFISENSOR_H
|
||||||
55
sensors/android/AccelerometerSensorAndroid.h
Normal file
55
sensors/android/AccelerometerSensorAndroid.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#ifndef ACCELEROMETERSENSOR_H
|
||||||
|
#define ACCELEROMETERSENSOR_H
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "../AccelerometerSensor.h"
|
||||||
|
|
||||||
|
#include <QtSensors/QAccelerometer>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class AccelerometerSensorAndroid : public AccelerometerSensor {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QAccelerometer acc;
|
||||||
|
|
||||||
|
/** hidden ctor. use singleton */
|
||||||
|
AccelerometerSensorAndroid() {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** singleton access */
|
||||||
|
static AccelerometerSensor& get() {
|
||||||
|
static AccelerometerSensor acc;
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() override {
|
||||||
|
|
||||||
|
auto onSensorData = [&] () {
|
||||||
|
AccelerometerData data(acc.reading()->x(), acc.reading()->y(), acc.reading()->z());
|
||||||
|
informListeners(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
acc.connect(&acc, &QAccelerometer::readingChanged, onSensorData);
|
||||||
|
acc.start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() override {
|
||||||
|
throw "todo";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif ANDROID
|
||||||
|
|
||||||
|
#endif // ACCELEROMETERSENSOR_H
|
||||||
76
sensors/android/WiFiSensorAndroid.h
Normal file
76
sensors/android/WiFiSensorAndroid.h
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
#ifndef WIFISENSORANDROID_H
|
||||||
|
#define WIFISENSORANDROID_H
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
|
||||||
|
#include <QAndroidJniObject>
|
||||||
|
|
||||||
|
#include "Debug.h"
|
||||||
|
#include "WiFiSensor.h"
|
||||||
|
|
||||||
|
class WiFiSensorAndroid : public WiFiSensor {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/** hidden ctor. use singleton! */
|
||||||
|
WiFiSensorAndroid() {;}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** singleton access */
|
||||||
|
static WiFiSensorAndroid& get() {
|
||||||
|
static WiFiSensorAndroid wifi;
|
||||||
|
return wifi;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() override {
|
||||||
|
|
||||||
|
// start scanning
|
||||||
|
int res = QAndroidJniObject::callStaticMethod<int>("java/indoor/WiFi", "start", "()I");
|
||||||
|
(void) res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** called from java. handle the given incoming scan result */
|
||||||
|
void handle(const std::string& data) {
|
||||||
|
|
||||||
|
// to-be-constructed sensor data
|
||||||
|
WiFiSensorData sensorData;
|
||||||
|
|
||||||
|
// parse each mac->rssi entry
|
||||||
|
for (int i = 0; i < (int)data.length(); i += 17+1+2) {
|
||||||
|
const std::string bssid = data.substr(i, 17);
|
||||||
|
const int8_t rssi = data[i+17];
|
||||||
|
const int8_t pad1 = data[i+18];
|
||||||
|
const int8_t pad2 = data[i+19];
|
||||||
|
if (pad1 != 0 || pad2 != 0) {Debug::error("padding error within WiFi scan result");}
|
||||||
|
sensorData.entries.push_back(WiFiSensorDataEntry(bssid, rssi));
|
||||||
|
}
|
||||||
|
|
||||||
|
// call listeners
|
||||||
|
informListeners(sensorData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
/** called after each successful WiFi scan */
|
||||||
|
JNIEXPORT void JNICALL Java_java_indoor_WiFi_onScanComplete(JNIEnv* env, jobject jobj, jbyteArray arrayID) {
|
||||||
|
(void) env; (void) jobj;
|
||||||
|
jsize length = env->GetArrayLength(arrayID);
|
||||||
|
jboolean isCopy;
|
||||||
|
jbyte* data = env->GetByteArrayElements(arrayID, &isCopy);
|
||||||
|
std::string str((char*)data, length);
|
||||||
|
env->ReleaseByteArrayElements(arrayID, data, JNI_ABORT);
|
||||||
|
WiFiSensorAndroid::get().handle(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // WIFISENSORANDROID_H
|
||||||
27
sensors/dummy/AccelerometerSensorDummy.h
Normal file
27
sensors/dummy/AccelerometerSensorDummy.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef ACCELEROMETERSENSORDUMMY_H
|
||||||
|
#define ACCELEROMETERSENSORDUMMY_H
|
||||||
|
|
||||||
|
#include "../AccelerometerSensor.h"
|
||||||
|
|
||||||
|
class AccelerometerSensorDummy : public AccelerometerSensor {
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** singleton access */
|
||||||
|
static AccelerometerSensorDummy& get() {
|
||||||
|
static AccelerometerSensorDummy acc;
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() override {
|
||||||
|
//throw "todo";
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() override {
|
||||||
|
throw "todo";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ACCELEROMETERSENSORDUMMY_H
|
||||||
92
sensors/dummy/WiFiSensorDummy.h
Normal file
92
sensors/dummy/WiFiSensorDummy.h
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#ifndef WIFISENSORDUMMY_H
|
||||||
|
#define WIFISENSORDUMMY_H
|
||||||
|
|
||||||
|
#include "../WiFiSensor.h"
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#include <Indoor/geo/Point3.h>
|
||||||
|
#include <Indoor/sensors/radio/model/LogDistanceModel.h>
|
||||||
|
|
||||||
|
#include <Indoor/grid/Grid.h>
|
||||||
|
#include <Indoor/grid/factory/v2/GridFactory.h>
|
||||||
|
|
||||||
|
|
||||||
|
class WiFiSensorDummy : public WiFiSensor {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
bool enabled;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
/** singleton access */
|
||||||
|
static WiFiSensorDummy& get() {
|
||||||
|
static WiFiSensorDummy wifi;
|
||||||
|
return wifi;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void start() override {
|
||||||
|
|
||||||
|
enabled = true;
|
||||||
|
std::thread t(&WiFiSensorDummy::simulate, this);
|
||||||
|
t.detach();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() override {
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
struct DummyAP {
|
||||||
|
std::string mac;
|
||||||
|
Point2 pos;
|
||||||
|
DummyAP(const std::string mac, const Point2 pos) : mac(mac), pos(pos) {;}
|
||||||
|
};
|
||||||
|
|
||||||
|
void simulate() {
|
||||||
|
|
||||||
|
std::vector<DummyAP> aps;
|
||||||
|
aps.push_back(DummyAP("00:00:00:00:00:01", Point2(0, 0)));
|
||||||
|
aps.push_back(DummyAP("00:00:00:00:00:02", Point2(20, 0)));
|
||||||
|
aps.push_back(DummyAP("00:00:00:00:00:03", Point2(10, 20)));
|
||||||
|
|
||||||
|
float deg = 0;
|
||||||
|
|
||||||
|
while(enabled) {
|
||||||
|
|
||||||
|
// wait
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
|
||||||
|
// circle-run around center
|
||||||
|
deg += M_PI * 0.4;
|
||||||
|
|
||||||
|
const float cx = 10;
|
||||||
|
const float cy = 10;
|
||||||
|
const float rad = 5;
|
||||||
|
|
||||||
|
const float x = cx + std::sin(deg) * rad;
|
||||||
|
const float y = cy + std::cos(deg) * rad;
|
||||||
|
|
||||||
|
// construct scan data
|
||||||
|
WiFiSensorData scan;
|
||||||
|
for (DummyAP& ap : aps) {
|
||||||
|
const float dist = ap.pos.getDistance(Point2(x, y));
|
||||||
|
const float rssi = LogDistanceModel::distanceToRssi(-40, 1.5, dist);
|
||||||
|
scan.entries.push_back(WiFiSensorDataEntry(ap.mac, rssi));
|
||||||
|
}
|
||||||
|
|
||||||
|
// call
|
||||||
|
informListeners(scan);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WIFISENSORDUMMY_H
|
||||||
33
sensors/linux/WiFiSensorLinux.h
Normal file
33
sensors/linux/WiFiSensorLinux.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef WIFISENSORLINUX_H
|
||||||
|
#define WIFISENSORLINUX_H
|
||||||
|
|
||||||
|
#include "../WiFiSensor.h"
|
||||||
|
|
||||||
|
class WiFiSensorLinux : public WiFiSensor {
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
WiFiSensorLinux() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** singleton access */
|
||||||
|
static WiFiSensorLinux& get() {
|
||||||
|
static WiFiSensorLinux wifi;
|
||||||
|
return wifi;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() override {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() override {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WIFISENSORLINUX_H
|
||||||
54
yasmin.pro
Normal file
54
yasmin.pro
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
QT += qml
|
||||||
|
|
||||||
|
# android?
|
||||||
|
#QT += androidextras sensors
|
||||||
|
#DEFINES += ANDROID
|
||||||
|
|
||||||
|
CONFIG += c++11
|
||||||
|
|
||||||
|
# use files in ./_android for the project as well
|
||||||
|
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/_android
|
||||||
|
|
||||||
|
INCLUDEPATH += \
|
||||||
|
../
|
||||||
|
|
||||||
|
OTHER_FILES += \
|
||||||
|
_android/src/WiFi.java \
|
||||||
|
_android/AndroidManifest.xml
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
main.cpp \
|
||||||
|
|
||||||
|
RESOURCES += qml.qrc
|
||||||
|
|
||||||
|
# Additional import path used to resolve QML modules in Qt Creator's code model
|
||||||
|
QML_IMPORT_PATH =
|
||||||
|
|
||||||
|
# Default rules for deployment.
|
||||||
|
include(deployment.pri)
|
||||||
|
|
||||||
|
target.path = $$[QT_INSTALL_EXAMPLES]/androidextras/notification
|
||||||
|
INSTALLS += target
|
||||||
|
|
||||||
|
#DISTFILES += \
|
||||||
|
# android-sources/AndroidManifest.xml \
|
||||||
|
# android-sources/src/WiFi.java
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
sensors/linux/WiFiSensorLinux.h \
|
||||||
|
sensors/android/WiFiSensorAndroid.h \
|
||||||
|
sensors/StepSensor.h \
|
||||||
|
sensors/AccelerometerSensor.h \
|
||||||
|
sensors/android/AccelerometerSensorAndroid.h \
|
||||||
|
sensors/dummy/AccelerometerSensorDummy.h \
|
||||||
|
sensors/Sensor.h \
|
||||||
|
sensors/SensorFactory.h \
|
||||||
|
sensors/WiFiSensor.h \
|
||||||
|
misc/Debug.h \
|
||||||
|
misc/fixc11.h \
|
||||||
|
sensors/dummy/WiFiSensorDummy.h
|
||||||
|
|
||||||
|
DISTFILES += \
|
||||||
|
android-sources/src/MyActivity.java
|
||||||
Reference in New Issue
Block a user