Histogram implementation
This commit is contained in:
@@ -35,8 +35,7 @@ public class RTT {
|
||||
private static Thread ftmThread;
|
||||
private static boolean ftmRunning;
|
||||
|
||||
// called when a RTT is completed successfully
|
||||
public static native void onRTTComplete(final byte[] result);
|
||||
public static native void onRttData(int success, final byte[] mac, long timeMS, int distMM, int distStdDevMM, int numAttemptedMeas, int numSuccessfullMeas, int rssi);
|
||||
|
||||
// result callback
|
||||
private static final RangingResultCallback callback = new RangingResultCallback() {
|
||||
@@ -52,57 +51,34 @@ public class RTT {
|
||||
Log.d("RTT", "onRangingResults: " + list.size());
|
||||
|
||||
for (final RangingResult res : list) {
|
||||
int success = 0;
|
||||
long timeStampInMS = 0;
|
||||
MacAddress mac = res.getMacAddress();
|
||||
int dist = 0;
|
||||
int stdDevDist = 0;
|
||||
int rssi = 0;
|
||||
int numAttemptedMeas = 0;
|
||||
int numSuccessfulMeas = 0;
|
||||
|
||||
final MacAddress mac = res.getMacAddress();
|
||||
if (res.getStatus() == RangingResult.STATUS_SUCCESS) {
|
||||
final int dist = res.getDistanceMm();
|
||||
final int stdDevDist = res.getDistanceStdDevMm();
|
||||
Log.d("RTT", mac.toString() + " " + dist + " " + stdDevDist);
|
||||
} else {
|
||||
Log.d("RTT", mac.toString() + " FAILED");
|
||||
}
|
||||
if (res.getStatus() == RangingResult.STATUS_SUCCESS) {
|
||||
success = 1;
|
||||
timeStampInMS = res.getRangingTimestampMillis();
|
||||
dist = res.getDistanceMm();
|
||||
stdDevDist = res.getDistanceStdDevMm();
|
||||
rssi = res.getRssi();
|
||||
numAttemptedMeas = res.getNumAttemptedMeasurements();
|
||||
numSuccessfulMeas = res.getNumSuccessfulMeasurements();
|
||||
|
||||
RTT.onRTTComplete(serialize(res));
|
||||
//Log.d("RTT", mac.toString() + " " + dist + " " + stdDevDist + " " + rssi);
|
||||
} else {
|
||||
//Log.d("RTT", mac.toString() + " FAILED");
|
||||
}
|
||||
|
||||
onRttData(success, mac.toString().getBytes(), timeStampInMS, dist, stdDevDist, numAttemptedMeas, numSuccessfulMeas, rssi);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static byte[] serialize(final RangingResult res) {
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try {
|
||||
char delim = ';';
|
||||
boolean success = res.getStatus() == RangingResult.STATUS_SUCCESS;
|
||||
|
||||
baos.write(success ? '1' : '0');
|
||||
baos.write(delim);
|
||||
|
||||
baos.write(("" + System.currentTimeMillis()).getBytes());
|
||||
baos.write(delim);
|
||||
|
||||
baos.write(res.getMacAddress().toString().getBytes());
|
||||
baos.write(delim);
|
||||
|
||||
int distValue = 0;
|
||||
int distStdDev = 0;
|
||||
int rssi = 0;
|
||||
|
||||
if (success) {
|
||||
distValue = res.getDistanceMm();
|
||||
distStdDev = res.getDistanceStdDevMm();
|
||||
rssi = res.getRssi();
|
||||
}
|
||||
|
||||
baos.write( ("" + distValue).getBytes() );
|
||||
baos.write(delim);
|
||||
baos.write( ("" + distStdDev).getBytes() );
|
||||
baos.write(delim);
|
||||
baos.write( ("" + rssi).getBytes() );
|
||||
|
||||
} catch (final Exception e) {;}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
public static int start() {
|
||||
|
||||
if (ftmRunning)
|
||||
@@ -116,10 +92,11 @@ public class RTT {
|
||||
mainExecutor = act.getMainExecutor();
|
||||
|
||||
final ArrayList<MacAddress> macs = new ArrayList<>();
|
||||
macs.add(MacAddress.fromString("38:de:ad:6d:77:25")); // NUC 1
|
||||
macs.add(MacAddress.fromString("38:de:ad:6d:77:25")); // NUC 1
|
||||
macs.add(MacAddress.fromString("38:de:ad:6d:60:ff")); // NUC 2
|
||||
macs.add(MacAddress.fromString("1c:1b:b5:ef:a2:9a")); // NUC 3
|
||||
macs.add(MacAddress.fromString("1c:1b:b5:ec:d1:82")); // NUC 4
|
||||
macs.add(MacAddress.fromString("d0:c6:37:bc:5c:41")); // NUC 5
|
||||
|
||||
ftmRunning = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user