【Android】【Bluetooth Stack】蓝牙电话协议之AT指令详解(超详细)

1. 精讲蓝牙协议栈(Bluetooth Stack):SPP/A2DP/AVRCP/HFP/PBAP/IAP2/HID/MAP/OPP/PAN/GATTC/GATTS/HOGP等协议理论

2. 欢迎大家关注和订阅,【蓝牙协议栈】【Android Bluetooth Stack】专栏会持续更新中.....敬请期待!

 1. 协议架构

1.1 Profile Dependencies

在蓝牙电话的数据传输中使用的是SCO协议(同步定向链接)。支持对时延敏感的信息如语音。

使用保留带宽进行同步通信,即两台设备在LMP层利用保留时隙在物理信道上周期传送数据包,这种类型的链接主要用于传送SCO包(语音数据)。SCO不包括CRC码,且不进行重传,主要支持传输有时间限制的信息,例如声音。

仅仅在ACL链接已经建立之后,才可以建立SCO链接;

  • AT CMD:AT指令是应用于终端设备和PC应用之间的连接与通信的指令;

  • SPP:蓝牙串口协议,在蓝牙设备之间建立虚拟的串口进行数据通信,简单的说就是两个蓝牙设备对端发送自定义数据;iPhone不支持SPP协议;

  • GAP:通用访问配置文件,该Profile保证不同的Bluetooth产品可以互相发现对方并建立连接;GAP定义了蓝牙设备如何发现和建立与其他设备的安全/不安全连接,它处理一些一般模式的业务(询问、命名和搜索)和一些安全性问题;GAP一般有4个作用:

    • Profile Role
    • 可发现模式和过程
    • 连接模式和过程
    • 安全模式和过程
  • eSCO:可以简单的理解为和SCO不同点:支持数据包的重传;

  • incoming call:由Phone Network到AG的通话,即称为来电;

  • outgoing call:由AG到Phone Network的通话,即称为拨号,去电;

1.2 HFP Protocol Stack

针对蓝牙电话,涉及到的协议有:HFP、RFCOMM;

目前HFP的使用场景常见的有车载蓝牙、耳机、PDA(Personal Digital Assistant - 掌上电脑,类似于智能手机、平板电脑、手持游戏机等),其中HFP协议中定义了AG和HFP两种角色:

  • AG(Audio Gate):音频网关 - 音频设备输入输出网关;
  • HF(Hands Free):免提 - 该设备作为音频网关的远程音频输入 / 输出机制,并可提供若干遥控功能;

在车载领域,手机侧为AG,车载侧为HF,在Android源码定义中,通常将AG称为HFP/AG,将HF称为HFPClient/HF;

2. HFP功能支持情况

(M代表强制支持,O代表可选)

Num function HF AG Num function HF AG
1 连接管理 M M 14 噪声抑制回声消除 O O
2 电话状态信息 M M 15 语音识别 O O
3 音频连接处理 M M 16 号码绑定语音标签 O O
4 接收语音来电 M M 17 传输多音频能力 O M
5 拒绝语音来电 M O 18 远程音量控制 O O
6 中断电话 M M 19 回复和保持 O O
7 通话中音频链路切换 M M 20 描述号码信息 O M
8 免提设备拨号 O M 21a 扩展电话状态 O M
9 历史列表拨号 O M 21b 扩展电话控制 O O
10 拨打最后一个电话 O M 22 特有指示 O M
11 拨号等待通知 O M 23 宽频语音 O O
12 三方通话 O O 24 编解码器协商 O O
13 CLI(呼叫线路识别) O M 25 手持设备指示器 O O

3. AT 指令详解

3.1 AT+BRSF & +BRSF

Frame 443: 26 bytes on wire (208 bits), 26 bytes captured (208 bits)
    Encapsulation type: Bluetooth H4 with linux header (99)
    Arrival Time: Jan  1, 2020 00:02:46.903888000 CST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1577808166.903888000 seconds
    [Time delta from previous captured frame: 0.000048000 seconds]
    [Time delta from previous displayed frame: 0.000048000 seconds]
    [Time since reference or first frame: 20.797399000 seconds]
    Frame Number: 443
    Frame Length: 26 bytes (208 bits)
    Capture Length: 26 bytes (208 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    Point-to-Point Direction: Sent (0)
    [Protocols in frame: bluetooth:hci_h4:bthci_acl:btl2cap:btrfcomm:bthfp]
Bluetooth
    [Source: BarrotTe_50:67:20 (04:7f:0e:50:67:20)]
    [Destination: HuaweiDe_42:c7:dd (30:aa:e4:42:c7:dd)]
Bluetooth HCI H4
    [Direction: Sent (0x00)]
    HCI Packet Type: ACL Data (0x02)
Bluetooth HCI ACL Packet
    .... 0000 0000 0001 = Connection Handle: 0x001
    ..10 .... .... .... = PB Flag: First Automatically Flushable Packet (2)
    00.. .... .... .... = BC Flag: Point-To-Point (0)
    Data Total Length: 21
    Data
    [Connect in frame: 115]
    [Source BD_ADDR: BarrotTe_50:67:20 (04:7f:0e:50:67:20)]
    [Source Device Name: HAVAL_6720]
    [Source Role: Slave (2)]
    [Destination BD_ADDR: HuaweiDe_42:c7:dd (30:aa:e4:42:c7:dd)]
    [Destination Device Name: dupz]
    [Destination Role: Master (1)]
    [Last Role Change in Frame: 111]
    [Current Mode: Active Mode (0)]
    [Last Mode Change in Frame: 400]
Bluetooth L2CAP Protocol
    Length: 17
    CID: Dynamically Allocated Channel (0x0041)
    [Connect in frame: 416]
    [PSM: RFCOMM (0x0003)]
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 1, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..1. = C/R Flag: Command (0x1)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 12
    Credits: 3
    Frame Check Sequence: 0x93
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+BRSF=767\r
    Command 0: +BRSF
        Command Line Prefix: AT
        Command: +BRSF (Bluetooth Retrieve Supported Features)
        Type: Action Command (0x003d)
        Parameters
            HS supported features bitmask: 767
                .... .... .... .... .... .... .... ...1 = EC and/or NR function: True
                .... .... .... .... .... .... .... ..1. = Call waiting or 3-way calling: True
                .... .... .... .... .... .... .... .1.. = CLI Presentation: True
                .... .... .... .... .... .... .... 1... = Voice Recognition Activation: True
                .... .... .... .... .... .... ...1 .... = Remote Volume Control: True
                .... .... .... .... .... .... ..1. .... = Enhanced Call Status: True
                .... .... .... .... .... .... .1.. .... = Enhanced Call Control: True
                .... .... .... .... .... .... 1... .... = Codec Negotiation: True
                .... .... .... .... .... ...0 .... .... = HF Indicators: False
                .... .... .... .... .... ..1. .... .... = eSCO S4 (and T2) Settings Support: True
                0000 0000 0000 0000 0000 00.. .... .... = Reserved: 0x000000

上述的数据包中,Frame、Bluetooth、Bluetooth HCI H4、Bluetooth HCI ACL Packet信息基本上和之前描述蓝牙音乐模块描述的信息一致,主要是用来表述数据包Frame、Source Device Info 和 Destination Device Info信息;

其中PSM 中执行协议为 RFCOMM,代表了使用了RFCOMM协议为 L2CAP 建立连接的;

核心的模块为BLuetooth HFP Profile模块信息的描述;

  • Command Line Prefix:AT,用于代表了命令前缀;

  • Command:+BSRF,用于一方向另一方通知该设备支持的服功能情况;

  • Parameters:用于描述HS 支持的 features;

    • EC and/or NR function(EC / NR 功能):true
    • Call waiting or 3-way calling(三方通话):true
    • CLI Presentation(CLI演示功能):true
    • Voice Recognition Activation(语音识别激活):true
    • Remote Volume Control(远程音量控制):true
    • Enhanced Call Status(增强的通话状态):true
    • Enhanced Call Control(增强的呼叫控制):true
    • Codec Negotiation(编解码器协商):true
    • HF Indicators(HF 指标):true
    • eSCO S4 (and T2) Settings Support(支持的eSCO S4 设置):true

上述的Parameters用于描述HF侧支持的功能并告知AG侧,同时也向AG侧发起了支持功能的请求,通过 +BSRF 来响应 AT+BSRF 指令;

…………………………
​
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 0, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..0. = C/R Flag: Response (0x0)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 14
    Credits: 4
    Frame Check Sequence: 0x49
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+BRSF: 879\r\n
    Command 0: +BRSF
        Command: +BRSF (Bluetooth Retrieve Supported Features)
        Type: Response (0x003a)
        Parameters
            AG supported features bitmask: 879
                .... .... .... .... .... .... .... ...1 = Three Way Calling: True
                .... .... .... .... .... .... .... ..1. = EC and/or NR function: True
                .... .... .... .... .... .... .... .1.. = Voice Recognition Function: True
                .... .... .... .... .... .... .... 1... = In-band Ring Tone: True
                .... .... .... .... .... .... ...0 .... = Attach Number to Voice Tag: False
                .... .... .... .... .... .... ..1. .... = Ability to Reject a Call: True
                .... .... .... .... .... .... .1.. .... = Enhanced Call Status: True
                .... .... .... .... .... .... 0... .... = Enhanced Call Control: False
                .... .... .... .... .... ...1 .... .... = Extended Error Result Codes: True
                .... .... .... .... .... ..1. .... .... = Codec Negotiation: True
                .... .... .... .... .... .0.. .... .... = HF Indicators: False
                .... .... .... .... .... 0... .... .... = eSCO S4 (and T2) Settings Support: False
                0000 0000 0000 0000 0000 .... .... .... = Reserved: 0x00000
  • Command:+BRSF,代表了AT+BRSF指令的响应;

  • Type:Response,表明了+BRSF指令的类型为响应;

  • Parameters:和AT+BRSF指令类似,都是用于描述对应侧,这里指AG侧支持的功能;

    • Three Way Calling:true
    • EC and/or NR function:true
    • Voice Recognition Function:true
    • In-band Ring Tone:true
    • Attach Number to Voice Tag:false
    • Ability to Reject a Call:true
    • Enhanced Call Status:true
    • Enhanced Call Control:false
    • Extended Error Result Codes:true
    • Codec Indicators:false
    • eSCO S4 (and T2) Settings Support:false

3.2 AT+BAC

…………………………
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 1, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..1. = C/R Flag: Command (0x1)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 11
    Credits: 2
    Frame Check Sequence: 0x93
Bluetooth HFP Profile
    [Role: HS - Headset (2)]+BIND
    AT Stream: AT+BAC=1,2\r
    Command 0: +BAC
        Command Line Prefix: AT
        Command: +BAC (Bluetooth Available Codecs)
        Type: Action Command (0x003d)
        Parameters
            Codec: CVSD (1)
            Codec: mSBC (2)
  • Command:+BAC,蓝牙可用编解码器,此指令通知AG HF支持哪些编解码器;
  • Codec = CVSD (1):该编码方式的数据传输使用SCO或eSCO链路。链路的选取是根据本端Controller是否支持Enhanced Setup Synchronous Connection指令来决定的,如果支持该命令则创建语音音频链路时使用eSCO,否则创建SCO链路;
  • Codec = mSBC (2):该编码方式的数据传输只能使用eSCO链路;

这里提及到了音频编解码的选择,我们简单描述一下蓝牙中涉及到的编解码方式;

  • 媒体音频:播放蓝牙音乐的数据,这种音频对指令要求高,数据发送有重传机制,从而以L2CAP的数据形式走ACL链路。编码方式有SBC、AAC、APTX、APTX_HD、LDAC这五种编码方式,最基础的编码方式是SBC,支持蓝牙多媒体播放的设备必须支持该编码方式,编码质量最好的是LDAC。编码方式的选取需要蓝牙连接设备间的互相协商确定;
  • 电话音频:蓝牙通话过程的语音数据,这种音频对时效性有高要求,一般通过特殊的SCO或eSCO链路传输数据。编码方式有:CVSD、mSBC。最基础的编码方式为CVSD,免提蓝牙设备都需支持该编码方式,支持宽带语音的设备可选mSBC编码数据;
…………………………
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 0, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..0. = C/R Flag: Response (0x0)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 6
    Credits: 1
    Frame Check Sequence: 0x49
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\nOK\r\n
    Command 0: OK
        Command: OK (OK)
        Type: Response (0x0d0a)
        Parameters: No

这个就是AT+BAC指令对应的Response;

3.3 AT+CIND=? & +CIND

AT+CIND指令有两种Syntax:AT+CIND=? 和 AT+CIND?,其中AT+CIND=?代表了获取对方特性支持情况,并不会给出当前具体的状态情况值;

…………………………
Bluetooth L2CAP Protocol
    Length: 15
    CID: Dynamically Allocated Channel (0x0041)
    [Connect in frame: 416]
    [PSM: RFCOMM (0x0003)]
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 1, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..1. = C/R Flag: Command (0x1)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 10
    Credits: 1
    Frame Check Sequence: 0x93
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CIND=?\r
    Command 0: +CIND
        Command Line Prefix: AT
        Command: +CIND (Phone Indicators)
        Type: Test Command (0x3d3f)
        Parameters: No
  • type:Test Command

对应的Response为:

…………………………
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 0, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..0. = C/R Flag: Response (0x0)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 132
    Credits: 1
    Frame Check Sequence: 0x49
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+CIND: ("call",(0,1)),("callsetup",(0-3)),("service",(0-1)),("signal",(0-5)),("roam",(0,1)),("battchg",(0-5)),("callheld",(0-2))\r\n
    Command 0: +CIND
        Command: +CIND (Phone Indicators)
        Type: Response (0x003a)
        Parameters
            Indicator 1: ("call",(0,1))
            Indicator 2: ("callsetup",(0-3))
            Indicator 3: ("service",(0-1))
            Indicator 4: ("signal",(0-5))
            Indicator 5: ("roam",(0,1))
            Indicator 6: ("battchg",(0-5))
            Indicator 7: ("callheld",(0-2))
  • Indicator 1:call,取值范围:0~1,表明了当前电话是否在通话中;
  • Indicator 2:callsetup,取值范围:0~3,表明了当前电话的通话状态;
  • Indicator 3:service,取值范围:0~1,表明了当前Phone是否有信号服务;
  • Indicator 4:signal,取值范围:0~5,代表了电话信号质量;
  • Indicator 5:roam,取值范围:0~1,代表当前Phone是否处于漫游状态;
  • Indicator 6:battchg,取值范围:0~5,AG侧(Phone)电量值情况;
  • Indicator 7:callheld,取值范围:0~2,代表了当前Phone的保持状态;

3.4 AT+CIND? & +CIND

与AT+CIND=?不同,该指令用于获取设备当前具体的状态情况;

…………………………
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 1, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..1. = C/R Flag: Command (0x1)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 9
    Credits: 2
    Frame Check Sequence: 0x93
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CIND?\r
    Command 0: +CIND
        Command Line Prefix: AT
        Command: +CIND (Phone Indicators)
        Type: Read Command (0x003f)
        Parameters: No
…………………………
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 0, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..0. = C/R Flag: Response (0x0)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 24
    Credits: 1
    Frame Check Sequence: 0x49
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+CIND: 0,0,1,5,0,4,0\r\n
    Command 0: +CIND
        Command: +CIND (Phone Indicators)
        Type: Response (0x003a)
        Parameters
            Indicator 1: 0
            Indicator 2: 0
            Indicator 3: 1
            Indicator 4: 5
            Indicator 5: 0
            Indicator 6: 4
            Indicator 7: 0

对AT+CIND=?指令的+CIND Response不同,AT+CIND?指令对应的+CIND响应的Indicator为具体的状态情况:

  • Indicator 1: 0,call = 0,表明当前没有电话在进行中;
  • Indicator 2: 0,callsetup = 0,表明当前没在呼叫中;
  • Indicator 3: 1,service = 1,表明当前Phone有信号服务;
  • Indicator 4: 5,signal = 5,表明当前的电话信号质量满格;
  • Indicator 5: 0,roam = 0,表明当前Phone没有处于漫游中;
  • Indicator 6: 4,battchg = 4,将100%电量分为5个层次,0-20%、20-40%、40-60%、60-80%、80-100%5个档次,当前Phone的电量状态为60%-80%之间;
  • Indicator 7: 0,callheld = 0,表明当前没有电话在保持中;

3.5 AT+CMER

AT+CMER代表了标准事件报告激活/停用AT命令,即移动设备事件报告。这个命令决定是否允许在键按下时是否主动发送结果代码;

…………………………
Bluetooth RFCOMM Protocol
    Address: E/A flag: 1, C/R flag: 1, Direction: 0, Channel: 3
        0001 10.. = DLCI: 0x06 (Direction: 0, Channel: 3)
            0001 1... = Channel: 3
            .... .0.. = Direction: 0x0
        .... ..1. = C/R Flag: Command (0x1)
        .... ...1 = EA Flag: Last field octet (0x1)
    Control: Frame type: Unnumbered Information with Header check (UIH) (0xef), P/F flag: 1
        ...1 .... = P/F flag: 0x1
        111. 1111 = Frame type: Unnumbered Information with Header check (UIH) (0xef)
    Payload length: 16
    Credits: 2
    Frame Check Sequence: 0x93
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CMER=3,0,0,1\r
    Command 0: +CMER
        Command Line Prefix: AT
        Command: +CMER (Event Reporting Activation/Deactivation)
        Type: Action Command (0x003d)
        Parameters
            Mode: 3
            Keypad: 0
            Display: 0
            Indicator: 1

我们看到在Parameters中涉及到了4个参数,但是在HFP协议中只有Mode和Indicator这两个参数是有效的,其他参数无效;

  • Mode = 3:一般情况下,Mode value都为3;
  • Indicator = 1:表明激活AG侧主动通知电话状态变化信息,0为禁用电话状态通知;
…………………………
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\nOK\r\n
    Command 0: OK
        Command: OK (OK)
        Type: Response (0x0d0a)
        Parameters: No

AT+CMER指令对应的Response同样为OK;

3.6 AT+CHLD=? & +CHLD

AT+CHLD=?,标准呼叫保持和多方处理AT命令;

的取值范围:

  • 0:挂掉所有保持中的电话或者拒接来电等待中的电话;
  • 1:挂掉所有通话中的电话并且接听其他保持或者来电等待中的电话;
  • 1:只挂掉第路标志的通话中的电话;
  • 2:设置所有通话中的电话为保持状态且接听其他保持或来电等待中的电话;
  • 2:设置所有通话中的电话为保持状态,除了第路标示出来的电话
  • 3:将一个保持中的电话加入会谈;
  • 4:连接两个呼叫并断开用于与两个呼叫的连接(显式呼叫转移)。
…………………………
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CHLD=?\r
    Command 0: +CHLD
        Command Line Prefix: AT
        Command: +CHLD (Call Hold and Multiparty Handling)
        Type: Test Command (0x3d3f)
        Parameters: No
…………………………
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+CHLD: (0,1,2,3)\r\n
    Command 0: +CHLD
        Command: +CHLD (Call Hold and Multiparty Handling)
        Type: Response (0x003a)
        Parameters
            Supported Modes: (0,1,2,3)

+CHLD Response的motes范围:

  • 0、1、2、3

暂不支持1、2和4这3中Mode;

…………………………
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\nOK\r\n
    Command 0: OK
        Command: OK (OK)
        Type: Response (0x0d0a)
        Parameters: No

最后又响应了OK Response;

3.7 AT+BIA

代表了蓝牙指示器激活,激活或停用单个指示器;

…………………………
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+BIA=1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0\r
    Command 0: +BIA
        Command Line Prefix: AT
        Command: +BIA (Bluetooth Indicators Activation)
        Type: Action Command (0x003d)
        Parameters
            Indicator 1: Activate (1)
            Indicator 2: Activate (1)
            Indicator 3: Activate (1)
            Indicator 4: Activate (1)
            Indicator 5: Activate (1)
            Indicator 6: Activate (1)
            Indicator 7: Activate (1)
            Indicator 8: Deactivate (0)
            Indicator 9: Deactivate (0)
            Indicator 10: Deactivate (0)
            Indicator 11: Deactivate (0)
            Indicator 12: Deactivate (0)
            Indicator 13: Deactivate (0)
            Indicator 14: Deactivate (0)
            Indicator 15: Deactivate (0)
            Indicator 16: Deactivate (0)
            Indicator 17: Deactivate (0)
            Indicator 18: Deactivate (0)
            Indicator 19: Deactivate (0)
            Indicator 20: Deactivate (0)

针对上述的0、1:

  • 0:代表停用
  • 1:代表激活

上述涉及到了20个indicators,即代表了指示器数量最大为20;

其中,有7项为激活状态,其余的indicator为停用状态。

实际允许的指标数量由AT+CIND命令定义。在AT+CIND中,我们涉及到了同样也是7个indicator:

call、callsetup、service、signal、roam、battchg、callheld;

AT+BIA指令的Response为OK;

3.8 AT+CCWA & +CCWA

标准的呼叫等待通知AT命令,在该规范中,仅适用参数启动/禁用呼叫等待通知主动结果代码;

…………………………
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CCWA=1\r
    Command 0: +CCWA
        Command Line Prefix: AT
        Command: +CCWA (Call Waiting Notification)
        Type: Action Command (0x003d)
        Parameters
            Show Result Code Presentation Status: Enabled (1)


  • Command:+CCWA
  • Show Result Code Presentation Status:Enabled (1),代表了是否启用呼叫等待通知主动上报;

对应的Response为OK;

3.9 AT+CMEE

标准AT命令用于启用,用于设置终端错误报告,使能后当发送AT执行错误时终端会返回错误编码,这样便于定位问题;

…………………………
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CMEE=1\r
    Command 0: +CMEE
        Command Line Prefix: AT
        Command: +CMEE (Mobile Equipment Error)
        Type: Action Command (0x003d)
        Parameters
            Mode: Enabled (1)
  • Command:+CMEE
  • Mode:Enabled (1),代表了开启错误码上报;

对应的Response为OK;

而错误码上报的方式为:+CME ERROR:,该指令对应的Error Code非常多,每一种Error对应一个错误,我们举几个简单的例子:

Error Error Description
CME ERROR: 0 Phone failure 电话故障
CME ERROR: 1 No connection to phone 电话不通
CME ERROR: 2 Phone adapter link reserved 保留电话适配器链接
CME ERROR: 3 Operation not allowed 操作不允许
CME ERROR: 4 Operation not supported 操作不支持
………… ………… …………

3.10 AT+COPS=?,?

运营商选择状态

……………………
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+COPS=3,0\r
    Command 0: +COPS
        Command Line Prefix: AT
        Command: +COPS (Reading Network Operator)
        Type: Action Command (0x003d)
        Parameters
            Mode: Set Only Format (3)
            Format: Long Format Alphanumeric (0)
  • Mode:模式

    • 0:自动注册,忽略、参数
    • 1:手动注册
    • 2:强制注销
    • 3:设置格式模式
    • 4:先手动再自动
  • Format:

    • 0:长字符格式
    • 1:短字符格式
    • 2:数字格式

AT+COPS=3,0代表的含义:设置查询格式,format为长字符格式;

对应的Response为OK;

3.11 AT+BTRH?

AT+BTRH对应了两种Syntax:

  • AT+BTRH=:设置指令
  • AT+BTRH?:读取当前状态

蓝牙响应和保持功能,HF为AG中的“响应和保持”功能发出的命令。本规范定义了set和read命令的使用,AT+BTRH ? HF应使用命令来查询 AG 的当前“响应和保持”状态,值定义:

  • 0:代表保留来电
  • 1:代表接受保持的来电
  • 2:代表拒绝保持的来电
…………………………
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+BTRH?\r
    Command 0: +BTRH
        Command Line Prefix: AT
        Command: +BTRH (Bluetooth Response and Hold Feature)
        Type: Read Command (0x003f)
        Parameters: No

发送读取当前call状态的指令;

…………………………
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+CME ERROR: 4\r\n
    Command 0: +CME ERROR
        Command: +CME ERROR (Extended Audio Gateway Error Result Code)
        Type: Response (0x003a)
        Parameters
            CME Error: Operation not Supported (4)

AT+BTRH?指令的Response为+CME ERROR,对应的Error Code为4,操作不支持;

3.12 AT+CLIP & +CLIP

标准呼叫线路识别通知激活AT命令,它启用/禁用呼叫线路识别通知主动结果代码 +CLIP;

…………………………
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CLIP=1\r
    Command 0: +CLIP
        Command Line Prefix: AT
        Command: +CLIP (Calling Line Identification Notification)
        Type: Action Command (0x003d)
        Parameters
            Mode: Enabled (1)

  • Mode:Enabled (1),启用呼叫线路识别通知激活,0代表禁用;

对应的Response为OK;

3.13 AT+NREC

表示噪音和回显的开关,0代表关闭,1代表开启;

…………………………
Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+NREC=0\r
    Command 0: +NREC
        Command Line Prefix: AT
        Command: +NREC (Noise Reduction and Echo Canceling)
        Type: Action Command (0x003d)
        Parameters
            Noise Reduction: Disable EC/NR in the AG (0)
  • Noise Reduction:Disable EC/NR in the AG (0),禁用;

对应的Response为OK;

3.14 AT+COPS? & +COPS

运营商查询,对应的Response为+COPS;

Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+COPS?\r
    Command 0: +COPS
        Command Line Prefix: AT
        Command: +COPS (Reading Network Operator)
        Type: Read Command (0x003f)
        Parameters: No
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+COPS: 0,0,"China Mobile"\r\n
    Command 0: +COPS
        Command: +COPS (Reading Network Operator)
        Type: Response (0x003a)
        Parameters
            Mode: Automatic (0)
            Format: Long Format Alphanumeric (0)
            Operator: "China Mobile"

对应的Response如上,其中包含了几个参数;

  • Mode:自动注册,对应的value = 0;
  • Format:长字符格式,对应了之前的 AT+COPS=3,0 指令;
  • Operator:China Mobile,中国移动;

+COPS 指令 Response完成之后,紧接着返回对应的Response为OK;

3.15 AT+CNUM & +CNUM

签署者号码,简单理解为本机号码,对应了 +CNUM Response;

Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CNUM\r
    Command 0: +CNUM
        Command Line Prefix: AT
        Command: +CNUM (Subscriber Number Information)
        Type: Action Command (0x000d)
        Parameters: No

Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+CNUM: ,"+86182xxxxxxxx",145,,4\r\n
    Command 0: +CNUM
        Command: +CNUM (Subscriber Number Information)
        Type: Response (0x003a)
        Parameters
            Alpha: 
            Number: "+86182xxxxxxxx"
            Type:  The phone number format is an international number, including the country code prefix. If the plus sign ("+") is not included as part of the number and shall be added by the AG as needed. (145)
            Speed: autobauding (0)
            Service: Voice (4)
  • Alpha:不支持这个可选字段,应该留空。

  • Number:+86182xxxxxxxx,本机号码,这个不方便显示;

  • Type:字段指定提供的电话号码的格式,145,电话号码格式为国际号码,包含国家代码前缀;该参数有3个范围定义;

    • 128-143:国内格式或国际格式(可以含前缀或者转义数字)
    • 144-159:国际号码(含国家代码)
    • 160-175:国际号码(不含前缀或者转义数字)
  • Speed:不支持这个可选字段,应该留空。

  • Service:Voice,指示此电话号码与哪个服务相关。应该是4(声音)或5(传真),这个关联的service为4,声音;

    • 0:异步调制解调器
    • 1:同步调制解调器
    • 2:PAD接入(异步)
    • 3:包接入(同步)
    • 4:语音
    • 5:传真

+CNUM 指令 Response完成之后,紧接着返回对应的Response为OK;

3.16 AT+CLCC & +CLCC

列出当前的呼叫;

Bluetooth HFP Profile
    [Role: HS - Headset (2)]
    AT Stream: AT+CLCC\r
    Command 0: +CLCC
        Command Line Prefix: AT
        Command: +CLCC (Current Calls)
        Type: Action Command (0x000d)
        Parameters: No

请求当前呼叫的信息;

HF请求当前的电话信息列表,构造格式:+CLCC: < idx >,< dir >,< status >,< mode >,< mpty >,< number >,< type >,AG侧回复当前的电话信息列表。如果当前没有电话,AG侧也需回复OK指令,不然将电话信息以列表形式发送给HF;

3.16.1 拨打状态

Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+CLCC: 1,0,2,0,0,"03511008611",129\r\n
    Command 0: +CLCC
        Command: +CLCC (Current Calls)
        Type: Response (0x003a)
        Parameters
            ID: 1
            Direction: Mobile Originated (0)
            State: Dialing (2)
            Mode: Voice (0)
            Mpty: Call is not one of multiparty (conference) call parties (0)
            Number: "03511008611"
            Type: The phone number format may be a national or international format, and may contain prefix and/or escape digits. No changes on the number presentation are required. (129)
  • < idx >:当前电话是第几路,从 1 开始计数;

  • < dir >:电话方向,0代表往外拨打的电话outgoing;1代表来电incoming;

  • < status >:电话状态

    • 0:Active
    • 1:Held
    • 2:Dialing(outgoing calls only)
    • 3:Alerting(outgoing calls only)
    • 4:Incoming(incoming calls only)
    • 5:Waiting(incoming calls only)
    • 6:Call held by Response and Hold
  • < mode >:电话模式

    • 0:voice
    • 1:data
    • 2:FAX
  • < mpty >:是否为多方通话的电话

    • 0:this call is NOT a member of a multi-party(conference)call
    • 1:this call is a member of a multi-party(conference)call
  • < number >:可选项,电话号码,代表了拨打的号码

  • < type >:可选项,电话类型,129代表了国内号码;

3.16.2 接听状态

 
Bluetooth HFP Profile
    [Role: AG - Audio Gate (1)]
    AT Stream: \r\n+CLCC: 1,0,0,0,0,"03511008611",129\r\n
    Command 0: +CLCC
        Command: +CLCC (Current Calls)
        Type: Response (0x003a)
        Parameters
            ID: 1
            Direction: Mobile Originated (0)
            State: Active (0)
            Mode: Voice (0)
            Mpty: Call is not one of multiparty (conference) call parties (0)
            Number: "03511008611"
            Type: The phone number format may be a national or international format, and may contain prefix and/or escape digits. No changes on the number presentation are required. (129)

和拨打状态唯一的不太点是:State,接听状态下 state = Active;

上一篇:uniapp安装axios


下一篇:2024年 前端JavaScript Web APIs 第四天 笔记-4.9-今日综合案例-学生信息表