Skip to content

Commit 0d0cdb6

Browse files
committed
BLE: Cordio implementation of pal::GenericAccessService.
1 parent 1b7a3ff commit 0d0cdb6

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#ifndef CORDIO_PAL_GENERIC_ACCESS_SERVICE_
2+
#define CORDIO_PAL_GENERIC_ACCESS_SERVICE_
3+
4+
#include "ble/pal/GenericAccessService.h"
5+
#include "CordioGattServer.h"
6+
7+
8+
namespace ble {
9+
namespace pal {
10+
namespace vendor {
11+
namespace cordio {
12+
13+
/**
14+
* Implementation of ble::pal::GenericAccessService for the Cordio stack.
15+
*/
16+
class GenericAccessService : public ::ble::pal::GenericAccessService {
17+
public:
18+
GenericAccessService() { }
19+
20+
virtual ~GenericAccessService() { }
21+
22+
virtual ble_error_t get_device_name_length(uint8_t& length) {
23+
const uint8_t* name = NULL;
24+
uint16_t actual_length = 0;
25+
26+
gatt_server().getDeviceName(name, actual_length);
27+
length = actual_length;
28+
return BLE_ERROR_NONE;
29+
}
30+
31+
virtual ble_error_t get_device_name(ArrayView<uint8_t>& array) {
32+
const uint8_t* name = NULL;
33+
uint16_t length = 0;
34+
35+
gatt_server().getDeviceName(name, length);
36+
37+
if (length > array.size()) {
38+
return BLE_ERROR_PARAM_OUT_OF_RANGE;
39+
}
40+
41+
memcpy(array.data(), name, length);
42+
return BLE_ERROR_NONE;
43+
}
44+
45+
virtual ble_error_t set_device_name(const uint8_t* device_name) {
46+
return gatt_server().setDeviceName(device_name);
47+
}
48+
49+
virtual ble_error_t get_appearance(
50+
GapAdvertisingData::Appearance& appearance
51+
) {
52+
appearance = gatt_server().getAppearance();
53+
return BLE_ERROR_NONE;
54+
}
55+
56+
virtual ble_error_t set_appearance(
57+
GapAdvertisingData::Appearance appearance
58+
) {
59+
gatt_server().setAppearance(appearance);
60+
return BLE_ERROR_NONE;
61+
}
62+
63+
virtual ble_error_t get_peripheral_prefered_connection_parameters(
64+
::Gap::ConnectionParams_t& parameters
65+
) {
66+
parameters = gatt_server().getPreferredConnectionParams();
67+
return BLE_ERROR_NONE;
68+
}
69+
70+
virtual ble_error_t set_peripheral_prefered_connection_parameters(
71+
const ::Gap::ConnectionParams_t& parameters
72+
) {
73+
gatt_server().setPreferredConnectionParams(parameters);
74+
return BLE_ERROR_NONE;
75+
}
76+
77+
private:
78+
ble::vendor::cordio::GattServer& gatt_server() {
79+
return ble::vendor::cordio::GattServer::getInstance();
80+
}
81+
};
82+
83+
} // cordio
84+
} // vendor
85+
} // pal
86+
} // ble
87+
88+
#endif /* CORDIO_PAL_GENERIC_ACCESS_SERVICE_ */

0 commit comments

Comments
 (0)