Skip to content
Merged
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
4 changes: 2 additions & 2 deletions cwrapper/scrutiny_cwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ extern "C"
get_config(config)->set_published_values(
reinterpret_cast<scrutiny::RuntimePublishedValue const *>(array), // should match as per static_assert above
nbr,
reinterpret_cast<scrutiny::RpvReadCallback>(reinterpret_cast<void *>(rd_cb)), // Expect signature to match
reinterpret_cast<scrutiny::RpvWriteCallback>(reinterpret_cast<void *>(wr_cb))); // Expect signature to match
reinterpret_cast<scrutiny::RpvReadCallback>(rd_cb), // Expect signature to match
reinterpret_cast<scrutiny::RpvWriteCallback>(wr_cb)); // Expect signature to match
}

void scrutiny_c_config_set_loops(scrutiny_c_config_t *config, scrutiny_c_loop_handler_t **loops, uint8_t const loop_count)
Expand Down
9 changes: 8 additions & 1 deletion lib/inc/datalogging/scrutiny_datalogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
namespace scrutiny
{
class MainHandler;
class LoopHandler;

namespace datalogging
{
Expand Down Expand Up @@ -120,6 +121,11 @@ namespace scrutiny
/// @brief Returns the number of bytes acquired since the trigger event.
buffer_size_t data_counter_since_trigger(void) const;

/// @brief Return the LoopHandler that owns the datalogger. Null if owned by the MainHandler. This value is updated by the owner himself.
inline LoopHandler *get_owner(void) const { return m_owner; }
/// @brief Sets the LoopHandler that owns the datalogger. Null if owned by the MainHandler. This value is updated by the owner himself.
inline void set_owner(LoopHandler *const owner) { m_owner = owner; }

/// @brief Forces the trigger condition to be fulfilled, triggering an acquisition if the datalogger is armed.
void force_trigger(void)
{
Expand All @@ -143,7 +149,7 @@ namespace scrutiny
m_trigger_callback; // A function pointer to be called when the trigger trigs. Executed in the owner loop (no thread safety)

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

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

LoopHandler *m_owner; // A pointer to the loop owning the datalogger. Should reflect MainHandler::m_datalogging.owner.
struct
{
bool previous_val; // Trigger condition result of the previous cycle
Expand Down
4 changes: 3 additions & 1 deletion lib/inc/datalogging/scrutiny_datalogger_raw_encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
namespace scrutiny
{
class MainHandler;
class LoopHandler;

namespace datalogging
{
class RawFormatEncoder;
Expand Down Expand Up @@ -62,7 +64,7 @@ namespace scrutiny
datalogging::Configuration const *const config,
uint8_t *const buffer,
datalogging::buffer_size_t const buffer_size);
void encode_next_entry(void);
void encode_next_entry(LoopHandler *const caller);
void reset(void);
inline void reset_write_counter(void) { m_entry_write_counter = 0; }
inline void set_timebase(Timebase const *const timebase) { m_timebase = timebase; }
Expand Down
4 changes: 3 additions & 1 deletion lib/inc/datalogging/scrutiny_datalogging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ namespace scrutiny
/// @param operand The operand to read
/// @param val Output value
/// @param variable_type Output variable type
/// @param caller the calling LoopHandler. Null if done by the MainHandler
/// @return true on success. false on failure
bool fetch_operand(
MainHandler const *const main_handler,
Operand const *const operand,
AnyType *const val,
VariableType::eVariableType *const variable_type);
VariableType::eVariableType *const variable_type,
LoopHandler *const caller);
} // namespace datalogging
} // namespace scrutiny

Expand Down
5 changes: 3 additions & 2 deletions lib/inc/scrutiny_c_compatible_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ typedef struct
} scrutiny_c_runtime_published_value_t;

/// @brief Callback called on Runtime Published Value read
typedef int (*scrutiny_c_rpv_read_callback_t)(scrutiny_c_runtime_published_value_t const rpv, scrutiny_c_any_type_t *outval);
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);
/// @brief Callback called on Runtime Published Value write
typedef int (*scrutiny_c_rpv_write_callback_t)(scrutiny_c_runtime_published_value_t const rpv, scrutiny_c_any_type_t const *inval);
typedef int (
*scrutiny_c_rpv_write_callback_t)(scrutiny_c_runtime_published_value_t const rpv, scrutiny_c_any_type_t const *inval, void *const caller);

#if SCRUTINY_ENABLE_DATALOGGING
typedef void (*scrutiny_c_datalogging_trigger_callback_t)();
Expand Down
6 changes: 2 additions & 4 deletions lib/inc/scrutiny_loop_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace scrutiny
m_name(name)
#if SCRUTINY_ENABLE_DATALOGGING
,
m_datalogger(SCRUTINY_NULL), m_owns_datalogger(false), m_datalogger_data_acquired(false), m_support_datalogging(true)
m_datalogger(SCRUTINY_NULL), m_datalogger_data_acquired(false), m_support_datalogging(true)
#endif
{
}
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace scrutiny

inline bool owns_datalogger(void) const
{
return m_owns_datalogger;
return (m_datalogger->get_owner() == this);
}
#endif

Expand All @@ -171,8 +171,6 @@ namespace scrutiny
#if SCRUTINY_ENABLE_DATALOGGING
/// @brief A pointer to the datalogger object part of the Main Handler
datalogging::DataLogger *m_datalogger;
/// @brief Tells wether this loop is the owner of the datalogger
bool m_owns_datalogger;
/// @brief Indicates if data has been acquired and ready to be downloaded or saved
bool m_datalogger_data_acquired;
/// @brief Indicates if this loop can do datalogging
Expand Down
6 changes: 4 additions & 2 deletions lib/inc/scrutiny_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace scrutiny
{
class LoopHandler;

namespace ctypes
{
#include "scrutiny_c_compatible_types.h"
Expand Down Expand Up @@ -144,9 +146,9 @@ namespace scrutiny
};

/// @brief Callback called on Runtime Published Value read
typedef bool (*RpvReadCallback)(RuntimePublishedValue const rpv, AnyType *outval);
typedef bool (*RpvReadCallback)(RuntimePublishedValue const rpv, AnyType *outval, LoopHandler *const caller);
/// @brief Callback called on Runtime Published Value write
typedef bool (*RpvWriteCallback)(RuntimePublishedValue const rpv, AnyType const *inval);
typedef bool (*RpvWriteCallback)(RuntimePublishedValue const rpv, AnyType const *inval, LoopHandler *const caller);

/// @brief Represents a memory block with data/mask pointer. Mainly used for memory write operations.
struct MemoryBlock
Expand Down
5 changes: 3 additions & 2 deletions lib/src/datalogging/scrutiny_datalogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace scrutiny
m_main_handler = main_handler;
m_buffer_size = buffer_size;
m_trigger_callback = trigger_callback;
m_owner = SCRUTINY_NULL;

m_encoder.init(main_handler, &m_config, buffer, buffer_size);
m_acquisition_id = 0;
Expand Down Expand Up @@ -337,7 +338,7 @@ namespace scrutiny
{
if (++m_decimation_counter >= m_config.decimation)
{
m_encoder.encode_next_entry();
m_encoder.encode_next_entry(m_owner);
m_decimation_counter = 0;
}
}
Expand Down Expand Up @@ -371,7 +372,7 @@ namespace scrutiny

for (unsigned int i = 0; i < nb_operand; i++)
{
if (fetch_operand(m_main_handler, &m_config.trigger.operands[i], &opvals[i], &optypes[i]) == false)
if (fetch_operand(m_main_handler, &m_config.trigger.operands[i], &opvals[i], &optypes[i], SCRUTINY_NULL) == false)
{
return false;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/src/datalogging/scrutiny_datalogger_raw_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace scrutiny
}

/// @brief Takes a snapshot of the data to log and write it into the datalogger buffer
void RawFormatEncoder::encode_next_entry(void)
void RawFormatEncoder::encode_next_entry(LoopHandler *const caller)
{
if (m_error)
{
Expand Down Expand Up @@ -148,7 +148,10 @@ namespace scrutiny
uint16_t const rpv_id = m_config->items_to_log[i].data.rpv.id;
m_main_handler->get_rpv(rpv_id, &rpv);
uint8_t const typesize = tools::get_type_size(rpv.type); // Should be supported. We rely on datalogger::configure
m_main_handler->get_rpv_read_callback()(rpv, &outval); // We assume that this is not nullptr. We rely on datalogger::configure
m_main_handler->get_rpv_read_callback()(
rpv,
&outval,
caller); // We assume that this is not nullptr. We rely on datalogger::configure
codecs::encode_anytype_big_endian(&outval, typesize, &m_buffer[cursor]);
cursor += typesize;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/datalogging/scrutiny_datalogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ namespace scrutiny
MainHandler const *const main_handler,
Operand const *const operand,
AnyType *const val,
VariableType::eVariableType *const variable_type)
VariableType::eVariableType *const variable_type,
LoopHandler *const caller)
{
bool success = true;
if (operand->type == OperandType::LITERAL)
Expand All @@ -112,7 +113,7 @@ namespace scrutiny
{
RuntimePublishedValue rpv;
main_handler->get_rpv(operand->data.rpv.id, &rpv);
success = main_handler->get_rpv_read_callback()(rpv, val);
success = main_handler->get_rpv_read_callback()(rpv, val, caller);
*variable_type = rpv.type;
}
else if (operand->type == OperandType::VAR)
Expand Down
13 changes: 6 additions & 7 deletions lib/src/scrutiny_loop_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace scrutiny
m_main2loop_msg.clear();
m_loop2main_msg.clear();
#if SCRUTINY_ENABLE_DATALOGGING
m_owns_datalogger = false;
m_datalogger_data_acquired = false;
m_datalogger = main_handler->datalogger();
#else
Expand All @@ -42,27 +41,27 @@ namespace scrutiny
{
#if SCRUTINY_ENABLE_DATALOGGING
case Main2LoopMessageID::TAKE_DATALOGGER_OWNERSHIP:
m_owns_datalogger = true;
m_datalogger->set_owner(this);
m_datalogger_data_acquired = false;
msg_out.message_id = Loop2MainMessageID::DATALOGGER_OWNERSHIP_TAKEN;
m_loop2main_msg.send(msg_out);
break;
case Main2LoopMessageID::DATALOGGER_ARM_TRIGGER:
if (m_owns_datalogger)
if (owns_datalogger())
{
m_datalogger->arm_trigger();
}
break;
case Main2LoopMessageID::DATALOGGER_DISARM_TRIGGER:
if (m_owns_datalogger)
if (owns_datalogger())
{
m_datalogger->disarm_trigger();
}
break;
case Main2LoopMessageID::RELEASE_DATALOGGER_OWNERSHIP:
if (m_owns_datalogger)
if (owns_datalogger())
{
m_owns_datalogger = false;
m_datalogger->set_owner(SCRUTINY_NULL);
msg_out.message_id = Loop2MainMessageID::DATALOGGER_OWNERSHIP_RELEASED;
m_loop2main_msg.send(msg_out);
}
Expand All @@ -74,7 +73,7 @@ namespace scrutiny
}

#if SCRUTINY_ENABLE_DATALOGGING
if (m_owns_datalogger)
if (owns_datalogger())
{
m_datalogger->process();

Expand Down
17 changes: 11 additions & 6 deletions lib/src/scrutiny_main_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,15 @@ namespace scrutiny
// No owner, can read directly. Otherwise will be updated by an IPC message
m_datalogging.threadsafe_data.datalogger_state = m_datalogging.datalogger.get_state();

if (m_datalogging.new_owner != SCRUTINY_NULL)
if (m_datalogging.new_owner != SCRUTINY_NULL) // We need to give ownership to someone else
{
if (!m_datalogging.new_owner->ipc_main2loop()->has_content())
if (!m_datalogging.new_owner->ipc_main2loop()->has_content()) // If there is room to send a msg
{
// Ask the wanted new owner to take ownership
LoopHandler::Main2LoopMessage msg;
msg.message_id = LoopHandler::Main2LoopMessageID::TAKE_DATALOGGER_OWNERSHIP;
m_datalogging.new_owner->ipc_main2loop()->send(msg);
m_datalogging.new_owner = SCRUTINY_NULL;
m_datalogging.new_owner = SCRUTINY_NULL; //
}
}

Expand All @@ -349,7 +350,7 @@ namespace scrutiny
}
else
{
if (!m_datalogging.owner->ipc_main2loop()->has_content())
if (!m_datalogging.owner->ipc_main2loop()->has_content()) // If there is room to send a msg
{
LoopHandler::Main2LoopMessage msg;
if (m_datalogging.request_ownership_release)
Expand All @@ -371,6 +372,10 @@ namespace scrutiny
m_datalogging.owner->ipc_main2loop()->send(msg);
m_datalogging.request_disarm_trigger = false;
}
else
{
// No message to send, do nothing
}
}
}
}
Expand Down Expand Up @@ -1185,7 +1190,7 @@ namespace scrutiny
break;
}

bool const callback_success = m_config.get_rpv_read_callback()(stack.read_rpv.rpv, &stack.read_rpv.v);
bool const callback_success = m_config.get_rpv_read_callback()(stack.read_rpv.rpv, &stack.read_rpv.v, SCRUTINY_NULL);
if (!callback_success)
{
code = protocol::ResponseCode::FailureToProceed;
Expand Down Expand Up @@ -1237,7 +1242,7 @@ namespace scrutiny
continue;
}

bool const write_success = m_config.get_rpv_write_callback()(stack.write_rpv.rpv, &stack.write_rpv.v);
bool const write_success = m_config.get_rpv_write_callback()(stack.write_rpv.rpv, &stack.write_rpv.v, SCRUTINY_NULL);
if (!write_success)
{
code = protocol::ResponseCode::FailureToProceed;
Expand Down
6 changes: 4 additions & 2 deletions projects/c_testapp/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ struct
#endif
} rpvStorage;

int TestAppRPVReadCallback(const scrutiny_c_runtime_published_value_t rpv, scrutiny_c_any_type_t *outval)
int TestAppRPVReadCallback(const scrutiny_c_runtime_published_value_t rpv, scrutiny_c_any_type_t *outval, scrutiny_c_loop_handler_t* const caller)
{
(void)caller;
int ok = 1;
if (rpv.id == 0x1000)
{
Expand Down Expand Up @@ -166,8 +167,9 @@ int TestAppRPVReadCallback(const scrutiny_c_runtime_published_value_t rpv, scrut
return ok;
}

int TestAppRPVWriteCallback(const scrutiny_c_runtime_published_value_t rpv, const scrutiny_c_any_type_t *inval)
int TestAppRPVWriteCallback(const scrutiny_c_runtime_published_value_t rpv, const scrutiny_c_any_type_t *inval, scrutiny_c_loop_handler_t* const caller)
{
(void) caller;
int ok = 1;
if (rpv.id == 0x1000)
{
Expand Down
6 changes: 4 additions & 2 deletions projects/testapp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ struct
#endif
} rpvStorage;

bool TestAppRPVReadCallback(const scrutiny::RuntimePublishedValue rpv, scrutiny::AnyType *outval)
bool TestAppRPVReadCallback(const scrutiny::RuntimePublishedValue rpv, scrutiny::AnyType *outval, scrutiny::LoopHandler *const caller)
{
static_cast<void>(caller);
bool ok = true;
if (rpv.id == 0x1000)
{
Expand Down Expand Up @@ -175,8 +176,9 @@ bool TestAppRPVReadCallback(const scrutiny::RuntimePublishedValue rpv, scrutiny:
return ok;
}

bool TestAppRPVWriteCallback(const scrutiny::RuntimePublishedValue rpv, scrutiny::AnyType const *inval)
bool TestAppRPVWriteCallback(const scrutiny::RuntimePublishedValue rpv, scrutiny::AnyType const *inval, scrutiny::LoopHandler *const caller)
{
static_cast<void>(caller);
bool ok = true;
if (rpv.id == 0x1000)
{
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(FetchContent)
FetchContent_Declare(
scrutinytest
GIT_REPOSITORY https://github.com/scrutinydebugger/scrutiny-test-framework
GIT_TAG 2420737a511a073d021e73b7651e7731b8960b89
GIT_TAG 52110794f54e2c6a7c8026523b23f3f396b1ea44
)

set(SCRUTINYTEST_DISABLE_EXCEPTIONS OFF)
Expand Down
3 changes: 2 additions & 1 deletion test/commands/test_datalog_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

using namespace scrutiny;

static bool rpv_read_callback(RuntimePublishedValue rpv, AnyType *outval)
static bool rpv_read_callback(RuntimePublishedValue rpv, AnyType *outval, LoopHandler *const caller)
{
static_cast<void>(caller);
if (rpv.id == 0x8888 && rpv.type == VariableType::float32)
{
outval->float32 = 1.7f;
Expand Down
Loading