Skip to content

Commit 70b0e17

Browse files
JordanYatesjhedberg
authored andcommitted
gnss: gnss_emul: decouple realtime and gnss time
Allow the emulator to be set to an arbitrary UTC time, instead of being locked to reporting the current system uptime as UTC. Signed-off-by: Jordan Yates <[email protected]>
1 parent 7c3beaf commit 70b0e17

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

drivers/gnss/gnss_emul.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct gnss_emul_data {
3535
struct k_sem lock;
3636
int64_t resume_timestamp_ms;
3737
int64_t fix_timestamp_ms;
38+
int64_t boot_realtime_ms;
3839
uint32_t fix_interval_ms;
3940
enum gnss_navigation_mode nav_mode;
4041
gnss_systems_t enabled_systems;
@@ -302,15 +303,16 @@ void gnss_emul_clear_data(const struct device *dev)
302303
static void gnss_emul_set_utc(const struct device *dev)
303304
{
304305
struct gnss_emul_data *data = dev->data;
306+
int64_t timestamp_realtime;
305307
time_t timestamp;
306308
struct tm datetime;
307309
uint16_t millisecond;
308310

309-
timestamp = (time_t)(data->fix_timestamp_ms / 1000);
311+
timestamp_realtime = data->boot_realtime_ms + data->fix_timestamp_ms;
312+
timestamp = (time_t)(timestamp_realtime / 1000);
310313
gmtime_r(&timestamp, &datetime);
311314

312-
millisecond = (uint16_t)(data->fix_timestamp_ms % 1000)
313-
+ (uint16_t)(datetime.tm_sec * 1000);
315+
millisecond = (uint16_t)(timestamp_realtime % 1000) + (uint16_t)(datetime.tm_sec * 1000);
314316

315317
data->data.utc.hour = datetime.tm_hour;
316318
data->data.utc.millisecond = millisecond;
@@ -323,13 +325,13 @@ static void gnss_emul_set_utc(const struct device *dev)
323325
#ifdef CONFIG_GNSS_EMUL_MANUAL_UPDATE
324326

325327
void gnss_emul_set_data(const struct device *dev, const struct navigation_data *nav,
326-
const struct gnss_info *info, int64_t timestamp_ms)
328+
const struct gnss_info *info, int64_t boot_realtime_ms)
327329
{
328330
struct gnss_emul_data *data = dev->data;
329331

330332
data->data.nav_data = *nav;
331333
data->data.info = *info;
332-
data->fix_timestamp_ms = timestamp_ms;
334+
data->boot_realtime_ms = boot_realtime_ms;
333335
gnss_emul_set_utc(dev);
334336
}
335337

include/zephyr/drivers/gnss/gnss_emul.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ void gnss_emul_clear_data(const struct device *dev);
2525
* @param dev GNSS emulator device
2626
* @param nav Updated navigation state
2727
* @param info Updated GNSS fix information
28-
* @param timestamp_ms Timestamp associated with the GNSS fix
28+
* @param boot_realtime_ms Unix timestamp associated with system boot
2929
*/
3030
void gnss_emul_set_data(const struct device *dev, const struct navigation_data *nav,
31-
const struct gnss_info *info, int64_t timestamp_ms);
31+
const struct gnss_info *info, int64_t boot_realtime_ms);
3232

3333
/**
3434
* @brief Retrieve the last configured fix rate, regardless of PM state

0 commit comments

Comments
 (0)