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
 
@@ -46,10 +46,11 @@ namespace Demo.WindowsForms
 
        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)
 
            {
 
@@ -2561,11 +2562,12 @@ namespace Demo.WindowsForms
 
        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
 
            */
 
@@ -2579,13 +2581,18 @@ namespace Demo.WindowsForms
 
            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;
 
@@ -2599,10 +2606,16 @@ 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
 
                {
 
                    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
 
@@ -2612,7 +2625,9 @@ namespace Demo.WindowsForms
 
        //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);
 
            }
 
@@ -2727,6 +2742,7 @@ namespace Demo.WindowsForms
 
            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));
0 comments (0 inline, 0 general)