Working on experimental features

This commit is contained in:
Martino Ferrari
2026-03-24 21:16:24 +01:00
parent 7adbecdb6e
commit e2f47d7410
12 changed files with 2029 additions and 2157 deletions
@@ -1,9 +1,11 @@
#ifndef DEBUGBROKERWRAPPER_H
#define DEBUGBROKERWRAPPER_H
#include "AdvancedErrorManagement.h"
#include "BrokerI.h"
#include "DataSourceI.h"
#include "DebugService.h"
#include "ErrorType.h"
#include "FastPollingMutexSem.h"
#include "HighResolutionTimer.h"
#include "MemoryMapBroker.h"
@@ -23,6 +25,7 @@
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
#include "MemoryMapSynchronisedOutputBroker.h"
#include "RealTimeThreadSynchBroker.h"
namespace MARTe {
@@ -86,12 +89,11 @@ public:
StreamString dsPath;
DebugService::GetFullObjectName(dataSourceIn, dsPath);
fprintf(stderr, ">> %s broker for %s [%d]\n",
direction == InputSignals ? "Input" : "Output", dsPath.Buffer(),
numCopies);
MemoryMapBroker *mmb = dynamic_cast<MemoryMapBroker *>(broker);
if (mmb == NULL_PTR(MemoryMapBroker *)) {
fprintf(stderr, ">> Impossible to get broker pointer!!\n");
REPORT_ERROR_STATIC(ErrorManagement::Warning,
"Impossible to get broker pointer for %s!!\n",
dsPath.Buffer());
}
for (uint32 i = 0; i < numCopies; i++) {
@@ -106,8 +108,8 @@ public:
StreamString signalName;
if (!dataSourceIn.GetSignalName(dsIdx, signalName))
signalName = "Unknown";
fprintf(stderr, ">> registering %s.%s [%p]\n", dsPath.Buffer(),
signalName.Buffer(), mmb);
REPORT_ERROR_STATIC(ErrorManagement::Debug, "Registering %s.%s [%p]\n",
dsPath.Buffer(), signalName.Buffer(), mmb);
uint8 dims = 0;
uint32 elems = 1;
@@ -148,18 +150,18 @@ public:
// Register short path (In/Out) for GUI compatibility
gamFullName.Printf("%s.%s.%s", absGamPath.Buffer(), dirStrShort,
signalName.Buffer());
signalInfoPointers[i] =
service->RegisterSignal(addr, type, gamFullName.Buffer(), dims, elems);
signalInfoPointers[i] = service->RegisterSignal(
addr, type, gamFullName.Buffer(), dims, elems);
} else {
// Fallback to short form
gamFullName.Printf("%s.%s.%s", functionName, dirStrShort,
signalName.Buffer());
signalInfoPointers[i] =
service->RegisterSignal(addr, type, gamFullName.Buffer(), dims, elems);
signalInfoPointers[i] = service->RegisterSignal(
addr, type, gamFullName.Buffer(), dims, elems);
}
} else {
signalInfoPointers[i] =
service->RegisterSignal(addr, type, dsFullName.Buffer(), dims, elems);
signalInfoPointers[i] = service->RegisterSignal(
addr, type, dsFullName.Buffer(), dims, elems);
}
}
@@ -199,8 +201,8 @@ public:
virtual bool Init(SignalDirection direction, DataSourceI &ds,
const char8 *const name, void *gamMem) {
bool ret = BaseClass::Init(direction, ds, name, gamMem);
fprintf(stderr, ">> INIT BROKER %s %s\n", name,
direction == InputSignals ? "In" : "Out");
REPORT_ERROR_STATIC(ErrorManagement::Debug, "INIT BROKER %s %s\n", name,
direction == InputSignals ? "In" : "Out");
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers,
@@ -214,8 +216,8 @@ public:
virtual bool Init(SignalDirection direction, DataSourceI &ds,
const char8 *const name, void *gamMem, const bool optim) {
bool ret = BaseClass::Init(direction, ds, name, gamMem, false);
fprintf(stderr, ">> INIT optimized BROKER %s %s\n", name,
direction == InputSignals ? "In" : "Out");
REPORT_ERROR_STATIC(ErrorManagement::Debug, "INIT optimized BROKER %s %s\n",
name, direction == InputSignals ? "In" : "Out");
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers,
@@ -403,6 +405,55 @@ typedef DebugBrokerWrapper<MemoryMapSynchronisedMultiBufferOutputBroker>
DebugMemoryMapSynchronisedMultiBufferOutputBroker;
// LCOV_EXCL_STOP
/**
* @brief Specialized wrapper for RealTimeThreadSynchBroker.
* @details The RealTimeThreadSynchBroker copies data in AddSample() which is
* called from the DataSource thread, not from Execute(). We trace signals
* in Execute() after the data has been safely copied.
*/
class DebugRealTimeThreadSyncBroker : public RealTimeThreadSynchBroker {
public:
DebugRealTimeThreadSyncBroker() : RealTimeThreadSynchBroker() {
service = NULL_PTR(DebugService *);
signalInfoPointers = NULL_PTR(DebugSignalInfo **);
numSignals = 0;
anyActive = false;
}
virtual ~DebugRealTimeThreadSyncBroker() {
if (signalInfoPointers)
delete[] signalInfoPointers;
}
virtual bool Execute() {
bool ret = RealTimeThreadSynchBroker::Execute();
// Trace after data has been safely copied by AddSample
if (ret && (anyActive || (service && service->IsPaused()))) {
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices,
activeSizes, activeMutex);
}
return ret;
}
virtual bool Init(SignalDirection direction, DataSourceI &ds,
const char8 *const name, void *gamMem) {
bool ret = RealTimeThreadSynchBroker::Init(direction, ds, name, gamMem);
if (ret) {
numSignals = this->GetNumberOfCopies();
DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers,
numSignals, this->copyTable, name,
direction, &anyActive, &activeIndices,
&activeSizes, &activeMutex);
}
return ret;
}
DebugService *service;
DebugSignalInfo **signalInfoPointers;
uint32 numSignals;
volatile bool anyActive;
Vec<uint32> activeIndices;
Vec<uint32> activeSizes;
FastPollingMutexSem activeMutex;
};
// LCOV_EXCL_START
typedef DebugBrokerBuilder<DebugMemoryMapInputBroker>
DebugMemoryMapInputBrokerBuilder;
// LCOV_EXCL_START
@@ -426,6 +477,8 @@ typedef DebugBrokerBuilder<DebugMemoryMapAsyncOutputBroker>
DebugMemoryMapAsyncOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugMemoryMapAsyncTriggerOutputBroker>
DebugMemoryMapAsyncTriggerOutputBrokerBuilder;
typedef DebugBrokerBuilder<DebugRealTimeThreadSyncBroker>
DebugRealTimeThreadSyncBrokerBuilder;
// LCOV_EXCL_STOP
} // namespace MARTe