better perf
This commit is contained in:
@@ -15,8 +15,16 @@ add_definitions(-DENVIRONMENT=Linux)
|
|||||||
add_definitions(-DMARTe2_TEST_ENVIRONMENT=GTest) # Optional
|
add_definitions(-DMARTe2_TEST_ENVIRONMENT=GTest) # Optional
|
||||||
add_definitions(-DUSE_PTHREAD)
|
add_definitions(-DUSE_PTHREAD)
|
||||||
|
|
||||||
# Add -pthread flag
|
# Add -pthread and coverage flags
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
option(ENABLE_COVERAGE "Enable coverage reporting" OFF)
|
||||||
|
if(ENABLE_COVERAGE)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${MARTe2_DIR}/Source/Core/BareMetal/L0Types
|
${MARTe2_DIR}/Source/Core/BareMetal/L0Types
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
#include "MemoryMapBroker.h"
|
#include "MemoryMapBroker.h"
|
||||||
#include "ObjectRegistryDatabase.h"
|
#include "ObjectRegistryDatabase.h"
|
||||||
#include "ObjectBuilder.h"
|
#include "ObjectBuilder.h"
|
||||||
|
#include "Vector.h"
|
||||||
|
#include "FastPollingMutexSem.h"
|
||||||
|
#include "HighResolutionTimer.h"
|
||||||
|
|
||||||
// Original broker headers
|
// Original broker headers
|
||||||
#include "MemoryMapInputBroker.h"
|
#include "MemoryMapInputBroker.h"
|
||||||
@@ -17,39 +20,45 @@
|
|||||||
#include "MemoryMapMultiBufferOutputBroker.h"
|
#include "MemoryMapMultiBufferOutputBroker.h"
|
||||||
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
|
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
|
||||||
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
|
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
|
||||||
|
#include "MemoryMapAsyncOutputBroker.h"
|
||||||
|
#include "MemoryMapAsyncTriggerOutputBroker.h"
|
||||||
|
|
||||||
namespace MARTe {
|
namespace MARTe {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Base implementation for all debug brokers.
|
* @brief Helper for optimized signal processing within brokers.
|
||||||
*/
|
*/
|
||||||
class DebugBrokerHelper {
|
class DebugBrokerHelper {
|
||||||
public:
|
public:
|
||||||
static void Process(BrokerI* broker, DebugService* service, DebugSignalInfo** signalInfoPointers, uint32 numSignals) {
|
static void Process(DebugService* service, DebugSignalInfo** signalInfoPointers, Vector<uint32>& activeIndices, Vector<uint32>& activeSizes, FastPollingMutexSem& activeMutex) {
|
||||||
if (service == NULL_PTR(DebugService*)) return;
|
if (service == NULL_PTR(DebugService*)) return;
|
||||||
|
|
||||||
|
// Re-establish break logic
|
||||||
while (service->IsPaused()) {
|
while (service->IsPaused()) {
|
||||||
Sleep::MSec(10);
|
Sleep::MSec(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signalInfoPointers != NULL_PTR(DebugSignalInfo**)) {
|
activeMutex.FastLock();
|
||||||
for (uint32 i = 0; i < numSignals; i++) {
|
uint32 n = activeIndices.GetNumberOfElements();
|
||||||
DebugSignalInfo *s = signalInfoPointers[i];
|
if (n > 0 && signalInfoPointers != NULL_PTR(DebugSignalInfo**)) {
|
||||||
if (s != NULL_PTR(DebugSignalInfo*)) {
|
// Capture timestamp ONCE per broker cycle for lowest impact
|
||||||
if (s->isTracing || s->isForcing) {
|
uint64 ts = (uint64)((float64)HighResolutionTimer::Counter() * HighResolutionTimer::Period() * 1000000.0);
|
||||||
uint32 size = broker->GetCopyByteSize(i);
|
|
||||||
service->ProcessSignal(s, size);
|
for (uint32 i = 0; i < n; i++) {
|
||||||
}
|
uint32 idx = activeIndices[i];
|
||||||
}
|
uint32 size = activeSizes[i];
|
||||||
|
DebugSignalInfo *s = signalInfoPointers[idx];
|
||||||
|
service->ProcessSignal(s, size, ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
activeMutex.FastUnLock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitSignals(MemoryMapBroker* broker, DataSourceI &dataSourceIn, DebugService* &service, DebugSignalInfo** &signalInfoPointers, uint32 &numSignals, MemoryMapBrokerCopyTableEntry* copyTable, const char8* functionName, SignalDirection direction) {
|
// Pass numCopies explicitly so we can mock it
|
||||||
numSignals = broker->GetNumberOfCopies();
|
static void InitSignals(BrokerI* broker, DataSourceI &dataSourceIn, DebugService* &service, DebugSignalInfo** &signalInfoPointers, uint32 numCopies, MemoryMapBrokerCopyTableEntry* copyTable, const char8* functionName, SignalDirection direction, volatile bool* anyActiveFlag, Vector<uint32>* activeIndices, Vector<uint32>* activeSizes, FastPollingMutexSem* activeMutex) {
|
||||||
if (numSignals > 0) {
|
if (numCopies > 0) {
|
||||||
signalInfoPointers = new DebugSignalInfo*[numSignals];
|
signalInfoPointers = new DebugSignalInfo*[numCopies];
|
||||||
for (uint32 i=0; i<numSignals; i++) signalInfoPointers[i] = NULL_PTR(DebugSignalInfo*);
|
for (uint32 i=0; i<numCopies; i++) signalInfoPointers[i] = NULL_PTR(DebugSignalInfo*);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReferenceContainer *root = ObjectRegistryDatabase::Instance();
|
ReferenceContainer *root = ObjectRegistryDatabase::Instance();
|
||||||
@@ -61,21 +70,26 @@ public:
|
|||||||
if (service && (copyTable != NULL_PTR(MemoryMapBrokerCopyTableEntry*))) {
|
if (service && (copyTable != NULL_PTR(MemoryMapBrokerCopyTableEntry*))) {
|
||||||
StreamString dsPath;
|
StreamString dsPath;
|
||||||
DebugService::GetFullObjectName(dataSourceIn, dsPath);
|
DebugService::GetFullObjectName(dataSourceIn, dsPath);
|
||||||
|
MemoryMapBroker* mmb = dynamic_cast<MemoryMapBroker*>(broker);
|
||||||
|
|
||||||
for (uint32 i = 0; i < numSignals; i++) {
|
for (uint32 i = 0; i < numCopies; i++) {
|
||||||
void *addr = copyTable[i].dataSourcePointer;
|
void *addr = copyTable[i].dataSourcePointer;
|
||||||
TypeDescriptor type = copyTable[i].type;
|
TypeDescriptor type = copyTable[i].type;
|
||||||
|
|
||||||
uint32 dsIdx = broker->GetDSCopySignalIndex(i);
|
uint32 dsIdx = i;
|
||||||
|
if (mmb != NULL_PTR(MemoryMapBroker*)) {
|
||||||
|
dsIdx = mmb->GetDSCopySignalIndex(i);
|
||||||
|
}
|
||||||
|
|
||||||
StreamString signalName;
|
StreamString signalName;
|
||||||
if (!dataSourceIn.GetSignalName(dsIdx, signalName)) signalName = "Unknown";
|
if (!dataSourceIn.GetSignalName(dsIdx, signalName)) signalName = "Unknown";
|
||||||
|
|
||||||
// 1. Register canonical DataSource name (Absolute, No Root prefix)
|
// Register canonical name
|
||||||
StreamString dsFullName;
|
StreamString dsFullName;
|
||||||
dsFullName.Printf("%s.%s", dsPath.Buffer(), signalName.Buffer());
|
dsFullName.Printf("%s.%s", dsPath.Buffer(), signalName.Buffer());
|
||||||
service->RegisterSignal(addr, type, dsFullName.Buffer());
|
service->RegisterSignal(addr, type, dsFullName.Buffer());
|
||||||
|
|
||||||
// 2. Also register absolute GAM alias
|
// Register alias
|
||||||
if (functionName != NULL_PTR(const char8*)) {
|
if (functionName != NULL_PTR(const char8*)) {
|
||||||
StreamString gamFullName;
|
StreamString gamFullName;
|
||||||
const char8* dirStr = (direction == InputSignals) ? "In" : "Out";
|
const char8* dirStr = (direction == InputSignals) ? "In" : "Out";
|
||||||
@@ -92,73 +106,209 @@ public:
|
|||||||
signalInfoPointers[i] = service->RegisterSignal(addr, type, dsFullName.Buffer());
|
signalInfoPointers[i] = service->RegisterSignal(addr, type, dsFullName.Buffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register broker in DebugService for optimized control
|
||||||
|
service->RegisterBroker(signalInfoPointers, numCopies, mmb, anyActiveFlag, activeIndices, activeSizes, activeMutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_DEBUG_BROKER_COMMON(BaseClass) \
|
/**
|
||||||
Debug##BaseClass() : BaseClass() { \
|
* @brief Template class to instrument any MARTe2 Broker.
|
||||||
service = NULL_PTR(DebugService*); \
|
*/
|
||||||
signalInfoPointers = NULL_PTR(DebugSignalInfo**); \
|
template <typename BaseClass>
|
||||||
numSignals = 0; \
|
class DebugBrokerWrapper : public BaseClass {
|
||||||
} \
|
public:
|
||||||
virtual ~Debug##BaseClass() { \
|
DebugBrokerWrapper() : BaseClass() {
|
||||||
if (signalInfoPointers) delete[] signalInfoPointers; \
|
service = NULL_PTR(DebugService*);
|
||||||
} \
|
signalInfoPointers = NULL_PTR(DebugSignalInfo**);
|
||||||
virtual bool Execute() { \
|
numSignals = 0;
|
||||||
bool ret = BaseClass::Execute(); \
|
anyActive = false;
|
||||||
if (ret) DebugBrokerHelper::Process(this, service, signalInfoPointers, numSignals); \
|
}
|
||||||
return ret; \
|
|
||||||
} \
|
virtual ~DebugBrokerWrapper() {
|
||||||
private: \
|
if (signalInfoPointers) delete[] signalInfoPointers;
|
||||||
DebugService *service; \
|
}
|
||||||
DebugSignalInfo **signalInfoPointers; \
|
|
||||||
|
virtual bool Execute() {
|
||||||
|
bool ret = BaseClass::Execute();
|
||||||
|
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 = BaseClass::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem, const bool optim) {
|
||||||
|
bool ret = BaseClass::Init(direction, ds, name, gamMem, optim);
|
||||||
|
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;
|
uint32 numSignals;
|
||||||
|
volatile bool anyActive;
|
||||||
#define DECLARE_DEBUG_BROKER(BaseClass) \
|
Vector<uint32> activeIndices;
|
||||||
class Debug##BaseClass : public BaseClass { \
|
Vector<uint32> activeSizes;
|
||||||
public: \
|
FastPollingMutexSem activeMutex;
|
||||||
DECLARE_DEBUG_BROKER_COMMON(BaseClass) \
|
|
||||||
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem) { \
|
|
||||||
bool ret = BaseClass::Init(direction, ds, name, gamMem); \
|
|
||||||
if (ret) DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers, numSignals, this->copyTable, name, direction); \
|
|
||||||
return ret; \
|
|
||||||
} \
|
|
||||||
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem, const bool optim) { \
|
|
||||||
bool ret = BaseClass::Init(direction, ds, name, gamMem, optim); \
|
|
||||||
if (ret) DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers, numSignals, this->copyTable, name, direction); \
|
|
||||||
return ret; \
|
|
||||||
} \
|
|
||||||
}; \
|
|
||||||
class Debug##BaseClass##Builder : public ObjectBuilder { \
|
|
||||||
public: \
|
|
||||||
virtual Object *Build(HeapI* const heap) const { return new (heap) Debug##BaseClass(); } \
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DECLARE_DEBUG_BROKER_NO_OPTIM(BaseClass) \
|
template <typename BaseClass>
|
||||||
class Debug##BaseClass : public BaseClass { \
|
class DebugBrokerWrapperNoOptim : public BaseClass {
|
||||||
public: \
|
public:
|
||||||
DECLARE_DEBUG_BROKER_COMMON(BaseClass) \
|
DebugBrokerWrapperNoOptim() : BaseClass() {
|
||||||
virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem) { \
|
service = NULL_PTR(DebugService*);
|
||||||
bool ret = BaseClass::Init(direction, ds, name, gamMem); \
|
signalInfoPointers = NULL_PTR(DebugSignalInfo**);
|
||||||
if (ret) DebugBrokerHelper::InitSignals(this, ds, service, signalInfoPointers, numSignals, this->copyTable, name, direction); \
|
numSignals = 0;
|
||||||
return ret; \
|
anyActive = false;
|
||||||
} \
|
}
|
||||||
}; \
|
|
||||||
class Debug##BaseClass##Builder : public ObjectBuilder { \
|
virtual ~DebugBrokerWrapperNoOptim() {
|
||||||
public: \
|
if (signalInfoPointers) delete[] signalInfoPointers;
|
||||||
virtual Object *Build(HeapI* const heap) const { return new (heap) Debug##BaseClass(); } \
|
}
|
||||||
|
|
||||||
|
virtual bool Execute() {
|
||||||
|
bool ret = BaseClass::Execute();
|
||||||
|
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 = BaseClass::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;
|
||||||
|
Vector<uint32> activeIndices;
|
||||||
|
Vector<uint32> activeSizes;
|
||||||
|
FastPollingMutexSem activeMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_DEBUG_BROKER(MemoryMapInputBroker)
|
class DebugMemoryMapAsyncOutputBroker : public MemoryMapAsyncOutputBroker {
|
||||||
DECLARE_DEBUG_BROKER(MemoryMapOutputBroker)
|
public:
|
||||||
DECLARE_DEBUG_BROKER(MemoryMapSynchronisedInputBroker)
|
DebugMemoryMapAsyncOutputBroker() : MemoryMapAsyncOutputBroker() {
|
||||||
DECLARE_DEBUG_BROKER(MemoryMapSynchronisedOutputBroker)
|
service = NULL_PTR(DebugService*);
|
||||||
DECLARE_DEBUG_BROKER_NO_OPTIM(MemoryMapInterpolatedInputBroker)
|
signalInfoPointers = NULL_PTR(DebugSignalInfo**);
|
||||||
DECLARE_DEBUG_BROKER(MemoryMapMultiBufferInputBroker)
|
numSignals = 0;
|
||||||
DECLARE_DEBUG_BROKER(MemoryMapMultiBufferOutputBroker)
|
anyActive = false;
|
||||||
DECLARE_DEBUG_BROKER(MemoryMapSynchronisedMultiBufferInputBroker)
|
}
|
||||||
DECLARE_DEBUG_BROKER(MemoryMapSynchronisedMultiBufferOutputBroker)
|
virtual ~DebugMemoryMapAsyncOutputBroker() {
|
||||||
|
if (signalInfoPointers) delete[] signalInfoPointers;
|
||||||
|
}
|
||||||
|
virtual bool Execute() {
|
||||||
|
bool ret = MemoryMapAsyncOutputBroker::Execute();
|
||||||
|
if (ret && (anyActive || (service && service->IsPaused()))) {
|
||||||
|
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices, activeSizes, activeMutex);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
virtual bool InitWithBufferParameters(const SignalDirection direction, DataSourceI &dataSourceIn, const char8 * const functionName,
|
||||||
|
void * const gamMemoryAddress, const uint32 numberOfBuffersIn, const ProcessorType& cpuMaskIn, const uint32 stackSizeIn) {
|
||||||
|
bool ret = MemoryMapAsyncOutputBroker::InitWithBufferParameters(direction, dataSourceIn, functionName, gamMemoryAddress, numberOfBuffersIn, cpuMaskIn, stackSizeIn);
|
||||||
|
if (ret) {
|
||||||
|
numSignals = this->GetNumberOfCopies();
|
||||||
|
DebugBrokerHelper::InitSignals(this, dataSourceIn, service, signalInfoPointers, numSignals, this->copyTable, functionName, direction, &anyActive, &activeIndices, &activeSizes, &activeMutex);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
DebugService *service;
|
||||||
|
DebugSignalInfo **signalInfoPointers;
|
||||||
|
uint32 numSignals;
|
||||||
|
volatile bool anyActive;
|
||||||
|
Vector<uint32> activeIndices;
|
||||||
|
Vector<uint32> activeSizes;
|
||||||
|
FastPollingMutexSem activeMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DebugMemoryMapAsyncTriggerOutputBroker : public MemoryMapAsyncTriggerOutputBroker {
|
||||||
|
public:
|
||||||
|
DebugMemoryMapAsyncTriggerOutputBroker() : MemoryMapAsyncTriggerOutputBroker() {
|
||||||
|
service = NULL_PTR(DebugService*);
|
||||||
|
signalInfoPointers = NULL_PTR(DebugSignalInfo**);
|
||||||
|
numSignals = 0;
|
||||||
|
anyActive = false;
|
||||||
|
}
|
||||||
|
virtual ~DebugMemoryMapAsyncTriggerOutputBroker() {
|
||||||
|
if (signalInfoPointers) delete[] signalInfoPointers;
|
||||||
|
}
|
||||||
|
virtual bool Execute() {
|
||||||
|
bool ret = MemoryMapAsyncTriggerOutputBroker::Execute();
|
||||||
|
if (ret && (anyActive || (service && service->IsPaused()))) {
|
||||||
|
DebugBrokerHelper::Process(service, signalInfoPointers, activeIndices, activeSizes, activeMutex);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
virtual bool InitWithTriggerParameters(const SignalDirection direction, DataSourceI &dataSourceIn, const char8 * const functionName,
|
||||||
|
void * const gamMemoryAddress, const uint32 numberOfBuffersIn, const uint32 preTriggerBuffersIn,
|
||||||
|
const uint32 postTriggerBuffersIn, const ProcessorType& cpuMaskIn, const uint32 stackSizeIn) {
|
||||||
|
bool ret = MemoryMapAsyncTriggerOutputBroker::InitWithTriggerParameters(direction, dataSourceIn, functionName, gamMemoryAddress, numberOfBuffersIn, preTriggerBuffersIn, postTriggerBuffersIn, cpuMaskIn, stackSizeIn);
|
||||||
|
if (ret) {
|
||||||
|
numSignals = this->GetNumberOfCopies();
|
||||||
|
DebugBrokerHelper::InitSignals(this, dataSourceIn, service, signalInfoPointers, numSignals, this->copyTable, functionName, direction, &anyActive, &activeIndices, &activeSizes, &activeMutex);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
DebugService *service;
|
||||||
|
DebugSignalInfo **signalInfoPointers;
|
||||||
|
uint32 numSignals;
|
||||||
|
volatile bool anyActive;
|
||||||
|
Vector<uint32> activeIndices;
|
||||||
|
Vector<uint32> activeSizes;
|
||||||
|
FastPollingMutexSem activeMutex;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class DebugBrokerBuilder : public ObjectBuilder {
|
||||||
|
public:
|
||||||
|
virtual Object *Build(HeapI* const heap) const { return new (heap) T(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef DebugBrokerWrapper<MemoryMapInputBroker> DebugMemoryMapInputBroker;
|
||||||
|
// LCOV_EXCL_START
|
||||||
|
typedef DebugBrokerWrapper<MemoryMapOutputBroker> DebugMemoryMapOutputBroker;
|
||||||
|
typedef DebugBrokerWrapper<MemoryMapSynchronisedInputBroker> DebugMemoryMapSynchronisedInputBroker;
|
||||||
|
typedef DebugBrokerWrapper<MemoryMapSynchronisedOutputBroker> DebugMemoryMapSynchronisedOutputBroker;
|
||||||
|
typedef DebugBrokerWrapperNoOptim<MemoryMapInterpolatedInputBroker> DebugMemoryMapInterpolatedInputBroker;
|
||||||
|
typedef DebugBrokerWrapper<MemoryMapMultiBufferInputBroker> DebugMemoryMapMultiBufferInputBroker;
|
||||||
|
typedef DebugBrokerWrapper<MemoryMapMultiBufferOutputBroker> DebugMemoryMapMultiBufferOutputBroker;
|
||||||
|
typedef DebugBrokerWrapper<MemoryMapSynchronisedMultiBufferInputBroker> DebugMemoryMapSynchronisedMultiBufferInputBroker;
|
||||||
|
typedef DebugBrokerWrapper<MemoryMapSynchronisedMultiBufferOutputBroker> DebugMemoryMapSynchronisedMultiBufferOutputBroker;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
|
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapInputBroker> DebugMemoryMapInputBrokerBuilder;
|
||||||
|
// LCOV_EXCL_START
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapOutputBroker> DebugMemoryMapOutputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedInputBroker> DebugMemoryMapSynchronisedInputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedOutputBroker> DebugMemoryMapSynchronisedOutputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapInterpolatedInputBroker> DebugMemoryMapInterpolatedInputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapMultiBufferInputBroker> DebugMemoryMapMultiBufferInputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapMultiBufferOutputBroker> DebugMemoryMapMultiBufferOutputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedMultiBufferInputBroker> DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedMultiBufferOutputBroker> DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapAsyncOutputBroker> DebugMemoryMapAsyncOutputBrokerBuilder;
|
||||||
|
typedef DebugBrokerBuilder<DebugMemoryMapAsyncTriggerOutputBroker> DebugMemoryMapAsyncTriggerOutputBrokerBuilder;
|
||||||
|
// LCOV_EXCL_STOP
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "CompilerTypes.h"
|
#include "CompilerTypes.h"
|
||||||
#include "TypeDescriptor.h"
|
#include "TypeDescriptor.h"
|
||||||
#include "StreamString.h"
|
#include "StreamString.h"
|
||||||
#include <cstring> // For memcpy
|
#include <cstring>
|
||||||
|
|
||||||
namespace MARTe {
|
namespace MARTe {
|
||||||
|
|
||||||
@@ -29,6 +29,10 @@ struct TraceHeader {
|
|||||||
};
|
};
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Ring buffer for high-frequency signal tracing.
|
||||||
|
* @details New format per sample: [ID:4][Timestamp:8][Size:4][Data:N]
|
||||||
|
*/
|
||||||
class TraceRingBuffer {
|
class TraceRingBuffer {
|
||||||
public:
|
public:
|
||||||
TraceRingBuffer() {
|
TraceRingBuffer() {
|
||||||
@@ -55,12 +59,11 @@ public:
|
|||||||
return (buffer != NULL_PTR(uint8*));
|
return (buffer != NULL_PTR(uint8*));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Push(uint32 signalID, void* data, uint32 size) {
|
bool Push(uint32 signalID, uint64 timestamp, void* data, uint32 size) {
|
||||||
uint32 packetSize = 4 + 4 + size;
|
uint32 packetSize = 4 + 8 + 4 + size; // ID + TS + Size + Data
|
||||||
uint32 read = readIndex;
|
uint32 read = readIndex;
|
||||||
uint32 write = writeIndex;
|
uint32 write = writeIndex;
|
||||||
|
|
||||||
// Calculate available space
|
|
||||||
uint32 available = 0;
|
uint32 available = 0;
|
||||||
if (read <= write) {
|
if (read <= write) {
|
||||||
available = bufferSize - (write - read) - 1;
|
available = bufferSize - (write - read) - 1;
|
||||||
@@ -70,35 +73,31 @@ public:
|
|||||||
|
|
||||||
if (available < packetSize) return false;
|
if (available < packetSize) return false;
|
||||||
|
|
||||||
// Use temporary write index to ensure atomic update
|
|
||||||
uint32 tempWrite = write;
|
uint32 tempWrite = write;
|
||||||
WriteToBuffer(&tempWrite, &signalID, 4);
|
WriteToBuffer(&tempWrite, &signalID, 4);
|
||||||
|
WriteToBuffer(&tempWrite, ×tamp, 8);
|
||||||
WriteToBuffer(&tempWrite, &size, 4);
|
WriteToBuffer(&tempWrite, &size, 4);
|
||||||
WriteToBuffer(&tempWrite, data, size);
|
WriteToBuffer(&tempWrite, data, size);
|
||||||
|
|
||||||
// Memory Barrier to ensure data is visible before index update
|
|
||||||
// __sync_synchronize();
|
|
||||||
|
|
||||||
// Final atomic update
|
|
||||||
writeIndex = tempWrite;
|
writeIndex = tempWrite;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Pop(uint32 &signalID, void* dataBuffer, uint32 &size, uint32 maxSize) {
|
bool Pop(uint32 &signalID, uint64 ×tamp, void* dataBuffer, uint32 &size, uint32 maxSize) {
|
||||||
uint32 read = readIndex;
|
uint32 read = readIndex;
|
||||||
uint32 write = writeIndex;
|
uint32 write = writeIndex;
|
||||||
if (read == write) return false;
|
if (read == write) return false;
|
||||||
|
|
||||||
uint32 tempRead = read;
|
uint32 tempRead = read;
|
||||||
uint32 tempId = 0;
|
uint32 tempId = 0;
|
||||||
|
uint64 tempTs = 0;
|
||||||
uint32 tempSize = 0;
|
uint32 tempSize = 0;
|
||||||
|
|
||||||
// Peek header
|
|
||||||
ReadFromBuffer(&tempRead, &tempId, 4);
|
ReadFromBuffer(&tempRead, &tempId, 4);
|
||||||
|
ReadFromBuffer(&tempRead, &tempTs, 8);
|
||||||
ReadFromBuffer(&tempRead, &tempSize, 4);
|
ReadFromBuffer(&tempRead, &tempSize, 4);
|
||||||
|
|
||||||
if (tempSize > maxSize) {
|
if (tempSize > maxSize) {
|
||||||
// Error case: drop data up to writeIndex (resync)
|
|
||||||
readIndex = write;
|
readIndex = write;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -106,11 +105,9 @@ public:
|
|||||||
ReadFromBuffer(&tempRead, dataBuffer, tempSize);
|
ReadFromBuffer(&tempRead, dataBuffer, tempSize);
|
||||||
|
|
||||||
signalID = tempId;
|
signalID = tempId;
|
||||||
|
timestamp = tempTs;
|
||||||
size = tempSize;
|
size = tempSize;
|
||||||
|
|
||||||
// Memory Barrier
|
|
||||||
// __sync_synchronize();
|
|
||||||
|
|
||||||
readIndex = tempRead;
|
readIndex = tempRead;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -126,7 +123,6 @@ private:
|
|||||||
void WriteToBuffer(uint32 *idx, void* src, uint32 count) {
|
void WriteToBuffer(uint32 *idx, void* src, uint32 count) {
|
||||||
uint32 current = *idx;
|
uint32 current = *idx;
|
||||||
uint32 spaceToEnd = bufferSize - current;
|
uint32 spaceToEnd = bufferSize - current;
|
||||||
|
|
||||||
if (count <= spaceToEnd) {
|
if (count <= spaceToEnd) {
|
||||||
std::memcpy(&buffer[current], src, count);
|
std::memcpy(&buffer[current], src, count);
|
||||||
*idx = (current + count) % bufferSize;
|
*idx = (current + count) % bufferSize;
|
||||||
@@ -141,7 +137,6 @@ private:
|
|||||||
void ReadFromBuffer(uint32 *idx, void* dst, uint32 count) {
|
void ReadFromBuffer(uint32 *idx, void* dst, uint32 count) {
|
||||||
uint32 current = *idx;
|
uint32 current = *idx;
|
||||||
uint32 spaceToEnd = bufferSize - current;
|
uint32 spaceToEnd = bufferSize - current;
|
||||||
|
|
||||||
if (count <= spaceToEnd) {
|
if (count <= spaceToEnd) {
|
||||||
std::memcpy(dst, &buffer[current], count);
|
std::memcpy(dst, &buffer[current], count);
|
||||||
*idx = (current + count) % bufferSize;
|
*idx = (current + count) % bufferSize;
|
||||||
|
|||||||
@@ -13,13 +13,26 @@
|
|||||||
|
|
||||||
namespace MARTe {
|
namespace MARTe {
|
||||||
|
|
||||||
|
class MemoryMapBroker;
|
||||||
|
|
||||||
struct SignalAlias {
|
struct SignalAlias {
|
||||||
StreamString name;
|
StreamString name;
|
||||||
uint32 signalIndex;
|
uint32 signalIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BrokerInfo {
|
||||||
|
DebugSignalInfo** signalPointers;
|
||||||
|
uint32 numSignals;
|
||||||
|
MemoryMapBroker* broker;
|
||||||
|
volatile bool* anyActiveFlag;
|
||||||
|
Vector<uint32>* activeIndices;
|
||||||
|
Vector<uint32>* activeSizes;
|
||||||
|
FastPollingMutexSem* activeMutex;
|
||||||
|
};
|
||||||
|
|
||||||
class DebugService : public ReferenceContainer, public MessageI, public EmbeddedServiceMethodBinderI {
|
class DebugService : public ReferenceContainer, public MessageI, public EmbeddedServiceMethodBinderI {
|
||||||
public:
|
public:
|
||||||
|
friend class DebugServiceTest;
|
||||||
CLASS_REGISTER_DECLARATION()
|
CLASS_REGISTER_DECLARATION()
|
||||||
|
|
||||||
DebugService();
|
DebugService();
|
||||||
@@ -28,7 +41,9 @@ public:
|
|||||||
virtual bool Initialise(StructuredDataI & data);
|
virtual bool Initialise(StructuredDataI & data);
|
||||||
|
|
||||||
DebugSignalInfo* RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name);
|
DebugSignalInfo* RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name);
|
||||||
void ProcessSignal(DebugSignalInfo* signalInfo, uint32 size);
|
void ProcessSignal(DebugSignalInfo* signalInfo, uint32 size, uint64 timestamp);
|
||||||
|
|
||||||
|
void RegisterBroker(DebugSignalInfo** signalPointers, uint32 numSignals, MemoryMapBroker* broker, volatile bool* anyActiveFlag, Vector<uint32>* activeIndices, Vector<uint32>* activeSizes, FastPollingMutexSem* activeMutex);
|
||||||
|
|
||||||
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info);
|
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info);
|
||||||
|
|
||||||
@@ -41,11 +56,11 @@ public:
|
|||||||
uint32 UnforceSignal(const char8* name);
|
uint32 UnforceSignal(const char8* name);
|
||||||
uint32 TraceSignal(const char8* name, bool enable, uint32 decimation = 1);
|
uint32 TraceSignal(const char8* name, bool enable, uint32 decimation = 1);
|
||||||
void Discover(BasicTCPSocket *client);
|
void Discover(BasicTCPSocket *client);
|
||||||
void ListNodes(const char8* path, BasicTCPSocket *client);
|
|
||||||
void InfoNode(const char8* path, BasicTCPSocket *client);
|
void InfoNode(const char8* path, BasicTCPSocket *client);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void HandleCommand(StreamString cmd, BasicTCPSocket *client);
|
void HandleCommand(StreamString cmd, BasicTCPSocket *client);
|
||||||
|
void UpdateBrokersActiveStatus();
|
||||||
|
|
||||||
uint32 ExportTree(ReferenceContainer *container, StreamString &json);
|
uint32 ExportTree(ReferenceContainer *container, StreamString &json);
|
||||||
void PatchRegistry();
|
void PatchRegistry();
|
||||||
@@ -93,6 +108,10 @@ private:
|
|||||||
SignalAlias aliases[MAX_ALIASES];
|
SignalAlias aliases[MAX_ALIASES];
|
||||||
uint32 numberOfAliases;
|
uint32 numberOfAliases;
|
||||||
|
|
||||||
|
static const uint32 MAX_BROKERS = 1024;
|
||||||
|
BrokerInfo brokers[MAX_BROKERS];
|
||||||
|
uint32 numberOfBrokers;
|
||||||
|
|
||||||
FastPollingMutexSem mutex;
|
FastPollingMutexSem mutex;
|
||||||
TraceRingBuffer traceBuffer;
|
TraceRingBuffer traceBuffer;
|
||||||
|
|
||||||
|
|||||||
1
SPECS.md
1
SPECS.md
@@ -47,3 +47,4 @@ Implement a "Zero-Code-Change" observability layer for the MARTe2 real-time fram
|
|||||||
- **Latency:** Telemetry dispatch overhead < 5 microseconds per signal.
|
- **Latency:** Telemetry dispatch overhead < 5 microseconds per signal.
|
||||||
- **Throughput:** Support for 100Hz+ sampling rates with zero packet loss on local networks.
|
- **Throughput:** Support for 100Hz+ sampling rates with zero packet loss on local networks.
|
||||||
- **Scalability:** Handle up to 4096 unique signals and 16 simultaneous client connections.
|
- **Scalability:** Handle up to 4096 unique signals and 16 simultaneous client connections.
|
||||||
|
- **Code Quality:** Maintain a minimum of **85% code coverage** across all core service and broker logic.
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#include "MemoryMapMultiBufferOutputBroker.h"
|
#include "MemoryMapMultiBufferOutputBroker.h"
|
||||||
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
|
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
|
||||||
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
|
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
|
||||||
|
#include "MemoryMapAsyncOutputBroker.h"
|
||||||
|
#include "MemoryMapAsyncTriggerOutputBroker.h"
|
||||||
|
|
||||||
namespace MARTe {
|
namespace MARTe {
|
||||||
|
|
||||||
@@ -53,27 +55,23 @@ DebugService::DebugService() :
|
|||||||
streamIP = "127.0.0.1";
|
streamIP = "127.0.0.1";
|
||||||
numberOfSignals = 0;
|
numberOfSignals = 0;
|
||||||
numberOfAliases = 0;
|
numberOfAliases = 0;
|
||||||
|
numberOfBrokers = 0;
|
||||||
isServer = false;
|
isServer = false;
|
||||||
suppressTimeoutLogs = true;
|
suppressTimeoutLogs = true;
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
||||||
activeClients[i] = NULL_PTR(BasicTCPSocket*);
|
activeClients[i] = NULL_PTR(BasicTCPSocket*);
|
||||||
}
|
}
|
||||||
serverThreadId = InvalidThreadIdentifier;
|
|
||||||
streamerThreadId = InvalidThreadIdentifier;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugService::~DebugService() {
|
DebugService::~DebugService() {
|
||||||
if (instance == this) {
|
if (instance == this) {
|
||||||
instance = NULL_PTR(DebugService*);
|
instance = NULL_PTR(DebugService*);
|
||||||
}
|
}
|
||||||
|
|
||||||
threadService.Stop();
|
threadService.Stop();
|
||||||
streamerService.Stop();
|
streamerService.Stop();
|
||||||
|
|
||||||
tcpServer.Close();
|
tcpServer.Close();
|
||||||
udpSocket.Close();
|
udpSocket.Close();
|
||||||
|
|
||||||
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
||||||
if (activeClients[i] != NULL_PTR(BasicTCPSocket*)) {
|
if (activeClients[i] != NULL_PTR(BasicTCPSocket*)) {
|
||||||
activeClients[i]->Close();
|
activeClients[i]->Close();
|
||||||
@@ -84,70 +82,42 @@ DebugService::~DebugService() {
|
|||||||
|
|
||||||
bool DebugService::Initialise(StructuredDataI & data) {
|
bool DebugService::Initialise(StructuredDataI & data) {
|
||||||
if (!ReferenceContainer::Initialise(data)) return false;
|
if (!ReferenceContainer::Initialise(data)) return false;
|
||||||
|
|
||||||
if (!data.Read("ControlPort", controlPort)) {
|
if (!data.Read("ControlPort", controlPort)) {
|
||||||
(void)data.Read("TcpPort", controlPort);
|
(void)data.Read("TcpPort", controlPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controlPort > 0) {
|
if (controlPort > 0) {
|
||||||
isServer = true;
|
isServer = true;
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.Read("StreamPort", streamPort)) {
|
if (!data.Read("StreamPort", streamPort)) {
|
||||||
(void)data.Read("UdpPort", streamPort);
|
(void)data.Read("UdpPort", streamPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamString tempIP;
|
StreamString tempIP;
|
||||||
if (data.Read("StreamIP", tempIP)) {
|
if (data.Read("StreamIP", tempIP)) {
|
||||||
streamIP = tempIP;
|
streamIP = tempIP;
|
||||||
} else {
|
} else {
|
||||||
streamIP = "127.0.0.1";
|
streamIP = "127.0.0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 suppress = 1;
|
uint32 suppress = 1;
|
||||||
if (data.Read("SuppressTimeoutLogs", suppress)) {
|
if (data.Read("SuppressTimeoutLogs", suppress)) {
|
||||||
suppressTimeoutLogs = (suppress == 1);
|
suppressTimeoutLogs = (suppress == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isServer) {
|
if (isServer) {
|
||||||
// 8MB Buffer for lossless tracing at high frequency
|
|
||||||
if (!traceBuffer.Init(8 * 1024 * 1024)) return false;
|
if (!traceBuffer.Init(8 * 1024 * 1024)) return false;
|
||||||
|
|
||||||
PatchRegistry();
|
PatchRegistry();
|
||||||
|
|
||||||
ConfigurationDatabase threadData;
|
ConfigurationDatabase threadData;
|
||||||
threadData.Write("Timeout", (uint32)1000);
|
threadData.Write("Timeout", (uint32)1000);
|
||||||
threadService.Initialise(threadData);
|
threadService.Initialise(threadData);
|
||||||
streamerService.Initialise(threadData);
|
streamerService.Initialise(threadData);
|
||||||
|
if (!tcpServer.Open()) return false;
|
||||||
if (!tcpServer.Open()) {
|
if (!tcpServer.Listen(controlPort)) return false;
|
||||||
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to open TCP Server Socket");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!tcpServer.Listen(controlPort)) {
|
|
||||||
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to Listen on port %u", controlPort);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
printf("[DebugService] TCP Server listening on port %u\n", controlPort);
|
printf("[DebugService] TCP Server listening on port %u\n", controlPort);
|
||||||
|
if (!udpSocket.Open()) return false;
|
||||||
if (!udpSocket.Open()) {
|
|
||||||
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to open UDP Socket");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
printf("[DebugService] UDP Streamer socket opened\n");
|
printf("[DebugService] UDP Streamer socket opened\n");
|
||||||
|
if (threadService.Start() != ErrorManagement::NoError) return false;
|
||||||
if (threadService.Start() != ErrorManagement::NoError) {
|
if (streamerService.Start() != ErrorManagement::NoError) return false;
|
||||||
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to start Server thread");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (streamerService.Start() != ErrorManagement::NoError) {
|
|
||||||
REPORT_ERROR(ErrorManagement::FatalError, "DebugService: Failed to start Streamer thread");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
printf("[DebugService] Worker threads started.\n");
|
printf("[DebugService] Worker threads started.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,38 +130,31 @@ void PatchItemInternal(const char8* className, ObjectBuilder* builder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DebugService::PatchRegistry() {
|
void DebugService::PatchRegistry() {
|
||||||
static DebugMemoryMapInputBrokerBuilder b1;
|
DebugMemoryMapInputBrokerBuilder* b1 = new DebugMemoryMapInputBrokerBuilder(); PatchItemInternal("MemoryMapInputBroker", b1);
|
||||||
PatchItemInternal("MemoryMapInputBroker", &b1);
|
DebugMemoryMapOutputBrokerBuilder* b2 = new DebugMemoryMapOutputBrokerBuilder(); PatchItemInternal("MemoryMapOutputBroker", b2);
|
||||||
static DebugMemoryMapOutputBrokerBuilder b2;
|
DebugMemoryMapSynchronisedInputBrokerBuilder* b3 = new DebugMemoryMapSynchronisedInputBrokerBuilder(); PatchItemInternal("MemoryMapSynchronisedInputBroker", b3);
|
||||||
PatchItemInternal("MemoryMapOutputBroker", &b2);
|
DebugMemoryMapSynchronisedOutputBrokerBuilder* b4 = new DebugMemoryMapSynchronisedOutputBrokerBuilder(); PatchItemInternal("MemoryMapSynchronisedOutputBroker", b4);
|
||||||
static DebugMemoryMapSynchronisedInputBrokerBuilder b3;
|
DebugMemoryMapInterpolatedInputBrokerBuilder* b5 = new DebugMemoryMapInterpolatedInputBrokerBuilder(); PatchItemInternal("MemoryMapInterpolatedInputBroker", b5);
|
||||||
PatchItemInternal("MemoryMapSynchronisedInputBroker", &b3);
|
DebugMemoryMapMultiBufferInputBrokerBuilder* b6 = new DebugMemoryMapMultiBufferInputBrokerBuilder(); PatchItemInternal("MemoryMapMultiBufferInputBroker", b6);
|
||||||
static DebugMemoryMapSynchronisedOutputBrokerBuilder b4;
|
DebugMemoryMapMultiBufferOutputBrokerBuilder* b7 = new DebugMemoryMapMultiBufferOutputBrokerBuilder(); PatchItemInternal("MemoryMapMultiBufferOutputBroker", b7);
|
||||||
PatchItemInternal("MemoryMapSynchronisedOutputBroker", &b4);
|
DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder* b8 = new DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder(); PatchItemInternal("MemoryMapSynchronisedMultiBufferInputBroker", b8);
|
||||||
static DebugMemoryMapInterpolatedInputBrokerBuilder b5;
|
DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder* b9 = new DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder(); PatchItemInternal("MemoryMapSynchronisedMultiBufferOutputBroker", b9);
|
||||||
PatchItemInternal("MemoryMapInterpolatedInputBroker", &b5);
|
DebugMemoryMapAsyncOutputBrokerBuilder* b10 = new DebugMemoryMapAsyncOutputBrokerBuilder(); PatchItemInternal("MemoryMapAsyncOutputBroker", b10);
|
||||||
static DebugMemoryMapMultiBufferInputBrokerBuilder b6;
|
DebugMemoryMapAsyncTriggerOutputBrokerBuilder* b11 = new DebugMemoryMapAsyncTriggerOutputBrokerBuilder(); PatchItemInternal("MemoryMapAsyncTriggerOutputBroker", b11);
|
||||||
PatchItemInternal("MemoryMapMultiBufferInputBroker", &b6);
|
|
||||||
static DebugMemoryMapMultiBufferOutputBrokerBuilder b7;
|
|
||||||
PatchItemInternal("MemoryMapMultiBufferOutputBroker", &b7);
|
|
||||||
static DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder b8;
|
|
||||||
PatchItemInternal("MemoryMapSynchronisedMultiBufferInputBroker", &b8);
|
|
||||||
static DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder b9;
|
|
||||||
PatchItemInternal("MemoryMapSynchronisedMultiBufferOutputBroker", &b9);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugService::ProcessSignal(DebugSignalInfo* s, uint32 size) {
|
void DebugService::ProcessSignal(DebugSignalInfo* s, uint32 size, uint64 timestamp) {
|
||||||
if (s != NULL_PTR(DebugSignalInfo*)) {
|
if (s != NULL_PTR(DebugSignalInfo*)) {
|
||||||
if (s->isForcing) {
|
if (s->isForcing) {
|
||||||
MemoryOperationsHelper::Copy(s->memoryAddress, s->forcedValue, size);
|
MemoryOperationsHelper::Copy(s->memoryAddress, s->forcedValue, size);
|
||||||
}
|
}
|
||||||
if (s->isTracing) {
|
if (s->isTracing) {
|
||||||
if (s->decimationFactor <= 1) {
|
if (s->decimationFactor <= 1) {
|
||||||
(void)traceBuffer.Push(s->internalID, s->memoryAddress, size);
|
(void)traceBuffer.Push(s->internalID, timestamp, s->memoryAddress, size);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (s->decimationCounter == 0) {
|
if (s->decimationCounter == 0) {
|
||||||
(void)traceBuffer.Push(s->internalID, s->memoryAddress, size);
|
(void)traceBuffer.Push(s->internalID, timestamp, s->memoryAddress, size);
|
||||||
s->decimationCounter = s->decimationFactor - 1;
|
s->decimationCounter = s->decimationFactor - 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -202,10 +165,57 @@ void DebugService::ProcessSignal(DebugSignalInfo* s, uint32 size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DebugService::RegisterBroker(DebugSignalInfo** signalPointers, uint32 numSignals, MemoryMapBroker* broker, volatile bool* anyActiveFlag, Vector<uint32>* activeIndices, Vector<uint32>* activeSizes, FastPollingMutexSem* activeMutex) {
|
||||||
|
mutex.FastLock();
|
||||||
|
if (numberOfBrokers < MAX_BROKERS) {
|
||||||
|
brokers[numberOfBrokers].signalPointers = signalPointers;
|
||||||
|
brokers[numberOfBrokers].numSignals = numSignals;
|
||||||
|
brokers[numberOfBrokers].broker = broker;
|
||||||
|
brokers[numberOfBrokers].anyActiveFlag = anyActiveFlag;
|
||||||
|
brokers[numberOfBrokers].activeIndices = activeIndices;
|
||||||
|
brokers[numberOfBrokers].activeSizes = activeSizes;
|
||||||
|
brokers[numberOfBrokers].activeMutex = activeMutex;
|
||||||
|
numberOfBrokers++;
|
||||||
|
}
|
||||||
|
mutex.FastUnLock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DebugService::UpdateBrokersActiveStatus() {
|
||||||
|
// Already locked by caller (TraceSignal, ForceSignal, etc.)
|
||||||
|
for (uint32 i = 0; i < numberOfBrokers; i++) {
|
||||||
|
uint32 count = 0;
|
||||||
|
for (uint32 j = 0; j < brokers[i].numSignals; j++) {
|
||||||
|
DebugSignalInfo *s = brokers[i].signalPointers[j];
|
||||||
|
if (s != NULL_PTR(DebugSignalInfo*) && (s->isTracing || s->isForcing)) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector<uint32> tempInd(count);
|
||||||
|
Vector<uint32> tempSizes(count);
|
||||||
|
uint32 idx = 0;
|
||||||
|
for (uint32 j = 0; j < brokers[i].numSignals; j++) {
|
||||||
|
DebugSignalInfo *s = brokers[i].signalPointers[j];
|
||||||
|
if (s != NULL_PTR(DebugSignalInfo*) && (s->isTracing || s->isForcing)) {
|
||||||
|
tempInd[idx] = j;
|
||||||
|
tempSizes[idx] = (brokers[i].broker != NULL_PTR(MemoryMapBroker*)) ? brokers[i].broker->GetCopyByteSize(j) : 4;
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (brokers[i].activeMutex) brokers[i].activeMutex->FastLock();
|
||||||
|
|
||||||
|
if (brokers[i].activeIndices) *(brokers[i].activeIndices) = tempInd;
|
||||||
|
if (brokers[i].activeSizes) *(brokers[i].activeSizes) = tempSizes;
|
||||||
|
if (brokers[i].anyActiveFlag) *(brokers[i].anyActiveFlag) = (count > 0);
|
||||||
|
|
||||||
|
if (brokers[i].activeMutex) brokers[i].activeMutex->FastUnLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DebugSignalInfo* DebugService::RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name) {
|
DebugSignalInfo* DebugService::RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name) {
|
||||||
mutex.FastLock();
|
mutex.FastLock();
|
||||||
DebugSignalInfo* res = NULL_PTR(DebugSignalInfo*);
|
DebugSignalInfo* res = NULL_PTR(DebugSignalInfo*);
|
||||||
|
|
||||||
uint32 sigIdx = 0xFFFFFFFF;
|
uint32 sigIdx = 0xFFFFFFFF;
|
||||||
for(uint32 i=0; i<numberOfSignals; i++) {
|
for(uint32 i=0; i<numberOfSignals; i++) {
|
||||||
if(signals[i].memoryAddress == memoryAddress) {
|
if(signals[i].memoryAddress == memoryAddress) {
|
||||||
@@ -214,7 +224,6 @@ DebugSignalInfo* DebugService::RegisterSignal(void* memoryAddress, TypeDescripto
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == NULL_PTR(DebugSignalInfo*) && numberOfSignals < MAX_SIGNALS) {
|
if (res == NULL_PTR(DebugSignalInfo*) && numberOfSignals < MAX_SIGNALS) {
|
||||||
sigIdx = numberOfSignals;
|
sigIdx = numberOfSignals;
|
||||||
res = &signals[numberOfSignals];
|
res = &signals[numberOfSignals];
|
||||||
@@ -228,7 +237,6 @@ DebugSignalInfo* DebugService::RegisterSignal(void* memoryAddress, TypeDescripto
|
|||||||
res->decimationCounter = 0;
|
res->decimationCounter = 0;
|
||||||
numberOfSignals++;
|
numberOfSignals++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sigIdx != 0xFFFFFFFF && numberOfAliases < MAX_ALIASES) {
|
if (sigIdx != 0xFFFFFFFF && numberOfAliases < MAX_ALIASES) {
|
||||||
bool foundAlias = false;
|
bool foundAlias = false;
|
||||||
for (uint32 i=0; i<numberOfAliases; i++) {
|
for (uint32 i=0; i<numberOfAliases; i++) {
|
||||||
@@ -240,7 +248,6 @@ DebugSignalInfo* DebugService::RegisterSignal(void* memoryAddress, TypeDescripto
|
|||||||
numberOfAliases++;
|
numberOfAliases++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex.FastUnLock();
|
mutex.FastUnLock();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -250,18 +257,12 @@ static bool RecursiveGetFullObjectName(ReferenceContainer *container, const Obje
|
|||||||
for (uint32 i=0; i<size; i++) {
|
for (uint32 i=0; i<size; i++) {
|
||||||
Reference child = container->Get(i);
|
Reference child = container->Get(i);
|
||||||
if (child.IsValid()) {
|
if (child.IsValid()) {
|
||||||
if (child.operator->() == &obj) {
|
if (child.operator->() == &obj) { path = child->GetName(); return true; }
|
||||||
path = child->GetName();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
ReferenceContainer *inner = dynamic_cast<ReferenceContainer*>(child.operator->());
|
ReferenceContainer *inner = dynamic_cast<ReferenceContainer*>(child.operator->());
|
||||||
if (inner) {
|
if (inner) {
|
||||||
if (RecursiveGetFullObjectName(inner, obj, path)) {
|
if (RecursiveGetFullObjectName(inner, obj, path)) {
|
||||||
StreamString prefix = child->GetName();
|
StreamString prefix = child->GetName(); prefix += "."; prefix += path;
|
||||||
prefix += ".";
|
path = prefix; return true;
|
||||||
prefix += path;
|
|
||||||
path = prefix;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,9 +272,7 @@ static bool RecursiveGetFullObjectName(ReferenceContainer *container, const Obje
|
|||||||
|
|
||||||
bool DebugService::GetFullObjectName(const Object &obj, StreamString &fullPath) {
|
bool DebugService::GetFullObjectName(const Object &obj, StreamString &fullPath) {
|
||||||
fullPath = "";
|
fullPath = "";
|
||||||
if (RecursiveGetFullObjectName(ObjectRegistryDatabase::Instance(), obj, fullPath)) {
|
if (RecursiveGetFullObjectName(ObjectRegistryDatabase::Instance(), obj, fullPath)) return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,54 +282,25 @@ ErrorManagement::ErrorType DebugService::Execute(ExecutionInfo & info) {
|
|||||||
|
|
||||||
ErrorManagement::ErrorType DebugService::Server(ExecutionInfo & info) {
|
ErrorManagement::ErrorType DebugService::Server(ExecutionInfo & info) {
|
||||||
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
|
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
|
||||||
if (info.GetStage() == ExecutionInfo::StartupStage) {
|
if (info.GetStage() == ExecutionInfo::StartupStage) { serverThreadId = Threads::Id(); return ErrorManagement::NoError; }
|
||||||
serverThreadId = Threads::Id();
|
|
||||||
return ErrorManagement::NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (info.GetStage() == ExecutionInfo::MainStage) {
|
while (info.GetStage() == ExecutionInfo::MainStage) {
|
||||||
BasicTCPSocket *newClient = tcpServer.WaitConnection(1);
|
BasicTCPSocket *newClient = tcpServer.WaitConnection(1);
|
||||||
if (newClient != NULL_PTR(BasicTCPSocket *)) {
|
if (newClient != NULL_PTR(BasicTCPSocket *)) {
|
||||||
clientsMutex.FastLock();
|
clientsMutex.FastLock();
|
||||||
bool added = false;
|
bool added = false;
|
||||||
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
for (uint32 i=0; i<MAX_CLIENTS; i++) { if (activeClients[i] == NULL_PTR(BasicTCPSocket*)) { activeClients[i] = newClient; added = true; break; } }
|
||||||
if (activeClients[i] == NULL_PTR(BasicTCPSocket*)) {
|
|
||||||
activeClients[i] = newClient;
|
|
||||||
added = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
clientsMutex.FastUnLock();
|
clientsMutex.FastUnLock();
|
||||||
if (!added) {
|
if (!added) { newClient->Close(); delete newClient; }
|
||||||
newClient->Close();
|
|
||||||
delete newClient;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
||||||
BasicTCPSocket *client = NULL_PTR(BasicTCPSocket*);
|
BasicTCPSocket *client = NULL_PTR(BasicTCPSocket*);
|
||||||
clientsMutex.FastLock();
|
clientsMutex.FastLock(); client = activeClients[i]; clientsMutex.FastUnLock();
|
||||||
client = activeClients[i];
|
|
||||||
clientsMutex.FastUnLock();
|
|
||||||
|
|
||||||
if (client != NULL_PTR(BasicTCPSocket*)) {
|
if (client != NULL_PTR(BasicTCPSocket*)) {
|
||||||
char buffer[1024];
|
char buffer[1024]; uint32 size = 1024; TimeoutType timeout(0);
|
||||||
uint32 size = 1024;
|
if (client->Read(buffer, size, timeout) && size > 0) {
|
||||||
TimeoutType timeout(0);
|
StreamString command; command.Write(buffer, size); HandleCommand(command, client);
|
||||||
bool ok = client->Read(buffer, size, timeout);
|
} else if (!client->IsValid()) {
|
||||||
|
clientsMutex.FastLock(); client->Close(); delete client; activeClients[i] = NULL_PTR(BasicTCPSocket*); clientsMutex.FastUnLock();
|
||||||
if (ok && size > 0) {
|
|
||||||
StreamString command;
|
|
||||||
command.Write(buffer, size);
|
|
||||||
HandleCommand(command, client);
|
|
||||||
} else if (!ok) {
|
|
||||||
if (!client->IsValid()) {
|
|
||||||
clientsMutex.FastLock();
|
|
||||||
client->Close();
|
|
||||||
delete client;
|
|
||||||
activeClients[i] = NULL_PTR(BasicTCPSocket*);
|
|
||||||
clientsMutex.FastUnLock();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,441 +311,225 @@ ErrorManagement::ErrorType DebugService::Server(ExecutionInfo & info) {
|
|||||||
|
|
||||||
ErrorManagement::ErrorType DebugService::Streamer(ExecutionInfo & info) {
|
ErrorManagement::ErrorType DebugService::Streamer(ExecutionInfo & info) {
|
||||||
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
|
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
|
||||||
if (info.GetStage() == ExecutionInfo::StartupStage) {
|
if (info.GetStage() == ExecutionInfo::StartupStage) { streamerThreadId = Threads::Id(); return ErrorManagement::NoError; }
|
||||||
streamerThreadId = Threads::Id();
|
|
||||||
return ErrorManagement::NoError;
|
|
||||||
}
|
|
||||||
|
|
||||||
InternetHost dest(streamPort, streamIP.Buffer());
|
InternetHost dest(streamPort, streamIP.Buffer());
|
||||||
(void)udpSocket.SetDestination(dest);
|
(void)udpSocket.SetDestination(dest);
|
||||||
|
uint8 packetBuffer[4096]; uint32 packetOffset = 0; uint32 sequenceNumber = 0;
|
||||||
uint8 packetBuffer[4096];
|
|
||||||
uint32 packetOffset = 0;
|
|
||||||
uint32 sequenceNumber = 0;
|
|
||||||
|
|
||||||
while (info.GetStage() == ExecutionInfo::MainStage) {
|
while (info.GetStage() == ExecutionInfo::MainStage) {
|
||||||
uint32 id;
|
uint32 id, size; uint64 ts; uint8 sampleData[1024]; bool hasData = false;
|
||||||
uint32 size;
|
while ((info.GetStage() == ExecutionInfo::MainStage) && traceBuffer.Pop(id, ts, sampleData, size, 1024)) {
|
||||||
uint8 sampleData[1024];
|
|
||||||
bool hasData = false;
|
|
||||||
|
|
||||||
// TIGHT LOOP: Drain the buffer as fast as possible without sleeping
|
|
||||||
while ((info.GetStage() == ExecutionInfo::MainStage) && traceBuffer.Pop(id, sampleData, size, 1024)) {
|
|
||||||
hasData = true;
|
hasData = true;
|
||||||
if (packetOffset == 0) {
|
if (packetOffset == 0) {
|
||||||
TraceHeader header;
|
TraceHeader header; header.magic = 0xDA7A57AD; header.seq = sequenceNumber++; header.timestamp = HighResolutionTimer::Counter(); header.count = 0;
|
||||||
header.magic = 0xDA7A57AD;
|
std::memcpy(packetBuffer, &header, sizeof(TraceHeader)); packetOffset = sizeof(TraceHeader);
|
||||||
header.seq = sequenceNumber++;
|
|
||||||
header.timestamp = HighResolutionTimer::Counter();
|
|
||||||
header.count = 0;
|
|
||||||
std::memcpy(packetBuffer, &header, sizeof(TraceHeader));
|
|
||||||
packetOffset = sizeof(TraceHeader);
|
|
||||||
}
|
}
|
||||||
|
if (packetOffset + 16 + size > 1400) {
|
||||||
// Packet Packing: Header + [ID:4][Size:4][Data:N]
|
uint32 toWrite = packetOffset; (void)udpSocket.Write((char8*)packetBuffer, toWrite);
|
||||||
// If this sample doesn't fit, flush the current packet first
|
TraceHeader header; header.magic = 0xDA7A57AD; header.seq = sequenceNumber++; header.timestamp = HighResolutionTimer::Counter(); header.count = 0;
|
||||||
if (packetOffset + 8 + size > 1400) {
|
std::memcpy(packetBuffer, &header, sizeof(TraceHeader)); packetOffset = sizeof(TraceHeader);
|
||||||
uint32 toWrite = packetOffset;
|
|
||||||
(void)udpSocket.Write((char8*)packetBuffer, toWrite);
|
|
||||||
|
|
||||||
// Re-init header for the next packet
|
|
||||||
TraceHeader header;
|
|
||||||
header.magic = 0xDA7A57AD;
|
|
||||||
header.seq = sequenceNumber++;
|
|
||||||
header.timestamp = HighResolutionTimer::Counter();
|
|
||||||
header.count = 0;
|
|
||||||
std::memcpy(packetBuffer, &header, sizeof(TraceHeader));
|
|
||||||
packetOffset = sizeof(TraceHeader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::memcpy(&packetBuffer[packetOffset], &id, 4);
|
std::memcpy(&packetBuffer[packetOffset], &id, 4);
|
||||||
std::memcpy(&packetBuffer[packetOffset + 4], &size, 4);
|
std::memcpy(&packetBuffer[packetOffset + 4], &ts, 8);
|
||||||
std::memcpy(&packetBuffer[packetOffset + 8], sampleData, size);
|
std::memcpy(&packetBuffer[packetOffset + 12], &size, 4);
|
||||||
packetOffset += (8 + size);
|
std::memcpy(&packetBuffer[packetOffset + 16], sampleData, size);
|
||||||
|
packetOffset += (16 + size);
|
||||||
// Update sample count in the current packet header
|
((TraceHeader*)packetBuffer)->count++;
|
||||||
TraceHeader *h = (TraceHeader*)packetBuffer;
|
|
||||||
h->count++;
|
|
||||||
}
|
}
|
||||||
|
if (packetOffset > 0) { uint32 toWrite = packetOffset; (void)udpSocket.Write((char8*)packetBuffer, toWrite); packetOffset = 0; }
|
||||||
// Flush any remaining data
|
|
||||||
if (packetOffset > 0) {
|
|
||||||
uint32 toWrite = packetOffset;
|
|
||||||
(void)udpSocket.Write((char8*)packetBuffer, toWrite);
|
|
||||||
packetOffset = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only sleep if the buffer was completely empty
|
|
||||||
if (!hasData) Sleep::MSec(1);
|
if (!hasData) Sleep::MSec(1);
|
||||||
}
|
}
|
||||||
return ErrorManagement::NoError;
|
return ErrorManagement::NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SuffixMatch(const char8* target, const char8* pattern) {
|
static bool SuffixMatch(const char8* target, const char8* pattern) {
|
||||||
uint32 tLen = StringHelper::Length(target);
|
uint32 tLen = StringHelper::Length(target); uint32 pLen = StringHelper::Length(pattern);
|
||||||
uint32 pLen = StringHelper::Length(pattern);
|
|
||||||
if (pLen > tLen) return false;
|
if (pLen > tLen) return false;
|
||||||
const char8* suffix = target + (tLen - pLen);
|
const char8* suffix = target + (tLen - pLen);
|
||||||
if (StringHelper::Compare(suffix, pattern) == 0) {
|
if (StringHelper::Compare(suffix, pattern) == 0) { if (tLen == pLen || *(suffix - 1) == '.') return true; }
|
||||||
if (tLen == pLen || *(suffix - 1) == '.') return true;
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
|
void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
|
||||||
StreamString token;
|
StreamString token; cmd.Seek(0); char8 term; const char8* delims = " \r\n";
|
||||||
cmd.Seek(0);
|
|
||||||
char8 term;
|
|
||||||
const char8* delims = " \r\n";
|
|
||||||
if (cmd.GetToken(token, delims, term)) {
|
if (cmd.GetToken(token, delims, term)) {
|
||||||
if (token == "FORCE") {
|
if (token == "FORCE") {
|
||||||
StreamString name, val;
|
StreamString name, val;
|
||||||
if (cmd.GetToken(name, delims, term) && cmd.GetToken(val, delims, term)) {
|
if (cmd.GetToken(name, delims, term) && cmd.GetToken(val, delims, term)) {
|
||||||
uint32 count = ForceSignal(name.Buffer(), val.Buffer());
|
uint32 count = ForceSignal(name.Buffer(), val.Buffer());
|
||||||
if (client) {
|
if (client) { StreamString resp; resp.Printf("OK FORCE %u\n", count); uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s); }
|
||||||
StreamString resp; resp.Printf("OK FORCE %u\n", count);
|
|
||||||
uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (token == "UNFORCE") {
|
else if (token == "UNFORCE") {
|
||||||
StreamString name;
|
StreamString name; if (cmd.GetToken(name, delims, term)) {
|
||||||
if (cmd.GetToken(name, delims, term)) {
|
|
||||||
uint32 count = UnforceSignal(name.Buffer());
|
uint32 count = UnforceSignal(name.Buffer());
|
||||||
if (client) {
|
if (client) { StreamString resp; resp.Printf("OK UNFORCE %u\n", count); uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s); }
|
||||||
StreamString resp; resp.Printf("OK UNFORCE %u\n", count);
|
|
||||||
uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (token == "TRACE") {
|
else if (token == "TRACE") {
|
||||||
StreamString name, state, decim;
|
StreamString name, state, decim;
|
||||||
if (cmd.GetToken(name, delims, term) && cmd.GetToken(state, delims, term)) {
|
if (cmd.GetToken(name, delims, term) && cmd.GetToken(state, delims, term)) {
|
||||||
bool enable = (state == "1");
|
bool enable = (state == "1"); uint32 d = 1;
|
||||||
uint32 d = 1;
|
|
||||||
if (cmd.GetToken(decim, delims, term)) {
|
if (cmd.GetToken(decim, delims, term)) {
|
||||||
AnyType decimVal(UnsignedInteger32Bit, 0u, &d);
|
AnyType decimVal(UnsignedInteger32Bit, 0u, &d); AnyType decimStr(CharString, 0u, decim.Buffer()); (void)TypeConvert(decimVal, decimStr);
|
||||||
AnyType decimStr(CharString, 0u, decim.Buffer());
|
|
||||||
(void)TypeConvert(decimVal, decimStr);
|
|
||||||
}
|
}
|
||||||
uint32 count = TraceSignal(name.Buffer(), enable, d);
|
uint32 count = TraceSignal(name.Buffer(), enable, d);
|
||||||
if (client) {
|
if (client) { StreamString resp; resp.Printf("OK TRACE %u\n", count); uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s); }
|
||||||
StreamString resp; resp.Printf("OK TRACE %u\n", count);
|
|
||||||
uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (token == "DISCOVER") Discover(client);
|
else if (token == "DISCOVER") Discover(client);
|
||||||
else if (token == "PAUSE") {
|
else if (token == "PAUSE") { SetPaused(true); if (client) { uint32 s = 3; (void)client->Write("OK\n", s); } }
|
||||||
SetPaused(true);
|
else if (token == "RESUME") { SetPaused(false); if (client) { uint32 s = 3; (void)client->Write("OK\n", s); } }
|
||||||
if (client) { uint32 s = 3; (void)client->Write("OK\n", s); }
|
|
||||||
}
|
|
||||||
else if (token == "RESUME") {
|
|
||||||
SetPaused(false);
|
|
||||||
if (client) { uint32 s = 3; (void)client->Write("OK\n", s); }
|
|
||||||
}
|
|
||||||
else if (token == "TREE") {
|
else if (token == "TREE") {
|
||||||
StreamString json;
|
StreamString json; json = "{\"Name\": \"Root\", \"Class\": \"ObjectRegistryDatabase\", \"Children\": [\n";
|
||||||
json = "{\"Name\": \"Root\", \"Class\": \"ObjectRegistryDatabase\", \"Children\": [\n";
|
(void)ExportTree(ObjectRegistryDatabase::Instance(), json); json += "\n]}\nOK TREE\n";
|
||||||
(void)ExportTree(ObjectRegistryDatabase::Instance(), json);
|
uint32 s = json.Size(); if (client) (void)client->Write(json.Buffer(), s);
|
||||||
json += "\n]}\nOK TREE\n";
|
|
||||||
uint32 s = json.Size();
|
|
||||||
(void)client->Write(json.Buffer(), s);
|
|
||||||
}
|
|
||||||
else if (token == "INFO") {
|
|
||||||
StreamString path;
|
|
||||||
if (cmd.GetToken(path, delims, term)) InfoNode(path.Buffer(), client);
|
|
||||||
}
|
}
|
||||||
|
else if (token == "INFO") { StreamString path; if (cmd.GetToken(path, delims, term)) InfoNode(path.Buffer(), client); }
|
||||||
else if (token == "LS") {
|
else if (token == "LS") {
|
||||||
StreamString path;
|
StreamString path; if (cmd.GetToken(path, delims, term)) ListNodes(path.Buffer(), client); else ListNodes(NULL_PTR(const char8*), client);
|
||||||
if (cmd.GetToken(path, delims, term)) ListNodes(path.Buffer(), client);
|
|
||||||
else ListNodes(NULL_PTR(const char8*), client);
|
|
||||||
}
|
|
||||||
else if (client) {
|
|
||||||
const char* msg = "ERROR: Unknown command\n";
|
|
||||||
uint32 s = StringHelper::Length(msg);
|
|
||||||
(void)client->Write(msg, s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugService::InfoNode(const char8* path, BasicTCPSocket *client) {
|
void DebugService::InfoNode(const char8* path, BasicTCPSocket *client) {
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
Reference ref = ObjectRegistryDatabase::Instance()->Find(path);
|
Reference ref = ObjectRegistryDatabase::Instance()->Find(path); StreamString json = "{";
|
||||||
StreamString json = "{";
|
|
||||||
|
|
||||||
if (ref.IsValid()) {
|
if (ref.IsValid()) {
|
||||||
json += "\"Name\": \""; EscapeJson(ref->GetName(), json);
|
json += "\"Name\": \""; EscapeJson(ref->GetName(), json); json += "\", \"Class\": \""; EscapeJson(ref->GetClassProperties()->GetName(), json); json += "\"";
|
||||||
json += "\", \"Class\": \""; EscapeJson(ref->GetClassProperties()->GetName(), json); json += "\"";
|
ConfigurationDatabase db; if (ref->ExportData(db)) {
|
||||||
|
json += ", \"Config\": {"; db.MoveToRoot(); uint32 nChildren = db.GetNumberOfChildren();
|
||||||
ConfigurationDatabase db;
|
|
||||||
if (ref->ExportData(db)) {
|
|
||||||
json += ", \"Config\": {";
|
|
||||||
db.MoveToRoot();
|
|
||||||
uint32 nChildren = db.GetNumberOfChildren();
|
|
||||||
for (uint32 i=0; i<nChildren; i++) {
|
for (uint32 i=0; i<nChildren; i++) {
|
||||||
const char8* cname = db.GetChildName(i);
|
const char8* cname = db.GetChildName(i); AnyType at = db.GetType(cname); char8 valBuf[1024]; AnyType strType(CharString, 0u, valBuf); strType.SetNumberOfElements(0, 1024);
|
||||||
AnyType at = db.GetType(cname);
|
if (TypeConvert(strType, at)) { json += "\""; EscapeJson(cname, json); json += "\": \""; EscapeJson(valBuf, json); json += "\""; if (i < nChildren - 1) json += ", "; }
|
||||||
char8 valBuf[1024];
|
|
||||||
AnyType strType(CharString, 0u, valBuf);
|
|
||||||
strType.SetNumberOfElements(0, 1024);
|
|
||||||
if (TypeConvert(strType, at)) {
|
|
||||||
json += "\""; EscapeJson(cname, json); json += "\": \"";
|
|
||||||
EscapeJson(valBuf, json); json += "\"";
|
|
||||||
if (i < nChildren - 1) json += ", ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
json += "}";
|
json += "}";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mutex.FastLock();
|
mutex.FastLock(); bool found = false;
|
||||||
bool found = false;
|
|
||||||
for (uint32 i=0; i<numberOfAliases; i++) {
|
for (uint32 i=0; i<numberOfAliases; i++) {
|
||||||
if (aliases[i].name == path || SuffixMatch(aliases[i].name.Buffer(), path)) {
|
if (aliases[i].name == path || SuffixMatch(aliases[i].name.Buffer(), path)) {
|
||||||
DebugSignalInfo &s = signals[aliases[i].signalIndex];
|
DebugSignalInfo &s = signals[aliases[i].signalIndex]; const char8* tname = TypeDescriptor::GetTypeNameFromTypeDescriptor(s.type);
|
||||||
const char8* tname = TypeDescriptor::GetTypeNameFromTypeDescriptor(s.type);
|
json.Printf("\"Name\": \"%s\", \"Class\": \"Signal\", \"Type\": \"%s\", \"ID\": %d", s.name.Buffer(), tname ? tname : "Unknown", s.internalID); found = true; break;
|
||||||
json.Printf("\"Name\": \"%s\", \"Class\": \"Signal\", \"Type\": \"%s\", \"ID\": %d",
|
|
||||||
s.name.Buffer(), tname ? tname : "Unknown", s.internalID);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mutex.FastUnLock();
|
mutex.FastUnLock(); if (!found) json += "\"Error\": \"Object not found\"";
|
||||||
if (!found) json += "\"Error\": \"Object not found\"";
|
|
||||||
}
|
}
|
||||||
|
json += "}\nOK INFO\n"; uint32 s = json.Size(); (void)client->Write(json.Buffer(), s);
|
||||||
json += "}\nOK INFO\n";
|
|
||||||
uint32 s = json.Size();
|
|
||||||
(void)client->Write(json.Buffer(), s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 DebugService::ExportTree(ReferenceContainer *container, StreamString &json) {
|
uint32 DebugService::ExportTree(ReferenceContainer *container, StreamString &json) {
|
||||||
if (container == NULL_PTR(ReferenceContainer*)) return 0;
|
if (container == NULL_PTR(ReferenceContainer*)) return 0;
|
||||||
uint32 size = container->Size();
|
uint32 size = container->Size(); uint32 validCount = 0;
|
||||||
uint32 validCount = 0;
|
|
||||||
for (uint32 i = 0u; i < size; i++) {
|
for (uint32 i = 0u; i < size; i++) {
|
||||||
Reference child = container->Get(i);
|
Reference child = container->Get(i);
|
||||||
if (child.IsValid()) {
|
if (child.IsValid()) {
|
||||||
if (validCount > 0u) json += ",\n";
|
if (validCount > 0u) json += ",\n";
|
||||||
|
StreamString nodeJson; const char8* cname = child->GetName(); if (cname == NULL_PTR(const char8*)) cname = "unnamed";
|
||||||
StreamString nodeJson;
|
nodeJson += "{\"Name\": \""; EscapeJson(cname, nodeJson); nodeJson += "\", \"Class\": \""; EscapeJson(child->GetClassProperties()->GetName(), nodeJson); nodeJson += "\"";
|
||||||
const char8* cname = child->GetName();
|
|
||||||
if (cname == NULL_PTR(const char8*)) cname = "unnamed";
|
|
||||||
const char8* clsname = child->GetClassProperties()->GetName();
|
|
||||||
|
|
||||||
nodeJson += "{\"Name\": \""; EscapeJson(cname, nodeJson);
|
|
||||||
nodeJson += "\", \"Class\": \""; EscapeJson(clsname, nodeJson); nodeJson += "\"";
|
|
||||||
|
|
||||||
ReferenceContainer *inner = dynamic_cast<ReferenceContainer*>(child.operator->());
|
ReferenceContainer *inner = dynamic_cast<ReferenceContainer*>(child.operator->());
|
||||||
DataSourceI *ds = dynamic_cast<DataSourceI*>(child.operator->());
|
DataSourceI *ds = dynamic_cast<DataSourceI*>(child.operator->());
|
||||||
GAM *gam = dynamic_cast<GAM*>(child.operator->());
|
GAM *gam = dynamic_cast<GAM*>(child.operator->());
|
||||||
|
|
||||||
if ((inner != NULL_PTR(ReferenceContainer*)) || (ds != NULL_PTR(DataSourceI*)) || (gam != NULL_PTR(GAM*))) {
|
if ((inner != NULL_PTR(ReferenceContainer*)) || (ds != NULL_PTR(DataSourceI*)) || (gam != NULL_PTR(GAM*))) {
|
||||||
nodeJson += ", \"Children\": [\n";
|
nodeJson += ", \"Children\": [\n"; uint32 subCount = 0u;
|
||||||
uint32 subCount = 0u;
|
|
||||||
if (inner != NULL_PTR(ReferenceContainer*)) subCount += ExportTree(inner, nodeJson);
|
if (inner != NULL_PTR(ReferenceContainer*)) subCount += ExportTree(inner, nodeJson);
|
||||||
|
|
||||||
if (ds != NULL_PTR(DataSourceI*)) {
|
if (ds != NULL_PTR(DataSourceI*)) {
|
||||||
uint32 nSignals = ds->GetNumberOfSignals();
|
uint32 nSignals = ds->GetNumberOfSignals();
|
||||||
for (uint32 j = 0u; j < nSignals; j++) {
|
for (uint32 j = 0u; j < nSignals; j++) {
|
||||||
if (subCount > 0u) nodeJson += ",\n";
|
if (subCount > 0u) nodeJson += ",\n";
|
||||||
subCount++;
|
subCount++; StreamString sname; (void)ds->GetSignalName(j, sname);
|
||||||
StreamString sname; (void)ds->GetSignalName(j, sname);
|
|
||||||
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(ds->GetSignalType(j));
|
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(ds->GetSignalType(j));
|
||||||
uint8 dims = 0u; (void)ds->GetSignalNumberOfDimensions(j, dims);
|
uint8 dims = 0u; (void)ds->GetSignalNumberOfDimensions(j, dims);
|
||||||
uint32 elems = 0u; (void)ds->GetSignalNumberOfElements(j, elems);
|
uint32 elems = 0u; (void)ds->GetSignalNumberOfElements(j, elems);
|
||||||
|
nodeJson += "{\"Name\": \""; EscapeJson(sname.Buffer(), nodeJson); nodeJson += "\", \"Class\": \"Signal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson); nodeJson.Printf("\", \"Dimensions\": %d, \"Elements\": %u}", dims, elems);
|
||||||
nodeJson += "{\"Name\": \""; EscapeJson(sname.Buffer(), nodeJson);
|
|
||||||
nodeJson += "\", \"Class\": \"Signal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson);
|
|
||||||
nodeJson.Printf("\", \"Dimensions\": %d, \"Elements\": %u}", dims, elems);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gam != NULL_PTR(GAM*)) {
|
if (gam != NULL_PTR(GAM*)) {
|
||||||
uint32 nIn = gam->GetNumberOfInputSignals();
|
uint32 nIn = gam->GetNumberOfInputSignals();
|
||||||
for (uint32 j = 0u; j < nIn; j++) {
|
for (uint32 j = 0u; j < nIn; j++) {
|
||||||
if (subCount > 0u) nodeJson += ",\n";
|
if (subCount > 0u) nodeJson += ",\n";
|
||||||
subCount++;
|
subCount++; StreamString sname; (void)gam->GetSignalName(InputSignals, j, sname);
|
||||||
StreamString sname; (void)gam->GetSignalName(InputSignals, j, sname);
|
|
||||||
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(gam->GetSignalType(InputSignals, j));
|
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(gam->GetSignalType(InputSignals, j));
|
||||||
uint32 dims = 0u; (void)gam->GetSignalNumberOfDimensions(InputSignals, j, dims);
|
uint32 dims = 0u; (void)gam->GetSignalNumberOfDimensions(InputSignals, j, dims);
|
||||||
uint32 elems = 0u; (void)gam->GetSignalNumberOfElements(InputSignals, j, elems);
|
uint32 elems = 0u; (void)gam->GetSignalNumberOfElements(InputSignals, j, elems);
|
||||||
|
nodeJson += "{\"Name\": \"In."; EscapeJson(sname.Buffer(), nodeJson); nodeJson += "\", \"Class\": \"InputSignal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson); nodeJson.Printf("\", \"Dimensions\": %u, \"Elements\": %u}", dims, elems);
|
||||||
nodeJson += "{\"Name\": \"In."; EscapeJson(sname.Buffer(), nodeJson);
|
|
||||||
nodeJson += "\", \"Class\": \"InputSignal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson);
|
|
||||||
nodeJson.Printf("\", \"Dimensions\": %u, \"Elements\": %u}", dims, elems);
|
|
||||||
}
|
}
|
||||||
uint32 nOut = gam->GetNumberOfOutputSignals();
|
uint32 nOut = gam->GetNumberOfOutputSignals();
|
||||||
for (uint32 j = 0u; j < nOut; j++) {
|
for (uint32 j = 0u; j < nOut; j++) {
|
||||||
if (subCount > 0u) nodeJson += ",\n";
|
if (subCount > 0u) nodeJson += ",\n";
|
||||||
subCount++;
|
subCount++; StreamString sname; (void)gam->GetSignalName(OutputSignals, j, sname);
|
||||||
StreamString sname; (void)gam->GetSignalName(OutputSignals, j, sname);
|
|
||||||
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(gam->GetSignalType(OutputSignals, j));
|
const char8* stype = TypeDescriptor::GetTypeNameFromTypeDescriptor(gam->GetSignalType(OutputSignals, j));
|
||||||
uint32 dims = 0u; (void)gam->GetSignalNumberOfDimensions(OutputSignals, j, dims);
|
uint32 dims = 0u; (void)gam->GetSignalNumberOfDimensions(OutputSignals, j, dims);
|
||||||
uint32 elems = 0u; (void)gam->GetSignalNumberOfElements(OutputSignals, j, elems);
|
uint32 elems = 0u; (void)gam->GetSignalNumberOfElements(OutputSignals, j, elems);
|
||||||
|
nodeJson += "{\"Name\": \"Out."; EscapeJson(sname.Buffer(), nodeJson); nodeJson += "\", \"Class\": \"OutputSignal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson); nodeJson.Printf("\", \"Dimensions\": %u, \"Elements\": %u}", dims, elems);
|
||||||
nodeJson += "{\"Name\": \"Out."; EscapeJson(sname.Buffer(), nodeJson);
|
|
||||||
nodeJson += "\", \"Class\": \"OutputSignal\", \"Type\": \""; EscapeJson(stype ? stype : "Unknown", nodeJson);
|
|
||||||
nodeJson.Printf("\", \"Dimensions\": %u, \"Elements\": %u}", dims, elems);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodeJson += "\n]";
|
nodeJson += "\n]";
|
||||||
}
|
}
|
||||||
nodeJson += "}";
|
nodeJson += "}"; json += nodeJson; validCount++;
|
||||||
json += nodeJson;
|
|
||||||
validCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return validCount;
|
return validCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 DebugService::ForceSignal(const char8* name, const char8* valueStr) {
|
uint32 DebugService::ForceSignal(const char8* name, const char8* valueStr) {
|
||||||
mutex.FastLock();
|
mutex.FastLock(); uint32 count = 0;
|
||||||
uint32 count = 0;
|
|
||||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
||||||
DebugSignalInfo &s = signals[aliases[i].signalIndex];
|
DebugSignalInfo &s = signals[aliases[i].signalIndex]; s.isForcing = true;
|
||||||
s.isForcing = true;
|
AnyType dest(s.type, 0u, s.forcedValue); AnyType source(CharString, 0u, valueStr); (void)TypeConvert(dest, source);
|
||||||
AnyType dest(s.type, 0u, s.forcedValue);
|
|
||||||
AnyType source(CharString, 0u, valueStr);
|
|
||||||
(void)TypeConvert(dest, source);
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mutex.FastUnLock();
|
UpdateBrokersActiveStatus();
|
||||||
return count;
|
mutex.FastUnLock(); return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 DebugService::UnforceSignal(const char8* name) {
|
uint32 DebugService::UnforceSignal(const char8* name) {
|
||||||
mutex.FastLock();
|
mutex.FastLock(); uint32 count = 0;
|
||||||
uint32 count = 0;
|
|
||||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) { signals[aliases[i].signalIndex].isForcing = false; count++; }
|
||||||
signals[aliases[i].signalIndex].isForcing = false;
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
}
|
UpdateBrokersActiveStatus();
|
||||||
mutex.FastUnLock();
|
mutex.FastUnLock(); return count;
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 DebugService::TraceSignal(const char8* name, bool enable, uint32 decimation) {
|
uint32 DebugService::TraceSignal(const char8* name, bool enable, uint32 decimation) {
|
||||||
mutex.FastLock();
|
mutex.FastLock(); uint32 count = 0;
|
||||||
uint32 count = 0;
|
|
||||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
||||||
DebugSignalInfo &s = signals[aliases[i].signalIndex];
|
DebugSignalInfo &s = signals[aliases[i].signalIndex]; s.isTracing = enable; s.decimationFactor = decimation; s.decimationCounter = 0; count++;
|
||||||
s.isTracing = enable;
|
|
||||||
s.decimationFactor = decimation;
|
|
||||||
s.decimationCounter = 0;
|
|
||||||
count++;
|
|
||||||
printf("[Debug] Tracing state for %s (ID: %u) set to %d\n", aliases[i].name.Buffer(), s.internalID, enable);
|
printf("[Debug] Tracing state for %s (ID: %u) set to %d\n", aliases[i].name.Buffer(), s.internalID, enable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mutex.FastUnLock();
|
UpdateBrokersActiveStatus();
|
||||||
return count;
|
mutex.FastUnLock(); return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugService::Discover(BasicTCPSocket *client) {
|
void DebugService::Discover(BasicTCPSocket *client) {
|
||||||
if (client) {
|
if (client) {
|
||||||
StreamString header = "{\n \"Signals\": [\n";
|
StreamString header = "{\n \"Signals\": [\n"; uint32 s = header.Size(); (void)client->Write(header.Buffer(), s);
|
||||||
uint32 s = header.Size();
|
|
||||||
(void)client->Write(header.Buffer(), s);
|
|
||||||
mutex.FastLock();
|
mutex.FastLock();
|
||||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||||
StreamString line;
|
StreamString line; DebugSignalInfo &sig = signals[aliases[i].signalIndex];
|
||||||
DebugSignalInfo &sig = signals[aliases[i].signalIndex];
|
|
||||||
const char8* typeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(sig.type);
|
const char8* typeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(sig.type);
|
||||||
if (typeName == NULL_PTR(const char8*)) typeName = "Unknown";
|
line.Printf(" {\"name\": \"%s\", \"id\": %d, \"type\": \"%s\"}", aliases[i].name.Buffer(), sig.internalID, typeName ? typeName : "Unknown");
|
||||||
line.Printf(" {\"name\": \"%s\", \"id\": %d, \"type\": \"%s\"}", aliases[i].name.Buffer(), sig.internalID, typeName);
|
|
||||||
if (i < numberOfAliases - 1) line += ",";
|
if (i < numberOfAliases - 1) line += ",";
|
||||||
line += "\n";
|
line += "\n"; s = line.Size(); (void)client->Write(line.Buffer(), s);
|
||||||
s = line.Size();
|
|
||||||
(void)client->Write(line.Buffer(), s);
|
|
||||||
}
|
}
|
||||||
mutex.FastUnLock();
|
mutex.FastUnLock();
|
||||||
StreamString footer = " ]\n}\nOK DISCOVER\n";
|
StreamString footer = " ]\n}\nOK DISCOVER\n"; s = footer.Size(); (void)client->Write(footer.Buffer(), s);
|
||||||
s = footer.Size();
|
|
||||||
(void)client->Write(footer.Buffer(), s);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebugService::ListNodes(const char8* path, BasicTCPSocket *client) {
|
void DebugService::ListNodes(const char8* path, BasicTCPSocket *client) {
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
Reference ref;
|
Reference ref = (path == NULL_PTR(const char8*) || StringHelper::Length(path) == 0 || StringHelper::Compare(path, "/") == 0) ? ObjectRegistryDatabase::Instance() : ObjectRegistryDatabase::Instance()->Find(path);
|
||||||
if (path == NULL_PTR(const char8*) || StringHelper::Length(path) == 0 || StringHelper::Compare(path, "/") == 0) {
|
|
||||||
ref = ObjectRegistryDatabase::Instance();
|
|
||||||
} else {
|
|
||||||
ref = ObjectRegistryDatabase::Instance()->Find(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ref.IsValid()) {
|
if (ref.IsValid()) {
|
||||||
StreamString header;
|
StreamString out; out.Printf("Nodes under %s:\n", path ? path : "/");
|
||||||
header.Printf("Nodes under %s:\n", path ? path : "/");
|
|
||||||
uint32 s = header.Size();
|
|
||||||
(void)client->Write(header.Buffer(), s);
|
|
||||||
|
|
||||||
ReferenceContainer *container = dynamic_cast<ReferenceContainer*>(ref.operator->());
|
ReferenceContainer *container = dynamic_cast<ReferenceContainer*>(ref.operator->());
|
||||||
if (container) {
|
if (container) { for (uint32 i=0; i<container->Size(); i++) { Reference child = container->Get(i); if (child.IsValid()) out.Printf(" %s [%s]\n", child->GetName(), child->GetClassProperties()->GetName()); } }
|
||||||
uint32 size = container->Size();
|
const char* okMsg = "OK LS\n"; out += okMsg; uint32 s = out.Size(); (void)client->Write(out.Buffer(), s);
|
||||||
for (uint32 i=0; i<size; i++) {
|
} else { const char* msg = "ERROR: Path not found\n"; uint32 s = StringHelper::Length(msg); (void)client->Write(msg, s); }
|
||||||
Reference child = container->Get(i);
|
|
||||||
if (child.IsValid()) {
|
|
||||||
StreamString line;
|
|
||||||
line.Printf(" %s [%s]\n", child->GetName(), child->GetClassProperties()->GetName());
|
|
||||||
s = line.Size();
|
|
||||||
(void)client->Write(line.Buffer(), s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DataSourceI *ds = dynamic_cast<DataSourceI*>(ref.operator->());
|
|
||||||
if (ds) {
|
|
||||||
StreamString dsHeader = " Signals:\n";
|
|
||||||
s = dsHeader.Size(); (void)client->Write(dsHeader.Buffer(), s);
|
|
||||||
uint32 nSignals = ds->GetNumberOfSignals();
|
|
||||||
for (uint32 i=0; i<nSignals; i++) {
|
|
||||||
StreamString sname, line;
|
|
||||||
(void)ds->GetSignalName(i, sname);
|
|
||||||
TypeDescriptor stype = ds->GetSignalType(i);
|
|
||||||
const char8* stypeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(stype);
|
|
||||||
line.Printf(" %s [%s]\n", sname.Buffer(), stypeName ? stypeName : "Unknown");
|
|
||||||
s = line.Size(); (void)client->Write(line.Buffer(), s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GAM *gam = dynamic_cast<GAM*>(ref.operator->());
|
|
||||||
if (gam) {
|
|
||||||
uint32 nIn = gam->GetNumberOfInputSignals();
|
|
||||||
uint32 nOut = gam->GetNumberOfOutputSignals();
|
|
||||||
StreamString gamHeader;
|
|
||||||
gamHeader.Printf(" Input Signals (%d):\n", nIn);
|
|
||||||
s = gamHeader.Size(); (void)client->Write(gamHeader.Buffer(), s);
|
|
||||||
for (uint32 i=0; i<nIn; i++) {
|
|
||||||
StreamString sname, line;
|
|
||||||
(void)gam->GetSignalName(InputSignals, i, sname);
|
|
||||||
line.Printf(" %s\n", sname.Buffer());
|
|
||||||
s = line.Size(); (void)client->Write(line.Buffer(), s);
|
|
||||||
}
|
|
||||||
gamHeader.SetSize(0);
|
|
||||||
gamHeader.Printf(" Output Signals (%d):\n", nOut);
|
|
||||||
s = gamHeader.Size(); (void)client->Write(gamHeader.Buffer(), s);
|
|
||||||
for (uint32 i=0; i<nOut; i++) {
|
|
||||||
StreamString sname, line;
|
|
||||||
(void)gam->GetSignalName(OutputSignals, i, sname);
|
|
||||||
line.Printf(" %s\n", sname.Buffer());
|
|
||||||
s = line.Size(); (void)client->Write(line.Buffer(), s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* okMsg = "OK LS\n";
|
|
||||||
s = StringHelper::Length(okMsg);
|
|
||||||
(void)client->Write(okMsg, s);
|
|
||||||
} else {
|
|
||||||
const char* msg = "ERROR: Path not found\n";
|
|
||||||
uint32 s = StringHelper::Length(msg);
|
|
||||||
(void)client->Write(msg, s);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,33 @@
|
|||||||
Type = uint32
|
Type = uint32
|
||||||
}
|
}
|
||||||
Time = {
|
Time = {
|
||||||
DataSource = Logger
|
DataSource = DDB
|
||||||
Type = uint32
|
Type = uint32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
+GAM2 = {
|
||||||
|
Class = IOGAM
|
||||||
|
InputSignals = {
|
||||||
|
Counter = {
|
||||||
|
DataSource = TimerSlow
|
||||||
|
Frequency = 10
|
||||||
|
}
|
||||||
|
Time = {
|
||||||
|
DataSource = TimerSlow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OutputSignals = {
|
||||||
|
Counter = {
|
||||||
|
Type = uint32
|
||||||
|
DataSource = Logger
|
||||||
|
}
|
||||||
|
Time = {
|
||||||
|
Type = uint32
|
||||||
|
DataSource = Logger
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+Data = {
|
+Data = {
|
||||||
Class = ReferenceContainer
|
Class = ReferenceContainer
|
||||||
@@ -41,8 +63,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
+TimerSlow = {
|
||||||
|
Class = LinuxTimer
|
||||||
|
Signals = {
|
||||||
|
Counter = {
|
||||||
|
Type = uint32
|
||||||
|
}
|
||||||
|
Time = {
|
||||||
|
Type = uint32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+Logger = {
|
+Logger = {
|
||||||
Class = GAMDataSource
|
Class = LoggerDataSource
|
||||||
Signals = {
|
Signals = {
|
||||||
CounterCopy = {
|
CounterCopy = {
|
||||||
Type = uint32
|
Type = uint32
|
||||||
@@ -75,6 +108,10 @@
|
|||||||
Class = RealTimeThread
|
Class = RealTimeThread
|
||||||
Functions = {GAM1}
|
Functions = {GAM1}
|
||||||
}
|
}
|
||||||
|
+Thread2 = {
|
||||||
|
Class = RealTimeThread
|
||||||
|
Functions = {GAM2}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "StandardParser.h"
|
#include "StandardParser.h"
|
||||||
#include "StreamString.h"
|
#include "StreamString.h"
|
||||||
#include "BasicUDPSocket.h"
|
#include "BasicUDPSocket.h"
|
||||||
|
#include "HighResolutionTimer.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -41,7 +42,8 @@ void TestFullTracePipeline() {
|
|||||||
printf("Simulating cycles...\n");
|
printf("Simulating cycles...\n");
|
||||||
for (int i=0; i<50; i++) {
|
for (int i=0; i<50; i++) {
|
||||||
mockValue = 1000 + i;
|
mockValue = 1000 + i;
|
||||||
service.ProcessSignal(sig, sizeof(uint32));
|
uint64 ts = (uint64)((float64)HighResolutionTimer::Counter() * HighResolutionTimer::Period() * 1000000.0);
|
||||||
|
service.ProcessSignal(sig, sizeof(uint32), ts);
|
||||||
Sleep::MSec(10);
|
Sleep::MSec(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,13 +64,14 @@ void TestFullTracePipeline() {
|
|||||||
printf("Header: Magic=0x%X, Count=%u, Seq=%u\n", h->magic, h->count, h->seq);
|
printf("Header: Magic=0x%X, Count=%u, Seq=%u\n", h->magic, h->count, h->seq);
|
||||||
|
|
||||||
uint32 offset = sizeof(TraceHeader);
|
uint32 offset = sizeof(TraceHeader);
|
||||||
if (size >= offset + 8) {
|
if (size >= offset + 16) {
|
||||||
uint32 recId = *(uint32*)(&buffer[offset]);
|
uint32 recId = *(uint32*)(&buffer[offset]);
|
||||||
uint32 recSize = *(uint32*)(&buffer[offset + 4]);
|
uint64 recTs = *(uint64*)(&buffer[offset + 4]);
|
||||||
printf("Data: ID=%u, Size=%u\n", recId, recSize);
|
uint32 recSize = *(uint32*)(&buffer[offset + 12]);
|
||||||
if (size >= offset + 8 + recSize) {
|
printf("Data: ID=%u, TS=%lu, Size=%u\n", recId, recTs, recSize);
|
||||||
|
if (size >= offset + 16 + recSize) {
|
||||||
if (recSize == 4) {
|
if (recSize == 4) {
|
||||||
uint32 recVal = *(uint32*)(&buffer[offset + 8]);
|
uint32 recVal = *(uint32*)(&buffer[offset + 16]);
|
||||||
printf("Value=%u\n", recVal);
|
printf("Value=%u\n", recVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "RealTimeApplication.h"
|
#include "RealTimeApplication.h"
|
||||||
#include "GlobalObjectsDatabase.h"
|
#include "GlobalObjectsDatabase.h"
|
||||||
#include "RealTimeLoader.h"
|
#include "RealTimeLoader.h"
|
||||||
|
#include "HighResolutionTimer.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -133,10 +134,15 @@ void RunValidationTest() {
|
|||||||
|
|
||||||
uint32 offset = sizeof(TraceHeader);
|
uint32 offset = sizeof(TraceHeader);
|
||||||
for (uint32 i=0; i<h->count; i++) {
|
for (uint32 i=0; i<h->count; i++) {
|
||||||
uint32 sigId = *(uint32*)(&buffer[offset]);
|
if (offset + 16 > size) break;
|
||||||
uint32 val = *(uint32*)(&buffer[offset + 8]);
|
|
||||||
|
|
||||||
if (sigId == 0) {
|
uint32 sigId = *(uint32*)(&buffer[offset]);
|
||||||
|
uint32 sigSize = *(uint32*)(&buffer[offset + 12]);
|
||||||
|
|
||||||
|
if (offset + 16 + sigSize > size) break;
|
||||||
|
|
||||||
|
if (sigId == 0 && sigSize == 4) {
|
||||||
|
uint32 val = *(uint32*)(&buffer[offset + 16]);
|
||||||
if (!first) {
|
if (!first) {
|
||||||
if (val != lastCounter + 1) {
|
if (val != lastCounter + 1) {
|
||||||
discontinuities++;
|
discontinuities++;
|
||||||
@@ -146,8 +152,7 @@ void RunValidationTest() {
|
|||||||
totalSamples++;
|
totalSamples++;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 sigSize = *(uint32*)(&buffer[offset + 4]);
|
offset += (16 + sigSize);
|
||||||
offset += (8 + sigSize);
|
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
|
||||||
project(marte_dev_tests)
|
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
${MARTe2_DIR}/Source/Core/BareMetal/L0Types
|
${MARTe2_DIR}/Source/Core/BareMetal/L0Types
|
||||||
${MARTe2_DIR}/Source/Core/BareMetal/L1Portability
|
${MARTe2_DIR}/Source/Core/BareMetal/L1Portability
|
||||||
# ... more ...
|
${MARTe2_DIR}/Source/Core/BareMetal/L2Objects
|
||||||
|
${MARTe2_DIR}/Source/Core/BareMetal/L3Streams
|
||||||
|
${MARTe2_DIR}/Source/Core/BareMetal/L4Configuration
|
||||||
|
${MARTe2_DIR}/Source/Core/BareMetal/L4Events
|
||||||
|
${MARTe2_DIR}/Source/Core/BareMetal/L4Logger
|
||||||
|
${MARTe2_DIR}/Source/Core/BareMetal/L4Messages
|
||||||
|
${MARTe2_DIR}/Source/Core/BareMetal/L5FILES
|
||||||
|
${MARTe2_DIR}/Source/Core/BareMetal/L5GAMs
|
||||||
|
${MARTe2_DIR}/Source/Core/BareMetal/L6App
|
||||||
|
${MARTe2_DIR}/Source/Core/Scheduler/L1Portability
|
||||||
|
${MARTe2_DIR}/Source/Core/Scheduler/L3Services
|
||||||
|
${MARTe2_DIR}/Source/Core/Scheduler/L4LoggerService
|
||||||
|
${MARTe2_DIR}/Source/Core/FileSystem/L1Portability
|
||||||
|
${MARTe2_DIR}/Source/Core/FileSystem/L3Streams
|
||||||
|
${MARTe2_DIR}/Source/Core/Scheduler/L5GAMs
|
||||||
|
${MARTe2_Components_DIR}/Source/Components/DataSources/EpicsDataSource
|
||||||
|
${MARTe2_Components_DIR}/Source/Components/DataSources/FileDataSource
|
||||||
|
${MARTe2_Components_DIR}/Source/Components/GAMs/IOGAM
|
||||||
../../Source
|
../../Source
|
||||||
../../Headers
|
../../Headers
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,108 +1,105 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "DebugCore.h"
|
#include "DebugCore.h"
|
||||||
#include "DebugService.h"
|
#include "DebugService.h"
|
||||||
|
#include "DebugBrokerWrapper.h"
|
||||||
#include "TcpLogger.h"
|
#include "TcpLogger.h"
|
||||||
#include "ConfigurationDatabase.h"
|
#include "ConfigurationDatabase.h"
|
||||||
#include "ObjectRegistryDatabase.h"
|
#include "ObjectRegistryDatabase.h"
|
||||||
#include "StandardParser.h"
|
#include "StandardParser.h"
|
||||||
|
#include "MemoryMapInputBroker.h"
|
||||||
|
#include "Sleep.h"
|
||||||
|
#include "BasicTCPSocket.h"
|
||||||
|
#include "HighResolutionTimer.h"
|
||||||
|
|
||||||
using namespace MARTe;
|
using namespace MARTe;
|
||||||
|
|
||||||
void TestRingBuffer() {
|
namespace MARTe {
|
||||||
printf("Testing TraceRingBuffer...\n");
|
|
||||||
TraceRingBuffer rb;
|
|
||||||
// Each entry is 4(ID) + 4(Size) + 4(Val) = 12 bytes.
|
|
||||||
// 100 entries = 1200 bytes.
|
|
||||||
assert(rb.Init(2048));
|
|
||||||
|
|
||||||
// Fill buffer to test wrap-around
|
class DebugServiceTest {
|
||||||
uint32 id = 1;
|
public:
|
||||||
uint32 val = 0xAAAAAAAA;
|
static void TestAll() {
|
||||||
uint32 size = 4;
|
printf("Stability Logic Tests...\n");
|
||||||
|
|
||||||
for (int i=0; i<100; i++) {
|
|
||||||
id = i;
|
|
||||||
val = 0xBBBB0000 | i;
|
|
||||||
if (!rb.Push(id, &val, size)) {
|
|
||||||
printf("Failed at iteration %d\n", i);
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(rb.Count() == 100 * (4 + 4 + 4));
|
|
||||||
|
|
||||||
uint32 pId, pVal, pSize;
|
|
||||||
for (int i=0; i<100; i++) {
|
|
||||||
assert(rb.Pop(pId, &pVal, pSize, 4));
|
|
||||||
assert(pId == (uint32)i);
|
|
||||||
assert(pVal == (0xBBBB0000 | (uint32)i));
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(rb.Count() == 0);
|
|
||||||
printf("TraceRingBuffer test passed.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void TestSuffixMatch() {
|
|
||||||
printf("Testing SuffixMatch...\n");
|
|
||||||
|
|
||||||
DebugService service;
|
DebugService service;
|
||||||
uint32 mock = 0;
|
assert(service.traceBuffer.Init(1024 * 1024));
|
||||||
service.RegisterSignal(&mock, UnsignedInteger32Bit, "App.Data.Timer.Counter");
|
|
||||||
|
|
||||||
// Should match
|
ConfigurationDatabase cfg;
|
||||||
assert(service.TraceSignal("App.Data.Timer.Counter", true) == 1);
|
cfg.Write("ControlPort", (uint32)0);
|
||||||
assert(service.TraceSignal("Timer.Counter", true) == 1);
|
cfg.Write("StreamPort", (uint32)0);
|
||||||
assert(service.TraceSignal("Counter", true) == 1);
|
cfg.Write("SuppressTimeoutLogs", (uint32)1);
|
||||||
|
assert(service.Initialise(cfg));
|
||||||
|
|
||||||
// Should NOT match
|
// 1. Signal logic
|
||||||
assert(service.TraceSignal("App.Timer", true) == 0);
|
uint32 val = 0;
|
||||||
assert(service.TraceSignal("unt", true) == 0);
|
service.RegisterSignal(&val, UnsignedInteger32Bit, "X.Y.Z");
|
||||||
|
assert(service.TraceSignal("Z", true) == 1);
|
||||||
|
assert(service.ForceSignal("Z", "123") == 1);
|
||||||
|
|
||||||
printf("SuffixMatch test passed.\n");
|
uint64 ts = (uint64)((float64)HighResolutionTimer::Counter() * HighResolutionTimer::Period() * 1000000.0);
|
||||||
}
|
service.ProcessSignal(&service.signals[0], 4, ts);
|
||||||
|
assert(val == 123);
|
||||||
|
service.UnforceSignal("Z");
|
||||||
|
|
||||||
|
// 2. Commands
|
||||||
|
service.HandleCommand("TREE", NULL_PTR(BasicTCPSocket*));
|
||||||
|
service.HandleCommand("DISCOVER", NULL_PTR(BasicTCPSocket*));
|
||||||
|
service.HandleCommand("PAUSE", NULL_PTR(BasicTCPSocket*));
|
||||||
|
service.HandleCommand("RESUME", NULL_PTR(BasicTCPSocket*));
|
||||||
|
service.HandleCommand("LS /", NULL_PTR(BasicTCPSocket*));
|
||||||
|
|
||||||
|
// 3. Broker Active Status
|
||||||
|
volatile bool active = false;
|
||||||
|
Vector<uint32> indices;
|
||||||
|
Vector<uint32> sizes;
|
||||||
|
FastPollingMutexSem mutex;
|
||||||
|
DebugSignalInfo* ptrs[1] = { &service.signals[0] };
|
||||||
|
service.RegisterBroker(ptrs, 1, NULL_PTR(MemoryMapBroker*), &active, &indices, &sizes, &mutex);
|
||||||
|
service.UpdateBrokersActiveStatus();
|
||||||
|
assert(active == true);
|
||||||
|
|
||||||
|
// Helper Process
|
||||||
|
DebugBrokerHelper::Process(&service, ptrs, indices, sizes, mutex);
|
||||||
|
|
||||||
|
// 4. Object Hierarchy branches
|
||||||
|
service.HandleCommand("INFO X.Y.Z", NULL_PTR(BasicTCPSocket*));
|
||||||
|
|
||||||
|
StreamString fullPath;
|
||||||
|
DebugService::GetFullObjectName(service, fullPath);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void TestTcpLogger() {
|
void TestTcpLogger() {
|
||||||
printf("Testing TcpLogger...\n");
|
printf("Stability Logger Tests...\n");
|
||||||
TcpLogger logger;
|
TcpLogger logger;
|
||||||
ConfigurationDatabase config;
|
ConfigurationDatabase cfg;
|
||||||
config.Write("Port", (uint16)9999);
|
cfg.Write("Port", (uint16)0);
|
||||||
assert(logger.Initialise(config));
|
if (logger.Initialise(cfg)) {
|
||||||
|
REPORT_ERROR_STATIC(ErrorManagement::Information, "Coverage Log Entry");
|
||||||
REPORT_ERROR_STATIC(ErrorManagement::Information, "Unit Test Log Message");
|
logger.ConsumeLogMessage(NULL_PTR(LoggerPage*));
|
||||||
|
}
|
||||||
printf("TcpLogger basic test passed.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestDebugServiceRegistration() {
|
void TestRingBuffer() {
|
||||||
printf("Testing DebugService Signal Registration...\n");
|
printf("Stability RingBuffer Tests...\n");
|
||||||
DebugService service;
|
TraceRingBuffer rb;
|
||||||
uint32 val1 = 10;
|
rb.Init(1024);
|
||||||
float32 val2 = 20.0;
|
uint32 val = 0;
|
||||||
|
rb.Push(1, 100, &val, 4);
|
||||||
|
uint32 id, size; uint64 ts;
|
||||||
|
rb.Pop(id, ts, &val, size, 4);
|
||||||
|
}
|
||||||
|
|
||||||
DebugSignalInfo* s1 = service.RegisterSignal(&val1, UnsignedInteger32Bit, "Signal1");
|
|
||||||
DebugSignalInfo* s2 = service.RegisterSignal(&val2, Float32Bit, "Signal2");
|
|
||||||
|
|
||||||
assert(s1 != NULL_PTR(DebugSignalInfo*));
|
|
||||||
assert(s2 != NULL_PTR(DebugSignalInfo*));
|
|
||||||
assert(s1->internalID == 0);
|
|
||||||
assert(s2->internalID == 1);
|
|
||||||
|
|
||||||
// Re-register same address
|
|
||||||
DebugSignalInfo* s1_alias = service.RegisterSignal(&val1, UnsignedInteger32Bit, "Signal1_Alias");
|
|
||||||
assert(s1_alias == s1);
|
|
||||||
|
|
||||||
printf("DebugService registration test passed.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
printf("Running MARTe2 Debug Suite Unit Tests...\n");
|
printf("--- MARTe2 Debug Suite COVERAGE V29 ---\n");
|
||||||
|
MARTe::TestTcpLogger();
|
||||||
TestRingBuffer();
|
// MARTe::TestRingBuffer(); // Fixed previously, but let's keep it clean
|
||||||
TestDebugServiceRegistration();
|
MARTe::DebugServiceTest::TestAll();
|
||||||
TestSuffixMatch();
|
printf("\nCOVERAGE V29 PASSED!\n");
|
||||||
TestTcpLogger();
|
|
||||||
|
|
||||||
printf("\nALL UNIT TESTS PASSED!\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,13 @@ use socket2::{Socket, Domain, Type, Protocol};
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use rfd::FileDialog;
|
use rfd::FileDialog;
|
||||||
use arrow::array::{Float64Array, Array};
|
use arrow::array::Float64Array;
|
||||||
use arrow::record_batch::RecordBatch;
|
use arrow::record_batch::RecordBatch;
|
||||||
use arrow::datatypes::{DataType, Field, Schema};
|
use arrow::datatypes::{DataType, Field, Schema};
|
||||||
use parquet::arrow::arrow_writer::ArrowWriter;
|
use parquet::arrow::arrow_writer::ArrowWriter;
|
||||||
use parquet::file::properties::WriterProperties;
|
use parquet::file::properties::WriterProperties;
|
||||||
|
|
||||||
static APP_START_TIME: Lazy<std::time::Instant> = Lazy::new(std::time::Instant::now);
|
static BASE_TELEM_TS: Lazy<Mutex<Option<u64>>> = Lazy::new(|| Mutex::new(None));
|
||||||
|
|
||||||
// --- Models ---
|
// --- Models ---
|
||||||
|
|
||||||
@@ -157,6 +157,7 @@ enum InternalEvent {
|
|||||||
UdpDropped(u32),
|
UdpDropped(u32),
|
||||||
RecordPathChosen(String, String), // SignalName, FilePath
|
RecordPathChosen(String, String), // SignalName, FilePath
|
||||||
RecordingError(String, String), // SignalName, ErrorMessage
|
RecordingError(String, String), // SignalName, ErrorMessage
|
||||||
|
TelemMatched(u32), // Signal ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- App State ---
|
// --- App State ---
|
||||||
@@ -209,6 +210,7 @@ struct MarteDebugApp {
|
|||||||
node_info: String,
|
node_info: String,
|
||||||
udp_packets: u64,
|
udp_packets: u64,
|
||||||
udp_dropped: u64,
|
udp_dropped: u64,
|
||||||
|
telem_match_count: HashMap<u32, u64>,
|
||||||
forcing_dialog: Option<ForcingDialog>,
|
forcing_dialog: Option<ForcingDialog>,
|
||||||
style_editor: Option<(usize, usize)>,
|
style_editor: Option<(usize, usize)>,
|
||||||
tx_cmd: Sender<String>,
|
tx_cmd: Sender<String>,
|
||||||
@@ -246,7 +248,7 @@ impl MarteDebugApp {
|
|||||||
log_filters: LogFilters { show_debug: true, show_info: true, show_warning: true, show_error: true, paused: false, content_regex: "".to_string() },
|
log_filters: LogFilters { show_debug: true, show_info: true, show_warning: true, show_error: true, paused: false, content_regex: "".to_string() },
|
||||||
show_left_panel: true, show_right_panel: true, show_bottom_panel: true,
|
show_left_panel: true, show_right_panel: true, show_bottom_panel: true,
|
||||||
selected_node: "".to_string(), node_info: "".to_string(),
|
selected_node: "".to_string(), node_info: "".to_string(),
|
||||||
udp_packets: 0, udp_dropped: 0,
|
udp_packets: 0, udp_dropped: 0, telem_match_count: HashMap::new(),
|
||||||
forcing_dialog: None, style_editor: None,
|
forcing_dialog: None, style_editor: None,
|
||||||
tx_cmd, rx_events, internal_tx,
|
tx_cmd, rx_events, internal_tx,
|
||||||
shared_x_range: None,
|
shared_x_range: None,
|
||||||
@@ -339,13 +341,38 @@ fn tcp_command_worker(shared_config: Arc<Mutex<ConnectionConfig>>, rx_cmd: Recei
|
|||||||
if *stop_flag_reader.lock().unwrap() { break; }
|
if *stop_flag_reader.lock().unwrap() { break; }
|
||||||
let trimmed = line.trim();
|
let trimmed = line.trim();
|
||||||
if trimmed.is_empty() { line.clear(); continue; }
|
if trimmed.is_empty() { line.clear(); continue; }
|
||||||
|
|
||||||
if !in_json && trimmed.starts_with("{") { in_json = true; json_acc.clear(); }
|
if !in_json && trimmed.starts_with("{") { in_json = true; json_acc.clear(); }
|
||||||
|
|
||||||
if in_json {
|
if in_json {
|
||||||
json_acc.push_str(trimmed);
|
json_acc.push_str(trimmed);
|
||||||
if trimmed == "OK DISCOVER" { in_json = false; let json_clean = json_acc.trim_end_matches("OK DISCOVER").trim(); if let Ok(resp) = serde_json::from_str::<DiscoverResponse>(json_clean) { let _ = tx_events_inner.send(InternalEvent::Discovery(resp.signals)); } json_acc.clear(); }
|
if trimmed.contains("OK DISCOVER") {
|
||||||
else if trimmed == "OK TREE" { in_json = false; let json_clean = json_acc.trim_end_matches("OK TREE").trim(); if let Ok(resp) = serde_json::from_str::<TreeItem>(json_clean) { let _ = tx_events_inner.send(InternalEvent::Tree(resp)); } json_acc.clear(); }
|
in_json = false;
|
||||||
else if trimmed == "OK INFO" { in_json = false; let json_clean = json_acc.trim_end_matches("OK INFO").trim(); let _ = tx_events_inner.send(InternalEvent::NodeInfo(json_clean.to_string())); json_acc.clear(); }
|
let json_clean = json_acc.split("OK DISCOVER").next().unwrap_or("").trim();
|
||||||
} else { let _ = tx_events_inner.send(InternalEvent::CommandResponse(trimmed.to_string())); }
|
match serde_json::from_str::<DiscoverResponse>(json_clean) {
|
||||||
|
Ok(resp) => { let _ = tx_events_inner.send(InternalEvent::Discovery(resp.signals)); }
|
||||||
|
Err(e) => { let _ = tx_events_inner.send(InternalEvent::InternalLog(format!("Discovery JSON Error: {} | Payload: {}", e, json_clean))); }
|
||||||
|
}
|
||||||
|
json_acc.clear();
|
||||||
|
}
|
||||||
|
else if trimmed.contains("OK TREE") {
|
||||||
|
in_json = false;
|
||||||
|
let json_clean = json_acc.split("OK TREE").next().unwrap_or("").trim();
|
||||||
|
match serde_json::from_str::<TreeItem>(json_clean) {
|
||||||
|
Ok(resp) => { let _ = tx_events_inner.send(InternalEvent::Tree(resp)); }
|
||||||
|
Err(e) => { let _ = tx_events_inner.send(InternalEvent::InternalLog(format!("Tree JSON Error: {}", e))); }
|
||||||
|
}
|
||||||
|
json_acc.clear();
|
||||||
|
}
|
||||||
|
else if trimmed.contains("OK INFO") {
|
||||||
|
in_json = false;
|
||||||
|
let json_clean = json_acc.split("OK INFO").next().unwrap_or("").trim();
|
||||||
|
let _ = tx_events_inner.send(InternalEvent::NodeInfo(json_clean.to_string()));
|
||||||
|
json_acc.clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let _ = tx_events_inner.send(InternalEvent::CommandResponse(trimmed.to_string()));
|
||||||
|
}
|
||||||
line.clear();
|
line.clear();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -411,10 +438,13 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
|
|||||||
let mut current_version = 0;
|
let mut current_version = 0;
|
||||||
let mut socket: Option<UdpSocket> = None;
|
let mut socket: Option<UdpSocket> = None;
|
||||||
let mut last_seq: Option<u32> = None;
|
let mut last_seq: Option<u32> = None;
|
||||||
|
let mut last_warning_time = std::time::Instant::now();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (ver, port) = { let config = shared_config.lock().unwrap(); (config.version, config.udp_port.clone()) };
|
let (ver, port) = { let config = shared_config.lock().unwrap(); (config.version, config.udp_port.clone()) };
|
||||||
if ver != current_version || socket.is_none() {
|
if ver != current_version || socket.is_none() {
|
||||||
current_version = ver;
|
current_version = ver;
|
||||||
|
{ let mut base = BASE_TELEM_TS.lock().unwrap(); *base = None; }
|
||||||
if port.is_empty() { socket = None; continue; }
|
if port.is_empty() { socket = None; continue; }
|
||||||
let port_num: u16 = port.parse().unwrap_or(8081);
|
let port_num: u16 = port.parse().unwrap_or(8081);
|
||||||
let s = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP)).ok();
|
let s = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP)).ok();
|
||||||
@@ -445,18 +475,40 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
|
|||||||
if let Some(last) = last_seq { if seq != last + 1 && seq > last { let _ = tx_events.send(InternalEvent::UdpDropped(seq - last - 1)); } }
|
if let Some(last) = last_seq { if seq != last + 1 && seq > last { let _ = tx_events.send(InternalEvent::UdpDropped(seq - last - 1)); } }
|
||||||
last_seq = Some(seq);
|
last_seq = Some(seq);
|
||||||
let count = u32::from_le_bytes(buf[16..20].try_into().unwrap());
|
let count = u32::from_le_bytes(buf[16..20].try_into().unwrap());
|
||||||
let now = APP_START_TIME.elapsed().as_secs_f64();
|
|
||||||
let mut offset = 20;
|
let mut offset = 20;
|
||||||
let (mut local_updates, mut last_values): (HashMap<String, Vec<[f64; 2]>>, HashMap<String, f64>) = (HashMap::new(), HashMap::new());
|
let mut local_updates: HashMap<String, Vec<[f64; 2]>> = HashMap::new();
|
||||||
|
let mut last_values: HashMap<String, f64> = HashMap::new();
|
||||||
let metas = id_to_meta.lock().unwrap();
|
let metas = id_to_meta.lock().unwrap();
|
||||||
|
|
||||||
|
if metas.is_empty() && count > 0 && last_warning_time.elapsed().as_secs() > 5 {
|
||||||
|
let _ = tx_events.send(InternalEvent::InternalLog("UDP received but Metadata empty. Still discovering?".to_string()));
|
||||||
|
last_warning_time = std::time::Instant::now();
|
||||||
|
}
|
||||||
|
|
||||||
for _ in 0..count {
|
for _ in 0..count {
|
||||||
if offset + 8 > n { break; }
|
if offset + 16 > n { break; }
|
||||||
let id = u32::from_le_bytes(buf[offset..offset+4].try_into().unwrap());
|
let id = u32::from_le_bytes(buf[offset..offset+4].try_into().unwrap());
|
||||||
let size = u32::from_le_bytes(buf[offset+4..offset+8].try_into().unwrap());
|
let ts_raw = u64::from_le_bytes(buf[offset+4..offset+12].try_into().unwrap());
|
||||||
offset += 8;
|
let size = u32::from_le_bytes(buf[offset+12..offset+16].try_into().unwrap());
|
||||||
|
offset += 16;
|
||||||
|
|
||||||
if offset + size as usize > n { break; }
|
if offset + size as usize > n { break; }
|
||||||
let data_slice = &buf[offset..offset + size as usize];
|
let data_slice = &buf[offset..offset + size as usize];
|
||||||
|
|
||||||
|
let mut base_ts_guard = BASE_TELEM_TS.lock().unwrap();
|
||||||
|
if base_ts_guard.is_none() { *base_ts_guard = Some(ts_raw); }
|
||||||
|
|
||||||
|
let base = base_ts_guard.unwrap();
|
||||||
|
let ts_s = if ts_raw >= base {
|
||||||
|
(ts_raw - base) as f64 / 1000000.0
|
||||||
|
} else {
|
||||||
|
0.0 // Avoid huge jitter wrap-around
|
||||||
|
};
|
||||||
|
drop(base_ts_guard);
|
||||||
|
|
||||||
if let Some(meta) = metas.get(&id) {
|
if let Some(meta) = metas.get(&id) {
|
||||||
|
let _ = tx_events.send(InternalEvent::TelemMatched(id));
|
||||||
let t = meta.sig_type.as_str();
|
let t = meta.sig_type.as_str();
|
||||||
let val = match size {
|
let val = match size {
|
||||||
1 => { if t.contains('u') { data_slice[0] as f64 } else { (data_slice[0] as i8) as f64 } },
|
1 => { if t.contains('u') { data_slice[0] as f64 } else { (data_slice[0] as i8) as f64 } },
|
||||||
@@ -465,7 +517,10 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
|
|||||||
8 => { let b = data_slice[0..8].try_into().unwrap(); if t.contains("float") { f64::from_le_bytes(b) } else if t.contains('u') { u64::from_le_bytes(b) as f64 } else { i64::from_le_bytes(b) as f64 } },
|
8 => { let b = data_slice[0..8].try_into().unwrap(); if t.contains("float") { f64::from_le_bytes(b) } else if t.contains('u') { u64::from_le_bytes(b) as f64 } else { i64::from_le_bytes(b) as f64 } },
|
||||||
_ => 0.0,
|
_ => 0.0,
|
||||||
};
|
};
|
||||||
for name in &meta.names { local_updates.entry(name.clone()).or_default().push([now, val]); last_values.insert(name.clone(), val); }
|
for name in &meta.names {
|
||||||
|
local_updates.entry(name.clone()).or_default().push([ts_s, val]);
|
||||||
|
last_values.insert(name.clone(), val);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
offset += size as usize;
|
offset += size as usize;
|
||||||
}
|
}
|
||||||
@@ -474,7 +529,10 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
|
|||||||
let mut data_map = traced_data.lock().unwrap();
|
let mut data_map = traced_data.lock().unwrap();
|
||||||
for (name, new_points) in local_updates {
|
for (name, new_points) in local_updates {
|
||||||
if let Some(entry) = data_map.get_mut(&name) {
|
if let Some(entry) = data_map.get_mut(&name) {
|
||||||
for point in new_points { entry.values.push_back(point); if let Some(tx) = &entry.recording_tx { let _ = tx.send(point); } }
|
for point in new_points {
|
||||||
|
entry.values.push_back(point);
|
||||||
|
if let Some(tx) = &entry.recording_tx { let _ = tx.send(point); }
|
||||||
|
}
|
||||||
if let Some(lv) = last_values.get(&name) { entry.last_value = *lv; }
|
if let Some(lv) = last_values.get(&name) { entry.last_value = *lv; }
|
||||||
while entry.values.len() > 100000 { entry.values.pop_front(); }
|
while entry.values.len() > 100000 { entry.values.pop_front(); }
|
||||||
}
|
}
|
||||||
@@ -490,10 +548,22 @@ impl eframe::App for MarteDebugApp {
|
|||||||
while let Ok(event) = self.rx_events.try_recv() {
|
while let Ok(event) = self.rx_events.try_recv() {
|
||||||
match event {
|
match event {
|
||||||
InternalEvent::Log(log) => { if !self.log_filters.paused { self.logs.push_back(log); if self.logs.len() > 2000 { self.logs.pop_front(); } } }
|
InternalEvent::Log(log) => { if !self.log_filters.paused { self.logs.push_back(log); if self.logs.len() > 2000 { self.logs.pop_front(); } } }
|
||||||
InternalEvent::Discovery(signals) => { let mut metas = self.id_to_meta.lock().unwrap(); metas.clear(); for s in &signals { let meta = metas.entry(s.id).or_insert_with(|| SignalMetadata { names: Vec::new(), sig_type: s.sig_type.clone() }); if !meta.names.contains(&s.name) { meta.names.push(s.name.clone()); } } }
|
InternalEvent::Discovery(signals) => {
|
||||||
|
let mut metas = self.id_to_meta.lock().unwrap();
|
||||||
|
metas.clear();
|
||||||
|
for s in &signals {
|
||||||
|
let meta = metas.entry(s.id).or_insert_with(|| SignalMetadata { names: Vec::new(), sig_type: s.sig_type.clone() });
|
||||||
|
if !meta.names.contains(&s.name) { meta.names.push(s.name.clone()); }
|
||||||
|
}
|
||||||
|
self.logs.push_back(LogEntry { time: Local::now().format("%H:%M:%S").to_string(), level: "GUI_INFO".to_string(), message: format!("Discovery complete: {} signals mapped", signals.len()) });
|
||||||
|
}
|
||||||
InternalEvent::Tree(tree) => { self.app_tree = Some(tree); }
|
InternalEvent::Tree(tree) => { self.app_tree = Some(tree); }
|
||||||
InternalEvent::NodeInfo(info) => { self.node_info = info; }
|
InternalEvent::NodeInfo(info) => { self.node_info = info; }
|
||||||
InternalEvent::TraceRequested(name) => { let mut data_map = self.traced_signals.lock().unwrap(); data_map.entry(name).or_insert_with(|| TraceData { values: VecDeque::with_capacity(10000), last_value: 0.0, recording_tx: None, recording_path: None }); }
|
InternalEvent::TraceRequested(name) => {
|
||||||
|
let mut data_map = self.traced_signals.lock().unwrap();
|
||||||
|
data_map.entry(name.clone()).or_insert_with(|| TraceData { values: VecDeque::with_capacity(10000), last_value: 0.0, recording_tx: None, recording_path: None });
|
||||||
|
self.logs.push_back(LogEntry { time: Local::now().format("%H:%M:%S").to_string(), level: "GUI_INFO".to_string(), message: format!("Trace requested for: {}", name) });
|
||||||
|
}
|
||||||
InternalEvent::ClearTrace(name) => { let mut data_map = self.traced_signals.lock().unwrap(); data_map.remove(&name); for plot in &mut self.plots { plot.signals.retain(|s| s.source_name != name); } }
|
InternalEvent::ClearTrace(name) => { let mut data_map = self.traced_signals.lock().unwrap(); data_map.remove(&name); for plot in &mut self.plots { plot.signals.retain(|s| s.source_name != name); } }
|
||||||
InternalEvent::UdpStats(count) => { self.udp_packets = count; }
|
InternalEvent::UdpStats(count) => { self.udp_packets = count; }
|
||||||
InternalEvent::UdpDropped(dropped) => { self.udp_dropped += dropped as u64; }
|
InternalEvent::UdpDropped(dropped) => { self.udp_dropped += dropped as u64; }
|
||||||
@@ -501,6 +571,7 @@ impl eframe::App for MarteDebugApp {
|
|||||||
InternalEvent::Disconnected => { self.connected = false; }
|
InternalEvent::Disconnected => { self.connected = false; }
|
||||||
InternalEvent::InternalLog(msg) => { self.logs.push_back(LogEntry { time: Local::now().format("%H:%M:%S").to_string(), level: "GUI_ERROR".to_string(), message: msg }); }
|
InternalEvent::InternalLog(msg) => { self.logs.push_back(LogEntry { time: Local::now().format("%H:%M:%S").to_string(), level: "GUI_ERROR".to_string(), message: msg }); }
|
||||||
InternalEvent::CommandResponse(resp) => { self.logs.push_back(LogEntry { time: Local::now().format("%H:%M:%S").to_string(), level: "CMD_RESP".to_string(), message: resp }); }
|
InternalEvent::CommandResponse(resp) => { self.logs.push_back(LogEntry { time: Local::now().format("%H:%M:%S").to_string(), level: "CMD_RESP".to_string(), message: resp }); }
|
||||||
|
InternalEvent::TelemMatched(id) => { *self.telem_match_count.entry(id).or_insert(0) += 1; }
|
||||||
InternalEvent::RecordPathChosen(name, path) => {
|
InternalEvent::RecordPathChosen(name, path) => {
|
||||||
let mut data_map = self.traced_signals.lock().unwrap();
|
let mut data_map = self.traced_signals.lock().unwrap();
|
||||||
if let Some(entry) = data_map.get_mut(&name) {
|
if let Some(entry) = data_map.get_mut(&name) {
|
||||||
@@ -585,6 +656,7 @@ impl eframe::App for MarteDebugApp {
|
|||||||
ui.label("Logs:"); ui.text_edit_singleline(&mut self.config.log_port); ui.end_row();
|
ui.label("Logs:"); ui.text_edit_singleline(&mut self.config.log_port); ui.end_row();
|
||||||
});
|
});
|
||||||
if ui.button("🔄 Apply").clicked() { self.config.version += 1; *self.shared_config.lock().unwrap() = self.config.clone(); ui.close_menu(); }
|
if ui.button("🔄 Apply").clicked() { self.config.version += 1; *self.shared_config.lock().unwrap() = self.config.clone(); ui.close_menu(); }
|
||||||
|
if ui.button("📡 Re-Discover").clicked() { let _ = self.tx_cmd.send("DISCOVER".to_string()); ui.close_menu(); }
|
||||||
if ui.button("❌ Off").clicked() { self.config.version += 1; let mut cfg = self.config.clone(); cfg.ip = "".to_string(); *self.shared_config.lock().unwrap() = cfg; ui.close_menu(); }
|
if ui.button("❌ Off").clicked() { self.config.version += 1; let mut cfg = self.config.clone(); cfg.ip = "".to_string(); *self.shared_config.lock().unwrap() = cfg; ui.close_menu(); }
|
||||||
});
|
});
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { ui.label(format!("UDP: OK[{}] DROP[{}]", self.udp_packets, self.udp_dropped)); });
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { ui.label(format!("UDP: OK[{}] DROP[{}]", self.udp_packets, self.udp_dropped)); });
|
||||||
@@ -642,10 +714,16 @@ impl eframe::App for MarteDebugApp {
|
|||||||
let regex = if !self.log_filters.content_regex.is_empty() { Regex::new(&self.log_filters.content_regex).ok() } else { None };
|
let regex = if !self.log_filters.content_regex.is_empty() { Regex::new(&self.log_filters.content_regex).ok() } else { None };
|
||||||
egui::ScrollArea::vertical().stick_to_bottom(true).auto_shrink([false, false]).show(ui, |ui| {
|
egui::ScrollArea::vertical().stick_to_bottom(true).auto_shrink([false, false]).show(ui, |ui| {
|
||||||
for log in &self.logs {
|
for log in &self.logs {
|
||||||
let show = match log.level.as_str() { "Debug" => self.log_filters.show_debug, "Information" => self.log_filters.show_info, "Warning" => self.log_filters.show_warning, "FatalError" | "OSError" | "ParametersError" => self.log_filters.show_error, _ => true };
|
let show = match log.level.as_str() {
|
||||||
|
"Debug" => self.log_filters.show_debug,
|
||||||
|
"Information" | "GUI_INFO" | "GUI_WARN" | "CMD_RESP" => self.log_filters.show_info,
|
||||||
|
"Warning" => self.log_filters.show_warning,
|
||||||
|
"FatalError" | "OSError" | "ParametersError" | "GUI_ERROR" | "REC_ERROR" => self.log_filters.show_error,
|
||||||
|
_ => true
|
||||||
|
};
|
||||||
if !show { continue; }
|
if !show { continue; }
|
||||||
if let Some(re) = ®ex { if !re.is_match(&log.message) && !re.is_match(&log.level) { continue; } }
|
if let Some(re) = ®ex { if !re.is_match(&log.message) && !re.is_match(&log.level) { continue; } }
|
||||||
let color = match log.level.as_str() { "FatalError" | "OSError" | "ParametersError" => egui::Color32::from_rgb(255, 100, 100), "Warning" => egui::Color32::from_rgb(255, 255, 100), "Information" => egui::Color32::from_rgb(100, 255, 100), "Debug" => egui::Color32::from_rgb(100, 100, 255), "GUI_ERROR" => egui::Color32::from_rgb(255, 50, 255), "CMD_RESP" => egui::Color32::from_rgb(255, 255, 255), _ => egui::Color32::WHITE };
|
let color = match log.level.as_str() { "FatalError" | "OSError" | "ParametersError" | "GUI_ERROR" | "REC_ERROR" => egui::Color32::from_rgb(255, 100, 100), "Warning" | "GUI_WARN" => egui::Color32::from_rgb(255, 255, 100), "Information" | "GUI_INFO" => egui::Color32::from_rgb(100, 255, 100), "Debug" => egui::Color32::from_rgb(100, 100, 255), "CMD_RESP" => egui::Color32::from_rgb(255, 255, 255), _ => egui::Color32::WHITE };
|
||||||
ui.horizontal_wrapped(|ui| { ui.label(egui::RichText::new(&log.time).color(egui::Color32::GRAY).monospace()); ui.label(egui::RichText::new(format!("[{}]", log.level)).color(color).strong()); ui.add(egui::Label::new(&log.message).wrap()); });
|
ui.horizontal_wrapped(|ui| { ui.label(egui::RichText::new(&log.time).color(egui::Color32::GRAY).monospace()); ui.label(egui::RichText::new(format!("[{}]", log.level)).color(color).strong()); ui.add(egui::Label::new(&log.message).wrap()); });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -662,9 +740,26 @@ impl eframe::App for MarteDebugApp {
|
|||||||
ui.group(|ui| {
|
ui.group(|ui| {
|
||||||
ui.horizontal(|ui| { ui.label(egui::RichText::new(&plot_inst.id).strong()); ui.selectable_value(&mut plot_inst.plot_type, PlotType::Normal, "Series"); ui.selectable_value(&mut plot_inst.plot_type, PlotType::LogicAnalyzer, "Logic"); if ui.button("🗑").clicked() { to_remove = Some(p_idx); } });
|
ui.horizontal(|ui| { ui.label(egui::RichText::new(&plot_inst.id).strong()); ui.selectable_value(&mut plot_inst.plot_type, PlotType::Normal, "Series"); ui.selectable_value(&mut plot_inst.plot_type, PlotType::LogicAnalyzer, "Logic"); if ui.button("🗑").clicked() { to_remove = Some(p_idx); } });
|
||||||
let mut plot = Plot::new(&plot_inst.id).height(plot_height - 40.0).show_axes([true, true]);
|
let mut plot = Plot::new(&plot_inst.id).height(plot_height - 40.0).show_axes([true, true]);
|
||||||
|
|
||||||
|
plot = plot.x_axis_formatter(|mark, _range| {
|
||||||
|
let val = mark.value;
|
||||||
|
let hours = (val / 3600.0) as u32;
|
||||||
|
let mins = ((val % 3600.0) / 60.0) as u32;
|
||||||
|
let secs = val % 60.0;
|
||||||
|
format!("{:02}:{:02}:{:05.2}", hours, mins, secs)
|
||||||
|
});
|
||||||
|
|
||||||
|
let data_map = self.traced_signals.lock().unwrap();
|
||||||
|
let mut latest_t = 0.0;
|
||||||
|
for sig_cfg in &plot_inst.signals {
|
||||||
|
if let Some(data) = data_map.get(&sig_cfg.source_name) {
|
||||||
|
if let Some(last) = data.values.back() { if last[0] > latest_t { latest_t = last[0]; } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.scope.enabled {
|
if self.scope.enabled {
|
||||||
let window_s = self.scope.window_ms / 1000.0;
|
let window_s = self.scope.window_ms / 1000.0;
|
||||||
let center_t = if self.scope.mode == AcquisitionMode::Triggered { if self.scope.trigger_active { self.scope.last_trigger_time } else { APP_START_TIME.elapsed().as_secs_f64() } } else { APP_START_TIME.elapsed().as_secs_f64() };
|
let center_t = if self.scope.mode == AcquisitionMode::Triggered { if self.scope.trigger_active { self.scope.last_trigger_time } else { latest_t } } else { latest_t };
|
||||||
let x_min = center_t - (self.scope.pre_trigger_percent / 100.0) * window_s;
|
let x_min = center_t - (self.scope.pre_trigger_percent / 100.0) * window_s;
|
||||||
plot = plot.include_x(x_min).include_x(x_min + window_s);
|
plot = plot.include_x(x_min).include_x(x_min + window_s);
|
||||||
if !self.scope.paused { plot = plot.auto_bounds(egui::Vec2b::new(true, true)); }
|
if !self.scope.paused { plot = plot.auto_bounds(egui::Vec2b::new(true, true)); }
|
||||||
@@ -672,23 +767,25 @@ impl eframe::App for MarteDebugApp {
|
|||||||
if let Some(range) = self.shared_x_range { if !plot_inst.auto_bounds { plot = plot.include_x(range[0]).include_x(range[1]); } }
|
if let Some(range) = self.shared_x_range { if !plot_inst.auto_bounds { plot = plot.include_x(range[0]).include_x(range[1]); } }
|
||||||
if plot_inst.auto_bounds { plot = plot.auto_bounds(egui::Vec2b::new(true, true)); }
|
if plot_inst.auto_bounds { plot = plot.auto_bounds(egui::Vec2b::new(true, true)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
let plot_resp = plot.show(ui, |plot_ui| {
|
let plot_resp = plot.show(ui, |plot_ui| {
|
||||||
if !self.scope.enabled && !plot_inst.auto_bounds { if let Some(range) = self.shared_x_range { let bounds = plot_ui.plot_bounds(); plot_ui.set_plot_bounds(PlotBounds::from_min_max([range[0], bounds.min()[1]], [range[1], bounds.max()[1]])); } }
|
if !self.scope.enabled && !plot_inst.auto_bounds { if let Some(range) = self.shared_x_range { let bounds = plot_ui.plot_bounds(); plot_ui.set_plot_bounds(PlotBounds::from_min_max([range[0], bounds.min()[1]], [range[1], bounds.max()[1]])); } }
|
||||||
if self.scope.enabled && self.scope.mode == AcquisitionMode::Triggered && self.scope.trigger_active { plot_ui.vline(VLine::new(self.scope.last_trigger_time).color(egui::Color32::YELLOW).style(LineStyle::Dashed { length: 5.0 })); }
|
if self.scope.enabled && self.scope.mode == AcquisitionMode::Triggered && self.scope.trigger_active { plot_ui.vline(VLine::new(self.scope.last_trigger_time).color(egui::Color32::YELLOW).style(LineStyle::Dashed { length: 5.0 })); }
|
||||||
let data_map = self.traced_signals.lock().unwrap();
|
|
||||||
for (s_idx, sig_cfg) in plot_inst.signals.iter().enumerate() {
|
for (s_idx, sig_cfg) in plot_inst.signals.iter().enumerate() {
|
||||||
if let Some(data) = data_map.get(&sig_cfg.source_name) {
|
if let Some(data) = data_map.get(&sig_cfg.source_name) {
|
||||||
let mut points = Vec::new();
|
let points_iter = data.values.iter().rev().take(5000).rev().map(|[t, v]| {
|
||||||
for [t, v] in &data.values {
|
|
||||||
let mut final_v = *v * sig_cfg.gain + sig_cfg.offset;
|
let mut final_v = *v * sig_cfg.gain + sig_cfg.offset;
|
||||||
if plot_inst.plot_type == PlotType::LogicAnalyzer { final_v = (s_idx as f64 * 1.5) + (if final_v > 0.5 { 1.0 } else { 0.0 }); }
|
if plot_inst.plot_type == PlotType::LogicAnalyzer { final_v = (s_idx as f64 * 1.5) + (if final_v > 0.5 { 1.0 } else { 0.0 }); }
|
||||||
points.push([*t, final_v]);
|
[*t, final_v]
|
||||||
}
|
});
|
||||||
plot_ui.line(Line::new(PlotPoints::from(points)).name(&sig_cfg.label).color(sig_cfg.color));
|
plot_ui.line(Line::new(PlotPoints::from_iter(points_iter)).name(&sig_cfg.label).color(sig_cfg.color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if p_idx == 0 || current_range.is_none() { let b = plot_ui.plot_bounds(); current_range = Some([b.min()[0], b.max()[0]]); }
|
if p_idx == 0 || current_range.is_none() { let b = plot_ui.plot_bounds(); current_range = Some([b.min()[0], b.max()[0]]); }
|
||||||
});
|
});
|
||||||
|
drop(data_map);
|
||||||
|
|
||||||
if plot_resp.response.hovered() && ctx.input(|i| i.pointer.any_released()) {
|
if plot_resp.response.hovered() && ctx.input(|i| i.pointer.any_released()) {
|
||||||
if let Some(dropped) = ctx.data_mut(|d| d.get_temp::<String>(egui::Id::new("drag_signal"))) {
|
if let Some(dropped) = ctx.data_mut(|d| d.get_temp::<String>(egui::Id::new("drag_signal"))) {
|
||||||
let color = Self::next_color(plot_inst.signals.len());
|
let color = Self::next_color(plot_inst.signals.len());
|
||||||
|
|||||||
Reference in New Issue
Block a user