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
 
@@ -1126,64 +1126,64 @@ namespace Demo.WindowsForms
 
                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);
 
@@ -1228,54 +1228,48 @@ namespace Demo.WindowsForms
 
        //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);
 
            }
 
@@ -1334,56 +1328,56 @@ namespace Demo.WindowsForms
 
                        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;
 
                }
 
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();
 
0 comments (0 inline, 0 general)