Subversion Repositories Projects

Rev

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

Rev 2321 Rev 2324
Line 25... Line 25...
25
using System.Windows.Media.Imaging;
25
using System.Windows.Media.Imaging;
26
using System.Windows.Navigation;
26
using System.Windows.Navigation;
27
using System.Windows.Shapes;
27
using System.Windows.Shapes;
28
using System.Windows.Threading;
28
using System.Windows.Threading;
29
using System.Globalization;
29
using System.Globalization;
-
 
30
using System.Xml;
-
 
31
using System.Xml.Linq;
Line 30... Line 32...
30
 
32
 
31
namespace MKLiveView
33
namespace MKLiveView
32
{
34
{
33
    /// <summary>
35
    /// <summary>
Line 41... Line 43...
41
        GMapMarker home;
43
        GMapMarker home;
42
        PointLatLng start;
44
        PointLatLng start;
43
        PointLatLng end;
45
        PointLatLng end;
44
        PointLatLng pHome;
46
        PointLatLng pHome;
Line 45... Line -...
45
 
-
 
-
 
47
 
46
 
48
        #region NC-Errors
47
        String[] NC_Error = new string[44]
49
        String[] NC_Error = new string[44]
48
        {
50
        {
49
            "No Error",
51
            "No Error",
50
            "FC not compatible" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A1_.22FC_not_compatible_.22",
52
            "FC not compatible" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A1_.22FC_not_compatible_.22",
Line 89... Line 91...
89
            "ERR: 5V RC-Supply" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A40_.22ERR:_5V_RC-Supply.22",
91
            "ERR: 5V RC-Supply" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A40_.22ERR:_5V_RC-Supply.22",
90
            "ERR:Power-Supply" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A41_.22ERR:Power-Supply.22",
92
            "ERR:Power-Supply" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A41_.22ERR:Power-Supply.22",
91
            "ACC not calibr." + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A42_.22ACC_not_calibr..22",
93
            "ACC not calibr." + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A42_.22ACC_not_calibr..22",
92
            "ERR:Parachute!" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A43_.22ERR:Parachute.21.22"
94
            "ERR:Parachute!" + Environment.NewLine + "http://wiki.mikrokopter.de/ErrorCodes#A43_.22ERR:Parachute.21.22"
93
        };
95
        };
94
 
-
 
-
 
96
        #endregion NC-Errors
95
        [FlagsAttribute]
97
        [FlagsAttribute]
96
        enum NC_HWError0 : short
98
        enum NC_HWError0 : short
97
        {
99
        {
98
            None = 0,
100
            None = 0,
99
            SPI_RX = 1,
101
            SPI_RX = 1,
Line 144... Line 146...
144
        bool _blctrlDataAutorefresh = true;
146
        bool _blctrlDataAutorefresh = true;
145
        bool _OSDAutorefresh = true;
147
        bool _OSDAutorefresh = true;
146
        bool _bErrorLog = false;
148
        bool _bErrorLog = false;
147
        bool _bConnErr = false;
149
        bool _bConnErr = false;
148
        bool _bFollowCopter = false;
150
        bool _bFollowCopter = false;
-
 
151
        bool _bGPXLog = false;
Line 149... Line 152...
149
 
152
 
150
        bool _bSaveWinStateNormal = true;
153
        bool _bSaveWinStateNormal = true;
Line 151... Line 154...
151
        bool _bSaveWinStateFull = true;
154
        bool _bSaveWinStateFull = true;
Line 231... Line 234...
231
        int[] serChan_sub = new int[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
234
        int[] serChan_sub = new int[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
232
        string[] serChanTitle = new string[12];
235
        string[] serChanTitle = new string[12];
Line 233... Line 236...
233
 
236
 
234
        string[] sAnalogLabel = new string[32];
237
        string[] sAnalogLabel = new string[32];
-
 
238
        string[] sAnalogData = new string[32];
Line 235... Line 239...
235
        string[] sAnalogData = new string[32];
239
        int[] iAnalogData = new int[32];
236
 
240
 
237
        int[] iTimings = new int[] {100,150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000 };
241
        int[] iTimings = new int[] {100,150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000 };
238
        int[] iMotors = new int[] {3,4,5,6,7,8,9,10,11,12 };
242
        int[] iMotors = new int[] {3,4,5,6,7,8,9,10,11,12 };
Line 266... Line 270...
266
        static volatile int _iWPCount = -1;
270
        static volatile int _iWPCount = -1;
267
        static volatile int _iWPIndex = -1;
271
        static volatile int _iWPIndex = -1;
268
        int _iWPTimeout = 1000;
272
        int _iWPTimeout = 1000;
269
        bool _bGetWP = false;
273
        bool _bGetWP = false;
270
        static volatile bool _bGetWPCount = false;
274
        static volatile bool _bGetWPCount = false;
271
 
-
 
-
 
275
        DataTable dtGPX = new DataTable();
-
 
276
        DataRow drGPX;
-
 
277
        bool _bAirborne = false;
272
        DispatcherTimer timer = new DispatcherTimer();
278
        DispatcherTimer timer = new DispatcherTimer();
Line 273... Line 279...
273
 
279
 
274
        /// <summary>
280
        /// <summary>
275
        /// stuff for enabeling touch zoom for the map
281
        /// stuff for enabeling touch zoom for the map
Line 339... Line 345...
339
            cBoxTimingsNav.SelectedItem = navctrlInterval * 10;
345
            cBoxTimingsNav.SelectedItem = navctrlInterval * 10;
340
            cBoxTimingsBl.SelectedItem = blctrlInterval * 10;
346
            cBoxTimingsBl.SelectedItem = blctrlInterval * 10;
341
            cBoxTimingsOSD.SelectedItem = OSDInterval * 10;
347
            cBoxTimingsOSD.SelectedItem = OSDInterval * 10;
342
            checkBoxAutoSetHP.IsChecked = _bAutoHome;
348
            checkBoxAutoSetHP.IsChecked = _bAutoHome;
343
            checkBoxFollowCopter.IsChecked = _bFollowCopter;
349
            checkBoxFollowCopter.IsChecked = _bFollowCopter;
344
 
-
 
-
 
350
            checkBoxGPXLog.IsChecked = _bGPXLog;
Line 345... Line 351...
345
 
351
 
346
        }
352
        }
347
        /// <summary>
353
        /// <summary>
348
        /// initialize the datatables
354
        /// initialize the datatables
Line 386... Line 392...
386
            dtWaypoints.PrimaryKey = new DataColumn[] { dtWaypoints.Columns["Index"] };
392
            dtWaypoints.PrimaryKey = new DataColumn[] { dtWaypoints.Columns["Index"] };
387
            dgvWP.ItemsSource = dtWaypoints.DefaultView;
393
            dgvWP.ItemsSource = dtWaypoints.DefaultView;
388
            dgvWP.ColumnHeaderStyle = new Style();
394
            dgvWP.ColumnHeaderStyle = new Style();
389
            dgvWP.ColumnHeaderStyle = style;
395
            dgvWP.ColumnHeaderStyle = style;
Line -... Line 396...
-
 
396
 
-
 
397
            dtGPX.Columns.Add("Index",typeof(int));
-
 
398
            dtGPX.Columns.Add("Latitude",typeof(double));
-
 
399
            dtGPX.Columns.Add("Longitude",typeof(double));
-
 
400
            dtGPX.Columns.Add("Elevation",typeof(int));
-
 
401
            dtGPX.Columns.Add("Time",typeof(string));
-
 
402
            dtGPX.PrimaryKey = new DataColumn[] { dtGPX.Columns["Index"] };
Line 390... Line 403...
390
 
403
            drGPX = dtGPX.NewRow();
391
 
404
 
392
        }
405
        }
393
        /// <summary>
406
        /// <summary>
Line 424... Line 437...
424
        private void serialPortCtrl_PortClosed()
437
        private void serialPortCtrl_PortClosed()
425
        {
438
        {
426
            Dispatcher.Invoke(() => imageWiFi.Source = new BitmapImage(new Uri("Images/WiFi_W.png", UriKind.Relative)));
439
            Dispatcher.Invoke(() => imageWiFi.Source = new BitmapImage(new Uri("Images/WiFi_W.png", UriKind.Relative)));
427
            _readCont(false);
440
            _readCont(false);
428
        }
441
        }
-
 
442
        bool _bToggle = false;
429
        void timerEvent(object sender, EventArgs e)
443
        void timerEvent(object sender, EventArgs e)
430
        {
444
        {
431
            if (bReadContinously)
445
            if (bReadContinously)
432
            {
446
            {
433
                if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); }
447
                if (_debugDataAutorefresh) { _readDebugData(true); Thread.Sleep(10); }
Line 448... Line 462...
448
                {
462
                {
449
                    Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_G.png", UriKind.Relative)));
463
                    Dispatcher.Invoke(() => imageConn.Source = new BitmapImage(new Uri("Images/Data_G.png", UriKind.Relative)));
450
                  //  Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.LightGreen));
464
                  //  Dispatcher.Invoke((Action)(() => rctConnection.Fill = Brushes.LightGreen));
451
                    _iLifeCounter = 0;
465
                    _iLifeCounter = 0;
452
                    _bConnErr = false;
466
                    _bConnErr = false;
-
 
467
                //    if(_bAirborne && _bGPXLog)
-
 
468
                    {
-
 
469
                        drGPX[0] = dtGPX.Rows.Count;
-
 
470
                        dtGPX.Rows.Add(new object[] { drGPX[0], drGPX[1], drGPX[2], drGPX[3], drGPX[4] });
-
 
471
                    }
-
 
472
                    Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.Background = (_bGPXLog && _bToggle) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));
-
 
473
                    Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.Foreground = (_bGPXLog) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));
-
 
474
                    Dispatcher.Invoke((Action)(() => tbSideBarGPXLog.BorderBrush = (_bGPXLog) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));
-
 
475
                    _bToggle = !_bToggle;
453
                }
476
                }
454
                else
477
                else
455
                {
478
                {
456
                    if (!_bConnErr)
479
                    if (!_bConnErr)
457
                    {
480
                    {
Line 593... Line 616...
593
            _setMotorGridSize();
616
            _setMotorGridSize();
594
        }
617
        }
595
        private void Window_Closing(object sender, CancelEventArgs e)
618
        private void Window_Closing(object sender, CancelEventArgs e)
596
        {
619
        {
597
            _writeIni();
620
            _writeIni();
-
 
621
            if(_bGPXLog && dtGPX.Rows.Count > 0)
-
 
622
                _saveGPXLog();
598
        }
623
        }
599
        #endregion events
624
        #endregion events
Line 600... Line 625...
600
 
625
 
Line 1271... Line 1296...
1271
        /// <param name="data">the received byte array to process</param>
1296
        /// <param name="data">the received byte array to process</param>
1272
        void _processDebugVals(byte adr, byte[] data)
1297
        void _processDebugVals(byte adr, byte[] data)
1273
        {
1298
        {
1274
            if (data.Length == 66)
1299
            if (data.Length == 66)
1275
            {
1300
            {
1276
                int[] iAnalogData = new int[32];
-
 
-
 
1301
               
1277
                double v;
1302
                double v;
1278
                int index = 0;
1303
                int index = 0;
1279
                Int16 i16 = 0;
1304
                Int16 i16 = 0;
1280
                double dTemp = 0;
1305
                double dTemp = 0;
1281
                for (int i = 2; i < 66; i += 2)
1306
                for (int i = 2; i < 66; i += 2)
Line 1299... Line 1324...
1299
                                Dispatcher.Invoke((Action)(() => tbRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
1324
                                Dispatcher.Invoke((Action)(() => tbRoll.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0°")));
1300
                                break;
1325
                                break;
1301
                            case 4: //altitude
1326
                            case 4: //altitude
1302
                                Dispatcher.Invoke(() => tbAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m"));
1327
                                Dispatcher.Invoke(() => tbAlt.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m"));
1303
                                Dispatcher.Invoke(() => tbTopHeight.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m"));
1328
                                Dispatcher.Invoke(() => tbTopHeight.Text = ((double)iAnalogData[index] / (double)10).ToString("0.0 m"));
-
 
1329
                                Dispatcher.Invoke(() => { drGPX[3] = (double)iAnalogData[index] / (double)10; });
1304
                                break;
1330
                                break;
1305
                            case 7: //Voltage
1331
                            case 7: //Voltage
1306
                                v = (double)iAnalogData[index] / (double)10;
1332
                                v = (double)iAnalogData[index] / (double)10;
1307
                                Dispatcher.Invoke(() => tbVolt.Text = v.ToString("0.0 V"));
1333
                                Dispatcher.Invoke(() => tbVolt.Text = v.ToString("0.0 V"));
1308
                                Dispatcher.Invoke(() => tbTopVoltage.Text = v.ToString("0.0 V"));
1334
                                Dispatcher.Invoke(() => tbTopVoltage.Text = v.ToString("0.0 V"));
Line 1554... Line 1580...
1554
            iVal += i_32 << 16;
1580
            iVal += i_32 << 16;
1555
            i_32 = data[2];
1581
            i_32 = data[2];
1556
            iVal += i_32 << 8;
1582
            iVal += i_32 << 8;
1557
            iVal += data[1];
1583
            iVal += data[1];
1558
            d = (double)iVal / Math.Pow(10, 7);
1584
            d = (double)iVal / Math.Pow(10, 7);
-
 
1585
            Dispatcher.Invoke(() => { drGPX[2] = d; });
1559
           
1586
 
1560
            PointLatLng p = new PointLatLng();
1587
            PointLatLng p = new PointLatLng();
Line 1561... Line 1588...
1561
 
1588
 
1562
            p.Lng = d;
1589
            p.Lng = d;
1563
          //  lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = d.ToString("0.######°"))); //GPS-Position: Longitude in decimal degree
1590
          //  lblNCGPSLong.Invoke((Action)(() => lblNCGPSLong.Text = d.ToString("0.######°"))); //GPS-Position: Longitude in decimal degree
Line 1569... Line 1596...
1569
            iVal += i_32 << 16;
1596
            iVal += i_32 << 16;
1570
            i_32 = data[6];
1597
            i_32 = data[6];
1571
            iVal += i_32 << 8;
1598
            iVal += i_32 << 8;
1572
            iVal += data[5];
1599
            iVal += data[5];
1573
            d = (double)iVal / Math.Pow(10, 7);
1600
            d = (double)iVal / Math.Pow(10, 7);
-
 
1601
            Dispatcher.Invoke(() => { drGPX[1] = d; });
-
 
1602
            Dispatcher.Invoke(() => { drGPX[4] = DateTime.UtcNow.ToString("u", System.Globalization.CultureInfo.InvariantCulture); }); //2011-01-14T01:59:01Z });
1574
            p.Lat = d;
1603
            p.Lat = d;
1575
            if (data[50] > 4)//if more than 4 sats in use . otherwise the map would jump and scroll insane at beginning
1604
            if (data[50] > 4)//if more than 4 sats in use . otherwise the map would jump and scroll insane at beginning
1576
            {
1605
            {
1577
                _bSatFix = true; _iSatsJitter = 0; _bVoiceSatFixActive = false;
1606
                _bSatFix = true; _iSatsJitter = 0; _bVoiceSatFixActive = false;
1578
                if(_bAutoHome && !_bFirstSatFix)
1607
                if(_bAutoHome && !_bFirstSatFix)
Line 1756... Line 1785...
1756
            Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Text = ((data[68] & 4) == 4) ? "CH" : "PH"));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04
1785
            Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Text = ((data[68] & 4) == 4) ? "CH" : "PH"));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04
1757
            Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Background = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04
1786
            Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Background = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.LightSeaGreen) : new SolidColorBrush(Colors.Transparent)));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04
1758
            Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Foreground = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04
1787
            Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.Foreground = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04
1759
            Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.BorderBrush = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04
1788
            Dispatcher.Invoke((Action)(() => tbSideBarStatusPH.BorderBrush = (((data[68] & 2) == 2)|((data[68] & 4) == 4)) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Color.FromArgb(255, 211, 210, 210))));// NC_FLAG_PH 0x02 / NC_FLAG_CH 0x04
Line -... Line 1789...
-
 
1789
 
1760
 
1790
            _bAirborne = (data[67] & 2) == 2 ? true : false;
1761
        }
1791
        }
1762
        /// <summary>
1792
        /// <summary>
1763
        /// Navi-Ctrl WP data struct 'X'
1793
        /// Navi-Ctrl WP data struct 'X'
1764
        /// called by index
1794
        /// called by index
Line 2461... Line 2491...
2461
 
2491
 
2462
                sVal = ini.IniReadValue("map", "followMe");
2492
                sVal = ini.IniReadValue("map", "followMe");
2463
                if (sVal != "") _bFollowCopter = Convert.ToBoolean(sVal);
2493
                if (sVal != "") _bFollowCopter = Convert.ToBoolean(sVal);
2464
                sVal = ini.IniReadValue("map", "AutoSetHome");
2494
                sVal = ini.IniReadValue("map", "AutoSetHome");
-
 
2495
                if (sVal != "") _bAutoHome = Convert.ToBoolean(sVal);
-
 
2496
                sVal = ini.IniReadValue("map", "GPXLog");
Line 2465... Line 2497...
2465
                if (sVal != "") _bAutoHome = Convert.ToBoolean(sVal);
2497
                if (sVal != "") _bGPXLog = Convert.ToBoolean(sVal);
2466
 
2498
 
2467
                sVal = ini.IniReadValue("threshold", "VoltageWarning");
2499
                sVal = ini.IniReadValue("threshold", "VoltageWarning");
2468
                if(sVal != "") _dThresholdVoltageWarn = Convert.ToDouble(sVal);
2500
                if(sVal != "") _dThresholdVoltageWarn = Convert.ToDouble(sVal);
Line 2529... Line 2561...
2529
                ini.IniWriteValue("general", "LiPoCells", _LipoCells.ToString());
2561
                ini.IniWriteValue("general", "LiPoCells", _LipoCells.ToString());
2530
                ini.IniWriteValue("general", "Motors", _iMotors.ToString());
2562
                ini.IniWriteValue("general", "Motors", _iMotors.ToString());
Line 2531... Line 2563...
2531
 
2563
 
2532
                ini.IniWriteValue("map", "followMe", _bFollowCopter.ToString());
2564
                ini.IniWriteValue("map", "followMe", _bFollowCopter.ToString());
-
 
2565
                ini.IniWriteValue("map", "AutoSetHome", _bAutoHome.ToString());
Line 2533... Line 2566...
2533
                ini.IniWriteValue("map", "AutoSetHome", _bAutoHome.ToString());
2566
                ini.IniWriteValue("map", "GPXLog", _bGPXLog.ToString());
2534
 
2567
 
2535
                ini.IniWriteValue("topBar", "voltage", chkBoxTopBarShowVoltage.IsChecked.ToString());
2568
                ini.IniWriteValue("topBar", "voltage", chkBoxTopBarShowVoltage.IsChecked.ToString());
2536
                ini.IniWriteValue("topBar", "capacity", chkBoxTopBarShowCapacity.IsChecked.ToString());
2569
                ini.IniWriteValue("topBar", "capacity", chkBoxTopBarShowCapacity.IsChecked.ToString());
Line 2832... Line 2865...
2832
                }
2865
                }
2833
                else
2866
                else
2834
                    ((CustomMarkerCopter)(copter.Shape)).setColor("red");
2867
                    ((CustomMarkerCopter)(copter.Shape)).setColor("red");
2835
            });
2868
            });
2836
        }
2869
        }
-
 
2870
 
2837
        private void btnLoadWPLFile_Click(object sender, RoutedEventArgs e)
2871
        private void btnLoadWPLFile_Click(object sender, RoutedEventArgs e)
2838
        {
2872
        {
2839
            _readWPLFile();
2873
            _readWPLFile();
2840
        }
2874
        }
2841
        #endregion WP
2875
        #endregion WP
-
 
2876
        #region GPX
-
 
2877
        private void checkBoxGPXLog_Click(object sender, RoutedEventArgs e)
-
 
2878
        {
-
 
2879
            _bGPXLog = (bool)checkBoxGPXLog.IsChecked;
-
 
2880
        }
-
 
2881
        void _gpxAdd(double lat,double lon, int elevation)
-
 
2882
        {
-
 
2883
            DataRow dr = dtGPX.NewRow();
-
 
2884
            dr[0] = dtGPX.Rows.Count - 1;
-
 
2885
            dr[1] = lat;
-
 
2886
            dr[2] = lon;
-
 
2887
            dr[3] = elevation;
-
 
2888
            dr[4] = DateTime.UtcNow.ToString("s", System.Globalization.CultureInfo.InvariantCulture); //2011-01-14T01:59:01Z
-
 
2889
            dtGPX.Rows.Add(dr);
-
 
2890
        }
-
 
2891
        void _saveGPXLog()
-
 
2892
        {
-
 
2893
            if (!Directory.Exists("GPXLog"))
-
 
2894
                Directory.CreateDirectory("GPXLog");
-
 
2895
            string SaveFileName = "GPXLog\\" + DateTime.Now.ToString("yyyyMMdd_HHmm") + ".gpx";
-
 
2896
            XmlTextWriter myXmlTextWriter = null;
-
 
2897
            myXmlTextWriter = new XmlTextWriter(SaveFileName, null);
-
 
2898
            NumberFormatInfo nfi = new NumberFormatInfo();
-
 
2899
            nfi.NumberDecimalSeparator = ".";
-
 
2900
 
-
 
2901
            try
-
 
2902
            {
-
 
2903
                myXmlTextWriter.Formatting = Formatting.Indented;
-
 
2904
 
-
 
2905
                myXmlTextWriter.WriteStartDocument();
-
 
2906
 
-
 
2907
                myXmlTextWriter.WriteStartElement("gpx");
-
 
2908
 
-
 
2909
                myXmlTextWriter.WriteAttributeString("version", "1.0");
-
 
2910
                myXmlTextWriter.WriteAttributeString("creator", "MKLiveView v1.0");
-
 
2911
                myXmlTextWriter.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
-
 
2912
                myXmlTextWriter.WriteAttributeString("xmlns", "http://www.topografix.com/GPX/1/1");
-
 
2913
                myXmlTextWriter.WriteAttributeString("xsi:schemaLocation", "http://www.topografix.com/GPX/1/1/gpx.xsd");
-
 
2914
 
-
 
2915
                myXmlTextWriter.WriteElementString("time", DateTime.UtcNow.ToString("u", System.Globalization.CultureInfo.InvariantCulture));
-
 
2916
 
-
 
2917
                myXmlTextWriter.WriteStartElement("trk");
-
 
2918
                myXmlTextWriter.WriteStartElement("trkseg");
-
 
2919
                for(int i = 0; i< dtGPX.Rows.Count;i++)
-
 
2920
                {
-
 
2921
                    myXmlTextWriter.WriteStartElement("trkpt");
-
 
2922
                    myXmlTextWriter.WriteAttributeString("lat", dtGPX.Rows[i][1].ToString() != "" ? ((double)dtGPX.Rows[i][1]).ToString(nfi) : "");
-
 
2923
                    myXmlTextWriter.WriteAttributeString("lon", dtGPX.Rows[i][2].ToString() != "" ? ((double)dtGPX.Rows[i][2]).ToString(nfi) : "");
-
 
2924
                    myXmlTextWriter.WriteElementString("ele", dtGPX.Rows[i][3].ToString());
-
 
2925
                    myXmlTextWriter.WriteElementString("time", dtGPX.Rows[i][4].ToString());
-
 
2926
                    myXmlTextWriter.WriteEndElement();
-
 
2927
                }
-
 
2928
                myXmlTextWriter.WriteEndElement();
-
 
2929
                myXmlTextWriter.WriteEndElement();
-
 
2930
                myXmlTextWriter.WriteEndElement();
-
 
2931
            }
-
 
2932
            catch (Exception e)
-
 
2933
            {
-
 
2934
                Console.WriteLine("Exception: {0}", e.ToString());
-
 
2935
            }
-
 
2936
            finally
-
 
2937
            {
-
 
2938
                if (myXmlTextWriter != null)
-
 
2939
                {
-
 
2940
                    myXmlTextWriter.Close();
-
 
2941
                }
-
 
2942
            }
-
 
2943
        }
-
 
2944
 
-
 
2945
        private void btnLoadGPXLog_Click(object sender, RoutedEventArgs e)
-
 
2946
        {
-
 
2947
            _loadGPXLog();
-
 
2948
        }
Line -... Line 2949...
-
 
2949
 
-
 
2950
        void _loadGPXLog()
-
 
2951
        {
-
 
2952
 
-
 
2953
            Microsoft.Win32.OpenFileDialog fd = new Microsoft.Win32.OpenFileDialog();
-
 
2954
            fd.Filter = "GPX-Logfile | *.gpx";
-
 
2955
            fd.Multiselect = false;
-
 
2956
            if (fd.ShowDialog().Value)
-
 
2957
            {
-
 
2958
                string file = fd.FileName;
-
 
2959
                try
-
 
2960
                {
-
 
2961
                    XDocument gpxDoc = XDocument.Load(file);
-
 
2962
                    XNamespace gpx = XNamespace.Get("http://www.topografix.com/GPX/1/1");
-
 
2963
 
-
 
2964
                    NumberFormatInfo nfi = new NumberFormatInfo();
-
 
2965
                    nfi.NumberDecimalSeparator = ".";
-
 
2966
 
-
 
2967
                    var tracks = from track in gpxDoc.Descendants(gpx + "trk")
-
 
2968
                                 select new
-
 
2969
                                 {
-
 
2970
                                     Name = track.Element(gpx + "name") != null ? track.Element(gpx + "name").Value : null,
-
 
2971
                                     Segs = (
-
 
2972
                                         from trackpoint in track.Descendants(gpx + "trkpt")
-
 
2973
                                         select new
-
 
2974
                                         {
-
 
2975
                                             Latitude = trackpoint.Attribute("lat").Value,
-
 
2976
                                             Longitude = trackpoint.Attribute("lon").Value,
-
 
2977
                                             Elevation = trackpoint.Element(gpx + "ele") != null ?
-
 
2978
                                             trackpoint.Element(gpx + "ele").Value : null,
-
 
2979
                                             Time = trackpoint.Element(gpx + "time") != null ?
-
 
2980
                                             trackpoint.Element(gpx + "time").Value : null
-
 
2981
                                         }
-
 
2982
                                     )
-
 
2983
                                 };
-
 
2984
 
-
 
2985
                    List<PointLatLng> wpl = new List<PointLatLng>();
-
 
2986
                    foreach(var trk in tracks)
-
 
2987
                    {
-
 
2988
                        foreach(var trkseg in trk.Segs)
-
 
2989
                        {
-
 
2990
                            if(trkseg.Latitude != "" && trkseg.Longitude !="")
-
 
2991
                            wpl.Add(new PointLatLng(Convert.ToDouble(trkseg.Latitude, nfi), Convert.ToDouble(trkseg.Longitude, nfi)));
-
 
2992
                        }
-
 
2993
 
-
 
2994
                    }
-
 
2995
                    if(wpl.Count() > 0)
-
 
2996
                    {
-
 
2997
                        for (int k = 0; k < MainMap.Markers.Count;)
-
 
2998
                        {
-
 
2999
                            GMapMarker p = MainMap.Markers[k];
-
 
3000
                            if (p.Shape.GetType() == typeof(GMapRoute))
-
 
3001
                                MainMap.Markers.Remove(p);
-
 
3002
                            else
-
 
3003
                                k++;
-
 
3004
                        }
-
 
3005
                        MapRoute mr = new MapRoute(wpl, "flying");
-
 
3006
 
-
 
3007
                        GMapRoute mRoute = new GMapRoute(mr.Points);
-
 
3008
                        MainMap.Markers.Add(mRoute);
-
 
3009
                    }
-
 
3010
 
-
 
3011
                }
-
 
3012
                catch (Exception e)
-
 
3013
                {
-
 
3014
                    Console.WriteLine("Exception: {0}", e.ToString());
-
 
3015
                }
-
 
3016
            }
-
 
3017
        }
2842
 
3018
        #endregion GPX
2843
        #endregion functions
3019
        #endregion functions
2844
    }
3020
    }
2845
     /// <summary>
3021
     /// <summary>
2846
    /// formats the wp datatable values for display in datagrid - this is bound in the datagrid as a converter
3022
    /// formats the wp datatable values for display in datagrid - this is bound in the datagrid as a converter