Skip to content
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
20 changes: 7 additions & 13 deletions docs/module/manuals/api_description/use_cases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,13 @@ diagnostics and PTP data sanity checks:

</div>

.. warning::

Both PTP data callbacks (``TimeSlaveSyncData`` and ``PDelayMeasurementData``) are
**not yet delivered**. Calling ``Subscribe<...>()`` compiles and runs without error,
but the registered callbacks will never be invoked. Delivery will be wired from a
dedicated background thread in a future change.
Delivery is performed by a dedicated worker thread owned by the ``VehicleTime`` backend.
The TimeDaemon publishes into a shared-memory segment without a notification facility, so
the worker polls that segment at a fixed interval (50 ms). The thread is started when the
first callback is registered and runs until the backend is destroyed; while no callback is
registered it sleeps until the next registration. A newly registered callback receives the first
frame polled after its registration; afterwards it is invoked only for frames whose sync or
pDelay content differs from the previously delivered one.

.. code-block:: cpp

Expand Down Expand Up @@ -376,13 +377,6 @@ excluded from the comparison.

</div>

.. warning::

The ``VehicleTimeStatus`` callback is **not yet delivered**. Calling
``Subscribe<VehicleTimeStatus>()`` compiles and runs without error, but the registered
callback will never be invoked. Delivery will be wired from a dedicated background
thread in a future change.

.. code-block:: cpp

#include "score/time/vehicle_time/src/vehicle_clock.h"
Expand Down
2 changes: 1 addition & 1 deletion docs/module/manuals/examples/vehicle_time.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Key features:
- **Dual time sources**: Both vehicle and local time in single call
- **Status monitoring**: Reliability and consistency flags
- **Rate tracking**: Clock deviation measurement
- **Callback support**: Status change notifications (future feature)
- **Callback support**: Status change notifications delivered on the backend's worker thread

Main Program
~~~~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions examples/time/vehicle_time/src/vehicle_time_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ class VehicleTimeHandler

/// @brief Registers a callback that is invoked when VehicleTimeStatus flags change.
///
/// @note Delivery is not yet implemented in the backend. The callback can
/// be registered now; it will be invoked once background-thread
/// delivery is wired up in a future change.
/// The callback fires once with the current status right after registration and
/// afterwards whenever the status flags change. It is invoked on the backend's
/// worker thread, so the callback implementation must be thread-safe.
void RegisterStatusCallback(score::time::VehicleTime::StatusChangedCallback callback) noexcept
{
clock_.Subscribe<score::time::VehicleTimeStatus>(std::move(callback));
Expand Down
61 changes: 58 additions & 3 deletions score/time/vehicle_time/src/details/td_impl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,78 @@
load("@score_baselibs//:bazel/unit_tests.bzl", "cc_unit_test_suites_for_host_and_qnx")
load("@score_baselibs//score/language/safecpp:toolchain_features.bzl", "COMPILER_WARNING_FEATURES")

# Production backend: reads live PTP data from the TimeDaemon via SvtReceiver.
# Production backend: reads live PTP data from the TimeDaemon via SvtReceiver and
# delivers subscription callbacks from a dedicated worker thread.
# Link this target (or the forwarding alias //score/time/vehicle_time/src/details:td_impl)
# into the production binary to provide CreateBackend<VehicleTime>().
cc_library(
name = "td_impl",
srcs = [
"svt_callback_dispatcher.cpp",
"vehicle_clock_backend_impl.cpp",
"//score/time/vehicle_time/src/details:logging_contexts", # internal header
],
hdrs = ["vehicle_clock_backend_impl.h"],
hdrs = [
"svt_callback_dispatcher.h",
"svt_callback_wrapper.h",
"vehicle_clock_backend_impl.h",
],
features = COMPILER_WARNING_FEATURES,
visibility = ["//score/time/vehicle_time:__subpackages__"],
deps = [
"//score/time/high_res_steady_time/src:high_res_steady_clock",
"//score/time/vehicle_time/src:vehicle_clock",
"//score/time_daemon/src/ipc:svt_receiver",
"@score_baselibs//score/concurrency:condition_variable",
"@score_baselibs//score/language/futurecpp",
"@score_baselibs//score/mw/log:frontend",
],
)

cc_test(
name = "svt_callback_wrapper_test",
srcs = [
"svt_callback_wrapper.h",
"svt_callback_wrapper_test.cpp",
],
features = COMPILER_WARNING_FEATURES,
tags = ["unit"],
deps = [
"@googletest//:gtest",
"@googletest//:gtest_main",
"@score_baselibs//score/language/futurecpp",
],
)

cc_test(
name = "svt_callback_dispatcher_test",
srcs = [
"svt_callback_dispatcher.cpp",
"svt_callback_dispatcher.h",
"svt_callback_dispatcher_test.cpp",
"svt_callback_wrapper.h",
"svt_test_helpers.h",
],
features = COMPILER_WARNING_FEATURES,
tags = ["unit"],
deps = [
"//score/time/vehicle_time/src:vehicle_clock",
"//score/time_daemon/src/ipc:svt_receiver_mock",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@score_baselibs//score/concurrency:condition_variable",
"@score_baselibs//score/language/futurecpp",
"@score_baselibs//score/language/safecpp/coverage_termination_handler",
],
)

cc_test(
name = "vehicle_clock_backend_impl_test",
srcs = [
"svt_callback_dispatcher.cpp",
"svt_callback_dispatcher.h",
"svt_callback_wrapper.h",
"svt_test_helpers.h",
"vehicle_clock_backend_impl.cpp",
"vehicle_clock_backend_impl.h",
"vehicle_clock_backend_impl_test.cpp",
Expand All @@ -53,6 +102,8 @@ cc_test(
"//score/time_daemon/src/ipc:svt_receiver_mock",
"@googletest//:gtest",
"@googletest//:gtest_main",
"@score_baselibs//score/concurrency:condition_variable",
"@score_baselibs//score/language/futurecpp",
"@score_baselibs//score/language/safecpp/coverage_termination_handler",
"@score_baselibs//score/mw/log:console_only_backend",
"@score_baselibs//score/mw/log:frontend",
Expand All @@ -61,6 +112,10 @@ cc_test(

cc_unit_test_suites_for_host_and_qnx(
name = "unit_test_suite",
cc_unit_tests = [":vehicle_clock_backend_impl_test"],
cc_unit_tests = [
":svt_callback_dispatcher_test",
":svt_callback_wrapper_test",
":vehicle_clock_backend_impl_test",
],
visibility = ["//score/time/vehicle_time:__subpackages__"],
)
Loading
Loading