1
6
7
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
52
53
54
55
56
57
60
63
66
69
72
75
78
81
84
87
90
93
96
97
98
99
100
103
104
105
106
109
110
111
112
113
114
115
116
117
118
119
120
121
122
125
126
127
128
129
130
131
132
133
134
135
136
140
141
142
145
148
151
154
157
161
164
167
170
171
172
173
174
175
176
177
178
181
184
187
188
189
190
/* ... */
#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"
/* ... */
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;
}{ ... }
/* ... */
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:
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;
}{ ... }