Android通过AT命令与HFP设备通信 [英] Android communicating to HFP device via AT commands

查看:251
本文介绍了Android通过AT命令与HFP设备通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im试图通过Android中的HFP(免提配置文件)来控制具有振动功能的蓝牙手链.我已经能够连接到手镯并访问输入和输出流.

im trying to control a bluetooth bracelet with vibration function via HFP (hands free profile) in Android. I've been able to connect to the bracelet and access the input- and outputstream.

我的目标是模拟来电,以便蓝牙手镯开始振动(这似乎是唯一的方法).为此,即时通讯使用AT命令.在 https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=238193 在第22页,您可以看到建立服务级别连接的握手. 我需要建立此连接才能使用"+ CIEV"命令(请参见握手第48页).

My goal is to simulate an incoming call so that the bluetooth bracelet starts vibrating (which seems to be the only way to do that). To do this, im using AT commands. In the bluetooth specs at https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=238193 on page 22 you can see the handshake to establish service level connection. I need to establish this connection to use the "+CIEV" command (see handshake page 48).

但是当我的手镯返回命令"AT + CIND =?"时,我不知道该如何回应.我找不到有关如何使用"CIND:"命令回答的任何提示.我也不知道如何发送确认(只是确定"?)​​.

But when my bracelet returns the command "AT+CIND=?" I dont know how to respond. I can't find any hints on how to answer with the "CIND:" command. Also I dont know how to send the acknowledgement (is it just "OK"?).

这甚至可能是完全错误的方法.每个建议都表示赞赏.我只发现了一个 post 关于stackoverflow的问题,以某种方式对我有帮助,我发现的其余帖子均未得到解答. 顺便说一句,即时通讯使用智能手机与Android 4.1.2.手链支持HFP和HSP.预先感谢.

That might even be the completely wrong way to do this. Every suggestion is appreciated. I only found one post on stackoverflow that helped me in some way, rest of the posts I found were unanswered. By the way, im using a smartphone with Android 4.1.2. The bracelet supports HFP and HSP. Thanks in advance.

更新10/29/2014

=====通过RFCOMM套接字建立的连接=====

===== Connection through RFCOMM Socket established at this point =====

        // read AT+BRSF=0 from device
        byte[] buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());

        //write answer BRSF: ...
        mBluetoothSocket.getOutputStream().write("+BRSF=20\r".getBytes());
        mBluetoothSocket.getOutputStream().write("OK\r".getBytes());

        // read AT+CIND=? command
        buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());

        //write answer CIND: ...
        mBluetoothSocket.getOutputStream().write("+CIND: (\"battchg\",(0-5)),(\"signal\",(0-5)),
           (\"service\",(0,1)),(\"call\",(0,1)),(\"callsetup\",(0-3)),
           (\"callheld\",(0-2)),(\"roam\",(0,1))".getBytes());
        mBluetoothSocket.getOutputStream().write("OK".getBytes());

        // read AT+CIND?
        buffer = new byte[200];
        mBluetoothSocket.getInputStream().read(buffer);
        Log.d(TAG, new String(buffer).trim());

按照协议的步骤操作,我应该收到"AT + CIND?"命令,然后我可以发送命令"+ CIND:5、5、1、0、0、0、0",但是...我没有收到"AT + CIND?"命令.即时消息我什么也没收到.我想念什么吗?发送确定"不会改变任何事情……

Following the procedure of the protocol, I should receive the "AT+CIND?" command and then I could send the command "+CIND: 5,5,1,0,0,0,0", but...I dont receive the "AT+CIND?" command. Actually im not receiving anything. Am I missing something? Sending an "OK" doesnt change anything btw...

推荐答案

我对同样的问题感到困惑.经过数天的反复试验,我终于使它起作用. 我认为这取决于您回答HF命令的速度以及正确的行尾("COMMAND").

I was fiddeling with exaclty the same problem. After days of trial and error, I finally got it to work. I think it depends on the speed at wich you answer the HF's commands, as well as on the correct line-endings ("COMMAND").

这是我的DroidScript,可以正常工作.它没有清理,但是可以工作.

Here is my DroidScript which works. It's not cleaned up, but it works.

https://gist.github.com/t-oster/68a568ac4c4e133f67ac

这篇关于Android通过AT命令与HFP设备通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆