source codes and tests
Revision | 159781834080903c0cb5aad945ff2a72c60a354f (tree) |
---|---|
Time | 2011-02-07 09:34:49 |
Author | kimikage <kimikage_ceo@hotm...> |
Commiter | kimikage |
Wordのパリティ生成を実装
@@ -13,6 +13,19 @@ namespace Yubeshi | ||
13 | 13 | { |
14 | 14 | public class Almanac |
15 | 15 | { |
16 | + #region type definitions | |
17 | + public enum HealthIndication : byte | |
18 | + { | |
19 | + AllDataOk = 0, | |
20 | + ParityFailure = 1, | |
21 | + TlmHowFormatProblem = 2, | |
22 | + ZCountInHowBad = 3, | |
23 | + Subframes123 = 4, | |
24 | + Subframes45 = 5, | |
25 | + AllUploadedDataBad = 6, | |
26 | + AllDataBad = 7 | |
27 | + } | |
28 | + #endregion | |
16 | 29 | #region properties |
17 | 30 | public int ID |
18 | 31 | { |
@@ -20,7 +33,7 @@ namespace Yubeshi | ||
20 | 33 | set; |
21 | 34 | } |
22 | 35 | |
23 | - public int Health | |
36 | + public HealthIndication Health | |
24 | 37 | { |
25 | 38 | get; |
26 | 39 | set; |
@@ -0,0 +1,17 @@ | ||
1 | +/* | |
2 | + * Yubeshi GPS Parser | |
3 | + * | |
4 | + * This software is distributed under a zlib-style license. | |
5 | + * See license.txt for more information. | |
6 | + */ | |
7 | + | |
8 | +using System; | |
9 | +using System.Collections.Generic; | |
10 | +using System.Text; | |
11 | + | |
12 | +namespace Yubeshi.Gps | |
13 | +{ | |
14 | + class HandoverWord : Word | |
15 | + { | |
16 | + } | |
17 | +} |
@@ -0,0 +1,29 @@ | ||
1 | +/* | |
2 | + * Yubeshi GPS Parser | |
3 | + * | |
4 | + * This software is distributed under a zlib-style license. | |
5 | + * See license.txt for more information. | |
6 | + */ | |
7 | + | |
8 | +using System; | |
9 | +using System.Collections.Generic; | |
10 | +using System.Text; | |
11 | + | |
12 | +namespace Yubeshi.Gps | |
13 | +{ | |
14 | + public abstract class Subframe | |
15 | + { | |
16 | + #region fields | |
17 | + protected Word[] words; | |
18 | + #endregion | |
19 | + | |
20 | + #region constructor | |
21 | + public Subframe(Word[] words) | |
22 | + { | |
23 | + this.words = words; | |
24 | + } | |
25 | + | |
26 | + #endregion | |
27 | + | |
28 | + } | |
29 | +} |
@@ -0,0 +1,17 @@ | ||
1 | +/* | |
2 | + * Yubeshi GPS Parser | |
3 | + * | |
4 | + * This software is distributed under a zlib-style license. | |
5 | + * See license.txt for more information. | |
6 | + */ | |
7 | + | |
8 | +using System; | |
9 | +using System.Collections.Generic; | |
10 | +using System.Text; | |
11 | + | |
12 | +namespace Yubeshi.Gps | |
13 | +{ | |
14 | + class TelemetryWord : Word | |
15 | + { | |
16 | + } | |
17 | +} |
@@ -14,19 +14,45 @@ namespace Yubeshi.Gps | ||
14 | 14 | public class Word |
15 | 15 | { |
16 | 16 | #region fields |
17 | + public static readonly Word Null = new Word(); | |
18 | + /// <summary> | |
19 | + /// (msb) D29* D30* D1 D2 ... D24 ... D28 D29 D30 (lsb) | |
20 | + /// </summary> | |
17 | 21 | protected uint value; |
18 | - | |
19 | 22 | #endregion |
20 | 23 | |
21 | 24 | #region constructor |
25 | + public Word() | |
26 | + { | |
27 | + value = 0; | |
28 | + } | |
22 | 29 | |
23 | 30 | public Word(uint source) |
31 | + : this(source, Word.Null) | |
24 | 32 | { |
25 | - value = source; | |
33 | + } | |
34 | + | |
35 | + public Word(uint source, Word previous) | |
36 | + { | |
37 | + if ((previous & 1) != 0) | |
38 | + { | |
39 | + source ^= 0xFFFFFF; | |
40 | + } | |
41 | + value = (source & 0xFFFFFF) << 6; | |
42 | + value |= (previous & 3) << 30; | |
43 | + | |
44 | + value |= GenerateParity(this); | |
26 | 45 | } |
27 | 46 | #endregion |
28 | 47 | |
29 | 48 | #region operator |
49 | + public static implicit operator Word(uint value) | |
50 | + { | |
51 | + Word w = new Word(); | |
52 | + w.value = value; | |
53 | + return w; | |
54 | + } | |
55 | + | |
30 | 56 | public static implicit operator uint(Word word) |
31 | 57 | { |
32 | 58 | return (uint)word.value; |
@@ -38,10 +64,63 @@ namespace Yubeshi.Gps | ||
38 | 64 | { |
39 | 65 | get |
40 | 66 | { |
41 | - return value >> 24; | |
67 | + return value & 0x3F; | |
68 | + } | |
69 | + } | |
70 | + | |
71 | + public uint Source | |
72 | + { | |
73 | + get | |
74 | + { | |
75 | + return (value & 0x3FFFFFC0) >> 6; | |
42 | 76 | } |
43 | 77 | } |
44 | 78 | |
79 | + public uint Value | |
80 | + { | |
81 | + get | |
82 | + { | |
83 | + return value; | |
84 | + } | |
85 | + } | |
86 | + | |
87 | + #endregion | |
88 | + | |
89 | + #region public methods | |
90 | + public static uint GenerateParity(Word word) | |
91 | + { | |
92 | + // (msb) 0 0 d1 d2 ... d24 0 0 0 0 D29* D30* (lsb) | |
93 | + uint s = (word & 0x3FFFFFC0) | (word >> 30); | |
94 | + if ((word & 0x40000000) != 0) | |
95 | + { | |
96 | + s ^= 0x3FFFFFC0; | |
97 | + } | |
98 | + uint[] c = new uint[]{ // 111111111122222222223 | |
99 | + // 123456789012345678901234567890 | |
100 | + 0x0b7a89c2, // 0b001011011110101000100111000010 | |
101 | + 0x2bb1f341, // 0b101011101100011111001101000001 | |
102 | + 0x1763e681, // 0b010111011000111110011010000001 | |
103 | + 0x2ec7cd02, // 0b101110110001111100110100000010 | |
104 | + 0x1d8f9a41, // 0b011101100011111001101001000001 | |
105 | + 0x3b1f3482, // 0b111011000111110011010010000010 | |
106 | + }; | |
107 | + for (int i = 0; i < c.Length; ++i) | |
108 | + { | |
109 | + c[i] &= s; | |
110 | + c[i] ^= c[i] >> 16; | |
111 | + c[i] ^= c[i] >> 8; | |
112 | + c[i] ^= c[i] >> 4; | |
113 | + c[i] ^= c[i] >> 2; | |
114 | + c[i] ^= c[i] >> 1; | |
115 | + } | |
116 | + uint parity = 0; | |
117 | + for (int i = 0; i < c.Length; ++i) | |
118 | + { | |
119 | + parity |= (c[i] & 1) << i; | |
120 | + } | |
121 | + | |
122 | + return parity; | |
123 | + } | |
45 | 124 | #endregion |
46 | 125 | } |
47 | 126 | } |
@@ -43,7 +43,10 @@ | ||
43 | 43 | <Compile Include="GeodeticCoordinate.cs" /> |
44 | 44 | <Compile Include="EcefCoordinate.cs" /> |
45 | 45 | <Compile Include="EcefVelocity.cs" /> |
46 | + <Compile Include="Gps\TelemetryWord.cs" /> | |
46 | 47 | <Compile Include="Gps\Word.cs" /> |
48 | + <Compile Include="Gps\Subframe.cs" /> | |
49 | + <Compile Include="Gps\HandoverWord.cs" /> | |
47 | 50 | <Compile Include="Nmea\Parser.cs" /> |
48 | 51 | <Compile Include="OctetString.cs" /> |
49 | 52 | <Compile Include="Parser.cs" /> |
@@ -44,7 +44,7 @@ namespace Yubeshi | ||
44 | 44 | }; |
45 | 45 | setters["Health"] = delegate(Almanac a, string v) |
46 | 46 | { |
47 | - a.Health = Int32.Parse(v); | |
47 | + a.Health = (Almanac.HealthIndication)Int16.Parse(v); | |
48 | 48 | }; |
49 | 49 | setters["Eccentricity"] = delegate(Almanac a, string v) |
50 | 50 | { |
@@ -0,0 +1,41 @@ | ||
1 | +/* | |
2 | + * Yubeshi GPS Parser | |
3 | + * | |
4 | + * This software is distributed under a zlib-style license. | |
5 | + * See license.txt for more information. | |
6 | + */ | |
7 | + | |
8 | +using System; | |
9 | +using System.Collections.Generic; | |
10 | +using System.Text; | |
11 | +using NUnit.Framework; | |
12 | +using Yubeshi.Gps; | |
13 | + | |
14 | +namespace YubeshiTest.GpsTest | |
15 | +{ | |
16 | + class WordTest | |
17 | + { | |
18 | + | |
19 | + [Test] | |
20 | + public void Encode() | |
21 | + { | |
22 | + Word w1; | |
23 | + Word w2; | |
24 | + w1 = new Word(0x8B6DE8); | |
25 | + w2 = new Word(0x8B6DE8, (Word)2); | |
26 | + Assert.AreEqual(w1.Parity, Word.GenerateParity(w1)); | |
27 | + Assert.AreEqual(w2.Parity, Word.GenerateParity(w2)); | |
28 | + | |
29 | + w1 = new Word(0x8B6002); | |
30 | + w2 = new Word(0x8B6002, (Word)2); | |
31 | + Assert.AreEqual(w1.Parity, Word.GenerateParity(w1)); | |
32 | + Assert.AreEqual(w2.Parity, Word.GenerateParity(w2)); | |
33 | + | |
34 | + w1 = new Word(0x8B8074); | |
35 | + w2 = new Word(0x1BCD15, (Word)2); | |
36 | + Assert.AreEqual(w1.Parity, Word.GenerateParity(w1)); | |
37 | + Assert.AreEqual(w2.Parity, Word.GenerateParity(w2)); | |
38 | + } | |
39 | + | |
40 | + } | |
41 | +} |
@@ -46,6 +46,7 @@ | ||
46 | 46 | <ItemGroup> |
47 | 47 | <Compile Include="EcefCoordinateTest.cs" /> |
48 | 48 | <Compile Include="GeodeticCoordinateTest.cs" /> |
49 | + <Compile Include="GpsTest\WordTest.cs" /> | |
49 | 50 | <Compile Include="NmeaTest\PacketTest.cs" /> |
50 | 51 | <Compile Include="NmeaTest\ParserTest.cs" /> |
51 | 52 | <Compile Include="NmeaTest\SamplePackets.cs" /> |