Skip to content

Commit 5cb8842

Browse files
authored
Pass down caller pointer to RPV callbacks (#76)
1 parent 09dc37d commit 5cb8842

22 files changed

+108
-67
lines changed

cwrapper/scrutiny_cwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ extern "C"
9696
get_config(config)->set_published_values(
9797
reinterpret_cast<scrutiny::RuntimePublishedValue const *>(array), // should match as per static_assert above
9898
nbr,
99-
reinterpret_cast<scrutiny::RpvReadCallback>(reinterpret_cast<void *>(rd_cb)), // Expect signature to match
100-
reinterpret_cast<scrutiny::RpvWriteCallback>(reinterpret_cast<void *>(wr_cb))); // Expect signature to match
99+
reinterpret_cast<scrutiny::RpvReadCallback>(rd_cb), // Expect signature to match
100+
reinterpret_cast<scrutiny::RpvWriteCallback>(wr_cb)); // Expect signature to match
101101
}
102102

103103
void scrutiny_c_config_set_loops(scrutiny_c_config_t *config, scrutiny_c_loop_handler_t **loops, uint8_t const loop_count)

lib/inc/datalogging/scrutiny_datalogger.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
namespace scrutiny
2323
{
2424
class MainHandler;
25+
class LoopHandler;
2526

2627
namespace datalogging
2728
{
@@ -120,6 +121,11 @@ namespace scrutiny
120121
/// @brief Returns the number of bytes acquired since the trigger event.
121122
buffer_size_t data_counter_since_trigger(void) const;
122123

124+
/// @brief Return the LoopHandler that owns the datalogger. Null if owned by the MainHandler. This value is updated by the owner himself.
125+
inline LoopHandler *get_owner(void) const { return m_owner; }
126+
/// @brief Sets the LoopHandler that owns the datalogger. Null if owned by the MainHandler. This value is updated by the owner himself.
127+
inline void set_owner(LoopHandler *const owner) { m_owner = owner; }
128+
123129
/// @brief Forces the trigger condition to be fulfilled, triggering an acquisition if the datalogger is armed.
124130
void force_trigger(void)
125131
{
@@ -143,7 +149,7 @@ namespace scrutiny
143149
m_trigger_callback; // A function pointer to be called when the trigger trigs. Executed in the owner loop (no thread safety)
144150

145151
Timebase const *m_timebase; // Pointer to the timebase of the owning loop. Used for logging at trigger handling (hold time & timeouts)
146-
State::eState m_state; // Internal state
152+
State::eState m_state; // Internal state
147153
timestamp_t m_trigger_timestamp; // The timestamp at which the trigger happened
148154
buffer_size_t m_trigger_cursor_location; // Cursor location when trigger point has been recorded
149155

@@ -159,6 +165,7 @@ namespace scrutiny
159165
uint16_t m_config_id; // The configuration ID given by the server
160166
buffer_size_t m_log_points_after_trigger; // Number of log entry counted after the trigger condition was fulfilled.
161167

168+
LoopHandler *m_owner; // A pointer to the loop owning the datalogger. Should reflect MainHandler::m_datalogging.owner.
162169
struct
163170
{
164171
bool previous_val; // Trigger condition result of the previous cycle

lib/inc/datalogging/scrutiny_datalogger_raw_encoder.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
namespace scrutiny
2727
{
2828
class MainHandler;
29+
class LoopHandler;
30+
2931
namespace datalogging
3032
{
3133
class RawFormatEncoder;
@@ -62,7 +64,7 @@ namespace scrutiny
6264
datalogging::Configuration const *const config,
6365
uint8_t *const buffer,
6466
datalogging::buffer_size_t const buffer_size);
65-
void encode_next_entry(void);
67+
void encode_next_entry(LoopHandler *const caller);
6668
void reset(void);
6769
inline void reset_write_counter(void) { m_entry_write_counter = 0; }
6870
inline void set_timebase(Timebase const *const timebase) { m_timebase = timebase; }

lib/inc/datalogging/scrutiny_datalogging.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ namespace scrutiny
3535
/// @param operand The operand to read
3636
/// @param val Output value
3737
/// @param variable_type Output variable type
38+
/// @param caller the calling LoopHandler. Null if done by the MainHandler
3839
/// @return true on success. false on failure
3940
bool fetch_operand(
4041
MainHandler const *const main_handler,
4142
Operand const *const operand,
4243
AnyType *const val,
43-
VariableType::eVariableType *const variable_type);
44+
VariableType::eVariableType *const variable_type,
45+
LoopHandler *const caller);
4446
} // namespace datalogging
4547
} // namespace scrutiny
4648

lib/inc/scrutiny_c_compatible_types.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ typedef struct
134134
} scrutiny_c_runtime_published_value_t;
135135

136136
/// @brief Callback called on Runtime Published Value read
137-
typedef int (*scrutiny_c_rpv_read_callback_t)(scrutiny_c_runtime_published_value_t const rpv, scrutiny_c_any_type_t *outval);
137+
typedef int (*scrutiny_c_rpv_read_callback_t)(scrutiny_c_runtime_published_value_t const rpv, scrutiny_c_any_type_t *outval, void *const caller);
138138
/// @brief Callback called on Runtime Published Value write
139-
typedef int (*scrutiny_c_rpv_write_callback_t)(scrutiny_c_runtime_published_value_t const rpv, scrutiny_c_any_type_t const *inval);
139+
typedef int (
140+
*scrutiny_c_rpv_write_callback_t)(scrutiny_c_runtime_published_value_t const rpv, scrutiny_c_any_type_t const *inval, void *const caller);
140141

141142
#if SCRUTINY_ENABLE_DATALOGGING
142143
typedef void (*scrutiny_c_datalogging_trigger_callback_t)();

lib/inc/scrutiny_loop_handler.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace scrutiny
9696
m_name(name)
9797
#if SCRUTINY_ENABLE_DATALOGGING
9898
,
99-
m_datalogger(SCRUTINY_NULL), m_owns_datalogger(false), m_datalogger_data_acquired(false), m_support_datalogging(true)
99+
m_datalogger(SCRUTINY_NULL), m_datalogger_data_acquired(false), m_support_datalogging(true)
100100
#endif
101101
{
102102
}
@@ -149,7 +149,7 @@ namespace scrutiny
149149

150150
inline bool owns_datalogger(void) const
151151
{
152-
return m_owns_datalogger;
152+
return (m_datalogger->get_owner() == this);
153153
}
154154
#endif
155155

@@ -171,8 +171,6 @@ namespace scrutiny
171171
#if SCRUTINY_ENABLE_DATALOGGING
172172
/// @brief A pointer to the datalogger object part of the Main Handler
173173
datalogging::DataLogger *m_datalogger;
174-
/// @brief Tells wether this loop is the owner of the datalogger
175-
bool m_owns_datalogger;
176174
/// @brief Indicates if data has been acquired and ready to be downloaded or saved
177175
bool m_datalogger_data_acquired;
178176
/// @brief Indicates if this loop can do datalogging

lib/inc/scrutiny_types.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
namespace scrutiny
1616
{
17+
class LoopHandler;
18+
1719
namespace ctypes
1820
{
1921
#include "scrutiny_c_compatible_types.h"
@@ -144,9 +146,9 @@ namespace scrutiny
144146
};
145147

146148
/// @brief Callback called on Runtime Published Value read
147-
typedef bool (*RpvReadCallback)(RuntimePublishedValue const rpv, AnyType *outval);
149+
typedef bool (*RpvReadCallback)(RuntimePublishedValue const rpv, AnyType *outval, LoopHandler *const caller);
148150
/// @brief Callback called on Runtime Published Value write
149-
typedef bool (*RpvWriteCallback)(RuntimePublishedValue const rpv, AnyType const *inval);
151+
typedef bool (*RpvWriteCallback)(RuntimePublishedValue const rpv, AnyType const *inval, LoopHandler *const caller);
150152

151153
/// @brief Represents a memory block with data/mask pointer. Mainly used for memory write operations.
152154
struct MemoryBlock

lib/src/datalogging/scrutiny_datalogger.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace scrutiny
3131
m_main_handler = main_handler;
3232
m_buffer_size = buffer_size;
3333
m_trigger_callback = trigger_callback;
34+
m_owner = SCRUTINY_NULL;
3435

3536
m_encoder.init(main_handler, &m_config, buffer, buffer_size);
3637
m_acquisition_id = 0;
@@ -337,7 +338,7 @@ namespace scrutiny
337338
{
338339
if (++m_decimation_counter >= m_config.decimation)
339340
{
340-
m_encoder.encode_next_entry();
341+
m_encoder.encode_next_entry(m_owner);
341342
m_decimation_counter = 0;
342343
}
343344
}
@@ -371,7 +372,7 @@ namespace scrutiny
371372

372373
for (unsigned int i = 0; i < nb_operand; i++)
373374
{
374-
if (fetch_operand(m_main_handler, &m_config.trigger.operands[i], &opvals[i], &optypes[i]) == false)
375+
if (fetch_operand(m_main_handler, &m_config.trigger.operands[i], &opvals[i], &optypes[i], SCRUTINY_NULL) == false)
375376
{
376377
return false;
377378
}

lib/src/datalogging/scrutiny_datalogger_raw_encoder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace scrutiny
114114
}
115115

116116
/// @brief Takes a snapshot of the data to log and write it into the datalogger buffer
117-
void RawFormatEncoder::encode_next_entry(void)
117+
void RawFormatEncoder::encode_next_entry(LoopHandler *const caller)
118118
{
119119
if (m_error)
120120
{
@@ -148,7 +148,10 @@ namespace scrutiny
148148
uint16_t const rpv_id = m_config->items_to_log[i].data.rpv.id;
149149
m_main_handler->get_rpv(rpv_id, &rpv);
150150
uint8_t const typesize = tools::get_type_size(rpv.type); // Should be supported. We rely on datalogger::configure
151-
m_main_handler->get_rpv_read_callback()(rpv, &outval); // We assume that this is not nullptr. We rely on datalogger::configure
151+
m_main_handler->get_rpv_read_callback()(
152+
rpv,
153+
&outval,
154+
caller); // We assume that this is not nullptr. We rely on datalogger::configure
152155
codecs::encode_anytype_big_endian(&outval, typesize, &m_buffer[cursor]);
153156
cursor += typesize;
154157
}

lib/src/datalogging/scrutiny_datalogging.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ namespace scrutiny
100100
MainHandler const *const main_handler,
101101
Operand const *const operand,
102102
AnyType *const val,
103-
VariableType::eVariableType *const variable_type)
103+
VariableType::eVariableType *const variable_type,
104+
LoopHandler *const caller)
104105
{
105106
bool success = true;
106107
if (operand->type == OperandType::LITERAL)
@@ -112,7 +113,7 @@ namespace scrutiny
112113
{
113114
RuntimePublishedValue rpv;
114115
main_handler->get_rpv(operand->data.rpv.id, &rpv);
115-
success = main_handler->get_rpv_read_callback()(rpv, val);
116+
success = main_handler->get_rpv_read_callback()(rpv, val, caller);
116117
*variable_type = rpv.type;
117118
}
118119
else if (operand->type == OperandType::VAR)

0 commit comments

Comments
 (0)