From 8e704b53f4151843fc6ddfa5345859798e4fbfd2 Mon Sep 17 00:00:00 2001 From: Pier-Yves Lessard Date: Mon, 9 Jun 2025 19:53:09 -0400 Subject: [PATCH 1/2] Allow to specify the timestep for ff loop --- lib/src/scrutiny_loop_handler.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/scrutiny_loop_handler.cpp b/lib/src/scrutiny_loop_handler.cpp index 9458428..4680054 100644 --- a/lib/src/scrutiny_loop_handler.cpp +++ b/lib/src/scrutiny_loop_handler.cpp @@ -113,9 +113,14 @@ namespace scrutiny { process_common(m_timestep_100ns); } - void VariableFrequencyLoopHandler::process(timediff_t const timestep_100ns) + + void FixedFrequencyLoopHandler::process(timediff_t const timestep_100ns) { process_common(timestep_100ns); } + void VariableFrequencyLoopHandler::process(timediff_t const timestep_100ns) + { + process_common(timestep_100ns); + } } \ No newline at end of file From 250651a0dd9d8749f900aadfaf7db90bbd8ccd85 Mon Sep 17 00:00:00 2001 From: Pier-Yves Lessard Date: Mon, 9 Jun 2025 20:11:09 -0400 Subject: [PATCH 2/2] finalize support of time emasurement for ff loops --- cwrapper/scrutiny_cwrapper.cpp | 4 ++-- cwrapper/scrutiny_cwrapper.h | 3 ++- lib/inc/scrutiny_loop_handler.hpp | 9 +++++++-- projects/c_testapp/src/main.c | 7 ++++--- projects/testapp/src/main.cpp | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cwrapper/scrutiny_cwrapper.cpp b/cwrapper/scrutiny_cwrapper.cpp index e25dd01..13f1668 100644 --- a/cwrapper/scrutiny_cwrapper.cpp +++ b/cwrapper/scrutiny_cwrapper.cpp @@ -162,9 +162,9 @@ extern "C" return reinterpret_cast(new (mem) scrutiny::FixedFrequencyLoopHandler(timestep_100ns, name)); // Placement new } - void scrutiny_c_loop_handler_fixed_freq_process(scrutiny_c_loop_handler_ff_t *loop_handler) + void scrutiny_c_loop_handler_fixed_freq_process(scrutiny_c_loop_handler_ff_t *loop_handler, scrutiny_c_timediff_t const timestep_100n) { - get_loop_handler_ff(loop_handler)->process(); + get_loop_handler_ff(loop_handler)->process(timestep_100n); } scrutiny_c_loop_handler_vf_t *scrutiny_c_loop_handler_variable_freq_construct(void *mem, size_t const size, char const *name) diff --git a/cwrapper/scrutiny_cwrapper.h b/cwrapper/scrutiny_cwrapper.h index 3e1750d..d27936a 100644 --- a/cwrapper/scrutiny_cwrapper.h +++ b/cwrapper/scrutiny_cwrapper.h @@ -196,7 +196,8 @@ extern "C" /// @brief Wrapper for `FixedFrequencyLoopHandler::process()` /// Process function be called at each iteration of the loop. /// @param loop_handler The `FixedFrequencyLoopHandler` object to work on - void scrutiny_c_loop_handler_fixed_freq_process(scrutiny_c_loop_handler_ff_t *loop_handler); + /// @param timestep_100n The real, used when graphing with MeasuredTime + void scrutiny_c_loop_handler_fixed_freq_process(scrutiny_c_loop_handler_ff_t *loop_handler, scrutiny_c_timediff_t const timestep_100n); /// @brief Wrapper for `VariableFrequencyLoopHandler::VariableFrequencyLoopHandler()`. /// Construct `scrutiny::VariableFrequencyLoopHandler` object at a given address. Fails if `mem` is NULL or if the size is not big enough. diff --git a/lib/inc/scrutiny_loop_handler.hpp b/lib/inc/scrutiny_loop_handler.hpp index 25d602c..d5de245 100644 --- a/lib/inc/scrutiny_loop_handler.hpp +++ b/lib/inc/scrutiny_loop_handler.hpp @@ -156,8 +156,13 @@ namespace scrutiny m_timestep_100ns(timestep_100ns) { } + + /// @brief Process function be called at each iteration of the loop. + void process(); + /// @brief Process function be called at each iteration of the loop. - void process(void); + /// @param timestep_100ns Time delta since last call to process() in multiple of 100ns + void process(timediff_t const timestep_100ns); /// @brief Return the type of loop handler virtual LoopType loop_type(void) const override { return LoopType::FIXED_FREQ; } @@ -185,7 +190,7 @@ namespace scrutiny /// @brief Process function be called at each iteration of the loop. /// @param timestep_100ns Time delta since last call to process() in multiple of 100ns - void process(timediff_t timestep_100ns); + void process(timediff_t const timestep_100ns); /// @brief Return the type of loop handler virtual LoopType loop_type(void) const override { return LoopType::VARIABLE_FREQ; } diff --git a/projects/c_testapp/src/main.c b/projects/c_testapp/src/main.c index 08cb33b..a9c4076 100644 --- a/projects/c_testapp/src/main.c +++ b/projects/c_testapp/src/main.c @@ -447,9 +447,10 @@ void process_scrutiny_lib(comm_channel_interface_t *channel) } printf("\n"); } - - scrutiny_c_loop_handler_variable_freq_process(vf_loop, timestep_us*10); - scrutiny_c_loop_handler_fixed_freq_process(ff_loop); + + uint32_t const timestep_100ns = timestep_us*10; + scrutiny_c_loop_handler_variable_freq_process(vf_loop, timestep_100ns); + scrutiny_c_loop_handler_fixed_freq_process(ff_loop, timestep_100ns); #if SCRUTINY_BUILD_WINDOWS Sleep(10); #else diff --git a/projects/testapp/src/main.cpp b/projects/testapp/src/main.cpp index 337533a..4f71f76 100644 --- a/projects/testapp/src/main.cpp +++ b/projects/testapp/src/main.cpp @@ -446,7 +446,7 @@ void process_scrutiny_lib(AbstractCommChannel *channel) } vf_loop.process(timestep_us * 10); - ff_loop.process(); + ff_loop.process(timestep_us * 10); #if SCRUTINY_BUILD_WINDOWS Sleep(10); #else