1: void Update(string msg) { 2: float radius = this.ImageSize.Width / 2;
3: textBox2.Text = "";
4: lbDOP.Text = "";
5:
6: List<SatelliteView> result = Satellite.GetSatelliteViews(msg);
7: if (result.Count < 1) { 8: textBox2.Text = "no signal";
9: return;
10: }
11:
12: this.DrawRectangle();
13: foreach (SatelliteView sv in result) { 14: textBox2.AppendText(string.Format("prn:{0},elevation:{1},azimuth:{2},snr:{3},distance:{4}\n" 15: , sv.PRN.ToString(), sv.Elevation, sv.Azimuth, sv.SNR
16: , this.GetDistance(radius, sv.Elevation).ToString()
17: )
18: );
19: this.DrawPoint(sv.PRN, this.GetDistance(radius, sv.Elevation), sv.Azimuth, sv.SNR);
20: }
21:
22: SatelliteDOP dop = Satellite.GetDOP(msg);
23: this.ShowDOP(dop);
24: }
25:
26: void DrawRectangle() { 27: pictureBox1.Image = new Bitmap(this.ImageSize.Width, this.ImageSize.Height);
28: pictureBox1.BackColor = Color.WhiteSmoke;
29:
30: Graphics line = Graphics.FromImage(pictureBox1.Image);
31: line.DrawLine(Pens.Black, 0, this.ImageSize.Height / 2, this.ImageSize.Width, this.ImageSize.Height / 2);
32: line.DrawLine(Pens.Black, ImageSize.Width / 2, 0, ImageSize.Height / 2, ImageSize.Height);
33:
34: line.DrawString("N", new Font("arial", 8F), Brushes.Black, this.ImageSize.Width / 2 - 6, 0); 35: line.DrawString("E", new Font("arial", 8F), Brushes.Black, this.ImageSize.Width - 12, this.ImageSize.Height / 2 - 6); 36: line.DrawString("W", new Font("arial", 8F), Brushes.Black, 0, this.ImageSize.Height / 2 - 6); 37: line.DrawString("S", new Font("arial", 8F), Brushes.Black, this.ImageSize.Width / 2 - 6, this.ImageSize.Height - 12); 38:
39: }
40:
41: void DrawPoint(int prn , float distance, int degree , int? snr) { 42: double y = 0.0;
43: double x = 0.0;
44:
45: if (degree <= 90) { 46: x += ImageSize.Width / 2;
47: y = ImageSize .Height / 2 - Math.Abs(Math.Sin(Math.PI * degree / 180F) * distance);
48: x += Math.Abs(Math.Cos(Math.PI * degree / 180F) * distance);
49: }
50: if (degree > 90 && degree <= 180) { 51: x += ImageSize.Width / 2;
52: y += ImageSize.Height / 2;
53: degree = degree - 90;
54: y += Math.Abs(Math.Sin(Math.PI * degree / 180F) * distance);
55: x += Math.Abs(Math.Cos(Math.PI * degree / 180F) * distance);
56: }
57: if (degree > 180 && degree <= 270) { 58: y += ImageSize.Height / 2;
59: degree = degree - 180;
60: y += Math.Abs(Math.Cos(Math.PI * degree / 180F) * distance);
61: x = ImageSize.Width / 2 - Math.Abs(Math.Sin(Math.PI * degree / 180F) * distance);
62: }
63: if (degree > 270 && degree <= 360) { 64: degree = degree - 270;
65: y = ImageSize.Height / 2 - Math.Abs(Math.Sin(Math.PI * degree / 180F) * distance);
66: x = ImageSize.Width / 2 - Math.Abs(Math.Cos(Math.PI * degree / 180F) * distance);
67: }
68: Graphics circle = Graphics.FromImage(pictureBox1.Image);
69: circle.FillEllipse(this.GetSNRColor(snr), Convert.ToInt32(x) - 8, Convert.ToInt32(y) - 8, 16, 16);
70: circle.DrawString(prn.ToString(), new Font("arial" , 8F), Brushes.Black, Convert.ToInt32(x)-6, Convert.ToInt32(y)-6); 71: }
72:
73: Brush GetSNRColor(int? val) { 74: if (!val.HasValue) return Brushes.Black;
75: if (val < 20) return Brushes.Gray;
76: if (val >= 20 && val < 30) return Brushes.Pink;
77: if (val >= 30) return Brushes.Red;
78:
79: return Brushes.Black;
80: }