Development Examples

[中文版]

Profile Initialization

Module Profile initialization, response event examples are as follows:

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: Profile initialization

bt -> host: +DEVSTAT=0
bt -> host: +PWRSTAT=1
bt -> host: +VER=BT936,V4.6.5,20220622
bt -> host: +PROFILE=339
bt -> host: +SPPSTAT=1
bt -> host: +GATTSTAT=1
bt -> host: +A2DPSTAT=1
bt -> host: -A2DPSTAT=1
bt -> host: +AVRCPSTAT=1
bt -> host: +HFPSTAT=1
bt -> host: -HFPSTAT=1
bt -> host: +DEVSTAT=1
bt -> host: +DEVSTAT=7
bt -> host: +AUDROUTE=0

@enduml

Parameter Modification

Modify Bluetooth Name

Modify Name. Examples of AT command operations and response events are as follows:

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: Change Bluetooth name
host -> bt: AT+NAME
bt -> host: AT+NAME=FSC-BT1036-1E49
host -> bt: AT+NAME=CARKIT,0
bt -> host: OK
host -> bt: AT+NAME
bt -> host: +NAME=CARKIT

@enduml

Before the MCU modifies any parameters, it is recommended to first query, then modify, and finally verify. For the MCU to modify the device name to CARKIT, the reference code example is as follows:

void change_name(void)
{

    uart_send("AT+NAME\r\n");
    if(uart_read("+NAME",name_buf))
    {
        if(memcmp(name_buf,"CARKIT",6))
        {
            uart_send("AT+NAME=CARKIT,0\r\n");  //defalut disable MAC address suffix
            uart_send("AT+NAME\r\n"); // read bt name
            if(uart_read("+NAME",name_buf))
            {
                if(memcmp(name_buf,"CARKIT",6))
                {
                    //change name fail
                }
                else
                {
                    //change name success
                }
            }
        }
    }
}

Audio Source Mode

Search for Bluetooth headsets

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: Search for Bluetooth headsets

host -> bt: AT+SCAN=1
bt -> host: +DEVSTAT=5
bt -> host: +DEVSTAT=13
bt -> host: OK
bt -> host: +SCAN=1,-71,0,86677A027ADA,ZN108_7ADA,040680
bt -> host: +SCAN=2,-59,0,648FDB44048B,Xiaomi Buds 5,244404
bt -> host: +SCAN=3,-57,0,DC0D30402073,iMin TF2-34 2073,000680
bt -> host: +SCAN=4,-74,0,DC0D300005D1,FSC-BW246,000680
bt -> host: +SCAN=5,-69,0,AC198EAC5DFE,FR,2A410C
bt -> host: +SCAN=6,-66,0,E0D8C4660C75,JMGO-N1 Pro-0127,2C043C
bt -> host: +SCAN=7,-67,0,80C3BA3834B2,CX Plus True Wireless,240404
bt -> host: +SCAN=8,-55,0,A0B339DB5208,QUZHENGWEI,2A410C
bt -> host: +DEVSTAT=5
bt -> host: +SCAN=E
bt -> host: +DEVSTAT=7
@enduml

Connect the main Bluetooth headset

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: Connect the main Bluetooth headset

host -> bt: AT+FOCUS=648FDB44048B
bt -> host: +A2DPSTAT=2
bt -> host: +PEERSTAT=648FDB44048B,2,1
bt -> host: +PAIRREQ=243705,648FDB44048B,Xiaomi Buds 5
bt -> host: +PAIRED=0,648FDB44048B,Xiaomi Buds 5
bt -> host: +A2DPSTAT=3(A2DP connected)
bt -> host: +DEVSTAT=5
bt -> host: +A2DPDEV=648FDB44048B,Xiaomi Buds 5
bt -> host: +AVRCPSTAT=3(AVRCP connected)
bt -> host: +PLAYSTAT=2
bt -> host: +PEERSTAT=648FDB44048B,3,1
bt -> host: +HFPSTAT=2
bt -> host: +HFPSTAT=3(HFP connected)
bt -> host: +HFPDEV=648FDB44048B,Xiaomi Buds 5
bt -> host: +PEERSTAT=648FDB44048B,3,3
@enduml

Connect the secondary Bluetooth headset

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: Connect the secondary Bluetooth headset

host -> bt: AT+FOCUS=,80C3BA3834B2
bt -> host: -A2DPSTAT=2
bt -> host: -PEERSTAT=80C3BA3834B2,2,1
bt -> host: +PAIRREQ=616247,80C3BA3834B2,CX Plus True Wireless
bt -> host: +PAIRED=0,80C3BA3834B2,CX Plus True Wireless
bt -> host: -A2DPSTAT=3
bt -> host: -A2DPDEV=80C3BA3834B2,CX Plus True Wireless
bt -> host: -PEERSTAT=80C3BA3834B2,3,1
bt -> host: -HFPSTAT=2
bt -> host: -HFPSTAT=3
bt -> host: -HFPDEV=80C3BA3834B2,CX Plus True Wireless
bt -> host: -PEERSTAT=80C3BA3834B2,3,3
@enduml

Audio Routing Management

Transmit audio to the main and secondary Bluetooth headsets via the A2DP

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: via the A2DP

host -> bt: AT+AUDROUTE=1
bt -> host: +AUDROUTE=1
bt -> host: OK
bt -> host: +A2DPSTAT=5
bt -> host: +PLAYSTAT=1
bt -> host: -A2DPSTAT=5
bt -> host: +AUDMODE=1
bt -> host: +PEERSTAT=648FDB44048B,5,3
bt -> host: -PEERSTAT=80C3BA3834B2,5,3

@enduml

Transmit audio to the main Bluetooth headset via the HFP

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: via the HFP

host -> bt: AT+AUDROUTE=2
bt -> host: +AUDROUTE=2
bt -> host: OK
bt -> host: -A2DPSTAT=4
bt -> host: +PLAYSTAT=2
bt -> host: +A2DPSTAT=4
bt -> host: +AUDMODE=0
bt -> host: +HFPSTAT=4
bt -> host: +AUDMODE=2
bt -> host: +HFPAUDIO=1
bt -> host: +PEERSTAT=648FDB44048B,4,4
bt -> host: -PEERSTAT=80C3BA3834B2,4,3
bt -> host: +HFPSTAT=6
bt -> host: +PEERSTAT=648FDB44048B,4,6

@enduml

Turn off audio routing

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: Turn off audio routing

host -> bt: AT+AUDROUTE=0
bt -> host: +AUDROUTE=0
bt -> host: OK
bt -> host: +HFPAUDIO=0
bt -> host: +HFPSTAT=3
bt -> host: +AUDMODE=0
bt -> host: +PEERSTAT=648FDB44048B,4,3


@enduml

Disconnect

Two headsets have been connected,disconnect the main Bluetooth headset.

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: Profile初始化

host -> bt: AT+FOCUS=000000000000,
bt -> host: +HFPSTAT=1
bt -> host: +A2DPSTAT=1
bt -> host: +DEVSTAT=7
bt -> host: +HFPSTAT=3
bt -> host: +AVRCPSTAT=1
bt -> host: +ACL=22,648FDB44048B
bt -> host: +PEERSTAT=648FDB44048B,1,1
host -> bt: AT+-A2DPSTAT
bt -> host: -A2DPSTAT=5
bt -> host: -A2DPDEV=80C3BA3834B2,CX Plus True Wireless
bt -> host: +A2DPSTAT=1
bt -> host: OK

@enduml

Two headsets have been connected,disconnect the secondary Bluetooth headset.

@startuml
hide footbox
skinparam sequenceMessageAlign center

box  #LightBlue
participant Host as host
participant Blueware as bt
end box

rnote over host, bt: Profile初始化

host -> bt: AT+FOCUS=,000000000000
bt -> host: -HFPSTAT=1
bt -> host: -A2DPSTAT=1
bt -> host: +DEVSTAT=7
bt -> host: +ACL=22,80C3BA3834B2
bt -> host: -PEERSTAT=80C3BA3834B2,1,1

host -> bt: AT+A2DPSTAT
bt -> host: +A2DPSTAT=5
bt -> host: +A2DPDEV=648FDB44048B,Xiaomi Buds 5
bt -> host: -A2DPSTAT=1
bt -> host: OK

@enduml