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
 
@@ -37,28 +37,29 @@ namespace Demo.WindowsForms
 
 
        // polygons
 
        //GMapPolygon polygon;
 
 
        // etc
 
        readonly Random rnd = new Random();
 
        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;";
 
                //MainMap.Manager.SecondaryCache = ch;
 
 
                // set your proxy here if need
 
                //GMapProvider.WebProxy = new WebProxy("10.2.0.100", 8080);
 
                //GMapProvider.WebProxy.Credentials = new NetworkCredential("ogrenci@bilgeadam.com", "bilgeada");
 
 
@@ -2552,76 +2553,90 @@ 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)
 
        {
 
            //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");
 
            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);
 
 
            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
 
            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++)
 
            {
 
                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
 
        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
 
            {
 
@@ -2718,24 +2733,25 @@ namespace Demo.WindowsForms
 
 
        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)
0 comments (0 inline, 0 general)