Skip to content

Commit 82a849d

Browse files
alstrzebonskirlubos
authored andcommitted
dult: Add motion detector module
Jira: NCSDK-25429 Signed-off-by: Aleksander Strzebonski <aleksander.strzebonski@nordicsemi.no>
1 parent 693748a commit 82a849d

9 files changed

+699
-5
lines changed

include/dult.h

+71-5
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,21 @@ int dult_id_read_state_cb_register(const struct dult_user *user,
182182
*/
183183
int dult_id_read_state_enter(const struct dult_user *user);
184184

185-
/** Minimum duration in milliseconds for the DULT sound action. */
186-
#define DULT_SOUND_DURATION_MIN_MS (5000U)
185+
/** Minimum duration in milliseconds for the DULT sound action originating from the Bluetooth
186+
* accessory non-owner service (see @ref DULT_SOUND_SRC_BT_GATT).
187+
*/
188+
#define DULT_SOUND_DURATION_BT_GATT_MIN_MS (5000U)
187189

188190
/** DULT sound source types. */
189191
enum dult_sound_src {
190192
/** Sound source type originating from the Bluetooth accessory non-owner service. */
191193
DULT_SOUND_SRC_BT_GATT,
192194

195+
/** Sound source type originating from the Motion detector.
196+
* Used only when the @kconfig{CONFIG_DULT_MOTION_DETECTOR} is enabled.
197+
*/
198+
DULT_SOUND_SRC_MOTION_DETECTOR,
199+
193200
/** External source type originating from the unknown location to the DULT module. */
194201
DULT_SOUND_SRC_EXTERNAL,
195202
};
@@ -204,7 +211,8 @@ struct dult_sound_cb {
204211
* structure), it then calls the @ref dult_sound_state_update API.
205212
*
206213
* @param src Sound source type. Only the DULT internal sources are
207-
* used in this callback: @ref DULT_SOUND_SRC_BT_GATT.
214+
* used in this callback: @ref DULT_SOUND_SRC_BT_GATT,
215+
* @ref DULT_SOUND_SRC_MOTION_DETECTOR.
208216
*/
209217
void (*sound_start)(enum dult_sound_src src);
210218

@@ -215,8 +223,9 @@ struct dult_sound_cb {
215223
* response to this request (as described by the @ref dult_sound_state_param
216224
* structure), it then calls the @ref dult_sound_state_update API.
217225
*
218-
* @param src Sound source type. Only the DULT internal sources are
219-
* used in this callback: @ref DULT_SOUND_SRC_BT_GATT.
226+
* @param src Sound source type. Only the DULT internal source originating
227+
* from the Bluetooth accessory non-owner service
228+
* (@ref DULT_SOUND_SRC_BT_GATT) is used in this callback.
220229
*/
221230
void (*sound_stop)(enum dult_sound_src src);
222231
};
@@ -279,6 +288,63 @@ struct dult_sound_state_param {
279288
int dult_sound_state_update(const struct dult_user *user,
280289
const struct dult_sound_state_param *param);
281290

291+
/** @brief Motion detector callback structure.
292+
*
293+
* Used only when the @kconfig{CONFIG_DULT_MOTION_DETECTOR} Kconfig option is enabled.
294+
*/
295+
struct dult_motion_detector_cb {
296+
/** @brief Request the user to start the motion detector.
297+
*
298+
* This callback is called to start the motion detector
299+
* activity. From now on, the motion detector events are polled
300+
* periodically with the @ref period_expired API.
301+
* The motion detector activity stops when the
302+
* @ref stop is called.
303+
*/
304+
void (*start)(void);
305+
306+
/** @brief Notify the user that the motion detector period has expired.
307+
*
308+
* This callback is called at the end of each
309+
* motion detector period. The @ref start function
310+
* indicates the beginning of the first motion detector period.
311+
* The next period is started as soon as the previous period expires.
312+
* The user should notify the DULT module if motion was detected
313+
* in the previous period. The return value of this callback
314+
* is used to pass this information.
315+
*
316+
* @return true to indicate detected motion in the last period,
317+
* otherwise false.
318+
*/
319+
bool (*period_expired)(void);
320+
321+
/** @brief Notify the user that the motion detector can be stopped.
322+
*
323+
* This callback is called to notify the user that the motion
324+
* detector is no longer used by the DULT module. It concludes
325+
* the motion detector activity that was started by the
326+
* @ref start callback.
327+
*/
328+
void (*stop)(void);
329+
};
330+
331+
/** @brief Register motion detector callbacks.
332+
*
333+
* This function registers callbacks to handle motion detector activities defined
334+
* in the Motion detector feature from the DULT specification. This API can only
335+
* be used when the @kconfig{CONFIG_DULT_MOTION_DETECTOR} Kconfig option is
336+
* enabled. If this configuration is active, this function must be called after
337+
* registering the DULT user with @ref dult_user_register and before enabling
338+
* DULT with @ref dult_enable function.
339+
*
340+
* @param user User structure used to authenticate the user.
341+
* @param cb Motion detector callback structure.
342+
*
343+
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
344+
*/
345+
int dult_motion_detector_cb_register(const struct dult_user *user,
346+
const struct dult_motion_detector_cb *cb);
347+
282348
/** Modes of the DULT near-owner state. */
283349
enum dult_near_owner_state_mode {
284350
/** Separated mode of the near-owner state. */

subsys/dult/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ zephyr_library_include_directories(include)
1111
zephyr_library_sources_ifdef(CONFIG_DULT_BATTERY battery.c)
1212
zephyr_library_sources_ifdef(CONFIG_DULT_BT_ANOS bt/anos.c)
1313
zephyr_library_sources_ifdef(CONFIG_DULT_ID id.c)
14+
zephyr_library_sources_ifdef(CONFIG_DULT_MOTION_DETECTOR motion_detector.c)
1415
zephyr_library_sources_ifdef(CONFIG_DULT_NEAR_OWNER_STATE near_owner_state.c)
1516
zephyr_library_sources_ifdef(CONFIG_DULT_SOUND sound.c)
1617
zephyr_library_sources_ifdef(CONFIG_DULT_USER user.c)

subsys/dult/Kconfig

+63
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,69 @@ config DULT_USER
148148
help
149149
Add DULT user source files.
150150

151+
config DULT_MOTION_DETECTOR
152+
bool "Enable DULT Motion detector feature"
153+
help
154+
The DULT Motion detector requests the device to ring if the accessory separated
155+
from owner is moving. For more details see
156+
https://www.ietf.org/archive/id/draft-detecting-unwanted-location-trackers-01.html#name-motion-detector.
157+
158+
if DULT_MOTION_DETECTOR
159+
160+
config DULT_MOTION_DETECTOR_TEST_MODE
161+
bool "Enable DULT Motion detector test mode"
162+
help
163+
The DULT Motion detector test mode allows to configure motion detector parameters
164+
for testing purposes. Those values are defined in the DULT specification and should
165+
not be changed in the production code.
166+
167+
config DULT_MOTION_DETECTOR_SEPARATED_UT_SAMPLING_RATE1
168+
int
169+
default 10000
170+
help
171+
Sampling rate in milliseconds when motion detector is enabled in separated state.
172+
173+
config DULT_MOTION_DETECTOR_SEPARATED_UT_SAMPLING_RATE2
174+
int
175+
default 500
176+
help
177+
Motion detector sampling rate in milliseconds when movement is detected in separated
178+
state.
179+
180+
config DULT_MOTION_DETECTOR_SEPARATED_UT_BACKOFF_PERIOD
181+
int "Period in minutes to disable motion detector if accessory is in separated state" if DULT_MOTION_DETECTOR_TEST_MODE
182+
default 2 if DULT_MOTION_DETECTOR_TEST_MODE
183+
default 360
184+
185+
config DULT_MOTION_DETECTOR_SEPARATED_UT_TIMEOUT_PERIOD_MIN
186+
int "Minimum time span in minutes in separated state before enabling motion detector" if DULT_MOTION_DETECTOR_TEST_MODE
187+
default 3 if DULT_MOTION_DETECTOR_TEST_MODE
188+
default 480
189+
190+
config DULT_MOTION_DETECTOR_SEPARATED_UT_TIMEOUT_PERIOD_MAX
191+
int "Maximum time span in minutes in separated state before enabling motion detector" if DULT_MOTION_DETECTOR_TEST_MODE
192+
default DULT_MOTION_DETECTOR_SEPARATED_UT_TIMEOUT_PERIOD_MIN if DULT_MOTION_DETECTOR_TEST_MODE
193+
default 1440
194+
195+
config DULT_MOTION_DETECTOR_SEPARATED_UT_ACTIVE_POLL_DURATION
196+
int
197+
default 20
198+
help
199+
Time span in seconds of motion detector active polling with
200+
CONFIG_DULT_MOTION_DETECTOR_SEPARATED_UT_SAMPLING_RATE2 rate. After the timeout, the
201+
motion detector is disabled for CONFIG_DULT_MOTION_DETECTOR_SEPARATED_UT_BACKOFF_PERIOD
202+
period.
203+
204+
config DULT_MOTION_DETECTOR_SEPARATED_UT_MAX_SOUND_COUNT
205+
int
206+
default 10
207+
help
208+
Maximum number of sound indications to be sent by motion detector before disabling it.
209+
After sending maximum number of sound indications, the motion detector is disabled for
210+
CONFIG_DULT_MOTION_DETECTOR_SEPARATED_UT_BACKOFF_PERIOD period."
211+
212+
endif # DULT_MOTION_DETECTOR
213+
151214
module = DULT
152215
module-str = DULT
153216
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef _DULT_MOTION_DETECTOR_H_
8+
#define _DULT_MOTION_DETECTOR_H_
9+
10+
#include <stdint.h>
11+
#include <stddef.h>
12+
13+
#include "dult.h"
14+
15+
/**
16+
* @defgroup dult_motion_detector Detecting Unwanted Location Trackers motion detector
17+
* @brief Private API for DULT specification implementation of the motion detector module
18+
*
19+
* Used only when the CONFIG_DULT_MOTION_DETECTOR Kconfig option is enabled.
20+
* @{
21+
*/
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
/** @brief DULT motion detector sound callback structure. */
28+
struct dult_motion_detector_sound_cb {
29+
/** @brief Start sound action.
30+
*
31+
* This callback is called to notify the upper layer that the sound action shall be
32+
* started due to the motion detector requirements.
33+
*/
34+
void (*sound_start)(void);
35+
};
36+
37+
/** @brief Register DULT motion detector sound callback structure.
38+
*
39+
* @param cb Sound callback structure.
40+
*/
41+
void dult_motion_detector_sound_cb_register(const struct dult_motion_detector_sound_cb *cb);
42+
43+
/** @brief Notify the DULT motion detector module about the sound state change.
44+
*
45+
* @param active True when the play sound action is in progress.
46+
* False: otherwise.
47+
* @param native True when the play sound action was triggered by this module.
48+
* False: otherwise.
49+
*/
50+
void dult_motion_detector_sound_state_change_notify(bool active, bool native);
51+
52+
/** @brief Enable DULT motion detector.
53+
*
54+
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
55+
*/
56+
int dult_motion_detector_enable(void);
57+
58+
/** @brief Reset DULT motion detector.
59+
*
60+
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
61+
*/
62+
int dult_motion_detector_reset(void);
63+
64+
#ifdef __cplusplus
65+
}
66+
#endif
67+
68+
/**
69+
* @}
70+
*/
71+
72+
#endif /* _DULT_MOTION_DETECTOR_H_ */

subsys/dult/include/dult_near_owner_state.h

+20
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ extern "C" {
2828
*/
2929
enum dult_near_owner_state_mode dult_near_owner_state_get(void);
3030

31+
/** @brief DULT near owner state callback structure. */
32+
struct dult_near_owner_state_cb {
33+
/** @brief DULT near owner state changed.
34+
*
35+
* This callback is called to notify that the near owner state has been changed.
36+
*
37+
* @param mode Mode of the current DULT near owner state.
38+
*/
39+
void (*state_changed)(enum dult_near_owner_state_mode mode);
40+
41+
/** Internally used field for list handling. */
42+
sys_snode_t node;
43+
};
44+
45+
/** @brief Register DULT near owner state callback structure.
46+
*
47+
* @param cb Near owner state callback structure.
48+
*/
49+
void dult_near_owner_state_cb_register(struct dult_near_owner_state_cb *cb);
50+
3151
/** @brief Reset DULT near owner state.
3252
*
3353
* Resets DULT near owner state to boot value which is equal to

0 commit comments

Comments
 (0)