Select one of the symbols to view example projects that use it.
 
Outline
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "esp_log.h"
#include "ble_ancs.h"
#define BLE_ANCS_TAG
EventID_to_String(uint8_t)
CategoryID_to_String(uint8_t)
esp_receive_apple_notification_source(uint8_t *, uint16_t)
esp_receive_apple_data_source(uint8_t *, uint16_t)
Errcode_to_String(uint16_t)
Files
loading...
SourceVuESP-IDF Framework and Examplesble_ancs samplemain/ble_ancs.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 *//* ... */ #include <stdlib.h> #include <string.h> #include <inttypes.h> #include "esp_log.h" #include "ble_ancs.h"5 includes #define BLE_ANCS_TAG "BLE_ANCS" /* | EventID(1 Byte) | EventFlags(1 Byte) | CategoryID(1 Byte) | CategoryCount(1 Byte) | NotificationUID(4 Bytes) | A GATT notification delivered through the Notification Source characteristic contains the following information: * EventID: This field informs the accessory whether the given iOS notification was added, modified, or removed. The enumerated values for this field are defined in EventID Values. * EventFlags: A bitmask whose set bits inform an NC of specificities with the iOS notification. For example, if an iOS notification is considered “important”, the NC may want to display a more aggressive user interface (UI) to make sure the user is properly alerted. The enumerated bits for this field are defined in EventFlags. * CategoryID: A numerical value providing a category in which the iOS notification can be classified. The NP will make a best effort to provide an accurate category for each iOS notification. The enumerated values for this field are defined in CategoryID Values. * CategoryCount: The current number of active iOS notifications in the given category. For example, if two unread emails are sitting in a user’s email inbox, and a new email is pushed to the user’s iOS device, the value of CategoryCount is 3. * NotificationUID: A 32-bit numerical value that is the unique identifier (UID) for the iOS notification. This value can be used as a handle in commands sent to the Control Point characteristic to interact with the iOS notification. *//* ... */ char *EventID_to_String(uint8_t EventID) { char *str = NULL; switch (EventID) { case EventIDNotificationAdded: str = "New message"; break;... case EventIDNotificationModified: str = "Modified message"; break;... case EventIDNotificationRemoved: str = "Removed message"; break;... default: str = "unknown EventID"; break;... }{...} return str; }{ ... } char *CategoryID_to_String(uint8_t CategoryID) { char *Cidstr = NULL; switch(CategoryID) { case CategoryIDOther: Cidstr = "Other"; break;... case CategoryIDIncomingCall: Cidstr = "IncomingCall"; break;... case CategoryIDMissedCall: Cidstr = "MissedCall"; break;... case CategoryIDVoicemail: Cidstr = "Voicemail"; break;... case CategoryIDSocial: Cidstr = "Social"; break;... case CategoryIDSchedule: Cidstr = "Schedule"; break;... case CategoryIDEmail: Cidstr = "Email"; break;... case CategoryIDNews: Cidstr = "News"; break;... case CategoryIDHealthAndFitness: Cidstr = "HealthAndFitness"; break;... case CategoryIDBusinessAndFinance: Cidstr = "BusinessAndFinance"; break;... case CategoryIDLocation: Cidstr = "Location"; break;... case CategoryIDEntertainment: Cidstr = "Entertainment"; break;... default: Cidstr = "Unknown CategoryID"; break;... }{...} return Cidstr; }{ ... } /* | EventID(1 Byte) | EventFlags(1 Byte) | CategoryID(1 Byte) | CategoryCount(1 Byte) | NotificationUID(4 Bytes) | *//* ... */ void esp_receive_apple_notification_source(uint8_t *message, uint16_t message_len) { if (!message || message_len < 5) { return; }{...} uint8_t EventID = message[0]; char *EventIDS = EventID_to_String(EventID); uint8_t EventFlags = message[1]; uint8_t CategoryID = message[2]; char *Cidstr = CategoryID_to_String(CategoryID); uint8_t CategoryCount = message[3]; uint32_t NotificationUID = (message[4]) | (message[5]<< 8) | (message[6]<< 16) | (message[7] << 24); ESP_LOGI(BLE_ANCS_TAG, "EventID:%s EventFlags:0x%x CategoryID:%s CategoryCount:%d NotificationUID:%" PRIu32, EventIDS, EventFlags, Cidstr, CategoryCount, NotificationUID); }{ ... } void esp_receive_apple_data_source(uint8_t *message, uint16_t message_len) { if (!message || message_len == 0) { return; }{...} uint8_t Command_id = message[0]; switch (Command_id) { case CommandIDGetNotificationAttributes: { uint32_t NotificationUID = (message[1]) | (message[2]<< 8) | (message[3]<< 16) | (message[4] << 24); uint32_t remian_attr_len = message_len - 5; uint8_t *attrs = &message[5]; ESP_LOGI(BLE_ANCS_TAG, "recevice Notification Attributes response Command_id %d NotificationUID %" PRIu32, Command_id, NotificationUID); while(remian_attr_len > 0) { uint8_t AttributeID = attrs[0]; uint16_t len = attrs[1] | (attrs[2] << 8); if(len > (remian_attr_len -3)) { ESP_LOGE(BLE_ANCS_TAG, "data error"); break; }{...} switch (AttributeID) { case NotificationAttributeIDAppIdentifier: ESP_LOG_BUFFER_CHAR("Identifier", &attrs[3], len); break;... case NotificationAttributeIDTitle: ESP_LOG_BUFFER_CHAR("Title", &attrs[3], len); break;... case NotificationAttributeIDSubtitle: ESP_LOG_BUFFER_CHAR("Subtitle", &attrs[3], len); break;... case NotificationAttributeIDMessage: ESP_LOG_BUFFER_CHAR("Message", &attrs[3], len); break;... case NotificationAttributeIDMessageSize: ESP_LOG_BUFFER_CHAR("MessageSize", &attrs[3], len); break;... case NotificationAttributeIDDate: //yyyyMMdd'T'HHmmSS ESP_LOG_BUFFER_CHAR("Date", &attrs[3], len); break;... case NotificationAttributeIDPositiveActionLabel: ESP_LOG_BUFFER_HEX("PActionLabel", &attrs[3], len); break;... case NotificationAttributeIDNegativeActionLabel: ESP_LOG_BUFFER_HEX("NActionLabel", &attrs[3], len); break;... default: ESP_LOG_BUFFER_HEX("unknownAttributeID", &attrs[3], len); break;... }{...} attrs += (1 + 2 + len); remian_attr_len -= (1 + 2 + len); }{...} break; }{...} ... case CommandIDGetAppAttributes: ESP_LOGI(BLE_ANCS_TAG, "recevice APP Attributes response"); break;... case CommandIDPerformNotificationAction: ESP_LOGI(BLE_ANCS_TAG, "recevice Perform Notification Action"); break;... default: ESP_LOGI(BLE_ANCS_TAG, "unknown Command ID"); break;... }{...} }{ ... } char *Errcode_to_String(uint16_t status) { char *Errstr = NULL; switch (status) { case Unknown_command: Errstr = "Unknown_command"; break;... case Invalid_command: Errstr = "Invalid_command"; break;... case Invalid_parameter: Errstr = "Invalid_parameter"; break;... case Action_failed: Errstr = "Action_failed"; break;... default: Errstr = "unknown_failed"; break;... }{...} return Errstr; }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.