Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2287 | - | 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 | |||
2312 | - | 12 | public enum pointType |
2287 | - | 13 | { |
14 | INVALID= 255, |
||
15 | WP = 0, |
||
2356 | - | 16 | POI = 1, |
2372 | - | 17 | FS = 2, |
18 | LAND = 3 |
||
2287 | - | 19 | } |
20 | |||
2312 | - | 21 | public enum status |
2287 | - | 22 | { |
23 | INVALID= 255, |
||
24 | NEW = 0, |
||
25 | DONE = 1 |
||
26 | } |
||
27 | |||
2312 | - | 28 | public static string CAMAngle(int iVal) |
2287 | - | 29 | { |
2313 | - | 30 | if (iVal == 255 | iVal < 0) |
2287 | - | 31 | return "Auto"; |
2313 | - | 32 | //if (iVal < 0) |
33 | // return "WP " + (Math.Abs(iVal)).ToString(); |
||
2287 | - | 34 | if (iVal == 0) |
35 | return "- - -"; |
||
36 | |||
2313 | - | 37 | return iVal.ToString("0 °"); |
2287 | - | 38 | } |
39 | |||
2312 | - | 40 | public static string WPSpeed(int iVal) |
2287 | - | 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"); |
||
2356 | - | 46 | if (iVal > 247) |
2287 | - | 47 | return "Poti" + (256 - iVal).ToString(); |
48 | |||
49 | return iVal.ToString(); |
||
50 | } |
||
51 | |||
2313 | - | 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 | } |
||
2287 | - | 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; |
||
2313 | - | 72 | |
2287 | - | 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]; |
||
2313 | - | 93 | iVal = (i_32 << 24); |
2287 | - | 94 | i_32 = data[12]; |
95 | iVal += i_32 << 16; |
||
96 | i_32 = data[11]; |
||
97 | iVal += i_32 << 8; |
||
98 | iVal += data[10]; |
||
2313 | - | 99 | altitude = (double)iVal/10; |
2287 | - | 100 | |
101 | pstatus = data[14]; |
||
102 | |||
2313 | - | 103 | i_32 = (int)(sbyte)data[16]; |
2287 | - | 104 | iVal = i_32 << 8; |
105 | iVal += data[15]; |
||
2313 | - | 106 | heading = iVal; |
2287 | - | 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]; |
||
2313 | - | 117 | camAngle = (int)(sbyte)data[25]; |
2287 | - | 118 | |
119 | name = new string(ASCIIEncoding.ASCII.GetChars(data, 26, 4)).Trim('\0'); |
||
120 | |||
121 | autoTrigger = data[30]; |
||
2313 | - | 122 | dr.ItemArray = new object[] { data[1], type, name, latitude, longitude, altitude, heading, speed, altitudeRate, tolRadius, holdTime, autoTrigger, camAngle, eventFlag, WPeventChanVal, pstatus}; |
2287 | - | 123 | |
2313 | - | 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() }; |
2287 | - | 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 | |||
2312 | - | 135 | |
2287 | - | 136 | } |
137 | } |