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
 
@@ -247,49 +247,49 @@ namespace Demo.WindowsForms
 
                            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;
 
            }
 
 
@@ -2400,49 +2400,49 @@ namespace Demo.WindowsForms
 
        //   }
 
        //}
 
 
        //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 = "";
 
        }
 
 
@@ -2540,67 +2540,70 @@ namespace Demo.WindowsForms
 
            //-----------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);
 
@@ -2670,83 +2673,102 @@ namespace Demo.WindowsForms
 
            //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;
0 comments (0 inline, 0 general)