{\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
set;\r
}\r
\r
- public int Health\r
+ public HealthIndication Health\r
{\r
get;\r
set;\r
--- /dev/null
+/*\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
--- /dev/null
+/*\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
--- /dev/null
+/*\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
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
{\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
<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
};\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
--- /dev/null
+/*\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
<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