Changeset - 0f22c89cdda0
[Not reviewed]
default
0 1 0
mkanning@CL-ENS241-10.cedarville.edu - 13 years ago 2013-02-19 15:22:11
mkanning@CL-ENS241-10.cedarville.edu
further improvements and exception catches. also csv writing
1 file changed with 22 insertions and 6 deletions:
0 comments (0 inline, 0 general)
Demo.WindowsForms/Forms/MainForm.cs
Show inline comments
 
@@ -43,16 +43,17 @@ namespace Demo.WindowsForms
 
        readonly DescendingComparer ComparerIpStatus = new DescendingComparer();
 
        GMapMarkerRect CurentRectMarker = null;
 
        string mobileGpsLog = string.Empty;
 
        bool isMouseDown = false;
 
        PointLatLng start;
 
        PointLatLng end;
 
 
        TimeSpan unixTime;
 
        public MainForm()
 
        {
 
            InitializeComponent();
 
            unixTime = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
 
 
            if (!DesignMode)
 
            {
 
                // add your custom map db provider
 
                //GMap.NET.CacheProviders.MySQLPureImageCache ch = new GMap.NET.CacheProviders.MySQLPureImageCache();
 
                //ch.ConnectionString = @"server=sql2008;User Id=trolis;Persist Security Info=True;database=gmapnetcache;password=trolis;";
 
@@ -2558,17 +2559,18 @@ namespace Demo.WindowsForms
 
        //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)
 
            if (!cboxCollectData.Checked && rawDataReceived.StartsWith("KD8TDF"))
 
            {
 
                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
 
            int indexStart = rawDataReceived.IndexOf("z");
 
@@ -2576,19 +2578,24 @@ namespace Demo.WindowsForms
 
            latitude = rawDataReceived.Substring(indexStart + 1, indexEnd - indexStart - 1);
 
 
            indexStart = rawDataReceived.IndexOf("N/");
 
            indexEnd = rawDataReceived.IndexOf("WO");
 
            longitude = rawDataReceived.Substring(indexStart + 2, indexEnd - indexStart - 2);
 
 
            if (latitude != "" && longitude != "")
 
            if (latitude == "" || longitude == "")
 
            {
 
                AddText("No GPS fix: ");
 
            }
 
            else
 
            {
 
                addMarkerFromTransmit(latitude, longitude);
 
            }
 
 
            AddText(rawDataReceived + "\r\n");
 
 
            rawDataReceived = rawDataReceived.Substring(59); //remove APRS overhead from string
 
            rawDataReceived = rawDataReceived.Substring(rawDataReceived.IndexOf(" ")); //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
 
@@ -2596,26 +2603,34 @@ namespace Demo.WindowsForms
 
            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++)
 
            {
 
                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
 
                {
 
                    dataTransmission[i] += "0";
 
                }
 
                typeCode = dataTransmission[i].Substring(0, 1);
 
                data = double.Parse(dataTransmission[i].Substring(1));
 
                //addToChart(typeCode, data);
 
                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))
 
            string path = Directory.GetCurrentDirectory();
 
            string filename = path+"\\debug" + unixTime.Milliseconds + ".csv";
 
            using (StreamWriter writer = new StreamWriter(filename, 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
 
@@ -2724,12 +2739,13 @@ namespace Demo.WindowsForms
 
            // 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
0 comments (0 inline, 0 general)