Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: lib: date_time: Tests for scheduled updates #17477

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/nrf/libraries/others/date_time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ See the API documentation for more information on these functions.
If an application has time-dependent operations immediately after connecting to the LTE network, it should wait for a confirmation indicating that time has been updated.
If the :kconfig:option:`CONFIG_DATE_TIME_AUTO_UPDATE` option is not set, the first date-time update cycle (after boot) does not occur until the time set by the :kconfig:option:`CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS` option has elapsed.

.. note::

Exceptions to the regular date-time update interval set by the :kconfig:option:`CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS` Kconfig option occur when
the :c:func:`date_time_update_async` function is called and a new date-time update is triggered and scheduled.
Either retry or regular update interval is used depending on the outcome of the date-time update procedure.
Date-time update from modem through AT%XTIME notification will not disturb regular update interval.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Date-time update from modem through AT%XTIME notification will not disturb regular update interval.
Date-time update from modem through an ``AT%XTIME`` notification does not disturb the regular update interval.


Configuration
*************

Expand Down
4 changes: 4 additions & 0 deletions lib/date_time/date_time_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static void date_time_core_notify_event(enum date_time_evt_type time_source)

if (app_evt_handler != NULL) {
app_evt_handler(&evt);
} else {
LOG_DBG("No date-time event handler registered");
}
}

Expand Down Expand Up @@ -241,6 +243,8 @@ int date_time_core_now_local(int64_t *local_time_ms)

int date_time_core_update_async(date_time_evt_handler_t evt_handler)
{
LOG_DBG("Requesting date-time update asynchronously");

if (evt_handler) {
app_evt_handler = evt_handler;
} else if (app_evt_handler == NULL) {
Expand Down
18 changes: 13 additions & 5 deletions lib/date_time/date_time_modem.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ int date_time_modem_get(int64_t *date_time_ms, int *date_time_tz)
/* Want to match 6 or 7 args */
if (rc != 6 && rc != 7) {
LOG_WRN("Did not get time from cellular network (error: %d). "
"This is normal as some cellular networks don't provide it or "
"This may be normal as some cellular networks don't provide it or "
"time may not be available yet.", rc);
return -ENODATA;
}
Expand Down Expand Up @@ -122,9 +122,6 @@ static void date_time_at_xtime_handler(const char *notif)
int err;
int tz;

if (notif == NULL) {
return;
}
modem_valid_network_time = true;

/* Check if current time is valid */
Expand Down Expand Up @@ -160,7 +157,8 @@ static void date_time_at_xtime_handler(const char *notif)
time_buf_len = hex2bin(time_str_start, 14, time_buf, sizeof(time_buf));

if (time_buf_len < sizeof(time_buf)) {
LOG_ERR("%%XTIME notification decoding failed (ret=%d): %s", time_buf_len, notif);
LOG_ERR("Time value decoding failed from %%XTIME notification (ret=%d): %s",
time_buf_len, notif);
return;
}

Expand All @@ -171,6 +169,12 @@ static void date_time_at_xtime_handler(const char *notif)
date_time.tm_min = semioctet_to_dec(time_buf[4]);
date_time.tm_sec = semioctet_to_dec(time_buf[5]);

/* 3GPP TS 23.040 Section 9.2.3.11 says about the time zone as follows:
* The Time Zone indicates the difference, expressed in quarters of an hour,
* between the local time and GMT. In the first of the two semi octets,
* the first bit (bit 3 of the seventh octet of the TP Service Centre Time Stamp field)
* represents the algebraic sign of this difference (0: positive, 1: negative).
*/
tz = semioctet_to_dec(time_buf[6] & 0xF7);
if (time_buf[6] & 0x08) {
tz = -tz;
Expand Down Expand Up @@ -235,9 +239,13 @@ void date_time_modem_xtime_subscribe_work_fn(struct k_work *work_item)
}
}

#if defined(CONFIG_UNITY)
void date_time_modem_on_cfun(int mode, void *ctx)
#else
NRF_MODEM_LIB_ON_CFUN(date_time_cfun_hook, date_time_modem_on_cfun, NULL);

static void date_time_modem_on_cfun(int mode, void *ctx)
#endif
{
ARG_UNUSED(ctx);

Expand Down
5 changes: 5 additions & 0 deletions tests/lib/date_time/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ CONFIG_MOCK_NRF_MODEM_AT=y
CONFIG_LTE_LINK_CONTROL=y
CONFIG_POSIX_API=y

CONFIG_DATE_TIME_UPDATE_INTERVAL_SECONDS=3
CONFIG_DATE_TIME_TOO_OLD_SECONDS=1
CONFIG_DATE_TIME_RETRY_COUNT=2
CONFIG_DATE_TIME_RETRY_INTERVAL_SECONDS=1

# Enable logs if you want to explore them
CONFIG_LOG=n
CONFIG_DATE_TIME_LOG_LEVEL_DBG=n
Loading
Loading