for this, we use the same ui interface and fingerprint positions as wifi. if wifi has done 30 scans, also the ble scans will be stopped. this is just a quick and dirte solution, as changing the gui completely for this two options was to time consuming
83 lines
1.8 KiB
C++
83 lines
1.8 KiB
C++
#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
|