nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
ble_environmental_data_provider.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#pragma once
8
9#include "ble_bridged_device.h"
10#include "ble_connectivity_manager.h"
11#include "bridged_device_data_provider.h"
12
13class BleEnvironmentalDataProvider : public Nrf::BLEBridgedDeviceProvider {
14public:
15 explicit BleEnvironmentalDataProvider(UpdateAttributeCallback updateCallback, InvokeCommandCallback commandCallback) : Nrf::BLEBridgedDeviceProvider(updateCallback, commandCallback) {}
16 ~BleEnvironmentalDataProvider() { Unsubscribe(); }
17
18 void Init() override;
19 void NotifyUpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data,
20 size_t dataSize) override;
21 CHIP_ERROR UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override;
22 const bt_uuid *GetServiceUuid() override;
23 int ParseDiscoveredData(bt_gatt_dm *discoveredData) override;
24
25private:
26 static constexpr uint32_t kMeasurementsIntervalMs{ CONFIG_BRIDGE_BLE_DEVICE_POLLING_INTERVAL };
27
28 void StartHumidityTimer();
29 void StopHumidityTimer() { k_timer_stop(&mHumidityTimer); }
30 void Subscribe();
31 void Unsubscribe();
32 bool CheckSubscriptionParameters(bt_gatt_subscribe_params *params);
33
34 CHIP_ERROR ParseTemperatureCharacteristic(bt_gatt_dm *discoveredData);
35 CHIP_ERROR ParseHumidityCharacteristic(bt_gatt_dm *discoveredData);
36
37 static uint8_t GattTemperatureNotifyCallback(bt_conn *conn, bt_gatt_subscribe_params *params, const void *data,
38 uint16_t length);
39 static uint8_t GattHumidityNotifyCallback(bt_conn *conn, bt_gatt_subscribe_params *params, const void *data,
40 uint16_t length);
41 static void NotifyTemperatureAttributeChange(intptr_t context);
42 static void NotifyHumidityAttributeChange(intptr_t context);
43
44 static void ReadGATTHumidity(intptr_t context);
45 static void HumidityTimerTimeoutCallback(k_timer *timer);
46 static uint8_t HumidityGATTReadCallback(bt_conn *conn, uint8_t att_err, bt_gatt_read_params *params,
47 const void *data, uint16_t read_len);
48
49 uint16_t mTemperatureValue{};
50 uint16_t mHumidityValue{};
51
52 uint16_t mTemperatureCharacteristicHandle{};
53 uint16_t mHumidityCharacteristicHandle{};
54
55 bt_gatt_subscribe_params mGattTemperatureSubscribeParams{};
56 bt_gatt_subscribe_params mGattHumiditySubscribeParams{};
57
58 uint16_t mCccTemperatureHandle{};
59 uint16_t mCccHumidityHandle{};
60
61 k_timer mHumidityTimer;
62
63 static bt_gatt_read_params sHumidityReadParams;
64};
int ParseDiscoveredData(bt_gatt_dm *discoveredData) override
void NotifyUpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, void *data, size_t dataSize) override
~BleEnvironmentalDataProvider()
Definition: ble_environmental_data_provider.h:16
BleEnvironmentalDataProvider(UpdateAttributeCallback updateCallback, InvokeCommandCallback commandCallback)
Definition: ble_environmental_data_provider.h:15
CHIP_ERROR UpdateState(chip::ClusterId clusterId, chip::AttributeId attributeId, uint8_t *buffer) override
const bt_uuid * GetServiceUuid() override
Definition: ble_environmental_data_provider.h:13