Skip to content

Commit b1544b6

Browse files
authored
Allow fixed freq loop to specify real time delta (#67)
Allow fixed freq loop to specify real time delta
1 parent ab2ca7c commit b1544b6

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

cwrapper/scrutiny_cwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ extern "C"
162162
return reinterpret_cast<scrutiny_c_loop_handler_ff_t *>(new (mem) scrutiny::FixedFrequencyLoopHandler(timestep_100ns, name)); // Placement new
163163
}
164164

165-
void scrutiny_c_loop_handler_fixed_freq_process(scrutiny_c_loop_handler_ff_t *loop_handler)
165+
void scrutiny_c_loop_handler_fixed_freq_process(scrutiny_c_loop_handler_ff_t *loop_handler, scrutiny_c_timediff_t const timestep_100n)
166166
{
167-
get_loop_handler_ff(loop_handler)->process();
167+
get_loop_handler_ff(loop_handler)->process(timestep_100n);
168168
}
169169

170170
scrutiny_c_loop_handler_vf_t *scrutiny_c_loop_handler_variable_freq_construct(void *mem, size_t const size, char const *name)

cwrapper/scrutiny_cwrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ extern "C"
196196
/// @brief Wrapper for `FixedFrequencyLoopHandler::process()`
197197
/// Process function be called at each iteration of the loop.
198198
/// @param loop_handler The `FixedFrequencyLoopHandler` object to work on
199-
void scrutiny_c_loop_handler_fixed_freq_process(scrutiny_c_loop_handler_ff_t *loop_handler);
199+
/// @param timestep_100n The real, used when graphing with MeasuredTime
200+
void scrutiny_c_loop_handler_fixed_freq_process(scrutiny_c_loop_handler_ff_t *loop_handler, scrutiny_c_timediff_t const timestep_100n);
200201

201202
/// @brief Wrapper for `VariableFrequencyLoopHandler::VariableFrequencyLoopHandler()`.
202203
/// Construct `scrutiny::VariableFrequencyLoopHandler` object at a given address. Fails if `mem` is NULL or if the size is not big enough.

lib/inc/scrutiny_loop_handler.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,13 @@ namespace scrutiny
156156
m_timestep_100ns(timestep_100ns)
157157
{
158158
}
159+
160+
/// @brief Process function be called at each iteration of the loop.
161+
void process();
162+
159163
/// @brief Process function be called at each iteration of the loop.
160-
void process(void);
164+
/// @param timestep_100ns Time delta since last call to process() in multiple of 100ns
165+
void process(timediff_t const timestep_100ns);
161166

162167
/// @brief Return the type of loop handler
163168
virtual LoopType loop_type(void) const override { return LoopType::FIXED_FREQ; }
@@ -185,7 +190,7 @@ namespace scrutiny
185190

186191
/// @brief Process function be called at each iteration of the loop.
187192
/// @param timestep_100ns Time delta since last call to process() in multiple of 100ns
188-
void process(timediff_t timestep_100ns);
193+
void process(timediff_t const timestep_100ns);
189194

190195
/// @brief Return the type of loop handler
191196
virtual LoopType loop_type(void) const override { return LoopType::VARIABLE_FREQ; }

lib/src/scrutiny_loop_handler.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,14 @@ namespace scrutiny
113113
{
114114
process_common(m_timestep_100ns);
115115
}
116-
void VariableFrequencyLoopHandler::process(timediff_t const timestep_100ns)
116+
117+
void FixedFrequencyLoopHandler::process(timediff_t const timestep_100ns)
117118
{
118119
process_common(timestep_100ns);
119120
}
120121

122+
void VariableFrequencyLoopHandler::process(timediff_t const timestep_100ns)
123+
{
124+
process_common(timestep_100ns);
125+
}
121126
}

projects/c_testapp/src/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,10 @@ void process_scrutiny_lib(comm_channel_interface_t *channel)
447447
}
448448
printf("\n");
449449
}
450-
451-
scrutiny_c_loop_handler_variable_freq_process(vf_loop, timestep_us*10);
452-
scrutiny_c_loop_handler_fixed_freq_process(ff_loop);
450+
451+
uint32_t const timestep_100ns = timestep_us*10;
452+
scrutiny_c_loop_handler_variable_freq_process(vf_loop, timestep_100ns);
453+
scrutiny_c_loop_handler_fixed_freq_process(ff_loop, timestep_100ns);
453454
#if SCRUTINY_BUILD_WINDOWS
454455
Sleep(10);
455456
#else

projects/testapp/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ void process_scrutiny_lib(AbstractCommChannel *channel)
446446
}
447447

448448
vf_loop.process(timestep_us * 10);
449-
ff_loop.process();
449+
ff_loop.process(timestep_us * 10);
450450
#if SCRUTINY_BUILD_WINDOWS
451451
Sleep(10);
452452
#else

0 commit comments

Comments
 (0)