Compare commits
	
		
			5 Commits
		
	
	
		
			48cfc08e06
			...
			d67d4a8a04
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d67d4a8a04 | |||
| 2063583714 | |||
| 99f5cae65f | |||
| e65a5f3803 | |||
| a4f8f58804 | 
							
								
								
									
										26
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "version": "0.2.0",
 | 
				
			||||||
 | 
					    "configurations": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // Use IntelliSense to find out which attributes exist for C# debugging
 | 
				
			||||||
 | 
					            // Use hover for the description of the existing attributes
 | 
				
			||||||
 | 
					            // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
 | 
				
			||||||
 | 
					            "name": ".NET Core Launch (console)",
 | 
				
			||||||
 | 
					            "type": "coreclr",
 | 
				
			||||||
 | 
					            "request": "launch",
 | 
				
			||||||
 | 
					            "preLaunchTask": "build",
 | 
				
			||||||
 | 
					            // If you have changed target frameworks, make sure to update the program path.
 | 
				
			||||||
 | 
					            "program": "${workspaceFolder}/bin/Debug/net6.0/EFBTracker.dll",
 | 
				
			||||||
 | 
					            "args": [],
 | 
				
			||||||
 | 
					            "cwd": "${workspaceFolder}",
 | 
				
			||||||
 | 
					            // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
 | 
				
			||||||
 | 
					            "console": "externalTerminal",
 | 
				
			||||||
 | 
					            "stopAtEntry": false
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "name": ".NET Core Attach",
 | 
				
			||||||
 | 
					            "type": "coreclr",
 | 
				
			||||||
 | 
					            "request": "attach"
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										41
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "version": "2.0.0",
 | 
				
			||||||
 | 
					    "tasks": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "label": "build",
 | 
				
			||||||
 | 
					            "command": "dotnet",
 | 
				
			||||||
 | 
					            "type": "process",
 | 
				
			||||||
 | 
					            "args": [
 | 
				
			||||||
 | 
					                "build",
 | 
				
			||||||
 | 
					                "${workspaceFolder}/EFBTracker.csproj",
 | 
				
			||||||
 | 
					                "/property:GenerateFullPaths=true",
 | 
				
			||||||
 | 
					                "/consoleloggerparameters:NoSummary"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "problemMatcher": "$msCompile"
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "label": "publish",
 | 
				
			||||||
 | 
					            "command": "dotnet",
 | 
				
			||||||
 | 
					            "type": "process",
 | 
				
			||||||
 | 
					            "args": [
 | 
				
			||||||
 | 
					                "publish",
 | 
				
			||||||
 | 
					                "${workspaceFolder}/EFBTracker.csproj",
 | 
				
			||||||
 | 
					                "/property:GenerateFullPaths=true",
 | 
				
			||||||
 | 
					                "/consoleloggerparameters:NoSummary"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "problemMatcher": "$msCompile"
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "label": "watch",
 | 
				
			||||||
 | 
					            "command": "dotnet",
 | 
				
			||||||
 | 
					            "type": "process",
 | 
				
			||||||
 | 
					            "args": [
 | 
				
			||||||
 | 
					                "watch",
 | 
				
			||||||
 | 
					                "run",
 | 
				
			||||||
 | 
					                "--project",
 | 
				
			||||||
 | 
					                "${workspaceFolder}/EFBTracker.csproj"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "problemMatcher": "$msCompile"
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										37
									
								
								Program.cs
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								Program.cs
									
									
									
									
									
								
							@@ -1,2 +1,35 @@
 | 
				
			|||||||
// See https://aka.ms/new-console-template for more information
 | 
					using System.Net;
 | 
				
			||||||
Console.WriteLine("Hello, World!");
 | 
					using System.Net.Sockets;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using EFBTracker.Tracking;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool done = false;
 | 
				
			||||||
 | 
					int listenPort = 49003;
 | 
				
			||||||
 | 
					using(UdpClient listener = new UdpClient(listenPort))
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    IPEndPoint listenEndPoint = new IPEndPoint(2130706433, listenPort);
 | 
				
			||||||
 | 
					    while(!done)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        byte[] receivedData = listener.Receive(ref listenEndPoint);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Console.Clear();
 | 
				
			||||||
 | 
					        Console.WriteLine("Received broadcast message from client {0}", listenEndPoint.ToString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Console.WriteLine("Decoded data is:");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Packet[]? data = Packet.ReadPackets(receivedData);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (data != null)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            SimPosition position = new SimPosition(data);
 | 
				
			||||||
 | 
					            Console.WriteLine($"Latitude: {position.Latitude} Longitude: {position.Longitude} Altitude: {position.Altitude}");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										58
									
								
								Tracking/Packet.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								Tracking/Packet.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace EFBTracker.Tracking
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class Packet
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public string Type { get; set; }
 | 
				
			||||||
 | 
					        public int Id { get; set; }
 | 
				
			||||||
 | 
					        public float[] Data { get; set; } = new float[4];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public Packet(string type, int id, float[] data){
 | 
				
			||||||
 | 
					            Type = type;
 | 
				
			||||||
 | 
					            Id = id;
 | 
				
			||||||
 | 
					            Data = data;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public static Packet[]? ReadPackets(byte[] data){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if((data.Length - 5) % 36 == 0){//If there are correctly sized packets
 | 
				
			||||||
 | 
					                int packetPos = 0;
 | 
				
			||||||
 | 
					                List<Packet> packets = new List<Packet>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //Next 4 bytes are packet header
 | 
				
			||||||
 | 
					                string header = Encoding.UTF8.GetString(data, packetPos, 4);
 | 
				
			||||||
 | 
					                packetPos += 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                while(packetPos < data.Length)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    int id = BitConverter.ToInt32(data, packetPos);
 | 
				
			||||||
 | 
					                    packetPos += 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    //Array to take 4 values
 | 
				
			||||||
 | 
					                    float[] values = new float[4];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    for (var i = 0; i < values.Length; i++)
 | 
				
			||||||
 | 
					                    {//Read 4 values from packet and save into array
 | 
				
			||||||
 | 
					                        var value = BitConverter.ToSingle(data, packetPos);
 | 
				
			||||||
 | 
					                        values[i] = value;
 | 
				
			||||||
 | 
					                        packetPos += 8;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    //Generate new packet object and add to list
 | 
				
			||||||
 | 
					                    packets.Add(new Packet(header, id, values));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return packets.ToArray();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										26
									
								
								Tracking/SimPosition.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Tracking/SimPosition.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace EFBTracker.Tracking
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class SimPosition
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public float Latitude { get; set; }
 | 
				
			||||||
 | 
					        public float Longitude { get; set; }
 | 
				
			||||||
 | 
					        public int Altitude { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public SimPosition(Packet[] data){
 | 
				
			||||||
 | 
					            if (data[0].Data != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                //Use Linq to search through the packets for a given id and use that data
 | 
				
			||||||
 | 
					                Latitude = (data.Where(x => x.Id == 22).Select(x => x.Data[0]).ToArray())[0];
 | 
				
			||||||
 | 
					                Longitude = (data.Where(x => x.Id == 23).Select(x => x.Data[0]).ToArray())[0];
 | 
				
			||||||
 | 
					                Altitude = Convert.ToInt32((data.Where(x => x.Id == 24).Select(x => x.Data[0]).ToArray())[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user