Skip to content

Commit 65ead6e

Browse files
committed
Fix typos and remove unnecessary commented code
1 parent f888483 commit 65ead6e

File tree

2 files changed

+10
-45
lines changed

2 files changed

+10
-45
lines changed

src/components/ble/AppleNotificationCenterClient.cpp

+8-43
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,17 @@ bool AppleNotificationCenterClient::OnDiscoveryEvent(uint16_t connectionHandle,
4646
if (service == nullptr && error->status == BLE_HS_EDONE) {
4747
if (isDiscovered) {
4848
NRF_LOG_INFO("ANCS Discovery found, starting characteristics discovery");
49-
// DebugNotification("ANCS Discovery found, starting characteristics discovery");
50-
5149
ble_gattc_disc_all_chrs(connectionHandle, ancsStartHandle, ancsEndHandle, OnANCSCharacteristicDiscoveredCallback, this);
5250
} else {
5351
NRF_LOG_INFO("ANCS not found");
54-
// DebugNotification("ANCS not found");
5552
onServiceDiscovered(connectionHandle);
5653
}
5754
return true;
5855
}
5956

6057
if (service != nullptr && ble_uuid_cmp(&ancsUuid.u, &service->uuid.u) == 0) {
6158
NRF_LOG_INFO("ANCS discovered : 0x%x - 0x%x", service->start_handle, service->end_handle);
62-
// DebugNotification("ANCS discovered");
59+
6360
ancsStartHandle = service->start_handle;
6461
ancsEndHandle = service->end_handle;
6562
isDiscovered = true;
@@ -72,19 +69,16 @@ int AppleNotificationCenterClient::OnCharacteristicsDiscoveryEvent(uint16_t conn
7269
const ble_gatt_chr* characteristic) {
7370
if (error->status != 0 && error->status != BLE_HS_EDONE) {
7471
NRF_LOG_INFO("ANCS Characteristic discovery ERROR");
75-
// DebugNotification("ANCS Characteristic discovery ERROR");
7672
onServiceDiscovered(connectionHandle);
7773
return 0;
7874
}
7975

8076
if (characteristic == nullptr && error->status == BLE_HS_EDONE) {
8177
NRF_LOG_INFO("ANCS Characteristic discovery complete");
82-
// DebugNotification("ANCS Characteristic discovery complete");
8378
if (isCharacteristicDiscovered) {
8479
ble_gattc_disc_all_dscs(connectionHandle, notificationSourceHandle, ancsEndHandle, OnANCSDescriptorDiscoveryEventCallback, this);
8580
}
8681
if (isDataCharacteristicDiscovered) {
87-
// DebugNotification("ANCS Characteristic discovery complete: Data Source");
8882
ble_gattc_disc_all_dscs(connectionHandle, dataSourceHandle, ancsEndHandle, OnANCSDescriptorDiscoveryEventCallback, this);
8983
}
9084
if (isCharacteristicDiscovered == isControlCharacteristicDiscovered && isCharacteristicDiscovered == isDataCharacteristicDiscovered) {
@@ -94,19 +88,16 @@ int AppleNotificationCenterClient::OnCharacteristicsDiscoveryEvent(uint16_t conn
9488
if (characteristic != nullptr) {
9589
if (ble_uuid_cmp(&notificationSourceChar.u, &characteristic->uuid.u) == 0) {
9690
NRF_LOG_INFO("ANCS Characteristic discovered: Notification Source");
97-
// DebugNotification("ANCS Characteristic discovered: Notification Source");
9891
notificationSourceHandle = characteristic->val_handle;
9992
isCharacteristicDiscovered = true;
10093
} else if (ble_uuid_cmp(&controlPointChar.u, &characteristic->uuid.u) == 0) {
10194
NRF_LOG_INFO("ANCS Characteristic discovered: Control Point");
102-
// DebugNotification("ANCS Characteristic discovered: Control Point");
10395
controlPointHandle = characteristic->val_handle;
10496
isControlCharacteristicDiscovered = true;
10597
} else if (ble_uuid_cmp(&dataSourceChar.u, &characteristic->uuid.u) == 0) {
10698
char msg[55];
10799
snprintf(msg, sizeof(msg), "ANCS Characteristic discovered: Data Source\n%d", characteristic->val_handle);
108100
NRF_LOG_INFO(msg);
109-
// DebugNotification(msg);
110101
dataSourceHandle = characteristic->val_handle;
111102
isDataCharacteristicDiscovered = true;
112103
}
@@ -123,7 +114,6 @@ int AppleNotificationCenterClient::OnDescriptorDiscoveryEventCallback(uint16_t c
123114
if (characteristicValueHandle == notificationSourceHandle && ble_uuid_cmp(&notificationSourceChar.u, &descriptor->uuid.u)) {
124115
if (notificationSourceDescriptorHandle == 0) {
125116
NRF_LOG_INFO("ANCS Descriptor discovered : %d", descriptor->handle);
126-
// DebugNotification("ANCS Descriptor discovered");
127117
notificationSourceDescriptorHandle = descriptor->handle;
128118
isDescriptorFound = true;
129119
uint8_t value[2] {1, 0};
@@ -133,14 +123,12 @@ int AppleNotificationCenterClient::OnDescriptorDiscoveryEventCallback(uint16_t c
133123
} else if (characteristicValueHandle == controlPointHandle && ble_uuid_cmp(&controlPointChar.u, &descriptor->uuid.u)) {
134124
if (controlPointDescriptorHandle == 0) {
135125
NRF_LOG_INFO("ANCS Descriptor discovered : %d", descriptor->handle);
136-
// DebugNotification("ANCS Descriptor discovered");
137126
controlPointDescriptorHandle = descriptor->handle;
138127
isControlDescriptorFound = true;
139128
}
140129
} else if (characteristicValueHandle == dataSourceHandle && ble_uuid_cmp(&dataSourceChar.u, &descriptor->uuid.u)) {
141130
if (dataSourceDescriptorHandle == 0) {
142131
NRF_LOG_INFO("ANCS Descriptor discovered : %d", descriptor->handle);
143-
// DebugNotification("ANCS Descriptor discovered: Data Source");
144132
dataSourceDescriptorHandle = descriptor->handle;
145133
isDataDescriptorFound = true;
146134
uint8_t value[2] {1, 0};
@@ -152,7 +140,6 @@ int AppleNotificationCenterClient::OnDescriptorDiscoveryEventCallback(uint16_t c
152140
char errorStr[55];
153141
snprintf(errorStr, sizeof(errorStr), "ANCS Descriptor discovery ERROR: %d", error->status);
154142
NRF_LOG_INFO(errorStr);
155-
// DebugNotification(errorStr);
156143
}
157144
if (isDescriptorFound == isDataDescriptorFound)
158145
onServiceDiscovered(connectionHandle);
@@ -165,10 +152,8 @@ int AppleNotificationCenterClient::OnNewAlertSubcribe(uint16_t connectionHandle,
165152
ble_gatt_attr* /*attribute*/) {
166153
if (error->status == 0) {
167154
NRF_LOG_INFO("ANCS New alert subscribe OK");
168-
// DebugNotification("ANCS New alert subscribe OK");
169155
} else {
170156
NRF_LOG_INFO("ANCS New alert subscribe ERROR");
171-
// DebugNotification("ANCS New alert subscribe ERROR");
172157
}
173158
if (isDescriptorFound == isControlDescriptorFound && isDescriptorFound == isDataDescriptorFound)
174159
onServiceDiscovered(connectionHandle);
@@ -181,12 +166,10 @@ int AppleNotificationCenterClient::OnControlPointWrite(uint16_t /*connectionHand
181166
ble_gatt_attr* /*attribute*/) {
182167
if (error->status == 0) {
183168
NRF_LOG_INFO("ANCS Control Point write OK");
184-
// DebugNotification("ANCS Control Point write OK");
185169
} else {
186170
char errorStr[55];
187171
snprintf(errorStr, sizeof(errorStr), "ANCS Control Point ERROR: %d", error->status);
188172
NRF_LOG_INFO(errorStr);
189-
// DebugNotification(errorStr);
190173
}
191174
return 0;
192175
}
@@ -212,7 +195,7 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
212195
// bool positiveAction = eventFlags & static_cast<uint8_t>(EventFlags::PositiveAction);
213196
// bool negativeAction = eventFlags & static_cast<uint8_t>(EventFlags::NegativeAction);
214197

215-
AncsNotitfication ancsNotif;
198+
AncsNotification ancsNotif;
216199
ancsNotif.eventId = eventId;
217200
ancsNotif.eventFlags = eventFlags;
218201
ancsNotif.category = category;
@@ -254,20 +237,6 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
254237
request[13] = ((messageSize >> 8) & 0xFF);
255238

256239
ble_gattc_write_flat(event->notify_rx.conn_handle, controlPointHandle, request, sizeof(request), OnControlPointWriteCallback, this);
257-
258-
// NotificationManager::Notification notif;
259-
// char uuidStr[55];
260-
// snprintf(uuidStr, sizeof(uuidStr), "iOS Notif.:%08lx\nEvID: %d\nCat: %d\nFlags: %d", notificationUuid, eventId, category, eventFlags);
261-
// notif.message = std::array<char, 101> {};
262-
// std::strncpy(notif.message.data(), uuidStr, notif.message.size() - 1);
263-
// notif.message[10] = '\0'; // Seperate Title and Message
264-
// notif.message[notif.message.size() - 1] = '\0'; // Ensure null-termination
265-
// notif.size = std::min(std::strlen(uuidStr), notif.message.size());
266-
// notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
267-
// notificationManager.Push(std::move(notif));
268-
269-
// systemTask.PushMessage(Pinetime::System::Messages::OnNewNotification);
270-
// DebugNotification("ANCS Notification received");
271240
} else if (event->notify_rx.attr_handle == dataSourceHandle || event->notify_rx.attr_handle == dataSourceDescriptorHandle) {
272241
uint16_t titleSize;
273242
uint16_t subTitleSize;
@@ -279,7 +248,7 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
279248
os_mbuf_copydata(event->notify_rx.om, 8 + titleSize + 1, 2, &subTitleSize);
280249
os_mbuf_copydata(event->notify_rx.om, 8 + titleSize + 1 + 2 + subTitleSize + 1, 2, &messageSize);
281250

282-
AncsNotitfication ancsNotif;
251+
AncsNotification ancsNotif;
283252
ancsNotif.uuid = 0;
284253

285254
if (notifications.contains(notificationUid)) {
@@ -294,8 +263,6 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
294263

295264
NRF_LOG_INFO("Decoded Title: %s", decodedTitle.c_str());
296265
NRF_LOG_INFO("Decoded SubTitle: %s", decodedSubTitle.c_str());
297-
// DebugNotification(decodedTitle.c_str());
298-
// DebugNotification("ANCS Data Source received");
299266

300267
bool incomingCall = ancsNotif.uuid != 0 && ancsNotif.category == static_cast<uint8_t>(Categories::IncomingCall);
301268

@@ -333,7 +300,6 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
333300

334301
NotificationManager::Notification notif;
335302
notif.ancsUid = notificationUid;
336-
// std::string notifStr = "iOS Notif.:" + decodedTitle + "\n" + decodedSubTitle;
337303
std::string notifStr;
338304

339305
if (incomingCall) {
@@ -359,11 +325,11 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
359325
std::strncpy(notif.message.data(), notifStr.c_str(), notif.message.size() - 1);
360326

361327
if (incomingCall)
362-
notif.message[13] = '\0'; // Seperate Title and Message
328+
notif.message[13] = '\0'; // Separate Title and Message
363329
else if (!decodedSubTitle.empty())
364-
notif.message[titleSize + subTitleSize] = '\0'; // Seperate Title and Message
330+
notif.message[titleSize + subTitleSize] = '\0'; // Separate Title and Message
365331
else
366-
notif.message[titleSize - 1] = '\0'; // Seperate Title and Message
332+
notif.message[titleSize - 1] = '\0'; // Separate Title and Message
367333

368334
notif.message[notif.message.size() - 1] = '\0'; // Ensure null-termination
369335
notif.size = std::min(std::strlen(notifStr.c_str()), notif.message.size());
@@ -379,7 +345,7 @@ void AppleNotificationCenterClient::OnNotification(ble_gap_event* event) {
379345
}
380346

381347
void AppleNotificationCenterClient::AcceptIncomingCall(uint32_t uuid) {
382-
AncsNotitfication ancsNotif;
348+
AncsNotification ancsNotif;
383349
if (notifications.contains(uuid)) {
384350
ancsNotif = notifications[uuid];
385351
if (ancsNotif.category != static_cast<uint8_t>(Categories::IncomingCall)) {
@@ -401,7 +367,7 @@ void AppleNotificationCenterClient::AcceptIncomingCall(uint32_t uuid) {
401367
}
402368

403369
void AppleNotificationCenterClient::RejectIncomingCall(uint32_t uuid) {
404-
AncsNotitfication ancsNotif;
370+
AncsNotification ancsNotif;
405371
if (notifications.contains(uuid)) {
406372
ancsNotif = notifications[uuid];
407373
if (ancsNotif.category != static_cast<uint8_t>(Categories::IncomingCall)) {
@@ -451,7 +417,6 @@ void AppleNotificationCenterClient::Reset() {
451417

452418
void AppleNotificationCenterClient::Discover(uint16_t connectionHandle, std::function<void(uint16_t)> onServiceDiscovered) {
453419
NRF_LOG_INFO("[ANCS] Starting discovery");
454-
// DebugNotification("[ANCS] Starting discovery");
455420
this->onServiceDiscovered = onServiceDiscovered;
456421
ble_gattc_disc_svc_by_uuid(connectionHandle, &ancsUuid.u, OnDiscoveryEventCallback, this);
457422
}

src/components/ble/AppleNotificationCenterClient.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ namespace Pinetime {
9292
NegativeAction = (1 << 4)
9393
};
9494

95-
struct AncsNotitfication {
95+
struct AncsNotification {
9696
uint8_t eventId {0};
9797
uint8_t eventFlags {0};
9898
uint8_t category {0};
9999
uint32_t uuid {0};
100100
};
101101

102-
std::unordered_map<uint32_t, AncsNotitfication> notifications;
102+
std::unordered_map<uint32_t, AncsNotification> notifications;
103103

104104
std::string DecodeUtf8String(os_mbuf* om, uint16_t size, uint16_t offset);
105105

0 commit comments

Comments
 (0)