diff options
author | Sven Gothel <[email protected]> | 2020-09-16 13:36:57 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-09-16 13:36:57 +0200 |
commit | 2ae1ba72a8d0e5dd06d075fd06dae287b44f8bf6 (patch) | |
tree | 50a84aa92bee3d719ecdc36e1002d9da785fe598 /examples | |
parent | a1310a8481663d2d868b1546651b09976063c5c1 (diff) |
ScannerTinyB10, dbt_scanner10: Add '-silent_gatt' options: Don't print detailed GATT info, nor PERFv2.1.21
Testing with multiple devices in parallel, it is useful to be in the most quiet mode - not walking through tons of info dumps.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/direct_bt_scanner10/dbt_scanner10.cpp | 54 | ||||
-rw-r--r-- | examples/java/ScannerTinyB10.java | 30 |
2 files changed, 56 insertions, 28 deletions
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp index f89e5e0c..1a0bbf5a 100644 --- a/examples/direct_bt_scanner10/dbt_scanner10.cpp +++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp @@ -61,8 +61,9 @@ static bool USE_WHITELIST = false; static std::vector<EUI48> WHITELIST; static bool SHOW_UPDATE_EVENTS = false; +static bool SILENT_GATT = false; -static std::vector<EUI48> waitForDevice; +static std::vector<EUI48> waitForDevices; static void connectDiscoveredDevice(std::shared_ptr<DBTDevice> device); @@ -151,8 +152,8 @@ class MyAdapterStatusListener : public AdapterStatusListener { return; } if( !isDeviceProcessing( device->getAddress() ) && - ( waitForDevice.empty() || - ( contains(waitForDevice, device->getAddress()) && + ( waitForDevices.empty() || + ( contains(waitForDevices, device->getAddress()) && ( 0 < MULTI_MEASUREMENTS || !isDeviceProcessed(device->getAddress()) ) ) ) @@ -182,8 +183,8 @@ class MyAdapterStatusListener : public AdapterStatusListener { (void)timestamp; if( !isDeviceProcessing( device->getAddress() ) && - ( waitForDevice.empty() || - ( contains(waitForDevice, device->getAddress()) && + ( waitForDevices.empty() || + ( contains(waitForDevices, device->getAddress()) && ( 0 < MULTI_MEASUREMENTS || !isDeviceProcessed(device->getAddress()) ) ) ) @@ -287,7 +288,7 @@ static void processConnectedDevice(std::shared_ptr<DBTDevice> device) { } const uint64_t t5 = getCurrentMilliseconds(); - { + if( !SILENT_GATT ) { const uint64_t td01 = t1 - timestamp_t0; // adapter-init -> processing-start const uint64_t td15 = t5 - t1; // get-gatt-services const uint64_t tdc5 = t5 - device->getLastDiscoveryTimestamp(); // discovered to gatt-complete @@ -301,14 +302,14 @@ static void processConnectedDevice(std::shared_ptr<DBTDevice> device) { td01, td15, tdc5, (tdc5 - td15), td05); } std::shared_ptr<GenericAccess> ga = device->getGATTGenericAccess(); - if( nullptr != ga ) { + if( nullptr != ga && !SILENT_GATT ) { fprintf(stderr, " GenericAccess: %s\n\n", ga->toString().c_str()); } { std::shared_ptr<GATTHandler> gatt = device->getGATTHandler(); if( nullptr != gatt && gatt->isOpen() ) { std::shared_ptr<DeviceInformation> di = gatt->getDeviceInformation(primServices); - if( nullptr != di ) { + if( nullptr != di && !SILENT_GATT ) { fprintf(stderr, " DeviceInformation: %s\n\n", di->toString().c_str()); } } @@ -316,24 +317,32 @@ static void processConnectedDevice(std::shared_ptr<DBTDevice> device) { for(size_t i=0; i<primServices.size(); i++) { GATTService & primService = *primServices.at(i); - fprintf(stderr, " [%2.2d] Service %s\n", (int)i, primService.toString().c_str()); - fprintf(stderr, " [%2.2d] Service Characteristics\n", (int)i); + if( !SILENT_GATT ) { + fprintf(stderr, " [%2.2d] Service %s\n", (int)i, primService.toString().c_str()); + fprintf(stderr, " [%2.2d] Service Characteristics\n", (int)i); + } std::vector<GATTCharacteristicRef> & serviceCharacteristics = primService.characteristicList; for(size_t j=0; j<serviceCharacteristics.size(); j++) { GATTCharacteristic & serviceChar = *serviceCharacteristics.at(j); - fprintf(stderr, " [%2.2d.%2.2d] Decla: %s\n", (int)i, (int)j, serviceChar.toString().c_str()); + if( !SILENT_GATT ) { + fprintf(stderr, " [%2.2d.%2.2d] Decla: %s\n", (int)i, (int)j, serviceChar.toString().c_str()); + } if( serviceChar.hasProperties(GATTCharacteristic::PropertyBitVal::Read) ) { POctets value(GATTHandler::number(GATTHandler::Defaults::MAX_ATT_MTU), 0); if( serviceChar.readValue(value) ) { std::string sval = dfa_utf8_decode(value.get_ptr(), value.getSize()); - fprintf(stderr, " [%2.2d.%2.2d] Value: %s ('%s')\n", (int)i, (int)j, value.toString().c_str(), sval.c_str()); + if( !SILENT_GATT ) { + fprintf(stderr, " [%2.2d.%2.2d] Value: %s ('%s')\n", (int)i, (int)j, value.toString().c_str(), sval.c_str()); + } } } bool cccdEnableResult[2]; bool cccdRet = serviceChar.addCharacteristicListener( std::shared_ptr<GATTCharacteristicListener>( new MyGATTEventListener(&serviceChar) ), cccdEnableResult ); - fprintf(stderr, " [%2.2d.%2.2d] addCharacteristicListener Notification(%d), Indication(%d): Result %d\n", - (int)i, (int)j, cccdEnableResult[0], cccdEnableResult[1], cccdRet); + if( !SILENT_GATT ) { + fprintf(stderr, " [%2.2d.%2.2d] addCharacteristicListener Notification(%d), Indication(%d): Result %d\n", + (int)i, (int)j, cccdEnableResult[0], cccdEnableResult[1], cccdRet); + } } } // FIXME sleep 1s for potential callbacks .. @@ -417,12 +426,12 @@ void test(int dev_id) { while( !done ) { if( 0 == MULTI_MEASUREMENTS || - ( -1 == MULTI_MEASUREMENTS && !waitForDevice.empty() && allDevicesProcessed(waitForDevice) ) + ( -1 == MULTI_MEASUREMENTS && !waitForDevices.empty() && allDevicesProcessed(waitForDevices) ) ) { fprintf(stderr, "****** EOL Test MULTI_MEASUREMENTS left %d, processed %zd/%zd\n", - MULTI_MEASUREMENTS, devicesProcessed.size(), waitForDevice.size()); - printList("****** WaitForDevice ", waitForDevice); + MULTI_MEASUREMENTS, devicesProcessed.size(), waitForDevices.size()); + printList("****** WaitForDevice ", waitForDevices); printList("****** DevicesProcessed ", devicesProcessed); done = true; } else { @@ -444,6 +453,8 @@ int main(int argc, char *argv[]) waitForEnter = true; } else if( !strcmp("-show_update_events", argv[i]) ) { SHOW_UPDATE_EVENTS = true; + } else if( !strcmp("-silent_gatt", argv[i]) ) { + SILENT_GATT = true; } else if( !strcmp("-dev_id", argv[i]) && argc > (i+1) ) { dev_id = atoi(argv[++i]); } else if( !strcmp("-btmode", argv[i]) && argc > (i+1) ) { @@ -453,7 +464,7 @@ int main(int argc, char *argv[]) } } else if( !strcmp("-mac", argv[i]) && argc > (i+1) ) { std::string macstr = std::string(argv[++i]); - waitForDevice.push_back( EUI48(macstr) ); + waitForDevices.push_back( EUI48(macstr) ); } else if( !strcmp("-wl", argv[i]) && argc > (i+1) ) { std::string macstr = std::string(argv[++i]); EUI48 wlmac(macstr); @@ -472,15 +483,18 @@ int main(int argc, char *argv[]) } fprintf(stderr, "pid %d\n", getpid()); - fprintf(stderr, "Run with '[-dev_id <adapter-index>] [-btmode <BT-MODE>] [-mac <device_address>] [-disconnect] [-count <number>] [-single] (-wl <device_address>)* [-show_update_events]'\n"); + fprintf(stderr, "Run with '[-dev_id <adapter-index>] [-btmode <BT-MODE>] (-mac <device_address>)* " + "[-disconnect] [-count <number>] [-single] (-wl <device_address>)* [-show_update_events] [-silent_gatt]'\n"); fprintf(stderr, "MULTI_MEASUREMENTS %d\n", MULTI_MEASUREMENTS); fprintf(stderr, "KEEP_CONNECTED %d\n", KEEP_CONNECTED); fprintf(stderr, "REMOVE_DEVICE %d\n", REMOVE_DEVICE); fprintf(stderr, "USE_WHITELIST %d\n", USE_WHITELIST); + fprintf(stderr, "SHOW_UPDATE_EVENTS %d\n", SHOW_UPDATE_EVENTS); + fprintf(stderr, "SILENT_GATT %d\n", SILENT_GATT); fprintf(stderr, "dev_id %d\n", dev_id); fprintf(stderr, "btmode %s\n", getBTModeString(btMode).c_str()); - printList( "waitForDevice: ", waitForDevice); + printList( "waitForDevice: ", waitForDevices); // initialize manager with given default BTMode DBTManager::get(btMode); diff --git a/examples/java/ScannerTinyB10.java b/examples/java/ScannerTinyB10.java index 8d39cd1e..3afb97e4 100644 --- a/examples/java/ScannerTinyB10.java +++ b/examples/java/ScannerTinyB10.java @@ -78,6 +78,7 @@ public class ScannerTinyB10 { final List<String> characteristicList = new ArrayList<String>(); boolean SHOW_UPDATE_EVENTS = false; + boolean SILENT_GATT = false; int dev_id = -1; // use default @@ -272,7 +273,7 @@ public class ScannerTinyB10 { throw new RuntimeException("Processing Device: getServices() failed " + device.toString()); } final long t5 = BluetoothUtils.getCurrentMilliseconds(); - { + if( !SILENT_GATT ) { final long td01 = t1 - timestamp_t0; // adapter-init -> processing-start final long td15 = t5 - t1; // get-gatt-services final long tdc5 = t5 - device.getLastDiscoveryTimestamp(); // discovered to gatt-complete @@ -319,25 +320,33 @@ public class ScannerTinyB10 { }; final boolean addedCharacteristicListenerRes = BluetoothGattService.addCharacteristicListenerToAll(device, primServices, myCharacteristicListener); - println("Added GATTCharacteristicListener: "+addedCharacteristicListenerRes); + if( !SILENT_GATT ) { + println("Added GATTCharacteristicListener: "+addedCharacteristicListenerRes); + } } try { int i=0, j=0; for(final Iterator<BluetoothGattService> srvIter = primServices.iterator(); srvIter.hasNext(); i++) { final BluetoothGattService primService = srvIter.next(); - printf(" [%02d] Service %s\n", i, primService.toString()); - printf(" [%02d] Service Characteristics\n", i); + if( !SILENT_GATT ) { + printf(" [%02d] Service %s\n", i, primService.toString()); + printf(" [%02d] Service Characteristics\n", i); + } final List<BluetoothGattCharacteristic> serviceCharacteristics = primService.getCharacteristics(); for(final Iterator<BluetoothGattCharacteristic> charIter = serviceCharacteristics.iterator(); charIter.hasNext(); j++) { final BluetoothGattCharacteristic serviceChar = charIter.next(); - printf(" [%02d.%02d] Decla: %s\n", i, j, serviceChar.toString()); + if( !SILENT_GATT ) { + printf(" [%02d.%02d] Decla: %s\n", i, j, serviceChar.toString()); + } final List<String> properties = Arrays.asList(serviceChar.getFlags()); if( properties.contains("read") ) { final byte[] value = serviceChar.readValue(); final String svalue = BluetoothUtils.decodeUTF8String(value, 0, value.length); - printf(" [%02d.%02d] Value: %s ('%s')\n", - i, j, BluetoothUtils.bytesHexString(value, true, true), svalue); + if( !SILENT_GATT ) { + printf(" [%02d.%02d] Value: %s ('%s')\n", + i, j, BluetoothUtils.bytesHexString(value, true, true), svalue); + } } } } @@ -544,6 +553,8 @@ public class ScannerTinyB10 { waitForEnter = true; } else if( arg.equals("-show_update_events") ) { test.SHOW_UPDATE_EVENTS = true; + } else if( arg.equals("-silent_gatt") ) { + test.SILENT_GATT = true; } else if( arg.equals("-dev_id") && args.length > (i+1) ) { test.dev_id = Integer.valueOf(args[++i]).intValue(); } else if( arg.equals("-shutdown") && args.length > (i+1) ) { @@ -568,7 +579,7 @@ public class ScannerTinyB10 { } } println("Run with '[-default_dev_id <adapter-index>] [-dev_id <adapter-index>] (-mac <device_address>)* "+ - "[-disconnect] [-count <number>] [-single] (-wl <device_address>)* (-char <uuid>)* [-show_update_events] "+ + "[-disconnect] [-count <number>] [-single] (-wl <device_address>)* (-char <uuid>)* [-show_update_events] [-silent_gatt]"+ "[-bluetoothManager <BluetoothManager-Implementation-Class-Name>] "+ "[-verbose] [-debug] "+ "[-dbt_verbose [true|false]] "+ @@ -584,6 +595,9 @@ public class ScannerTinyB10 { println("KEEP_CONNECTED "+test.KEEP_CONNECTED); println("REMOVE_DEVICE "+test.REMOVE_DEVICE); println("USE_WHITELIST "+test.USE_WHITELIST); + println("SHOW_UPDATE_EVENTS "+test.SHOW_UPDATE_EVENTS); + println("SILENT_GATT "+test.SILENT_GATT); + println("dev_id "+test.dev_id); println("waitForDevice: "+Arrays.toString(test.waitForDevices.toArray())); println("characteristicList: "+Arrays.toString(test.characteristicList.toArray())); |