Subversion Repositories Projects

Rev

Rev 2333 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2333 Rev 2335
Line 695... Line 695...
695
        }
695
        }
696
        void clearHomePos()
696
        void clearHomePos()
697
        {
697
        {
698
            MainMap.Markers.Remove(home);
698
            MainMap.Markers.Remove(home);
699
        }
699
        }
-
 
700
        void _clearMapMarkers(Type markerType)
-
 
701
        {
-
 
702
            for (int k = 0; k < MainMap.Markers.Count;)
-
 
703
            {
-
 
704
                GMapMarker p = MainMap.Markers[k];
-
 
705
                if (p.GetType() == markerType | p.Shape.GetType() == markerType)
-
 
706
                    MainMap.Markers.Remove(p);
-
 
707
                else
-
 
708
                    k++;
-
 
709
            }
-
 
710
 
-
 
711
        }
Line 700... Line 712...
700
 
712
 
701
        // access mode
713
        // access mode
702
        private void comboBoxMode_DropDownClosed(object sender, EventArgs e)
714
        private void comboBoxMode_DropDownClosed(object sender, EventArgs e)
703
        {
715
        {
Line 1653... Line 1665...
1653
                            Dispatcher.Invoke(() => stbSatFixLostAnim.Begin());
1665
                            Dispatcher.Invoke(() => stbSatFixLostAnim.Begin());
1654
                            _bAnimSatFixActive = true;
1666
                            _bAnimSatFixActive = true;
1655
                        }
1667
                        }
1656
                        if (_bVoiceSatFixPlay && !_bVoiceSatFixActive)
1668
                        if (_bVoiceSatFixPlay && !_bVoiceSatFixActive)
1657
                        {
1669
                        {
1658
                            Thread th = new Thread(() => _mediaPlayer("Voice\\CriticalBattery.mp3"));
1670
                            Thread th = new Thread(() => _mediaPlayer("Voice\\SatFixLost.mp3"));
1659
                            th.Start();
1671
                            th.Start();
1660
                            _bVoiceSatFixActive = true;
1672
                            _bVoiceSatFixActive = true;
1661
                        }
1673
                        }
Line 1662... Line 1674...
1662
 
1674
 
Line 1837... Line 1849...
1837
                        _setMarkerColor(wp, (int)dr[1]);
1849
                        _setMarkerColor(wp, (int)dr[1]);
1838
                        MainMap.Markers.Add(wp);
1850
                        MainMap.Markers.Add(wp);
1839
                    });
1851
                    });
1840
                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
1852
                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
1841
                    Dispatcher.Invoke(() => _iWPIndex = data[1]);
1853
                    Dispatcher.Invoke(() => _iWPIndex = data[1]);
-
 
1854
                    if ((int)dr[1] == 0)
1842
                    wpList.Add(new PointLatLng((double)dr[3], (double)dr[4]));
1855
                        wpList.Add(new PointLatLng((double)dr[3], (double)dr[4]));
1843
                    if (data[1] == data[0])
1856
                    if (data[1] == data[0])
1844
                    {
1857
                    {
1845
                        _bGetWP = false;
1858
                        _bGetWP = false;
1846
                        Dispatcher.Invoke(() => dgvWP.Items.Refresh());
1859
                        Dispatcher.Invoke(() => dgvWP.Items.Refresh());
Line 2084... Line 2097...
2084
                Log(LogMsgType.Error, "NOT CONNECTED!");
2097
                Log(LogMsgType.Error, "NOT CONNECTED!");
Line 2085... Line 2098...
2085
 
2098
 
2086
        }
2099
        }
2087
        void _getWP()
2100
        void _getWP()
-
 
2101
        {
2088
        {
2102
            int iTimeout = 0;
2089
            _bGetWPCount = true;
2103
            _bGetWPCount = true;
2090
            _getpWP(1); //get the itemscount of wp
2104
            _getpWP(1); //get the itemscount of wp
-
 
2105
            while (_bGetWPCount & iTimeout < _iWPTimeout * 5)
2091
            while (_bGetWPCount)
2106
            {
-
 
2107
                Thread.Sleep(10);
-
 
2108
                iTimeout++;
2092
                Thread.Sleep(100);
2109
            }
2093
            if (_iWPCount > 0)
2110
            if (_iWPCount > 0 & !_bGetWPCount)
2094
                _getWPList();
2111
                _getWPList();
2095
        }
2112
        }
2096
        void _getWPList()
2113
        void _getWPList()
2097
        {
2114
        {
Line 2108... Line 2125...
2108
                }
2125
                }
2109
            }
2126
            }
2110
        }
2127
        }
2111
        void _sendWPList()
2128
        void _sendWPList()
2112
        {
2129
        {
-
 
2130
            int iTimeout = 0;
2113
            if (serialPortCtrl.Port.IsOpen)
2131
            if (serialPortCtrl.Port.IsOpen)
2114
            {
2132
            {
2115
                byte[] bData = new byte[30];
2133
                byte[] bData = new byte[30];
2116
                for (int i = 0; i < 30; i++)
2134
                for (int i = 0; i < 30; i++)
2117
                    bData[i] = 0;
2135
                    bData[i] = 0;
2118
                Stream serialStream = serialPortCtrl.Port.BaseStream;
2136
                Stream serialStream = serialPortCtrl.Port.BaseStream;
2119
                byte[] bytes = FlightControllerMessage.CreateMessage('w', 2, bData); //delete all WP on Copter by sending 'invalid'(==0) at index 0
2137
                byte[] bytes = FlightControllerMessage.CreateMessage('w', 2, bData); //delete all WP on Copter by sending 'invalid'(==0) at index 0
2120
                serialStream.Write(bytes, 0, bytes.Length);
2138
                serialStream.Write(bytes, 0, bytes.Length);
Line 2121... Line 2139...
2121
 
2139
 
2122
                _iWPCount = -1;
2140
                _iWPCount = -1;
-
 
2141
                while (_iWPCount == -1 & iTimeout < _iWPTimeout * 5)
2123
                while (_iWPCount == -1)
2142
                {
-
 
2143
                    Thread.Sleep(10);
-
 
2144
                    iTimeout++;
2124
                    Thread.Sleep(10);
2145
                }
-
 
2146
                Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString());
-
 
2147
                if (_iWPCount > -1)
Line 2125... Line 2148...
2125
                Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString());
2148
                {
2126
 
2149
 
2127
                int iVal;
2150
                    int iVal;
2128
                double dVal;
2151
                    double dVal;
2129
                NumberFormatInfo nfi = new NumberFormatInfo();
2152
                    NumberFormatInfo nfi = new NumberFormatInfo();
2130
                nfi.NumberDecimalSeparator = ",";
2153
                    nfi.NumberDecimalSeparator = ",";
2131
                for (int i = 0; i < dtWaypoints.Rows.Count; i++)
2154
                    for (int i = 0; i < dtWaypoints.Rows.Count; i++)
2132
                {
2155
                    {
2133
                    //longitude
2156
                        //longitude
2134
                    dVal = Convert.ToDouble(dtWaypoints.Rows[i][4], nfi);
2157
                        dVal = Convert.ToDouble(dtWaypoints.Rows[i][4], nfi);
2135
                    iVal = (int)(dVal * Math.Pow(10, 7));
2158
                        iVal = (int)(dVal * Math.Pow(10, 7));
2136
                    bData[0] = (byte)(iVal & 0xff);
2159
                        bData[0] = (byte)(iVal & 0xff);
2137
                    bData[1] = (byte)((iVal >> 8) & 0xff);
2160
                        bData[1] = (byte)((iVal >> 8) & 0xff);
2138
                    bData[2] = (byte)((iVal >> 16) & 0xff);
2161
                        bData[2] = (byte)((iVal >> 16) & 0xff);
2139
                    bData[3] = (byte)(iVal >> 24);
2162
                        bData[3] = (byte)(iVal >> 24);
2140
                    //latitude
2163
                        //latitude
2141
                    dVal = Convert.ToDouble(dtWaypoints.Rows[i][3], nfi);
2164
                        dVal = Convert.ToDouble(dtWaypoints.Rows[i][3], nfi);
2142
                    iVal = (int)(dVal * Math.Pow(10, 7));
2165
                        iVal = (int)(dVal * Math.Pow(10, 7));
2143
                    bData[4] = (byte)(iVal & 0xff);
2166
                        bData[4] = (byte)(iVal & 0xff);
2144
                    bData[5] = (byte)((iVal >> 8) & 0xff);
2167
                        bData[5] = (byte)((iVal >> 8) & 0xff);
2145
                    bData[6] = (byte)((iVal >> 16) & 0xff);
2168
                        bData[6] = (byte)((iVal >> 16) & 0xff);
2146
                    bData[7] = (byte)(iVal >> 24);
2169
                        bData[7] = (byte)(iVal >> 24);
2147
                    //altitude
2170
                        //altitude
2148
                    dVal = Convert.ToDouble(dtWaypoints.Rows[i][5], nfi);
2171
                        dVal = Convert.ToDouble(dtWaypoints.Rows[i][5], nfi);
2149
                    iVal = (int)(dVal * 10);
2172
                        iVal = (int)(dVal * 10);
2150
                    bData[8] = (byte)(iVal & 0xff);
2173
                        bData[8] = (byte)(iVal & 0xff);
2151
                    bData[9] = (byte)((iVal >> 8) & 0xff);
2174
                        bData[9] = (byte)((iVal >> 8) & 0xff);
2152
                    bData[10] = (byte)((iVal >> 16) & 0xff);
2175
                        bData[10] = (byte)((iVal >> 16) & 0xff);
2153
                    bData[11] = (byte)(iVal >> 24);
2176
                        bData[11] = (byte)(iVal >> 24);
2154
                    //Status 'NEWDATA'
2177
                        //Status 'NEWDATA'
2155
                    bData[12] = 1;
2178
                        bData[12] = 1;
2156
                    //heading
2179
                        //heading
2157
                    iVal = Convert.ToInt16(dtWaypoints.Rows[i][6]);
2180
                        iVal = Convert.ToInt16(dtWaypoints.Rows[i][6]);
2158
                    bData[13] = (byte)(iVal & 0xff);
2181
                        bData[13] = (byte)(iVal & 0xff);
2159
                    bData[14] = (byte)((iVal >> 8) & 0xff);
2182
                        bData[14] = (byte)((iVal >> 8) & 0xff);
2160
                    //ToleranceRadius
2183
                        //ToleranceRadius
2161
                    bData[15] = Convert.ToByte(dtWaypoints.Rows[i][9]);
2184
                        bData[15] = Convert.ToByte(dtWaypoints.Rows[i][9]);
2162
                    //HoldTime
2185
                        //HoldTime
2163
                    bData[16] = Convert.ToByte(dtWaypoints.Rows[i][10]);
2186
                        bData[16] = Convert.ToByte(dtWaypoints.Rows[i][10]);
2164
                    //Event_Flag
2187
                        //Event_Flag
2165
                    bData[17] = Convert.ToByte(dtWaypoints.Rows[i][13]);
2188
                        bData[17] = Convert.ToByte(dtWaypoints.Rows[i][13]);
2166
                    //Index
2189
                        //Index
2167
                    bData[18] = Convert.ToByte((int)dtWaypoints.Rows[i][0]);
2190
                        bData[18] = Convert.ToByte((int)dtWaypoints.Rows[i][0]);
2168
                    //Type
2191
                        //Type
2169
                    bData[19] = Convert.ToByte(dtWaypoints.Rows[i][1]);
2192
                        bData[19] = Convert.ToByte(dtWaypoints.Rows[i][1]);
2170
                    //WP_EventChannelValue
2193
                        //WP_EventChannelValue
2171
                    bData[20] = Convert.ToByte(dtWaypoints.Rows[i][14]);
2194
                        bData[20] = Convert.ToByte(dtWaypoints.Rows[i][14]);
2172
                    //AltitudeRate
2195
                        //AltitudeRate
2173
                    bData[21] = Convert.ToByte(dtWaypoints.Rows[i][8]);
2196
                        bData[21] = Convert.ToByte(dtWaypoints.Rows[i][8]);
2174
                    //Speed
2197
                        //Speed
2175
                    bData[22] = Convert.ToByte(dtWaypoints.Rows[i][7]);
2198
                        bData[22] = Convert.ToByte(dtWaypoints.Rows[i][7]);
2176
                    //CamAngle
2199
                        //CamAngle
2177
                    bData[23] = (byte)Convert.ToInt16(dtWaypoints.Rows[i][12]);
2200
                        bData[23] = (byte)Convert.ToInt16(dtWaypoints.Rows[i][12]);
2178
                    //Name
2201
                        //Name
2179
                    byte[] name = ASCIIEncoding.ASCII.GetBytes((string)dtWaypoints.Rows[i][2]);
2202
                        byte[] name = ASCIIEncoding.ASCII.GetBytes((string)dtWaypoints.Rows[i][2]);
2180
                    bData[24] = name.Length > 0 ? name[0] : (byte)0;
2203
                        bData[24] = name.Length > 0 ? name[0] : (byte)0;
2181
                    bData[25] = name.Length > 1 ? name[1] : (byte)0;
2204
                        bData[25] = name.Length > 1 ? name[1] : (byte)0;
2182
                    bData[26] = name.Length > 2 ? name[2] : (byte)0;
2205
                        bData[26] = name.Length > 2 ? name[2] : (byte)0;
2183
                    bData[27] = name.Length > 3 ? name[3] : (byte)0;
2206
                        bData[27] = name.Length > 3 ? name[3] : (byte)0;
2184
                    //Autotrigger
2207
                        //Autotrigger
2185
                    bData[28] = Convert.ToByte(dtWaypoints.Rows[i][11]);
2208
                        bData[28] = Convert.ToByte(dtWaypoints.Rows[i][11]);
2186
 
2209
 
2187
                    bytes = FlightControllerMessage.CreateMessage('w', 2, bData);
2210
                        bytes = FlightControllerMessage.CreateMessage('w', 2, bData);
2188
                    serialStream.Write(bytes, 0, bytes.Length);
2211
                        serialStream.Write(bytes, 0, bytes.Length);
2189
 
2212
 
-
 
2213
                        _iWPCount = -1;
-
 
2214
                        iTimeout = 0;
2190
                    _iWPCount = -1;
2215
                        while (_iWPCount == -1 & iTimeout < _iWPTimeout * 5)
-
 
2216
                        {
-
 
2217
                            Thread.Sleep(10);
-
 
2218
                            iTimeout++;
-
 
2219
                        }
-
 
2220
                        if (_iWPCount == -1)
-
 
2221
                        {
-
 
2222
                            Log(LogMsgType.Error, "Timeout while sending list!");
2191
                    while (_iWPCount == -1)
2223
                            break;
-
 
2224
                        }
2192
                        Thread.Sleep(10);
2225
                        Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString());
-
 
2226
                    }
-
 
2227
                }
2193
                    Dispatcher.Invoke(() => lblWPCount.Content = _iWPCount.ToString());
2228
                else
2194
                }
2229
                    Log(LogMsgType.Error, "Timeout while sending list!");
2195
            }
2230
            }
Line 2196... Line 2231...
2196
            else
2231
            else
Line 2975... Line 3010...
2975
        }
3010
        }
2976
        private void btnLoadWPLFile_Click(object sender, RoutedEventArgs e)
3011
        private void btnLoadWPLFile_Click(object sender, RoutedEventArgs e)
2977
        {
3012
        {
2978
            _readWPLFile();
3013
            _readWPLFile();
2979
        }
3014
        }
-
 
3015
        private void btnClearWPList_Click(object sender, RoutedEventArgs e)
-
 
3016
        {
-
 
3017
            _clearMapMarkers(typeof(CustomMarkerWP));
-
 
3018
            wpList.Clear();
-
 
3019
            if (mRouteWP != null)
-
 
3020
                MainMap.Markers.Remove(mRouteWP);
-
 
3021
            dtWaypoints.Rows.Clear();
-
 
3022
            Dispatcher.Invoke(() => dgvWP.Items.Refresh());
-
 
3023
            Dispatcher.Invoke(() => lblWPIndex.Content = 0);
-
 
3024
            Dispatcher.Invoke(() => lblWPCount.Content = 0);
-
 
3025
            Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m");
-
 
3026
        }
2980
        #endregion WP
3027
        #endregion WP
-
 
3028
 
2981
        #region GPX
3029
        #region GPX
2982
        private void checkBoxGPXLog_Click(object sender, RoutedEventArgs e)
3030
        private void checkBoxGPXLog_Click(object sender, RoutedEventArgs e)
2983
        {
3031
        {
2984
            _bGPXLog = (bool)checkBoxGPXLog.IsChecked;
3032
            _bGPXLog = (bool)checkBoxGPXLog.IsChecked;
2985
        }
3033
        }
Line 3054... Line 3102...
3054
 
3102
 
3055
        private void btnClearRoute_Click(object sender, RoutedEventArgs e)
3103
        private void btnClearRoute_Click(object sender, RoutedEventArgs e)
3056
        {
3104
        {
3057
            _clearMapMarkers(typeof(GMapRoute));
3105
            _clearMapMarkers(typeof(GMapRoute));
3058
        }
-
 
3059
        void _clearMapMarkers(Type markerType)
-
 
3060
        {
-
 
3061
            for (int k = 0; k < MainMap.Markers.Count;)
-
 
3062
            {
-
 
3063
                GMapMarker p = MainMap.Markers[k];
-
 
3064
                if (p.GetType() == markerType | p.Shape.GetType() == markerType)
-
 
3065
                    MainMap.Markers.Remove(p);
-
 
3066
                else
-
 
3067
                    k++;
-
 
Line 3068... Line -...
3068
            }
-
 
3069
 
3106
        }
3070
        }
3107
 
Line 3071... Line 3108...
3071
        void _loadGPXLog()
3108
        void _loadGPXLog()
3072
        {
3109
        {