diff options
author | Sven Gothel <[email protected]> | 2020-10-23 09:44:33 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-10-23 09:44:33 +0200 |
commit | 65e706721ed1ffa3800d8d2eb1d34f779cf55b85 (patch) | |
tree | 346324df2158949f951ac18922a16505d3ed80cf /examples | |
parent | 39de6a7097abb12d1f60fdc9142b79d2a3ba456e (diff) |
BluetoothUtils.java: Shorten *Milliseconds* functions; Reuse C++ environment::startupTimeMilliseconds for startupTimeMillis(), aligning timing.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/java/DBTScanner10.java | 16 | ||||
-rw-r--r-- | examples/java/ScannerTinyB01.java | 26 | ||||
-rw-r--r-- | examples/java/ScannerTinyB02.java | 24 |
3 files changed, 33 insertions, 33 deletions
diff --git a/examples/java/DBTScanner10.java b/examples/java/DBTScanner10.java index 843cf54e..59affe46 100644 --- a/examples/java/DBTScanner10.java +++ b/examples/java/DBTScanner10.java @@ -93,14 +93,14 @@ public class DBTScanner10 { static void printf(final String format, final Object... args) { final Object[] args2 = new Object[args.length+1]; - args2[0] = BluetoothUtils.getElapsedMillisecond(); + args2[0] = BluetoothUtils.elapsedTimeMillis(); System.arraycopy(args, 0, args2, 1, args.length); System.err.printf("[%,9d] "+format, args2); // System.err.printf("[%,9d] ", BluetoothUtils.getElapsedMillisecond()); // System.err.printf(format, args); } static void println(final String msg) { - System.err.printf("[%,9d] %s%s", BluetoothUtils.getElapsedMillisecond(), msg, System.lineSeparator()); + System.err.printf("[%,9d] %s%s", BluetoothUtils.elapsedTimeMillis(), msg, System.lineSeparator()); } @@ -159,7 +159,7 @@ public class DBTScanner10 { { println("****** FOUND__-0: Connecting "+device.toString()); { - final long td = BluetoothUtils.getCurrentMilliseconds() - timestamp_t0; // adapter-init -> now + final long td = BluetoothUtils.currentTimeMillis() - timestamp_t0; // adapter-init -> now println("PERF: adapter-init -> FOUND__-0 " + td + " ms"); } final Thread deviceConnectTask = new Thread( new Runnable() { @@ -195,7 +195,7 @@ public class DBTScanner10 { connectionCount.incrementAndGet(); println("****** CONNECTED-0: Processing["+connectionCount.get()+"] "+device.toString()); { - final long td = BluetoothUtils.getCurrentMilliseconds() - timestamp_t0; // adapter-init -> now + final long td = BluetoothUtils.currentTimeMillis() - timestamp_t0; // adapter-init -> now println("PERF: adapter-init -> CONNECTED-0 " + td + " ms"); } final Thread deviceProcessingTask = new Thread( new Runnable() { @@ -300,7 +300,7 @@ public class DBTScanner10 { println("****** Processing Device: stopDiscovery result "+r); } - final long t1 = BluetoothUtils.getCurrentMilliseconds(); + final long t1 = BluetoothUtils.currentTimeMillis(); boolean success = false; // Secure Pairing @@ -336,7 +336,7 @@ public class DBTScanner10 { // And it is an error case nonetheless ;-) throw new RuntimeException("Processing Device: getServices() failed " + device.toString()); } - final long t5 = BluetoothUtils.getCurrentMilliseconds(); + final long t5 = BluetoothUtils.currentTimeMillis(); if( !QUIET ) { final long td01 = t1 - timestamp_t0; // adapter-init -> processing-start final long td15 = t5 - t1; // get-gatt-services @@ -547,7 +547,7 @@ public class DBTScanner10 { } } - timestamp_t0 = BluetoothUtils.getCurrentMilliseconds(); + timestamp_t0 = BluetoothUtils.currentTimeMillis(); adapter.addStatusListener(statusListener, null); adapter.enableDiscoverableNotifications(new BooleanNotification("Discoverable", timestamp_t0)); @@ -729,7 +729,7 @@ public class DBTScanner10 { @Override public void run(final Boolean v) { synchronized(this) { - final long t1 = BluetoothUtils.getCurrentMilliseconds(); + final long t1 = BluetoothUtils.currentTimeMillis(); this.v = v.booleanValue(); System.out.println("###### "+name+": "+v+" in td "+(t1-t0)+" ms!"); this.notifyAll(); diff --git a/examples/java/ScannerTinyB01.java b/examples/java/ScannerTinyB01.java index 533b3160..e431f610 100644 --- a/examples/java/ScannerTinyB01.java +++ b/examples/java/ScannerTinyB01.java @@ -208,7 +208,7 @@ public class ScannerTinyB01 { }; adapter.addStatusListener(statusListener, null); - final long timestamp_t0 = BluetoothUtils.getCurrentMilliseconds(); + final long timestamp_t0 = BluetoothUtils.currentTimeMillis(); adapter.enableDiscoverableNotifications(new BooleanNotification("Discoverable", timestamp_t0)); @@ -224,7 +224,7 @@ public class ScannerTinyB01 { loop++; System.err.println("****** Loop "+loop); - final long t0 = BluetoothUtils.getCurrentMilliseconds(); + final long t0 = BluetoothUtils.currentTimeMillis(); final HCIStatusCode discoveryStatus = adapter.startDiscovery(true); @@ -239,7 +239,7 @@ public class ScannerTinyB01 { boolean timeout = false; while( !timeout && null == matchingDiscoveredDeviceBucket[0] ) { matchingDiscoveredDeviceBucket.wait(t0_discovery); - final long tn = BluetoothUtils.getCurrentMilliseconds(); + final long tn = BluetoothUtils.currentTimeMillis(); timeout = ( tn - t0 ) > t0_discovery; } sensor = matchingDiscoveredDeviceBucket[0]; @@ -250,7 +250,7 @@ public class ScannerTinyB01 { while( null == sensor && !timeout ) { sensor = adapter.find(null, waitForDevice, t0_discovery); if( null == sensor ) { - final long tn = BluetoothUtils.getCurrentMilliseconds(); + final long tn = BluetoothUtils.currentTimeMillis(); timeout = ( tn - t0 ) > t0_discovery; Thread.sleep(60); } @@ -267,13 +267,13 @@ public class ScannerTinyB01 { } } if( null == sensor ) { - final long tn = BluetoothUtils.getCurrentMilliseconds(); + final long tn = BluetoothUtils.currentTimeMillis(); timeout = ( tn - t0 ) > t0_discovery; Thread.sleep(60); } } } - final long t1 = BluetoothUtils.getCurrentMilliseconds(); + final long t1 = BluetoothUtils.currentTimeMillis(); if (sensor == null) { System.err.println("No sensor found within "+(t1-t0)+" ms"); continue; // forever loop @@ -288,22 +288,22 @@ public class ScannerTinyB01 { sensor.enableConnectedNotifications(connectedNotification); sensor.enableServicesResolvedNotifications(servicesResolvedNotification); - final long t2 = BluetoothUtils.getCurrentMilliseconds(); + final long t2 = BluetoothUtils.currentTimeMillis(); final long t3; HCIStatusCode res; if ( ( res = sensor.connect() ) == HCIStatusCode.SUCCESS ) { - t3 = BluetoothUtils.getCurrentMilliseconds(); + t3 = BluetoothUtils.currentTimeMillis(); System.err.println("Sensor connect issued: "+(t3-t2)+" ms, total "+(t3-t0)+" ms"); System.err.println("Sensor connectedNotification: "+connectedNotification.getValue()); } else { - t3 = BluetoothUtils.getCurrentMilliseconds(); + t3 = BluetoothUtils.currentTimeMillis(); System.out.println("connect command failed, res "+res+": "+(t3-t2)+" ms, total "+(t3-t0)+" ms"); // we tolerate the failed immediate connect, as it might happen at a later time } synchronized( servicesResolvedNotification ) { while( !servicesResolvedNotification.getValue() ) { - final long tn = BluetoothUtils.getCurrentMilliseconds(); + final long tn = BluetoothUtils.currentTimeMillis(); if( tn - t3 > TO_CONNECT_AND_RESOLVE ) { break; } @@ -312,10 +312,10 @@ public class ScannerTinyB01 { } final long t4; if ( servicesResolvedNotification.getValue() ) { - t4 = BluetoothUtils.getCurrentMilliseconds(); + t4 = BluetoothUtils.currentTimeMillis(); System.err.println("Sensor servicesResolved: "+(t4-t3)+" ms, total "+(t4-t0)+" ms"); } else { - t4 = BluetoothUtils.getCurrentMilliseconds(); + t4 = BluetoothUtils.currentTimeMillis(); System.out.println("Sensor service not resolved: "+(t4-t3)+" ms, total "+(t4-t0)+" ms"); System.exit(-1); } @@ -427,7 +427,7 @@ public class ScannerTinyB01 { @Override public void run(final Boolean v) { synchronized(this) { - final long t1 = BluetoothUtils.getCurrentMilliseconds(); + final long t1 = BluetoothUtils.currentTimeMillis(); this.v = v.booleanValue(); System.out.println("###### "+name+": "+v+" in td "+(t1-t0)+" ms!"); this.notifyAll(); diff --git a/examples/java/ScannerTinyB02.java b/examples/java/ScannerTinyB02.java index d8409397..e40052a9 100644 --- a/examples/java/ScannerTinyB02.java +++ b/examples/java/ScannerTinyB02.java @@ -188,7 +188,7 @@ public class ScannerTinyB02 { }; adapter.addStatusListener(statusListener, null); - final long timestamp_t0 = BluetoothUtils.getCurrentMilliseconds(); + final long timestamp_t0 = BluetoothUtils.currentTimeMillis(); adapter.enableDiscoverableNotifications(new BooleanNotification("Discoverable", timestamp_t0)); @@ -204,7 +204,7 @@ public class ScannerTinyB02 { loop++; System.err.println("****** Loop "+loop); - final long t0 = BluetoothUtils.getCurrentMilliseconds(); + final long t0 = BluetoothUtils.currentTimeMillis(); final boolean discoveryStarted = true; // adapter.startDiscovery(true); { @@ -229,7 +229,7 @@ public class ScannerTinyB02 { boolean timeout = false; while( !timeout && null == matchingDiscoveredDeviceBucket[0] ) { matchingDiscoveredDeviceBucket.wait(t0_discovery); - final long tn = BluetoothUtils.getCurrentMilliseconds(); + final long tn = BluetoothUtils.currentTimeMillis(); timeout = ( tn - t0 ) > t0_discovery; } sensor = matchingDiscoveredDeviceBucket[0]; @@ -253,14 +253,14 @@ public class ScannerTinyB02 { } } if( null == sensor ) { - final long tn = BluetoothUtils.getCurrentMilliseconds(); + final long tn = BluetoothUtils.currentTimeMillis(); timeout = ( tn - t0 ) > t0_discovery; System.err.print("."); Thread.sleep(60); } } } - final long t1 = BluetoothUtils.getCurrentMilliseconds(); + final long t1 = BluetoothUtils.currentTimeMillis(); if (sensor == null) { System.err.println("No sensor found within "+(t1-t0)+" ms"); continue; // forever loop @@ -285,22 +285,22 @@ public class ScannerTinyB02 { sensor.enableConnectedNotifications(connectedNotification); sensor.enableServicesResolvedNotifications(servicesResolvedNotification); - final long t2 = BluetoothUtils.getCurrentMilliseconds(); + final long t2 = BluetoothUtils.currentTimeMillis(); final long t3; HCIStatusCode res; if ( (res = sensor.connect() ) == HCIStatusCode.SUCCESS ) { - t3 = BluetoothUtils.getCurrentMilliseconds(); + t3 = BluetoothUtils.currentTimeMillis(); System.err.println("Sensor connect issued: "+(t3-t2)+" ms, total "+(t3-t0)+" ms"); System.err.println("Sensor connectedNotification: "+connectedNotification.getValue()); } else { - t3 = BluetoothUtils.getCurrentMilliseconds(); + t3 = BluetoothUtils.currentTimeMillis(); System.out.println("connect command failed, res "+res+": "+(t3-t2)+" ms, total "+(t3-t0)+" ms"); // we tolerate the failed immediate connect, as it might happen at a later time } synchronized( servicesResolvedNotification ) { while( !servicesResolvedNotification.getValue() ) { - final long tn = BluetoothUtils.getCurrentMilliseconds(); + final long tn = BluetoothUtils.currentTimeMillis(); if( tn - t3 > TO_CONNECT ) { break; } @@ -309,10 +309,10 @@ public class ScannerTinyB02 { } final long t4; if ( servicesResolvedNotification.getValue() ) { - t4 = BluetoothUtils.getCurrentMilliseconds(); + t4 = BluetoothUtils.currentTimeMillis(); System.err.println("Sensor servicesResolved: "+(t4-t3)+" ms, total "+(t4-t0)+" ms"); } else { - t4 = BluetoothUtils.getCurrentMilliseconds(); + t4 = BluetoothUtils.currentTimeMillis(); System.out.println("Could not connect device: "+(t4-t3)+" ms, total "+(t4-t0)+" ms"); // System.exit(-1); } @@ -369,7 +369,7 @@ public class ScannerTinyB02 { @Override public void run(final Boolean v) { synchronized(this) { - final long t1 = BluetoothUtils.getCurrentMilliseconds(); + final long t1 = BluetoothUtils.currentTimeMillis(); this.v = v.booleanValue(); System.out.println("###### "+name+": "+v+" in td "+(t1-t0)+" ms!"); this.notifyAll(); |