forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdm.h
181 lines (144 loc) · 3.93 KB
/
dm.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#ifndef DM_H_
#define DM_H_
#include <stdlib.h>
#include <zephyr/types.h>
#include <zephyr/kernel.h>
#include <zephyr/bluetooth/addr.h>
/**
* @file
* @defgroup dm Distance Measurement API
* @{
* @brief API for the Distance Measurement (DM).
*/
#ifdef __cplusplus
extern "C" {
#endif
/** @brief Role definition. */
enum dm_dev_role {
/** Undefined role. */
DM_ROLE_NONE,
/** Act as an initiator. */
DM_ROLE_INITIATOR,
/** Act as a reflector. */
DM_ROLE_REFLECTOR,
};
/** @brief Ranging mode definition. */
enum dm_ranging_mode {
/** Round trip timing. */
DM_RANGING_MODE_RTT,
/** Multi-carrier phase difference. */
DM_RANGING_MODE_MCPD,
};
/** @brief Measurement quality definition. */
enum dm_quality {
/** Good measurement quality. */
DM_QUALITY_OK,
/** Poor measurement quality. */
DM_QUALITY_POOR,
/** Measurements not usable. */
DM_QUALITY_DO_NOT_USE,
/** Incorrect measurement CRC. */
DM_QUALITY_CRC_FAIL,
/** Measurement quality not specified. */
DM_QUALITY_NONE,
};
/** @brief Distance Measurement result structure. */
struct dm_result {
/** Status of the procedure. \a True if measurement was done correctly,
* \a False otherwise.
*/
bool status;
/** Quality indicator */
enum dm_quality quality;
/** Bluetooth LE device address. The address is used to distinguish peers. */
bt_addr_le_t bt_addr;
/** Mode used for ranging. */
enum dm_ranging_mode ranging_mode;
/** Container of distance estimate results for a number of different methods, in meters.*/
union {
struct mcpd {
/** MCPD: Distance estimate based on IFFT of spectrum. */
float ifft;
/** MCPD: Distance estimate based on average phase slope estimation. */
float phase_slope;
/** RSSI: Distance estimate based on Friis path loss formula. */
float rssi_openspace;
/** Best effort distance estimate. */
float best;
#ifdef CONFIG_DM_HIGH_PRECISION_CALC
/* MCPD: Distance estimate based on advanced algorithms */
float high_precision;
#endif
} mcpd;
struct rtt {
/** RTT: Distance estimate based on RTT measurement. */
float rtt;
} rtt;
} dist_estimates;
};
/** @brief Event callback structure. */
struct dm_cb {
/** @brief Data ready.
*
* Callback that is executed when the result
* of the Distance Measurement is available for reading.
*
* @param[out] result Pointer to the variable that is used to store
* the Distance Measurement result.
*/
void (*data_ready)(struct dm_result *result);
};
/** @brief DM initialization parameters. */
struct dm_init_param {
/** Event callback structure. */
struct dm_cb *cb;
};
/** @brief DM request structure. */
struct dm_request {
/** Role of the device. */
enum dm_dev_role role;
/** Bluetooth LE device address. */
bt_addr_le_t bt_addr;
/** Seed used in pseudo random number generation.
* Needs to be the same for an initiator and a reflector that will range with each other.
*/
uint32_t rng_seed;
/** Ranging mode to use in the procedure. */
enum dm_ranging_mode ranging_mode;
/** Start delay. */
uint32_t start_delay_us;
/** Extra time to extend the ranging window. */
uint32_t extra_window_time_us;
};
/** @brief Initialize the DM.
*
* Initialize the DM by specifying a list of supported operations.
*
* @param[in] init_param Initialization parameters.
*
* @retval 0 if the operation was successful.
* Otherwise, a (negative) error code is returned.
*/
int dm_init(struct dm_init_param *init_param);
/** @brief Add measurement request.
*
* Adding a measurement request. This is related to timeslot allocation.
*
* @param[in] req Address of the structure with request parameters.
*
* @retval 0 if the operation was successful.
* Otherwise, a (negative) error code is returned.
*/
int dm_request_add(struct dm_request *req);
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* DM_H_ */