Skip to content

Commit 711c8ce

Browse files
JordanYatesjhedberg
authored andcommitted
gnss: gnss_emul: manual data update mode
Add an option for the GNSS fix state reported by the emulated GNSS modem to be manually configured by test code, instead of being hardcoded to always achieve a fix of hardcoded parameters after 5 seconds. Signed-off-by: Jordan Yates <[email protected]>
1 parent f3f332c commit 711c8ce

File tree

3 files changed

+85
-20
lines changed

3 files changed

+85
-20
lines changed

drivers/gnss/Kconfig.emul

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ config GNSS_EMUL
99
select TIMEOUT_64BIT
1010
help
1111
Enable emulated GNSS driver.
12+
13+
config GNSS_EMUL_MANUAL_UPDATE
14+
bool "Internal state manually updated through gnss_emul_set_data"
15+
depends on GNSS_EMUL
16+
help
17+
The internal state of the GNSS emulator (location, time, etc)
18+
must be updated through gnss_emul_set_data, instead of automatically
19+
transitioning to hardcoded states at hardcoded times. Once the current
20+
time is set, the published time automatically increments.

drivers/gnss/gnss_emul.c

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,6 @@ static void gnss_emul_update_fix_timestamp(const struct device *dev, bool resumi
7373
}
7474
}
7575

76-
static bool gnss_emul_fix_is_acquired(const struct device *dev)
77-
{
78-
struct gnss_emul_data *data = dev->data;
79-
int64_t time_since_resume;
80-
81-
time_since_resume = data->fix_timestamp_ms - data->resume_timestamp_ms;
82-
return time_since_resume >= GNSS_EMUL_FIX_ACQUIRE_TIME_MS;
83-
}
84-
8576
#ifdef CONFIG_PM_DEVICE
8677
static void gnss_emul_clear_fix_timestamp(const struct device *dev)
8778
{
@@ -346,23 +337,13 @@ static DEVICE_API(gnss, api) = {
346337
.get_supported_systems = gnss_emul_api_get_supported_systems,
347338
};
348339

349-
static void gnss_emul_clear_data(const struct device *dev)
340+
void gnss_emul_clear_data(const struct device *dev)
350341
{
351342
struct gnss_emul_data *data = dev->data;
352343

353344
memset(&data->data, 0, sizeof(data->data));
354345
}
355346

356-
static void gnss_emul_set_fix(const struct device *dev)
357-
{
358-
struct gnss_emul_data *data = dev->data;
359-
360-
data->data.info.satellites_cnt = 8;
361-
data->data.info.hdop = 100;
362-
data->data.info.fix_status = GNSS_FIX_STATUS_GNSS_FIX;
363-
data->data.info.fix_quality = GNSS_FIX_QUALITY_GNSS_SPS;
364-
}
365-
366347
static void gnss_emul_set_utc(const struct device *dev)
367348
{
368349
struct gnss_emul_data *data = dev->data;
@@ -384,6 +365,40 @@ static void gnss_emul_set_utc(const struct device *dev)
384365
data->data.utc.century_year = datetime.tm_year % 100;
385366
}
386367

368+
#ifdef CONFIG_GNSS_EMUL_MANUAL_UPDATE
369+
370+
void gnss_emul_set_data(const struct device *dev, const struct navigation_data *nav,
371+
const struct gnss_info *info, int64_t timestamp_ms)
372+
{
373+
struct gnss_emul_data *data = dev->data;
374+
375+
data->data.nav_data = *nav;
376+
data->data.info = *info;
377+
data->fix_timestamp_ms = timestamp_ms;
378+
gnss_emul_set_utc(dev);
379+
}
380+
381+
#else
382+
383+
static bool gnss_emul_fix_is_acquired(const struct device *dev)
384+
{
385+
struct gnss_emul_data *data = dev->data;
386+
int64_t time_since_resume;
387+
388+
time_since_resume = data->fix_timestamp_ms - data->resume_timestamp_ms;
389+
return time_since_resume >= GNSS_EMUL_FIX_ACQUIRE_TIME_MS;
390+
}
391+
392+
static void gnss_emul_set_fix(const struct device *dev)
393+
{
394+
struct gnss_emul_data *data = dev->data;
395+
396+
data->data.info.satellites_cnt = 8;
397+
data->data.info.hdop = 100;
398+
data->data.info.fix_status = GNSS_FIX_STATUS_GNSS_FIX;
399+
data->data.info.fix_quality = GNSS_FIX_QUALITY_GNSS_SPS;
400+
}
401+
387402
static void gnss_emul_set_nav_data(const struct device *dev)
388403
{
389404
struct gnss_emul_data *data = dev->data;
@@ -395,6 +410,8 @@ static void gnss_emul_set_nav_data(const struct device *dev)
395410
data->data.nav_data.altitude = 20000;
396411
}
397412

413+
#endif /* CONFIG_GNSS_EMUL_MANUAL_UPDATE */
414+
398415
#ifdef CONFIG_GNSS_SATELLITES
399416
static void gnss_emul_clear_satellites(const struct device *dev)
400417
{
@@ -444,13 +461,19 @@ static void gnss_emul_work_handler(struct k_work *work)
444461
struct gnss_emul_data *data = CONTAINER_OF(dwork, struct gnss_emul_data, data_dwork);
445462
const struct device *dev = data->dev;
446463

464+
#ifdef CONFIG_GNSS_EMUL_MANUAL_UPDATE
465+
/* Tick the timestamp */
466+
gnss_emul_set_utc(dev);
467+
#else
468+
/* Automatically update internal state if not done manually */
447469
if (!gnss_emul_fix_is_acquired(dev)) {
448470
gnss_emul_clear_data(dev);
449471
} else {
450472
gnss_emul_set_fix(dev);
451473
gnss_emul_set_utc(dev);
452474
gnss_emul_set_nav_data(dev);
453475
}
476+
#endif /* CONFIG_GNSS_EMUL_MANUAL_UPDATE */
454477

455478
gnss_publish_data(dev, &data->data);
456479

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2025 Embeint Pty Ltd
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_DRIVERS_GNSS_GNSS_EMUL_H_
8+
#define ZEPHYR_DRIVERS_GNSS_GNSS_EMUL_H_
9+
10+
#include <stdint.h>
11+
12+
#include <zephyr/device.h>
13+
#include <zephyr/drivers/gnss.h>
14+
15+
/**
16+
* @brief Clear all internal GNSS data of the emulator
17+
*
18+
* @param dev GNSS emulator device
19+
*/
20+
void gnss_emul_clear_data(const struct device *dev);
21+
22+
/**
23+
* @brief Set the internal GNSS data of the emulator
24+
*
25+
* @param dev GNSS emulator device
26+
* @param nav Updated navigation state
27+
* @param info Updated GNSS fix information
28+
* @param timestamp_ms Timestamp associated with the GNSS fix
29+
*/
30+
void gnss_emul_set_data(const struct device *dev, const struct navigation_data *nav,
31+
const struct gnss_info *info, int64_t timestamp_ms);
32+
33+
#endif /* ZEPHYR_DRIVERS_GNSS_GNSS_EMUL_H_ */

0 commit comments

Comments
 (0)