stand island, fixed building for FTM
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
/build
|
/build
|
||||||
/captures
|
/captures
|
||||||
|
/.idea/caches/build_file_checksums.ser
|
||||||
|
|||||||
BIN
.idea/caches/build_file_checksums.ser
generated
BIN
.idea/caches/build_file_checksums.ser
generated
Binary file not shown.
116
.idea/codeStyles/Project.xml
generated
Normal file
116
.idea/codeStyles/Project.xml
generated
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<code_scheme name="Project" version="173">
|
||||||
|
<codeStyleSettings language="XML">
|
||||||
|
<indentOptions>
|
||||||
|
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||||
|
</indentOptions>
|
||||||
|
<arrangement>
|
||||||
|
<rules>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>xmlns:android</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>xmlns:.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:id</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*:name</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>name</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>style</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>ANDROID_ATTRIBUTE_ORDER</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<rule>
|
||||||
|
<match>
|
||||||
|
<AND>
|
||||||
|
<NAME>.*</NAME>
|
||||||
|
<XML_ATTRIBUTE />
|
||||||
|
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||||
|
</AND>
|
||||||
|
</match>
|
||||||
|
<order>BY_NAME</order>
|
||||||
|
</rule>
|
||||||
|
</section>
|
||||||
|
</rules>
|
||||||
|
</arrangement>
|
||||||
|
</codeStyleSettings>
|
||||||
|
</code_scheme>
|
||||||
|
</component>
|
||||||
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@@ -6,4 +6,4 @@
|
|||||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.android.support:design:23.4.0'
|
implementation 'com.android.support:design:28.0.0'
|
||||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
testCompile 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
implementation 'com.android.support:appcompat-v7:23.4.0'
|
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||||
implementation 'com.google.android.gms:play-services:10.2.0'
|
implementation 'com.google.android.gms:play-services:12.0.1'
|
||||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||||
implementation 'org.apmem.tools:layouts:1.10@aar'
|
implementation 'org.apmem.tools:layouts:1.10@aar'
|
||||||
//compile 'com.google.android.support:wearable:1.3.0'
|
//compile 'com.google.android.support:wearable:1.3.0'
|
||||||
|
|||||||
@@ -10,10 +10,9 @@
|
|||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.BODY_SENSORS" />
|
<uses-permission android:name="android.permission.BODY_SENSORS" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
|
|
||||||
<uses-feature android:name="android.hardware.location.gps" />
|
<uses-feature android:name="android.hardware.location.gps" />
|
||||||
|
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>
|
||||||
|
|
||||||
<uses-permission-sdk-23 android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import de.fhws.indoor.sensorreadout.sensors.LoggerRAM;
|
|||||||
import de.fhws.indoor.sensorreadout.sensors.PedestrianActivity;
|
import de.fhws.indoor.sensorreadout.sensors.PedestrianActivity;
|
||||||
import de.fhws.indoor.sensorreadout.sensors.PedestrianActivityButton;
|
import de.fhws.indoor.sensorreadout.sensors.PedestrianActivityButton;
|
||||||
import de.fhws.indoor.sensorreadout.sensors.PhoneSensors;
|
import de.fhws.indoor.sensorreadout.sensors.PhoneSensors;
|
||||||
|
import de.fhws.indoor.sensorreadout.sensors.UnorderedLogger;
|
||||||
import de.fhws.indoor.sensorreadout.sensors.WiFi;
|
import de.fhws.indoor.sensorreadout.sensors.WiFi;
|
||||||
import de.fhws.indoor.sensorreadout.sensors.WiFiRTT;
|
import de.fhws.indoor.sensorreadout.sensors.WiFiRTT;
|
||||||
import de.fhws.indoor.sensorreadout.sensors.iBeacon;
|
import de.fhws.indoor.sensorreadout.sensors.iBeacon;
|
||||||
@@ -55,7 +56,8 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
private final ArrayList<mySensor> sensors = new ArrayList<mySensor>();
|
private final ArrayList<mySensor> sensors = new ArrayList<mySensor>();
|
||||||
//private final Logger logger = new Logger(this);
|
//private final Logger logger = new Logger(this);
|
||||||
private final LoggerRAM logger = new LoggerRAM(this);
|
//private final LoggerRAM logger = new LoggerRAM(this);
|
||||||
|
private final UnorderedLogger logger = new UnorderedLogger(this);
|
||||||
private Button btnStart;
|
private Button btnStart;
|
||||||
private Button btnStop;
|
private Button btnStop;
|
||||||
private Button btnGround;
|
private Button btnGround;
|
||||||
@@ -261,7 +263,7 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
if (id == SensorType.WIFIRTT) {
|
if (id == SensorType.WIFIRTT) {
|
||||||
final TextView txt = (TextView) findViewById(R.id.txtWifi);
|
final TextView txt = (TextView) findViewById(R.id.txtWifi);
|
||||||
txt.setText(((++loadCounterWifi % 2) == 0) ? "wi" : "WI");
|
txt.setText(((++loadCounterWifi % 7) == 0) ? "wi" : "WI");
|
||||||
} else if (id == SensorType.IBEACON) {
|
} else if (id == SensorType.IBEACON) {
|
||||||
final TextView txt = (TextView) findViewById(R.id.txtBeacon);
|
final TextView txt = (TextView) findViewById(R.id.txtBeacon);
|
||||||
txt.setText(((++loadCounterBeacon % 2) == 0) ? "ib" : "IB");
|
txt.setText(((++loadCounterBeacon % 2) == 0) ? "ib" : "IB");
|
||||||
@@ -425,13 +427,13 @@ public class MainActivity extends Activity {
|
|||||||
|
|
||||||
if(activeSensors.contains("PHONE")) {
|
if(activeSensors.contains("PHONE")) {
|
||||||
// heartbeat permission
|
// heartbeat permission
|
||||||
if(ActivityCompat.shouldShowRequestPermissionRationale(this,
|
// if(ActivityCompat.shouldShowRequestPermissionRationale(this,
|
||||||
Manifest.permission.BODY_SENSORS)) {
|
// Manifest.permission.BODY_SENSORS)) {
|
||||||
} else {
|
// } else {
|
||||||
ActivityCompat.requestPermissions(this,
|
// ActivityCompat.requestPermissions(this,
|
||||||
new String[]{Manifest.permission.BODY_SENSORS},
|
// new String[]{Manifest.permission.BODY_SENSORS},
|
||||||
MY_PERMISSIONS_REQUEST_READ_HEART);
|
// MY_PERMISSIONS_REQUEST_READ_HEART);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//all Phone-Sensors (Accel, Gyro, Magnet, ...)
|
//all Phone-Sensors (Accel, Gyro, Magnet, ...)
|
||||||
final PhoneSensors phoneSensors = new PhoneSensors(this);
|
final PhoneSensors phoneSensors = new PhoneSensors(this);
|
||||||
@@ -479,6 +481,8 @@ public class MainActivity extends Activity {
|
|||||||
MY_PERMISSIONS_REQUEST_READ_BT);
|
MY_PERMISSIONS_REQUEST_READ_BT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: add something that asks the user to also enable GPS!
|
||||||
|
|
||||||
// log iBeacons using sensor number 9
|
// log iBeacons using sensor number 9
|
||||||
final mySensor beacon;
|
final mySensor beacon;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class PhoneSensors extends mySensor implements SensorEventListener{
|
public class PhoneSensors extends mySensor implements SensorEventListener{
|
||||||
|
|
||||||
private static final int SENSOR_TYPE_HEARTRATE = 65562;
|
//private static final int SENSOR_TYPE_HEARTRATE = 65562;
|
||||||
|
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
private Sensor acc;
|
private Sensor acc;
|
||||||
@@ -34,7 +34,7 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
|
|||||||
private Sensor magnet;
|
private Sensor magnet;
|
||||||
private Sensor press;
|
private Sensor press;
|
||||||
private Sensor ori;
|
private Sensor ori;
|
||||||
private Sensor heart;
|
//private Sensor heart;
|
||||||
private Sensor humidity;
|
private Sensor humidity;
|
||||||
private Sensor rotationVector;
|
private Sensor rotationVector;
|
||||||
private Sensor light;
|
private Sensor light;
|
||||||
@@ -61,7 +61,7 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
|
|||||||
magnet = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
magnet = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||||
press = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
|
press = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
|
||||||
ori = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
ori = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
|
||||||
heart = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
|
//heart = sensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
|
||||||
humidity = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
|
humidity = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
|
||||||
rotationVector = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
|
rotationVector = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
|
||||||
light = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
light = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
|
||||||
@@ -103,7 +103,7 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
|
|||||||
dumpSensor(sb, SensorType.ORIENTATION_OLD, ori);
|
dumpSensor(sb, SensorType.ORIENTATION_OLD, ori);
|
||||||
dumpSensor(sb, SensorType.LIGHT, light);
|
dumpSensor(sb, SensorType.LIGHT, light);
|
||||||
dumpSensor(sb, SensorType.AMBIENT_TEMPERATURE, temperature);
|
dumpSensor(sb, SensorType.AMBIENT_TEMPERATURE, temperature);
|
||||||
dumpSensor(sb, SensorType.HEART_RATE, heart);
|
//dumpSensor(sb, SensorType.HEART_RATE, heart);
|
||||||
dumpSensor(sb, SensorType.GAME_ROTATION_VECTOR, gameRotationVector);
|
dumpSensor(sb, SensorType.GAME_ROTATION_VECTOR, gameRotationVector);
|
||||||
|
|
||||||
// write
|
// write
|
||||||
@@ -156,16 +156,16 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
|
// if(event.sensor.getType() == Sensor.TYPE_HEART_RATE) {
|
||||||
|
//
|
||||||
// inform listeners
|
// // inform listeners
|
||||||
if (listener != null){
|
// if (listener != null){
|
||||||
listener.onData(SensorType.HEART_RATE, event.timestamp,
|
// listener.onData(SensorType.HEART_RATE, event.timestamp,
|
||||||
Float.toString(event.values[0])
|
// Float.toString(event.values[0])
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
else if(event.sensor.getType() == Sensor.TYPE_LIGHT) {
|
else if(event.sensor.getType() == Sensor.TYPE_LIGHT) {
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ public class PhoneSensors extends mySensor implements SensorEventListener{
|
|||||||
registerIfPresent(magnet, SensorManager.SENSOR_DELAY_FASTEST);
|
registerIfPresent(magnet, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
registerIfPresent(press, SensorManager.SENSOR_DELAY_FASTEST);
|
registerIfPresent(press, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
registerIfPresent(ori, SensorManager.SENSOR_DELAY_FASTEST);
|
registerIfPresent(ori, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
registerIfPresent(heart, SensorManager.SENSOR_DELAY_FASTEST);
|
//registerIfPresent(heart, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
registerIfPresent(humidity, SensorManager.SENSOR_DELAY_FASTEST);
|
registerIfPresent(humidity, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
registerIfPresent(rotationVector, SensorManager.SENSOR_DELAY_FASTEST);
|
registerIfPresent(rotationVector, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
registerIfPresent(light, SensorManager.SENSOR_DELAY_FASTEST);
|
registerIfPresent(light, SensorManager.SENSOR_DELAY_FASTEST);
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
package de.fhws.indoor.sensorreadout.sensors;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* log sensor data to file
|
||||||
|
* Created by Frank on 25.03.2015.
|
||||||
|
* Re-Written by Markus on 20.06.2019.
|
||||||
|
*/
|
||||||
|
public final class UnorderedLogger {
|
||||||
|
|
||||||
|
public static final long BEGINNING_TS = -1;
|
||||||
|
|
||||||
|
private StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
private File file;
|
||||||
|
private FileOutputStream fos;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
private int entries = 0;
|
||||||
|
private int sizeTotal = 0;
|
||||||
|
private int currentSize = 0;
|
||||||
|
|
||||||
|
private volatile boolean addingStopped = false; // Just to be sure
|
||||||
|
private ArrayBlockingQueue<LogEntry> lineBuffer = new ArrayBlockingQueue<>(5000);
|
||||||
|
private WriteBackWorker writeBackWorker;
|
||||||
|
|
||||||
|
/** timestamp of logging start. all entries are relative to this one */
|
||||||
|
private long startTS = 0;
|
||||||
|
|
||||||
|
public UnorderedLogger(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** start logging (caching a couple of entries in RAM) */
|
||||||
|
public final void start() {
|
||||||
|
|
||||||
|
// start empty
|
||||||
|
stringBuilder.setLength(0);
|
||||||
|
entries = 0;
|
||||||
|
sizeTotal = 0;
|
||||||
|
addingStopped = false;
|
||||||
|
writeBackWorker = new WriteBackWorker();
|
||||||
|
|
||||||
|
// starting timestamp
|
||||||
|
startTS = SystemClock.elapsedRealtimeNanos();
|
||||||
|
|
||||||
|
// open the output-file immediately (to get permission errors)
|
||||||
|
// but do NOT yet write anything to the file
|
||||||
|
final DataFolder folder = new DataFolder(context, "sensorOutFiles");
|
||||||
|
file = new File(folder.getFolder(), startTS + ".csv");
|
||||||
|
|
||||||
|
try {
|
||||||
|
fos = new FileOutputStream(file);
|
||||||
|
Log.d("logger", "will write to: " + file.toString());
|
||||||
|
} catch (final Exception e) {
|
||||||
|
throw new MyException("error while opening log-file", e);
|
||||||
|
}
|
||||||
|
writeBackWorker.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** stop logging and flush RAM-data to the flash-chip */
|
||||||
|
public final void stop() {
|
||||||
|
debug(true);
|
||||||
|
addingStopped = true;
|
||||||
|
// wait for flushing to succeed
|
||||||
|
try {
|
||||||
|
writeBackWorker.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
debug(true);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getFile() {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCurrentBufferSize() {return currentSize;}
|
||||||
|
public int getTotalSize() {return sizeTotal;}
|
||||||
|
|
||||||
|
public int getNumEntries() {return entries;}
|
||||||
|
|
||||||
|
/** add a new CSV entry for the given sensor number to the internal buffer */
|
||||||
|
public final void addCSV(final SensorType sensorNr, final long timestamp, final String csv) {
|
||||||
|
final long relTS = (timestamp == BEGINNING_TS) ? 0 : (timestamp - startTS);
|
||||||
|
if(relTS >= 0) { // drop pre startTS logs (at the beginning, sensors sometimes deliver old values)
|
||||||
|
if(addingStopped) {
|
||||||
|
// addCSV was called after calling stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append(relTS); // relative timestamp (uses less space)
|
||||||
|
stringBuilder.append(';');
|
||||||
|
stringBuilder.append(sensorNr.id());
|
||||||
|
stringBuilder.append(';');
|
||||||
|
stringBuilder.append(csv);
|
||||||
|
stringBuilder.append('\n');
|
||||||
|
++entries;
|
||||||
|
LogEntry logEntry = new LogEntry(relTS, stringBuilder.toString());
|
||||||
|
sizeTotal += logEntry.csv.length();
|
||||||
|
currentSize += logEntry.csv.length();
|
||||||
|
stringBuilder.setLength(0);
|
||||||
|
|
||||||
|
|
||||||
|
// Commit to line/flush buffer
|
||||||
|
lineBuffer.add(logEntry);
|
||||||
|
}
|
||||||
|
debug(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void close() {
|
||||||
|
try {
|
||||||
|
fos.close();
|
||||||
|
} catch (final Exception e) {
|
||||||
|
throw new MyException("error while writing log-file", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final long getStartTS() {
|
||||||
|
return startTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
|
private final void debug(boolean force) {
|
||||||
|
if (++cnt % 1000 == 0 || force) {
|
||||||
|
Log.d("buffer", "size: " + lineBuffer.size() + " lines");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static class LogEntry implements Comparable<LogEntry> {
|
||||||
|
public long timestamp;
|
||||||
|
public String csv;
|
||||||
|
|
||||||
|
public LogEntry(long timestamp, String csv) {
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.csv = csv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(@NonNull LogEntry another) {
|
||||||
|
return (timestamp < another.timestamp) ? (-1) : (+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class WriteBackWorker extends Thread {
|
||||||
|
|
||||||
|
public WriteBackWorker() {
|
||||||
|
setName("WriteBackWorker");
|
||||||
|
setPriority(Thread.MIN_PRIORITY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
LogEntry entry = lineBuffer.poll();
|
||||||
|
if (entry == null) {
|
||||||
|
if (addingStopped) { // Queue empty, recording stopped. exit
|
||||||
|
return;
|
||||||
|
} else { // Currently no line in queue, wait 10 ms
|
||||||
|
Thread.sleep(10);
|
||||||
|
}
|
||||||
|
} else { // print log line
|
||||||
|
fos.write(entry.csv.getBytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,18 +5,24 @@ import android.bluetooth.BluetoothAdapter;
|
|||||||
import android.bluetooth.BluetoothManager;
|
import android.bluetooth.BluetoothManager;
|
||||||
import android.bluetooth.le.BluetoothLeScanner;
|
import android.bluetooth.le.BluetoothLeScanner;
|
||||||
import android.bluetooth.le.ScanCallback;
|
import android.bluetooth.le.ScanCallback;
|
||||||
|
import android.bluetooth.le.ScanFilter;
|
||||||
|
import android.bluetooth.le.ScanSettings;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Frank on 25.03.2015.
|
* Created by Frank on 25.03.2015.
|
||||||
*/
|
*/
|
||||||
public class iBeacon extends mySensor {
|
public class iBeacon extends mySensor {
|
||||||
|
|
||||||
private BluetoothAdapter bt = null;
|
private BluetoothAdapter bt;
|
||||||
private BluetoothLeScanner scanner = null;
|
private BluetoothLeScanner scanner;
|
||||||
|
private static ScanSettings settings;
|
||||||
private static final int REQUEST_ENABLE_BT = 1;
|
private static final int REQUEST_ENABLE_BT = 1;
|
||||||
private ScanCallback mLeScanCallback;
|
private ScanCallback mLeScanCallback;
|
||||||
|
|
||||||
@@ -35,7 +41,9 @@ public class iBeacon extends mySensor {
|
|||||||
bt = mgr.getAdapter();
|
bt = mgr.getAdapter();
|
||||||
|
|
||||||
// bluetooth supported?
|
// bluetooth supported?
|
||||||
if (bt == null) {
|
if (bt == null || !bt.isEnabled()) {
|
||||||
|
|
||||||
|
//TODO: add something that asks the user to enable BLE. this need also be called in onResum()
|
||||||
Toast.makeText(act, "Bluetooth not supported!", Toast.LENGTH_SHORT).show();
|
Toast.makeText(act, "Bluetooth not supported!", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -53,9 +61,15 @@ public class iBeacon extends mySensor {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
settings = new ScanSettings.Builder()
|
||||||
|
.setReportDelay(0)
|
||||||
|
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
|
||||||
|
//.setNumOfMatches(ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT) //comment this out for apk < 23
|
||||||
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void enableBT(final Activity act) {
|
private void enableBT(final Activity act) {
|
||||||
if (bt == null) {throw new RuntimeException("BT not supported!");}
|
if (bt == null) {throw new RuntimeException("BT not supported!");}
|
||||||
if (!bt.isEnabled()) {
|
if (!bt.isEnabled()) {
|
||||||
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
||||||
@@ -66,7 +80,9 @@ public class iBeacon extends mySensor {
|
|||||||
@Override public void onResume(final Activity act) {
|
@Override public void onResume(final Activity act) {
|
||||||
if (bt != null) {
|
if (bt != null) {
|
||||||
enableBT(act);
|
enableBT(act);
|
||||||
scanner.startScan(mLeScanCallback);
|
List<ScanFilter> filters = new ArrayList<ScanFilter>();
|
||||||
|
scanner.startScan(filters, settings, mLeScanCallback);
|
||||||
|
//scanner.startScan(mLeScanCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user