public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] At commands not available
@ 2005-07-16 16:32 Dirk Vanden Boer
  2005-07-16 17:17 ` Fred Schaettgen
  0 siblings, 1 reply; 8+ messages in thread
From: Dirk Vanden Boer @ 2005-07-16 16:32 UTC (permalink / raw)
  To: bluez-devel

Hi,
I'm trying to send AT commands to my mobile phone using an rfcomm
connection. The connection seems to work because I can exectute some
commands (like manufacturer name). But a whole bunch of commands are
not available (eg. battery charge: "AT+CBC\r" returns ERROR). I can
run the AT* command which lists the available commands but a lot of
common commands are not in the list. Could it be that there is
something wrong with my connection?

Minimilistic testing code:
//necessary includes
#include ...

#define BTADDR "00:0E:07:2D:85:C7"
#define CHANNEL 4
#define BUFSIZE 1024

using namespace std;
string ATCommand(int sock, string atcmd);

int main()
{
=09int sock;
=09struct sockaddr_rc laddr, raddr;
=09struct hci_dev_info di;
=09=09
=09if(hci_devinfo(0, &di) < 0) {
=09=09perror("HCI device info failed"); exit(1);
=09}
=09
=09laddr.rc_family =3D AF_BLUETOOTH;
=09laddr.rc_bdaddr =3D di.bdaddr;
=09laddr.rc_channel =3D 0;
=09
=09raddr.rc_family =3D AF_BLUETOOTH;
=09str2ba(BTADDR,&raddr.rc_bdaddr);
=09raddr.rc_channel =3D htobs(CHANNEL);
=09
=09if((sock =3D socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
=09=09perror("socket"); exit(1);
=09}
=09if(bind(sock, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
=09=09perror("bind"); exit(1);
=09}
=09if(connect(sock, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) {
=09=09perror("connect"); exit(1);
=09}
=09
=09cout << "Response:\n" << ATCommand(sock, "AT+CBC\r");
=09
=09close (sock);
=09return 0;
}

string ATCommand(int sock, string atcmd)
{
=09char buf[BUFSIZE];
=09int nbytes;
=09string response =3D "";
=09
=09if(send(sock, atcmd.c_str(), atcmd.length(), 0) =3D=3D -1){
=09=09perror("send"); exit(1);
=09}
=09
=09for(;;)
=09{
=09=09if((nbytes =3D recv(sock, buf, sizeof (buf), 0)) > 0)
=09=09{
=09=09=09response.append(buf);
=09=09=09if (strstr(buf, "\r\nOK") !=3D NULL)
=09=09=09=09break;
=09=09=09if (strstr(buf, "\r\nERROR") !=3D NULL)
=09=09=09=09break;
=09=09}
=09}
=09return response;
}

results in:
AT+CBC
ERROR

Did I forget something that activates the extra commands?

Thanks in advance,
Dirk


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-07-19 15:06 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-16 16:32 [Bluez-devel] At commands not available Dirk Vanden Boer
2005-07-16 17:17 ` Fred Schaettgen
2005-07-16 17:26   ` Dirk Vanden Boer
2005-07-16 17:35     ` Peter Wippich
2005-07-16 18:06       ` Dirk Vanden Boer
2005-07-16 18:24         ` Peter Wippich
2005-07-16 19:13           ` Dirk Vanden Boer
2005-07-19 15:06             ` Luca Pizzamiglio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox