Changeset - a8f22329d687
[Not reviewed]
default
0 1 0
mkanning@CL-ENS241-10.cedarville.edu - 13 years ago 2013-02-21 14:37:00
mkanning@CL-ENS241-10.cedarville.edu
organized some functions, added comments
1 file changed with 77 insertions and 52 deletions:
0 comments (0 inline, 0 general)
Demo.WindowsForms/Forms/MainForm.cs
Show inline comments
 
@@ -2488,6 +2488,7 @@ namespace Demo.WindowsForms
 
 
        #endregion
 
 
        //runs on init 
 
        public void PrepareGraphs(){
 
 
            //set up for graphs MDKEdit
 
@@ -2554,9 +2555,9 @@ namespace Demo.WindowsForms
 
            //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)
 
@@ -2566,39 +2567,30 @@ namespace Demo.WindowsForms
 
            {
 
                return;
 
            }
 
            /* sample stansmission
 
            KD8TDF-9>APRS,WIDE2-1:/191950zN/WO/ T79 S00 V H99.99 _ |
 
            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
 
 
            /* sample stansmissions
 
             * KD8TDF-9>APRS,WIDE2-1:/191950zN/WO/ T79 S00 V H99.99 _ |
 
             * KD8TDF-9>APRS,WIDE2-1:/151916z3944.87N/08348.75WO005/0.013 SV:09 A-30.5 B45.64 C99542
 
             */
 
 
            //find and store latitude string
 
            int indexStart = rawDataReceived.IndexOf("z");
 
            int indexEnd = rawDataReceived.IndexOf("N/");
 
            latitude = rawDataReceived.Substring(indexStart + 1, indexEnd - indexStart - 1);
 
 
            //find and store longitude string
 
            indexStart = rawDataReceived.IndexOf("N/");
 
            indexEnd = rawDataReceived.IndexOf("WO");
 
            longitude = rawDataReceived.Substring(indexStart + 2, indexEnd - indexStart - 2);
 
 
            if (latitude == "" || longitude == "")
 
            {
 
                AddText("No GPS fix: ");
 
            }
 
            else
 
            {
 
                addMarkerFromTransmit(latitude, longitude);
 
            }
 
 
            AddText(rawDataReceived + "\r\n");
 
 
            rawDataReceived = rawDataReceived.Substring(rawDataReceived.IndexOf(" ")); //remove APRS overhead from string
 
            
 
            //remove APRS overhead from string
 
            string transmissionCommentField= rawDataReceived.Substring(rawDataReceived.IndexOf(" ")); 
 
 
            //place each datum in its own variable
 
            string[] dataTransmission;
 
            dataTransmission = rawDataReceived.Split(' ');
 
 
            //parse out the data type - should be a single letter
 
            dataTransmission = transmissionCommentField.Split(' ');
 
 
            //variables for processing datums
 
            string typeCode;
 
            double data;
 
            string csvData = "";
 
@@ -2606,17 +2598,37 @@ namespace Demo.WindowsForms
 
            //loop through all datums in the transmission and send them to the chart builder
 
            for (int i = 1; i < dataTransmission.Length; i++)
 
            {
 
                dataTransmission[i] = dataTransmission[i].Trim('\r'); //remove unwanted characters
 
                if (dataTransmission[i].Length == 1) //zero not always trasmitted properly so add '0.0' to any transmission with no data
 
                //remove unwanted characters
 
                dataTransmission[i] = dataTransmission[i].Trim('\r');
 
 
                //zero not always trasmitted properly so add '0.0' to any transmission with no data
 
                if (dataTransmission[i].Length == 1) 
 
                {
 
                    dataTransmission[i] += "0";
 
                }
 
                
 
                //pull out data and data type and send to processing function
 
                typeCode = dataTransmission[i].Substring(0, 1);
 
                data = double.Parse(dataTransmission[i].Substring(1));
 
                addToChart(typeCode, data);
 
                processTransmissionDatum(typeCode, data);
 
 
                //append data to string for CSV write
 
                csvData += typeCode + data + ",";
 
                
 
            }
 
 
            //handle case of no GPS fix
 
            if (latitude == "" || longitude == "")
 
            {
 
                AddText("No GPS fix: ");
 
            }
 
            else
 
            {
 
                //marker added here so extra accuracy can be added
 
                addMarkerFromTransmit(latitude, longitude);
 
            }
 
 
            //display transmission in message box
 
            AddText(rawDataReceived + "\r\n");
 
 
            //write the data to CSV file
 
            WriteToCSV(csvData);
 
@@ -2632,10 +2644,11 @@ namespace Demo.WindowsForms
 
                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)
 
        
 
        //method to process data from transmissions (usually chart inserts)
 
        private void processTransmissionDatum(string dataType, double data)
 
        {
 
            //TODO: add inserts for all charts. altitude is finished and is a template
 
            ///data types organized by listing in google doc
 
            //MASTER MODULE DATA VALUES
 
            if (dataType.Equals("t"))  //board temperature
 
@@ -2660,7 +2673,15 @@ namespace Demo.WindowsForms
 
            }
 
            else if (dataType.Equals("I"))  //Info/error Message
 
            {
 
 
                AddText("Info: " + data + "\r\n");
 
            }
 
            else if (dataType.Equals("_"))  //extra latitude decimals
 
            {
 
                longitude += data / 1000; //TODO: check math and decimal placement
 
            }
 
            else if (dataType.Equals("|"))  //extra longitude decimals
 
            {
 
                latitude += data / 1000; //TODO: check math and decimal placement
 
            }
 
 
            //ATMOSPHERIC MODULE DATA VALUES
 
@@ -2668,7 +2689,7 @@ namespace Demo.WindowsForms
 
            {
 
 
            }
 
            else if (dataType.Equals("C"))  //battery level
 
            else if (dataType.Equals("C"))  //
 
            {
 
 
            }
 
@@ -2700,12 +2721,33 @@ namespace Demo.WindowsForms
 
            {
 
 
            }
 
            else  //invalid data type
 
 
            //INVALID DATA TYPE
 
            else
 
            {
 
 
            }
 
        }
 
 
        //must change lat/long coords to properly place map marker
 
        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;
 
        }
 
 
        //must change lat/long coords to properly place map marker
 
        public decimal DmsToDD(double d, double m = 0, double s = 0)
 
        {
 
            return Convert.ToDecimal((d + (m / 60) + (s / 3600)) * (d < 0 ? -1 : 1));
 
        }
 
 
        // add marker from an APRS transmission - MDKEdit
 
        private void addMarkerFromTransmit(string lat, string lng)
 
        {
 
@@ -2730,24 +2772,7 @@ namespace Demo.WindowsForms
 
 
            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
 
@@ -2776,7 +2801,7 @@ namespace Demo.WindowsForms
 
            }
 
            else
 
            {
 
                addToChart(dataType, data);
 
                processTransmissionDatum(dataType, data);
 
            }
 
        }
 
0 comments (0 inline, 0 general)