00001 using System;
00002 using System.Collections.Generic;
00003 using System.ComponentModel;
00004 using System.Data;
00005 using System.Drawing;
00006 using System.Linq;
00007 using System.Text;
00008 using System.Windows.Forms;
00009 using RS232Port;
00010
00011 namespace GpsModule {
00012 public partial class GpsModuleMainForm : Form {
00013
00014 GpsStrategy _strategy;
00015
00016 bool _silent = true;
00017 public bool Silent {
00018 get { return _silent; }
00019 set {
00020 _silent = value;
00021 if (_silent) {
00022 _strategy.updateUiEvent -= updateUi;
00023 _strategy.setSilentModeEvent -= setSilentMode;
00024 } else {
00025 _strategy.updateUiEvent += updateUi;
00026 _strategy.setSilentModeEvent += setSilentMode;
00027 }
00028 }
00029 }
00030
00031
00032 private void setSilentMode() {
00033 if (Silent != _strategy.Silent)
00034 Silent = _strategy.Silent;
00035 }
00036
00037 public GpsModuleMainForm() {
00038 InitializeComponent();
00039 _strategy = new GpsStrategy("COM8");
00040 initializeObject();
00041 }
00042
00043 public GpsModuleMainForm(ref GpsStrategy strategy) {
00044 InitializeComponent();
00045 _strategy = strategy;
00046 initializeObject();
00047 }
00048
00049 private void initializeObject() {
00050 if (_strategy.Status.Contains("opened")) {
00051 toolStripStatusLabel1.Text = "gps_init";
00052 toolStripStatusLabel1.BackColor = Color.Green;
00053 }
00054 toolStripStatusLabel2.Text = _strategy.Status;
00055 }
00056
00057 private void updateUi() {
00058 debugTextBox.Text = _strategy.Gga.Data.Sentance + "\r\n" + _strategy.Rmc.Data.Sentance + "\r\n";
00059 timeTextBox.Text = _strategy.Gga.Data.Time.ToString();
00060 latTextBox.Text = _strategy.Gga.Data.Latitude.ToString();
00061 nsTextBox.Text = _strategy.Gga.Data.NorthOrSouth.ToString();
00062 lonTextBox.Text = _strategy.Gga.Data.Longitude.ToString();
00063 ewTextBox.Text = _strategy.Gga.Data.EastOrWest.ToString();
00064 qualityTextBox.Text = _strategy.Gga.Data.QualityIndicator.ToString();
00065 satelitesTextBox.Text = _strategy.Gga.Data.SatelitesInView.ToString();
00066 dilutionTextBox.Text = _strategy.Gga.Data.HorizontalDilutionOfPrecision.ToString();
00067 altitudeTextBox.Text = _strategy.Gga.Data.AntennaAltitude.ToString();
00068 aUnitsTextBox.Text = _strategy.Gga.Data.UnitsOfAntennaAltitude.ToString();
00069 geoidTextBox.Text = _strategy.Gga.Data.GeoidalSeparation.ToString();
00070 gUnitsTextBox.Text = _strategy.Gga.Data.UnitsOfGeoidalSeperation.ToString();
00071 speedTextBox.Text = _strategy.Rmc.Data.SpeedOverGround.ToString();
00072 trackTextBox.Text = _strategy.Rmc.Data.TrackMadeGood.ToString();
00073 magTextBox.Text = _strategy.Rmc.Data.MagneticVariation.ToString();
00074 }
00075
00076 private void rS232PortToolStripMenuItem_Click(object sender, EventArgs e) {
00077 _strategy.showSerialPort();
00078 }
00079
00080 private void silentCheckBox_CheckedChanged(object sender, EventArgs e) {
00081 _strategy.setSilentMode(silentCheckBox.Checked);
00082 Silent = silentCheckBox.Checked;
00083 }
00084
00085 private void hideButton_Click(object sender, EventArgs e) {
00086 this.Hide();
00087 }
00088
00089 private void clearDebugWindowButton_Click(object sender, EventArgs e) {
00090 debugTextBox.Clear();
00091 }
00092
00093 private void openComButton_Click(object sender, EventArgs e) {
00094 toolStripStatusLabel2.Text = _strategy.openPort();
00095 if (_strategy.Status.Contains("opened")) {
00096 toolStripStatusLabel1.BackColor = Color.Green;
00097 toolStripStatusLabel1.Text = "gps_init";
00098 }
00099 }
00100
00101 private void closeComButton_Click(object sender, EventArgs e) {
00102 toolStripStatusLabel2.Text = _strategy.closePort();
00103 toolStripStatusLabel1.BackColor = Color.Red;
00104 toolStripStatusLabel1.Text = "not initialized";
00105 }
00106 }
00107 }