00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005
00006 namespace GpsModule {
00007 public class GgaStrategy {
00008
00009 public delegate void updateErrorEventHandler(Exception error);
00010 public event updateErrorEventHandler updateErrorEvent;
00011
00012 GgaData _data;
00013 public GgaData Data {
00014 get { return _data; }
00015 }
00016
00017 public GgaStrategy() {
00018 _data = new GgaData();
00019 }
00020
00021 public void parseSentance(string sentence) {
00022 try {
00023 _data.setSentance(sentence);
00024
00025 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00026 string s = sentence.Substring(0, sentence.IndexOf(","));
00027 int hour;
00028 int.TryParse(s.Substring(0, 2), out hour);
00029 int minute;
00030 int.TryParse(s.Substring(2, 2), out minute);
00031 int second;
00032 int.TryParse(s.Substring(4, 2), out second);
00033
00034 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00035 _data.setLatitude(sentence.Substring(0, sentence.IndexOf(",")));
00036
00037 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00038 _data.setNorthOrSouth(sentence.Substring(0, sentence.IndexOf(","))[0]);
00039
00040 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00041 _data.setLongitude((sentence.Substring(0, sentence.IndexOf(","))));
00042
00043 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00044 _data.setEastOrWest(sentence.Substring(0, sentence.IndexOf(","))[0]);
00045
00046 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00047 _data.setQualityIndicator(int.Parse(sentence.Substring(0, sentence.IndexOf(","))));
00048
00049 if (_data.QualityIndicator > 0) {
00050
00051 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00052 _data.setSatelitesInView(int.Parse(sentence.Substring(0, sentence.IndexOf(","))));
00053
00054 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00055 _data.setHorizontalDilutionOfPrecision(double.Parse(sentence.Substring(0, sentence.IndexOf(","))));
00056
00057 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00058 _data.setAntennaAltitude(double.Parse(sentence.Substring(0, sentence.IndexOf(","))));
00059
00060 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00061 _data.setUnitsOfGeoidalSeperation(sentence.Substring(0, sentence.IndexOf(","))[0]);
00062
00063
00064 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00065 _data.setGeoidalSeparation(double.Parse(sentence.Substring(0, sentence.IndexOf(","))));
00066
00067 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00068 _data.setUnitsOfAntennaAltitude(sentence.Substring(0, sentence.IndexOf(","))[0]);
00069
00070
00071 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00072
00073
00074 sentence = sentence.Substring(sentence.IndexOf(",") + 1, sentence.Length - sentence.IndexOf(",") - 1);
00075
00076
00077 sentence = sentence.Substring(sentence.IndexOf("*") + 1, sentence.Length - sentence.IndexOf("*") - 1);
00078
00079 }
00080
00081 _data.setTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month
00082 , DateTime.Now.Day, hour, minute, second, DateTimeKind.Utc));
00083 } catch (Exception e) {
00084 if (updateErrorEvent != null)
00085 updateErrorEvent.Invoke(e);
00086 }
00087 }
00088 }
00089 }