mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
backend-native: Handle multi AT commands in a buffer
When we connect Lenovo XT99 bt headset in the Ubuntu 22.04, this headset could only work in A2DP profile, couldn't work in HFP profile with a high chance. This headset supports mSBC, after pulseaudio replies "+BCS:2" to headset, we expect to receive a "AT+BCS=2\r" from the headset, but with a high chance, it will receive 2 AT commands in a buffer like this "AT+CHLD=?\rAT+BCS=2\r", and we also observed other 2 AT commands in a buffer like this "AT+NREC=0\rAT+CGMI?\r". Here we don't suppose there is only one AT command in a buffer, we will find each command by the delimiter "\r" and handle each command by sequence. Signed-off-by: Hui Wang <hui.wang@canonical.com> Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/804>
This commit is contained in:
parent
81a6cc4967
commit
d7dc04e8f5
1 changed files with 97 additions and 83 deletions
|
|
@ -889,21 +889,23 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events & PA_IO_EVENT_INPUT) {
|
if (events & PA_IO_EVENT_INPUT) {
|
||||||
char buf[512];
|
char rbuf[512];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
int gain, dummy;
|
int gain, dummy;
|
||||||
bool do_reply = false;
|
bool do_reply = false;
|
||||||
int vendor, product, version, features;
|
int vendor, product, version, features;
|
||||||
|
char *buf = rbuf;
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
len = pa_read(fd, buf, 511, NULL);
|
len = pa_read(fd, rbuf, 511, NULL);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
pa_log_error("RFCOMM read error: %s", pa_cstrerror(errno));
|
pa_log_error("RFCOMM read error: %s", pa_cstrerror(errno));
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
buf[len] = 0;
|
rbuf[len] = 0;
|
||||||
pa_log_debug("RFCOMM << %s", buf);
|
pa_log_debug("RFCOMM << %s", rbuf);
|
||||||
|
|
||||||
|
while (buf[0]) {
|
||||||
/* There are only four HSP AT commands:
|
/* There are only four HSP AT commands:
|
||||||
* AT+VGS=value: value between 0 and 15, sent by the HS to AG to set the speaker gain.
|
* AT+VGS=value: value between 0 and 15, sent by the HS to AG to set the speaker gain.
|
||||||
* +VGS=value is sent by AG to HS as a response to an AT+VGS command or when the gain
|
* +VGS=value is sent by AG to HS as a response to an AT+VGS command or when the gain
|
||||||
|
|
@ -989,6 +991,18 @@ static void rfcomm_io_callback(pa_mainloop_api *io, pa_io_event *e, int fd, pa_i
|
||||||
|
|
||||||
if (do_reply)
|
if (do_reply)
|
||||||
rfcomm_write_response(fd, "OK");
|
rfcomm_write_response(fd, "OK");
|
||||||
|
|
||||||
|
if (buf[0] == '\r') /* in case it is the command with format \r\nCOMMAND\r\n, skip the starting \r */
|
||||||
|
buf = buf + 1;
|
||||||
|
|
||||||
|
buf = strstr(buf, "\r"); /* try to find the next AT command in the buf */
|
||||||
|
if (!buf)
|
||||||
|
break;
|
||||||
|
else if (buf[1] == '\n')
|
||||||
|
buf = buf + 2; /* skip \r\n */
|
||||||
|
else
|
||||||
|
buf = buf + 1; /* skip \r */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue