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