Skip to content

Commit

Permalink
Fix characteristics and services definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
scandinave committed Feb 16, 2022
1 parent 157f10e commit d232440
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
38 changes: 19 additions & 19 deletions src/components/ble/AppleNotificationCenterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@
using namespace Pinetime::Controllers;

constexpr ble_uuid128_t AppleNotificationCenterService::ancsChar;
constexpr ble_uuid128_t AppleNotificationCenterService::dataSourceChar;
constexpr ble_uuid128_t AppleNotificationCenterService::controlPointChar;
constexpr ble_uuid128_t AppleNotificationCenterService::notificationSourceSvc;
constexpr ble_uuid128_t AppleNotificationCenterService::dataSourceSvc;
constexpr ble_uuid128_t AppleNotificationCenterService::controlPointSvc;

int AppleNotificationCenterAlertCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
auto ancService = static_cast<AppleNotificationCenterService*>(arg);
return ancService->OnAlert(conn_handle, attr_handle, ctxt);
}

int AppleNotificationCenterDataCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
auto ancService = static_cast<AppleNotificationCenterService*>(arg);
return ancService->OnData(conn_handle, attr_handle, ctxt);
}

void AppleNotificationCenterService::Init() {
int res;
res = ble_gatts_count_cfg(serviceDefinition);
Expand All @@ -30,14 +26,23 @@ void AppleNotificationCenterService::Init() {

AppleNotificationCenterService::AppleNotificationCenterService(System::SystemTask& systemTask, NotificationManager& notificationManager)
: characteristicDefinition {
{.uuid = &ancsChar.u, .access_cb = AppleNotificationCenterAlertCallback, .arg = this, .flags = BLE_GATT_CHR_F_NOTIFY},
{.uuid = &controlPointChar}, // TODO
{.uuid = &dataSourceChar, .access_cb = AppleNotificationCenterAlertCallback, .arg = this, .flags = BLE_GATT_CHR_F_NOTIFY},
{0}},
{.uuid = &ancsChar.u, .access_cb = AppleNotificationCenterAlertCallback, .arg = this, .flags = BLE_GATT_CHR_F_NOTIFY |
BLE_GATT_CHR_F_WRITE},
{0}},
serviceDefinition {
{/* Device Information Service */
{/* Notification source Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = &notificationSourceSvc.u,
.characteristics = characteristicDefinition
},
{/* Control Point Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = &ancsChar.u,
.uuid = &controlPointSvc.u,
.characteristics = characteristicDefinition
},
{/* Data Source Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = &dataSourceSvc.u,
.characteristics = characteristicDefinition
},
{0},
Expand Down Expand Up @@ -93,15 +98,10 @@ int AppleNotificationCenterService::OnAlert(uint16_t conn_handle, uint16_t attr_
return 0;
}

// Handle data from dataSourceChar
int AppleNotificationCenterService::OnData(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) {

}

// Send a Get Notification Attributes command to Control Point
void AppleNotificationCenterService::GetNotificationAttribute() {}
// Send a Get App Attributes command to Control Point
void AppleNotificationCenterService::GetAppAttributes() {}
// Send a Perform Notification Action command to Control Point
void AppleNotificationCenterService::PerformNitificationAction() {}
void AppleNotificationCenterService::PerformNotificationAction() {}

17 changes: 9 additions & 8 deletions src/components/ble/AppleNotificationCenterService.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* UUID Apple Notification Center Service : 7905F431-B5CE-4E99-A40F-4B1E122D00D0
* Value obtains by decoding this uuid to string, reversing the result and prefixing all part with 0x
*/
#define APPLE_NOTIFICATION_CENTER_SERVICE_UUID_BASE \
#define APPLE_NOTIFICATION_CENTER_CHAR_UUID \
{ 0xd0, 0x00, 0x2D, 0x12, 0x1E, 0x4B, 0x0F, 0x24, 0x99, 0x0E, 0xCE, 0xB5, 0x31, 0xF4, 0x05, 0x79 }


Expand All @@ -31,9 +31,7 @@ namespace Pinetime {
void Init();

int OnAlert(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt);

int OnData(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access ctxt* ctxt);


void GetNotificationAttribute();
void GetAppAttributes();
void PerformNotificationAction();
Expand Down Expand Up @@ -96,23 +94,26 @@ namespace Pinetime {
enum class AppAttribute : uint8_t {
DisplayName = 0x00
};

//7905F431-B5CE-4E99-A40F-4B1E122D00D0
static constexpr ble_uuid128_t ancsChar { {BLE_UUID_TYPE_128}, APPLE_NOTIFICATION_CENTER_CHAR_UUID};

// 9FBF120D-6301-42D9-8C58-25E699A21DBD
static constexpr ble_uuid128_t ancsChar { {BLE_UUID_TYPE_128}, {0xBD, 0x1D, 0xA2, 0x99,
static constexpr ble_uuid128_t notificationSourceSvc { {BLE_UUID_TYPE_128}, {0xBD, 0x1D, 0xA2, 0x99,
0xE6, 0x25, 0x58, 0X0C, 0xD9, 0x02,
0x01, 0x63, 0x0D,0x12, 0xBF, 0x9F}};
// 69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9
static constexpr ble_uuid128_t controlPointChar {{BLE_UUID_TYPE_128},
static constexpr ble_uuid128_t controlPointSvc {{BLE_UUID_TYPE_128},
{0xD9, 0xD9, 0xAA, 0xFD, 0xBD, 0x9B,
0x21, 0X18,0xA8, 0x09,0xE1, 0x45, 0xF3,
0xD8, 0xD1, 0x69 }};
// 22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB
static constexpr ble_uuid128_t dataSourceChar {{BLE_UUID_TYPE_128},
static constexpr ble_uuid128_t dataSourceSvc {{BLE_UUID_TYPE_128},
{0xFB, 0x7B, 0x7C, 0xCE, 0x6A, 0xB3,
0x44, 0X3E,0xB5, 0x0B,0xD6, 0x24, 0xE9,
0xC6, 0xEA, 0x22 }};
struct ble_gatt_chr_def characteristicDefinition[2];
struct ble_gatt_svc_def serviceDefinition[2];
struct ble_gatt_svc_def serviceDefinition[4];

Pinetime::System::SystemTask& systemTask;
NotificationManager& notificationManager;
Expand Down
2 changes: 2 additions & 0 deletions src/components/ble/NimbleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
currentTimeClient {dateTimeController},
anService {systemTask, notificationManager},
alertNotificationClient {systemTask, notificationManager},
ancService {systemTask, notificationManager},
currentTimeService {dateTimeController},
musicService {systemTask},
weatherService {systemTask, dateTimeController},
Expand Down Expand Up @@ -93,6 +94,7 @@ void NimbleController::Init() {
weatherService.Init();
navService.Init();
anService.Init();
ancService.Init();
dfuService.Init();
batteryInformationService.Init();
immediateAlertService.Init();
Expand Down
2 changes: 2 additions & 0 deletions src/components/ble/NimbleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "components/ble/weather/WeatherService.h"
#include "components/fs/FS.h"
#include "components/ble/FSService.h"
#include "AppleNotificationCenterService.h"

namespace Pinetime {
namespace Drivers {
Expand Down Expand Up @@ -102,6 +103,7 @@ namespace Pinetime {
CurrentTimeClient currentTimeClient;
AlertNotificationService anService;
AlertNotificationClient alertNotificationClient;
AppleNotificationCenterService ancService;
CurrentTimeService currentTimeService;
MusicService musicService;
WeatherService weatherService;
Expand Down

0 comments on commit d232440

Please sign in to comment.