Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
197 lines (172 loc) · 8.04 KB
/
Copy pathProgram.cs
File metadata and controls
197 lines (172 loc) · 8.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml;
using System.Xml.Serialization;
using Enterprise.Uci;
namespace LatticeUciBridge;
public record LatticeLocation(
[property: JsonPropertyName("latitude")] double Latitude,
[property: JsonPropertyName("longitude")] double Longitude,
[property: JsonPropertyName("altitude_meters")] double AltitudeMeters
);
public record LatticeKinematics(
[property: JsonPropertyName("heading_degrees")] double? HeadingDegrees,
[property: JsonPropertyName("ground_speed_mps")] double? GroundSpeedMps,
[property: JsonPropertyName("vertical_speed_mps")] double? VerticalSpeedMps,
[property: JsonPropertyName("airspeed_mps")] double? AirspeedMps,
[property: JsonPropertyName("pitch_degrees")] double? PitchDegrees,
[property: JsonPropertyName("roll_degrees")] double? RollDegrees
);
public record LatticeFlightPlan(
[property: JsonPropertyName("flight_mode")] string? FlightMode,
[property: JsonPropertyName("active_waypoint_id")] string? ActiveWaypointId,
[property: JsonPropertyName("fuel_remaining_percent")] double? FuelRemainingPercent
);
public record LatticeEntity(
[property: JsonPropertyName("id")] string Id,
[property: JsonPropertyName("callsign")] string? Callsign,
[property: JsonPropertyName("timestamp")] string Timestamp,
[property: JsonPropertyName("source_system")] string? SourceSystem,
[property: JsonPropertyName("classification")] string? Classification,
[property: JsonPropertyName("status")] string? Status,
[property: JsonPropertyName("location")] LatticeLocation Location,
[property: JsonPropertyName("kinematics")] LatticeKinematics Kinematics,
[property: JsonPropertyName("flight_plan")] LatticeFlightPlan? FlightPlan
);
public static class Program
{
private static string FindDataFile()
{
string[] candidates = {
"data/lattice_entity.json",
"../../data/lattice_entity.json",
"../data/lattice_entity.json"
};
foreach (var c in candidates)
{
if (File.Exists(c))
{
return Path.GetFullPath(c);
}
}
throw new FileNotFoundException("Could not locate data/lattice_entity.json");
}
private static EntityMt TranslateLatticeToUci(LatticeEntity lattice)
{
var ts = DateTimeOffset.TryParse(lattice.Timestamp, out var parsedTs)
? parsedTs
: DateTimeOffset.UtcNow;
var status = lattice.Status?.ToUpperInvariant() switch
{
"CONFIRMED" => EntityStatusEnum.Confirmed,
"TENTATIVE" => EntityStatusEnum.Tentative,
"LOST" => EntityStatusEnum.Lost,
"DROPPED" => EntityStatusEnum.Dropped,
"DESTROYED" => EntityStatusEnum.Destroyed,
_ => EntityStatusEnum.Potential
};
var entityId = new EntityIdType(lattice.Id, lattice.Callsign);
var kinematics = new KinematicsType(
lattice.Location.Latitude,
lattice.Location.Longitude,
lattice.Location.AltitudeMeters,
lattice.Kinematics.HeadingDegrees,
lattice.Kinematics.GroundSpeedMps,
lattice.Kinematics.VerticalSpeedMps,
lattice.Kinematics.AirspeedMps,
lattice.Kinematics.PitchDegrees,
lattice.Kinematics.RollDegrees
);
var mdt = new EntityMdt(
entityId,
ts,
status,
kinematics,
lattice.SourceSystem,
lattice.FlightPlan?.FlightMode,
lattice.FlightPlan?.ActiveWaypointId,
lattice.FlightPlan?.FuelRemainingPercent
);
return new EntityMt(ObjectStateEnum.Active, mdt)
{
SecurityInformation = new SecurityInformationType(ClassificationEnum.Unclassified, "USA"),
MessageHeader = new HeaderType(
$"MSG-{lattice.Id.Substring(0, 8).ToUpperInvariant()}",
ts,
lattice.SourceSystem ?? "LATTICE_MESH_NODE_DELTA"
)
};
}
public static void Main(string[] args)
{
Console.WriteLine("================================================================================");
Console.WriteLine("🛸 PolyXML: Anduril Lattice SDK ↔ USAF UCI C2 Bridge (C# 12 / .NET 8)");
Console.WriteLine(" Autonomous Flying Drone Airplane Telemetry (UNCLASSIFIED)");
Console.WriteLine("================================================================================");
var dataPath = FindDataFile();
var jsonBytes = File.ReadAllBytes(dataPath);
var lattice = JsonSerializer.Deserialize<LatticeEntity>(jsonBytes)!;
Console.WriteLine($"Ingesting Autonomous Drone Telemetry: {lattice.Callsign ?? "N/A"} (ID: {lattice.Id})");
// Benchmark XML Serialization
var swXml = Stopwatch.StartNew();
var uciEntity = TranslateLatticeToUci(lattice);
var xmlSerializer = new XmlSerializer(typeof(EntityMt));
var xmlSettings = new XmlWriterSettings
{
Indent = true,
OmitXmlDeclaration = true
};
using var stringWriter = new StringWriter();
using (var xmlWriter = XmlWriter.Create(stringWriter, xmlSettings))
{
var namespaces = new XmlSerializerNamespaces();
namespaces.Add("uci", "https://www.vdl.afrl.af.mil/programs/oam");
xmlSerializer.Serialize(xmlWriter, uciEntity, namespaces);
}
swXml.Stop();
var xmlOutput = stringWriter.ToString();
Console.WriteLine($"\n[1] Generated USAF UCI XML Message (latency: {swXml.Elapsed.TotalMicroseconds:F2} μs):");
Console.WriteLine(xmlOutput);
// Benchmark Native JSON Serialization on same record
var swJson = Stopwatch.StartNew();
var jsonOptions = new JsonSerializerOptions
{
WriteIndented = true
};
var jsonOutput = JsonSerializer.Serialize(uciEntity, jsonOptions);
swJson.Stop();
Console.WriteLine($"\n[2] Generated Native JSON on Same Model (latency: {swJson.Elapsed.TotalMicroseconds:F2} μs):");
Console.WriteLine(jsonOutput);
// Benchmark Native JSON Deserialization back into EntityMt record
var swFromJson = Stopwatch.StartNew();
var restoredUci = JsonSerializer.Deserialize<EntityMt>(jsonOutput);
swFromJson.Stop();
Console.WriteLine($"\n[3] Inherent JSON Deserialization into EntityMt (latency: {swFromJson.Elapsed.TotalMicroseconds:F2} μs):");
Console.WriteLine($" Restored UUID: {restoredUci?.MessageData.EntityId.Uuid}");
Console.WriteLine($" Restored Callsign: {restoredUci?.MessageData.EntityId.Callsign}");
Console.WriteLine($" Restored Coordinates: ({restoredUci?.MessageData.Kinematics.Latitude}, {restoredUci?.MessageData.Kinematics.Longitude})");
Console.WriteLine($" Restored Airspeed: {restoredUci?.MessageData.Kinematics.Airspeed} m/s | Pitch: {restoredUci?.MessageData.Kinematics.Pitch}° | Roll: {restoredUci?.MessageData.Kinematics.Roll}°");
Console.WriteLine($" Restored Flight Mode: {restoredUci?.MessageData.FlightMode}");
Console.WriteLine($" Restored Classification: {restoredUci?.SecurityInformation.Classification}");
if (restoredUci?.MessageData.EntityId.Uuid != lattice.Id)
{
throw new InvalidOperationException("UUID mismatch in C# JSON roundtrip");
}
if (!xmlOutput.Contains("EntityMT"))
{
throw new InvalidOperationException("Missing EntityMT in XML output");
}
if (!xmlOutput.Contains(lattice.Id))
{
throw new InvalidOperationException("Missing UUID in XML output");
}
if (!xmlOutput.Contains("UNCLASSIFIED"))
{
throw new InvalidOperationException("Missing UNCLASSIFIED in XML output");
}
Console.WriteLine("\n✅ C# 12 Lattice ↔ UCI Bridge executed successfully with dual attributes!");
}
}