• R/O
  • HTTP
  • SSH
  • HTTPS

yubeshi: Commit

source codes and tests


Commit MetaInfo

Revision159781834080903c0cb5aad945ff2a72c60a354f (tree)
Time2011-02-07 09:34:49
Authorkimikage <kimikage_ceo@hotm...>
Commiterkimikage

Log Message

Wordのパリティ生成を実装

Change Summary

Incremental Difference

--- a/Yubeshi/Almanac.cs
+++ b/Yubeshi/Almanac.cs
@@ -13,6 +13,19 @@ namespace Yubeshi
1313 {
1414 public class Almanac
1515 {
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
1629 #region properties
1730 public int ID
1831 {
@@ -20,7 +33,7 @@ namespace Yubeshi
2033 set;
2134 }
2235
23- public int Health
36+ public HealthIndication Health
2437 {
2538 get;
2639 set;
--- /dev/null
+++ b/Yubeshi/Gps/HandoverWord.cs
@@ -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+}
--- /dev/null
+++ b/Yubeshi/Gps/Subframe.cs
@@ -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+}
--- /dev/null
+++ b/Yubeshi/Gps/TelemetryWord.cs
@@ -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+}
--- a/Yubeshi/Gps/Word.cs
+++ b/Yubeshi/Gps/Word.cs
@@ -14,19 +14,45 @@ namespace Yubeshi.Gps
1414 public class Word
1515 {
1616 #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>
1721 protected uint value;
18-
1922 #endregion
2023
2124 #region constructor
25+ public Word()
26+ {
27+ value = 0;
28+ }
2229
2330 public Word(uint source)
31+ : this(source, Word.Null)
2432 {
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);
2645 }
2746 #endregion
2847
2948 #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+
3056 public static implicit operator uint(Word word)
3157 {
3258 return (uint)word.value;
@@ -38,10 +64,63 @@ namespace Yubeshi.Gps
3864 {
3965 get
4066 {
41- return value >> 24;
67+ return value & 0x3F;
68+ }
69+ }
70+
71+ public uint Source
72+ {
73+ get
74+ {
75+ return (value & 0x3FFFFFC0) >> 6;
4276 }
4377 }
4478
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+ }
45124 #endregion
46125 }
47126 }
--- a/Yubeshi/Yubeshi.csproj
+++ b/Yubeshi/Yubeshi.csproj
@@ -43,7 +43,10 @@
4343 <Compile Include="GeodeticCoordinate.cs" />
4444 <Compile Include="EcefCoordinate.cs" />
4545 <Compile Include="EcefVelocity.cs" />
46+ <Compile Include="Gps\TelemetryWord.cs" />
4647 <Compile Include="Gps\Word.cs" />
48+ <Compile Include="Gps\Subframe.cs" />
49+ <Compile Include="Gps\HandoverWord.cs" />
4750 <Compile Include="Nmea\Parser.cs" />
4851 <Compile Include="OctetString.cs" />
4952 <Compile Include="Parser.cs" />
--- a/Yubeshi/YumaAlmanacReader.cs
+++ b/Yubeshi/YumaAlmanacReader.cs
@@ -44,7 +44,7 @@ namespace Yubeshi
4444 };
4545 setters["Health"] = delegate(Almanac a, string v)
4646 {
47- a.Health = Int32.Parse(v);
47+ a.Health = (Almanac.HealthIndication)Int16.Parse(v);
4848 };
4949 setters["Eccentricity"] = delegate(Almanac a, string v)
5050 {
--- /dev/null
+++ b/YubeshiTest/GpsTest/WordTest.cs
@@ -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+}
--- a/YubeshiTest/YubeshiTest.csproj
+++ b/YubeshiTest/YubeshiTest.csproj
@@ -46,6 +46,7 @@
4646 <ItemGroup>
4747 <Compile Include="EcefCoordinateTest.cs" />
4848 <Compile Include="GeodeticCoordinateTest.cs" />
49+ <Compile Include="GpsTest\WordTest.cs" />
4950 <Compile Include="NmeaTest\PacketTest.cs" />
5051 <Compile Include="NmeaTest\ParserTest.cs" />
5152 <Compile Include="NmeaTest\SamplePackets.cs" />
Show on old repository browser