Compare commits
7 Commits
debugsched
...
aaf69c0949
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aaf69c0949 | ||
|
|
ec29bd5148 | ||
|
|
56bb3536fc | ||
|
|
6b1fc59fc0 | ||
|
|
253a4989f9 | ||
|
|
04fb98bc74 | ||
|
|
3ad581d13b |
@@ -4,6 +4,7 @@
|
||||
#include "CompilerTypes.h"
|
||||
#include "TypeDescriptor.h"
|
||||
#include "StreamString.h"
|
||||
#include <cstring> // For memcpy
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
@@ -58,7 +59,14 @@ public:
|
||||
uint32 packetSize = 4 + 4 + size;
|
||||
uint32 read = readIndex;
|
||||
uint32 write = writeIndex;
|
||||
uint32 available = (read <= write) ? (bufferSize - (write - read) - 1) : (read - write - 1);
|
||||
|
||||
// Calculate available space
|
||||
uint32 available = 0;
|
||||
if (read <= write) {
|
||||
available = bufferSize - (write - read) - 1;
|
||||
} else {
|
||||
available = read - write - 1;
|
||||
}
|
||||
|
||||
if (available < packetSize) return false;
|
||||
|
||||
@@ -68,6 +76,9 @@ public:
|
||||
WriteToBuffer(&tempWrite, &size, 4);
|
||||
WriteToBuffer(&tempWrite, data, size);
|
||||
|
||||
// Memory Barrier to ensure data is visible before index update
|
||||
// __sync_synchronize();
|
||||
|
||||
// Final atomic update
|
||||
writeIndex = tempWrite;
|
||||
return true;
|
||||
@@ -79,20 +90,27 @@ public:
|
||||
if (read == write) return false;
|
||||
|
||||
uint32 tempRead = read;
|
||||
uint32 tempId, tempSize;
|
||||
uint32 tempId = 0;
|
||||
uint32 tempSize = 0;
|
||||
|
||||
// Peek header
|
||||
ReadFromBuffer(&tempRead, &tempId, 4);
|
||||
ReadFromBuffer(&tempRead, &tempSize, 4);
|
||||
|
||||
if (tempSize > maxSize) {
|
||||
// Error case: drop data up to writeIndex
|
||||
// Error case: drop data up to writeIndex (resync)
|
||||
readIndex = write;
|
||||
return false;
|
||||
}
|
||||
|
||||
ReadFromBuffer(&tempRead, dataBuffer, tempSize);
|
||||
|
||||
signalID = tempId;
|
||||
size = tempSize;
|
||||
|
||||
// Memory Barrier
|
||||
// __sync_synchronize();
|
||||
|
||||
readIndex = tempRead;
|
||||
return true;
|
||||
}
|
||||
@@ -106,18 +124,32 @@ public:
|
||||
|
||||
private:
|
||||
void WriteToBuffer(uint32 *idx, void* src, uint32 count) {
|
||||
uint8* s = (uint8*)src;
|
||||
for (uint32 i=0; i<count; i++) {
|
||||
buffer[*idx] = s[i];
|
||||
*idx = (*idx + 1) % bufferSize;
|
||||
uint32 current = *idx;
|
||||
uint32 spaceToEnd = bufferSize - current;
|
||||
|
||||
if (count <= spaceToEnd) {
|
||||
std::memcpy(&buffer[current], src, count);
|
||||
*idx = (current + count) % bufferSize;
|
||||
} else {
|
||||
std::memcpy(&buffer[current], src, spaceToEnd);
|
||||
uint32 remaining = count - spaceToEnd;
|
||||
std::memcpy(&buffer[0], (uint8*)src + spaceToEnd, remaining);
|
||||
*idx = remaining;
|
||||
}
|
||||
}
|
||||
|
||||
void ReadFromBuffer(uint32 *idx, void* dst, uint32 count) {
|
||||
uint8* d = (uint8*)dst;
|
||||
for (uint32 i=0; i<count; i++) {
|
||||
d[i] = buffer[*idx];
|
||||
*idx = (*idx + 1) % bufferSize;
|
||||
uint32 current = *idx;
|
||||
uint32 spaceToEnd = bufferSize - current;
|
||||
|
||||
if (count <= spaceToEnd) {
|
||||
std::memcpy(dst, &buffer[current], count);
|
||||
*idx = (current + count) % bufferSize;
|
||||
} else {
|
||||
std::memcpy(dst, &buffer[current], spaceToEnd);
|
||||
uint32 remaining = count - spaceToEnd;
|
||||
std::memcpy((uint8*)dst + spaceToEnd, &buffer[0], remaining);
|
||||
*idx = remaining;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef DEBUGFASTSCHEDULER_H
|
||||
#define DEBUGFASTSCHEDULER_H
|
||||
|
||||
#include "FastScheduler.h"
|
||||
#include "DebugService.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
class DebugFastScheduler : public FastScheduler {
|
||||
public:
|
||||
CLASS_REGISTER_DECLARATION()
|
||||
|
||||
DebugFastScheduler();
|
||||
virtual ~DebugFastScheduler();
|
||||
|
||||
virtual bool Initialise(StructuredDataI & data);
|
||||
|
||||
ErrorManagement::ErrorType Execute(ExecutionInfo &information);
|
||||
|
||||
protected:
|
||||
virtual void CustomPrepareNextState();
|
||||
|
||||
private:
|
||||
ErrorManagement::ErrorType DebugSetupThreadMap();
|
||||
|
||||
EmbeddedServiceMethodBinderT<DebugFastScheduler> debugBinder;
|
||||
DebugService *debugService;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
29
SPECS.md
29
SPECS.md
@@ -9,8 +9,33 @@ Implement a "Zero-Code-Change" observability layer for the MARTe2 real-time fram
|
||||
- **FR-02 (Telemetry):** Stream high-frequency signal data (verified up to 100Hz) to a remote client.
|
||||
- **FR-03 (Forcing):** Allow manual override of signal values in memory during execution.
|
||||
- **FR-04 (Logs):** Stream global framework logs to a dedicated terminal via a standalone `TcpLogger` service.
|
||||
- **FR-05 (Execution Control):** Pause and resume the real-time execution threads via scheduler injection.
|
||||
- **FR-06 (UI):** Provide a native, immediate-mode GUI for visualization (Oscilloscope).
|
||||
- **FR-05 (Log Filtering):** The client must support filtering logs by type (Debug, Information, Warning, FatalError) and by content using regular expressions.
|
||||
- **FR-06 (Execution & UI):**
|
||||
- Provide a native GUI for visualization.
|
||||
- Support Pause/Resume of real-time execution threads via scheduler injection.
|
||||
- **FR-07 (Session Management):**
|
||||
- The top panel must provide a "Disconnect" button to close active network streams.
|
||||
- Support runtime re-configuration and "Apply & Reconnect" logic.
|
||||
- **FR-08 (Decoupled Tracing):**
|
||||
Clicking `trace` activates telemetry; data is buffered and shown as a "Last Value" in the sidebar, but not plotted until manually assigned.
|
||||
- **FR-08 (Advanced Plotting):**
|
||||
- Support multiple plot panels with perfectly synchronized time (X) axes.
|
||||
- Drag-and-drop signals from the traced list into specific plots.
|
||||
- Automatic distinct color assignment for each signal added to a plot.
|
||||
- Plot modes: Standard (Time Series) and Logic Analyzer (Stacked rows).
|
||||
- Signal transformations: Gain, offset, units, and custom labels.
|
||||
- Visual styling: Deep customization of colors, line styles (Solid, Dashed, etc.), and marker shapes (Circle, Square, etc.).
|
||||
- **FR-09 (Navigation):**
|
||||
- Context menus for resetting zoom (X, Y, or both).
|
||||
- "Fit to View" functionality that automatically scales both axes to encompass all available buffered data points.
|
||||
- **FR-10 (Scope Mode):**
|
||||
- High-performance oscilloscope mode with configurable time windows (10ms to 10s).
|
||||
- Global synchronization of time axes across all plot panels.
|
||||
- Support for Free-run and Triggered acquisition (Single/Continuous, rising/falling edges).
|
||||
- **FR-11 (Data Recording):**
|
||||
- Record any traced signal to disk in Parquet format.
|
||||
- Native file dialog for destination selection.
|
||||
- Visual recording indicator in the GUI.
|
||||
|
||||
### 2.2 Technical Constraints (TC)
|
||||
- **TC-01:** No modifications allowed to the MARTe2 core library or component source code.
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
#include "DebugFastScheduler.h"
|
||||
#include "AdvancedErrorManagement.h"
|
||||
#include "ExecutionInfo.h"
|
||||
#include "MemoryOperationsHelper.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
const uint64 ALL_CPUS = 0xFFFFFFFFFFFFFFFFull;
|
||||
|
||||
DebugFastScheduler::DebugFastScheduler() :
|
||||
FastScheduler(),
|
||||
debugBinder(*this, &DebugFastScheduler::Execute)
|
||||
{
|
||||
debugService = NULL_PTR(DebugService*);
|
||||
}
|
||||
|
||||
DebugFastScheduler::~DebugFastScheduler() {
|
||||
}
|
||||
|
||||
bool DebugFastScheduler::Initialise(StructuredDataI & data) {
|
||||
bool ret = FastScheduler::Initialise(data);
|
||||
if (ret) {
|
||||
ReferenceContainer *root = ObjectRegistryDatabase::Instance();
|
||||
Reference serviceRef = root->Find("DebugService");
|
||||
if (serviceRef.IsValid()) {
|
||||
debugService = dynamic_cast<DebugService*>(serviceRef.operator->());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ErrorManagement::ErrorType DebugFastScheduler::DebugSetupThreadMap() {
|
||||
ErrorManagement::ErrorType err;
|
||||
ComputeMaxNThreads();
|
||||
REPORT_ERROR(ErrorManagement::Information, "DebugFastScheduler: Max Threads=%!", maxNThreads);
|
||||
|
||||
multiThreadService = new (NULL) MultiThreadService(debugBinder);
|
||||
multiThreadService->SetNumberOfPoolThreads(maxNThreads);
|
||||
err = multiThreadService->CreateThreads();
|
||||
if (err.ErrorsCleared()) {
|
||||
rtThreadInfo[0] = new RTThreadParam[maxNThreads];
|
||||
rtThreadInfo[1] = new RTThreadParam[maxNThreads];
|
||||
|
||||
for (uint32 i = 0u; i < numberOfStates; i++) {
|
||||
cpuMap[i] = new uint64[maxNThreads];
|
||||
for (uint32 j = 0u; j < maxNThreads; j++) {
|
||||
cpuMap[i][j] = ALL_CPUS;
|
||||
}
|
||||
}
|
||||
|
||||
if (countingSem.Create(maxNThreads)) {
|
||||
for (uint32 i = 0u; i < numberOfStates; i++) {
|
||||
uint32 nThreads = states[i].numberOfThreads;
|
||||
cpuThreadMap[i] = new uint32[nThreads];
|
||||
for (uint32 j = 0u; j < nThreads; j++) {
|
||||
uint64 cpu = static_cast<uint64>(states[i].threads[j].cpu.GetProcessorMask());
|
||||
CreateThreadMap(cpu, i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
void DebugFastScheduler::CustomPrepareNextState() {
|
||||
ErrorManagement::ErrorType err;
|
||||
|
||||
err = !realTimeApplicationT.IsValid();
|
||||
if (err.ErrorsCleared()) {
|
||||
uint8 nextBuffer = static_cast<uint8>(realTimeApplicationT->GetIndex());
|
||||
nextBuffer++;
|
||||
nextBuffer &= 0x1u;
|
||||
|
||||
if (!initialised) {
|
||||
cpuMap = new uint64*[numberOfStates];
|
||||
cpuThreadMap = new uint32*[numberOfStates];
|
||||
err = DebugSetupThreadMap();
|
||||
}
|
||||
if (err.ErrorsCleared()) {
|
||||
for (uint32 j = 0u; j < maxNThreads; j++) {
|
||||
rtThreadInfo[nextBuffer][j].executables = NULL_PTR(ExecutableI **);
|
||||
rtThreadInfo[nextBuffer][j].numberOfExecutables = 0u;
|
||||
rtThreadInfo[nextBuffer][j].cycleTime = NULL_PTR(uint32 *);
|
||||
rtThreadInfo[nextBuffer][j].lastCycleTimeStamp = 0u;
|
||||
}
|
||||
|
||||
ScheduledState *nextState = GetSchedulableStates()[nextBuffer];
|
||||
uint32 numberOfThreads = nextState->numberOfThreads;
|
||||
for (uint32 i = 0u; i < numberOfThreads; i++) {
|
||||
rtThreadInfo[nextBuffer][cpuThreadMap[nextStateIdentifier][i]].executables = nextState->threads[i].executables;
|
||||
rtThreadInfo[nextBuffer][cpuThreadMap[nextStateIdentifier][i]].numberOfExecutables = nextState->threads[i].numberOfExecutables;
|
||||
rtThreadInfo[nextBuffer][cpuThreadMap[nextStateIdentifier][i]].cycleTime = nextState->threads[i].cycleTime;
|
||||
rtThreadInfo[nextBuffer][cpuThreadMap[nextStateIdentifier][i]].lastCycleTimeStamp = 0u;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ErrorManagement::ErrorType DebugFastScheduler::Execute(ExecutionInfo & information) {
|
||||
ErrorManagement::ErrorType ret;
|
||||
|
||||
if (information.GetStage() == MARTe::ExecutionInfo::StartupStage) {
|
||||
}
|
||||
else if (information.GetStage() == MARTe::ExecutionInfo::MainStage) {
|
||||
uint32 threadNumber = information.GetThreadNumber();
|
||||
(void) eventSem.Wait(TTInfiniteWait);
|
||||
if (superFast == 0u) {
|
||||
(void) countingSem.WaitForAll(TTInfiniteWait);
|
||||
}
|
||||
|
||||
uint32 idx = static_cast<uint32>(realTimeApplicationT->GetIndex());
|
||||
|
||||
if (rtThreadInfo[idx] != NULL_PTR(RTThreadParam *)) {
|
||||
if (rtThreadInfo[idx][threadNumber].numberOfExecutables > 0u) {
|
||||
|
||||
// EXECUTION CONTROL HOOK
|
||||
if (debugService != NULL_PTR(DebugService*)) {
|
||||
while (debugService->IsPaused()) {
|
||||
Sleep::MSec(1);
|
||||
}
|
||||
}
|
||||
|
||||
bool ok = ExecuteSingleCycle(rtThreadInfo[idx][threadNumber].executables, rtThreadInfo[idx][threadNumber].numberOfExecutables);
|
||||
if (!ok) {
|
||||
if (errorMessage.IsValid()) {
|
||||
(void)MessageI::SendMessage(errorMessage, this);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 absTime = 0u;
|
||||
if (rtThreadInfo[idx][threadNumber].lastCycleTimeStamp != 0u) {
|
||||
uint64 tmp = (HighResolutionTimer::Counter() - rtThreadInfo[idx][threadNumber].lastCycleTimeStamp);
|
||||
float64 ticksToTime = (static_cast<float64>(tmp) * clockPeriod) * 1e6;
|
||||
absTime = static_cast<uint32>(ticksToTime);
|
||||
}
|
||||
uint32 sizeToCopy = static_cast<uint32>(sizeof(uint32));
|
||||
(void)MemoryOperationsHelper::Copy(rtThreadInfo[idx][threadNumber].cycleTime, &absTime, sizeToCopy);
|
||||
rtThreadInfo[idx][threadNumber].lastCycleTimeStamp = HighResolutionTimer::Counter();
|
||||
}
|
||||
else {
|
||||
(void) unusedThreadsSem.Wait(TTInfiniteWait);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
CLASS_REGISTER(DebugFastScheduler, "1.0")
|
||||
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "DebugService.h"
|
||||
#include "AdvancedErrorManagement.h"
|
||||
#include "StandardParser.h"
|
||||
#include "StreamString.h"
|
||||
#include "BasicSocket.h"
|
||||
#include "DebugBrokerWrapper.h"
|
||||
#include "DebugFastScheduler.h"
|
||||
#include "ObjectRegistryDatabase.h"
|
||||
#include "ClassRegistryItem.h"
|
||||
#include "ObjectBuilder.h"
|
||||
@@ -12,6 +12,15 @@
|
||||
#include "GAM.h"
|
||||
|
||||
// Explicitly include target brokers for templating
|
||||
#include "MemoryMapInputBroker.h"
|
||||
#include "MemoryMapOutputBroker.h"
|
||||
#include "MemoryMapSynchronisedInputBroker.h"
|
||||
#include "MemoryMapSynchronisedOutputBroker.h"
|
||||
#include "MemoryMapInterpolatedInputBroker.h"
|
||||
#include "MemoryMapMultiBufferInputBroker.h"
|
||||
#include "MemoryMapMultiBufferOutputBroker.h"
|
||||
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
|
||||
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
@@ -102,7 +111,8 @@ bool DebugService::Initialise(StructuredDataI & data) {
|
||||
}
|
||||
|
||||
if (isServer) {
|
||||
if (!traceBuffer.Init(1024 * 1024)) return false;
|
||||
// 8MB Buffer for lossless tracing at high frequency
|
||||
if (!traceBuffer.Init(8 * 1024 * 1024)) return false;
|
||||
|
||||
PatchRegistry();
|
||||
|
||||
@@ -168,10 +178,6 @@ void DebugService::PatchRegistry() {
|
||||
PatchItemInternal("MemoryMapSynchronisedMultiBufferInputBroker", &b8);
|
||||
static DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder b9;
|
||||
PatchItemInternal("MemoryMapSynchronisedMultiBufferOutputBroker", &b9);
|
||||
|
||||
// Patch Scheduler
|
||||
static ObjectBuilderT<DebugFastScheduler> schedBuilder;
|
||||
PatchItemInternal("FastScheduler", &schedBuilder);
|
||||
}
|
||||
|
||||
void DebugService::ProcessSignal(DebugSignalInfo* s, uint32 size) {
|
||||
@@ -341,7 +347,7 @@ ErrorManagement::ErrorType DebugService::Streamer(ExecutionInfo & info) {
|
||||
}
|
||||
|
||||
InternetHost dest(streamPort, streamIP.Buffer());
|
||||
udpSocket.SetDestination(dest);
|
||||
(void)udpSocket.SetDestination(dest);
|
||||
|
||||
uint8 packetBuffer[4096];
|
||||
uint32 packetOffset = 0;
|
||||
@@ -353,6 +359,7 @@ ErrorManagement::ErrorType DebugService::Streamer(ExecutionInfo & info) {
|
||||
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;
|
||||
if (packetOffset == 0) {
|
||||
@@ -361,36 +368,44 @@ ErrorManagement::ErrorType DebugService::Streamer(ExecutionInfo & info) {
|
||||
header.seq = sequenceNumber++;
|
||||
header.timestamp = HighResolutionTimer::Counter();
|
||||
header.count = 0;
|
||||
MemoryOperationsHelper::Copy(packetBuffer, &header, sizeof(TraceHeader));
|
||||
std::memcpy(packetBuffer, &header, sizeof(TraceHeader));
|
||||
packetOffset = sizeof(TraceHeader);
|
||||
}
|
||||
|
||||
// Packet Packing: Header + [ID:4][Size:4][Data:N]
|
||||
// If this sample doesn't fit, flush the current packet first
|
||||
if (packetOffset + 8 + size > 1400) {
|
||||
uint32 toWrite = packetOffset;
|
||||
udpSocket.Write((char8*)packetBuffer, toWrite);
|
||||
packetOffset = 0;
|
||||
(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;
|
||||
MemoryOperationsHelper::Copy(packetBuffer, &header, sizeof(TraceHeader));
|
||||
std::memcpy(packetBuffer, &header, sizeof(TraceHeader));
|
||||
packetOffset = sizeof(TraceHeader);
|
||||
}
|
||||
|
||||
MemoryOperationsHelper::Copy(&packetBuffer[packetOffset], &id, 4);
|
||||
MemoryOperationsHelper::Copy(&packetBuffer[packetOffset + 4], &size, 4);
|
||||
MemoryOperationsHelper::Copy(&packetBuffer[packetOffset + 8], sampleData, size);
|
||||
std::memcpy(&packetBuffer[packetOffset], &id, 4);
|
||||
std::memcpy(&packetBuffer[packetOffset + 4], &size, 4);
|
||||
std::memcpy(&packetBuffer[packetOffset + 8], sampleData, size);
|
||||
packetOffset += (8 + size);
|
||||
|
||||
// Update sample count in the current packet header
|
||||
TraceHeader *h = (TraceHeader*)packetBuffer;
|
||||
h->count++;
|
||||
}
|
||||
|
||||
// Flush any remaining data
|
||||
if (packetOffset > 0) {
|
||||
uint32 toWrite = packetOffset;
|
||||
udpSocket.Write((char8*)packetBuffer, toWrite);
|
||||
(void)udpSocket.Write((char8*)packetBuffer, toWrite);
|
||||
packetOffset = 0;
|
||||
}
|
||||
|
||||
// Only sleep if the buffer was completely empty
|
||||
if (!hasData) Sleep::MSec(1);
|
||||
}
|
||||
return ErrorManagement::NoError;
|
||||
@@ -419,7 +434,7 @@ void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
|
||||
uint32 count = ForceSignal(name.Buffer(), val.Buffer());
|
||||
if (client) {
|
||||
StreamString resp; resp.Printf("OK FORCE %u\n", count);
|
||||
uint32 s = resp.Size(); client->Write(resp.Buffer(), s);
|
||||
uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -429,7 +444,7 @@ void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
|
||||
uint32 count = UnforceSignal(name.Buffer());
|
||||
if (client) {
|
||||
StreamString resp; resp.Printf("OK UNFORCE %u\n", count);
|
||||
uint32 s = resp.Size(); client->Write(resp.Buffer(), s);
|
||||
uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -441,31 +456,31 @@ void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
|
||||
if (cmd.GetToken(decim, delims, term)) {
|
||||
AnyType decimVal(UnsignedInteger32Bit, 0u, &d);
|
||||
AnyType decimStr(CharString, 0u, decim.Buffer());
|
||||
TypeConvert(decimVal, decimStr);
|
||||
(void)TypeConvert(decimVal, decimStr);
|
||||
}
|
||||
uint32 count = TraceSignal(name.Buffer(), enable, d);
|
||||
if (client) {
|
||||
StreamString resp; resp.Printf("OK TRACE %u\n", count);
|
||||
uint32 s = resp.Size(); client->Write(resp.Buffer(), s);
|
||||
uint32 s = resp.Size(); (void)client->Write(resp.Buffer(), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (token == "DISCOVER") Discover(client);
|
||||
else if (token == "PAUSE") {
|
||||
SetPaused(true);
|
||||
if (client) { uint32 s = 3; 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; client->Write("OK\n", s); }
|
||||
if (client) { uint32 s = 3; (void)client->Write("OK\n", s); }
|
||||
}
|
||||
else if (token == "TREE") {
|
||||
StreamString json;
|
||||
json = "{\"Name\": \"Root\", \"Class\": \"ObjectRegistryDatabase\", \"Children\": [\n";
|
||||
ExportTree(ObjectRegistryDatabase::Instance(), json);
|
||||
(void)ExportTree(ObjectRegistryDatabase::Instance(), json);
|
||||
json += "\n]}\nOK TREE\n";
|
||||
uint32 s = json.Size();
|
||||
client->Write(json.Buffer(), s);
|
||||
(void)client->Write(json.Buffer(), s);
|
||||
}
|
||||
else if (token == "INFO") {
|
||||
StreamString path;
|
||||
@@ -479,7 +494,7 @@ void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
|
||||
else if (client) {
|
||||
const char* msg = "ERROR: Unknown command\n";
|
||||
uint32 s = StringHelper::Length(msg);
|
||||
client->Write(msg, s);
|
||||
(void)client->Write(msg, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -531,7 +546,7 @@ void DebugService::InfoNode(const char8* path, BasicTCPSocket *client) {
|
||||
|
||||
json += "}\nOK INFO\n";
|
||||
uint32 s = json.Size();
|
||||
client->Write(json.Buffer(), s);
|
||||
(void)client->Write(json.Buffer(), s);
|
||||
}
|
||||
|
||||
uint32 DebugService::ExportTree(ReferenceContainer *container, StreamString &json) {
|
||||
@@ -665,7 +680,7 @@ void DebugService::Discover(BasicTCPSocket *client) {
|
||||
if (client) {
|
||||
StreamString header = "{\n \"Signals\": [\n";
|
||||
uint32 s = header.Size();
|
||||
client->Write(header.Buffer(), s);
|
||||
(void)client->Write(header.Buffer(), s);
|
||||
mutex.FastLock();
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
StreamString line;
|
||||
@@ -676,12 +691,12 @@ void DebugService::Discover(BasicTCPSocket *client) {
|
||||
if (i < numberOfAliases - 1) line += ",";
|
||||
line += "\n";
|
||||
s = line.Size();
|
||||
client->Write(line.Buffer(), s);
|
||||
(void)client->Write(line.Buffer(), s);
|
||||
}
|
||||
mutex.FastUnLock();
|
||||
StreamString footer = " ]\n}\nOK DISCOVER\n";
|
||||
s = footer.Size();
|
||||
client->Write(footer.Buffer(), s);
|
||||
(void)client->Write(footer.Buffer(), s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -698,7 +713,7 @@ void DebugService::ListNodes(const char8* path, BasicTCPSocket *client) {
|
||||
StreamString header;
|
||||
header.Printf("Nodes under %s:\n", path ? path : "/");
|
||||
uint32 s = header.Size();
|
||||
client->Write(header.Buffer(), s);
|
||||
(void)client->Write(header.Buffer(), s);
|
||||
|
||||
ReferenceContainer *container = dynamic_cast<ReferenceContainer*>(ref.operator->());
|
||||
if (container) {
|
||||
@@ -709,7 +724,7 @@ void DebugService::ListNodes(const char8* path, BasicTCPSocket *client) {
|
||||
StreamString line;
|
||||
line.Printf(" %s [%s]\n", child->GetName(), child->GetClassProperties()->GetName());
|
||||
s = line.Size();
|
||||
client->Write(line.Buffer(), s);
|
||||
(void)client->Write(line.Buffer(), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -717,15 +732,15 @@ void DebugService::ListNodes(const char8* path, BasicTCPSocket *client) {
|
||||
DataSourceI *ds = dynamic_cast<DataSourceI*>(ref.operator->());
|
||||
if (ds) {
|
||||
StreamString dsHeader = " Signals:\n";
|
||||
s = dsHeader.Size(); client->Write(dsHeader.Buffer(), s);
|
||||
s = dsHeader.Size(); (void)client->Write(dsHeader.Buffer(), s);
|
||||
uint32 nSignals = ds->GetNumberOfSignals();
|
||||
for (uint32 i=0; i<nSignals; i++) {
|
||||
StreamString sname, line;
|
||||
ds->GetSignalName(i, sname);
|
||||
(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(); client->Write(line.Buffer(), s);
|
||||
s = line.Size(); (void)client->Write(line.Buffer(), s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -735,31 +750,31 @@ void DebugService::ListNodes(const char8* path, BasicTCPSocket *client) {
|
||||
uint32 nOut = gam->GetNumberOfOutputSignals();
|
||||
StreamString gamHeader;
|
||||
gamHeader.Printf(" Input Signals (%d):\n", nIn);
|
||||
s = gamHeader.Size(); client->Write(gamHeader.Buffer(), s);
|
||||
s = gamHeader.Size(); (void)client->Write(gamHeader.Buffer(), s);
|
||||
for (uint32 i=0; i<nIn; i++) {
|
||||
StreamString sname, line;
|
||||
gam->GetSignalName(InputSignals, i, sname);
|
||||
(void)gam->GetSignalName(InputSignals, i, sname);
|
||||
line.Printf(" %s\n", sname.Buffer());
|
||||
s = line.Size(); client->Write(line.Buffer(), s);
|
||||
s = line.Size(); (void)client->Write(line.Buffer(), s);
|
||||
}
|
||||
gamHeader.SetSize(0);
|
||||
gamHeader.Printf(" Output Signals (%d):\n", nOut);
|
||||
s = gamHeader.Size(); client->Write(gamHeader.Buffer(), s);
|
||||
s = gamHeader.Size(); (void)client->Write(gamHeader.Buffer(), s);
|
||||
for (uint32 i=0; i<nOut; i++) {
|
||||
StreamString sname, line;
|
||||
gam->GetSignalName(OutputSignals, i, sname);
|
||||
(void)gam->GetSignalName(OutputSignals, i, sname);
|
||||
line.Printf(" %s\n", sname.Buffer());
|
||||
s = line.Size(); client->Write(line.Buffer(), s);
|
||||
s = line.Size(); (void)client->Write(line.Buffer(), s);
|
||||
}
|
||||
}
|
||||
|
||||
const char* okMsg = "OK LS\n";
|
||||
s = StringHelper::Length(okMsg);
|
||||
client->Write(okMsg, s);
|
||||
(void)client->Write(okMsg, s);
|
||||
} else {
|
||||
const char* msg = "ERROR: Path not found\n";
|
||||
uint32 s = StringHelper::Length(msg);
|
||||
client->Write(msg, s);
|
||||
(void)client->Write(msg, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
Counter = {
|
||||
DataSource = Timer
|
||||
Type = uint32
|
||||
Frequency = 1
|
||||
Frequency = 1000
|
||||
}
|
||||
Time = {
|
||||
DataSource = Timer
|
||||
@@ -32,7 +32,6 @@
|
||||
DefaultDataSource = DDB
|
||||
+Timer = {
|
||||
Class = LinuxTimer
|
||||
SleepTime = 1000000
|
||||
Signals = {
|
||||
Counter = {
|
||||
Type = uint32
|
||||
@@ -43,7 +42,7 @@
|
||||
}
|
||||
}
|
||||
+Logger = {
|
||||
Class = LoggerDataSource
|
||||
Class = GAMDataSource
|
||||
Signals = {
|
||||
CounterCopy = {
|
||||
Type = uint32
|
||||
|
||||
@@ -7,201 +7,166 @@
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "RealTimeApplication.h"
|
||||
#include "GlobalObjectsDatabase.h"
|
||||
#include "RealTimeLoader.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace MARTe;
|
||||
|
||||
const char8 * const config_text =
|
||||
"+DebugService = {"
|
||||
// Removed '+' prefix from names for simpler lookup
|
||||
const char8 * const simple_config =
|
||||
"DebugService = {"
|
||||
" Class = DebugService "
|
||||
" ControlPort = 8080 "
|
||||
" UdpPort = 8081 "
|
||||
" StreamIP = \"127.0.0.1\" "
|
||||
"}"
|
||||
"+App = {"
|
||||
"App = {"
|
||||
" Class = RealTimeApplication "
|
||||
" +Functions = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +GAM1 = {"
|
||||
" Class = IOGAM "
|
||||
" InputSignals = {"
|
||||
" Counter = {"
|
||||
" DataSource = Timer "
|
||||
" Type = uint32 "
|
||||
" Frequency = 100 "
|
||||
" }"
|
||||
" Counter = { DataSource = Timer Type = uint32 Frequency = 1000 }"
|
||||
" Time = { DataSource = Timer Type = uint32 }"
|
||||
" }"
|
||||
" OutputSignals = {"
|
||||
" Counter = {"
|
||||
" DataSource = DDB "
|
||||
" Type = uint32 "
|
||||
" }"
|
||||
" Counter = { DataSource = DDB Type = uint32 }"
|
||||
" Time = { DataSource = DDB Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" +Data = {"
|
||||
" Class = ReferenceContainer "
|
||||
" DefaultDataSource = DDB "
|
||||
" +Timer = {"
|
||||
" Class = LinuxTimer "
|
||||
" SleepTime = 10000 "
|
||||
" Signals = {"
|
||||
" Counter = { Type = uint32 }"
|
||||
" Time = { Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" +DDB = {"
|
||||
" Class = GAMDataSource "
|
||||
" Signals = { Counter = { Type = uint32 } }"
|
||||
" }"
|
||||
" +Timer = { Class = LinuxTimer SleepTime = 1000 Signals = { Counter = { Type = uint32 } Time = { Type = uint32 } } }"
|
||||
" +DDB = { Class = GAMDataSource Signals = { Counter = { Type = uint32 } Time = { Type = uint32 } } }"
|
||||
" +DAMS = { Class = TimingDataSource }"
|
||||
" }"
|
||||
" +States = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +State1 = {"
|
||||
" Class = RealTimeState "
|
||||
" +Threads = {"
|
||||
" Class = ReferenceContainer "
|
||||
" +Thread1 = {"
|
||||
" Class = RealTimeThread "
|
||||
" Functions = {GAM1} "
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" }"
|
||||
" +Scheduler = {"
|
||||
" Class = GAMScheduler "
|
||||
" TimingDataSource = DAMS "
|
||||
" +State1 = { Class = RealTimeState +Threads = { Class = ReferenceContainer +Thread1 = { Class = RealTimeThread Functions = {GAM1} } } }"
|
||||
" }"
|
||||
" +Scheduler = { Class = GAMScheduler TimingDataSource = DAMS }"
|
||||
"}";
|
||||
|
||||
void RunValidationTest() {
|
||||
printf("--- MARTe2 100Hz Trace Validation Test ---\n");
|
||||
printf("--- MARTe2 1kHz Lossless Trace Validation Test ---\n");
|
||||
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
|
||||
ConfigurationDatabase cdb;
|
||||
StreamString ss = config_text;
|
||||
StreamString ss = simple_config;
|
||||
ss.Seek(0);
|
||||
StandardParser parser(ss, cdb);
|
||||
if (!parser.Parse()) {
|
||||
printf("ERROR: Failed to parse configuration\n");
|
||||
return;
|
||||
}
|
||||
assert(parser.Parse());
|
||||
|
||||
if (!ObjectRegistryDatabase::Instance()->Initialise(cdb)) {
|
||||
printf("ERROR: Failed to initialise ObjectRegistryDatabase.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ReferenceT<DebugService> service = ObjectRegistryDatabase::Instance()->Find("DebugService");
|
||||
if (!service.IsValid()) {
|
||||
printf("ERROR: DebugService not found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ReferenceT<RealTimeApplication> app = ObjectRegistryDatabase::Instance()->Find("App");
|
||||
if (!app.IsValid()) {
|
||||
printf("ERROR: App not found\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!app->ConfigureApplication()) {
|
||||
printf("ERROR: Failed to configure application\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->PrepareNextState("State1") != ErrorManagement::NoError) {
|
||||
printf("ERROR: Failed to prepare state State1\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->StartNextStateExecution() != ErrorManagement::NoError) {
|
||||
printf("ERROR: Failed to start execution\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Application and DebugService are active.\n");
|
||||
Sleep::MSec(1000);
|
||||
|
||||
// DIRECT ACTIVATION: Use the public TraceSignal method
|
||||
printf("Activating trace directly...\n");
|
||||
// We try multiple potential paths to be safe
|
||||
uint32 traceCount = 0;
|
||||
traceCount += service->TraceSignal("App.Data.Timer.Counter", true, 1);
|
||||
traceCount += service->TraceSignal("Timer.Counter", true, 1);
|
||||
traceCount += service->TraceSignal("Counter", true, 1);
|
||||
|
||||
printf("Trace enabled (Matched Aliases: %u)\n", traceCount);
|
||||
|
||||
// 4. Setup UDP Listener
|
||||
BasicUDPSocket listener;
|
||||
if (!listener.Open()) { printf("ERROR: Failed to open UDP socket\n"); return; }
|
||||
if (!listener.Listen(8081)) { printf("ERROR: Failed to listen on UDP 8081\n"); return; }
|
||||
|
||||
// 5. Validate for 10 seconds
|
||||
printf("Validating telemetry for 10 seconds...\n");
|
||||
uint32 lastVal = 0;
|
||||
bool first = true;
|
||||
uint32 packetCount = 0;
|
||||
uint32 discontinuityCount = 0;
|
||||
|
||||
float64 startTime = HighResolutionTimer::Counter() * HighResolutionTimer::Period();
|
||||
float64 globalTimeout = startTime + 30.0;
|
||||
|
||||
while ((HighResolutionTimer::Counter() * HighResolutionTimer::Period() - startTime) < 10.0) {
|
||||
if (HighResolutionTimer::Counter() * HighResolutionTimer::Period() > globalTimeout) {
|
||||
printf("CRITICAL ERROR: Global test timeout reached.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
char buffer[2048];
|
||||
uint32 size = 2048;
|
||||
TimeoutType timeout(200);
|
||||
cdb.MoveToRoot();
|
||||
uint32 n = cdb.GetNumberOfChildren();
|
||||
for (uint32 i=0; i<n; i++) {
|
||||
const char8* name = cdb.GetChildName(i);
|
||||
ConfigurationDatabase child;
|
||||
cdb.MoveRelative(name);
|
||||
cdb.Copy(child);
|
||||
cdb.MoveToAncestor(1u);
|
||||
|
||||
if (listener.Read(buffer, size, timeout)) {
|
||||
StreamString className;
|
||||
child.Read("Class", className);
|
||||
|
||||
Reference ref(className.Buffer(), GlobalObjectsDatabase::Instance()->GetStandardHeap());
|
||||
ref->SetName(name);
|
||||
assert(ref->Initialise(child));
|
||||
ObjectRegistryDatabase::Instance()->Insert(ref);
|
||||
}
|
||||
|
||||
Reference serviceGeneric = ObjectRegistryDatabase::Instance()->Find("DebugService");
|
||||
Reference appGeneric = ObjectRegistryDatabase::Instance()->Find("App");
|
||||
|
||||
if (!serviceGeneric.IsValid() || !appGeneric.IsValid()) {
|
||||
printf("ERROR: Objects NOT FOUND even without prefix\n");
|
||||
return;
|
||||
}
|
||||
|
||||
DebugService *service = dynamic_cast<DebugService*>(serviceGeneric.operator->());
|
||||
RealTimeApplication *app = dynamic_cast<RealTimeApplication*>(appGeneric.operator->());
|
||||
|
||||
assert(service);
|
||||
assert(app);
|
||||
|
||||
if (!app->ConfigureApplication()) {
|
||||
printf("ERROR: ConfigureApplication failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
assert(app->PrepareNextState("State1") == ErrorManagement::NoError);
|
||||
assert(app->StartNextStateExecution() == ErrorManagement::NoError);
|
||||
|
||||
printf("Application started at 1kHz. Enabling Traces...\n");
|
||||
Sleep::MSec(500);
|
||||
|
||||
// The registered name in DebugBrokerWrapper depends on GetFullObjectName
|
||||
// With App as root, it should be App.Data.Timer.Counter
|
||||
service->TraceSignal("App.Data.Timer.Counter", true, 1);
|
||||
|
||||
BasicUDPSocket listener;
|
||||
listener.Open();
|
||||
listener.Listen(8081);
|
||||
|
||||
printf("Validating for 10 seconds...\n");
|
||||
|
||||
uint32 lastCounter = 0;
|
||||
bool first = true;
|
||||
uint32 totalSamples = 0;
|
||||
uint32 discontinuities = 0;
|
||||
uint32 totalPackets = 0;
|
||||
|
||||
float64 startTest = HighResolutionTimer::Counter() * HighResolutionTimer::Period();
|
||||
|
||||
while ((HighResolutionTimer::Counter() * HighResolutionTimer::Period() - startTest) < 10.0) {
|
||||
char buffer[4096];
|
||||
uint32 size = 4096;
|
||||
if (listener.Read(buffer, size, TimeoutType(100))) {
|
||||
totalPackets++;
|
||||
TraceHeader *h = (TraceHeader*)buffer;
|
||||
if (h->magic == 0xDA7A57AD && h->count > 0) {
|
||||
uint32 offset = sizeof(TraceHeader);
|
||||
// Packet format: [Header][ID:4][Size:4][Value:N]
|
||||
if (h->magic != 0xDA7A57AD) continue;
|
||||
|
||||
uint32 offset = sizeof(TraceHeader);
|
||||
for (uint32 i=0; i<h->count; i++) {
|
||||
uint32 sigId = *(uint32*)(&buffer[offset]);
|
||||
uint32 val = *(uint32*)(&buffer[offset + 8]);
|
||||
|
||||
if (!first) {
|
||||
if (val != lastVal + 1) {
|
||||
discontinuityCount++;
|
||||
if (sigId == 0) {
|
||||
if (!first) {
|
||||
if (val != lastCounter + 1) {
|
||||
discontinuities++;
|
||||
}
|
||||
}
|
||||
lastCounter = val;
|
||||
totalSamples++;
|
||||
}
|
||||
lastVal = val;
|
||||
first = false;
|
||||
packetCount++;
|
||||
|
||||
if (packetCount % 200 == 0) {
|
||||
printf("Received %u packets... Current Value: %u\n", packetCount, val);
|
||||
}
|
||||
uint32 sigSize = *(uint32*)(&buffer[offset + 4]);
|
||||
offset += (8 + sigSize);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Test Finished.\n");
|
||||
printf("Total Packets Received: %u (Expected ~1000)\n", packetCount);
|
||||
printf("Discontinuities: %u\n", discontinuityCount);
|
||||
|
||||
float64 actualFreq = (float64)packetCount / 10.0;
|
||||
printf("Average Frequency: %.2f Hz\n", actualFreq);
|
||||
printf("\n--- Test Results ---\n");
|
||||
printf("Total UDP Packets: %u\n", totalPackets);
|
||||
printf("Total Counter Samples: %u\n", totalSamples);
|
||||
printf("Counter Discontinuities: %u\n", discontinuities);
|
||||
|
||||
if (packetCount < 100) {
|
||||
printf("FAILURE: Almost no packets received. Telemetry is broken.\n");
|
||||
} else if (packetCount < 800) {
|
||||
printf("WARNING: Too few packets received (Expected 1000, Got %u).\n", packetCount);
|
||||
} else if (discontinuityCount > 20) {
|
||||
printf("FAILURE: Too many discontinuities (%u).\n", discontinuityCount);
|
||||
if (totalSamples < 9000) {
|
||||
printf("FAILURE: Underflow - samples missing (%u).\n", totalSamples);
|
||||
} else if (discontinuities > 10) {
|
||||
printf("FAILURE: Excessive discontinuities detected! (%u)\n", discontinuities);
|
||||
} else {
|
||||
printf("VALIDATION SUCCESSFUL!\n");
|
||||
printf("VALIDATION SUCCESSFUL: 1kHz Lossless Tracing Verified.\n");
|
||||
}
|
||||
|
||||
app->StopCurrentStateExecution();
|
||||
listener.Close();
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
}
|
||||
|
||||
|
||||
977
Tools/gui_client/Cargo.lock
generated
977
Tools/gui_client/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -5,12 +5,14 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
eframe = "0.31.0"
|
||||
egui = "0.31.0"
|
||||
egui_plot = "0.31.0"
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
byteorder = "1.4"
|
||||
chrono = "0.4"
|
||||
crossbeam-channel = "0.5"
|
||||
regex = "1.12.3"
|
||||
regex = "1.10"
|
||||
socket2 = { version = "0.5", features = ["all"] }
|
||||
once_cell = "1.21"
|
||||
rfd = "0.15"
|
||||
parquet = { version = "53.0", features = ["arrow"] }
|
||||
arrow = "53.0"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user