Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2458 | - | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.Data; |
||
4 | using System.Linq; |
||
5 | using System.Text; |
||
6 | |||
7 | namespace MKLiveView |
||
8 | { |
||
9 | static class Waypoints |
||
10 | { |
||
11 | |||
12 | public enum pointType |
||
13 | { |
||
14 | INVALID= 255, |
||
15 | WP = 0, |
||
16 | POI = 1, |
||
17 | FS = 2, |
||
18 | LAND = 3 |
||
19 | } |
||
20 | |||
21 | public enum status |
||
22 | { |
||
23 | INVALID= 255, |
||
24 | NEW = 0, |
||
25 | DONE = 1 |
||
26 | } |
||
27 | |||
28 | public static string CAMAngle(int iVal) |
||
29 | { |
||
30 | if (iVal == 255 | iVal < 0) |
||
31 | return "Auto"; |
||
32 | //if (iVal < 0) |
||
33 | // return "WP " + (Math.Abs(iVal)).ToString(); |
||
34 | if (iVal == 0) |
||
35 | return "- - -"; |
||
36 | |||
37 | return iVal.ToString("0 °"); |
||
38 | } |
||
39 | |||
40 | public static string WPSpeed(int iVal) |
||
41 | { |
||
42 | if (iVal == 0) |
||
43 | return "MAX"; |
||
44 | if (iVal > 0 && iVal < 248) |
||
45 | return ((double)iVal * 0.1).ToString("0.0 m/s"); |
||
46 | if (iVal > 247) |
||
47 | return "Poti" + (256 - iVal).ToString(); |
||
48 | |||
49 | return iVal.ToString(); |
||
50 | } |
||
51 | |||
52 | public static string Heading(int iVal) |
||
53 | { |
||
54 | if (iVal == 0) |
||
55 | return "- - -"; |
||
56 | if (iVal > 0 && iVal < 360) |
||
57 | return iVal.ToString("0 °"); |
||
58 | if (iVal < 0) |
||
59 | return "WP " + (Math.Abs(iVal)).ToString(); |
||
60 | |||
61 | return iVal.ToString(); |
||
62 | } |
||
63 | public static DataRow toDataRow(byte[]data, DataRow dr) |
||
64 | { |
||
65 | double longitude = 0, latitude = 0, altitude = 0; |
||
66 | int pstatus = 0, heading = 0, tolRadius = 0, holdTime = 0, eventFlag = 0, index = 0, type = 0, WPeventChanVal = 0, altitudeRate = 0, speed = 0, camAngle = 0, autoTrigger=0; |
||
67 | string name = ""; |
||
68 | |||
69 | if (data.Length >= 28) |
||
70 | { |
||
71 | int i_32, iVal; |
||
72 | |||
73 | i_32 = data[5]; |
||
74 | iVal = i_32 << 24; |
||
75 | i_32 = data[4]; |
||
76 | iVal += i_32 << 16; |
||
77 | i_32 = data[3]; |
||
78 | iVal += i_32 << 8; |
||
79 | iVal += data[2]; |
||
80 | longitude = (double)iVal / Math.Pow(10, 7); |
||
81 | |||
82 | i_32 = data[9]; |
||
83 | iVal = i_32 << 24; |
||
84 | i_32 = data[8]; |
||
85 | iVal += i_32 << 16; |
||
86 | i_32 = data[7]; |
||
87 | iVal += i_32 << 8; |
||
88 | iVal += data[6]; |
||
89 | latitude = (double)iVal / Math.Pow(10, 7); |
||
90 | |||
91 | |||
92 | i_32 = data[13]; |
||
93 | iVal = (i_32 << 24); |
||
94 | i_32 = data[12]; |
||
95 | iVal += i_32 << 16; |
||
96 | i_32 = data[11]; |
||
97 | iVal += i_32 << 8; |
||
98 | iVal += data[10]; |
||
99 | altitude = (double)iVal/10; |
||
100 | |||
101 | pstatus = data[14]; |
||
102 | |||
103 | i_32 = (int)(sbyte)data[16]; |
||
104 | iVal = i_32 << 8; |
||
105 | iVal += data[15]; |
||
106 | heading = iVal; |
||
107 | |||
108 | tolRadius = data[17]; |
||
109 | holdTime = data[18]; |
||
110 | eventFlag = data[19]; |
||
111 | index = data[1]; |
||
112 | // index = data[20]; |
||
113 | type = data[21]; |
||
114 | WPeventChanVal = data[22]; |
||
115 | altitudeRate = data[23]; |
||
116 | speed = data[24]; |
||
117 | camAngle = (int)(sbyte)data[25]; |
||
118 | |||
119 | name = new string(ASCIIEncoding.ASCII.GetChars(data, 26, 4)).Trim('\0'); |
||
120 | |||
121 | autoTrigger = data[30]; |
||
122 | dr.ItemArray = new object[] { data[1], type, name, latitude, longitude, altitude, heading, speed, altitudeRate, tolRadius, holdTime, autoTrigger, camAngle, eventFlag, WPeventChanVal, pstatus}; |
||
123 | |||
124 | // dr.ItemArray = new object[] { data[1], ((pointType)type).ToString(), name, longitude, latitude, altitude, heading, WPSpeed(speed), altitudeRate, tolRadius, holdTime, autoTrigger, CAMAngle(camAngle), eventFlag, WPeventChanVal, ((status)pstatus).ToString() }; |
||
125 | // dr.ItemArray = new object[] {data[1],((pointType)type).ToString(),name,longitude,latitude,altitude,heading,speed,altitudeRate,tolRadius,holdTime,autoTrigger, CAMAngle(camAngle),((status)pstatus).ToString() }; |
||
126 | return dr; |
||
127 | |||
128 | } |
||
129 | return null; |
||
130 | |||
131 | |||
132 | } |
||
133 | |||
134 | |||
135 | |||
136 | } |
||
137 | } |