OSDN Git Service

NMEAパケット,パーサの一部実装
authorkimikage <kimikage_ceo@hotmail.com>
Wed, 22 Dec 2010 07:20:11 +0000 (16:20 +0900)
committerkimikage <kimikage_ceo@hotmail.com>
Wed, 22 Dec 2010 07:20:11 +0000 (16:20 +0900)
YubeshiTest/Nmea/PacketTest.cs
YubeshiTest/Nmea/ParserTest.cs [new file with mode: 0755]
YubeshiTest/Nmea/SamplePackets.cs [new file with mode: 0755]

index 4d52a2b..c5591bb 100755 (executable)
@@ -10,6 +10,7 @@ using System.Collections.Generic;
 using System.Text;\r
 using NUnit.Framework;\r
 using Yubeshi.Nmea;\r
+using P = YubeshiTest.Nmea.SamplePackets;\r
 \r
 namespace YubeshiTest.Nmea\r
 {\r
@@ -17,34 +18,22 @@ namespace YubeshiTest.Nmea
     class PacketTest\r
     {\r
 \r
-        static readonly byte[] gpdtm;\r
-        static readonly byte[] gpgbs;\r
-        static readonly byte[] gpgga;\r
-\r
-        static PacketTest()\r
-        {\r
-            Encoding ascii = Encoding.ASCII;\r
-\r
-            gpdtm = ascii.GetBytes("$GPDTM,W84,,0.000000,N,0.000000,E,0.0,W84*6F\r\n");\r
-            gpgga = ascii.GetBytes("$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47\r\n");\r
-        }\r
-\r
         [Test]\r
         public void GpDtmTest()\r
         {\r
             Packet p;\r
-            GpDtm.TryParse(gpdtm, out p);\r
+            GpDtm.TryParse(P.GpDtm, out p);\r
         }\r
 \r
         [Test]\r
         public void GpGgaTest()\r
         {\r
             Packet packet;\r
-            Assert.AreEqual(true, GpGga.TryParse(gpgga, out packet));\r
+            Assert.AreEqual(true, GpGga.TryParse(P.GpGga, out packet));\r
             GpGga p = packet as GpGga;\r
-            Assert.AreEqual(new TimeSpan(12,35,19), p.TimeOfFix);\r
-            Assert.AreEqual(48.1173m, p.Position.Latitude);\r
-            Assert.AreEqual(691m / 60m, p.Position.Longitude);\r
+            Assert.AreEqual(new TimeSpan(0, 9, 27, 25, 0), p.TimeOfFix);\r
+            Assert.AreEqual(2837.11399m / 60m, p.Position.Latitude);\r
+            Assert.AreEqual(513.9159m / 60m, p.Position.Longitude);\r
         }\r
     }\r
 }\r
diff --git a/YubeshiTest/Nmea/ParserTest.cs b/YubeshiTest/Nmea/ParserTest.cs
new file mode 100755 (executable)
index 0000000..3cb9ee1
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ *     Yubeshi GPS Parser\r
+ *\r
+ *     This software is distributed under a zlib-style license.\r
+ *     See license.txt for more information.\r
+ */\r
+\r
+using System;\r
+using System.Collections.Generic;\r
+using System.Text;\r
+using NUnit.Framework;\r
+using Yubeshi.Nmea;\r
+using P = YubeshiTest.Nmea.SamplePackets;\r
+\r
+namespace YubeshiTest.Nmea\r
+{\r
+\r
+    class ParserTest\r
+    {\r
+        [Test]\r
+        public void TryParse()\r
+        { \r
+            Packet p;\r
+\r
+            Assert.AreEqual(false, Parser.TryParse(P.Dummy, out p));\r
+            Assert.AreEqual(null, p);\r
+\r
+            Assert.AreEqual(true, Parser.TryParse(P.GpDtm, out p));\r
+            Assert.AreEqual(typeof(GpDtm), p.GetType());\r
+\r
+            Assert.AreEqual(true, Parser.TryParse(P.GpGga, out p));\r
+            Assert.AreEqual(typeof(GpGga), p.GetType());\r
+\r
+            Assert.AreEqual(true, Parser.TryParse(P.GpGll, out p));\r
+            Assert.AreEqual(typeof(GpGll), p.GetType());\r
+\r
+            Assert.AreEqual(true, Parser.TryParse(P.GpGrs, out p));\r
+            Assert.AreEqual(typeof(GpGrs), p.GetType());\r
+\r
+            Assert.AreEqual(true, Parser.TryParse(P.GpGsa, out p));\r
+            Assert.AreEqual(typeof(GpGsa), p.GetType());\r
+        }\r
+    }\r
+}\r
diff --git a/YubeshiTest/Nmea/SamplePackets.cs b/YubeshiTest/Nmea/SamplePackets.cs
new file mode 100755 (executable)
index 0000000..4733902
--- /dev/null
@@ -0,0 +1,34 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Text;\r
+\r
+namespace YubeshiTest.Nmea\r
+{\r
+    public class SamplePackets\r
+    {\r
+        public static readonly byte[] Dummy;\r
+        public static readonly byte[] GpDtm;\r
+        public static readonly byte[] GpGbs;\r
+        public static readonly byte[] GpGga;\r
+        public static readonly byte[] GpGll;\r
+        public static readonly byte[] GpGrs;\r
+        public static readonly byte[] GpGsa;\r
+        public static readonly byte[] GpGst;\r
+        public static readonly byte[] GpGsv;\r
+        public static readonly byte[] GpRmc;\r
+\r
+\r
+        static SamplePackets()\r
+        {\r
+            Encoding ascii = Encoding.ASCII;\r
+\r
+            Dummy = ascii.GetBytes("$GPXXX,YYY,ZZZ,*FF\r\n");\r
+            GpDtm = ascii.GetBytes("$GPDTM,W84,,0.000000,N,0.000000,E,0.0,W84*6F\r\n");\r
+            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");\r
+            GpGll = ascii.GetBytes("$GPGLL,4717.11364,N,00833.91565,E,092321.00,A,A*60\r\n");\r
+            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");\r
+            GpGsa = ascii.GetBytes("$GPGSA,A,3,23,29,07,08,09,18,26,28,,,,,1.94,1.18,1.54*0D\r\n");\r
+\r
+        }\r
+    }\r
+}\r