#ifndef BLESENSORANDROID_H #define BLESENSORANDROID_H #ifdef ANDROID #include #include "../../misc/Debug.h" #include "../BLESensor.h" #include <../misc/fixc11.h> #include 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("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(rssi))); // call listeners informListeners(BeaconMeasurement(curTS, Beacon(bssid), rssi)); } }; #endif #endif // BLESENSORANDROID_H