-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
lib: date_time: use millisecond precision in ntp api #11847
Conversation
|
Thank you for your contribution! Note: This comment is automatically posted and updated by the Contribs GitHub Action. |
Thanks for your contribution, @syscrypt. The implementation seems to have been like this already in the first version. I don't know the reason, but I don't see why we should ignore the fraction. Your change looks good to me, however you need to sign the CLA and the commit description needs some fine tuning to pass the compliance checks. The commit message needs to have a body and a "Signed-off-by" line. We follow the same contribution guidelines as Zephyr, here are instructions for the commit message: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/contribute/guidelines.html#commit-message-guidelines |
Please follow the commit message guidelines (https://docs.zephyrproject.org/latest/contribute/guidelines.html#commit-message-guidelines), in short:
|
Test specificationCI/Jenkins/NRF
CI/Jenkins/integration
Detailed information of selected test modules Note: This message is automatically posted and updated by the CI |
Ensures that the timestamp returned by the ntp api has millisecond accuracy instead of second accuracy. Signed-off-by: Maximilian Fischer <syscrypt@protonmail.com>
9947f32
to
521d8b0
Compare
Thanks for the quick turnaround, I have adjusted the commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it is a little bit confusing that the api
date_time_now
method expects anint64_t
pointer to a var calledunix_time_ms
which then has an accuracy of a second.
Zephyr has a convention of using time as int64_t
in milliseconds so regardless of what would make sense in a particular API, this convention is still followed in many places, such as Location library API.
Hi, the ntp part of the date_time lib ignores the fraction field returned by the ntp protocol, which leads to an accuracy within one second.
While this change makes sense and is fine for me, we will always have an accuracy issue because there is data transfer delay in returning the NTP time from the server and then getting it through the device's SW architecture. So this change removes some inaccuracy but there is still a random delay which can be seconds or even tens of seconds in some cases depending on cellular network conditions.
@@ -108,7 +109,9 @@ int date_time_ntp_get(int64_t *date_time_ms) | |||
continue; | |||
} | |||
LOG_DBG("Time obtained from NTP server %s", servers[i]); | |||
*date_time_ms = (int64_t)sntp_time.seconds * 1000; | |||
|
|||
milliseconds = (uint32_t)(((double) sntp_time.fraction / UINT32_MAX) * 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a comment would be nice to say that the fraction part is not milliseconds, microseconds or nanoseconds but rather fractions of a second based on 32 bit unsigned integer maximum value.
I know that's what the code does or "says" but given this is very weird unit, it would be good to have a comment alarming the reader about it.
@syscrypt You still need to sign the CLA, see #11847 (comment). |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Hi,
the ntp part of the date_time lib ignores the fraction field returned by the ntp protocol, which leads to an accuracy within one second. I am aware that the date_time api docs mention that the fetched time is a UTC date time stamp so I guess this is expected behavior. But it is a little bit confusing that the api
date_time_now
method expects anint64_t
pointer to a var calledunix_time_ms
which then has an accuracy of a second.Is it possible to update the ntp part to provide a millisecond accuracy as in my pr?
Regards