some btsco hacks
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello everyone,
I finally got time to investigate the issues with my headset. Sometimes after SCO connection establishment, the microphone produces only noise, and a reconnect is necessary to fix this. The attached patch is against btsco.c v1.22 from CVS, and does two things:
1. installs a handler for SIGUSR2 which automatically disconnects the SCO channel when connected and reconnects it after a short delay
2. allows the command string in .btscorc to contain '%d', which will be replaced with the current SCO connection status (0 or 1) upon command execution.
1. may be not really useful to most people - as mentioned, my headset is obviously somewhat buggy and needs a kind of reset sometimes, which this patch provides (actually, I wrote a shell script which samples 1 second of audio data from the headset, runs it through gzip to determine whether it's noise and sends SIGUSR2 accordingly - talk about evil hacks ;)
2. was included because I want certain actions to happen only when the connection is established, and not when it's shutting down.
Brad: if you think this could be useful otherwise, then feel free to include the patch into CVS.
Yours, Florian
- --
Preserve wildlife - pickle a squirrel today!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCemzI7CzyshGvatgRArpWAJ4g4j5sgUjj3ulgVwxORICyjYdyHgCg5qpr gE4T1Cniprq057+KD2i79kE=
=jha8
-----END PGP SIGNATURE-----
btsco.c +48 -20
@@ -80,7 +80,7 @@char *cmd; }; -static volatile int terminate =0 , ring =0 , hupped =0 ; +static volatile int terminate =0 , ring =0 , hupped =0 , reconnect =0 ;static int verbose =0 ;static void sig_term (int sig)
@@ -98,6 +98,11 @@ hupped =1 ; } +static void sig_usr (int sig) +{ + reconnect =1 ; +} +static int rfcomm_connect (bdaddr_t * src,bdaddr_t * dst,uint8_t channel) {struct sockaddr_rc addr;
@@ -573,6 +578,9 @@ sa.sa_handler = sig_ring;sigaction (SIGUSR1 , &sa,NULL ); + sa.sa_handler = sig_usr; +sigaction (SIGUSR2 , &sa,NULL ); + sa.sa_handler = sig_hup;sigaction (SIGHUP , &sa,NULL );
@@ -704,7 +712,11 @@int substl =0 ; subst =NULL ; - sysbuf =strdup (args); + +// add the current sco mode to the command string + sysbuf =malloc (strlen (args)+1 ); +sprintf (sysbuf,args,sco_mode); +for (i =0 ; sysbuf[i]; i++) {if ((sysbuf[i] =='\\' ) && (sysbuf[i +1 ] >='0' ) && (sysbuf[i +1 ] <='9' )) { match = sysbuf[i +1 ] -'0' ;
@@ -804,6 +816,40 @@ } +// mean little hack to allow for a signal-triggered reconnect +// force disconnection of the channel (if connected) +if (reconnect ==1 ) { +if (sco_mode ==CONNECTED ) { + force_sco =0 ; + reconnect =-1 ; + }else reconnect =0 ; + } + +if (((!dr_usage && (force_sco !=1 )) || (force_sco ==0 )) && (sco_mode ==CONNECTED )) { +if (verbose) { +printf ("driver is not in use\n" ); +fflush (stdout); + } +/* close bt_sco audio handle */ +bt_sco_set_fd (handle,-1 ); +/* disconnect SCO stream */ +close (sd); +if (verbose) { +printf ("disconnected SCO channel\n" ); +fflush (stdout); + } + + sco_mode =NOT_CONNECTED ; + } + +// if a reconnect has been requested, force +// the sco channel to be acquired again +if (reconnect ==-1 ) { + force_sco =1 ; + reconnect =0 ; +sleep (3 ); + } +if (((dr_usage && (force_sco !=0 )) || (force_sco ==1 )) && (sco_mode ==NOT_CONNECTED )) {if (verbose) {printf ("driver is in use\n" );
@@ -825,24 +871,6 @@ } sco_mode =CONNECTED ; } - - } -if (((!dr_usage && (force_sco !=1 )) || (force_sco ==0 )) && (sco_mode ==CONNECTED )) { -if (verbose) { -printf ("driver is not in use\n" ); -fflush (stdout); - } -/* close bt_sco audio handle */ -bt_sco_set_fd (handle,-1 ); -/* disconnect SCO stream */ -close (sd); -if (verbose) { -printf ("disconnected SCO channel\n" ); -fflush (stdout); - } - - sco_mode =NOT_CONNECTED ; - }if (ring) {
Florian
Quoted 3 lines
2. allows the command string in .btscorc to contain '%d', which will be replaced with the current SCO connection status (0 or 1) upon command execution.
the patch looks fine.
could you give me some examples from your .btscorc?
do you know what the syntax of 'back references' is in .btscorc?
brad
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello Brad,
I noticed that there was a small bug left in my patch (the value of force_sco was overwritten when a reconnect was requested). This small additional patch should fix that.
Quoted 1 line
could you give me some examples from your .btscorc?
Well, my .btscorc currently looks like this:
AT\+CKPD=200
sco-toggle on off
AT\+CKPD=200
system /home/echtler/bin/headset %d &
Quoted 1 line
do you know what the syntax of 'back references' is in .btscorc?
Back references to what/where?
Yours, Florian
- --
Preserve wildlife - pickle a squirrel today!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCe9ks7CzyshGvatgRAkoxAKDxCwtRZKTHSujGXyrqRdaNEL43/wCfbPjd D0q3ebE9/sMYojjLzaZFMug=
=4Wfl
-----END PGP SIGNATURE-----
btsco.c +13 -9
@@ -460,7 +460,7 @@uint16_t sco_handle, sco_mtu, vs;char line[100 ];int last_volumes[2 ]; -int dr_usage, force_sco; +int dr_usage, force_sco, force_old;// sco_mode is our running mode. 0 => not connect, 1 => connected // see NOT_CONNECTED,CONNECTED :)
@@ -624,6 +624,7 @@ } dr_usage = infobuf.playback_count || infobuf.capture_count; force_sco =-1 ; + force_old =-1 ;if (fork)daemon (0 ,0 );
@@ -818,12 +819,10 @@// mean little hack to allow for a signal-triggered reconnect // force disconnection of the channel (if connected) -if (reconnect ==1 ) { -if (sco_mode ==CONNECTED ) { - force_sco =0 ; - reconnect =-1 ; - }else reconnect =0 ; - } +if (reconnect && (sco_mode ==CONNECTED )) { + force_old = force_sco; + force_sco =0 ; + }else reconnect =0 ;if (((!dr_usage && (force_sco !=1 )) || (force_sco ==0 )) && (sco_mode ==CONNECTED )) {if (verbose) {
@@ -844,9 +843,8 @@// if a reconnect has been requested, force // the sco channel to be acquired again -if (reconnect ==-1 ) { +if (reconnect) { force_sco =1 ; - reconnect =0 ;sleep (3 ); }
@@ -872,6 +870,12 @@ sco_mode =CONNECTED ; } } + +// restore original program status +if (reconnect) { + force_sco = force_old; + reconnect =0 ; + }if (ring) {write (rd,"\r\nRING\r\n" ,8 );
Florian
Quoted 3 lines
I noticed that there was a small bug left in my patch (the value of
force_scowas overwritten when a reconnect was requested). This small additional patch should fix that.
ok, applied.
Quoted 10 lines
Well, my .btscorc currently looks like this:
AT\+CKPD=200
sco-toggle on off
AT\+CKPD=200
system/home/echtler/bin/headset%d &Quoted 1 line
do you know what the syntax of 'back references' is in .btscorc?
Back references to what/where?
backrefs are parts of the regexp surrounded by (). the matching expression is remembered and can be placed in the command string, by \0 \1 etc it turns out.
I figured them out & noted in the docs.
In keeping with \0 \1 for backrefs in the regexp and \p for pid, the headset state should be \s instead of %d. Would you be willing to make that change (or I could)?
thanks
Brad
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 4 lines
Quoted 1 line
Back references to what/where?
backrefs are parts of the regexp surrounded by (). the matching expression is remembered and can be placed in the command string, by \0 \1 etc it turns out. I figured them out & noted in the docs.
Ah, I see - I had overlooked that part of the code.
Quoted 3 lines
In keeping with \0 \1 for backrefs in the regexp and \p for pid, the headset state should be \s instead of %d. Would you be willing to make that change (or I could)?
No problem, see attached patch.
Another question: has anyone experienced the same problem as I have (the microphone input sometimes generates only noise) or is that strictly a bug of my headset?
Yours, Florian
- --
Preserve wildlife - pickle a squirrel today!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFCf+DS7CzyshGvatgRAmBVAKDfFJndw9pvwYxeENUCDj7gVyTLhwCfXBBS LXVG5Iht3y0zFJp7REc3VeE=
=r6pM
-----END PGP SIGNATURE-----
btsco.c +5 -4
@@ -713,10 +713,7 @@int substl =0 ; subst =NULL ; - -// add the current sco mode to the command string - sysbuf =malloc (strlen (args)+1 ); -sprintf (sysbuf,args,sco_mode); + sysbuf =strdup (args);for (i =0 ; sysbuf[i]; i++) {if ((sysbuf[i] =='\\' ) && (sysbuf[i +1 ] >='0' ) && (sysbuf[i +1 ] <='9' )) {
@@ -730,6 +727,10 @@ subst =malloc (11 );/* For potentially 32-bit PIDs */ substl =snprintf (subst,11 ,"%i" ,getpid ()); } +if ((sysbuf[i] =='\\' ) && (sysbuf[i +1 ] =='s' )) { + subst =malloc (11 );/* same as above, for SCO mode */ + substl =snprintf (subst,11 ,"%d" , sco_mode); + }if (subst !=NULL ) { sysbuf =realloc (sysbuf,strlen (sysbuf) + substl -1 );memmove (sysbuf + i + substl, sysbuf + i +2 ,strlen (sysbuf) - i -1 );
thanks Florian. applied.
Quoted 5 lines · Florian Echtler
Quoted 3 lines
In keeping with \0 \1 for backrefs in the regexp and \p for pid, the headset state should be \s instead of %d. Would you be willing to make that change (or I could)?
No problem, see attached patch.
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4 opportunities to win big! Highest score wins.NEC IT Guy Games. Play to win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel