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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IvyBus;
using System.Timers;
namespace Data
{
public class AircraftsList
{
private Dictionary<string, List<AircraftPosition>> listOfAircrafts;
private IvyBus.IvyControl TheIvyBus;
private List<IAircraftView> aircraftViews;
private Timer t_endWaitingForUpdate;
#region Constructeur
public AircraftsList(IvyBus.IvyControl TheIvyBus)
{
this.TheIvyBus = TheIvyBus;
listOfAircrafts = new Dictionary<string, List<AircraftPosition>>();
aircraftViews = new List<IAircraftView>();
t_endWaitingForUpdate = new Timer();
t_endWaitingForUpdate.Elapsed += new ElapsedEventHandler(HandleEndWaitingEvent);
t_endWaitingForUpdate.Interval = 4000;
t_endWaitingForUpdate.Start();
TheIvyBus.BindMsg(@"^TrackMovedEvent Flight=([0-9]+) CallSign=([a-zA-Z0-9_-]+) Ssr=([0-9]*)[ ]+Sector=(.*) Layers=(.*) X=(.+) Y=(.+) Vx=(.+) Vy=(.+) Afl=([0-9]+) Rate=(-?[0-9]+) Heading=([-\.0-9]+) GroundSpeed=([0-9]+) Tendency=(-?[0-9]) Time=([0-9]+:[0-9]+:[0-9]+)",
UpdateFlight, null);
}
#endregion
#region listGestion
private void AddAircraftPosition(AircraftPosition pos)
{
if (!listOfAircrafts.ContainsKey(pos.CallSign))
{
//New radar Track
listOfAircrafts[pos.CallSign] = new List<AircraftPosition>();
}
//Test if no more than CometLength Item
if (listOfAircrafts[pos.CallSign].Count > Config.aircraftCometLength)
listOfAircrafts[pos.CallSign].RemoveAt(0);
listOfAircrafts[pos.CallSign].Add(pos);
}
public Dictionary<string, List<AircraftPosition>> getAircraftList()
{
return listOfAircrafts;
}
#endregion
#region MVCAircraftViews
public void addAircraftView(IAircraftView view)
{
aircraftViews.Add(view);
}
public void removeAircraftView(IAircraftView view)
{
aircraftViews.Remove(view);
}
private void notifyAircraftViews()
{
foreach (IAircraftView view in aircraftViews)
{
view.updateView(listOfAircrafts);
}
}
#endregion
#region IvyGestion
private void UpdateFlight(object sender, IvyMessageEventArgs e)
{
//Create new aircraft and store it
AircraftPosition pos = new AircraftPosition();
pos.Flight = e[0];
pos.CallSign = e[1];
pos.Ssr = e[2];
pos.Sector = e[3];
pos.Layers = e[4];
pos.X = double.Parse(e[5], TheIvyBus.Culture);
pos.Y = double.Parse(e[6], TheIvyBus.Culture);
pos.Vx = double.Parse(e[7], TheIvyBus.Culture);
pos.Vy = double.Parse(e[8], TheIvyBus.Culture);
pos.AFL = int.Parse(e[9], TheIvyBus.Culture);
pos.Rate = int.Parse(e[10], TheIvyBus.Culture);
pos.Heading = int.Parse(e[11], TheIvyBus.Culture);
pos.GroundSpeed = double.Parse(e[12], TheIvyBus.Culture);
pos.Tendency = int.Parse(e[13], TheIvyBus.Culture);
//Parse the time
string sTime = e[14];
string[] time = sTime.Split(':');
pos.Time_Of_Plot = Convert.ToInt32(time[2]) +
Convert.ToInt32(time[1]) * 60 +
Convert.ToInt32(time[0]) * 3600;
AddAircraftPosition(pos);
notifyAircraftViews();
t_endWaitingForUpdate.Stop();
t_endWaitingForUpdate.Start();
}
#endregion
#region TimerGestion
public void HandleEndWaitingEvent(object source, ElapsedEventArgs e)
{
Console.WriteLine("Vue forcée");
TheIvyBus.SendMsg("GetRadarRefresh");
t_endWaitingForUpdate.Start();
}
#endregion
}
}
|