Compare commits

3 Commits

Author SHA1 Message Date
Martino Ferrari
56bb3536fc Implemented all basic features 2026-02-23 13:17:16 +01:00
Martino Ferrari
6b1fc59fc0 Implemetned better buffering and high frequency tracing 2026-02-23 12:00:14 +01:00
Martino Ferrari
253a4989f9 Testing HF data 2026-02-23 11:24:32 +01:00
8 changed files with 501 additions and 728 deletions

View File

@@ -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;
}
}

View File

@@ -9,8 +9,25 @@ 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.
### 2.2 Technical Constraints (TC)
- **TC-01:** No modifications allowed to the MARTe2 core library or component source code.

View File

@@ -1,6 +1,7 @@
#include "DebugService.h"
#include "AdvancedErrorManagement.h"
#include "StandardParser.h"
#include "StreamString.h"
#include "BasicSocket.h"
#include "DebugBrokerWrapper.h"
#include "ObjectRegistryDatabase.h"
#include "ClassRegistryItem.h"
@@ -11,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 {
@@ -101,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();
@@ -167,7 +178,6 @@ void DebugService::PatchRegistry() {
PatchItemInternal("MemoryMapSynchronisedMultiBufferInputBroker", &b8);
static DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder b9;
PatchItemInternal("MemoryMapSynchronisedMultiBufferOutputBroker", &b9);
}
void DebugService::ProcessSignal(DebugSignalInfo* s, uint32 size) {
@@ -337,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;
@@ -349,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) {
@@ -357,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;
@@ -415,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);
}
}
}
@@ -425,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);
}
}
}
@@ -437,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;
@@ -475,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);
}
}
}
@@ -527,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) {
@@ -661,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;
@@ -672,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);
}
}
@@ -694,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) {
@@ -705,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);
}
}
}
@@ -713,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);
}
}
@@ -731,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);
}
}

View File

@@ -8,7 +8,7 @@
Counter = {
DataSource = Timer
Type = uint32
Frequency = 100
Frequency = 1000
}
Time = {
DataSource = Timer

View File

@@ -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");
assert(parser.Parse());
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);
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;
}
if (!ObjectRegistryDatabase::Instance()->Initialise(cdb)) {
printf("ERROR: Failed to initialise ObjectRegistryDatabase.\n");
return;
}
DebugService *service = dynamic_cast<DebugService*>(serviceGeneric.operator->());
RealTimeApplication *app = dynamic_cast<RealTimeApplication*>(appGeneric.operator->());
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;
}
assert(service);
assert(app);
if (!app->ConfigureApplication()) {
printf("ERROR: Failed to configure application\n");
printf("ERROR: ConfigureApplication failed.\n");
return;
}
if (app->PrepareNextState("State1") != ErrorManagement::NoError) {
printf("ERROR: Failed to prepare state State1\n");
return;
}
assert(app->PrepareNextState("State1") == ErrorManagement::NoError);
assert(app->StartNextStateExecution() == ErrorManagement::NoError);
if (app->StartNextStateExecution() != ErrorManagement::NoError) {
printf("ERROR: Failed to start execution\n");
return;
}
printf("Application started at 1kHz. Enabling Traces...\n");
Sleep::MSec(500);
printf("Application and DebugService are active.\n");
Sleep::MSec(1000);
// 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);
// 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; }
listener.Open();
listener.Listen(8081);
// 5. Validate for 10 seconds
printf("Validating telemetry for 10 seconds...\n");
uint32 lastVal = 0;
printf("Validating for 10 seconds...\n");
uint32 lastCounter = 0;
bool first = true;
uint32 packetCount = 0;
uint32 discontinuityCount = 0;
uint32 totalSamples = 0;
uint32 discontinuities = 0;
uint32 totalPackets = 0;
float64 startTime = HighResolutionTimer::Counter() * HighResolutionTimer::Period();
float64 globalTimeout = startTime + 30.0;
float64 startTest = HighResolutionTimer::Counter() * HighResolutionTimer::Period();
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);
if (listener.Read(buffer, size, timeout)) {
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);
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);
float64 actualFreq = (float64)packetCount / 10.0;
printf("Average Frequency: %.2f Hz\n", actualFreq);
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();
}

View File

@@ -1796,6 +1796,7 @@ dependencies = [
"crossbeam-channel",
"eframe",
"egui_plot",
"once_cell",
"regex",
"serde",
"serde_json",

View File

@@ -12,3 +12,4 @@ chrono = "0.4"
crossbeam-channel = "0.5"
regex = "1.10"
socket2 = { version = "0.5", features = ["all"] }
once_cell = "1.21.3"

File diff suppressed because it is too large Load Diff