9
9
#include <stdint.h>
10
10
#include <string.h>
11
11
#include <ble.h>
12
+ #include <ble_gap.h>
12
13
#include <nrf_sdh_ble.h>
13
14
#include <zephyr/sys/atomic.h>
14
15
#include <zephyr/logging/log.h>
@@ -22,32 +23,6 @@ LOG_MODULE_REGISTER(ble_bms, CONFIG_CONN_STATE_LOG_LEVEL);
22
23
/** Connection handles in the same order as they are indexed in the atomics */
23
24
struct ble_conn_state_conn_handle_list connections ;
24
25
25
- int conn_id_get (uint8_t conn_idx )
26
- {
27
- return connections .conn_handles [conn_idx ];
28
- }
29
-
30
- int conn_idx_get (uint32_t conn_id )
31
- {
32
- for (int i = 0 ; i < connections .len ; i ++ ) {
33
- if (connections .conn_handles [i ] == conn_id ) {
34
- return i ;
35
- }
36
- }
37
-
38
- /* conn_id not found in list */
39
-
40
- for (int i = 0 ; i < BLE_CONN_STATE_MAX_CONNECTIONS ; i ++ ) {
41
- if (atomic_test_bit (& bcs .flags .connected_flags , conn_handle ) == false) {
42
- record_invalidate (i );
43
- connections .conn_handles [i ] = conn_id ;
44
- return i ;
45
- }
46
- }
47
-
48
- return -1 ;
49
- }
50
-
51
26
/**
52
27
* @brief Structure containing all the flag collections maintained by the Connection State module.
53
28
*/
@@ -110,7 +85,7 @@ static inline void bcs_internal_state_reset(void)
110
85
static struct ble_conn_state_conn_handle_list conn_handle_list_get (atomic_t flags )
111
86
{
112
87
struct ble_conn_state_conn_handle_list conn_handle_list = {
113
- .len = 0 ;
88
+ .len = 0
114
89
};
115
90
116
91
if (flags ) {
@@ -220,6 +195,32 @@ static void flag_toggle(atomic_t *flags, uint16_t conn_handle, bool value)
220
195
}
221
196
}
222
197
198
+ int conn_id_get (uint8_t conn_idx )
199
+ {
200
+ return connections .conn_handles [conn_idx ];
201
+ }
202
+
203
+ int conn_idx_get (uint32_t conn_id )
204
+ {
205
+ for (int i = 0 ; i < connections .len ; i ++ ) {
206
+ if (connections .conn_handles [i ] == conn_id ) {
207
+ return i ;
208
+ }
209
+ }
210
+
211
+ /* conn_id not found in list */
212
+
213
+ for (int i = 0 ; i < BLE_CONN_STATE_MAX_CONNECTIONS ; i ++ ) {
214
+ if (atomic_test_bit (& bcs .flags .connected_flags , i ) == false) {
215
+ record_invalidate (i );
216
+ connections .conn_handles [i ] = conn_id ;
217
+ return i ;
218
+ }
219
+ }
220
+
221
+ return -1 ;
222
+ }
223
+
223
224
/**
224
225
* @brief Function for handling BLE events.
225
226
*
0 commit comments