google / mobly

E2E test framework for tests with complex environment requirements.
https://github.com/google/mobly
Apache License 2.0
647 stars 179 forks source link

Control headphone device #589

Closed aglogger closed 5 years ago

aglogger commented 5 years ago

Is it possible to control a bluetooth headphone device with mobly in any way? For example, simulating pressing the pairing button to run automated tests without having to perform manual operations on the device.

xpconanfan commented 5 years ago

Yes.

You can use electric relays to simulate button presses.

On Fri, Jun 28, 2019, 3:14 PM aglogger notifications@github.com wrote:

Is it possible to control a bluetooth headphone device with mobly in any way? For example, simulating pressing the pairing button to run automated tests without having to perform manual operations on the device.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/mobly/issues/589?email_source=notifications&email_token=AARDNZLDFG6YJZCA6L6LJ23P4W26NA5CNFSM4H4CZJS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G4H54PQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AARDNZK2NLONQAAAX42PTKDP4W26NANCNFSM4H4CZJSQ .

aglogger commented 5 years ago

Do you might have anything on how to get me started on this, because I haven't had any experience with it yet.

xpconanfan commented 5 years ago

@mderu Can you share some links?

aglogger commented 5 years ago

What I found out so far is that I have to reverse-engineer the headphone (analyze what happens when pressing a button), then solder a relay to the corresponding positions on the headphone to bridge the circuits and finally control the corresponding relay signals via a PC using python. Is this basic structure correct so far? I would still be very happy about some links that explain the process of implementing such a setup. Thank you ;)

mderu commented 5 years ago

Hey @aglogger,

There's a controller found in Android's ACTS that has this functionality already.(https://android.googlesource.com/platform/tools/test/connectivity/+/refs/heads/master/acts/framework/acts/controllers/relay_lib/, https://android.googlesource.com/platform/tools/test/connectivity/+/refs/heads/master/acts/framework/acts/controllers/relay_device_controller.py) We're looking into bringing it into Mobly's controllers, but it's going to take some time to get around to. Feel free use this in the meantime. From the relay devices supported in the library, we've seen the best performance from https://www.sainsmart.com/products/8-channel-12v-usb-relay-module (sain_smart_8_channel_usb_relay_board.py in the above library), although after two years of constant use, some of these have spent their 50,000 switch lifespans.

aglogger commented 5 years ago

@mderu Thanks a lot for the tips! Was I right regarding the basic construction of the setup and could you recommend a headphone or speaker that can be reverse engineered as simply as possible for this purpose?

Concerning the ACTS controller: Can it be used out of the box or do I have to make adjustments?

mderu commented 5 years ago

Yes, we pull apart the devices and solder leads onto the button contacts, and attach them to a relay board.

I don't remember the easiest speaker to reverse engineer; most of the headsets take about the same amount of effort. Usually, the more exposed the buttons are, the easier it is to rewire them. Take a look at the headphone classes we have in the relay_lib directory, most of them should specify the exact model they use within the class docstring.

The ACTS controller should be usable out-of-the-box, but you'll need to change the ACTS_CONTROLLER_CONFIG_NAME to MOBLY_CONTROLLER_CONFIG_NAME instead to get it to work with Mobly's register_controller(). If you plan on copying the code and not installing ACTS directly, you may have to install the libftdi/libusb libraries. The file acts/framework/acts/controllers/relay_lib/sain_smart_8_channel_usb_relay_board.py should have documentation you need on the setup here.