BLE Bluetooth development ANCS service development

In the watch application, as the application becomes more and more complex, it is usually inseparable from the intelligent push of message reminders, so here is mainly for the explanation of ANCS, which is the specification of the APPLE IOS system. If android wants to achieve similar functions, generally Adopting a private protocol method, there is no unified standard.

Basic knowledge of ANCS

The purpose of ANCS (Apple Notification Center Service) is to provide Bluetooth peripherals with a simple and convenient way to obtain notification information from iOS devices. This enables Bluetooth bracelets and watches to receive incoming calls, text messages and notification messages from various applications from Apple mobile phones.
To realize ANCS, it must be bound. The connection process is roughly divided into the following steps:
1. Broadcast on the peripheral side, turn on Bluetooth on the mobile phone, search for the peripheral, connect to the peripheral, and then bind (this is very important, Otherwise, the notification cannot be received)
2. The peripheral needs to monitor the Notification Source in the ANCS Service on the mobile phone after the connection is established;
3. When there is a notification, the mobile phone will send a message to the peripheral indicating which application is the notification;
4. If If you want to further obtain the details of the notification, you can write the control information to Control Point to obtain the details;
5. The details will be sent through Data Source.
This will be combined with the code description later.

Proper nouns

l ANCS: Apple notification center service
l NP (Notification Provider): the producer of the notification, generally an ios device
l NC (Notification Consumer): the consumer of the notification, generally a Bluetooth device
l iOS notification: the notification that appears in the ios device
l GATT notification: notification sent by GATT characteristic

Concept definition

If there is no special instructions, the values ​​transmitted through ANCS are in little-endian mode;
if there is no special instructions, the strings transmitted through ANCS are all encoded in UTF-8.

service

ANCS有一个私有的UUID,这个不是SIG的,是APPLE定义的私有UUID,且有三个必须的Characteristic类型。

Service UUID: 7905F431-B5CE-4E99-A40F-4B1E122D00D0
Notification Source UUID: 9FBF120D-6301-42D9-8C58-25E699A21DBD (notifiable)
Basic notification source to notify some counting information;
Control Point UUID: 69D1D8F3-45E1-49A8-9821- 9BBDFDAAD9D9 (writeable with response)
controller, used to write control information to the IOS device, such as the details you want to read;
Data Source UUID: 22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB (notifiable)
data source, used to provide details The data is returned through this Characteristic after the Control Point control information is written.
Insert picture description here

Key interface

ancs_cbs

Key bottom-level callback: Take write result cb as an example, and eventually enter ance_client_cb
Insert picture description here

ancs_client_cb

ancs_client_cb is the callback interface for the main various information, including the completion of ANCS service discovery, receiving messages from IOS, write point result including enable/disable, write control information, etc.). Generally speaking, after the ancs service discovery is completed, ancs_set_data_source_notify will be called To open the data source
1. In the cb, when the ancs service is found to be completed,
ancs_set_data_source_notify->ANCS_WRITE_DATA_SOURCE_NOTIFY_ENABLE->ANCS_WRITE_NOTIFICATION_SOURCE_NOTIFY_ENABLE corresponds to the following two channels:
Insert picture description here
2. After the completion of the opening, when IOS has a message push, it
means that ANCS_SOURCE is triggered. There is such a thing, and then call app_parse_notification_source_data to fill in what information you want to get the message, here is the filtering mechanism F_BT_ANCS_APP_FILTER, and finally return the write result from the bottom, case ANCS_WRITE_CONTROL_POINT,
Insert picture description here
when the message comes, it will be parsed in ANCS_FROM_DATA_SOURCE, always Reflect in app_handle_notification_attribute_data:
Insert picture description here

Related structure

CategoryID

Insert picture description here

EventID

Insert picture description here

EventFlags

Insert picture description here

CommandID

Insert picture description here

NotificationAttributeID

Insert picture description here

AppAttributeID

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_24179601/article/details/113125129