User talk:Gabrys

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(Step three: load ALSA settings to switch codec "mode" to GSM BT)
(Step three: load ALSA settings to switch codec "mode" to GSM BT)
Line 67: Line 67:
 
(last two lines due to kernel bug).
 
(last two lines due to kernel bug).
  
Set bluetooth IIS to 8000 rate:
+
Issue dbus call to start exchanging audio between GSM and BT:
 +
 
 +
BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
 +
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Play
 +
 
 +
Set bluetooth IIS to 8000 rate and keep it with a sleep in Python:
  
 
  python set_pcm.py
 
  python set_pcm.py
Line 74: Line 79:
  
 
  import alsaaudio
 
  import alsaaudio
 +
import time
 
   
 
   
 
  pcm_play = alsaaudio.PCM( alsaaudio.PCM_PLAYBACK, alsaaudio.PCM_NONBLOCK, "hw:0,1" )
 
  pcm_play = alsaaudio.PCM( alsaaudio.PCM_PLAYBACK, alsaaudio.PCM_NONBLOCK, "hw:0,1" )
Line 87: Line 93:
 
  pcm_cap.setperiodsize(500000)
 
  pcm_cap.setperiodsize(500000)
  
Then issue dbus call to start exchanging audio between GSM and BT:
+
  time.sleep(999)
 
+
  BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
+
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Play
+
  
We should hear something in the BT headset and not in phone's speaker.
+
Now BT should work. Don't touch the screen though, because it will change ALSA settings and you'll lose BT connection.

Revision as of 22:32, 6 April 2010

Contents

Testing GSM <-> BT

Basics: We need to tell audio codec to route sound from GSM chip to BT chip. Codec is controlled by ALSA and mixer settings.

Prerequisites: BT device must be paired before the operation.

Step one: powering on bluetooth, setting up bluetoothd, pairing

Set /etc/bluetooth/audio.conf like this:

# SCO routing. Either PCM or HCI (in which case audio is routed to/from ALSA)   
# Defaults to HCI                                                               
SCORouting=PCM                                                                  

Then

echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on
sleep 1
bluetoothd
hciconfig hci0 up

then use simple-agent from here: http://wiki.openmoko.org/wiki/Manually_using_Bluetooth#Pair to pair the device.

Connect to the headset:

BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Connect

Test: "hcitool con" should say:

Connection
     ACL 00:13:17:78:7B:A3 handle 0 state 5 lm MASTER

Test2:

BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Connect

should say: Error org.bluez.Error.AlreadyConnected: Already Connected


More debug

root@om-gta02 /usr/lib/python2.6/site-packages $ dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Disconnect
method return sender=:1.18 -> dest=:1.287 reply_serial=2

root@om-gta02 /usr/lib/python2.6/site-packages $ dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Connect
Error org.bluez.Error.ConnectionAttemptFailed: Input/output error

root@om-gta02 /usr/lib/python2.6/site-packages $ dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Connect
method return sender=:1.18 -> dest=:1.290 reply_serial=2

root@om-gta02 /usr/lib/python2.6/site-packages $ dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Play   
method return sender=:1.18 -> dest=:1.292 reply_serial=2

Step two: make a call

Call to the phone and answer (or place a call, whichever is cheaper).

Step three: load ALSA settings to switch codec "mode" to GSM <=> BT

Wait till frameworkd sets its statefile and then overwrite it with your own:

alsactl -f /usr/share/shr/scenarii/gsmbluetooth.state restore
amixer sset "Capture Left Mixer" "Analogue Mix Right"
amixer sset "Capture Left Mixer" "Analogue Mix Left"

(last two lines due to kernel bug).

Issue dbus call to start exchanging audio between GSM and BT:

BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Play

Set bluetooth IIS to 8000 rate and keep it with a sleep in Python:

python set_pcm.py

Where the set_pcm.py is:

import alsaaudio
import time

pcm_play = alsaaudio.PCM( alsaaudio.PCM_PLAYBACK, alsaaudio.PCM_NONBLOCK, "hw:0,1" )
pcm_play.setchannels(1)
pcm_play.setrate(8000)
pcm_play.setformat(alsaaudio.PCM_FORMAT_S16_LE)
pcm_play.setperiodsize(500000)

pcm_cap = alsaaudio.PCM( alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, "hw:0,1" )
pcm_cap.setchannels(1)
pcm_cap.setrate(8000)
pcm_cap.setformat(alsaaudio.PCM_FORMAT_S16_LE)
pcm_cap.setperiodsize(500000)
time.sleep(999)

Now BT should work. Don't touch the screen though, because it will change ALSA settings and you'll lose BT connection.

Personal tools

Testing GSM <-> BT

Basics: We need to tell audio codec to route sound from GSM chip to BT chip. Codec is controlled by ALSA and mixer settings.

Prerequisites: BT device must be paired before the operation.

Step one: powering on bluetooth, setting up bluetoothd, pairing

Set /etc/bluetooth/audio.conf like this:

# SCO routing. Either PCM or HCI (in which case audio is routed to/from ALSA)   
# Defaults to HCI                                                               
SCORouting=PCM                                                                  

Then

echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on
sleep 1
bluetoothd
hciconfig hci0 up

then use simple-agent from here: http://wiki.openmoko.org/wiki/Manually_using_Bluetooth#Pair to pair the device.

Connect to the headset:

BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Connect

Test: "hcitool con" should say:

Connection
     ACL 00:13:17:78:7B:A3 handle 0 state 5 lm MASTER

Test2:

BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Connect

should say: Error org.bluez.Error.AlreadyConnected: Already Connected


More debug

root@om-gta02 /usr/lib/python2.6/site-packages $ dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Disconnect
method return sender=:1.18 -> dest=:1.287 reply_serial=2

root@om-gta02 /usr/lib/python2.6/site-packages $ dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Connect
Error org.bluez.Error.ConnectionAttemptFailed: Input/output error

root@om-gta02 /usr/lib/python2.6/site-packages $ dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Connect
method return sender=:1.18 -> dest=:1.290 reply_serial=2

root@om-gta02 /usr/lib/python2.6/site-packages $ dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Play   
method return sender=:1.18 -> dest=:1.292 reply_serial=2

Step two: make a call

Call to the phone and answer (or place a call, whichever is cheaper).

Step three: load ALSA settings to switch codec "mode" to GSM <=> BT

Wait till frameworkd sets its statefile and then overwrite it with your own:

alsactl -f /usr/share/shr/scenarii/gsmbluetooth.state restore
amixer sset "Capture Left Mixer" "Analogue Mix Right"
amixer sset "Capture Left Mixer" "Analogue Mix Left"

(last two lines due to kernel bug).

Issue dbus call to start exchanging audio between GSM and BT:

BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_13_17_78_7B_A3 org.bluez.Headset.Play

Set bluetooth IIS to 8000 rate and keep it with a sleep in Python:

python set_pcm.py

Where the set_pcm.py is:

import alsaaudio
import time

pcm_play = alsaaudio.PCM( alsaaudio.PCM_PLAYBACK, alsaaudio.PCM_NONBLOCK, "hw:0,1" )
pcm_play.setchannels(1)
pcm_play.setrate(8000)
pcm_play.setformat(alsaaudio.PCM_FORMAT_S16_LE)
pcm_play.setperiodsize(500000)

pcm_cap = alsaaudio.PCM( alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NONBLOCK, "hw:0,1" )
pcm_cap.setchannels(1)
pcm_cap.setrate(8000)
pcm_cap.setformat(alsaaudio.PCM_FORMAT_S16_LE)
pcm_cap.setperiodsize(500000)
time.sleep(999)

Now BT should work. Don't touch the screen though, because it will change ALSA settings and you'll lose BT connection.