Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Add support for Signal ID to GSV Parser #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions src/main/java/net/sf/marineapi/nmea/parser/GSVParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* GSVParser.java
* Copyright (C) 2010 Kimmo Tuukkanen
* Copyright (C) 2010-2020 Kimmo Tuukkanen
*
* This file is part of Java Marine API.
* <http://ktuukkan.github.io/marine-api/>
Expand Down Expand Up @@ -32,6 +32,7 @@
* GSV sentence parser.
*
* @author Kimmo Tuukkanen
* @author Gunnar Hillert
*/
class GSVParser extends SentenceParser implements GSVSentence {

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

// Satellite Group Start Index
private static final int SATELLITE_GROUP_START_INDEX = 3;

// Each Satellite Group has 4 values
private static final int SATELLITE_GROUP_SIZE = 4;

// A GSV Sentence may contain up to 4 satellites
private static final int SATELLITE_GROUP_MAX_NUMBER_OF_SATELLITES = 4;

// satellite id fields
private static final int[] ID_FIELDS = {3, 7, 11, 15};
private static final int[] ID_FIELDS = {SATELLITE_GROUP_START_INDEX, 7, 11, 15};

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

/**
* @see net.sf.marineapi.nmea.sentence.GSVSentence#getSignalId()
*/
@Override
public int getSignalId() {
final int signalIdIndex;
if (!this.isLast()) {
signalIdIndex = SATELLITE_GROUP_START_INDEX + SATELLITE_GROUP_MAX_NUMBER_OF_SATELLITES * SATELLITE_GROUP_SIZE;
}
else {
int numberOfSatellites = this.getSatelliteCount() - ((this.getSentenceIndex() - 1) * SATELLITE_GROUP_SIZE);
signalIdIndex = SATELLITE_GROUP_START_INDEX + (SATELLITE_GROUP_SIZE * numberOfSatellites);
}
return getIntValue(signalIdIndex);
}

/*
* (non-Javadoc)
* @see net.sf.marineapi.nmea.sentence.GSVSentence#getSatelliteInfo()
Expand Down
67 changes: 51 additions & 16 deletions src/main/java/net/sf/marineapi/nmea/sentence/GSVSentence.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/*
/*
* GSVSentence.java
* Copyright (C) 2010 Kimmo Tuukkanen
*
*
* This file is part of Java Marine API.
* <http://ktuukkan.github.io/marine-api/>
*
*
* Java Marine API is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
*
* Java Marine API is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
*
* You should have received a copy of the GNU Lesser General Public License
* along with Java Marine API. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -35,42 +35,77 @@
* <p>
* Example: <br>
* {@code $GPGSV,3,2,12,15,56,182,51,17,38,163,47,18,63,058,50,21,53,329,47*73}
*
*
* @author Kimmo Tuukkanen
*/
public interface GSVSentence extends Sentence {

/**
* Get the number of satellites in view.
*
*
* @return Satellite count
*/
int getSatelliteCount();

/**
* Get the satellites information.
*
*
* @return List of SatelliteInfo objects.
*/
List<SatelliteInfo> getSatelliteInfo();

/**
* Get the total number of sentences in GSV sequence.
*
*
* @return Number of sentences
*/
int getSentenceCount();

/**
* Get the GNSS signal ID (only NMEA 4.10 and later).
* <p>
* Be aware, that the returned signal id may differ between NMEA versions. For
* example, in the NMEA protocol version 4.10 the BeiDou and QZSS signal IDs
* are not defined. Therefore u-blox devices, for example, will send a proprietary
* signal id value that differs from the one defined in NMEA Protocol 4.11.
*
* NMEA Protocol 4.11 defines the following signal ids:
*
* <ul>
* <li>GPS L1C/A = 1
* <li>GPS L2 CL = 6
* <li>GPS L2 CM = 5
* <li>SBAS L1C/A = 1
* <li>Galileo E1 C = 7
* <li>Galileo E1 B = 7
* <li>Galileo E5 bI = 2
* <li>Galileo E5 bQ = 2
* <li>BeiDou B1I D1 = 1
* <li>BeiDou B1I D2 = 1
* <li>BeiDou B2I D1 = 11
* <li>BeiDou B2I D2 = 11
* <li>QZSS L1C/A = 1
* <li>QZSS L1S = 4
* <li>QZSS L2 CM = 5
* <li>QZSS L2 CL = 6
* <li>GLONASS L1 OF = 1
* <li>GLONASS L2 OF = 3
* </ul>
*
* @return signal ID
*/
int getSignalId();

/**
* Get the index of this sentence in GSV sequence.
*
*
* @return Sentence index
*/
int getSentenceIndex();

/**
* Tells if this is the first sentence in GSV sequence.
*
*
* @return true if first, otherwise false.
* @see #getSentenceCount()
* @see #getSentenceIndex()
Expand All @@ -82,22 +117,22 @@ public interface GSVSentence extends Sentence {
* method for comparison of
* {@code ({@link #getSentenceCount()} == {@link #getSentenceIndex()})}
* .
*
*
* @return {@code true} if first, otherwise {@code false}.
*/
boolean isLast();

/**
* Set the number of satellites in view.
*
*
* @param count Satellite count
* @throws IllegalArgumentException If specified number is negative
*/
void setSatelliteCount(int count);

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

/**
* Set the total number of sentences in GSV sequence.
*
*
* @param count Number of sentences
* @throws IllegalArgumentException If specified count is negative
*/
void setSentenceCount(int count);

/**
* Set the index of this sentence in GSV sequence.
*
*
* @param index Sentence index to set
* @throws IllegalArgumentException If specified index is negative
*/
Expand Down
48 changes: 41 additions & 7 deletions src/test/java/net/sf/marineapi/nmea/parser/GSVTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* Test the GSV sentence parser.
*
*
* @author Kimmo Tuukkanen
*/
public class GSVTest {
Expand Down Expand Up @@ -65,17 +65,17 @@ public void testGetSatelliteInfo() {
testSatelliteInfo(sat.get(2), "18", 63, 58, 50);
testSatelliteInfo(sat.get(3), "21", 53, 329, 47);
}

/**
* Test method for
* {@link net.sf.marineapi.nmea.parser.GSVParser#getSatelliteInfo()}.
*/
@Test
public void testGetSatelliteInfoWithEmptyFields() {

GSVSentence g = new GSVParser("$GPGSV,3,2,12,15,56,182,51,17,38,163,47,18,,,,21,53,329,47");
List<SatelliteInfo> sat = g.getSatelliteInfo();

assertEquals(3, sat.size());
testSatelliteInfo(sat.get(0), "15", 56, 182, 51);
testSatelliteInfo(sat.get(1), "17", 38, 163, 47);
Expand All @@ -88,15 +88,15 @@ public void testGetSatelliteInfoWithEmptyFields() {
*/
@Test
public void testGetSatelliteInfoWithShortSentence() {

GSVSentence g = new GSVParser("$GPGSV,3,2,12,15,56,182,51,17,38,163,47");
List<SatelliteInfo> sat = g.getSatelliteInfo();

assertEquals(2, sat.size());
testSatelliteInfo(sat.get(0), "15", 56, 182, 51);
testSatelliteInfo(sat.get(1), "17", 38, 163, 47);
}

/**
* Test method for
* {@link net.sf.marineapi.nmea.parser.GSVParser#getSentenceCount()}.
Expand Down Expand Up @@ -181,6 +181,40 @@ public void testParserGlonassGSV() {
assertEquals(TalkerId.GL, gl.getTalkerId());
}

@Test
public void testGetSignalIdWith1Satellite() {
final String EXAMPLE_WITH_SIGNALID = "$GAGSV,2,2,06,27,25,133,29,33,33,238,,2*71";
final GSVParser gsv = new GSVParser(EXAMPLE_WITH_SIGNALID);
assertEquals(2, gsv.getSignalId());
}

@Test
public void testGetSignalIdWith2SatellitesMsgNum1() {
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";
GSVParser gsv = new GSVParser(EXAMPLE_WITH_SIGNALID);
assertEquals(2, gsv.getSignalId());
}

@Test
public void testGetSignalIdWith2SatellitesMsgNum2() {
final String EXAMPLE_WITH_SIGNALID = "$GPGSV,4,2,13,10,12,045,,11,47,333,42,14,,,40,16,15,193,33,1*5C";
final GSVParser gsv = new GSVParser(EXAMPLE_WITH_SIGNALID);
assertEquals(1, gsv.getSignalId());
}


@Test
public void testGetEmptySignalId() {
final String EXAMPLE_WITH_SIGNALID = "$GAGSV,2,2,06,27,25,133,29,33,33,238,,*43";
final GSVParser gsv = new GSVParser(EXAMPLE_WITH_SIGNALID); //12
try {
gsv.getSignalId();
} catch (DataNotAvailableException e) {
return;
}
fail("Expected a DataNotAvailableException to be thrown.");
}

/**
* Tests the given SatelliteInfo against specified values.
*/
Expand Down
Loading