added the files
This commit is contained in:
12
sensors/BLESensor.h
Normal file
12
sensors/BLESensor.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef BLESENSOR_H
|
||||||
|
#define BLESENSOR_H
|
||||||
|
|
||||||
|
#include "Sensor.h"
|
||||||
|
#include <Indoor/sensors/beacon/Beacon.h>
|
||||||
|
#include <Indoor/sensors/beacon/BeaconMeasurements.h>
|
||||||
|
|
||||||
|
class BLESensor : public Sensor<BeaconMeasurement> {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BLESENSOR_H
|
||||||
82
sensors/android/BLESensorAndroid.h
Normal file
82
sensors/android/BLESensorAndroid.h
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#ifndef BLESENSORANDROID_H
|
||||||
|
#define BLESENSORANDROID_H
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ANDROID
|
||||||
|
|
||||||
|
#include <QAndroidJniObject>
|
||||||
|
|
||||||
|
#include "../../misc/Debug.h"
|
||||||
|
#include "../BLESensor.h"
|
||||||
|
#include <../misc/fixc11.h>
|
||||||
|
|
||||||
|
#include <Indoor/misc/Debug.h>
|
||||||
|
|
||||||
|
class BLESensorAndroid : public BLESensor {
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/** hidden ctor. use singleton! */
|
||||||
|
BLESensorAndroid() {;}
|
||||||
|
|
||||||
|
bool started = false;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** singleton access */
|
||||||
|
static BLESensorAndroid& get() {
|
||||||
|
static BLESensorAndroid beacon;
|
||||||
|
return beacon;
|
||||||
|
}
|
||||||
|
|
||||||
|
void start() override {
|
||||||
|
|
||||||
|
// do NOT start twice!
|
||||||
|
if (started) {return;}
|
||||||
|
started = true;
|
||||||
|
|
||||||
|
// start scanning
|
||||||
|
int res = QAndroidJniObject::callStaticMethod<int>("indoor/java/BLE", "start", "()I");
|
||||||
|
if (res != 1337) {throw Exception("error while starting BLE");}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() override {
|
||||||
|
throw "todo";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isRunning() const override {
|
||||||
|
return started;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* called from WiFi.java
|
||||||
|
* handle the given incoming scan result
|
||||||
|
* just a bit curious, thus std::string instead of std::string&
|
||||||
|
*/
|
||||||
|
void handle(const std::string data) {
|
||||||
|
|
||||||
|
// tag all scan-entries with the current app runtime
|
||||||
|
const Timestamp curTS = Timestamp::fromRunningTime();
|
||||||
|
|
||||||
|
// parse each mac->rssi entry
|
||||||
|
const std::string bssid = data.substr(0,17);
|
||||||
|
const int8_t rssi = data[17];
|
||||||
|
const int8_t pad1 = data[18];
|
||||||
|
const int8_t pad2 = data[19];
|
||||||
|
if (pad1 != 0 || pad2 != 0) {Debug::error("padding error within BLE scan result");}
|
||||||
|
|
||||||
|
Log::add("BLE", bssid + "; " + std::to_string(static_cast<int>(rssi)));
|
||||||
|
|
||||||
|
// call listeners
|
||||||
|
informListeners(BeaconMeasurement(curTS, Beacon(bssid), rssi));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // BLESENSORANDROID_H
|
||||||
Reference in New Issue
Block a user