Changeset - 636f2836d35c
[Not reviewed]
default
0 2 0
mkanning@CL-ENS241-10.cedarville.edu - 13 years ago 2013-04-04 20:38:29
mkanning@CL-ENS241-10.cedarville.edu
small changes
2 files changed with 6 insertions and 12 deletions:
0 comments (0 inline, 0 general)
Demo.WindowsForms/Forms/MainForm.cs
Show inline comments
 
@@ -1102,204 +1102,198 @@ 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();
 
        }
 
        
 
        //parses transmissions and saves data to CSV file
 
        public void ParseIncomingData(string rawDataReceived)
 
        {
 
            //check to see if data should be processed
 
            if (!cboxCollectData.Checked )
 
            {
 
                AddTextDelegate("Transmission not saved: " + rawDataReceived +"\r\n");
 
                return;
 
            }
 
            else if (!rawDataReceived.StartsWith("KD8TDF"))
 
            {
 
                AddTextDelegate("Foreign transmission: " + rawDataReceived + "\r\n");
 
                return;
 
            }
 
 
            /* 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);
 
            
 
            //remove APRS overhead from string
 
            string transmissionCommentField= rawDataReceived.Substring(rawDataReceived.IndexOf(" ")); 
 
            string transmissionCommentField = rawDataReceived.Substring(rawDataReceived.IndexOf(" ") + 1); 
 
 
            //place each datum in its own variable
 
            string[] dataTransmission;
 
            dataTransmission = transmissionCommentField.Split('~');
 
 
            //variables for processing datums
 
            string typeCode;
 
            string data;
 
            string csvData = "";
 
            string testString = "";
 
 
            //loop through all datums in the transmission and send them to the chart builder
 
            for (int i = 0; i < dataTransmission.Length; i++)
 
            for (int i = 1; i < dataTransmission.Length; i++)
 
            {
 
                if (i == 0)
 
                if (i == 1)
 
                {
 
                    firstTransmissionDatum = true;
 
                }
 
                else
 
                {
 
                    firstTransmissionDatum = false;
 
                }
 
 
                //remove unwanted characters
 
                dataTransmission[i] = dataTransmission[i].Trim();
 
 
                //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);
 
                if (typeCode != "e")
 
                {
 
                    testString = dataTransmission[i].Substring(1);
 
                    data = dataTransmission[i].Substring(1);
 
                    processTransmissionDatum(typeCode, data);
 
 
                    //append data to string for CSV write
 
                    csvData += typeCode + data + ",";
 
                }
 
                else
 
                {
 
                    AddTextDelegate("Error Message: " + dataTransmission[i].Substring(1) + "\r\n");
 
                }
 
            }
 
 
            //handle case of no GPS fix
 
            if (latitude == "" || longitude == "")
 
            {
 
                AddTextDelegate("No GPS fix: ");
 
            }
 
            else
 
            {
 
                //marker added here so extra accuracy can be added
 
                addTrackerMarker(latitude, longitude);
 
            }
 
 
            //display transmission in message box
 
            AddTextDelegate(rawDataReceived + "\r\n");
 
 
            //write the data to CSV file
 
            WriteToCSV(csvData);
 
        }
 
 
        //method to process data from transmissions (usually chart inserts)
 
        private void processTransmissionDatum(string dataType, string 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
 
            ChartDelegate(dataType, data);
 
 
        }
 
 
        //write the data to CSV file -- usually seniordesign-ui\Demo.WindowsForms\bin\Debug
 
        private void WriteToCSV(string data)
 
        {
 
            string path = Directory.GetCurrentDirectory();
 
            string filename = path+"\\TransmissionData" + unixTime.Milliseconds + ".csv";
 
            using (StreamWriter writer = new StreamWriter(filename, true))
 
            {
 
                writer.WriteLine(data);
 
            }
 
        }
 
        
 
        //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 addTrackerMarker(string lat, string lng)
 
        {
 
 
            double latitude = double.Parse(lat), longitude = double.Parse(lng);
 
            PointLatLng APRSloc = new PointLatLng();
 
            APRSloc.Lat = conv_coords((float)latitude);
 
            APRSloc.Lng = conv_coords((float)longitude)*-1;
 
 
            GMarkerGoogle m = new GMarkerGoogle(APRSloc, GMarkerGoogleType.blue_small);
 
 
            m.ToolTipText = "Tracker";
 
            m.ToolTipMode = MarkerTooltipMode.Always;
 
            objects.Markers.Add(m);
 
        }
 
 
        //places text in the message box
 
        delegate void SetTextDelegate(string value);
 
        public void AddTextDelegate(string value)
 
        {
 
            if (InvokeRequired)
 
            {
 
                Invoke(new SetTextDelegate(AddTextDelegate), value);
 
            }
 
            else
 
            {
 
                tboxMessageBox.AppendText(value);// += value;
 
                textBoxMarkerCount.Text = objects.Markers.Count.ToString();
 
            }
 
        }
 
 
        //this is where most of the transmission processing is done
 
        delegate void ChartDataDelegate(string dataType, string data);
 
        public void ChartDelegate(string dataType, string data)
 
        {
 
            if (InvokeRequired)
 
            {
 
                Invoke(new ChartDataDelegate(ChartDelegate), dataType, data);
 
            }
 
            else
 
            {
 
                if (firstTransmissionDatum)
 
                {
 
                    ClearTboxColor();
 
                }
 
                ///UNIVERSAL DATA TYPES
 
                if (dataType.Equals("t"))  //board temperature
 
                {
 
@@ -1310,104 +1304,104 @@ namespace Demo.WindowsForms
 
                        tboxMasterBoardTemp.BackColor = Color.Chartreuse;
 
                    }
 
                    else if (dataString.StartsWith("0")) //Atmo Module
 
                    {
 
                        tboxAtmoBoardTemp.Text = dataString.Substring(1);
 
                        tboxAtmoBoardTemp.BackColor = Color.Chartreuse;
 
                    }
 
                    else if (dataString.StartsWith("1")) //Geiger Module
 
                    {
 
                        tboxGeigerBoardTemp.Text = dataString.Substring(1);
 
                        tboxGeigerBoardTemp.BackColor = Color.Chartreuse;
 
                    }
 
                    else if (dataString.StartsWith("2")) //Camera Module
 
                    {
 
                        tboxCameraBoardTemp.Text = dataString.Substring(1);
 
                        tboxCameraBoardTemp.BackColor = Color.Chartreuse;
 
                    }
 
                }
 
                else if (dataType.Equals("l"))  //battery level
 
                {
 
                    string dataString = data.ToString();
 
                    if (dataString.StartsWith("9")) //Master Module
 
                    {
 
                        tboxMasterBatteryLevel.Text = dataString.Substring(1);
 
                        tboxMasterBatteryLevel.BackColor = Color.Chartreuse;
 
                    }
 
                    else if (dataString.StartsWith("0")) //Atmo Module
 
                    {
 
                        tboxAtmoBatteryLevel.Text = dataString.Substring(1);
 
                        tboxAtmoBatteryLevel.BackColor = Color.Chartreuse;
 
                    }
 
                    else if (dataString.StartsWith("1"))  //Geiger Module
 
                    {
 
                        tboxGeigerBatteryLevel.Text = dataString.Substring(1);
 
                        tboxGeigerBatteryLevel.BackColor = Color.Chartreuse;
 
                    }
 
                    else if (dataString.StartsWith("2")) //Camera Module
 
                    {
 
                        tboxCameraBatteryLevel.Text = dataString.Substring(1);
 
                        tboxCameraBatteryLevel.BackColor = Color.Chartreuse;
 
                    }
 
                }
 
                else if (dataType.Equals("i")) //Info Message
 
                {
 
                    AddTextDelegate("Info: " + data + "\r\n");
 
                }
 
                
 
                ///MASTER MODULE DATA TYPES
 
                else if (dataType.Equals("_"))  //latitude
 
                else if (dataType.Equals("_"))  //latitude extra accuracy
 
                {
 
                    //TODO: check math and decimal placement
 
                    latitude += data.ToString();
 
                    tboxMasterLatitude.Text = latitude;
 
                    tboxMasterLatitude.BackColor = Color.Chartreuse;
 
                }
 
                else if (dataType.Equals("|"))  //longitude
 
                else if (dataType.Equals("|"))  //longitude extra accuracy
 
                {
 
                    //TODO: check math and decimal placement
 
                    longitude += data.ToString();
 
                    tboxMasterLongitude.Text = longitude;
 
                    tboxMasterLongitude.BackColor = Color.Chartreuse;
 
                }
 
                else if (dataType.Equals("h"))  //HDOP
 
                {
 
                    tboxMasterHDOP.Text = data.ToString();
 
                    tboxMasterHDOP.BackColor = Color.Chartreuse;
 
                }
 
                else if (dataType.Equals("v"))  //Velocity
 
                {
 
                    chrtBottomRight.Series.FindByName("velocityTrend").Points.AddY(double.Parse(data));
 
                    velocitySum += double.Parse(data);
 
                    tboxMasterVelocity.Text = data.ToString();
 
                    tboxMasterVelocity.BackColor = Color.Chartreuse;
 
                }
 
                else if (dataType.Equals("s"))  //satellites in view
 
                {
 
                    tboxMasterSatellites.Text = data.ToString();
 
                    tboxMasterSatellites.BackColor = Color.Chartreuse;
 
                }
 
 
                ///ATMOSPHERIC MODULE DATA VALUES
 
                else if (dataType.Equals("C"))  //Air Temperature
 
                {
 
                    tboxAtmoAirTemp.Text = data.ToString();
 
                    tboxAtmoAirTemp.BackColor = Color.Chartreuse;
 
                }
 
                else if (dataType.Equals("L"))  //Ambient Light
 
                {
 
                    tboxAtmoLight.Text = data.ToString();
 
                    tboxAtmoLight.BackColor = Color.Chartreuse;
 
                }
 
                else if (dataType.Equals("H"))  //Humidity
 
                {
 
                    chrtTopRight.Series.FindByName("humidityTrend").Points.AddY(double.Parse(data));
 
                    humiditySum += double.Parse(data);
 
                    tboxAtmoHumidity.Text = data.ToString();
 
                    tboxAtmoHumidity.BackColor = Color.Chartreuse;
 
                }
 
                else if (dataType.Equals("P"))  //Pressure
 
                {
 
                    chrtBottomLeft.Series.FindByName("pressureTrend").Points.AddY(double.Parse(data));
 
                    pressureSum += double.Parse(data);
 
                    tboxAtmoPressure.Text = data.ToString();
 
                    tboxAtmoPressure.BackColor = Color.Chartreuse;
Demo.WindowsForms/Source/Program.cs
Show inline comments
 
using System;
 
using System.Collections;
 
using System.Collections.Generic;
 
using System.Diagnostics;
 
using System.Net;
 
using System.Net.NetworkInformation;
 
using System.Runtime.InteropServices;
 
using System.Text;
 
using System.Windows.Forms;
 
using System.IO;
 
using System.IO.Ports;
 
using System.Threading;
 
 
namespace Demo.WindowsForms
 
{
 
   class Program
 
   {
 
      /// <summary>
 
      /// The main entry point for the application.
 
      /// </summary>
 
      /// 
 
       // Instantiate the communications port 
 
       private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
 
       private SerialPort port = new SerialPort("COM5", 9600, Parity.None, 8, StopBits.One);
 
       static MainForm windowGUI;
 
 
      [STAThread]
 
      static void Main()
 
      {
 
          Application.SetCompatibleTextRenderingDefault(false);
 
          var program = new Program();
 
          windowGUI = new MainForm();
 
          program.SerialInitialize();
 
         Application.EnableVisualStyles();
 
 
         Application.Run(windowGUI);
 
      }
 
 
      //inits the serial port and event handler
 
      private void SerialInitialize()
 
      {
 
          // http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx
 
          // Attach a method to be called when there is data waiting in the port's buffer
 
          port.DataReceived += new SerialDataReceivedEventHandler(ReceiveData);
 
 
          // Open the port for communications
 
          port.Open();
 
 
      }
 
 
      //process received data
 
      private void ReceiveData(object sender, SerialDataReceivedEventArgs e)
 
      {
 
          // Show all the incoming data in the port's buffer
 
          string testChk = port.ReadLine();
 
          windowGUI.ParseIncomingData(testChk);
 
      }
 
   }
 
 
   public class Dummy
 
   {
 
 
   }
 
 
   class IpInfo
 
   {
 
      public string Ip;
 
      //public int Port;
 
      //public TcpState State;
 
      //public string ProcessName;
 
 
      public string CountryName;
0 comments (0 inline, 0 general)