Skip to content

Commit 21d35c1

Browse files
committed
Add support for Signal ID to GSV Parser
resolves ktuukkangh-116
1 parent 09424f5 commit 21d35c1

File tree

3 files changed

+120
-25
lines changed

3 files changed

+120
-25
lines changed

src/main/java/net/sf/marineapi/nmea/parser/GSVParser.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* GSVParser.java
3-
* Copyright (C) 2010 Kimmo Tuukkanen
3+
* Copyright (C) 2010-2020 Kimmo Tuukkanen
44
*
55
* This file is part of Java Marine API.
66
* <http://ktuukkan.github.io/marine-api/>
@@ -32,6 +32,7 @@
3232
* GSV sentence parser.
3333
*
3434
* @author Kimmo Tuukkanen
35+
* @author Gunnar Hillert
3536
*/
3637
class GSVParser extends SentenceParser implements GSVSentence {
3738

@@ -40,8 +41,17 @@ class GSVParser extends SentenceParser implements GSVSentence {
4041
private static final int SENTENCE_NUMBER = 1;
4142
private static final int SATELLITES_IN_VIEW = 2;
4243

44+
// Satellite Group Start Index
45+
private static final int SATELLITE_GROUP_START_INDEX = 3;
46+
47+
// Each Satellite Group has 4 values
48+
private static final int SATELLITE_GROUP_SIZE = 4;
49+
50+
// A GSV Sentence may contain up to 4 satellites
51+
private static final int SATELLITE_GROUP_MAX_NUMBER_OF_SATELLITES = 4;
52+
4353
// satellite id fields
44-
private static final int[] ID_FIELDS = {3, 7, 11, 15};
54+
private static final int[] ID_FIELDS = {SATELLITE_GROUP_START_INDEX, 7, 11, 15};
4555

4656
// satellite data fields, relative to each id field
4757
private static final int ELEVATION = 1;
@@ -74,6 +84,22 @@ public int getSatelliteCount() {
7484
return getIntValue(SATELLITES_IN_VIEW);
7585
}
7686

87+
/**
88+
* @see net.sf.marineapi.nmea.sentence.GSVSentence#getSignalId()
89+
*/
90+
@Override
91+
public int getSignalId() {
92+
final int signalIdIndex;
93+
if (!this.isLast()) {
94+
signalIdIndex = SATELLITE_GROUP_START_INDEX + SATELLITE_GROUP_MAX_NUMBER_OF_SATELLITES * SATELLITE_GROUP_SIZE;
95+
}
96+
else {
97+
int numberOfSatellites = this.getSatelliteCount() - ((this.getSentenceIndex() - 1) * SATELLITE_GROUP_SIZE);
98+
signalIdIndex = SATELLITE_GROUP_START_INDEX + (SATELLITE_GROUP_SIZE * numberOfSatellites);
99+
}
100+
return getIntValue(signalIdIndex);
101+
}
102+
77103
/*
78104
* (non-Javadoc)
79105
* @see net.sf.marineapi.nmea.sentence.GSVSentence#getSatelliteInfo()

src/main/java/net/sf/marineapi/nmea/sentence/GSVSentence.java

+51-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
/*
1+
/*
22
* GSVSentence.java
33
* Copyright (C) 2010 Kimmo Tuukkanen
4-
*
4+
*
55
* This file is part of Java Marine API.
66
* <http://ktuukkan.github.io/marine-api/>
7-
*
7+
*
88
* Java Marine API is free software: you can redistribute it and/or modify it
99
* under the terms of the GNU Lesser General Public License as published by the
1010
* Free Software Foundation, either version 3 of the License, or (at your
1111
* option) any later version.
12-
*
12+
*
1313
* Java Marine API is distributed in the hope that it will be useful, but
1414
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1515
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
1616
* for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with Java Marine API. If not, see <http://www.gnu.org/licenses/>.
2020
*/
@@ -35,42 +35,77 @@
3535
* <p>
3636
* Example: <br>
3737
* {@code $GPGSV,3,2,12,15,56,182,51,17,38,163,47,18,63,058,50,21,53,329,47*73}
38-
*
38+
*
3939
* @author Kimmo Tuukkanen
4040
*/
4141
public interface GSVSentence extends Sentence {
4242

4343
/**
4444
* Get the number of satellites in view.
45-
*
45+
*
4646
* @return Satellite count
4747
*/
4848
int getSatelliteCount();
4949

5050
/**
5151
* Get the satellites information.
52-
*
52+
*
5353
* @return List of SatelliteInfo objects.
5454
*/
5555
List<SatelliteInfo> getSatelliteInfo();
5656

5757
/**
5858
* Get the total number of sentences in GSV sequence.
59-
*
59+
*
6060
* @return Number of sentences
6161
*/
6262
int getSentenceCount();
6363

64+
/**
65+
* Get the GNSS signal ID (only NMEA 4.10 and later).
66+
* <p>
67+
* Be aware, that the returned signal id may differ between NMEA versions. For
68+
* example, in the NMEA protocol version 4.10 the BeiDou and QZSS signal IDs
69+
* are not defined. Therefore u-blox devices, for example, will send a proprietary
70+
* signal id value that differs from the one defined in NMEA Protocol 4.11.
71+
*
72+
* NMEA Protocol 4.11 defines the following signal ids:
73+
*
74+
* <ul>
75+
* <li>GPS L1C/A = 1
76+
* <li>GPS L2 CL = 6
77+
* <li>GPS L2 CM = 5
78+
* <li>SBAS L1C/A = 1
79+
* <li>Galileo E1 C = 7
80+
* <li>Galileo E1 B = 7
81+
* <li>Galileo E5 bI = 2
82+
* <li>Galileo E5 bQ = 2
83+
* <li>BeiDou B1I D1 = 1
84+
* <li>BeiDou B1I D2 = 1
85+
* <li>BeiDou B2I D1 = 11
86+
* <li>BeiDou B2I D2 = 11
87+
* <li>QZSS L1C/A = 1
88+
* <li>QZSS L1S = 4
89+
* <li>QZSS L2 CM = 5
90+
* <li>QZSS L2 CL = 6
91+
* <li>GLONASS L1 OF = 1
92+
* <li>GLONASS L2 OF = 3
93+
* </ul>
94+
*
95+
* @return signal ID
96+
*/
97+
int getSignalId();
98+
6499
/**
65100
* Get the index of this sentence in GSV sequence.
66-
*
101+
*
67102
* @return Sentence index
68103
*/
69104
int getSentenceIndex();
70105

71106
/**
72107
* Tells if this is the first sentence in GSV sequence.
73-
*
108+
*
74109
* @return true if first, otherwise false.
75110
* @see #getSentenceCount()
76111
* @see #getSentenceIndex()
@@ -82,22 +117,22 @@ public interface GSVSentence extends Sentence {
82117
* method for comparison of
83118
* {@code ({@link #getSentenceCount()} == {@link #getSentenceIndex()})}
84119
* .
85-
*
120+
*
86121
* @return {@code true} if first, otherwise {@code false}.
87122
*/
88123
boolean isLast();
89124

90125
/**
91126
* Set the number of satellites in view.
92-
*
127+
*
93128
* @param count Satellite count
94129
* @throws IllegalArgumentException If specified number is negative
95130
*/
96131
void setSatelliteCount(int count);
97132

98133
/**
99134
* Set the satellite information.
100-
*
135+
*
101136
* @param info List of SatelliteInfo objects, size from 0 to 4.
102137
* @throws IllegalArgumentException If specified list size is greater that
103138
* maximum allowed number of satellites per sentence (4).
@@ -106,15 +141,15 @@ public interface GSVSentence extends Sentence {
106141

107142
/**
108143
* Set the total number of sentences in GSV sequence.
109-
*
144+
*
110145
* @param count Number of sentences
111146
* @throws IllegalArgumentException If specified count is negative
112147
*/
113148
void setSentenceCount(int count);
114149

115150
/**
116151
* Set the index of this sentence in GSV sequence.
117-
*
152+
*
118153
* @param index Sentence index to set
119154
* @throws IllegalArgumentException If specified index is negative
120155
*/

src/test/java/net/sf/marineapi/nmea/parser/GSVTest.java

+41-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* Test the GSV sentence parser.
20-
*
20+
*
2121
* @author Kimmo Tuukkanen
2222
*/
2323
public class GSVTest {
@@ -65,17 +65,17 @@ public void testGetSatelliteInfo() {
6565
testSatelliteInfo(sat.get(2), "18", 63, 58, 50);
6666
testSatelliteInfo(sat.get(3), "21", 53, 329, 47);
6767
}
68-
68+
6969
/**
7070
* Test method for
7171
* {@link net.sf.marineapi.nmea.parser.GSVParser#getSatelliteInfo()}.
7272
*/
7373
@Test
7474
public void testGetSatelliteInfoWithEmptyFields() {
75-
75+
7676
GSVSentence g = new GSVParser("$GPGSV,3,2,12,15,56,182,51,17,38,163,47,18,,,,21,53,329,47");
7777
List<SatelliteInfo> sat = g.getSatelliteInfo();
78-
78+
7979
assertEquals(3, sat.size());
8080
testSatelliteInfo(sat.get(0), "15", 56, 182, 51);
8181
testSatelliteInfo(sat.get(1), "17", 38, 163, 47);
@@ -88,15 +88,15 @@ public void testGetSatelliteInfoWithEmptyFields() {
8888
*/
8989
@Test
9090
public void testGetSatelliteInfoWithShortSentence() {
91-
91+
9292
GSVSentence g = new GSVParser("$GPGSV,3,2,12,15,56,182,51,17,38,163,47");
9393
List<SatelliteInfo> sat = g.getSatelliteInfo();
94-
94+
9595
assertEquals(2, sat.size());
9696
testSatelliteInfo(sat.get(0), "15", 56, 182, 51);
9797
testSatelliteInfo(sat.get(1), "17", 38, 163, 47);
9898
}
99-
99+
100100
/**
101101
* Test method for
102102
* {@link net.sf.marineapi.nmea.parser.GSVParser#getSentenceCount()}.
@@ -181,6 +181,40 @@ public void testParserGlonassGSV() {
181181
assertEquals(TalkerId.GL, gl.getTalkerId());
182182
}
183183

184+
@Test
185+
public void testGetSignalIdWith1Satellite() {
186+
final String EXAMPLE_WITH_SIGNALID = "$GAGSV,2,2,06,27,25,133,29,33,33,238,,2*71";
187+
final GSVParser gsv = new GSVParser(EXAMPLE_WITH_SIGNALID);
188+
assertEquals(2, gsv.getSignalId());
189+
}
190+
191+
@Test
192+
public void testGetSignalIdWith2SatellitesMsgNum1() {
193+
final String EXAMPLE_WITH_SIGNALID = "$GAGSV,2,1,06,01,44,330,,13,33,031,19,21,75,093,38,26,73,310,,2*78";
194+
GSVParser gsv = new GSVParser(EXAMPLE_WITH_SIGNALID);
195+
assertEquals(2, gsv.getSignalId());
196+
}
197+
198+
@Test
199+
public void testGetSignalIdWith2SatellitesMsgNum2() {
200+
final String EXAMPLE_WITH_SIGNALID = "$GPGSV,4,2,13,10,12,045,,11,47,333,42,14,,,40,16,15,193,33,1*5C";
201+
final GSVParser gsv = new GSVParser(EXAMPLE_WITH_SIGNALID);
202+
assertEquals(1, gsv.getSignalId());
203+
}
204+
205+
206+
@Test
207+
public void testGetEmptySignalId() {
208+
final String EXAMPLE_WITH_SIGNALID = "$GAGSV,2,2,06,27,25,133,29,33,33,238,,*43";
209+
final GSVParser gsv = new GSVParser(EXAMPLE_WITH_SIGNALID); //12
210+
try {
211+
gsv.getSignalId();
212+
} catch (DataNotAvailableException e) {
213+
return;
214+
}
215+
fail("Expected a DataNotAvailableException to be thrown.");
216+
}
217+
184218
/**
185219
* Tests the given SatelliteInfo against specified values.
186220
*/

0 commit comments

Comments
 (0)