Changeset - 6b1dee8bd7ef
[Not reviewed]
default
0 1 0
mkanning@CL-ENS241-10.cedarville.edu - 13 years ago 2013-02-14 16:26:44
mkanning@CL-ENS241-10.cedarville.edu
fixed some mapping bugs and found converter for GPS
1 file changed with 31 insertions and 9 deletions:
0 comments (0 inline, 0 general)
Demo.WindowsForms/Forms/MainForm.cs
Show inline comments
 
@@ -223,97 +223,97 @@ namespace Demo.WindowsForms
 
                    {
 
                        MainMap.ZoomAndCenterMarkers(null);
 
                    }
 
 
                    //RegeneratePolygon();
 
 
                    try
 
                    {
 
                        GMapOverlay overlay = DeepClone<GMapOverlay>(objects);
 
                        Debug.WriteLine("ISerializable status for markers: OK");
 
 
                        //GMapOverlay overlay2 = DeepClone<GMapOverlay>(polygons);
 
                        //Debug.WriteLine("ISerializable status for polygons: OK");
 
 
                        GMapOverlay overlay3 = DeepClone<GMapOverlay>(routes);
 
                        Debug.WriteLine("ISerializable status for routes: OK");
 
                    }
 
                    catch (Exception ex)
 
                    {
 
                        Debug.WriteLine("ISerializable failure: " + ex.Message);
 
 
#if DEBUG
 
                        if (Debugger.IsAttached)
 
                        {
 
                            Debugger.Break();
 
                        }
 
#endif
 
                    }
 
                }
 
            }
 
        }
 
 
        public T DeepClone<T>(T obj)
 
        {
 
            using (var ms = new System.IO.MemoryStream())
 
            {
 
                var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
 
 
                formatter.Serialize(ms, obj);
 
 
                ms.Position = 0;
 
 
                return (T)formatter.Deserialize(ms);
 
            }
 
        }
 
 
        void Markers_CollectionChanged(object sender, GMap.NET.ObjectModel.NotifyCollectionChangedEventArgs e)
 
        {
 
            textBoxMarkerCount.Text = objects.Markers.Count.ToString();
 
            //textBoxMarkerCount.Text = objects.Markers.Count.ToString();
 
        }
 
 
        void Routes_CollectionChanged(object sender, GMap.NET.ObjectModel.NotifyCollectionChangedEventArgs e)
 
        {
 
            textBoxrouteCount.Text = routes.Routes.Count.ToString();
 
        }
 
 
        #region -- performance test --
 
 
        double NextDouble(Random rng, double min, double max)
 
        {
 
            return min + (rng.NextDouble() * (max - min));
 
        }
 
 
        int tt = 0;
 
        void timer_Tick(object sender, EventArgs e)
 
        {
 
            var pos = new PointLatLng(NextDouble(rnd, MainMap.ViewArea.Top, MainMap.ViewArea.Bottom), NextDouble(rnd, MainMap.ViewArea.Left, MainMap.ViewArea.Right));
 
            GMapMarker m = new GMarkerGoogle(pos, GMarkerGoogleType.green_pushpin);
 
            {
 
                m.ToolTipText = (tt++).ToString();
 
                m.ToolTipMode = MarkerTooltipMode.Always;
 
            }
 
 
            objects.Markers.Add(m);
 
 
            if (tt >= 333)
 
            {
 
                timerPerf.Stop();
 
                tt = 0;
 
            }
 
        }
 
 
        System.Windows.Forms.Timer timerPerf = new System.Windows.Forms.Timer();
 
        #endregion
 
 
        #region -- flight demo --
 
        //BackgroundWorker flightWorker = new BackgroundWorker();
 
 
        //readonly List<FlightRadarData> flights = new List<FlightRadarData>();
 
        //readonly Dictionary<int, GMapMarker> flightMarkers = new Dictionary<int, GMapMarker>();
 
 
        //bool firstLoadFlight = true;
 
        //GMapMarker currentFlight;
 
 
        //void flight_ProgressChanged(object sender, ProgressChangedEventArgs e)
 
        //{
 
        //    // stops immediate marker/route/polygon invalidations;
 
@@ -2376,97 +2376,97 @@ namespace Demo.WindowsForms
 
                                MainMap.ZoomAndCenterRoutes(null);
 
                            }
 
                        }
 
                    }
 
                    catch (Exception ex)
 
                    {
 
                        Debug.WriteLine("GPX import: " + ex.ToString());
 
                        MessageBox.Show("Error importing gpx: " + ex.Message, "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning);
 
                    }
 
                }
 
            }
 
        }
 
 
        // enable/disable host tracing
 
        //private void checkBoxTraceRoute_CheckedChanged(object sender, EventArgs e)
 
        //{
 
        //   TryTraceConnection = checkBoxTraceRoute.Checked;
 
        //   if(!TryTraceConnection)
 
        //   {
 
        //      if(iptracerWorker.IsBusy)
 
        //      {
 
        //         iptracerWorker.CancelAsync();
 
        //      }
 
        //      routes.Routes.Clear();
 
        //   }
 
        //}
 
 
        //private void GridConnections_DoubleClick(object sender, EventArgs e)
 
        //{
 
        //   GridConnections.ClearSelection();
 
        //}
 
 
        // open disk cache location
 
        private void button17_Click(object sender, EventArgs e)
 
        {
 
            try
 
            {
 
                string argument = "/select, \"" + MainMap.CacheLocation + "TileDBv5\"";
 
                System.Diagnostics.Process.Start("explorer.exe", argument);
 
            }
 
            catch (Exception ex)
 
            {
 
                MessageBox.Show("Failed to open: " + ex.Message, "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Error);
 
            }
 
        }
 
 
        #endregion
 
 
        #region graph functions
 
        #region graph and map functions
 
 
        #region chart coloring
 
        //this method clears the background of all charts
 
        private void ResetChartColors()
 
        {
 
            chrtTopLeft.BackColor = Color.LightGray;
 
            chrtTopRight.BackColor = Color.LightGray;
 
            chrtBottomLeft.BackColor = Color.LightGray;
 
            chrtBottomRight.BackColor = Color.LightGray;
 
        }
 
 
        //highlight Top Left chart on click
 
        //set text box values based on this chart
 
        private void chrtTopLeft_Click(object sender, EventArgs e)
 
        {
 
            ResetChartColors();
 
            chrtTopLeft.BackColor = Color.Gray;
 
            tboxChartData.Text = "Altitude";
 
            tboxCurrent.Text = "";
 
            tboxAverage.Text = "";
 
            tboxMax.Text = "";
 
            tboxMin.Text = "";
 
        }
 
 
        //highlight Top Right chart on click
 
        //set text box values based on this chart
 
        private void chrtTopRight_Click(object sender, EventArgs e)
 
        {
 
            ResetChartColors();
 
            chrtTopRight.BackColor = Color.Gray;
 
            tboxChartData.Text = "Humidity";
 
            tboxCurrent.Text = "";
 
            tboxAverage.Text = "";
 
            tboxMax.Text = "";
 
            tboxMin.Text = "";
 
        }
 
 
        //highlight Bottom Left chart on click
 
        //set text box values based on this chart
 
        private void chrtBottomLeft_Click(object sender, EventArgs e)
 
        {
 
            ResetChartColors();
 
            chrtBottomLeft.BackColor = Color.Gray;
 
            tboxChartData.Text = "Pressure";
 
            tboxCurrent.Text = "";
 
            tboxAverage.Text = "";
 
            tboxMax.Text = "";
 
            tboxMin.Text = "";
 
@@ -2516,115 +2516,118 @@ namespace Demo.WindowsForms
 
            ///required initial value
 
            chrtTopLeft.Series["altitudeTrend"].Points.AddXY(0, 0);
 
            //---------prep altitude area END 
 
 
 
            //-----------prep humidity area BEGIN
 
            chrtTopRight.Series["humidityTrend"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
 
            chrtTopRight.Series["humidityTrend"].Color = Color.Red;
 
            System.Windows.Forms.DataVisualization.Charting.AxisName.X.Equals("Time");
 
            System.Windows.Forms.DataVisualization.Charting.AxisName.Y.Equals("Humidity");
 
 
            ///required initial value
 
            chrtTopRight.Series["humidityTrend"].Points.AddXY(0, 0);
 
            //-----------prep humidity area END
 
 
 
            //-----------prep pressure area BEGIN
 
            chrtBottomLeft.Series["pressureTrend"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
 
            chrtBottomLeft.Series["pressureTrend"].Color = Color.Blue;
 
            System.Windows.Forms.DataVisualization.Charting.AxisName.X.Equals("Time");
 
            System.Windows.Forms.DataVisualization.Charting.AxisName.Y.Equals("Pressure");
 
 
            ///required initial value
 
            chrtBottomLeft.Series["pressureTrend"].Points.AddXY(0, 0);
 
            //-----------prep pressure area END
 
 
 
            //----------prep velocity area BEGIN
 
            chrtBottomRight.Series["velocityTrend"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
 
            chrtBottomRight.Series["velocityTrend"].Color = Color.Green;
 
            System.Windows.Forms.DataVisualization.Charting.AxisName.X.Equals("Time");
 
            System.Windows.Forms.DataVisualization.Charting.AxisName.Y.Equals("Altitude");
 
 
            ///required initial value
 
            chrtBottomRight.Series["velocityTrend"].Points.AddXY(0, 0);
 
            //----------prep velocity area END
 
 
            //put chart displays in a ready state
 
            ResetChartColors();
 
        }
 
        string latitude;
 
        string longitude;
 
        //handle line of input data and put into chart
 
 
        //parses transmissions and saves data to CSV file
 
        public void ParseIncomingData(string rawDataReceived)
 
        {
 
            //check to see if data should be processed
 
            //if (!cboxCollectData.Checked)
 
            //{
 
            //    return;
 
            //}
 
            if (!cboxCollectData.Checked)
 
            {
 
                return;
 
            }
 
            /* sample stansmission
 
            KD8TDF-9>APRS,WIDE2-1:/151916z3944.87N/08348.75WO005/0.013 SV:09 A-30.5 B45.64 C99542
 
                                          ^char 31 ^char 40            ^60
 
            */
 
 
            //TODO: verify index charcter accuracy with real transmission
 
            int indexStart = rawDataReceived.IndexOf("z");
 
            int indexEnd = rawDataReceived.IndexOf("N/");
 
            latitude = rawDataReceived.Substring(indexStart + 1, indexEnd - indexStart - 1);
 
 
            indexStart = rawDataReceived.IndexOf("N/");
 
            indexEnd = rawDataReceived.IndexOf("WO");
 
            longitude = rawDataReceived.Substring(indexStart + 2, indexEnd - indexStart - 2);
 
 
            //addMarkerFromTransmit(latitude, longitude);
 
            if (latitude != "" && longitude != "")
 
            {
 
                addMarkerFromTransmit(latitude, longitude);
 
            }
 
            AddText(rawDataReceived + "\r\n");
 
 
            rawDataReceived = rawDataReceived.Substring(59); //remove APRS overhead from string
 
 
            //place each datum in its own variable
 
            string[] dataTransmission;
 
            dataTransmission = rawDataReceived.Split(' ');
 
 
            //parse out the data type - should be a single letter
 
            string typeCode;
 
            double data;
 
            string csvData = "";
 
 
            //loop through all datums in the transmission and send them to the chart builder
 
            for (int i = 1; i < dataTransmission.Length; i++)
 
            {
 
                typeCode = dataTransmission[i].Substring(0, 1);
 
                data = double.Parse(dataTransmission[i].Substring(1));
 
                //addToChart(typeCode, data);
 
                csvData += typeCode + data + ",";
 
            }
 
 
            //write the data to CSV file
 
            WriteToCSV(csvData);
 
        }
 
 
        //write the data to CSV file
 
        private void WriteToCSV(string data)
 
        {
 
            using (StreamWriter writer = new StreamWriter("debug.csv", true))
 
            {
 
                writer.WriteLine(data);
 
            }
 
        }
 
        //method to insert parsed data into the charts
 
        //TODO: add inserts for all charts. altitude is finished and is a template
 
        private void addToChart(string dataType, double data)
 
        {
 
            ///data types organized by listing in google doc
 
            //MASTER MODULE DATA VALUES
 
            if (dataType.Equals("t"))  //board temperature
 
            {
 
 
            }
 
            else if (dataType.Equals("L"))  //battery level
 
            {
 
 
            }
 
@@ -2646,131 +2649,150 @@ namespace Demo.WindowsForms
 
            }
 
 
            //ATMOSPHERIC MODULE DATA VALUES
 
            else if (dataType.Equals("l"))  //battery level
 
            {
 
 
            }
 
            else if (dataType.Equals("C"))  //battery level
 
            {
 
 
            }
 
            else if (dataType.Equals("H"))  //Humidity
 
            {
 
                chrtTopRight.Series.FindByName("humidityTrend").Points.AddY(data);
 
            }
 
            else if (dataType.Equals("P"))  //Pressure
 
            {
 
                chrtBottomLeft.Series.FindByName("pressureTrend").Points.AddY(data);
 
            }
 
            else if (dataType.Equals("A"))  //Altitude
 
            {
 
                chrtTopLeft.Series.FindByName("altitudeTrend").Points.AddY(data);
 
            }
 
 
            //GEIGER MODULE DATA VALUES
 
            else if (dataType.Equals("l"))  //battery level
 
            {
 
 
            }
 
            else if (dataType.Equals("R"))  //radiation (CPM)
 
            {
 
 
            }
 
 
            // CAMERA MODULE DATA VALUES
 
            else if (dataType.Equals("l"))  //battery level
 
            {
 
 
            }
 
            else  //invalid data type
 
            {
 
 
            }
 
        }
 
 
        // add marker from an APRS transmission - MDKEdit
 
        private void addMarkerFromTransmit(string lat, string lng)
 
        {
 
 
            double latitude = double.Parse(lat), longitude = double.Parse(lng);
 
            PointLatLng APRSloc = new PointLatLng();
 
            APRSloc.Lat = latitude;
 
            APRSloc.Lng = longitude;
 
            APRSloc.Lat = conv_coords((float)latitude);
 
            APRSloc.Lng = conv_coords((float)longitude)*-1;
 
 
            GMarkerGoogle m = new GMarkerGoogle(APRSloc, GMarkerGoogleType.blue_small);
 
 
            Placemark? p = null;
 
            if (xboxPlacemarkInfo.Checked)
 
            {
 
                GeoCoderStatusCode status;
 
                var ret = GMapProviders.GoogleMap.GetPlacemark(currentMarker.Position, out status);
 
                if (status == GeoCoderStatusCode.G_GEO_SUCCESS && ret != null)
 
                {
 
                    p = ret;
 
                }
 
            }
 
 
            objects.Markers.Add(m);
 
        }
 
 
        float conv_coords(float in_coords)
 
        {
 
            //Initialize the location.
 
            float f = in_coords;
 
            // Get the first two digits by turning f into an integer, then doing an integer divide by 100;
 
            // firsttowdigits should be 77 at this point.
 
            int firsttwodigits = ((int)f) / 100;                               //This assumes that f < 10000.
 
            float nexttwodigits = f - (float)(firsttwodigits * 100);
 
            float theFinalAnswer = (float)(firsttwodigits + nexttwodigits / 60.0);
 
            return theFinalAnswer;
 
        }
 
        public decimal DmsToDD(double d, double m = 0, double s = 0)
 
        {
 
            return Convert.ToDecimal((d + (m / 60) + (s / 3600)) * (d < 0 ? -1 : 1));
 
        }
 
 
        #endregion
 
 
        #region cross theading
 
 
        //these are for function calls across threads
 
        delegate void SetTextDelegate(string value);
 
        public void AddText(string value)
 
        {
 
            if (InvokeRequired)
 
            {
 
                Invoke(new SetTextDelegate(AddText), value);
 
            }
 
            else
 
            {
 
                tboxMessageBox.AppendText(value);// += value;
 
                textBoxMarkerCount.Text = objects.Markers.Count.ToString();
 
            }
 
        }
 
 
        delegate void ChartDataDelegate(string dataType, double data);
 
        public void AddDataToChart(string dataType, double data)
 
        {
 
            if (InvokeRequired)
 
            {
 
                Invoke(new ChartDataDelegate(AddDataToChart), dataType, data);
 
            }
 
            else
 
            {
 
                addToChart(dataType, data);
 
            }
 
        }
 
 
        #endregion
 
 
        #region testing
 
        
 
        //click event on the test button
 
        //currently simulates serial inputs
 
        string testData;
 
        int testIteration = 0;
 
        double testLat = 39.751248, testLng = -83.809848, testVelocity = 5.8, testAltitude = 100, testPressure = 700, testHumidity = 38;
 
        private void btnTest_Click(object sender, EventArgs e)
 
        {
 
            testLat += GetRandomNumber(-.005, .015);
 
            testLng += GetRandomNumber(-.005, .015);
 
            testVelocity += GetRandomNumber(1, 15);
 
            testAltitude += GetRandomNumber(50, 150);
 
            testPressure -= GetRandomNumber(10, 50);
 
            testHumidity -= GetRandomNumber(1, 3);
 
 
            switch (testIteration)
 
            {
 
                case 0:
 
                    testData = "KD8TDF-9>APRS,WIDE2-1:/151916z" + testLat + "N/" + testLng + "WO005/0.013 V" + testVelocity + " A" + testAltitude+" H"+testHumidity+" P"+testPressure;
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 1:
 
                    testData = "KD8TDF-9>APRS,WIDE2-1:/151916z" + testLat + "N/" + testLng + "WO005/0.013 V" + testVelocity + " A" + testAltitude + " H" + testHumidity + " P" + testPressure;
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 2:
 
                    testData = "KD8TDF-9>APRS,WIDE2-1:/151916z" + testLat + "N/" + testLng + "WO005/0.013 V" + testVelocity + " A" + testAltitude + " H" + testHumidity + " P" + testPressure;
 
                    ParseIncomingData(testData);
 
                    break;
0 comments (0 inline, 0 general)