* [Bluez-devel] some btsco hacks
@ 2005-05-05 18:58 Florian Echtler
2005-05-05 21:09 ` [Bluez-devel] " Brad Midgley
0 siblings, 1 reply; 6+ messages in thread
From: Florian Echtler @ 2005-05-05 18:58 UTC (permalink / raw)
To: bmidgley, bluez-devel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1471 bytes --]
-----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-----
[-- Attachment #2: Type: TEXT/PLAIN, Size: 2812 bytes --]
diff -u -r1.22 btsco.c
--- btsco.c 3 May 2005 15:37:12 -0000 1.22
+++ btsco.c 5 May 2005 18:46:14 -0000
@@ -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) {
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bluez-devel] Re: some btsco hacks
2005-05-05 18:58 [Bluez-devel] some btsco hacks Florian Echtler
@ 2005-05-05 21:09 ` Brad Midgley
2005-05-06 20:52 ` Florian Echtler
0 siblings, 1 reply; 6+ messages in thread
From: Brad Midgley @ 2005-05-05 21:09 UTC (permalink / raw)
To: Florian Echtler, bluez-devel
Florian
> 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
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] Re: some btsco hacks
2005-05-05 21:09 ` [Bluez-devel] " Brad Midgley
@ 2005-05-06 20:52 ` Florian Echtler
2005-05-09 5:16 ` Brad Midgley
0 siblings, 1 reply; 6+ messages in thread
From: Florian Echtler @ 2005-05-06 20:52 UTC (permalink / raw)
To: bmidgley, bluez-devel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 770 bytes --]
-----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.
> 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 &
> 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-----
[-- Attachment #2: Type: TEXT/PLAIN, Size: 1535 bytes --]
diff -u -r1.24 btsco.c
--- btsco.c 5 May 2005 21:15:30 -0000 1.24
+++ btsco.c 6 May 2005 20:50:20 -0000
@@ -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);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] Re: some btsco hacks
2005-05-06 20:52 ` Florian Echtler
@ 2005-05-09 5:16 ` Brad Midgley
2005-05-09 22:14 ` Florian Echtler
0 siblings, 1 reply; 6+ messages in thread
From: Brad Midgley @ 2005-05-09 5:16 UTC (permalink / raw)
To: Florian Echtler, bluez-devel
Florian
> 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.
ok, applied.
> Well, my .btscorc currently looks like this:
>
> AT\+CKPD=200
> sco-toggle on off
> AT\+CKPD=200
> system /home/echtler/bin/headset %d &
>
>>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
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] Re: some btsco hacks
2005-05-09 5:16 ` Brad Midgley
@ 2005-05-09 22:14 ` Florian Echtler
2005-05-09 23:11 ` Brad Midgley
0 siblings, 1 reply; 6+ messages in thread
From: Florian Echtler @ 2005-05-09 22:14 UTC (permalink / raw)
To: Brad Midgley; +Cc: bluez-devel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 962 bytes --]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> > 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.
> 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-----
[-- Attachment #2: Type: TEXT/PLAIN, Size: 1035 bytes --]
diff -u -r1.25 btsco.c
--- btsco.c 9 May 2005 04:57:29 -0000 1.25
+++ btsco.c 9 May 2005 22:11:43 -0000
@@ -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);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bluez-devel] Re: some btsco hacks
2005-05-09 22:14 ` Florian Echtler
@ 2005-05-09 23:11 ` Brad Midgley
0 siblings, 0 replies; 6+ messages in thread
From: Brad Midgley @ 2005-05-09 23:11 UTC (permalink / raw)
To: bluez-devel
thanks Florian. applied.
Florian Echtler wrote:
>>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
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-05-09 23:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-05 18:58 [Bluez-devel] some btsco hacks Florian Echtler
2005-05-05 21:09 ` [Bluez-devel] " Brad Midgley
2005-05-06 20:52 ` Florian Echtler
2005-05-09 5:16 ` Brad Midgley
2005-05-09 22:14 ` Florian Echtler
2005-05-09 23:11 ` Brad Midgley
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.