2020-04-19 19:26:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2020-04-23 18:34:38 +00:00
|
|
|
|
|
|
|
#include "DeviceInformationService.h"
|
2020-04-19 19:26:09 +00:00
|
|
|
#include <host/ble_gap.h>
|
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
2020-04-22 18:19:36 +00:00
|
|
|
class DateTime;
|
2020-04-19 19:26:09 +00:00
|
|
|
class NimbleController {
|
|
|
|
public:
|
2020-04-22 18:19:36 +00:00
|
|
|
NimbleController(DateTime& dateTimeController);
|
2020-04-19 19:26:09 +00:00
|
|
|
void Init();
|
|
|
|
void StartAdvertising();
|
|
|
|
int OnGAPEvent(ble_gap_event *event);
|
2020-04-22 18:19:36 +00:00
|
|
|
int OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service);
|
|
|
|
int
|
|
|
|
OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error *error,
|
|
|
|
const ble_gatt_chr *characteristic);
|
|
|
|
int OnCurrentTimeReadResult(uint16_t conn_handle, const ble_gatt_error *error, const ble_gatt_attr *attribute);
|
2020-04-19 19:26:09 +00:00
|
|
|
private:
|
|
|
|
static constexpr char* deviceName = "Pinetime-JF";
|
2020-04-22 18:19:36 +00:00
|
|
|
static constexpr uint16_t BleGatServiceCts = 0x1805;
|
|
|
|
|
|
|
|
typedef struct __attribute__((packed)) {
|
|
|
|
uint16_t year;
|
|
|
|
uint8_t month;
|
|
|
|
uint8_t dayofmonth;
|
|
|
|
uint8_t hour;
|
|
|
|
uint8_t minute;
|
|
|
|
uint8_t second;
|
|
|
|
uint8_t millis;
|
|
|
|
uint8_t reason;
|
|
|
|
} CtsData;
|
|
|
|
|
|
|
|
DateTime& dateTimeController;
|
2020-04-23 18:34:38 +00:00
|
|
|
DeviceInformationService deviceInformationService;
|
2020-04-22 18:19:36 +00:00
|
|
|
|
|
|
|
ble_uuid16_t ctsUuid;
|
|
|
|
|
|
|
|
static constexpr uint16_t bleGattCharacteristicCurrentTime = 0x2a2b;
|
|
|
|
ble_uuid16_t ctsCurrentTimeUuid;
|
|
|
|
|
2020-04-19 19:26:09 +00:00
|
|
|
uint8_t addrType;
|
2020-04-22 18:19:36 +00:00
|
|
|
uint16_t connectionHandle;
|
2020-04-19 19:26:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|