OSDN Git Service

Wordのパリティ生成を実装
authorkimikage <kimikage_ceo@hotmail.com>
Mon, 7 Feb 2011 00:34:49 +0000 (09:34 +0900)
committerkimikage <kimikage_ceo@hotmail.com>
Mon, 7 Feb 2011 00:34:49 +0000 (09:34 +0900)
Yubeshi/Almanac.cs
Yubeshi/Gps/HandoverWord.cs [new file with mode: 0755]
Yubeshi/Gps/Subframe.cs [new file with mode: 0755]
Yubeshi/Gps/TelemetryWord.cs [new file with mode: 0755]
Yubeshi/Gps/Word.cs
Yubeshi/Yubeshi.csproj
Yubeshi/YumaAlmanacReader.cs
YubeshiTest/GpsTest/WordTest.cs [new file with mode: 0755]
YubeshiTest/YubeshiTest.csproj

index 898ddd4..8dbe2bf 100755 (executable)
@@ -13,6 +13,19 @@ namespace Yubeshi
 {\r
     public class Almanac\r
     {\r
+        #region type definitions\r
+        public enum HealthIndication : byte\r
+        { \r
+            AllDataOk = 0,\r
+            ParityFailure = 1,\r
+            TlmHowFormatProblem = 2,\r
+            ZCountInHowBad = 3,\r
+            Subframes123 = 4,\r
+            Subframes45 = 5,\r
+            AllUploadedDataBad = 6,\r
+            AllDataBad = 7\r
+        }\r
+        #endregion\r
         #region properties\r
         public int ID\r
         {\r
@@ -20,7 +33,7 @@ namespace Yubeshi
             set;\r
         }\r
 \r
-        public int Health\r
+        public HealthIndication Health\r
         {\r
             get;\r
             set;\r
diff --git a/Yubeshi/Gps/HandoverWord.cs b/Yubeshi/Gps/HandoverWord.cs
new file mode 100755 (executable)
index 0000000..4c68a11
--- /dev/null
@@ -0,0 +1,17 @@
+/*\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
+\r
+namespace Yubeshi.Gps\r
+{\r
+    class HandoverWord : Word\r
+    {\r
+    }\r
+}\r
diff --git a/Yubeshi/Gps/Subframe.cs b/Yubeshi/Gps/Subframe.cs
new file mode 100755 (executable)
index 0000000..2a63b2c
--- /dev/null
@@ -0,0 +1,29 @@
+/*\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
+\r
+namespace Yubeshi.Gps\r
+{\r
+    public abstract class Subframe\r
+    {\r
+        #region fields\r
+        protected Word[] words;\r
+        #endregion\r
+\r
+        #region constructor\r
+        public Subframe(Word[] words)\r
+        {\r
+            this.words = words;\r
+        }\r
+\r
+        #endregion\r
+\r
+    }\r
+}\r
diff --git a/Yubeshi/Gps/TelemetryWord.cs b/Yubeshi/Gps/TelemetryWord.cs
new file mode 100755 (executable)
index 0000000..28204ec
--- /dev/null
@@ -0,0 +1,17 @@
+/*\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
+\r
+namespace Yubeshi.Gps\r
+{\r
+    class TelemetryWord : Word\r
+    {\r
+    }\r
+}\r
index 6faf224..0fe5258 100755 (executable)
@@ -14,19 +14,45 @@ namespace Yubeshi.Gps
     public class Word\r
     {\r
         #region fields\r
+        public static readonly Word Null = new Word();\r
+        /// <summary>\r
+        ///     (msb) D29* D30* D1 D2 ... D24 ... D28 D29 D30 (lsb)\r
+        /// </summary>\r
         protected uint value;\r
-\r
         #endregion\r
 \r
         #region constructor\r
+        public Word()\r
+        {\r
+            value = 0;\r
+        }\r
 \r
         public Word(uint source)\r
+            : this(source, Word.Null)\r
         {\r
-            value = source;\r
+        }\r
+\r
+        public Word(uint source, Word previous)\r
+        {\r
+            if ((previous & 1) != 0)\r
+            {\r
+                source ^= 0xFFFFFF;\r
+            }\r
+            value = (source & 0xFFFFFF) << 6;\r
+            value |= (previous & 3) << 30;\r
+            \r
+            value |= GenerateParity(this);\r
         }\r
         #endregion\r
 \r
         #region operator\r
+        public static implicit operator Word(uint value)\r
+        {\r
+            Word w = new Word();\r
+            w.value = value;\r
+            return w;\r
+        }\r
+\r
         public static implicit operator uint(Word word)\r
         {\r
             return (uint)word.value;\r
@@ -38,10 +64,63 @@ namespace Yubeshi.Gps
         {\r
             get\r
             {\r
-                return value >> 24;\r
+                return value & 0x3F;\r
+            }\r
+        }\r
+\r
+        public uint Source\r
+        {\r
+            get\r
+            {\r
+                return (value & 0x3FFFFFC0) >> 6;\r
             }\r
         }\r
 \r
+        public uint Value\r
+        {\r
+            get\r
+            {\r
+                return value;\r
+            }\r
+        }\r
+\r
+        #endregion\r
+\r
+        #region public methods\r
+        public static uint GenerateParity(Word word)\r
+        {\r
+            // (msb) 0 0 d1 d2 ... d24 0 0 0 0 D29* D30* (lsb)\r
+            uint s = (word & 0x3FFFFFC0) | (word >> 30);\r
+            if ((word & 0x40000000) != 0)\r
+            {\r
+                s ^= 0x3FFFFFC0;\r
+            }\r
+            uint[] c = new uint[]{      //            111111111122222222223\r
+                                        //   123456789012345678901234567890\r
+                            0x0b7a89c2, // 0b001011011110101000100111000010\r
+                            0x2bb1f341, // 0b101011101100011111001101000001\r
+                            0x1763e681, // 0b010111011000111110011010000001\r
+                            0x2ec7cd02, // 0b101110110001111100110100000010\r
+                            0x1d8f9a41, // 0b011101100011111001101001000001\r
+                            0x3b1f3482, // 0b111011000111110011010010000010\r
+                            };\r
+            for (int i = 0; i < c.Length; ++i)\r
+            {\r
+                c[i] &= s;\r
+                c[i] ^= c[i] >> 16;\r
+                c[i] ^= c[i] >> 8;\r
+                c[i] ^= c[i] >> 4;\r
+                c[i] ^= c[i] >> 2;\r
+                c[i] ^= c[i] >> 1;\r
+            }\r
+            uint parity = 0;\r
+            for (int i = 0; i < c.Length; ++i)\r
+            {\r
+                parity |= (c[i] & 1) << i;\r
+            }\r
+            \r
+            return parity;\r
+        }\r
         #endregion\r
     }\r
 }\r
index 0a43c69..09283aa 100755 (executable)
     <Compile Include="GeodeticCoordinate.cs" />\r
     <Compile Include="EcefCoordinate.cs" />\r
     <Compile Include="EcefVelocity.cs" />\r
+    <Compile Include="Gps\TelemetryWord.cs" />\r
     <Compile Include="Gps\Word.cs" />\r
+    <Compile Include="Gps\Subframe.cs" />\r
+    <Compile Include="Gps\HandoverWord.cs" />\r
     <Compile Include="Nmea\Parser.cs" />\r
     <Compile Include="OctetString.cs" />\r
     <Compile Include="Parser.cs" />\r
index 08c3193..98e810d 100755 (executable)
@@ -44,7 +44,7 @@ namespace Yubeshi
                 };\r
             setters["Health"] = delegate(Almanac a, string v)\r
                 {\r
-                    a.Health = Int32.Parse(v);\r
+                    a.Health = (Almanac.HealthIndication)Int16.Parse(v);\r
                 };\r
             setters["Eccentricity"] = delegate(Almanac a, string v)\r
                 {\r
diff --git a/YubeshiTest/GpsTest/WordTest.cs b/YubeshiTest/GpsTest/WordTest.cs
new file mode 100755 (executable)
index 0000000..7459cdd
--- /dev/null
@@ -0,0 +1,41 @@
+/*\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.Gps;\r
+\r
+namespace YubeshiTest.GpsTest\r
+{\r
+    class WordTest\r
+    {\r
+\r
+        [Test]\r
+        public void Encode()\r
+        {\r
+            Word w1;\r
+            Word w2;\r
+            w1 = new Word(0x8B6DE8);\r
+            w2 = new Word(0x8B6DE8, (Word)2);\r
+            Assert.AreEqual(w1.Parity, Word.GenerateParity(w1));\r
+            Assert.AreEqual(w2.Parity, Word.GenerateParity(w2));\r
+\r
+            w1 = new Word(0x8B6002);\r
+            w2 = new Word(0x8B6002, (Word)2);\r
+            Assert.AreEqual(w1.Parity, Word.GenerateParity(w1));\r
+            Assert.AreEqual(w2.Parity, Word.GenerateParity(w2));\r
+\r
+            w1 = new Word(0x8B8074);\r
+            w2 = new Word(0x1BCD15, (Word)2);\r
+            Assert.AreEqual(w1.Parity, Word.GenerateParity(w1));\r
+            Assert.AreEqual(w2.Parity, Word.GenerateParity(w2));\r
+        }\r
+\r
+    }\r
+}\r
index 4954802..db3eb66 100755 (executable)
@@ -46,6 +46,7 @@
   <ItemGroup>\r
     <Compile Include="EcefCoordinateTest.cs" />\r
     <Compile Include="GeodeticCoordinateTest.cs" />\r
+    <Compile Include="GpsTest\WordTest.cs" />\r
     <Compile Include="NmeaTest\PacketTest.cs" />\r
     <Compile Include="NmeaTest\ParserTest.cs" />\r
     <Compile Include="NmeaTest\SamplePackets.cs" />\r