summaryrefslogtreecommitdiff
path: root/SimpleRadar_old/FormRadar.cs
blob: c1630afa9ed13388865131a8cae924398d6b5a98 (plain)
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IvyBus;
using System.Xml.Serialization;
using System.IO;

namespace SimpleRadar
{
    public partial class FormRadar : Form
    {
        static public int COMET_LENGTH = 5;

        public Dictionary<string, List<AircraftPosition>> RadarPlots;

        public FormRadar()
        {
            InitializeComponent();

            RadarPlots = new Dictionary<string, List<AircraftPosition>>();
        }

        private void FormRadar_Load(object sender, EventArgs e)
        {
            IvyBus.ivy.Start(ivyDomain.Domain);

            Bind();
        }

        private void Bind()
        {
            // ajoute la nouvelle regex
            //TrackMovedEvent Flight=324 CallSign=LB114JQ Ssr=0452 Sector=SL Layers=F,I X=87.00 Y=-128.88 Vx=-197 Vy=265 Afl=195 Rate=2098 Heading=323 GroundSpeed=330 Tendency=1 Time=12:08:32
            int regexp_id = IvyBus.ivy.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]+)",
                RecieveIvyMsgTrackMovedEvent, null);

            regexp_id = IvyBus.ivy.BindMsg(@"SelectionEvent acc=(.*) wp=(.*) role=(.*) Flight=([0-9]+)",
               SelectedAircraft, null);

      //      TheIvyBus.SendMsg("SelectionEvent acc=bordeaux wp=WP1 role=TC Flight=" + strip.SSR);

            //  int regexp_id1 = IvyBus.BindMsg(@"^ErasmusA Flight=(.*) Callsign=(.*) X=(.*) Y=(.*) Vx=(.*) Vy=(.*) Afl=(.*) Rate=(.*) Heading=(.*) GSpeed=(.*) EraGS=(.*) ManSta=(.*) Time=(.*)", RecieveIvyMsgErasmusSolve);
        }

        private void SelectedAircraft(object sender, IvyMessageEventArgs e)
        {
            userControlRadarView1.SelectedAircraft = e[3];

            userControlRadarView1.Invalidate();
        }
        private void RecieveIvyMsgTrackMovedEvent(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], IvyBus.Culture);
            pos.Y = double.Parse(e[6], IvyBus.Culture);
            pos.Vx = double.Parse(e[7], IvyBus.Culture);
            pos.Vy = double.Parse(e[8], IvyBus.Culture);
            pos.AFL = int.Parse(e[9], IvyBus.Culture);
            pos.Rate = int.Parse(e[10], IvyBus.Culture);
            pos.Heading = int.Parse(e[11], IvyBus.Culture);
            pos.GroundSpeed = double.Parse(e[12], IvyBus.Culture);
            pos.Tendency = int.Parse(e[13], IvyBus.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);
            UpdateView();
        }

        private void UpdateView()
        {
            userControlRadarView1.UpdateRadar(RadarPlots);
        }

        private void AddAircraftPosition(AircraftPosition pos)
        {

            if (!RadarPlots.ContainsKey(pos.CallSign))
            {
                //New radar Track
                if (!RadarPlots.ContainsKey(pos.CallSign))
                {
                    RadarPlots[pos.CallSign] = new List<AircraftPosition>();
                }
            }
            //Test if no more than CometLength Item
            if (RadarPlots[pos.CallSign].Count > COMET_LENGTH)
                RadarPlots[pos.CallSign].RemoveAt(0);

            RadarPlots[pos.CallSign].Add(pos);

        }


      



    }
}