• R/O
  • HTTP
  • SSH
  • HTTPS

yubeshi: Commit

source codes and tests


Commit MetaInfo

Revisionbda7a38aefc38ffb26eb23777c0a41b892e483cc (tree)
Time2012-06-08 21:31:10
Authorkimikage <kimikage_ceo@hotm...>
Commiterkimikage

Log Message

NMEAパケットの部分実装(GPDTM, GPGBS, GPGLL)

Change Summary

Incremental Difference

--- a/Yubeshi/Nmea/GpDtm.cs
+++ b/Yubeshi/Nmea/GpDtm.cs
@@ -58,8 +58,14 @@ namespace Yubeshi.Nmea
5858 : base(sentence, elements.PacketLength)
5959 {
6060 string[] v = elements.Values;
61- LocalDatumCode = codes[v[0]];
62- //Offset = new GeodeticCoordinate();
61+ LocalDatumCode = GetDatumCode(v[0]);
62+ LocalDatumSubCode = v[1];
63+ Offset = new GeodeticCoordinate(
64+ Degree.FromNmeaFormat(v[2], v[3]),
65+ Degree.FromNmeaFormat(v[4], v[5]),
66+ Double.Parse(v[6]));
67+ ReferenceDatumCode = GetDatumCode(v[7]);
68+ CheckSum = elements.CheckSum;
6369 }
6470
6571 #endregion
@@ -71,13 +77,19 @@ namespace Yubeshi.Nmea
7177 private set;
7278 }
7379
80+ public string LocalDatumSubCode
81+ {
82+ get;
83+ private set;
84+ }
85+
7486 public GeodeticCoordinate Offset
7587 {
7688 get;
7789 private set;
7890 }
7991
80- public Code ReferenceDetumCode
92+ public Code ReferenceDatumCode
8193 {
8294 get;
8395 private set;
@@ -100,6 +112,16 @@ namespace Yubeshi.Nmea
100112 return new GpDtm(sentence, elements);
101113 }
102114
115+ private Code GetDatumCode(string datumCode)
116+ {
117+ Code c;
118+ if (codes.TryGetValue(datumCode, out c))
119+ {
120+ return c;
121+ }
122+ return Code.Unknown;
123+ }
103124 #endregion
125+
104126 }
105127 }
--- a/Yubeshi/Nmea/GpGbs.cs
+++ b/Yubeshi/Nmea/GpGbs.cs
@@ -16,5 +16,111 @@ namespace Yubeshi.Nmea
1616 /// </summary>
1717 public class GpGbs : Packet
1818 {
19+ #region fields
20+ private static readonly byte[] header;
21+ private const int elementNum = 8;
22+
23+ #endregion
24+
25+ #region constructors
26+
27+ static GpGbs()
28+ {
29+ header = Encoding.ASCII.GetBytes("$GPGBS,");
30+ }
31+
32+ public GpGbs()
33+ {
34+ }
35+
36+ public GpGbs(byte[] sentence)
37+ : this(sentence, GetElements(sentence, elementNum))
38+ {
39+ }
40+
41+ private GpGbs(byte[] sentence, Elements elements)
42+ : base(sentence, elements.PacketLength)
43+ {
44+ string[] v = elements.Values;
45+ Utc = ParseTime(v[0]);
46+ LatitudeError = ParseDouble(v[1]);
47+ LongitudeError = ParseDouble(v[2]);
48+ AltitudeError = ParseDouble(v[3]);
49+ FailedSatellite = ParseInt(v[4], -1);
50+ ProbabilityOfMissedDetection = ParseDouble(v[5]);
51+ Bias = ParseDouble(v[6]);
52+ StandardDeviationOfBias = ParseDouble(v[7]);
53+ CheckSum = elements.CheckSum;
54+ }
55+
56+ #endregion
57+
58+ #region properties
59+ public TimeSpan Utc
60+ {
61+ get;
62+ private set;
63+ }
64+
65+ public double LatitudeError
66+ {
67+ get;
68+ private set;
69+ }
70+
71+ public double LongitudeError
72+ {
73+ get;
74+ private set;
75+ }
76+
77+ public double AltitudeError
78+ {
79+ get;
80+ private set;
81+ }
82+
83+ public int FailedSatellite
84+ {
85+ get;
86+ private set;
87+ }
88+
89+ public double ProbabilityOfMissedDetection
90+ {
91+ get;
92+ private set;
93+ }
94+
95+ public double Bias
96+ {
97+ get;
98+ private set;
99+ }
100+
101+ public double StandardDeviationOfBias
102+ {
103+ get;
104+ private set;
105+ }
106+ #endregion
107+
108+ #region public method
109+
110+ public static bool TryParse(byte[] sentence, out UnknownPacket packet)
111+ {
112+ return TryParse(sentence, out packet, header, elementNum, Build);
113+ }
114+
115+ #endregion
116+
117+ #region private method
118+
119+ private static Packet Build(byte[] sentence, Elements elements)
120+ {
121+ return new GpGbs(sentence, elements);
122+ }
123+
124+ #endregion
19125 }
20126 }
\ No newline at end of file
--- a/Yubeshi/Nmea/GpGll.cs
+++ b/Yubeshi/Nmea/GpGll.cs
@@ -16,10 +16,22 @@ namespace Yubeshi.Nmea
1616 /// </summary>
1717 public class GpGll : Packet
1818 {
19- #region fields
19+ #region type definitions
20+ public enum Mode
21+ {
22+ Unknown = -1,
23+ None,
24+ Autonomous,
25+ Differential,
26+ DeadReckoning,
27+ }
28+ #endregion
2029
30+ #region fields
31+ private static Dictionary<string, Mode> modes;
2132 private static readonly byte[] header;
22- private const int elementNum = 7;
33+ private const int elementNum = -1; // 6 or 7
34+
2335
2436 #endregion
2537
@@ -28,6 +40,12 @@ namespace Yubeshi.Nmea
2840 static GpGll()
2941 {
3042 header = Encoding.ASCII.GetBytes("$GPGLL,");
43+
44+ modes = new Dictionary<string, Mode>();
45+ modes["N"] = Mode.None;
46+ modes["A"] = Mode.Autonomous;
47+ modes["D"] = Mode.Differential;
48+ modes["E"] = Mode.DeadReckoning;
3149 }
3250
3351 public GpGll()
@@ -40,8 +58,48 @@ namespace Yubeshi.Nmea
4058 }
4159
4260 private GpGll(byte[] sentence, Elements elements)
43- {
61+ {
62+ string[] v = elements.Values;
63+ if (v.Length < 6 || v.Length > 7)
64+ {
65+ throw new ArgumentException();
66+ }
67+ Position = new GeodeticCoordinate(
68+ Degree.FromNmeaFormat(v[0], v[1]),
69+ Degree.FromNmeaFormat(v[2], v[3]));
70+ CurrentTime = ParseTime(v[4]);
71+ DataStatus = ParseStatus(v[5]);
72+ PositioningMode = (v.Length == 7) ?
73+ GetPositioningMode(v[6]): Mode.Unknown;
74+ CheckSum = elements.CheckSum;
75+ }
76+
77+ #endregion
78+
79+ #region properties
4480
81+ public GeodeticCoordinate Position
82+ {
83+ get;
84+ private set;
85+ }
86+
87+ public TimeSpan CurrentTime
88+ {
89+ get;
90+ private set;
91+ }
92+
93+ public Status DataStatus
94+ {
95+ get;
96+ private set;
97+ }
98+
99+ public Mode PositioningMode
100+ {
101+ get;
102+ private set;
45103 }
46104
47105 #endregion
@@ -62,6 +120,15 @@ namespace Yubeshi.Nmea
62120 return new GpGll(sentence, elements);
63121 }
64122
123+ private Mode GetPositioningMode(string mode)
124+ {
125+ Mode m;
126+ if (modes.TryGetValue(mode, out m))
127+ {
128+ return m;
129+ }
130+ return Mode.Unknown;
131+ }
65132 #endregion
66133 }
67134 }
\ No newline at end of file
--- a/YubeshiTest/NmeaTest/PacketTest.cs
+++ b/YubeshiTest/NmeaTest/PacketTest.cs
@@ -24,7 +24,31 @@ namespace YubeshiTest.NmeaTest
2424 {
2525 UnknownPacket packet;
2626 Assert.IsTrue(GpDtm.TryParse(P.GpDtm, out packet));
27- GpGga p = packet as GpGga;
27+ GpDtm p = packet as GpDtm;
28+ Assert.AreEqual(GpDtm.Code.Wgs84, p.LocalDatumCode);
29+ Assert.AreEqual("", p.LocalDatumSubCode);
30+ Assert.AreEqual(0.0, (double)p.Offset.Latitude);
31+ Assert.AreEqual(0.0, (double)p.Offset.Longitude);
32+ Assert.AreEqual(0.0, (double)p.Offset.Altitude);
33+ Assert.AreEqual(GpDtm.Code.Wgs84, p.ReferenceDatumCode);
34+ Assert.AreEqual(0x6F, p.CheckSum);
35+ }
36+
37+ [Test]
38+ public void GpGbsTest()
39+ {
40+ UnknownPacket packet;
41+ Assert.IsTrue(GpGbs.TryParse(P.GpGbs, out packet));
42+ GpGbs p = packet as GpGbs;
43+ Assert.AreEqual(new TimeSpan(23, 55, 03), p.Utc);
44+ Assert.AreEqual(1.6, (double)p.LatitudeError);
45+ Assert.AreEqual(1.4, (double)p.LongitudeError);
46+ Assert.AreEqual(3.2, (double)p.AltitudeError);
47+ Assert.AreEqual(-1, p.FailedSatellite);
48+ Assert.True(Double.IsNaN(p.ProbabilityOfMissedDetection));
49+ Assert.True(Double.IsNaN(p.Bias));
50+ Assert.True(Double.IsNaN(p.StandardDeviationOfBias));
51+ Assert.AreEqual(0x40, p.CheckSum);
2852 }
2953
3054 [Test]
@@ -36,6 +60,31 @@ namespace YubeshiTest.NmeaTest
3660 Assert.AreEqual(new TimeSpan(0, 9, 27, 25, 0), p.TimeOfFix);
3761 Assert.AreEqual(2837.11399, p.Position.Latitude * 60.0);
3862 Assert.AreEqual(513.9159, p.Position.Longitude * 60.0);
63+ Assert.AreEqual(GpGga.FixQualityClass.Gps, p.FixQuality);
64+ Assert.AreEqual(8, p.TrackedSatellites);
65+ Assert.AreEqual(1.01, p.HorizontalDop);
66+ Assert.AreEqual(499.6, (double)p.MslAltitude);
67+ Assert.True(p.MslAltitude.IsAltitude);
68+ Assert.AreEqual(48.0, (double)p.GeoidSeparation);
69+ Assert.AreEqual(Height.Base.Wgs84Ellipsoid,
70+ p.GeoidSeparation.BaseLevel);
71+ Assert.Less(p.AgeOfDgpsCorrections.TotalSeconds, 0.0);
72+ Assert.AreEqual(0, p.DgpsStation);
73+ Assert.AreEqual(0x5B, p.CheckSum);
74+ }
75+
76+ [Test]
77+ public void GpGllTest()
78+ {
79+ UnknownPacket packet;
80+ Assert.IsTrue(GpGll.TryParse(P.GpGll, out packet));
81+ GpGll p = packet as GpGll;
82+ Assert.AreEqual(2837.11364, p.Position.Latitude * 60.0);
83+ Assert.AreEqual(513.91565, p.Position.Longitude * 60.0);
84+ Assert.AreEqual(new TimeSpan(0, 9, 23, 21, 0), p.CurrentTime);
85+ Assert.AreEqual(GpGll.Status.Valid, p.DataStatus);
86+ Assert.AreEqual(GpGll.Mode.Autonomous, p.PositioningMode);
87+ Assert.AreEqual(0x60, p.CheckSum);
3988 }
4089 }
4190 }
--- a/YubeshiTest/NmeaTest/SamplePackets.cs
+++ b/YubeshiTest/NmeaTest/SamplePackets.cs
@@ -23,7 +23,9 @@ namespace YubeshiTest.NmeaTest
2323 public static readonly byte[] GpGst;
2424 public static readonly byte[] GpGsv;
2525 public static readonly byte[] GpRmc;
26-
26+ public static readonly byte[] GpTxt;
27+ public static readonly byte[] GpVtg;
28+ public static readonly byte[] GpZda;
2729
2830 static SamplePackets()
2931 {
@@ -33,11 +35,17 @@ namespace YubeshiTest.NmeaTest
3335
3436 // from u-blox document
3537 GpDtm = ascii.GetBytes("$GPDTM,W84,,0.000000,N,0.000000,E,0.0,W84*6F\r\n");
38+ GpGbs = ascii.GetBytes("$GPGBS,235503.00,1.6,1.4,3.2,,,,*40\r\n");
3639 GpGga = ascii.GetBytes("$GPGGA,092725.00,4717.11399,N,00833.91590,E,1,8,1.01,499.6,M,48.0,M,,0*5B\r\n");
3740 GpGll = ascii.GetBytes("$GPGLL,4717.11364,N,00833.91565,E,092321.00,A,A*60\r\n");
3841 GpGrs = ascii.GetBytes("$GPGRS,082632.00,1,0.54,0.83,1.00,1.02,-2.12,2.64,-0.71,-1.18,0.25,,,*70\r\n");
3942 GpGsa = ascii.GetBytes("$GPGSA,A,3,23,29,07,08,09,18,26,28,,,,,1.94,1.18,1.54*0D\r\n");
40-
43+ GpGst = ascii.GetBytes("$GPGST,082356.00,1.8,,,,1.7,1.3,2.2*7E\r\n");
44+ GpGsv = ascii.GetBytes("$GPGSV,3,1,10,23,38,230,44,29,71,156,47,07,29,116,41,08,09,081,36*7F\r\n");
45+ GpRmc = ascii.GetBytes("$GPRMC,083559.00,A,4717.11437,N,00833.91522,E,0.004,77.52,091202,,,A*57\r\n");
46+ GpTxt = ascii.GetBytes("$GPTXT,01,01,02,u-blox ag - www.u-blox.com*50\r\n");
47+ GpVtg = ascii.GetBytes("$GPVTG,77.52,T,,M,0.004,N,0.008,K,A*06\r\n");
48+ GpZda = ascii.GetBytes("$GPZDA,082710.00,16,09,2002,00,00*64\r\n");
4149 }
4250 }
4351 }
Show on old repository browser