diff mbox series

[Bluez,v2,5/6] test: Add test for LE Set Advertising Interval

Message ID 20200330160343.Bluez.v2.5.Ie551a8a414d17604f04e10cf8d9c514a2b170e31@changeid (mailing list archive)
State New, archived
Headers show
Series Add support of setting advertiing intervals. | expand

Commit Message

Yun-hao Chung March 30, 2020, 8:03 a.m. UTC
Perform the following steps to verify advertising intervals.
Open a terminal on the DUT, and execute
$ btmon

Open another terminal on the DUT, and register an advertisement.
$ ./example-advertisement

Observe that the default intervals are 1280 msec in btmon log.
    < HCI Command: LE Set Advertising Parameters (0x08|0x0006) plen 15
        Min advertising interval: 1280.000 msec (0x0800)
        Max advertising interval: 1280.000 msec (0x0800)
Press ctrl-c to terminate the advertisement.

Set new intervals to 200 ms.
$ ./example-advertising-intervals 200 200

It would show the following line in btmon log.
    = bluetoothd: Set Advertising Intervals: 0x0140, 0x0140

Register an advertisement again.
$ ./example-advertisement

Observe that the new intervals bcome 200 msec in btmon log.
    < HCI Command: LE Set Advertising Parameters (0x08|0x0006) plen 15
        Min advertising interval: 200.000 msec (0x0140)
        Max advertising interval: 200.000 msec (0x0140)
Press ctrl-c to terminate the advertisement.

Signed-off-by: Howard Chung <howardchung@google.com>
---

Changes in v2: None

 test/example-advertising-intervals | 48 ++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 test/example-advertising-intervals
diff mbox series

Patch

diff --git a/test/example-advertising-intervals b/test/example-advertising-intervals
new file mode 100644
index 000000000..8afc7225e
--- /dev/null
+++ b/test/example-advertising-intervals
@@ -0,0 +1,48 @@ 
+#!/usr/bin/python
+
+"""A simple script to set advertising intervals through the dbus method.
+
+Usage:
+    $ ./example_advertising_intervals.py min_interval_ms max_interval_ms
+
+    Example:
+    # Set both min and max advertising intervals to 200 ms.
+    $ ./exampel_advertising_intervals.py 200 200
+"""
+
+import dbus
+import time
+import subprocess
+import sys
+
+argv = sys.argv
+argc = len(argv)
+prog = argv[0]
+if argc == 3:
+    min_interval_ms = int(argv[1])
+    max_interval_ms = int(argv[2])
+    print 'Set advertising intervals: [%d, %d]' % (min_interval_ms,
+                                                   max_interval_ms)
+else:
+    print 'Usage: python %s min_interval_ms max_interval_ms' % prog
+    print '       python %s 200 200' % prog
+    sys.exit(1)
+
+
+# Set advertising intervals.
+bus = dbus.SystemBus()
+adapter = bus.get_object('org.bluez', '/org/bluez/hci0')
+adapter.SetAdvertisingIntervals(
+        min_interval_ms, max_interval_ms,
+        dbus_interface='org.bluez.LEAdvertisingManager1')
+
+
+# Wait a little while for dbus method to complete.
+time.sleep(0.2)
+
+
+# Check the current settings using btmgmt.
+btmgmt_cmd = 'btmgmt info'
+for line in subprocess.check_output(btmgmt_cmd.split()).splitlines():
+    if 'current settings' in line:
+        print line.strip()