diff options
| author | Tim Keller <geekboy1011@gmail.com> | 2021-10-17 01:09:26 (GMT) |
|---|---|---|
| committer | Tim Keller <geekboy1011@gmail.com> | 2021-12-10 01:18:57 (GMT) |
| commit | f57f797ff54d9ee8864d3fc62f0c8662df13aad8 (patch) | |
| tree | 6e6b1a2fabce753c3feffe538e872b160a155f13 /src/components/ble/FSService.cpp | |
| parent | 42a5cdb5b776c2cdeb08a8c6f26606282a809178 (diff) | |
Added Blank FSService that exposes only version info
Diffstat (limited to 'src/components/ble/FSService.cpp')
| -rw-r--r-- | src/components/ble/FSService.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/components/ble/FSService.cpp b/src/components/ble/FSService.cpp new file mode 100644 index 0000000..6551c20 --- /dev/null +++ b/src/components/ble/FSService.cpp @@ -0,0 +1,55 @@ +#include <nrf_log.h> +#include "FSService.h" + +using namespace Pinetime::Controllers; + +constexpr ble_uuid128_t FSService::fsServiceUuid; +constexpr ble_uuid128_t FSService::fsVersionUuid; +constexpr ble_uuid128_t FSService::fsTransferUuid; + +int FSServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { + auto* fsService = static_cast<FSService*>(arg); + return fsService->OnFSServiceRequested(conn_handle, attr_handle, ctxt); +} + +FSService::FSService(Pinetime::Controllers::FS& fs) + : fs {fs}, + characteristicDefinition {{.uuid = &fsVersionUuid.u, + .access_cb = FSServiceCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_READ, + .val_handle = &versionCharacteristicHandle}, + { + .uuid = &fsTransferUuid.u, + .access_cb = FSServiceCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, + .val_handle = nullptr, + }, + {0}}, + serviceDefinition { + {/* Device Information Service */ + .type = BLE_GATT_SVC_TYPE_PRIMARY, + .uuid = &fsServiceUuid.u, + .characteristics = characteristicDefinition}, + {0}, + } { +} + +void FSService::Init() { + int res = 0; + res = ble_gatts_count_cfg(serviceDefinition); + ASSERT(res == 0); + + res = ble_gatts_add_svcs(serviceDefinition); + ASSERT(res == 0); +} + +int FSService::OnFSServiceRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) { + if (attributeHandle == versionCharacteristicHandle) { + NRF_LOG_INFO("FS_S : handle = %d", versionCharacteristicHandle); + int res = os_mbuf_append(context->om, &fsVersion, sizeof(fsVersion)); + return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; + } + return 0; +} |
