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

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

问题描述

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

我的目标是模拟来电,以便蓝牙手环开始振动(这似乎是唯一的方法).为此,我使用 AT 命令.在

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.

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).

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"?).

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.

UPDATE 10/29/2014

===== 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
".getBytes());
        mBluetoothSocket.getOutputStream().write("OK
".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());

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...

解决方案

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").

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天全站免登陆