Updated with scheduler
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "BasicUDPSocket.h"
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "RealTimeApplication.h"
|
||||
#include "GlobalObjectsDatabase.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -28,6 +29,7 @@ const char8 * const config_text =
|
||||
" Counter = {"
|
||||
" DataSource = Timer "
|
||||
" Type = uint32 "
|
||||
" Frequency = 100 "
|
||||
" }"
|
||||
" }"
|
||||
" OutputSignals = {"
|
||||
@@ -46,6 +48,7 @@ const char8 * const config_text =
|
||||
" SleepTime = 10000 "
|
||||
" Signals = {"
|
||||
" Counter = { Type = uint32 }"
|
||||
" Time = { Type = uint32 }"
|
||||
" }"
|
||||
" }"
|
||||
" +DDB = {"
|
||||
@@ -76,7 +79,8 @@ const char8 * const config_text =
|
||||
void RunValidationTest() {
|
||||
printf("--- MARTe2 100Hz Trace Validation Test ---\n");
|
||||
|
||||
// 1. Load Configuration
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
|
||||
ConfigurationDatabase cdb;
|
||||
StreamString ss = config_text;
|
||||
ss.Seek(0);
|
||||
@@ -91,66 +95,70 @@ void RunValidationTest() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Start Application
|
||||
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;
|
||||
}
|
||||
|
||||
// We try to use State1 directly as many MARTe2 apps start in the first defined state if no transition is needed
|
||||
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");
|
||||
// We will try to investigate why, but for now we continue
|
||||
return;
|
||||
}
|
||||
|
||||
if (app->StartNextStateExecution() != ErrorManagement::NoError) {
|
||||
printf("ERROR: Failed to start execution. Maybe it needs an explicit state?\n");
|
||||
// return;
|
||||
printf("ERROR: Failed to start execution\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Application started at 100Hz.\n");
|
||||
printf("Application and DebugService are active.\n");
|
||||
Sleep::MSec(1000);
|
||||
|
||||
// 3. Enable Trace via TCP (Simulating GUI)
|
||||
BasicTCPSocket client;
|
||||
if (client.Connect("127.0.0.1", 8080)) {
|
||||
const char* cmd = "TRACE Root.App.Data.Timer.Counter 1\n";
|
||||
uint32 s = StringHelper::Length(cmd);
|
||||
client.Write(cmd, s);
|
||||
|
||||
char resp[1024]; s = 1024;
|
||||
TimeoutType timeout(1000);
|
||||
if (client.Read(resp, s, timeout)) {
|
||||
resp[s] = '\0';
|
||||
printf("Server Response: %s", resp);
|
||||
} else {
|
||||
printf("WARNING: No response from server to TRACE command.\n");
|
||||
}
|
||||
client.Close();
|
||||
} else {
|
||||
printf("ERROR: Failed to connect to DebugService on 8080\n");
|
||||
// continue anyway to see if it's already working
|
||||
}
|
||||
// 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 30 seconds
|
||||
printf("Validating telemetry for 30 seconds...\n");
|
||||
// 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) < 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(500);
|
||||
TimeoutType timeout(200);
|
||||
|
||||
if (listener.Read(buffer, size, timeout)) {
|
||||
TraceHeader *h = (TraceHeader*)buffer;
|
||||
@@ -168,7 +176,7 @@ void RunValidationTest() {
|
||||
first = false;
|
||||
packetCount++;
|
||||
|
||||
if (packetCount % 500 == 0) {
|
||||
if (packetCount % 200 == 0) {
|
||||
printf("Received %u packets... Current Value: %u\n", packetCount, val);
|
||||
}
|
||||
}
|
||||
@@ -176,17 +184,17 @@ void RunValidationTest() {
|
||||
}
|
||||
|
||||
printf("Test Finished.\n");
|
||||
printf("Total Packets Received: %u (Expected ~3000)\n", packetCount);
|
||||
printf("Total Packets Received: %u (Expected ~1000)\n", packetCount);
|
||||
printf("Discontinuities: %u\n", discontinuityCount);
|
||||
|
||||
float64 actualFreq = (float64)packetCount / 30.0;
|
||||
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 < 2500) {
|
||||
printf("WARNING: Too few packets received (Expected 3000, Got %u).\n", packetCount);
|
||||
} else if (discontinuityCount > 100) {
|
||||
} 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);
|
||||
} else {
|
||||
printf("VALIDATION SUCCESSFUL!\n");
|
||||
@@ -194,6 +202,7 @@ void RunValidationTest() {
|
||||
|
||||
app->StopCurrentStateExecution();
|
||||
listener.Close();
|
||||
ObjectRegistryDatabase::Instance()->Purge();
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
Reference in New Issue
Block a user