├── .gitignore ├── src ├── main │ ├── java │ │ └── net │ │ │ └── sf │ │ │ └── marineapi │ │ │ ├── util │ │ │ └── package-info.java │ │ │ ├── nmea │ │ │ ├── io │ │ │ │ ├── package-info.java │ │ │ │ ├── DataListener.java │ │ │ │ ├── ExceptionListener.java │ │ │ │ ├── DefaultDataReader.java │ │ │ │ └── ActivityMonitor.java │ │ │ ├── event │ │ │ │ ├── package-info.java │ │ │ │ └── SentenceEvent.java │ │ │ ├── sentence │ │ │ │ ├── package-info.java │ │ │ │ ├── HDMSentence.java │ │ │ │ ├── HDTSentence.java │ │ │ │ ├── DTBSentence.java │ │ │ │ ├── DepthSentence.java │ │ │ │ ├── MTASentence.java │ │ │ │ ├── MTWSentence.java │ │ │ │ ├── TimeSentence.java │ │ │ │ ├── DBTSentence.java │ │ │ │ ├── PositionSentence.java │ │ │ │ ├── HeadingSentence.java │ │ │ │ ├── WPLSentence.java │ │ │ │ ├── ROTSentence.java │ │ │ │ ├── DPTSentence.java │ │ │ │ ├── MMBSentence.java │ │ │ │ ├── DateSentence.java │ │ │ │ ├── VDRSentence.java │ │ │ │ ├── HTDSentence.java │ │ │ │ ├── HDGSentence.java │ │ │ │ ├── VHWSentence.java │ │ │ │ ├── RSASentence.java │ │ │ │ ├── STALKSentence.java │ │ │ │ └── XDRSentence.java │ │ │ ├── util │ │ │ │ ├── package-info.java │ │ │ │ ├── Datum.java │ │ │ │ ├── NavStatus.java │ │ │ │ ├── Direction.java │ │ │ │ ├── Side.java │ │ │ │ ├── CompassPoint.java │ │ │ │ ├── TargetStatus.java │ │ │ │ ├── AcquisitionType.java │ │ │ │ ├── RouteType.java │ │ │ │ ├── DataStatus.java │ │ │ │ ├── GpsFixStatus.java │ │ │ │ ├── TurnMode.java │ │ │ │ ├── ReferenceSystem.java │ │ │ │ ├── DisplayRotation.java │ │ │ │ ├── Units.java │ │ │ │ └── GpsFixQuality.java │ │ │ └── parser │ │ │ │ ├── package-info.java │ │ │ │ ├── VDMParser.java │ │ │ │ ├── UnsupportedSentenceException.java │ │ │ │ ├── DataNotAvailableException.java │ │ │ │ ├── VDOParser.java │ │ │ │ ├── ParseException.java │ │ │ │ ├── DTBParser.java │ │ │ │ ├── MTAParser.java │ │ │ │ ├── HDMParser.java │ │ │ │ ├── HDTParser.java │ │ │ │ ├── MTWParser.java │ │ │ │ └── MMBParser.java │ │ │ ├── ais │ │ │ ├── parser │ │ │ │ ├── package-info.java │ │ │ │ └── AISMessage18Parser.java │ │ │ ├── util │ │ │ │ ├── package-info.java │ │ │ │ ├── Violation.java │ │ │ │ ├── AISRuleViolation.java │ │ │ │ ├── PositioningDevice.java │ │ │ │ ├── TimeStamp.java │ │ │ │ ├── MMSI.java │ │ │ │ ├── NavigationalStatus.java │ │ │ │ └── ManeuverIndicator.java │ │ │ ├── message │ │ │ │ ├── package-info.java │ │ │ │ ├── AISMessage27.java │ │ │ │ ├── AISMessage01.java │ │ │ │ ├── AISMessage04.java │ │ │ │ ├── AISMessage18.java │ │ │ │ ├── AISMessage02.java │ │ │ │ ├── AISMessage03.java │ │ │ │ ├── AISMessage.java │ │ │ │ ├── AISPositionReport.java │ │ │ │ ├── AISPositionInfo.java │ │ │ │ ├── AISUTCReport.java │ │ │ │ └── AISMessage19.java │ │ │ └── event │ │ │ │ └── package-info.java │ │ │ ├── provider │ │ │ ├── event │ │ │ │ ├── package-info.java │ │ │ │ ├── SatelliteInfoListener.java │ │ │ │ ├── ProviderListener.java │ │ │ │ ├── ProviderEvent.java │ │ │ │ ├── HeadingListener.java │ │ │ │ ├── PositionListener.java │ │ │ │ └── HeadingEvent.java │ │ │ └── package-info.java │ │ │ ├── ublox │ │ │ ├── event │ │ │ │ └── package-info.java │ │ │ ├── message │ │ │ │ ├── package-info.java │ │ │ │ ├── UBXMessage.java │ │ │ │ └── UBXMessage03.java │ │ │ ├── parser │ │ │ │ ├── package-info.java │ │ │ │ └── UBXMessageParser.java │ │ │ └── util │ │ │ │ ├── package-info.java │ │ │ │ ├── UbloxSatelliteStatus.java │ │ │ │ ├── UbloxNavigationStatus.java │ │ │ │ └── UbloxSatelliteInfo.java │ │ │ └── example │ │ │ ├── package-info.java │ │ │ └── OutputExample.java │ └── resources │ │ └── doc │ │ └── readme.txt └── test │ ├── java │ └── net │ │ └── sf │ │ └── marineapi │ │ ├── test │ │ └── util │ │ │ ├── FOOSentence.java │ │ │ ├── FOOParser.java │ │ │ ├── VDMParser.java │ │ │ ├── UDPServerMock.java │ │ │ └── BARParser.java │ │ ├── nmea │ │ ├── parser │ │ │ ├── MTATest.java │ │ │ ├── DBTTest.java │ │ │ ├── UBXTest.java │ │ │ ├── MMBTest.java │ │ │ ├── DPTTest.java │ │ │ ├── MTWTest.java │ │ │ ├── VLWTest.java │ │ │ ├── VDRTest.java │ │ │ ├── ROTTest.java │ │ │ ├── MWDTest.java │ │ │ └── RSATest.java │ │ ├── util │ │ │ └── WaypointTest.java │ │ └── sentence │ │ │ ├── SentenceIdTest.java │ │ │ └── TalkerIdTest.java │ │ └── ais │ │ ├── parser │ │ ├── AISMessage04Test.java │ │ ├── AISMessage27ParserTest.java │ │ ├── AISPositionReportBParserTest.java │ │ └── AISMessageFactoryTest.java │ │ └── util │ │ └── SpeedOverGroundTest.java │ └── resources │ └── data │ ├── AIS-VDM-VDO.txt │ ├── sample1.txt │ └── AISsample.txt └── .github ├── dependabot.yml └── workflows └── build.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .classpath 3 | .settings 4 | .idea 5 | target/ 6 | *.iml 7 | .gradle 8 | .vscode/ 9 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Common library utils. 3 | */ 4 | package net.sf.marineapi.util; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/io/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * NMEA 0183 input/output. 3 | */ 4 | package net.sf.marineapi.nmea.io; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/parser/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * AIS message parsers. 3 | */ 4 | package net.sf.marineapi.ais.parser; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * AIS messaging related utils. 3 | */ 4 | package net.sf.marineapi.ais.util; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * AIS message interfaces. 3 | */ 4 | package net.sf.marineapi.ais.message; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/event/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * AIS message events and listeners. 3 | */ 4 | package net.sf.marineapi.ais.event; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/event/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * NMEA 0183 events and listeners. 3 | */ 4 | package net.sf.marineapi.nmea.event; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/provider/event/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provider events and listeners. 3 | */ 4 | package net.sf.marineapi.provider.event; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/event/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * UBX message events and listeners. 3 | */ 4 | package net.sf.marineapi.ublox.event; 5 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/message/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * u-blox (P)UBX message interfaces. 3 | */ 4 | package net.sf.marineapi.ublox.message; 5 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/parser/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * u-blox (P)UBX message parser implementations. 3 | */ 4 | package net.sf.marineapi.ublox.parser; 5 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Common library utils for u-blox vendor extensions 3 | */ 4 | package net.sf.marineapi.ublox.util; 5 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * NMEA 0183 sentence interfaces for supported sentences. 3 | */ 4 | package net.sf.marineapi.nmea.sentence; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/example/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Examples applications illustrating the usage of the Java Marine API 3 | */ 4 | package net.sf.marineapi.example; 5 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/provider/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Higher-level APIs that provide data updates for selected measurements. 3 | */ 4 | package net.sf.marineapi.provider; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * NMEA 0183 sentence utilities for handling the data extracted from sentences. 3 | */ 4 | package net.sf.marineapi.nmea.util; -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/test/util/FOOSentence.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.test.util; 2 | 3 | public interface FOOSentence { 4 | 5 | public abstract String getValueA(); 6 | 7 | public abstract String getValueB(); 8 | 9 | public abstract String getValueC(); 10 | 11 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "maven" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "weekly" 12 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * NMEA 0183 sentence parsers. Notice that all parsers, excluding the common 3 | * base class are visible only within the package scope and not meant to be used 4 | * directly. Instead, use {@link net.sf.marineapi.nmea.parser.SentenceFactory} 5 | * and {@link net.sf.marineapi.nmea.io.SentenceReader} classes. This approach is 6 | * selected to enable registering additional parsers at runtime, by exending the 7 | * {@link net.sf.marineapi.nmea.parser.SentenceParser} and registering the new 8 | * parser in the factory. 9 | */ 10 | package net.sf.marineapi.nmea.parser; -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISMessage27.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.ais.message; 2 | 3 | /** 4 | * Implementation of https://www.navcen.uscg.gov/?pageName=AISMessage27 5 | * 6 | * @author Krzysztof Borowski 7 | */ 8 | public interface AISMessage27 extends AISPositionReport { 9 | 10 | /** 11 | * Returns the RAIM flag. 12 | * 13 | * @return {@code true} if RAIM in use, otherwise {@code false}. 14 | */ 15 | boolean getRAIMFlag(); 16 | 17 | 18 | /** 19 | * Returns Position Latency. 20 | * 21 | * @return 0 = Reported position latency is less than 5 seconds; 1 = Reported position latency is greater than 5 seconds = default 22 | */ 23 | int getPositionLatency(); 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Build & Test 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | - name: Set up JDK 11 20 | uses: actions/setup-java@v4 21 | with: 22 | java-version: '17' 23 | distribution: 'adopt' 24 | cache: maven 25 | - name: Build 26 | run: mvn package --file pom.xml 27 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/test/util/FOOParser.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.test.util; 2 | 3 | import net.sf.marineapi.nmea.parser.SentenceParser; 4 | import net.sf.marineapi.nmea.sentence.TalkerId; 5 | 6 | /** 7 | * Dummy parser imaginary sentence type, for testing the inheritance of 8 | * SentenceParser. 9 | */ 10 | public class FOOParser extends SentenceParser implements FOOSentence { 11 | 12 | public FOOParser(String s) { 13 | super(s, "FOO"); 14 | } 15 | 16 | public FOOParser(TalkerId tid) { 17 | super(tid, "FOO", 3); 18 | } 19 | 20 | public String getValueA() { 21 | return getStringValue(0); 22 | } 23 | 24 | public String getValueB() { 25 | return getStringValue(1); 26 | } 27 | 28 | public String getValueC() { 29 | return getStringValue(2); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/VDMParser.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import net.sf.marineapi.nmea.sentence.SentenceId; 4 | import net.sf.marineapi.nmea.sentence.TalkerId; 5 | import net.sf.marineapi.nmea.sentence.AISSentence; 6 | 7 | /** 8 | * AIS VDM sentence parser, contains only the NMEA layer. The actual payload 9 | * message is parsed by AIS message parsers. 10 | * 11 | * @author Lázár József 12 | * @see AISSentence 13 | * @see AISParser 14 | */ 15 | class VDMParser extends AISParser { 16 | 17 | /** 18 | * Creates a new instance of VDMParser. 19 | * 20 | * @param nmea NMEA sentence String. 21 | */ 22 | public VDMParser(String nmea) { 23 | super(nmea, SentenceId.VDM); 24 | } 25 | 26 | /** 27 | * Creates a new empty VDMParser. 28 | * 29 | * @param talker TalkerId to set 30 | */ 31 | public VDMParser(TalkerId talker) { 32 | super(talker, SentenceId.VDM); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/test/util/VDMParser.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.test.util; 2 | 3 | import net.sf.marineapi.nmea.parser.SentenceParser; 4 | import net.sf.marineapi.nmea.sentence.TalkerId; 5 | 6 | /** 7 | * Dummy parser simulating AIVDM parser with alternative begin character, for 8 | * testing the inheritance of SentenceParser and custom parsers registering in 9 | * SentenceFactory. 10 | */ 11 | public class VDMParser extends SentenceParser { 12 | 13 | public VDMParser(String s) { 14 | // just like any other parser, begin char comes in String param 15 | super(s, "VDM"); 16 | } 17 | 18 | public VDMParser(TalkerId tid) { 19 | // alternative begin char is set here for empty sentences 20 | super('!', tid, "VDM", 3); 21 | } 22 | 23 | public String getValueA() { 24 | return getStringValue(0); 25 | } 26 | 27 | public String getValueB() { 28 | return getStringValue(1); 29 | } 30 | 31 | public String getValueC() { 32 | return getStringValue(2); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/resources/data/AIS-VDM-VDO.txt: -------------------------------------------------------------------------------- 1 | !AIVDM,1,1,,A,13u?etPv2;0n:dDPwUM1U1Cb069D,0*23 2 | !AIVDM,1,1,,A,400TcdiuiT7VDR>3nIfr6>i00000,0*78 3 | !AIVDM,2,1,0,A,58wt8Ui`g??r21`7S=:220588OA;0sk,0*7B 4 | !AIVDM,2,2,0,A,eQ8823mDm3kP00000000000,2*5D 5 | !AIVDM,2,1,9,B,61c2;qLPH1m@wsm6ARhp34k;S8i=3To,0*2C 6 | !AIVDM,2,2,9,B,Djhi=3Di<2pp=34k>4D,2*03 7 | !AIVDM,1,1,1,B,8>h8nkP0Glr=>M4fWA<59B1@E=@,0*17 10 | !AIVDM,1,1,,A,B6CdCm0t3`tba35f@V9faHi7kP06,0*58 11 | !AIVDM,2,1,0,B,C8u:8C@t7@TnGCKfm6Po`e6N`:Va0L2J;06HV50JV?SjBPL3,0*28 12 | !AIVDM,2,2,0,B,11RP,0*17 13 | !AIVDO,2,1,5,B,E1c2;q@b44ah4ah0h:2ab@70VRpU0U>0600:1Dp,2*7D 16 | !AIVDO,1,1,,B,H1c2;qDTijklmno31< 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.util; 22 | 23 | /** 24 | * Any message containing AIS rule violations. 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface Violation { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISMessage01.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISMessage01.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Position Report Class A. 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface AISMessage01 extends AISPositionReport { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISMessage04.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISMessage04.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Base Station Report. 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface AISMessage04 extends AISUTCReport, AISPositionInfo { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISMessage18.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISMessage01.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Standard Class B CS Position Report. 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface AISMessage18 extends AISPositionReportB { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISMessage02.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISMessage02.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Position Report Class A (Assigned schedule). 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface AISMessage02 extends AISPositionReport { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISMessage03.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISMessage03.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Position Report Class A (Response to interrogation). 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface AISMessage03 extends AISPositionReport { 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/HDMSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HDMSentence.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Vessel heading in degrees, relative to magnetic north.

25 | * 26 | *

Example:
{@code $IIHDM,213,M*3C}

27 | * 28 | * @author Kimmo Tuukkanen 29 | */ 30 | public interface HDMSentence extends HeadingSentence { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/HDTSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HDTSentence.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Vessel heading in degrees, relative to true north.

25 | * 26 | *

Example:
{@code $HCHDT,202.5,T*26}

27 | * 28 | * @author Kimmo Tuukkanen 29 | */ 30 | public interface HDTSentence extends HeadingSentence { 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/test/util/UDPServerMock.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.test.util; 2 | 3 | import java.net.DatagramPacket; 4 | import java.net.DatagramSocket; 5 | import java.net.InetAddress; 6 | 7 | /** 8 | * Dummy UDP server repeating single NMEA sentence. 9 | */ 10 | public class UDPServerMock implements Runnable { 11 | 12 | public final String TXT = "$IITXT,1,1,UDP,TEST*0F"; 13 | 14 | private DatagramSocket socket; 15 | private boolean running = true; 16 | 17 | public UDPServerMock() { 18 | new Thread(this).start(); 19 | } 20 | 21 | public void run() { 22 | try { 23 | int port = 3810; 24 | InetAddress host = InetAddress.getLocalHost(); 25 | byte[] data = TXT.getBytes(); 26 | socket = new DatagramSocket(); 27 | 28 | while (running) { 29 | DatagramPacket packet = 30 | new DatagramPacket(data, data.length, host, port); 31 | socket.send(packet); 32 | Thread.sleep(10); 33 | } 34 | 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } finally { 38 | socket.close(); 39 | } 40 | } 41 | 42 | public void stop() { 43 | running = false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/example/OutputExample.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.example; 2 | 3 | import net.sf.marineapi.nmea.parser.SentenceFactory; 4 | import net.sf.marineapi.nmea.sentence.MWVSentence; 5 | import net.sf.marineapi.nmea.sentence.TalkerId; 6 | import net.sf.marineapi.nmea.util.DataStatus; 7 | import net.sf.marineapi.nmea.util.Units; 8 | 9 | /** 10 | * Demonstrates the usage of sentence parsers for data output. 11 | * 12 | * @author Kimmo Tuukkanen 13 | */ 14 | public class OutputExample { 15 | 16 | public static void main(String[] args) { 17 | 18 | // Create a fresh MWV parser 19 | SentenceFactory sf = SentenceFactory.getInstance(); 20 | MWVSentence mwv = (MWVSentence) sf.createParser(TalkerId.II, "MWV"); 21 | 22 | // should output "$IIMWV,,,,,V*36" 23 | System.out.println(mwv.toSentence()); 24 | 25 | // Be sure to set all needed values correctly. For instance, in this 26 | // example setAngle() and setTrue() have mutual dependency. Likewise, 27 | // pay attention to set units correctly. 28 | mwv.setAngle(43.7); 29 | mwv.setTrue(true); 30 | mwv.setSpeed(4.54); 31 | mwv.setSpeedUnit(Units.METER); 32 | mwv.setStatus(DataStatus.ACTIVE); 33 | 34 | // should output "$IIMWV,043.7,T,4.5,M,A*39" 35 | System.out.println(mwv.toSentence()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/DTBSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DTBSentence.java 3 | * Copyright (C) 2019 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Boreal GasFinder data.

25 | * 26 | *

Example GasFinder2:
27 | * {@code $GFDTB,7.7,98,600,5527,2011/01/27 13:29:28,HFH2O-1xxx,1*28}

28 | * 29 | * @author Bob Schwarz 30 | * @see DTASentence 31 | */ 32 | public interface DTBSentence extends DTASentence { 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/provider/event/SatelliteInfoListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SatelliteInfoListener.java 3 | * Copyright (C) 2013 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.provider.event; 22 | 23 | /** 24 | * @author Kimmo Tuukkanen 25 | */ 26 | public interface SatelliteInfoListener extends ProviderListener { 27 | 28 | /** 29 | * Invoked when new satellite data is available. 30 | */ 31 | public void providerUpdate(SatelliteInfoEvent event); 32 | } 33 | -------------------------------------------------------------------------------- /src/test/resources/data/sample1.txt: -------------------------------------------------------------------------------- 1 | $IIMWV,273,R,24.3,N,A*10 2 | $IIVHW,,,347,M,0.00,N,,*64 3 | $IIVLW,1958.64,N,1958.64,N*4D 4 | $IIVPW,00.00,N,,*31 5 | $IIVTG,,T,312,M,0.0,N,,*0C 6 | $IIVWR,088,L,24.5,N,12.6,M,,*2A 7 | $IIVWT,088,L,24.7,N,12.6,M,,*2E 8 | $IIXTE,A,A,5.36,R,N*67 9 | $IIDBT,013.4,f,04.1,M,02.2,F*12 10 | $IIGLL,3748.4051,N,12226.618,W,,A*1D 11 | $IIHDM,348,M*33 12 | $IIMTA,39.4,C*0B 13 | $IIMTW,016,C*3A 14 | $IIMWD,,T,258,M,24.6,N,12.6,M*7E 15 | $IIMWV,272,R,24.6,N,A*14 16 | $IIVHW,,,348,M,0.00,N,,*6B 17 | $IIVLW,1958.64,N,1958.64,N*4D 18 | $IIVPW,00.00,N,,*31 19 | $IIVTG,,T,315,M,0.0,N,,*0B 20 | $IIVWR,091,L,24.9,N,12.8,M,,*20 21 | $IIVWT,090,L,24.6,N,12.6,M,,*26 22 | $IIXTE,A,A,5.36,R,N*67 23 | $IIDBT,013.2,f,04.0,M,02.2,F*15 24 | $IIGLL,3748.4052,N,12226.618,W,,A*1E 25 | $IIHDM,348,M*33 26 | $IIMTA,17.9,C*0A 27 | $IIMTW,016,C*3A 28 | $IIMWD,,T,254,M,26.4,N,13.5,M*70 29 | $IIMWV,267,R,26.0,N,A*14 30 | $IIVHW,,,348,M,0.00,N,,*6B 31 | $IIVLW,1958.64,N,1958.64,N*4D 32 | $IIVPW,00.00,N,,*31 33 | $IIVTG,,T,295,M,0.0,N,,*02 34 | $IIVWR,093,L,26.5,N,13.6,M,,*23 35 | $IIVWT,094,L,26.7,N,13.7,M,,*21 36 | $IIXTE,A,A,5.36,R,N*67 37 | $IIDBT,013.3,f,04.0,M,02.2,F*14 38 | $IIGLL,3748.4051,N,12226.618,W,,A*1D 39 | $IIHDM,348,M*33 40 | $IIMTA,3.6,C*30 41 | $IIMTW,016,C*3A 42 | $IIMWD,,T,250,M,27.0,N,13.8,M*7C 43 | $IIMWV,265,R,26.4,N,A*12 44 | $IIDPT,03.3,00.3,00.7*76 -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/io/DataListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DataListener.java 3 | * Copyright (C) 2014 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.io; 22 | 23 | /** 24 | * Listener for all data that is not recognized as NMEA 0183. 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public interface DataListener { 29 | 30 | /** 31 | * Invoked by {@link SentenceReader} when non-NMEA data has been read from 32 | * the device/data source. 33 | * 34 | * @param data Data String read from the device. 35 | */ 36 | void dataRead(String data); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/MTATest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | import net.sf.marineapi.nmea.sentence.MTASentence; 6 | import net.sf.marineapi.nmea.sentence.SentenceId; 7 | import net.sf.marineapi.nmea.sentence.TalkerId; 8 | 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | public class MTATest { 13 | 14 | public static final String EXAMPLE = "$IIMTA,21.5,C"; 15 | 16 | private MTASentence mta; 17 | 18 | @Before 19 | public void setUp() throws Exception { 20 | mta = new MTAParser(EXAMPLE); 21 | } 22 | 23 | @Test 24 | public void testMTAParserString() { 25 | assertEquals(TalkerId.II, mta.getTalkerId()); 26 | assertEquals(SentenceId.MTA.name(), mta.getSentenceId()); 27 | } 28 | 29 | @Test 30 | public void testMTAParserTalkerId() { 31 | MTAParser empty = new MTAParser(TalkerId.WI); 32 | assertEquals(TalkerId.WI, empty.getTalkerId()); 33 | assertEquals(SentenceId.MTA.name(), empty.getSentenceId()); 34 | assertTrue(empty.getCharValue(1) == 'C'); 35 | } 36 | 37 | @Test 38 | public void testGetTemperature() { 39 | assertEquals(21.5, mta.getTemperature(), 0.01); 40 | } 41 | 42 | @Test 43 | public void testSetTemperature() { 44 | mta.setTemperature(15.3335); 45 | assertEquals(15.33, mta.getTemperature(), 0.01); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/test/util/BARParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * BARParser.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.test.util; 22 | 23 | import net.sf.marineapi.nmea.parser.SentenceParser; 24 | import net.sf.marineapi.nmea.sentence.TalkerId; 25 | 26 | /** 27 | * Invalid parser implementation, no constructor with String param. 28 | * 29 | * @author Kimmo Tuukkanen 30 | */ 31 | public class BARParser extends SentenceParser { 32 | 33 | /** 34 | * Constructor 35 | */ 36 | public BARParser() { 37 | super(TalkerId.GP, "BAR", 5); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/Datum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Datum.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the supported datums, i.e. the coordinate systems used to specify 25 | * geographic positions. 26 | * 27 | * @author Kimmo Tuukkanen 28 | * @see net.sf.marineapi.nmea.util.Position 29 | */ 30 | public enum Datum { 31 | 32 | /** World Geodetic System 1984, the default datum in GPS systems. */ 33 | WGS84, 34 | /** North American Datum 1983 */ 35 | NAD83, 36 | /** North American Datum 1927 */ 37 | NAD27; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/io/ExceptionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ExceptionListener.java 3 | * Copyright (C) 2014 Johan Riisberg-Jensen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.io; 22 | 23 | /** 24 | * A listener callback interface for listening to Exceptions in DataReaders. 25 | * 26 | * @author Johan Riisberg-Jensen 27 | */ 28 | public interface ExceptionListener { 29 | 30 | /** 31 | * Invoked by {@link SentenceReader} when error has occured while reading 32 | * the data source. 33 | * 34 | * @param e Exception that was thrown while reading data. 35 | */ 36 | public void onException(Exception e); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/DepthSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DepthSentence.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | * Interface for sentences containing the depth of water. 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public interface DepthSentence extends Sentence { 29 | 30 | /** 31 | * Get depth of water, in meters. 32 | * 33 | * @return Depth value 34 | */ 35 | double getDepth(); 36 | 37 | /** 38 | * Set depth of water, in meters. 39 | * 40 | * @param depth Depth value 41 | */ 42 | void setDepth(double depth); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/provider/event/ProviderListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ProviderListener.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.provider.event; 22 | 23 | import java.util.EventListener; 24 | 25 | /** 26 | * Base interface for provider listeners. 27 | * 28 | * @author Kimmo Tuukkanen 29 | * @param {@link ProviderEvent} to be listened. 30 | */ 31 | public abstract interface ProviderListener extends 32 | EventListener { 33 | 34 | /** 35 | * Invoked when provider has new data available. 36 | * 37 | * @param evt ProviderEvent object 38 | */ 39 | void providerUpdate(T evt); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/provider/event/ProviderEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ProviderEvent.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.provider.event; 22 | 23 | import java.util.EventObject; 24 | 25 | /** 26 | * Abstract base class for provider events. 27 | * 28 | * @author Kimmo Tuukkanen 29 | */ 30 | public abstract class ProviderEvent extends EventObject { 31 | 32 | private static final long serialVersionUID = -5207967682036248721L; 33 | 34 | /** 35 | * Creates a new provider event. 36 | * 37 | * @param source The object that sends the event. 38 | */ 39 | public ProviderEvent(Object source) { 40 | super(source); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/parser/AISMessage18Parser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISMessage18Parser.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.parser; 22 | 23 | import net.sf.marineapi.ais.message.AISMessage18; 24 | import net.sf.marineapi.ais.util.Sixbit; 25 | 26 | /** 27 | * AIS message 18 parser, Standard Class B CS Position Report. 28 | * 29 | * @author Lázár József 30 | */ 31 | class AISMessage18Parser extends AISPositionReportBParser implements AISMessage18 { 32 | 33 | /** 34 | * Constructor. 35 | * 36 | * @param content Six-bit message content. 37 | */ 38 | public AISMessage18Parser(Sixbit content) { 39 | super(content); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/UnsupportedSentenceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * UnsupportedSentenceException.java 3 | * Copyright (C) 2018 Michael Skogberg 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | /** 24 | * Thrown when an unsupported sentence is encountered. 25 | * 26 | * @author Michael Skogberg 27 | */ 28 | public class UnsupportedSentenceException extends RuntimeException { 29 | 30 | private static final long serialVersionUID = 7618916517933110942L; 31 | 32 | /** 33 | * Constructor 34 | * 35 | * @param msg Exception message 36 | */ 37 | public UnsupportedSentenceException(String msg) { 38 | super(msg); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/provider/event/HeadingListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HeadingListener.java 3 | * Copyright (C) 2012 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.provider.event; 22 | 23 | /** 24 | * Listener interface for {@link net.sf.marineapi.provider.HeadingProvider}. 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public interface HeadingListener extends ProviderListener { 29 | 30 | /* 31 | * (non-Javadoc) 32 | * @see 33 | * net.sf.marineapi.provider.event.ProviderListener#providerUpdate(net.sf 34 | * .marineapi.provider.event.ProviderEvent) 35 | */ 36 | public void providerUpdate(HeadingEvent evt); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/MTASentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MTASentence.java 3 | * Copyright (C) 2012 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Air temperature in degrees Celsius.

25 | * 26 | *

Example:
{@code $IIMTA,16.7,C*05}

27 | * 28 | * @author Kimmo Tuukkanen 29 | */ 30 | public interface MTASentence extends Sentence { 31 | 32 | /** 33 | * Returns the air temperature. 34 | * 35 | * @return Temperature in degrees Celsius. 36 | */ 37 | double getTemperature(); 38 | 39 | /** 40 | * Sets the air temperature. 41 | * 42 | * @param temp Temperature in degrees Celsius. 43 | */ 44 | void setTemperature(double temp); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/provider/event/PositionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * PositionListener.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.provider.event; 22 | 23 | /** 24 | * Listener interface for GPS time/position/velocity events. 25 | * 26 | * @author Kimmo Tuukkanen 27 | * @see net.sf.marineapi.provider.PositionProvider 28 | * @see net.sf.marineapi.provider.event.PositionEvent 29 | */ 30 | public interface PositionListener extends ProviderListener { 31 | 32 | /** 33 | * Invoked when fresh time/position/velocity report is available, typically 34 | * once per second. 35 | * 36 | * @param evt PositionEvent 37 | */ 38 | void providerUpdate(PositionEvent evt); 39 | } 40 | -------------------------------------------------------------------------------- /src/test/resources/data/AISsample.txt: -------------------------------------------------------------------------------- 1 | # Syntactically correct sentences 2 | !AIVDM,1,1,,A,15RTgt0PAso;90TKcjM8h6g208CQ,0*4A 3 | !AIVDM,1,1,,A,16SteH0P00Jt63hHaa6SagvJ087r,0*42 4 | !AIVDM,1,1,,B,25Cjtd0Oj;Jp7ilG7=UkKBoB0<06,0*60 5 | !AIVDM,1,1,,A,38Id705000rRVJhE7cl9n;160000,0*40 6 | !AIVDM,1,1,,A,403OviQuMGCqWrRO9>E6fE700@GO,0*4D 7 | !AIVDM,2,1,1,A,55?MbV02;H;s;h00Fc>jpUlNV@ikwpUoP06,0*4C 11 | !AIVDM,1,1,,A,B52KB8h006fu`Q6:g1McCwb5oP06,0*00 12 | !AIVDM,1,1,,B,B5O6hr00NhWAwwo862PaLELTBJ:V00000000S0D:R220,0*0B 14 | !AIVDM,1,1,,A,H42O55i18tMET00000000000000,2*6D 15 | !AIVDM,1,1,,A,H42O55lti4hhhilD3nink000?050,0*40 16 | 17 | # Non printable and control character in data or string fields 18 | !AIVDM,1,1,,A,647sBv00b=E006P9>0,4*1B 19 | # Type 4 with date/time set to N/A 20 | !AIVDM,1,1,,A,402Fha0000Htt8700PS:,0*60 23 | # Type 4 with year set to 10196 (0x27D4), idempotency used to fail on this one 24 | # It has a bad epfd as well. 25 | !AIVDM,1,1,,B,4>O7m7Iu@<9qUfbtm`vSnwvH20S8,0*46 26 | 27 | # simultaneous use of buffers of channels A & B 28 | !AIVDM,2,1,6,B,542M92h00001@<7;?G0PD4i@R0220o0h:2240Ht50000000000,0*3B 29 | !AIVDM,2,1,2,A,542M92h00001@<7;?G0PD4i@R0220o0h:2240Ht500000000000000,0*3C 30 | !AIVDM,2,2,2,A,0000002,2*24 31 | !AIVDM,2,2,6,B,00000000000,2*21 32 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/DBTTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import net.sf.marineapi.nmea.sentence.DBTSentence; 5 | import net.sf.marineapi.nmea.sentence.TalkerId; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | public class DBTTest { 11 | 12 | public static final String EXAMPLE = "$IIDBT,013.4,f,04.1,M,02.2,F*12"; 13 | private DBTSentence dbt; 14 | private DBTSentence empty; 15 | 16 | @Before 17 | public void setUp() throws Exception { 18 | empty = new DBTParser(TalkerId.II); 19 | dbt = new DBTParser(EXAMPLE); 20 | } 21 | 22 | @Test 23 | public void testConstructor() { 24 | assertEquals("DBT", empty.getSentenceId()); 25 | assertEquals(TalkerId.II, empty.getTalkerId()); 26 | assertEquals(6, empty.getFieldCount()); 27 | } 28 | 29 | @Test 30 | public void testGetFathoms() { 31 | assertEquals(2.2, dbt.getFathoms(), 0.01); 32 | } 33 | 34 | @Test 35 | public void testGetFeet() { 36 | assertEquals(13.4, dbt.getFeet(), 0.01); 37 | } 38 | 39 | @Test 40 | public void testGetMeters() { 41 | assertEquals(4.1, dbt.getDepth(), 0.01); 42 | } 43 | 44 | @Test 45 | public void testSetFathoms() { 46 | empty.setFathoms(7.33333); 47 | assertEquals(7.3, empty.getFathoms(), 0.1); 48 | } 49 | 50 | @Test 51 | public void testSetFeet() { 52 | empty.setFeet(12.33333); 53 | assertEquals(12.3, empty.getFeet(), 0.1); 54 | } 55 | 56 | @Test 57 | public void testSetMeters() { 58 | empty.setDepth(23.654321); 59 | assertEquals(23.7, empty.getDepth(), 0.1); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/MTWSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MTWSentence.java 3 | * Copyright (C) 2011 Warren Zahra, Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Water temperature in degrees Celsius.

25 | * 26 | *

Example:
{@code $YXMTW,17.75,C*5D}

27 | * 28 | * @author Warren Zahra, Kimmo Tuukkanen 29 | */ 30 | public interface MTWSentence extends Sentence { 31 | 32 | /** 33 | * Get the water temperature. 34 | * 35 | * @return Temperature in degrees Celsius. 36 | */ 37 | double getTemperature(); 38 | 39 | /** 40 | * Set the water temperature. 41 | * 42 | * @param temp Water temperature in degrees Celsius. 43 | */ 44 | void setTemperature(double temp); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/message/UBXMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Gunnar Hillert 3 | * 4 | * This file is part of Java Marine API. 5 | * 6 | * 7 | * Java Marine API is free software: you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by the 9 | * Free Software Foundation, either version 3 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * Java Marine API is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with Java Marine API. If not, see . 19 | */ 20 | package net.sf.marineapi.ublox.message; 21 | 22 | import net.sf.marineapi.nmea.sentence.UBXSentence; 23 | import net.sf.marineapi.ublox.parser.UBXMessageParser; 24 | 25 | /** 26 | * Common base interface of UBX messages. Please be aware that the parsing of 27 | * UBX Messages is a two-stage process. Please see {@link UBXSentence} and 28 | * {@link UBXMessageParser} for details. 29 | * 30 | * @author Gunnar Hillert 31 | * 32 | * @see UBXSentence 33 | * @see UBXMessageParser 34 | */ 35 | public interface UBXMessage { 36 | 37 | /** 38 | * Returns the message type (Proprietary message identifier). 39 | * 40 | * @return Message type in range from 1 to 27. 41 | */ 42 | int getMessageType(); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/NavStatus.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.util; 2 | 3 | /** 4 | *

FAA operating modes reported by RMC sentences since NMEA 4.1.

5 | * @author John 6 | */ 7 | 8 | public enum NavStatus { 9 | 10 | /** Navigation status is autonomous. */ 11 | AUTONOMOUS('A'), 12 | 13 | /** Navigation status is differential. */ 14 | DIFFERENTIAL('D'), 15 | 16 | /** Navigation status is Estimated. */ 17 | ESTIMATED('E'), 18 | 19 | /** Navigation status is Manual. */ 20 | MANUAL('M'), 21 | 22 | /** Navigation status is Not valid. */ 23 | NOT_VALID('N'), 24 | 25 | /** Navigation status is Simulator. */ 26 | SIMULATOR('S'), 27 | 28 | /** Navigation status is Valid. */ 29 | VALID('V'); 30 | 31 | private final char navStatus; 32 | 33 | NavStatus(char navStatusCh) { 34 | navStatus = navStatusCh; 35 | } 36 | 37 | /** 38 | * Returns the corresponding char indicator of Navigation Status. 39 | * 40 | * @return NavStatus char used in sentences. 41 | */ 42 | public char toChar() { 43 | return navStatus; 44 | } 45 | 46 | /** 47 | * Returns the NavStatus enum corresponding the actual char indicator used in 48 | * the sentencess. 49 | * 50 | * @param ch Char mode indicator 51 | * @return NavStatus enum 52 | */ 53 | public static NavStatus valueOf(char ch) { 54 | for (NavStatus gm : values()) { 55 | if (gm.toChar() == ch) { 56 | return gm; 57 | } 58 | } 59 | return valueOf(String.valueOf(ch)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/message/UBXMessage03.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Gunnar Hillert 3 | * 4 | * This file is part of Java Marine API. 5 | * 6 | * 7 | * Java Marine API is free software: you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by the 9 | * Free Software Foundation, either version 3 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * Java Marine API is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with Java Marine API. If not, see . 19 | */ 20 | package net.sf.marineapi.ublox.message; 21 | 22 | import java.util.List; 23 | 24 | import net.sf.marineapi.ublox.util.UbloxSatelliteInfo; 25 | 26 | /** 27 | * Proprietary u-blox NMEA extension "Satellite status". 28 | * 29 | * @author Gunnar Hillert 30 | * 31 | */ 32 | public interface UBXMessage03 extends UBXMessage { 33 | 34 | /** 35 | * Number of GNSS satellites tracked. 36 | * 37 | * @return Number of satellites tracked 38 | */ 39 | int getNumberOfTrackedSatellites(); 40 | 41 | /** 42 | * Returns a collection of satellite statuses. 43 | * 44 | * @see UbloxSatelliteInfo 45 | * @return Collection of UbloxSatelliteInfo 46 | */ 47 | List getSatellites(); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/TimeSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TimeSentence.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import net.sf.marineapi.nmea.util.Time; 24 | 25 | /** 26 | * Interface for sentences that provide UTC time. Notice that some sentences 27 | * contain only UTC time, while others may provide also date. 28 | * 29 | * @author Kimmo Tuukkanen 30 | * @see net.sf.marineapi.nmea.sentence.DateSentence 31 | */ 32 | public interface TimeSentence extends Sentence { 33 | 34 | /** 35 | * Get the time of day. 36 | * 37 | * @return Time 38 | */ 39 | Time getTime(); 40 | 41 | /** 42 | * Set the time of day. 43 | * 44 | * @param t Time to set 45 | */ 46 | void setTime(Time t); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISMessage.java 3 | * Copyright (C) 2015 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Common base interface of AIS messages. 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public interface AISMessage { 29 | 30 | /** 31 | * Returns the message type. 32 | * 33 | * @return Message type in range from 1 to 27. 34 | */ 35 | int getMessageType(); 36 | 37 | /** 38 | * Tells how many times the message has been repeated. 39 | * 40 | * @return the number of repeats 41 | */ 42 | int getRepeatIndicator(); 43 | 44 | /** 45 | * Returns the unique identifier of the transmitting ship (MMSI, Maritime 46 | * Mobile Service Identity). 47 | * 48 | * @return MMSI identifier 49 | */ 50 | int getMMSI(); 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/UBXTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import net.sf.marineapi.nmea.sentence.TalkerId; 9 | import net.sf.marineapi.nmea.sentence.UBXSentence; 10 | 11 | /** 12 | * @author Gunnar Hillert 13 | */ 14 | public class UBXTest { 15 | 16 | final String message00 = "$PUBX,00,202920.00,1932.33821,N,15555.72641,W,451.876,G3,3.3,4.0,0.177,0.00,-0.035,,1.11,1.39,1.15,17,0,0*62"; 17 | 18 | private UBXSentence ubxSentence; 19 | 20 | /** 21 | * @throws java.lang.Exception 22 | */ 23 | @Before 24 | public void setUp() throws Exception { 25 | ubxSentence = new UBXParser(message00); 26 | } 27 | 28 | /** 29 | * Test method for 30 | * {@link net.sf.marineapi.nmea.parser.VDMParser#VDMParser(net.sf.marineapi.nmea.sentence.TalkerId)} 31 | * . 32 | */ 33 | @Test 34 | public void testUBXParserTalkerId() { 35 | final UBXSentence empty = new UBXParser(TalkerId.P); 36 | assertEquals(TalkerId.P, empty.getTalkerId()); 37 | assertEquals("UBX", empty.getSentenceId()); 38 | assertEquals(6, empty.getFieldCount()); 39 | } 40 | 41 | /** 42 | * Test method for 43 | * {@link net.sf.marineapi.nmea.parser.UBXParser#getMessageId()}. 44 | */ 45 | @Test 46 | public void testGetMessageId() { 47 | assertEquals(Integer.valueOf(0), ubxSentence.getMessageId()); 48 | } 49 | 50 | /** 51 | * Test method for 52 | * {@link net.sf.marineapi.nmea.parser.UBXParser#getUBXFieldCount()}. 53 | */ 54 | @Test 55 | public void testGetUBXFieldCount() { 56 | assertEquals(20, ubxSentence.getUBXFieldCount()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/resources/doc/readme.txt: -------------------------------------------------------------------------------- 1 | Java Marine API - README 2 | Version @VERSION@ (@BUILD_ID@) 3 | https://github.com/ktuukkan/marine-api 4 | 5 | Java Marine API is an NMEA-0183 library for decoding and encoding the data 6 | provided by various electronic marine instruments such as GPS, echo sounder and 7 | weather instruments. 8 | 9 | LICENSING 10 | 11 | Java Marine API is free software: you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published by the 13 | Free Software Foundation, either version 3 of the License, or (at your 14 | option) any later version. 15 | 16 | Java Marine API is distributed in the hope that it will be useful, but 17 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 18 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 19 | for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public License 22 | along with Java Marine API. If not, see http://www.gnu.org/licenses/ 23 | 24 | See also: 25 | https://www.gnu.org/licenses/lgpl-java.en.html 26 | 27 | DISCLAIMER 28 | 29 | Java Marine API is not official NMEA software. Further, it is not related to 30 | National Marine Electronics Association (http://www.nmea.org/). The 31 | interpretation of NMEA 0183 and related protocols is based entirely on 32 | varying set of publicly available documents in the Internet. Thus, it is not 33 | guaranteed that the library follows and implements these standards correctly. 34 | 35 | Electronic devices and software do not replace safe navigation practices and 36 | should never be your only reference. 37 | 38 | DEVELOPERS 39 | 40 | * Kimmo Tuukkanen (kimmo.tuukkanen@gmail.com) 41 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/DBTSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DBTSentence.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Water depth below transducer, in meters, feet and fathoms.

25 | *

Example:
{@code $SDDBT,8.1,f,2.4,M,1.3,F*0B}

26 | * 27 | * @author Kimmo Tuukkanen 28 | */ 29 | public interface DBTSentence extends DepthSentence { 30 | 31 | /** 32 | * Get depth in fathoms. 33 | * 34 | * @return Depth value 35 | */ 36 | double getFathoms(); 37 | 38 | /** 39 | * Get depth in feet. 40 | * 41 | * @return Depth value 42 | */ 43 | double getFeet(); 44 | 45 | /** 46 | * Set depth value, in fathoms. 47 | * 48 | * @param depth Depth to set 49 | */ 50 | void setFathoms(double depth); 51 | 52 | /** 53 | * Set depth value, in feet. 54 | * 55 | * @param depth Depth to set 56 | */ 57 | void setFeet(double depth); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/MMBTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import net.sf.marineapi.nmea.sentence.MMBSentence; 4 | import net.sf.marineapi.nmea.sentence.SentenceId; 5 | import net.sf.marineapi.nmea.sentence.TalkerId; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | /** 12 | * MMBTest 13 | * 14 | * @author Kimmo Tuukkanen 15 | */ 16 | public class MMBTest { 17 | 18 | public static final String EXAMPLE = "$IIMMB,29.9870,I,1.0154,B*75"; 19 | 20 | MMBSentence mmb; 21 | MMBSentence empty; 22 | 23 | @Before 24 | public void setUp() throws Exception { 25 | mmb = new MMBParser(EXAMPLE); 26 | empty = new MMBParser(TalkerId.WI); 27 | } 28 | 29 | @Test 30 | public void testConstructors() { 31 | assertEquals(4, mmb.getFieldCount()); 32 | assertEquals(4, empty.getFieldCount()); 33 | assertEquals(TalkerId.II, mmb.getTalkerId()); 34 | assertEquals(TalkerId.WI, empty.getTalkerId()); 35 | assertEquals(SentenceId.MMB.name(), empty.getSentenceId()); 36 | } 37 | 38 | @Test 39 | public void testGetInchesOfMercury() throws Exception { 40 | assertEquals(29.9870, mmb.getInchesOfMercury(), 0.0001); 41 | } 42 | 43 | @Test 44 | public void testGetBars() throws Exception { 45 | assertEquals(1.0154, mmb.getBars(), 0.0001); 46 | } 47 | 48 | @Test 49 | public void testSetInchesOfMercury() throws Exception { 50 | mmb.setInchesOfMercury(29.9999); 51 | assertEquals(29.9999, mmb.getInchesOfMercury(), 0.0001); 52 | } 53 | 54 | @Test 55 | public void testSetBars() throws Exception { 56 | mmb.setBars(1.1234); 57 | assertEquals(1.1234, mmb.getBars(), 0.0001); 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/DataNotAvailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DataNotAvailableException.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | /** 24 | * Thrown to indicate that requested data is not available. For example, when 25 | * invoking a getter for sentence data field that contains no value. 26 | * 27 | * @author Kimmo Tuukkanen 28 | */ 29 | public class DataNotAvailableException extends RuntimeException { 30 | 31 | private static final long serialVersionUID = -3672061046826633631L; 32 | 33 | /** 34 | * Constructor 35 | * 36 | * @param msg Exception message 37 | */ 38 | public DataNotAvailableException(String msg) { 39 | super(msg); 40 | } 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param msg Exception message 46 | * @param cause Throwable that caused the exception 47 | */ 48 | public DataNotAvailableException(String msg, Throwable cause) { 49 | super(msg, cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/util/AISRuleViolation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISRuleViolation.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.util; 22 | 23 | /** 24 | * Class holding information about a violation against an AIS rule. 25 | * 26 | * @author Lázár József 27 | */ 28 | public class AISRuleViolation implements Violation { 29 | 30 | private String fPlaceOfViolation; 31 | private Object fCurrentValue; 32 | private String fValidRange; 33 | 34 | /** 35 | * Creates a new Violation. 36 | * 37 | * @param where Place of violation. 38 | * @param value Current value 39 | * @param range Expected value range 40 | */ 41 | public AISRuleViolation(String where, Object value, String range) { 42 | fPlaceOfViolation = where; 43 | fCurrentValue = value; 44 | fValidRange = range; 45 | } 46 | 47 | public String toString() { 48 | return "Violation: Value " + fCurrentValue.toString() + 49 | " in " + fPlaceOfViolation + 50 | " is outside the allowed range (" + fValidRange + ")"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/PositionSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * PositionSentence.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import net.sf.marineapi.nmea.util.Position; 24 | 25 | /** 26 | * Common interface for sentences that contain geographic position. 27 | * 28 | * @author Kimmo Tuukkanen 29 | */ 30 | public interface PositionSentence extends Sentence { 31 | 32 | /** 33 | * Gets the geographic position. 34 | * 35 | * @return Position 36 | * @throws net.sf.marineapi.nmea.parser.DataNotAvailableException If any of the 37 | * position related fields is empty. 38 | * @throws net.sf.marineapi.nmea.parser.ParseException If any of the position 39 | * related fields contains unexpected value. 40 | */ 41 | Position getPosition(); 42 | 43 | /** 44 | * Set the geographic position. 45 | * 46 | * @param pos Position to set 47 | */ 48 | void setPosition(Position pos); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/Direction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Direction.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the relative directions, e.g. "left" and "right". 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public enum Direction { 29 | 30 | /** Left */ 31 | LEFT('L'), 32 | 33 | /** Right */ 34 | RIGHT('R'); 35 | 36 | private char ch; 37 | 38 | private Direction(char c) { 39 | ch = c; 40 | } 41 | 42 | /** 43 | * Returns the corresponding char constant. 44 | * 45 | * @return Char indicator for Direction 46 | */ 47 | public char toChar() { 48 | return ch; 49 | } 50 | 51 | /** 52 | * Get the enum corresponding to specified char. 53 | * 54 | * @param c Char indicator for Direction 55 | * @return Direction 56 | */ 57 | public static Direction valueOf(char c) { 58 | for (Direction d : values()) { 59 | if (d.toChar() == c) { 60 | return d; 61 | } 62 | } 63 | return valueOf(String.valueOf(c)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/Side.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Side.java 3 | * Copyright (C) 2014 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the sides of a boat, i.e. "port" and "starboard". 25 | * 26 | * @author Lázár József 27 | */ 28 | public enum Side { 29 | 30 | /** Port */ 31 | PORT('P'), 32 | 33 | /** Right */ 34 | STARBOARD('S'); 35 | 36 | private char ch; 37 | 38 | Side(char c) { 39 | ch = c; 40 | } 41 | 42 | /** 43 | * Returns the corresponding char constant. 44 | * 45 | * @return Char indicator for Direction 46 | */ 47 | public char toChar() { 48 | return ch; 49 | } 50 | 51 | /** 52 | * Get the enum corresponding to specified char. 53 | * 54 | * @param c Char indicator for Side 55 | * @return Side 56 | */ 57 | public static Side valueOf(char c) { 58 | for (Side d : values()) { 59 | if (d.toChar() == c) { 60 | return d; 61 | } 62 | } 63 | return valueOf(String.valueOf(c)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/DPTTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import net.sf.marineapi.nmea.sentence.DPTSentence; 5 | import net.sf.marineapi.nmea.sentence.TalkerId; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | public class DPTTest { 11 | 12 | public static final String EXAMPLE = "$IIDPT,012.6,-1.0,100"; 13 | DPTSentence empty; 14 | DPTSentence dpt; 15 | 16 | @Before 17 | public void setUp() throws Exception { 18 | empty = new DPTParser(TalkerId.II); 19 | dpt = new DPTParser(EXAMPLE); 20 | } 21 | 22 | @Test 23 | public void testDPTParser() { 24 | assertEquals(TalkerId.II, empty.getTalkerId()); 25 | assertEquals("DPT", empty.getSentenceId()); 26 | assertEquals(3, empty.getFieldCount()); 27 | 28 | } 29 | 30 | @Test 31 | public void testDPTParserString() { 32 | assertEquals(TalkerId.II, dpt.getTalkerId()); 33 | assertEquals("DPT", dpt.getSentenceId()); 34 | assertEquals(3, dpt.getFieldCount()); 35 | } 36 | 37 | @Test 38 | public void testGetDepth() { 39 | assertEquals(12.6, dpt.getDepth(), 0.01); 40 | } 41 | 42 | @Test 43 | public void testGetOffset() { 44 | assertEquals(-1.0, dpt.getOffset(), 0.01); 45 | } 46 | 47 | @Test 48 | public void testSetDepth() { 49 | final double depth = 1.2333333; 50 | empty.setDepth(depth); 51 | assertEquals(depth, empty.getDepth(), 0.1); 52 | } 53 | 54 | @Test 55 | public void testSetOffset() { 56 | final double offset = 1.555555; 57 | empty.setOffset(offset); 58 | assertEquals(offset, empty.getOffset(), 0.1); 59 | } 60 | 61 | @Test 62 | public void testGetMaximum() { 63 | assertEquals(100, dpt.getMaximum(), 1); 64 | } 65 | 66 | @Test 67 | public void testSetMaximum() { 68 | final int max = 123; 69 | dpt.setMaximum(max); 70 | assertEquals(max, dpt.getMaximum(), 1); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/VDOParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * VDOParser.java 3 | * Copyright (C) 2016 Henri Laurent 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | import net.sf.marineapi.nmea.sentence.AISSentence; 24 | import net.sf.marineapi.nmea.sentence.SentenceId; 25 | import net.sf.marineapi.nmea.sentence.TalkerId; 26 | 27 | /** 28 | * AIS VDO sentence parser, contains only the NMEA layer. The actual payload 29 | * message is parsed by AIS message parsers. 30 | * 31 | * @author Henri Laurent 32 | * @see AISSentence 33 | * @see AISParser 34 | */ 35 | class VDOParser extends AISParser { 36 | 37 | /** 38 | * Creates a new instance of VDOParser. 39 | * 40 | * @param nmea NMEA sentence String. 41 | */ 42 | public VDOParser(String nmea) { 43 | super(nmea, SentenceId.VDO); 44 | } 45 | 46 | /** 47 | * Creates a new empty VDOParser. 48 | * 49 | * @param talker TalkerId to set 50 | */ 51 | public VDOParser(TalkerId talker) { 52 | super(talker, SentenceId.VDO); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/util/PositioningDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * PositioningDevice.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.util; 22 | 23 | /** 24 | * Checks the positioning device type for validity. 25 | * 26 | * @author Lázár József 27 | */ 28 | public class PositioningDevice { 29 | 30 | /** 31 | * Returns a text string for the EPFD. 32 | * 33 | * @param deviceType Device type value to Stringify. 34 | * @return a text string describing the positioning device type 35 | */ 36 | static public String toString (int deviceType) { 37 | switch (deviceType) { 38 | case 0: 39 | return "undefined device"; 40 | case 1: 41 | return "GPS"; 42 | case 2: 43 | return "GLONASS"; 44 | case 3: 45 | return "combined GPS/GLONASS"; 46 | case 4: 47 | return "Loran-C"; 48 | case 5: 49 | return "Chayka"; 50 | case 6: 51 | return "integrated navigation system"; 52 | case 7: 53 | return "surveyed"; 54 | case 8: 55 | return "Galileo"; 56 | case 15: 57 | return "internal GNSS"; 58 | default: 59 | return "not used"; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/CompassPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Direction.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the supported compass and relative directions. 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public enum CompassPoint { 29 | 30 | /** North */ 31 | NORTH('N'), 32 | /** East */ 33 | EAST('E'), 34 | /** South */ 35 | SOUTH('S'), 36 | /** West */ 37 | WEST('W'); 38 | 39 | private char ch; 40 | 41 | private CompassPoint(char c) { 42 | this.ch = c; 43 | } 44 | 45 | /** 46 | * Returns the corresponding char constant. 47 | * 48 | * @return Char indicator for Direction 49 | */ 50 | public char toChar() { 51 | return ch; 52 | } 53 | 54 | /** 55 | * Get the enum corresponding to specified char. 56 | * 57 | * @param c Char indicator for Direction 58 | * @return Direction 59 | */ 60 | public static CompassPoint valueOf(char c) { 61 | for (CompassPoint d : values()) { 62 | if (d.toChar() == c) { 63 | return d; 64 | } 65 | } 66 | return valueOf(String.valueOf(c)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/HeadingSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HeadingSentence.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | * Interface for sentences that provide vessel's true or magnetic heading. 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public interface HeadingSentence extends Sentence { 29 | 30 | /** 31 | * Returns the vessel's current heading. 32 | * 33 | * @return Heading in degrees. 34 | * @see #isTrue() 35 | */ 36 | double getHeading(); 37 | 38 | /** 39 | * Tells if the heading returned and set by {@link #getHeading()} and 40 | * {@link #setHeading(double)} methods is true or magnetic 41 | * . 42 | * 43 | * @return {@code true} if true heading, otherwise {@code false} 44 | * for magnetic heading. 45 | */ 46 | boolean isTrue(); 47 | 48 | /** 49 | * Sets the heading value. 50 | * 51 | * @param hdt Heading in degrees 52 | * @see #isTrue() 53 | * @throws IllegalArgumentException If heading value out of range [0..360] 54 | */ 55 | void setHeading(double hdt); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/WPLSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * WPLSentence.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import net.sf.marineapi.nmea.util.Waypoint; 24 | 25 | /** 26 | * Destination waypoint location and ID. This sentence is transmitted by some 27 | * GPS models in GOTO mode. 28 | *

29 | * Example:
30 | * {@code $GPWPL,5536.200,N,01436.500,E,RUSKI*1F} 31 | * 32 | * @author Kimmo Tuukkanen 33 | */ 34 | public interface WPLSentence extends Sentence { 35 | 36 | /** 37 | * Get the destination waypoint. 38 | * 39 | * @return Waypoint 40 | * @throws net.sf.marineapi.nmea.parser.DataNotAvailableException If any of the 41 | * waypoint related data is not available. 42 | * @throws net.sf.marineapi.nmea.parser.ParseException If any of the waypoint 43 | * related fields contain unexpected or illegal value. 44 | */ 45 | Waypoint getWaypoint(); 46 | 47 | /** 48 | * Set the destination waypoint. 49 | * 50 | * @param wp Waypoint to set 51 | */ 52 | void setWaypoint(Waypoint wp); 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/TargetStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TargetStatus.java 3 | * Copyright (C) 2014 Johan Bergkvist 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the status of a target reported in a TTM sentence. 25 | * 26 | * @author Johan Bergkvist 27 | * @see net.sf.marineapi.nmea.sentence.TTMSentence 28 | */ 29 | public enum TargetStatus { 30 | 31 | /** Query */ 32 | QUERY('Q'), 33 | /** Lost */ 34 | LOST('L'), 35 | /** Tracking */ 36 | TRACKING('T'); 37 | 38 | private char ch; 39 | 40 | TargetStatus(char ch) { 41 | this.ch = ch; 42 | } 43 | 44 | /** 45 | * Returns the corresponding char constant. 46 | * 47 | * @return Char indicator for Status 48 | */ 49 | public char toChar() { 50 | return ch; 51 | } 52 | 53 | /** 54 | * Get the enum corresponding to specified char. 55 | * 56 | * @param c Char indicator for Status 57 | * @return Status 58 | */ 59 | public static TargetStatus valueOf(char c) { 60 | for (TargetStatus d : values()) { 61 | if (d.toChar() == c) { 62 | return d; 63 | } 64 | } 65 | return valueOf(String.valueOf(c)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/ParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ParseException.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | /** 24 | * Thrown to indicate that parser is unable interpret the contents of requested 25 | * data field. For example, when a field contains invalid value that cannot be 26 | * parsed to expected native data type. 27 | * 28 | * @author Kimmo Tuukkanen 29 | */ 30 | public class ParseException extends DataNotAvailableException { 31 | 32 | /** serialVersionUID */ 33 | private static final long serialVersionUID = 6203761984607273569L; 34 | 35 | /** 36 | * Constructor with description. 37 | * 38 | * @param msg Description of the Exception 39 | */ 40 | public ParseException(String msg) { 41 | super(msg); 42 | } 43 | 44 | /** 45 | * Constructor with message and cause. 46 | * 47 | * @param msg Description of the Exception 48 | * @param cause Throwable that caused this exception 49 | */ 50 | public ParseException(String msg, Throwable cause) { 51 | super(msg, cause); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/AcquisitionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AcquisitionType.java 3 | * Copyright (C) 2014 Johan Bergkvist 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Aquisition types. 25 | * 26 | * @author Johan Bergkvist 27 | * @see net.sf.marineapi.nmea.sentence.TTMSentence 28 | */ 29 | public enum AcquisitionType { 30 | 31 | /** Automatic */ 32 | AUTO('A'), 33 | /** Manual */ 34 | MANUAL('M'), 35 | /** Reported */ 36 | REPORTED('R'); 37 | 38 | private char ch; 39 | 40 | AcquisitionType(char ch) { 41 | this.ch = ch; 42 | } 43 | 44 | /** 45 | * Returns the corresponding char constant. 46 | * 47 | * @return Char indicator for AcquisitionType 48 | */ 49 | public char toChar() { 50 | return ch; 51 | } 52 | 53 | /** 54 | * Get the enum corresponding to specified char. 55 | * 56 | * @param c Char indicator for AcquisitionType 57 | * @return AcquisitionType 58 | */ 59 | public static AcquisitionType valueOf(char c) { 60 | for (AcquisitionType d : values()) { 61 | if (d.toChar() == c) { 62 | return d; 63 | } 64 | } 65 | return valueOf(String.valueOf(c)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/MTWTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import net.sf.marineapi.nmea.sentence.MTWSentence; 5 | import net.sf.marineapi.nmea.sentence.TalkerId; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | /** 11 | * MTW parser tests. 12 | * 13 | * @author Kimmo Tuukkanen 14 | */ 15 | public class MTWTest { 16 | 17 | public static final String EXAMPLE = "$IIMTW,17.75,C"; 18 | 19 | private MTWSentence mtw; 20 | 21 | /** 22 | * @throws java.lang.Exception 23 | */ 24 | @Before 25 | public void setUp() throws Exception { 26 | mtw = new MTWParser(EXAMPLE); 27 | } 28 | 29 | /** 30 | * Test method for 31 | * {@link net.sf.marineapi.nmea.parser.MTWParser#MTWParser(java.lang.String)} 32 | * . 33 | */ 34 | @Test 35 | public void testMTWParserString() { 36 | assertEquals("MTW", mtw.getSentenceId()); 37 | assertEquals(TalkerId.II, mtw.getTalkerId()); 38 | } 39 | 40 | /** 41 | * Test method for 42 | * {@link net.sf.marineapi.nmea.parser.MTWParser#MTWParser(net.sf.marineapi.nmea.sentence.TalkerId)} 43 | * . 44 | */ 45 | @Test 46 | public void testMTWParserTalkerId() { 47 | MTWParser empty = new MTWParser(TalkerId.II); 48 | assertEquals("MTW", empty.getSentenceId()); 49 | assertEquals(TalkerId.II, empty.getTalkerId()); 50 | assertEquals(2, empty.getFieldCount()); 51 | assertEquals('C', empty.getCharValue(1)); 52 | } 53 | 54 | /** 55 | * Test method for 56 | * {@link net.sf.marineapi.nmea.parser.MTWParser#getTemperature()}. 57 | */ 58 | @Test 59 | public void testGetTemperature() { 60 | assertEquals(17.75, mtw.getTemperature(), 0.01); 61 | } 62 | 63 | /** 64 | * Test method for 65 | * {@link net.sf.marineapi.nmea.parser.MTWParser#setTemperature(double)}. 66 | */ 67 | @Test 68 | public void testSetTemperature() { 69 | mtw.setTemperature(12.345); 70 | assertEquals(12.345, mtw.getTemperature(), 0.01); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/ais/parser/AISMessage04Test.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.ais.parser; 2 | 3 | import net.sf.marineapi.ais.message.AISMessage04; 4 | import net.sf.marineapi.ais.util.Sixbit; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | /** 10 | * AIS message 04 test. 11 | * 12 | * Expected values based on http://www.maritec.co.za/tools/aisvdmvdodecoding/ 13 | */ 14 | public class AISMessage04Test { 15 | 16 | // !AIVDM,1,1,,A,400TcdiuiT7VDR>3nIfr6>i00000,0*78 17 | private final String payload = "400TcdiuiT7VDR>3nIfr6>i00000"; 18 | private final Sixbit sixbit = new Sixbit(payload, 0); 19 | private final AISMessage04 msg = new AISMessage04Parser(sixbit); 20 | 21 | @Test 22 | public void getUtcYear() throws Exception { 23 | assertEquals(2012, msg.getUtcYear()); 24 | } 25 | 26 | @Test 27 | public void getUtcMonth() throws Exception { 28 | assertEquals(6, msg.getUtcMonth()); 29 | } 30 | 31 | @Test 32 | public void getUtcDay() throws Exception { 33 | assertEquals(8, msg.getUtcDay()); 34 | } 35 | 36 | @Test 37 | public void getUtcHour() throws Exception { 38 | assertEquals(7, msg.getUtcHour()); 39 | } 40 | 41 | @Test 42 | public void getUtcMinute() throws Exception { 43 | assertEquals(38, msg.getUtcMinute()); 44 | } 45 | 46 | @Test 47 | public void getUtcSecond() throws Exception { 48 | assertEquals(20, msg.getUtcSecond()); 49 | } 50 | 51 | @Test 52 | public void getLatitudeInDegrees() throws Exception { 53 | assertEquals(-29.870835, msg.getLatitudeInDegrees(), 0.000001); 54 | } 55 | 56 | @Test 57 | public void getLongitudeInDegrees() throws Exception { 58 | assertEquals(31.033513, msg.getLongitudeInDegrees(), 0.000001); 59 | } 60 | 61 | @Test 62 | public void getTypeOfEPFD() throws Exception { 63 | // 1 = GPS 64 | assertEquals(1, msg.getTypeOfEPFD()); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/ROTSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ROTSentence.java 3 | * Copyright (C) 2014 Mike Tamis, Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import net.sf.marineapi.nmea.util.DataStatus; 24 | 25 | /** 26 | *

Vessel's rate of turn given in degrees per minute. Negative values 27 | * indicate bow turning to port.

28 | * 29 | *

Example:
{@code $GPROT,35.6,A*4E}

30 | * 31 | * @author Mike Tamis, Kimmo Tuukkanen 32 | */ 33 | public interface ROTSentence extends Sentence { 34 | 35 | /** 36 | * Returns the vessel's rate of turn. 37 | * 38 | * @return Rate of Turn value (degrees per minute) 39 | */ 40 | double getRateOfTurn(); 41 | 42 | /** 43 | * Sets the vessel's rate of turn value. 44 | * 45 | * @param rot Rate of Turn value to set (degrees per minute) 46 | */ 47 | void setRateOfTurn(double rot); 48 | 49 | /** 50 | * Returns the data status (valid/invalid). 51 | * 52 | * @return True means data is valid 53 | */ 54 | DataStatus getStatus(); 55 | 56 | /** 57 | * Sets the data status. 58 | * 59 | * @param status DataStatus to set. 60 | */ 61 | void setStatus(DataStatus status); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/io/DefaultDataReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DefaultDataReader.java 3 | * Copyright (C) 2010-2014 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.io; 22 | 23 | import java.io.BufferedReader; 24 | import java.io.InputStream; 25 | import java.io.InputStreamReader; 26 | 27 | /** 28 | * The default data reader implementation using InputStream as data source. 29 | * 30 | * @author Kimmo Tuukkanen 31 | */ 32 | class DefaultDataReader extends AbstractDataReader { 33 | 34 | private final BufferedReader buffer; 35 | 36 | /** 37 | * Creates a new instance of DefaultDataReader. 38 | * 39 | * @param source InputStream to be used as data source. 40 | * @param parent SentenceReader dispatching events for this reader. 41 | */ 42 | DefaultDataReader(InputStream source, SentenceReader parent) { 43 | super(parent); 44 | this.buffer = new BufferedReader(new InputStreamReader(source)); 45 | } 46 | 47 | /* 48 | * (non-Javadoc) 49 | * 50 | * @see net.sf.marineapi.nmea.io.AbstractDataReader#read() 51 | */ 52 | @Override 53 | public String read() throws Exception { 54 | return buffer.ready() ? buffer.readLine() : null; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/ais/parser/AISMessage27ParserTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.ais.parser; 2 | 3 | import net.sf.marineapi.ais.message.AISMessage27; 4 | import net.sf.marineapi.ais.util.Sixbit; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | /** 10 | * AIS message 27 parser tests 11 | *

12 | * According to the specification: https://www.navcen.uscg.gov/?pageName=AISMessage27 13 | */ 14 | public class AISMessage27ParserTest { 15 | 16 | // !AIVDM,1,1,,,Kk:qFP0?fhT8=7m@,0*50 17 | private final String payload = "Kk:qFP0?fhT8=7m@"; 18 | private final Sixbit sixbit = new Sixbit(payload, 0); 19 | private final AISMessage27 message = new AisMessage27Parser(sixbit); 20 | 21 | @Test 22 | public void getRepeatIndicator() { 23 | assertEquals(3, message.getRepeatIndicator()); 24 | } 25 | 26 | @Test 27 | public void getMMSI() { 28 | assertEquals(212752000, message.getMMSI()); 29 | } 30 | 31 | @Test 32 | public void isAccurate() { 33 | assertFalse(message.isAccurate()); 34 | } 35 | 36 | @Test 37 | public void getRaimFlag() { 38 | assertFalse(message.getRAIMFlag()); 39 | } 40 | 41 | @Test 42 | public void getNavigationalStatus() { 43 | assertEquals(0, message.getNavigationalStatus()); 44 | } 45 | 46 | @Test 47 | public void getLongitude() { 48 | assertEquals(-7.3566666666666665, message.getLongitudeInDegrees(), 0); 49 | } 50 | 51 | @Test 52 | public void getLatitude() { 53 | assertEquals(56.36333333333334, message.getLatitudeInDegrees(), 0); 54 | } 55 | 56 | @Test 57 | public void getSpeedOverGround() { 58 | assertEquals(15.0, message.getSpeedOverGround(), 0); 59 | } 60 | 61 | @Test 62 | public void getCourseOverGround() { 63 | assertEquals(340.0, message.getCourseOverGround(), 0); 64 | } 65 | 66 | @Test 67 | public void getPositionLatency() { 68 | assertEquals(0, message.getPositionLatency()); 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/DPTSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DPTSentence.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Depth of water, measured in meters. Includes offset to transducer, positive 25 | * values for distance from transducer to water line and negative values for 26 | * distance from transducer to keel. The maximum value is included since NMEA 27 | * v3.0 and may thus be missing.

28 | * 29 | *

Example:
{@code $SDDPT,2.4,,*7F}

30 | * 31 | * @author Kimmo Tuukkanen 32 | */ 33 | public interface DPTSentence extends DepthSentence { 34 | 35 | /** 36 | * Get offset to transducer. 37 | * 38 | * @return Offset in meters. 39 | */ 40 | double getOffset(); 41 | 42 | /** 43 | * Set offset to transducer. 44 | * 45 | * @param offset Offset in meters 46 | */ 47 | void setOffset(double offset); 48 | 49 | /** 50 | * Get maximum depth value the sounder can detect. 51 | * 52 | * @return Maximum depth, in meters. 53 | */ 54 | double getMaximum(); 55 | 56 | /** 57 | * Set maximum depth value the sounder can detect. 58 | * 59 | * @param max Maximum depth, in meters. 60 | */ 61 | void setMaximum(double max); 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/VLWTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import net.sf.marineapi.nmea.sentence.TalkerId; 5 | import net.sf.marineapi.nmea.sentence.VLWSentence; 6 | 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | public class VLWTest { 11 | 12 | public static final String EXAMPLE = "$VWVLW,2.8,N,0.8,N"; 13 | 14 | VLWSentence vlw; 15 | VLWSentence empty; 16 | 17 | @Before 18 | public void setUp() throws Exception { 19 | vlw = new VLWParser(EXAMPLE); 20 | empty = new VLWParser(TalkerId.VD); 21 | } 22 | 23 | @Test 24 | public void testVLWParserString() { 25 | assertEquals(TalkerId.VW, vlw.getTalkerId()); 26 | assertEquals("VLW", vlw.getSentenceId()); 27 | assertEquals(4, vlw.getFieldCount()); 28 | } 29 | 30 | @Test 31 | public void testVLWParserTalkerId() { 32 | assertEquals(TalkerId.VD, empty.getTalkerId()); 33 | assertEquals("VLW", empty.getSentenceId()); 34 | assertEquals(4, empty.getFieldCount()); 35 | } 36 | 37 | @Test 38 | public void testGetTotal() { 39 | assertEquals(2.8, vlw.getTotal(), 0.1); 40 | } 41 | 42 | @Test 43 | public void testGetTotalUnits() { 44 | assertEquals('N', vlw.getTotalUnits()); 45 | } 46 | 47 | @Test 48 | public void testGetTrip() { 49 | assertEquals(0.8, vlw.getTrip(), 0.1); 50 | } 51 | 52 | @Test 53 | public void testGetTripUnits() { 54 | assertEquals('N', vlw.getTripUnits()); 55 | } 56 | 57 | @Test 58 | public void testSetTotal() { 59 | empty.setTotal(3.14); 60 | assertEquals(3.1, empty.getTotal(), 0.1); 61 | } 62 | 63 | @Test 64 | public void testSetTotalUnits() { 65 | empty.setTotalUnits(VLWSentence.KM); 66 | assertEquals(VLWSentence.KM, empty.getTotalUnits()); 67 | } 68 | 69 | @Test 70 | public void testSetTrip() { 71 | empty.setTrip(0.0); 72 | assertEquals(0.0, empty.getTrip(), 0.1); 73 | } 74 | 75 | @Test 76 | public void testSetTripUnits() { 77 | empty.setTripUnits(VLWSentence.NM); 78 | assertEquals(VLWSentence.NM, empty.getTripUnits()); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/util/UbloxSatelliteStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Gunnar Hillert 3 | * 4 | * This file is part of Java Marine API. 5 | * 6 | * 7 | * Java Marine API is free software: you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by the 9 | * Free Software Foundation, either version 3 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * Java Marine API is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with Java Marine API. If not, see . 19 | */ 20 | package net.sf.marineapi.ublox.util; 21 | 22 | import net.sf.marineapi.ublox.message.UBXMessage03; 23 | 24 | /** 25 | * Defines the satellite statuses defined by proprietary u-blox NMEA extension 26 | * 27 | * @author Gunnar Hillert 28 | * 29 | * @see UBXMessage03 30 | */ 31 | public enum UbloxSatelliteStatus { 32 | 33 | /** 34 | * Not used. 35 | */ 36 | NOT_USED('-'), 37 | 38 | /** 39 | * Used in solution. 40 | */ 41 | USED_IN_SOLUTION('U'), 42 | 43 | /** 44 | * Ephemeris available, but not used for navigation. 45 | */ 46 | NOT_USED_EPHEMERIS_AVAILABLE('e'); 47 | 48 | 49 | private char statusFlag; 50 | 51 | private UbloxSatelliteStatus(char statusFlag) { 52 | this.statusFlag = statusFlag; 53 | } 54 | 55 | public char getStatusFlag() { 56 | return statusFlag; 57 | } 58 | 59 | public static UbloxSatelliteStatus fromStatusFlag(char statusFlag) { 60 | 61 | for (UbloxSatelliteStatus ubloxSatelliteStatusType : UbloxSatelliteStatus.values()) { 62 | if (ubloxSatelliteStatusType.getStatusFlag() == statusFlag) { 63 | return ubloxSatelliteStatusType; 64 | } 65 | } 66 | 67 | return null; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/util/TimeStamp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TimeStamp.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.util; 22 | 23 | /** 24 | * Checks a 6-bit integer time stamp value for validity. 25 | * 26 | * @author Lázár József 27 | */ 28 | public class TimeStamp { 29 | 30 | private static final int MINVALUE = 0; 31 | private static final int MAXVALUE = 59; 32 | 33 | /** 34 | * Checks if the time stamp value is available. 35 | * 36 | * @param value Timetamp value to check 37 | * @return true if the time stamp falls within a range 38 | */ 39 | public static boolean isAvailable(int value) { 40 | return (value >= MINVALUE && value <= MAXVALUE); 41 | } 42 | 43 | /** 44 | * Return a string representing the time stamp value. 45 | * 46 | * @param value Timetamp value to stringify 47 | * @return a string representing the time stamp 48 | */ 49 | public static String toString(int value) { 50 | switch (value) { 51 | case 60: 52 | return "no time stamp"; 53 | case 61: 54 | return "positioning system manual"; 55 | case 62: 56 | return "dead reckoning"; 57 | case 63: 58 | return "positioning system inoperative"; 59 | default: 60 | return Integer.toString(value); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/RouteType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * RouteType.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the supported route types. 25 | * 26 | * @author Kimmo Tuukkanen 27 | * @see net.sf.marineapi.nmea.sentence.RTESentence 28 | */ 29 | public enum RouteType { 30 | 31 | /** 32 | * Active route: complete, all waypoints in route order. 33 | */ 34 | ACTIVE('c'), 35 | 36 | /** 37 | * Working route: the waypoint you just left, the waypoint you're heading to 38 | * and then all the rest. 39 | */ 40 | WORKING('w'); 41 | 42 | private final char chr; 43 | 44 | private RouteType(char c) { 45 | chr = c; 46 | } 47 | 48 | /** 49 | * Get the corresponding char indicator of enum. 50 | * 51 | * @return Char 52 | */ 53 | public char toChar() { 54 | return chr; 55 | } 56 | 57 | /** 58 | * Get the char indicator corresponding to enum. 59 | * 60 | * @param ch Char 61 | * @return ReturnType corresponding to specified char. 62 | */ 63 | public RouteType valueOf(char ch) { 64 | for (RouteType type : values()) { 65 | if (type.toChar() == ch) { 66 | return type; 67 | } 68 | } 69 | return valueOf(String.valueOf(ch)); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/DataStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DataStatus.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * DataStatus defines the validity of data being broadcasted by an NMEA device. 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public enum DataStatus { 29 | 30 | /** Valid data available. May also indicate boolean value {@code true}. */ 31 | ACTIVE('A'), 32 | 33 | /** 34 | * No valid data available. May also indicate boolean value 35 | * {@code false}. 36 | */ 37 | VOID('V'); 38 | 39 | private final char character; 40 | 41 | DataStatus(char ch) { 42 | character = ch; 43 | } 44 | 45 | /** 46 | * Returns the character used in NMEA sentences to indicate the status. 47 | * 48 | * @return Char indicator for DataStatus 49 | */ 50 | public char toChar() { 51 | return character; 52 | } 53 | 54 | /** 55 | * Returns the DataStatus enum for status char used in sentences. 56 | * 57 | * @param ch Status char 58 | * @return DataStatus 59 | */ 60 | public static DataStatus valueOf(char ch) { 61 | for (DataStatus ds : values()) { 62 | if (ds.toChar() == ch) { 63 | return ds; 64 | } 65 | } 66 | return valueOf(String.valueOf(ch)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/util/WaypointTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * WaypointTest.java 3 | * Copyright 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | 28 | /** 29 | * WaypointTest 30 | * 31 | * @author Kimmo Tuukkanen 32 | */ 33 | public class WaypointTest { 34 | 35 | private final String id1 = "FOO"; 36 | private final String id2 = "BAR"; 37 | private final String desc = "Description text"; 38 | Waypoint point; 39 | 40 | @Before 41 | public void setUp() { 42 | point = new Waypoint(id1, 60.0, 25.0, Datum.WGS84); 43 | } 44 | 45 | /** 46 | * Test method for 47 | * {@link net.sf.marineapi.nmea.util.Waypoint#setDescription(java.lang.String)} 48 | * . 49 | */ 50 | @Test 51 | public void testDescription() { 52 | assertEquals("", point.getDescription()); 53 | point.setDescription(desc); 54 | assertEquals(desc, point.getDescription()); 55 | } 56 | 57 | /** 58 | * Test method for 59 | * {@link net.sf.marineapi.nmea.util.Waypoint#setId(java.lang.String)}. 60 | */ 61 | @Test 62 | public void testId() { 63 | assertEquals(id1, point.getId()); 64 | point.setId(id2); 65 | assertEquals(id2, point.getId()); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/MMBSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MMBSentence.java 3 | * Copyright (C) 2016 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Barometer - Barometric pressure in bars and inches of mercury.

25 | * 26 | *

Notice: not recommended as of Oct 2008, should use {@code XDR} 27 | * instead.

28 | * 29 | *

Example:
30 | * {@code $IIMMB,29.9870,I,1.0154,B*75}

31 | * 32 | * @author Kimmo Tuukkanen 33 | */ 34 | public interface MMBSentence extends Sentence { 35 | 36 | /** 37 | * Returns the barometric pressure in inches of mercury. 38 | * 39 | * @return Barometric pressure, inHg. 40 | */ 41 | double getInchesOfMercury(); 42 | 43 | /** 44 | * Returns the barometric pressure in bars. 45 | * 46 | * @return Barometric pressure, bars. 47 | */ 48 | double getBars(); 49 | 50 | /** 51 | * Sets the barometric pressure in inches of mercury. 52 | * 53 | * @param inhg Barometric pressure, inHg. 54 | */ 55 | void setInchesOfMercury(double inhg); 56 | 57 | /** 58 | * Sets the barometric pressure in bars. 59 | * 60 | * @param bars Barometric pressure, bars. 61 | */ 62 | void setBars(double bars); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/parser/UBXMessageParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Gunnar Hillert 3 | * 4 | * This file is part of Java Marine API. 5 | * 6 | * 7 | * Java Marine API is free software: you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by the 9 | * Free Software Foundation, either version 3 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * Java Marine API is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with Java Marine API. If not, see . 19 | */ 20 | package net.sf.marineapi.ublox.parser; 21 | 22 | import net.sf.marineapi.nmea.parser.SentenceParser; 23 | import net.sf.marineapi.nmea.sentence.UBXSentence; 24 | import net.sf.marineapi.ublox.message.UBXMessage; 25 | 26 | /** 27 | * This is the base class for all UBX message parser implementations and contains 28 | * common logic. In a sense it wraps the given {@link UBXSentence}. The {@link UBXMessageParser} 29 | * extends {@link SentenceParser} to access the fields from the NMEA message (UBXSentence). 30 | * 31 | * @author Gunnar Hillert 32 | * 33 | * @see UBXMessage00Parser 34 | * @see UBXMessage03Parser 35 | */ 36 | public class UBXMessageParser extends SentenceParser implements UBXMessage { 37 | 38 | protected final UBXSentence sentence; 39 | 40 | /** 41 | * Construct a parser with the given {@link UBXSentence}. 42 | * 43 | * @param sentence UBXSentence 44 | */ 45 | public UBXMessageParser(UBXSentence sentence) { 46 | super(sentence.toString()); 47 | this.sentence = sentence; 48 | } 49 | 50 | /** 51 | * @see UBXMessage#getMessageType() 52 | */ 53 | @Override 54 | public int getMessageType() { 55 | return this.sentence.getMessageId(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/DateSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DateSentence.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import net.sf.marineapi.nmea.util.Date; 24 | 25 | /** 26 | * Sentences that contains date information. Notice that some sentences may 27 | * contain only time without the date. 28 | * 29 | * @author Kimmo Tuukkanen 30 | * @see net.sf.marineapi.nmea.sentence.TimeSentence 31 | */ 32 | public interface DateSentence extends Sentence { 33 | 34 | /** 35 | * Parses the date information from sentence fields and returns a 36 | * {@link Date}. 37 | * 38 | * @return Date object 39 | * @throws net.sf.marineapi.nmea.parser.DataNotAvailableException If the data is 40 | * not available. 41 | * @throws net.sf.marineapi.nmea.parser.ParseException If the field contains 42 | * unexpected or illegal value. 43 | */ 44 | Date getDate(); 45 | 46 | /** 47 | * Set date. Depending on the sentence type, the values may be inserted to 48 | * multiple fields or combined into one. Four-digit year value may also be 49 | * reduced into two-digit format. 50 | * 51 | * @param date {@link Date} 52 | */ 53 | void setDate(Date date); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/GpsFixStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GpsFixStatus.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * GpsFixStatus defines the status of current GPS fix. 25 | * 26 | * @author Kimmo Tuukkanen 27 | * @see FaaMode 28 | * @see GpsFixQuality 29 | * @see DataStatus 30 | */ 31 | public enum GpsFixStatus { 32 | 33 | /** No GPS fix available */ 34 | GPS_NA(1), 35 | /** 2D GPS fix (lat/lon) */ 36 | GPS_2D(2), 37 | /** 3D GPS fix (lat/lon/alt) */ 38 | GPS_3D(3); 39 | 40 | private final int status; 41 | 42 | GpsFixStatus(int intVal) { 43 | status = intVal; 44 | } 45 | 46 | /** 47 | * Returns the corresponding int value for fix status enum. 48 | * 49 | * @return Fix status integer values as in sentences 50 | */ 51 | public int toInt() { 52 | return status; 53 | } 54 | 55 | /** 56 | * Returns the GpsFixStatus enum corresponding to actual int identifier used 57 | * in the sentences. 58 | * 59 | * @param val Fix status indentifier int 60 | * @return GpsFixStatus enum 61 | */ 62 | public static GpsFixStatus valueOf(int val) { 63 | for (GpsFixStatus st : values()) { 64 | if (st.toInt() == val) { 65 | return st; 66 | } 67 | } 68 | return valueOf(String.valueOf(val)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/TurnMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TurnMode.java 3 | * Copyright (C) 2015 Paweł Kozioł, Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines how the ship changes heading, as returned by HTC and HTD sentences. 25 | * 26 | * @author Paweł Kozioł 27 | * @see net.sf.marineapi.nmea.sentence.HTCSentence 28 | * @see net.sf.marineapi.nmea.sentence.HTDSentence 29 | */ 30 | public enum TurnMode { 31 | 32 | /** Radius controlled */ 33 | RADIUS_CONTROLLED('R'), 34 | /** Turn rate controlled */ 35 | TURN_RATE_CONTROLLED('T'), 36 | /** Not controlled */ 37 | NOT_CONTROLLED('N'); 38 | 39 | private final char character; 40 | 41 | TurnMode(char ch) { 42 | character = ch; 43 | } 44 | 45 | /** 46 | * Returns the character used in NMEA sentences to indicate the status. 47 | * 48 | * @return Char indicator for TurnMode 49 | */ 50 | public char toChar() { 51 | return character; 52 | } 53 | 54 | /** 55 | * Returns the TurnMode enum for status char used in sentences. 56 | * 57 | * @param ch Status char 58 | * @return TurnMode 59 | */ 60 | public static TurnMode valueOf(char ch) { 61 | for (TurnMode tm : values()) { 62 | if (tm.toChar() == ch) { 63 | return tm; 64 | } 65 | } 66 | return valueOf(String.valueOf(ch)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISPositionReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISPositionReport.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | *

25 | * Common interface for all messages providing position reports.

26 | *

27 | * See Class A AIS 28 | * position report specification for more details on return values and 29 | * status codes.

30 | * @author Lázár József 31 | */ 32 | public interface AISPositionReport extends AISPositionReportB { 33 | 34 | /** 35 | * Returns the navigational status. 36 | * 37 | * @return The navigational status indicator between 0 - 15 38 | */ 39 | int getNavigationalStatus(); 40 | 41 | /** 42 | * Returns the rate of turn. 43 | * 44 | * @return Rate of turn, in degrees per min 45 | */ 46 | double getRateOfTurn(); 47 | 48 | /** 49 | * Returns the manouver indicator. 50 | * 51 | * @return 0 = not available = default, 1 = not engaged in special maneuver 52 | * or 2 = engaged in special maneuver 53 | */ 54 | int getManouverIndicator(); 55 | 56 | /** 57 | * Returns true if rate of turn is available in the message. 58 | * 59 | * @return true if has ROT, otherwise false. 60 | */ 61 | boolean hasRateOfTurn(); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/ReferenceSystem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ReferenceSystem.java 3 | * Copyright (C) 2020 Joshua Sweaney 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the various reference systems that can be used to calculate 25 | * a vessel's kinematics such as speed and course. 26 | * 27 | * @see net.sf.marineapi.nmea.sentence.OSDSentence 28 | * 29 | * @author Joshua Sweaney 30 | */ 31 | public enum ReferenceSystem { 32 | 33 | BOTTOM_TRACKING_LOG('B'), 34 | 35 | MANUALLY_ENTERED('M'), 36 | 37 | WATER_REFERENCED('W'), 38 | 39 | RADAR_TRACKING('R'), 40 | 41 | POSITIONING_SYSTEM_GROUND_REFERENCE('P'); 42 | 43 | private char ch; 44 | 45 | private ReferenceSystem(char c) { 46 | ch = c; 47 | } 48 | 49 | /** 50 | * Returns the corresponding char constant. 51 | * 52 | * @return Char indicator of enum 53 | */ 54 | public char toChar() { 55 | return ch; 56 | } 57 | 58 | /** 59 | * Get the enum corresponding to specified char. 60 | * 61 | * @param ch Char indicator for reference 62 | * @return ReferenceSystem enum 63 | */ 64 | public static ReferenceSystem valueOf(char ch) { 65 | for (ReferenceSystem r : values()) { 66 | if (r.toChar() == ch) { 67 | return r; 68 | } 69 | } 70 | return valueOf(String.valueOf(ch)); 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISPositionInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISPositionInfo.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Interface for all position information. 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface AISPositionInfo extends AISMessage { 29 | 30 | /** 31 | * Tells if the position is accurate. 32 | * 33 | * @return {@code true} if accurate (< 10 meters), otherwise {@code false}. 34 | */ 35 | boolean isAccurate(); 36 | 37 | /** 38 | * Returns the longitude in degrees. 39 | * 40 | * @return Longitude, in degrees. 41 | */ 42 | double getLongitudeInDegrees(); 43 | 44 | /** 45 | * Returns the latitude in degrees. 46 | * 47 | * @return Latitude, in degrees. 48 | */ 49 | double getLatitudeInDegrees(); 50 | 51 | /** 52 | * Tells if the longitude is available in the message. If not, 53 | * {@link #getLongitudeInDegrees} may return an out-of-range value. 54 | * 55 | * @return {@code true} if available, otherwise {@code false}. 56 | */ 57 | boolean hasLongitude(); 58 | 59 | /** 60 | * Tells if the latitude is available in the message. If not, 61 | * {@link #getLatitudeInDegrees()} may return an out-of-range value. 62 | * 63 | * @return {@code true} if available, otherwise {@code false}. 64 | */ 65 | boolean hasLatitude(); 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/VDRTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | import net.sf.marineapi.nmea.sentence.SentenceId; 6 | import net.sf.marineapi.nmea.sentence.TalkerId; 7 | import net.sf.marineapi.nmea.sentence.VDRSentence; 8 | 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | public class VDRTest { 13 | 14 | public static final String EXAMPLE = "$IIVDR,123.4,T,124.5,M,1.2,N"; 15 | 16 | private VDRSentence vdr; 17 | private VDRSentence empty; 18 | 19 | @Before 20 | public void setUp() throws Exception { 21 | vdr = new VDRParser(EXAMPLE); 22 | empty = new VDRParser(TalkerId.IN); 23 | } 24 | 25 | @Test 26 | public void testVDRParserString() { 27 | assertEquals(TalkerId.II, vdr.getTalkerId()); 28 | assertEquals(SentenceId.VDR.name(), vdr.getSentenceId()); 29 | assertEquals(6, vdr.getFieldCount()); 30 | } 31 | 32 | @Test 33 | public void testVDRParserTalkerId() { 34 | assertEquals(TalkerId.IN, empty.getTalkerId()); 35 | assertEquals(SentenceId.VDR.name(), empty.getSentenceId()); 36 | assertEquals(6, empty.getFieldCount()); 37 | assertTrue(empty.toString().startsWith("$INVDR,,T,,M,,N*")); 38 | } 39 | 40 | @Test 41 | public void testGetMagneticDirection() { 42 | assertEquals(124.5, vdr.getMagneticDirection(), 0.1); 43 | } 44 | 45 | @Test 46 | public void testGetSpeed() { 47 | assertEquals(1.2, vdr.getSpeed(), 0.1); 48 | } 49 | 50 | @Test 51 | public void testGetTrueDirection() { 52 | assertEquals(123.4, vdr.getTrueDirection(), 0.1); 53 | } 54 | 55 | @Test 56 | public void testSetMagneticDirection() { 57 | final double dir = 45.123; 58 | empty.setMagneticDirection(dir); 59 | assertEquals(dir, empty.getMagneticDirection(), 0.1); 60 | } 61 | 62 | @Test 63 | public void testSetSpeed() { 64 | final double speed = 2.124; 65 | empty.setSpeed(speed); 66 | assertEquals(speed, empty.getSpeed(), 0.1); 67 | } 68 | 69 | @Test 70 | public void testSetTrueDirection() { 71 | final double dir = 55.234; 72 | empty.setTrueDirection(dir); 73 | assertEquals(dir, empty.getTrueDirection(), 0.1); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/DisplayRotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DisplayRotation.java 3 | * Copyright (C) 2020 Joshua Sweaney 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the various display rotations a navigational display 25 | * (such as an ARPA) can select. 26 | * 27 | * @see net.sf.marineapi.nmea.sentence.RSDSentence 28 | * 29 | * @author Joshua Sweaney 30 | */ 31 | public enum DisplayRotation { 32 | 33 | /** Course up, course-over-ground up, degrees true */ 34 | COURSE_UP('C'), 35 | 36 | /** Head up, ship's heading (centre line) pointing up */ 37 | HEAD_UP('H'), 38 | 39 | /** North up, true north 0 degrees is up */ 40 | NORTH_UP('N'); 41 | 42 | private char ch; 43 | 44 | private DisplayRotation(char c) { 45 | ch = c; 46 | } 47 | 48 | /** 49 | * Returns the corresponding char constant. 50 | * 51 | * @return Char indicator of enum 52 | */ 53 | public char toChar() { 54 | return ch; 55 | } 56 | 57 | /** 58 | * Get the enum corresponding to specified char. 59 | * 60 | * @param ch Char indicator for display rotation 61 | * @return DisplayRotation enum 62 | */ 63 | public static DisplayRotation valueOf(char ch) { 64 | for (DisplayRotation r : values()) { 65 | if (r.toChar() == ch) { 66 | return r; 67 | } 68 | } 69 | return valueOf(String.valueOf(ch)); 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISUTCReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISUTCReport.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Common interface for all UTC time and position providing AIS messages. 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface AISUTCReport extends AISMessage { 29 | 30 | /** 31 | * Returns the UTC year. 32 | * @return an integer value representing the UTC year (1-9999) 33 | */ 34 | int getUtcYear(); 35 | 36 | /** 37 | * Returns the UTC month. 38 | * @return an integer value representing the UTC month (1-12) 39 | */ 40 | int getUtcMonth(); 41 | 42 | /** 43 | * Returns the UTC day. 44 | * @return an integer value representing the UTC day (1-31) 45 | */ 46 | int getUtcDay(); 47 | 48 | /** 49 | * Returns the UTC hour. 50 | * @return an integer value representing the UTC hour (0-23) 51 | */ 52 | int getUtcHour(); 53 | 54 | /** 55 | * Returns the UTC minute. 56 | * @return an integer value representing the UTC minute (0-59) 57 | */ 58 | int getUtcMinute(); 59 | 60 | /** 61 | * Returns the UTC second. 62 | * @return an integer value representing the UTC second (0-59) 63 | */ 64 | int getUtcSecond(); 65 | 66 | /** 67 | * Returns the type of electronic position fixing device. 68 | * @return an integer value of the position device 69 | */ 70 | int getTypeOfEPFD(); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/DTBParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DTBParser.java 3 | * Copyright (C) 2019 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | import net.sf.marineapi.nmea.sentence.DTBSentence; 24 | import net.sf.marineapi.nmea.sentence.SentenceId; 25 | import net.sf.marineapi.nmea.sentence.TalkerId; 26 | 27 | /** 28 | * DTB sentence parser. 29 | * 30 | * @author Bob Schwarz 31 | * @see marine-api fork 32 | */ 33 | class DTBParser extends DTAParser implements DTBSentence { 34 | 35 | public static final String DTB_SENTENCE_ID = "DTB"; 36 | 37 | /** 38 | * Creates a new instance of DTBParser with 8 data fields. 39 | * 40 | * @param talker DTB talkerId 41 | */ 42 | public DTBParser(TalkerId talker) { 43 | super(talker, SentenceId.DTB, 8); 44 | } 45 | 46 | /** 47 | * Creates a new instance of DTBParser. 48 | * 49 | * @param nmea DTB sentence String 50 | */ 51 | public DTBParser(String nmea) { 52 | super(nmea, SentenceId.DTB); 53 | } 54 | 55 | /** 56 | * Gets the hard-coded channel for GasFinder2. Since only GasFinder2 57 | * will send a DTB sentence, and since only GasFinderMC has channels, 58 | * there will normally be no channel in DTB sentences. 59 | * 60 | * @return Channel number, always 2. 61 | */ 62 | @Override 63 | public int getChannelNumber() { 64 | return 2; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/VDRSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * VDRSentence.java 3 | * Copyright (C) 2014 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | * Set and drift, true/magnetic direction and speed of current. 25 | * 26 | * @author Kimmo Tuukkanen 27 | */ 28 | public interface VDRSentence extends Sentence { 29 | 30 | /** 31 | * Returns the magnetic current direction. 32 | * 33 | * @return Direction in degrees 34 | * @see #getTrueDirection() 35 | */ 36 | double getMagneticDirection(); 37 | 38 | /** 39 | * Returns the current flow speed. 40 | * 41 | * @return Speed in knots 42 | */ 43 | double getSpeed(); 44 | 45 | /** 46 | * Returns the true direction of current. 47 | * 48 | * @return Direction in degrees 49 | * @see #getMagneticDirection() 50 | */ 51 | double getTrueDirection(); 52 | 53 | /** 54 | * Sets the magnetic direction of current. 55 | * 56 | * @param direction Direction to set, in degrees. 57 | */ 58 | void setMagneticDirection(double direction); 59 | 60 | /** 61 | * Sets the current flow speed. 62 | * 63 | * @param speed Speed in knots 64 | */ 65 | void setSpeed(double speed); 66 | 67 | /** 68 | * Sets the true direction of current. 69 | * 70 | * @param direction Direction in degrees 71 | * @see #setMagneticDirection(double) 72 | */ 73 | void setTrueDirection(double direction); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/ROTTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.fail; 5 | import net.sf.marineapi.nmea.sentence.ROTSentence; 6 | import net.sf.marineapi.nmea.sentence.SentenceId; 7 | import net.sf.marineapi.nmea.sentence.TalkerId; 8 | import net.sf.marineapi.nmea.util.DataStatus; 9 | 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | 13 | /** 14 | * Created by SJK on 22/01/14. 15 | */ 16 | public class ROTTest { 17 | 18 | public static final String EXAMPLE = "$HCROT,-0.3,A"; 19 | public static final String INVALID_EXAMPLE = "$HCROT,-0.3,V"; 20 | ROTSentence rot; 21 | ROTSentence irot; 22 | 23 | @Before 24 | public void setUp() throws Exception { 25 | rot = new ROTParser(EXAMPLE); 26 | irot = new ROTParser(INVALID_EXAMPLE); 27 | } 28 | 29 | @Test 30 | public void testConstructor() { 31 | ROTSentence empty = new ROTParser(TalkerId.HE); 32 | assertEquals(TalkerId.HE, empty.getTalkerId()); 33 | assertEquals(SentenceId.ROT.toString(), empty.getSentenceId()); 34 | try { 35 | empty.getRateOfTurn(); 36 | } catch (DataNotAvailableException e) { 37 | // pass 38 | } catch (Exception e) { 39 | fail(e.getMessage()); 40 | } 41 | } 42 | 43 | @Test 44 | public void testGetStatus() { 45 | assertEquals(DataStatus.ACTIVE, rot.getStatus()); 46 | assertEquals(DataStatus.VOID, irot.getStatus()); 47 | } 48 | 49 | @Test 50 | public void testSetStatus() { 51 | rot.setStatus(DataStatus.VOID); 52 | assertEquals(DataStatus.VOID, rot.getStatus()); 53 | } 54 | 55 | @Test 56 | public void testGetRateOfTurn() { 57 | double value = rot.getRateOfTurn(); 58 | assertEquals(-0.3, value, 0.1); 59 | } 60 | 61 | @Test 62 | public void testSetRateOfTurn() { 63 | final double newValue = 0.5; 64 | rot.setRateOfTurn(newValue); 65 | assertEquals(newValue, rot.getRateOfTurn(), 0.1); 66 | } 67 | 68 | @Test 69 | public void testSetRateOfTurnNegative() { 70 | final double newValue = -12.3; 71 | rot.setRateOfTurn(newValue); 72 | assertEquals(newValue, rot.getRateOfTurn(), 0.1); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/MTAParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MTAParser.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | import net.sf.marineapi.nmea.sentence.MTASentence; 24 | import net.sf.marineapi.nmea.sentence.SentenceId; 25 | import net.sf.marineapi.nmea.sentence.TalkerId; 26 | import net.sf.marineapi.nmea.util.Units; 27 | 28 | /** 29 | * MTA sentence parser. 30 | * 31 | * @author Kimmo Tuukkanen 32 | */ 33 | class MTAParser extends SentenceParser implements MTASentence { 34 | 35 | private static final int TEMPERATURE = 0; 36 | private static final int UNIT_INDICATOR = 1; 37 | 38 | /** 39 | * Constructor. 40 | * 41 | * @param mta MTA sentence String to parse. 42 | */ 43 | public MTAParser(String mta) { 44 | super(mta, SentenceId.MTA); 45 | } 46 | 47 | /** 48 | * Constructor for empty MTA sentence. 49 | * 50 | * @param talker Talker ID to set. 51 | */ 52 | public MTAParser(TalkerId talker) { 53 | super(talker, SentenceId.MTA, 2); 54 | setCharValue(UNIT_INDICATOR, Units.CELSIUS.toChar()); 55 | } 56 | 57 | /* 58 | * (non-Javadoc) 59 | * @see net.sf.marineapi.nmea.sentence.MTASentence#getTemperature() 60 | */ 61 | public double getTemperature() { 62 | return getDoubleValue(TEMPERATURE); 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * @see net.sf.marineapi.nmea.sentence.MTASentence#setTemperature(double) 68 | */ 69 | public void setTemperature(double temp) { 70 | setDoubleValue(TEMPERATURE, temp, 1, 2); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/ais/util/SpeedOverGroundTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.ais.util; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertEquals; 6 | import static org.junit.Assert.assertFalse; 7 | import static org.junit.Assert.assertTrue; 8 | 9 | public class SpeedOverGroundTest { 10 | private static final double DELTA = 0.001; 11 | 12 | @Test 13 | public void minValueIsAvailable() { 14 | assertTrue(SpeedOverGround.isAvailable(0)); 15 | } 16 | 17 | @Test 18 | public void minValueIsCorrect() { 19 | assertTrue(SpeedOverGround.isCorrect(0)); 20 | } 21 | 22 | @Test 23 | public void maxValueIsAvailable() { 24 | assertTrue(SpeedOverGround.isAvailable(1022)); 25 | } 26 | 27 | @Test 28 | public void maxValueIsCorrect() { 29 | assertTrue(SpeedOverGround.isCorrect(1022)); 30 | } 31 | 32 | @Test 33 | public void defaultValueIsNotAvailable() { 34 | assertFalse(SpeedOverGround.isAvailable(1023)); 35 | } 36 | 37 | @Test 38 | public void defaultValueIsCorrect() { 39 | assertTrue(SpeedOverGround.isCorrect(1023)); 40 | } 41 | 42 | @Test 43 | public void negativeValueIsNotAvailable() { 44 | assertFalse(SpeedOverGround.isAvailable(-1)); 45 | } 46 | 47 | @Test 48 | public void negativeValueIsNotCorrect() { 49 | assertFalse(SpeedOverGround.isCorrect(-1)); 50 | } 51 | 52 | @Test 53 | public void largeValueIsNotAvailable() { 54 | assertFalse(SpeedOverGround.isAvailable(1100)); 55 | } 56 | 57 | @Test 58 | public void largeValueIsNotCorrect() { 59 | assertFalse(SpeedOverGround.isCorrect(1100)); 60 | } 61 | 62 | @Test 63 | public void conversionToKnotsWorks() { 64 | assertEquals(0.0, SpeedOverGround.toKnots(0), DELTA); 65 | assertEquals(0.1, SpeedOverGround.toKnots(1), DELTA); 66 | assertEquals(90.9, SpeedOverGround.toKnots(909), DELTA); 67 | assertEquals(102.2, SpeedOverGround.toKnots(1022), DELTA); 68 | } 69 | 70 | @Test 71 | public void conversionReturnsOnInvalidValues() { 72 | assertEquals(-10.1, SpeedOverGround.toKnots(-101), DELTA); 73 | assertEquals(102.3, SpeedOverGround.toKnots(1023), DELTA); 74 | assertEquals(4567.8, SpeedOverGround.toKnots(45678), DELTA); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/io/ActivityMonitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ActivityMonitor.java 3 | * Copyright (C) 2012 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.io; 22 | 23 | /** 24 | * Monitor for firing state change events events, i.e. reader started, paused or 25 | * stopped. 26 | * 27 | * @author Kimmo Tuukkanen 28 | */ 29 | class ActivityMonitor { 30 | 31 | private long lastUpdated = -1; 32 | private SentenceReader parent; 33 | 34 | /** 35 | * Creates a new instance for given {@link SentenceReader}. 36 | * 37 | * @param parent Parent {@link SentenceReader} to monitor. 38 | */ 39 | public ActivityMonitor(SentenceReader parent) { 40 | this.parent = parent; 41 | } 42 | 43 | /** 44 | * Resets the monitor in initial state. 45 | */ 46 | public void reset() { 47 | lastUpdated = -1; 48 | } 49 | 50 | /** 51 | * Refreshes the monitor timestamp and fires reading started event if 52 | * currently paused. 53 | */ 54 | public void refresh() { 55 | if (lastUpdated < 0) { 56 | parent.fireReadingStarted(); 57 | } 58 | this.lastUpdated = System.currentTimeMillis(); 59 | } 60 | 61 | /** 62 | * Heartbeat method, checks the time out if not paused. 63 | */ 64 | public void tick() { 65 | if (lastUpdated > 0) { 66 | long elapsed = System.currentTimeMillis() - lastUpdated; 67 | int timeout = parent.getPauseTimeout(); 68 | if (elapsed >= timeout) { 69 | parent.fireReadingPaused(); 70 | reset(); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/MWDTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertTrue; 5 | import net.sf.marineapi.nmea.sentence.MWDSentence; 6 | import net.sf.marineapi.nmea.sentence.SentenceId; 7 | import net.sf.marineapi.nmea.sentence.TalkerId; 8 | 9 | import org.junit.Before; 10 | import org.junit.Test; 11 | 12 | /** 13 | * @author Richard van Nieuwenhoven 14 | */ 15 | public class MWDTest { 16 | 17 | public static final String EXAMPLE = "$IIMWD,295.19,T,,M,5.09,N,2.62,M*56"; 18 | 19 | private MWDSentence mwd; 20 | 21 | /** 22 | * @throws java.lang.Exception 23 | */ 24 | @Before 25 | public void setUp() throws Exception { 26 | mwd = new MWDParser(EXAMPLE); 27 | } 28 | 29 | @Test 30 | public void testMWDParserTalkerId() { 31 | MWDParser mwdp = new MWDParser(TalkerId.II); 32 | assertEquals(TalkerId.II, mwdp.getTalkerId()); 33 | assertEquals(SentenceId.MWD.toString(), mwdp.getSentenceId()); 34 | } 35 | 36 | @Test 37 | public void testGetMagneticWindDirection() { 38 | assertTrue(Double.isNaN(mwd.getMagneticWindDirection())); 39 | } 40 | 41 | @Test 42 | public void testGetTrueWindDirection() { 43 | assertEquals(295.19, mwd.getTrueWindDirection(), 0.1); 44 | } 45 | 46 | @Test 47 | public void testGetWindSpeed() { 48 | assertEquals(2.62, mwd.getWindSpeed(), 0.1); 49 | } 50 | 51 | @Test 52 | public void testGetWindSpeedKnots() { 53 | assertEquals(5.09, mwd.getWindSpeedKnots(), 0.1); 54 | } 55 | 56 | @Test 57 | public void testSetMagneticWindDirection() { 58 | mwd.setMagneticWindDirection(123.4); 59 | assertEquals(123.4, mwd.getMagneticWindDirection(), 0.1); 60 | } 61 | 62 | @Test 63 | public void testSetTrueWindDirection() { 64 | mwd.setTrueWindDirection(234.5); 65 | assertEquals(234.5, mwd.getTrueWindDirection(), 0.1); 66 | } 67 | 68 | @Test 69 | public void testSetWindSpeed() { 70 | mwd.setWindSpeed(12.3); 71 | assertEquals(12.3, mwd.getWindSpeed(), 0.1); 72 | } 73 | 74 | @Test 75 | public void testSetWindSpeedKnots() { 76 | mwd.setWindSpeedKnots(6.2); 77 | assertEquals(6.2, mwd.getWindSpeedKnots(), 0.1); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/HTDSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HTDSentence.java 3 | * Copyright (C) 2015 Paweł Kozioł, Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import net.sf.marineapi.nmea.util.DataStatus; 24 | 25 | /** 26 | * Heading/Track control systems data and commands. HTD provides output from a 27 | * heading controller with information about values, modes and references in 28 | * use, while HTC provides input to a heading controller to set values, modes 29 | * and references 30 | * [nuovamarea.com]. 31 | * 32 | * @author Paweł Kozioł 33 | * @see HTCSentence 34 | */ 35 | public interface HTDSentence extends HTCSentence, HeadingSentence { 36 | 37 | /** 38 | * Returns the rudder status. 39 | * 40 | * @return {@code DataStatus.ACTIVE} when within limits or 41 | * {@code DataStatus.VOID} when limit reached or exceeded. 42 | */ 43 | DataStatus getRudderStatus(); 44 | 45 | /** 46 | * Returns the off-heading status. 47 | * 48 | * @return {@code DataStatus.ACTIVE} when within limits or 49 | * {@code DataStatus.VOID} when limit reached or exceeded. 50 | */ 51 | DataStatus getOffHeadingStatus(); 52 | 53 | /** 54 | * Returns the off-track status. 55 | * 56 | * @return {@code DataStatus.ACTIVE} when within limits or 57 | * {@code DataStatus.VOID} when limit reached or exceeded. 58 | */ 59 | DataStatus getOffTrackStatus(); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/HDGSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HDGSentence.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Vessel heading with magnetic deviation and variation.

25 | * 26 | *

Example:
{@code $HCHDG,205.2,,,2.7,W}

27 | * 28 | * @author Kimmo Tuukkanen 29 | */ 30 | public interface HDGSentence extends HeadingSentence { 31 | 32 | /** 33 | * Get magnetic deviation. 34 | * 35 | * @return Deviation, in degrees. 36 | */ 37 | double getDeviation(); 38 | 39 | /** 40 | * Get magnetic variation. Returns negative values for easterly variation 41 | * and positive for westerly. 42 | * 43 | * @return Variation, in degrees. 44 | */ 45 | double getVariation(); 46 | 47 | /** 48 | * Set magnetic deviation. Provide negative values to set easterly deviation 49 | * and positive to set westerly. Sets also the correct direction indicator 50 | * according to value (East/West). 51 | * 52 | * @param deviation Deviation, in degrees. 53 | * @throws IllegalArgumentException If value is out of range [-180..180]. 54 | */ 55 | void setDeviation(double deviation); 56 | 57 | /** 58 | * Set magnetic variation. Provide negative values to set easterly variation 59 | * and positive to set westerly. Sets also the correct direction indicator 60 | * according to value (East/West). 61 | * 62 | * @param variation Variation, in degrees. 63 | * @throws IllegalArgumentException If value is out of range [-180..180]. 64 | */ 65 | void setVariation(double variation); 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/VHWSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * VHWSentence.java 3 | * Copyright (C) 2011 Warren Zahra, Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

Water speed and heading in respect to true and magnetic north.

25 | * 26 | *

Example:
{@code $IIVHW,,,213,M,0.00,N,,K*2F}

27 | * 28 | * @author Warren Zahra, Kimmo Tuukkanen 29 | */ 30 | public interface VHWSentence extends HeadingSentence { 31 | 32 | /** 33 | * Returns the current magnetic heading. 34 | * 35 | * @return Heading in degrees magnetic. 36 | */ 37 | double getMagneticHeading(); 38 | 39 | /** 40 | * Returns the current water speed. 41 | * 42 | * @return Speed in km/h (kilmetres per hour) 43 | */ 44 | double getSpeedKmh(); 45 | 46 | /** 47 | * Returns the current water speed. 48 | * 49 | * @return Speed in knots (nautical miles per hour) 50 | */ 51 | double getSpeedKnots(); 52 | 53 | /** 54 | * Sets the magnetic heading. 55 | * 56 | * @param hdg Heading in degrees magnetic. 57 | * @throws IllegalArgumentException If value is out of bounds [0..360] 58 | */ 59 | void setMagneticHeading(double hdg); 60 | 61 | /** 62 | * Sets the water speed in km/h. 63 | * 64 | * @param kmh Speed in kilmetres per hour. 65 | */ 66 | void setSpeedKmh(double kmh); 67 | 68 | /** 69 | * Sets the water speed in knots. 70 | * 71 | * @param knots Speed in knots (nautical miles per hour) 72 | */ 73 | void setSpeedKnots(double knots); 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/HDMParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HDMParser.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | import net.sf.marineapi.nmea.sentence.HDMSentence; 24 | import net.sf.marineapi.nmea.sentence.SentenceId; 25 | import net.sf.marineapi.nmea.sentence.TalkerId; 26 | 27 | /** 28 | * HDM sentence parser. 29 | * 30 | * @author Kimmo Tuukkanen 31 | */ 32 | class HDMParser extends SentenceParser implements HDMSentence { 33 | 34 | private static final int HEADING = 0; 35 | private static final int MAGN_INDICATOR = 1; 36 | 37 | /** 38 | * Creates a new HDM parser. 39 | * 40 | * @param nmea HDM sentence String 41 | */ 42 | public HDMParser(String nmea) { 43 | super(nmea, SentenceId.HDM); 44 | } 45 | 46 | /** 47 | * Creates a new empty HDM sentence. 48 | * 49 | * @param talker Talker id to set 50 | */ 51 | public HDMParser(TalkerId talker) { 52 | super(talker, SentenceId.HDM, 2); 53 | setCharValue(MAGN_INDICATOR, 'M'); 54 | } 55 | 56 | /* 57 | * (non-Javadoc) 58 | * @see net.sf.marineapi.nmea.sentence.HDMSentence#getHeading() 59 | */ 60 | public double getHeading() { 61 | return getDoubleValue(HEADING); 62 | } 63 | 64 | /* 65 | * (non-Javadoc) 66 | * @see net.sf.marineapi.nmea.sentence.HeadingSentence#isTrue() 67 | */ 68 | public boolean isTrue() { 69 | return false; 70 | } 71 | 72 | /* 73 | * (non-Javadoc) 74 | * @see net.sf.marineapi.nmea.sentence.HDMSentence#setHeading(double) 75 | */ 76 | public void setHeading(double hdm) { 77 | setDegreesValue(HEADING, hdm); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/sentence/SentenceIdTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SentenceIdTest.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import static org.junit.Assert.assertEquals; 24 | import static org.junit.Assert.fail; 25 | 26 | import org.junit.Test; 27 | 28 | /** 29 | * @author Kimmo Tuukkanen 30 | */ 31 | public class SentenceIdTest { 32 | 33 | @Test 34 | public void testParseKnownId() { 35 | SentenceId s = SentenceId.parse("$GPGLL,,,,,,,"); 36 | assertEquals(SentenceId.GLL, s); 37 | } 38 | 39 | @Test 40 | public void testParseUnknownId() { 41 | try { 42 | SentenceId.parse("$ABCDE,,,,,,"); 43 | fail("Did not throw exception"); 44 | } catch (Exception e) { 45 | // pass 46 | } 47 | } 48 | 49 | @Test 50 | public void testParseStrStandardId() { 51 | String s = SentenceId.parseStr("$GPGLL,,,,,,,"); 52 | assertEquals("GLL", s); 53 | } 54 | 55 | @Test 56 | public void testParseStrNormalLengthProprietaryId() { 57 | String s = SentenceId.parseStr("$PGRMZ,,,,,,,"); 58 | assertEquals("GRMZ", s); 59 | } 60 | 61 | @Test 62 | public void testParseStrShortProprietaryId() { 63 | String s = SentenceId.parseStr("$PBVE,,,,,,,"); 64 | assertEquals("BVE", s); 65 | } 66 | 67 | @Test 68 | public void testParseStrShortestPossibleProprietaryId() { 69 | String s = SentenceId.parseStr("$PAB,,,,,,,"); 70 | assertEquals("AB", s); 71 | } 72 | 73 | @Test 74 | public void testParseStrLongestPossibleProprietaryId() { 75 | String s = SentenceId.parseStr("$PABCDEFGHI,,,,,,,"); 76 | assertEquals("ABCDEFGHI", s); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/sentence/TalkerIdTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.sentence; 2 | 3 | /* 4 | * TalkerIdTest.java 5 | * Copyright (C) 2011 Kimmo Tuukkanen 6 | * 7 | * This file is part of Java Marine API. 8 | * 9 | * 10 | * Java Marine API is free software: you can redistribute it and/or modify it 11 | * under the terms of the GNU Lesser General Public License as published by the 12 | * Free Software Foundation, either version 3 of the License, or (at your 13 | * option) any later version. 14 | * 15 | * Java Marine API is distributed in the hope that it will be useful, but 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 18 | * for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with Java Marine API. If not, see . 22 | */ 23 | import static org.junit.Assert.assertEquals; 24 | import static org.junit.Assert.fail; 25 | 26 | import org.junit.Before; 27 | import org.junit.Test; 28 | 29 | /** 30 | * @author Kimmo Tuukkanen 31 | */ 32 | public class TalkerIdTest { 33 | 34 | /** 35 | * @throws java.lang.Exception 36 | */ 37 | @Before 38 | public void setUp() throws Exception { 39 | } 40 | 41 | /** 42 | * Test method for 43 | * {@link net.sf.marineapi.nmea.sentence.TalkerId#parse(java.lang.String)}. 44 | */ 45 | @Test 46 | public void testParse() { 47 | assertEquals(TalkerId.GP, TalkerId.parse("$GPGLL,,,,,,,")); 48 | assertEquals(TalkerId.GL, TalkerId.parse("$GLGSV,,,,,,,")); 49 | assertEquals(TalkerId.GN, TalkerId.parse("$GNGSV,,,,,,,")); 50 | assertEquals(TalkerId.II, TalkerId.parse("$IIDPT,,,,,,,")); 51 | } 52 | 53 | @Test 54 | public void testParseProprietary() { 55 | assertEquals(TalkerId.P, TalkerId.parse("$PRWIILOG,GGA,A,T,1,0")); 56 | } 57 | 58 | @Test 59 | public void testParseAIS() { 60 | assertEquals(TalkerId.AI, TalkerId.parse("!AIVDM,,,,,,,")); 61 | assertEquals(TalkerId.AB, TalkerId.parse("!ABVDM,,,,,,,")); 62 | assertEquals(TalkerId.BS, TalkerId.parse("!BSVDM,,,,,,,")); 63 | } 64 | 65 | @Test 66 | public void testParseUnknown() { 67 | try { 68 | TalkerId.parse("$XXXXX,,,,,,"); 69 | fail("Did not throw exception"); 70 | } catch (Exception e) { 71 | // pass 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/HDTParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HDTParser.java 3 | * Copyright (C) 2011 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | import net.sf.marineapi.nmea.sentence.HDTSentence; 24 | import net.sf.marineapi.nmea.sentence.SentenceId; 25 | import net.sf.marineapi.nmea.sentence.TalkerId; 26 | 27 | /** 28 | * HDT sentence parser. 29 | * 30 | * @author Kimmo Tuukkanen 31 | */ 32 | class HDTParser extends SentenceParser implements HDTSentence { 33 | 34 | private static final int HEADING = 0; 35 | private static final int TRUE_INDICATOR = 1; 36 | 37 | /** 38 | * Creates a new HDT parser. 39 | * 40 | * @param nmea HDT sentence String to parse. 41 | */ 42 | public HDTParser(String nmea) { 43 | super(nmea, SentenceId.HDT); 44 | } 45 | 46 | /** 47 | * Creates a new empty HDT sentence. 48 | * 49 | * @param talker Talker id to set 50 | */ 51 | public HDTParser(TalkerId talker) { 52 | super(talker, SentenceId.HDT, 2); 53 | setCharValue(TRUE_INDICATOR, 'T'); 54 | } 55 | 56 | /* 57 | * (non-Javadoc) 58 | * @see net.sf.marineapi.nmea.parser.HeadingSentence#getHeading() 59 | */ 60 | public double getHeading() { 61 | return getDoubleValue(HEADING); 62 | } 63 | 64 | /* 65 | * (non-Javadoc) 66 | * @see net.sf.marineapi.nmea.sentence.HeadingSentence#isTrue() 67 | */ 68 | public boolean isTrue() { 69 | return true; 70 | } 71 | 72 | /* 73 | * (non-Javadoc) 74 | * @see net.sf.marineapi.nmea.parser.HeadingSentence#setHeading(double) 75 | */ 76 | public void setHeading(double hdt) { 77 | setDegreesValue(HEADING, hdt); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/MTWParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MTWParser.java 3 | * Copyright (C) 2011 Warren Zahra 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | import net.sf.marineapi.nmea.sentence.MTWSentence; 24 | import net.sf.marineapi.nmea.sentence.SentenceId; 25 | import net.sf.marineapi.nmea.sentence.TalkerId; 26 | import net.sf.marineapi.nmea.util.Units; 27 | 28 | /** 29 | * MTW Sentence parser. 30 | * 31 | * @author Warren Zahra, Kimmo Tuukkanen 32 | */ 33 | class MTWParser extends SentenceParser implements MTWSentence { 34 | 35 | private static final int TEMPERATURE = 0; 36 | private static final int UNIT_INDICATOR = 1; 37 | 38 | /** 39 | * Creates new instance of MTWParser with specified sentence. 40 | * 41 | * @param nmea MTW sentence string 42 | */ 43 | public MTWParser(String nmea) { 44 | super(nmea); 45 | } 46 | 47 | /** 48 | * Creates new MTW parse without data. 49 | * 50 | * @param tid TalkerId to set 51 | */ 52 | public MTWParser(TalkerId tid) { 53 | super(tid, SentenceId.MTW, 2); 54 | setCharValue(UNIT_INDICATOR, Units.CELSIUS.toChar()); 55 | } 56 | 57 | /* 58 | * (non-Javadoc) 59 | * @see net.sf.marineapi.nmea.sentence.MTWSentence#getTemperature() 60 | */ 61 | public double getTemperature() { 62 | return getDoubleValue(TEMPERATURE); 63 | } 64 | 65 | /* 66 | * (non-Javadoc) 67 | * @see net.sf.marineapi.nmea.sentence.MTWSentence#setTemperature(double) 68 | */ 69 | public void setTemperature(double temp) { 70 | setDoubleValue(TEMPERATURE, temp, 1, 2); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/message/AISMessage19.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AISMessage19.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.message; 22 | 23 | /** 24 | * Extended Class B Equipment Position Report. 25 | * 26 | * @author Lázár József 27 | */ 28 | public interface AISMessage19 extends AISPositionReportB { 29 | 30 | /** 31 | * Returns the name of the transmitting ship. 32 | * 33 | * @return maximum 20 characters, representing the name 34 | */ 35 | String getName(); 36 | 37 | /** 38 | * Returns the type of ship and cargo. 39 | * 40 | * @return an integer value representing the type of ship and cargo 41 | */ 42 | int getTypeOfShipAndCargoType(); 43 | 44 | /** 45 | * Returns the distance from the reference point to the bow. 46 | * 47 | * @return Distance to bow, in meters. 48 | */ 49 | int getBow(); 50 | 51 | /** 52 | * Returns the distance from the reference point to the stern of the ship. 53 | * 54 | * @return Distance to stern, in meters. 55 | */ 56 | int getStern(); 57 | 58 | /** 59 | * Returns the distance from the reference point to the port side of the 60 | * ship. 61 | * 62 | * @return Distance to port side, in meters. 63 | */ 64 | int getPort(); 65 | 66 | /** 67 | * Returns the distance from the reference point to the starboard side of 68 | * the ship. 69 | * 70 | * @return Distance to starboard side, in meters. 71 | */ 72 | int getStarboard(); 73 | 74 | /** 75 | * Returns the type of electronic position fixing device. 76 | * 77 | * @return an integer value the the type of EPFD 78 | */ 79 | int getTypeOfEPFD(); 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/RSASentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * RSASentence.java 3 | * Copyright (C) 2014 Lázár József, Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import net.sf.marineapi.nmea.util.DataStatus; 24 | import net.sf.marineapi.nmea.util.Side; 25 | 26 | /** 27 | *

28 | * Rudder angle, measured in degrees. Negative value represents port side, 29 | * positive starboard side turn. May contain value for both port and starboard 30 | * rudder. {@link Side#PORT} is used for vessels with single rudder. 31 | *

32 | *

33 | * Example:
34 | * {@code $IIRSA,9,A,,*38} 35 | *

36 | * 37 | * @author Lázár József, Kimmo Tuukkanen 38 | */ 39 | public interface RSASentence extends Sentence { 40 | 41 | /** 42 | * Returns the rudder angle for specified side. 43 | * 44 | * @param side Rudder side 45 | * @return Rudder angle in degrees. 46 | */ 47 | double getRudderAngle(Side side); 48 | 49 | /** 50 | * Sets the rudder's angle for specified side. 51 | * 52 | * @param side Rudder side 53 | * @param angle Rudder angle in degrees 54 | */ 55 | void setRudderAngle(Side side, double angle); 56 | 57 | /** 58 | * Returns the data status (valid/invalid) for specified side. 59 | * 60 | * @param side Rudder side 61 | * @return Data status 62 | */ 63 | DataStatus getStatus(Side side); 64 | 65 | /** 66 | * Set data status for specified side. 67 | * @param side Rudder side 68 | * @param status Data status to set 69 | */ 70 | void setStatus(Side side, DataStatus status); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/STALKSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * STALKSentence.java 3 | * Copyright (C) 2017 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | /** 24 | *

25 | * Raymarine/Autohelm SeaTalk sentence. See 26 | * SeaTalk Technical Reference 27 | * by Thomas Knauf for more information on the protocol. 28 | *

29 | * 30 | *

Example:
31 | * {@code $STALK,52,A1,00,00*36} 32 | *

33 | * 34 | * @author Kimmo Tuukkanen 35 | */ 36 | public interface STALKSentence extends Sentence { 37 | 38 | /** 39 | * Add given parameter in sentence. Sentence field count is increased by one 40 | * field, notice that adding too many fields may result in invalid sentence. 41 | * 42 | * @param param Hex parameter to add 43 | */ 44 | void addParameter(String param); 45 | 46 | /** 47 | * Returns the SeaTalk command / datagram type. 48 | * 49 | * @return Command String, "00", "01", "02" etc. 50 | */ 51 | String getCommand(); 52 | 53 | /** 54 | * Sets the SeaTalk command / datagram type. 55 | * 56 | * @param cmd Command String, "00", "01", "02" etc. 57 | */ 58 | void setCommand(String cmd); 59 | 60 | /** 61 | * Returns the datagram payload. 62 | * 63 | * @return Parameters array containing hex values. 64 | */ 65 | String[] getParameters(); 66 | 67 | /** 68 | * Sets the datagram payload. 69 | * 70 | * @param params Parameters array containing hex Strings. 71 | */ 72 | void setParameters(String... params); 73 | } -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/Units.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Units.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * Defines the supported units of measure. 25 | * 26 | * @author Kimmo Tuukkanen 27 | * 28 | */ 29 | public enum Units { 30 | 31 | /** Pressure in bars */ 32 | BARS('B'), 33 | 34 | /** Temperature in degrees Celsius (centigrade) */ 35 | CELSIUS('C'), 36 | 37 | /** Depth in fathoms */ 38 | FATHOMS('F'), 39 | 40 | /** Length in feet */ 41 | FEET('f'), 42 | 43 | /** Distance/pressure in inches */ 44 | INCHES('I'), 45 | 46 | /** Kilometers - used for distance, and speed (as kilometers per hour) */ 47 | KILOMETERS('K'), 48 | 49 | /** Length in meter */ 50 | METER('M'), 51 | 52 | /** Nautical miles - used for distance, and for speed (nautical miles per hour, which are knots) */ 53 | NAUTICAL_MILES('N'), 54 | 55 | /** Statute miles - used for distance, and for speed (as miles per hour/mph) */ 56 | STATUTE_MILES('S'); 57 | 58 | private char ch; 59 | 60 | private Units(char c) { 61 | ch = c; 62 | } 63 | 64 | /** 65 | * Returns the corresponding char constant. 66 | * 67 | * @return Char indicator of enum 68 | */ 69 | public char toChar() { 70 | return ch; 71 | } 72 | 73 | /** 74 | * Get the enum corresponding to specified char. 75 | * 76 | * @param ch Char indicator for unit 77 | * @return Units enum 78 | */ 79 | public static Units valueOf(char ch) { 80 | for (Units u : values()) { 81 | if (u.toChar() == ch) { 82 | return u; 83 | } 84 | } 85 | return valueOf(String.valueOf(ch)); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/util/UbloxNavigationStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Gunnar Hillert 3 | * 4 | * This file is part of Java Marine API. 5 | * 6 | * 7 | * Java Marine API is free software: you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by the 9 | * Free Software Foundation, either version 3 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * Java Marine API is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with Java Marine API. If not, see . 19 | */ 20 | package net.sf.marineapi.ublox.util; 21 | 22 | /** 23 | * 24 | * @author Gunnar Hillert 25 | * 26 | */ 27 | public enum UbloxNavigationStatus { 28 | 29 | /** 30 | * No Fix. 31 | */ 32 | NO_FIX("NF"), 33 | 34 | /** 35 | * Dead reckoning only solution. 36 | */ 37 | DEAD_RECKONING_ONLY ("DR"), 38 | 39 | /** 40 | * Stand alone 2D solution. 41 | */ 42 | STAND_ALONE_2D("G2"), 43 | 44 | /** 45 | * Stand alone 3D solution. 46 | */ 47 | STAND_ALONE_3D("G3"), 48 | 49 | /** 50 | * Differential 2D solution. 51 | */ 52 | DIFFERENTIAL_2D_SOLUTION("D2"), 53 | 54 | /** 55 | * Differential 3D solution. 56 | */ 57 | DIFFERENTIAL_3D_SOLUTION("D3"), 58 | 59 | /** 60 | * Combined GPS + dead reckoning solution. 61 | */ 62 | COMBINED_GPS_AND_DEAD_RECKONING ("RK"), 63 | 64 | /** 65 | * Time only solution. 66 | */ 67 | TIME_ONLY("TT"); 68 | 69 | 70 | private String navigationStatusCode; 71 | 72 | private UbloxNavigationStatus(String navigationStatusCode) { 73 | this.navigationStatusCode = navigationStatusCode; 74 | } 75 | 76 | public String getNavigationStatusCode() { 77 | return navigationStatusCode; 78 | } 79 | 80 | public static UbloxNavigationStatus fromNavigationStatusCode(String navigationStatusCode) { 81 | 82 | for (UbloxNavigationStatus ubloxNavigationStatus : UbloxNavigationStatus.values()) { 83 | if (ubloxNavigationStatus.getNavigationStatusCode().equals(navigationStatusCode)) { 84 | return ubloxNavigationStatus; 85 | } 86 | } 87 | 88 | return null; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/nmea/parser/RSATest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.nmea.parser; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import net.sf.marineapi.nmea.sentence.RSASentence; 5 | import net.sf.marineapi.nmea.sentence.SentenceId; 6 | import net.sf.marineapi.nmea.sentence.TalkerId; 7 | import net.sf.marineapi.nmea.util.DataStatus; 8 | import net.sf.marineapi.nmea.util.Side; 9 | 10 | import org.junit.Before; 11 | import org.junit.Test; 12 | 13 | public class RSATest { 14 | 15 | public static final String EXAMPLE = "$IIRSA,1.2,A,2.3,V"; 16 | 17 | RSASentence empty; 18 | RSASentence instance; 19 | 20 | @Before 21 | public void setUp() throws Exception { 22 | empty = new RSAParser(TalkerId.II); 23 | instance = new RSAParser(EXAMPLE); 24 | } 25 | 26 | @Test 27 | public void testRSAParserString() { 28 | assertEquals(TalkerId.II, instance.getTalkerId()); 29 | assertEquals(SentenceId.RSA.name(), instance.getSentenceId()); 30 | } 31 | 32 | @Test 33 | public void testRSAParserTalkerId() { 34 | assertEquals(TalkerId.II, empty.getTalkerId()); 35 | assertEquals(SentenceId.RSA.name(), empty.getSentenceId()); 36 | assertEquals(DataStatus.VOID, empty.getStatus(Side.STARBOARD)); 37 | assertEquals(DataStatus.VOID, empty.getStatus(Side.PORT)); 38 | } 39 | 40 | @Test 41 | public void testGetRudderAngle() { 42 | assertEquals(1.2, instance.getRudderAngle(Side.STARBOARD), 0.1); 43 | assertEquals(2.3, instance.getRudderAngle(Side.PORT), 0.1); 44 | } 45 | 46 | @Test 47 | public void testSetRudderAngle() { 48 | final double portAngle = 4.5; 49 | final double starboardAngle = 5.6; 50 | instance.setRudderAngle(Side.PORT, portAngle); 51 | instance.setRudderAngle(Side.STARBOARD, starboardAngle); 52 | assertEquals(portAngle, instance.getRudderAngle(Side.PORT), 0.1); 53 | assertEquals(starboardAngle, instance.getRudderAngle(Side.STARBOARD), 0.1); 54 | } 55 | 56 | @Test 57 | public void testGetStatus() { 58 | assertEquals(DataStatus.ACTIVE, instance.getStatus(Side.STARBOARD)); 59 | assertEquals(DataStatus.VOID, instance.getStatus(Side.PORT)); 60 | } 61 | 62 | @Test 63 | public void testSetStatusPort() { 64 | empty.setStatus(Side.PORT, DataStatus.ACTIVE); 65 | assertEquals(DataStatus.ACTIVE, empty.getStatus(Side.PORT)); 66 | } 67 | 68 | @Test 69 | public void testSetStatusStarboard() { 70 | empty.setStatus(Side.STARBOARD, DataStatus.ACTIVE); 71 | assertEquals(DataStatus.ACTIVE, empty.getStatus(Side.STARBOARD)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/provider/event/HeadingEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * HeadingEvent.java 3 | * Copyright (C) 2012 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.provider.event; 22 | 23 | import net.sf.marineapi.nmea.sentence.HeadingSentence; 24 | 25 | /** 26 | * HeadingProvider event, reports the current magnetic/true heading of vessel in 27 | * degrees. 28 | * 29 | * @author Kimmo Tuukkanen 30 | * @see net.sf.marineapi.provider.HeadingProvider 31 | */ 32 | public class HeadingEvent extends ProviderEvent { 33 | 34 | private static final long serialVersionUID = 5706774741081575448L; 35 | private double heading; 36 | private boolean isTrue; 37 | 38 | /** 39 | * Creates a new heading event. 40 | * 41 | * @param source The object that sends the event. 42 | * @param s HeadingSentence that triggered the event. 43 | */ 44 | public HeadingEvent(Object source, HeadingSentence s) { 45 | super(source); 46 | heading = s.getHeading(); 47 | isTrue = s.isTrue(); 48 | } 49 | 50 | /** 51 | * Returns the current heading. 52 | * 53 | * @return Heading in degrees. 54 | */ 55 | public double getHeading() { 56 | return heading; 57 | } 58 | 59 | /** 60 | * Tells if the heading is relative to true or magnetic north. 61 | * 62 | * @return true if true heading, otherwise false (magnetic). 63 | */ 64 | public boolean isTrue() { 65 | return isTrue; 66 | } 67 | 68 | /* 69 | * (non-Javadoc) 70 | * @see java.util.EventObject#toString() 71 | */ 72 | public String toString() { 73 | return "[" + getHeading() + ", " + (isTrue() ? "T" : "M") + "]"; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/event/SentenceEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SentenceEvent.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.event; 22 | 23 | import java.util.EventObject; 24 | 25 | import net.sf.marineapi.nmea.sentence.Sentence; 26 | 27 | /** 28 | * Sentence events occur when a valid NMEA 0183 sentence has been read from the 29 | * data source. 30 | * 31 | * @author Kimmo Tuukkanen 32 | * @see SentenceListener 33 | * @see net.sf.marineapi.nmea.io.SentenceReader 34 | */ 35 | public class SentenceEvent extends EventObject { 36 | 37 | private static final long serialVersionUID = -2756954014186470514L; 38 | private final long timestamp = System.currentTimeMillis(); 39 | private final Sentence sentence; 40 | 41 | /** 42 | * Creates a new SentenceEvent object. 43 | * 44 | * @param src Object that fired the event 45 | * @param s Sentence that triggered the event 46 | * @throws IllegalArgumentException If specified sentence is {@code null} 47 | */ 48 | public SentenceEvent(Object src, Sentence s) { 49 | super(src); 50 | if (s == null) { 51 | throw new IllegalArgumentException("Sentence cannot be null"); 52 | } 53 | this.sentence = s; 54 | } 55 | 56 | /** 57 | * Gets the Sentence object that triggered the event. 58 | * 59 | * @return Sentence object 60 | */ 61 | public Sentence getSentence() { 62 | return sentence; 63 | } 64 | 65 | /** 66 | * Get system time when this event was created. 67 | * 68 | * @return Milliseconds timestamp 69 | */ 70 | public long getTimeStamp() { 71 | return timestamp; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/util/MMSI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MMSI.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.util; 22 | 23 | /** 24 | * Checks an MMSI value for validity. 25 | * 26 | * @author Lázár József 27 | */ 28 | public class MMSI { 29 | 30 | private static final long MINVALUE = 0; 31 | private static final long MAXVALUE = 999999999; 32 | 33 | /** 34 | * Checks whether the MMSI value is correct, i.e. within valid range. 35 | * 36 | * @param value MMSI value to check 37 | * @return true if the value is semantically correct. 38 | */ 39 | public static boolean isCorrect(long value) { 40 | return (MINVALUE <= value) && (value <= MAXVALUE); 41 | } 42 | 43 | /** 44 | * Returns the origin associated with the MMSI number. 45 | * 46 | * @param value MMSI value to stringify 47 | * @return A String describing the region of the transmitter 48 | */ 49 | public static String toString(long value) { 50 | int firstDigit = (int)(value / 100000000L); 51 | switch (firstDigit) { 52 | case 0: 53 | return "Ship group, coast station, or group of coast stations"; 54 | case 1: 55 | return "SAR aircraft"; 56 | case 2: 57 | return "Europe"; 58 | case 3: 59 | return "North and Central America and Caribbean"; 60 | case 4: 61 | return "Asia"; 62 | case 5: 63 | return "Oceana"; 64 | case 6: 65 | return "Africa"; 66 | case 7: 67 | return "South America"; 68 | case 8: 69 | return "Assigned for regional Use"; 70 | case 9: 71 | return "Nav aids or craft associated with a parent ship"; 72 | default: 73 | return "Invalid MMSI number"; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/util/GpsFixQuality.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GpsFixQuality.java 3 | * Copyright (C) 2010 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.util; 22 | 23 | /** 24 | * GpsFixQuality defines the supported fix quality types. 25 | * 26 | * @author Kimmo Tuukkanen 27 | * @see FaaMode 28 | * @see GpsFixStatus 29 | * @see DataStatus 30 | */ 31 | public enum GpsFixQuality { 32 | 33 | /** No GPS fix acquired. */ 34 | INVALID(0), 35 | 36 | /** Normal GPS fix, Standard Position Service (SPS). */ 37 | NORMAL(1), 38 | 39 | /** Differential GPS fix. */ 40 | DGPS(2), 41 | 42 | /** Precise Positioning Service fix. */ 43 | PPS(3), 44 | 45 | /** Real Time Kinematic */ 46 | RTK(4), 47 | 48 | /** Float RTK */ 49 | FRTK(5), 50 | 51 | /** Estimated, dead reckoning (2.3 feature) */ 52 | ESTIMATED(6), 53 | 54 | /** Manual input mode */ 55 | MANUAL(7), 56 | 57 | /** Simulation mode */ 58 | SIMULATED(8); 59 | 60 | private final int value; 61 | 62 | GpsFixQuality(int intValue) { 63 | value = intValue; 64 | } 65 | 66 | /** 67 | * Returns the corresponding int indicator for fix quality. 68 | * 69 | * @return Fix quality indicator value as indicated in sentences. 70 | */ 71 | public int toInt() { 72 | return value; 73 | } 74 | 75 | /** 76 | * Get GpsFixQuality enum that corresponds the actual integer identifier 77 | * used in the sentences. 78 | * 79 | * @param val Status identifier value 80 | * @return GpsFixQuality enum 81 | */ 82 | public static GpsFixQuality valueOf(int val) { 83 | for (GpsFixQuality gfq : values()) { 84 | if (gfq.toInt() == val) { 85 | return gfq; 86 | } 87 | } 88 | return valueOf(String.valueOf(val)); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ublox/util/UbloxSatelliteInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Gunnar Hillert 3 | * 4 | * This file is part of Java Marine API. 5 | * 6 | * 7 | * Java Marine API is free software: you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as published by the 9 | * Free Software Foundation, either version 3 of the License, or (at your 10 | * option) any later version. 11 | * 12 | * Java Marine API is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 | * for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with Java Marine API. If not, see . 19 | */ 20 | package net.sf.marineapi.ublox.util; 21 | 22 | import net.sf.marineapi.nmea.util.SatelliteInfo; 23 | import net.sf.marineapi.ublox.message.UBXMessage03; 24 | 25 | /** 26 | * Extends {@link SatelliteInfo} to provide additional properties supported by 27 | * the proprietary u-blox NMEA extension {@link UBXMessage03}. 28 | * 29 | * @author Gunnar Hillert 30 | * 31 | */ 32 | public class UbloxSatelliteInfo extends SatelliteInfo { 33 | 34 | private final UbloxSatelliteStatus satelliteStatus; 35 | 36 | private final int satelliteCarrierLockTime; 37 | 38 | public UbloxSatelliteInfo(String id, int elevation, int azimuth, int noise, 39 | UbloxSatelliteStatus satelliteStatus, int satelliteCarrierLockTime) { 40 | super(id, elevation, azimuth, noise); 41 | this.satelliteStatus = satelliteStatus; 42 | this.satelliteCarrierLockTime = satelliteCarrierLockTime; 43 | } 44 | 45 | /** 46 | * Satellite carrier lock time (range: 0-64) 47 | * 48 | *
    49 | *
  • 0 = code lock only 50 | *
  • 64 = lock for 64 seconds or more 51 | *
52 | * 53 | * @return Numeric value 0-64 54 | */ 55 | public int getSatelliteCarrierLockTime() { 56 | return satelliteCarrierLockTime; 57 | } 58 | 59 | /** 60 | * @return The {@link UbloxSatelliteStatus}. 61 | */ 62 | public UbloxSatelliteStatus getSatelliteStatus() { 63 | return satelliteStatus; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return super.toString() + " " + 69 | String.format("UbloxSatelliteInfo [satelliteStatus=%s, satelliteCarrierLockTime=%s sec]", satelliteStatus, 70 | satelliteCarrierLockTime); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/ais/parser/AISPositionReportBParserTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.ais.parser; 2 | 3 | import net.sf.marineapi.ais.message.AISPositionReportB; 4 | import net.sf.marineapi.ais.util.Sixbit; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | /** 10 | * AIS position report "type B" tests, covering parsers 18 and 19. 11 | * 12 | * TODO: missing getters for "Class B" flags 13 - 20. 13 | * 14 | * Expected values based on http://www.maritec.co.za/tools/aisvdmvdodecoding/ 15 | */ 16 | public class AISPositionReportBParserTest { 17 | 18 | // !AIVDM,1,1,,A,B6CdCm0t3`tba35f@V9faHi7kP06,0*58 19 | private final String payload = "B6CdCm0t3`tba35f@V9faHi7kP06"; 20 | private final Sixbit sixbit = new Sixbit(payload, 0); 21 | private final AISPositionReportB msg = new AISPositionReportBParser(sixbit); 22 | 23 | @Test 24 | public void getSpeedOverGround() throws Exception { 25 | assertEquals(1.4, msg.getSpeedOverGround(), 0.1); 26 | } 27 | 28 | @Test 29 | public void getPositionAccuracy() throws Exception { 30 | assertEquals(false, msg.isAccurate()); 31 | } 32 | 33 | @Test 34 | public void getLongitudeInDegrees() throws Exception { 35 | assertEquals(53.010996667, msg.getLongitudeInDegrees(), 0.000000001); 36 | } 37 | 38 | @Test 39 | public void getLatitudeInDegrees() throws Exception { 40 | assertEquals(40.005283333, msg.getLatitudeInDegrees(), 0.000000001); 41 | } 42 | 43 | @Test 44 | public void getCourseOverGround() throws Exception { 45 | assertEquals(177.0, msg.getCourseOverGround(), 0.1); 46 | } 47 | 48 | @Test 49 | public void getTrueHeading() throws Exception { 50 | assertEquals(177.0, msg.getTrueHeading(), 0.1); 51 | } 52 | 53 | @Test 54 | public void getTimeStamp() throws Exception { 55 | assertEquals(34, msg.getTimeStamp()); 56 | } 57 | 58 | @Test 59 | public void hasLatitude() { 60 | assertEquals(true, msg.hasLatitude()); 61 | } 62 | 63 | @Test 64 | public void hasLongitude() { 65 | assertEquals(true, msg.hasLongitude()); 66 | } 67 | 68 | @Test 69 | public void hasCourseOverGround() { 70 | assertEquals(true, msg.hasCourseOverGround()); 71 | } 72 | 73 | @Test 74 | public void hasSpeedOverGround() { 75 | assertEquals(true, msg.hasSpeedOverGround()); 76 | } 77 | 78 | @Test 79 | public void hasTimeStamp() { 80 | assertEquals(true, msg.hasTimeStamp()); 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /src/test/java/net/sf/marineapi/ais/parser/AISMessageFactoryTest.java: -------------------------------------------------------------------------------- 1 | package net.sf.marineapi.ais.parser; 2 | 3 | import net.sf.marineapi.ais.message.AISMessage; 4 | import net.sf.marineapi.ais.message.AISMessage01; 5 | import net.sf.marineapi.ais.message.AISMessage05; 6 | import net.sf.marineapi.nmea.parser.SentenceFactory; 7 | import net.sf.marineapi.nmea.sentence.AISSentence; 8 | 9 | import org.junit.Test; 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Test AISMessageFactory 14 | */ 15 | public class AISMessageFactoryTest { 16 | 17 | private final SentenceFactory sf = SentenceFactory.getInstance(); 18 | private final AISMessageFactory amf = AISMessageFactory.getInstance(); 19 | 20 | private String s1 = "!AIVDM,1,1,,A,13aEOK?P00PD2wVMdLDRhgvL289?,0*26"; 21 | private String s2_1 = "!AIVDM,2,1,9,B,53nFBv01SJ 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.util; 22 | 23 | /** 24 | * Checks the navigational status for validity. 25 | * 26 | * @author Lázár József 27 | */ 28 | public class NavigationalStatus { 29 | 30 | /** Valid range */ 31 | public static final String RANGE = "[0,8] + [14,15]"; 32 | final static private String[] VALUES = { 33 | "under way using engine", // 0 34 | "at anchor", // 1 35 | "not under command", // 2 36 | "restricted manoeuvrability", // 3 37 | "constrained by her draught", // 4 38 | "moored", // 5 39 | "aground", // 6 40 | "engaged in fishing", // 7 41 | "under way sailing", // 8 42 | "reserved for future amendment", // 9 43 | "reserved for future amendment", //10 44 | "reserved for future use", //11 45 | "reserved for future use", //12 46 | "reserved for future use", //13 47 | "AIS-SART (active)", //14 48 | "not defined" //15 49 | }; 50 | 51 | /** 52 | * Returns the String representing the given status. 53 | * 54 | * @param value Navigational status value to stringify. 55 | * @return text string describing the navigational status 56 | */ 57 | public static String toString(int value) { 58 | if (value >= 0 && value <=15) 59 | return VALUES[value]; 60 | else 61 | return VALUES[15]; 62 | } 63 | 64 | /** 65 | * Checks if the given status value is correct. 66 | * 67 | * @param value Navigational status value to check 68 | * @return true if the status falls within the range 69 | */ 70 | public static boolean isCorrect(int value) { 71 | return (0 <= value) && (value <= 15) && 72 | !((9 <= value) && (value <= 13)); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/parser/MMBParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MMBParser.java 3 | * Copyright (C) 2016 Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.parser; 22 | 23 | import net.sf.marineapi.nmea.sentence.MMBSentence; 24 | import net.sf.marineapi.nmea.sentence.SentenceId; 25 | import net.sf.marineapi.nmea.sentence.TalkerId; 26 | 27 | /** 28 | * MMBParser - Barometer. 29 | * 30 | * {@code $--MMB,x.x,I,x.x,B*hh} 31 | * 32 | * @author Kimmo Tuukkanen 33 | */ 34 | class MMBParser extends SentenceParser implements MMBSentence { 35 | 36 | private static final int PRESSURE_INHG = 0; 37 | private static final int UNIT_INHG = 1; 38 | private static final int PRESSURE_BARS = 2; 39 | private static final int UNIT_BARS = 3; 40 | 41 | /** 42 | * Constructor for parsing MMB. 43 | * 44 | * @param nmea MMB sentence String. 45 | */ 46 | public MMBParser(String nmea) { 47 | super(nmea, SentenceId.MMB); 48 | } 49 | 50 | /** 51 | * Constructs a fresh MMB parser. 52 | * 53 | * @param tid TalkerId to use in sentence. 54 | */ 55 | public MMBParser(TalkerId tid) { 56 | super(tid, SentenceId.MMB, 4); 57 | setCharValue(UNIT_INHG, 'I'); 58 | setCharValue(UNIT_BARS, 'B'); 59 | } 60 | 61 | @Override 62 | public double getInchesOfMercury() { 63 | return getDoubleValue(PRESSURE_INHG); 64 | } 65 | 66 | @Override 67 | public double getBars() { 68 | return getDoubleValue(PRESSURE_BARS); 69 | } 70 | 71 | @Override 72 | public void setInchesOfMercury(double inHg) { 73 | setDoubleValue(PRESSURE_INHG, inHg); 74 | } 75 | 76 | @Override 77 | public void setBars(double bars) { 78 | setDoubleValue(PRESSURE_BARS, bars); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/ais/util/ManeuverIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ManeuverIndicator.java 3 | * Copyright (C) 2015 Lázár József 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.ais.util; 22 | 23 | /** 24 | * Checks a 2-bit signed integer maneuver value for validity. 25 | * 26 | * @author Lázár József 27 | */ 28 | public class ManeuverIndicator { 29 | 30 | private static final int DEFAULTVALUE = 0; 31 | private static final int MINVALUE = 1 ; 32 | private static final int MAXVALUE = 2; 33 | 34 | /** Valid range with default value for "no value" */ 35 | public static final String RANGE = 36 | "[" + MINVALUE + "," + MAXVALUE + "] + {" + DEFAULTVALUE + "}"; 37 | 38 | /** 39 | * Checks if the value is in the correct range. 40 | * 41 | * @param value Int value to check 42 | * @return true if the value is correct 43 | */ 44 | public static boolean isCorrect(int value) { 45 | return (MINVALUE <= value && value <= MAXVALUE) || (value == DEFAULTVALUE); 46 | } 47 | 48 | /** 49 | * Checks if the maneuver value is available. 50 | * 51 | * @param value Int value to check 52 | * @return true if the value is not the default value 53 | */ 54 | public static boolean isAvailable(int value) { 55 | return value != DEFAULTVALUE; 56 | } 57 | 58 | /** 59 | * Rerturns the string representation of given int value. 60 | * 61 | * @param value Value to stringify 62 | * @return a string representing the maneuvre indicator value 63 | */ 64 | public static String toString(int value) { 65 | switch (value) { 66 | case 0: 67 | return "no special maneuver indicator"; 68 | case 1: 69 | return "not in special maneuver"; 70 | case 2: 71 | return "in special maneuver"; 72 | default: 73 | return "invalid special maneuver indicator"; 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /src/main/java/net/sf/marineapi/nmea/sentence/XDRSentence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * XDRSentence.java 3 | * Copyright (C) 2013 Robert Huitema, Kimmo Tuukkanen 4 | * 5 | * This file is part of Java Marine API. 6 | * 7 | * 8 | * Java Marine API is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU Lesser General Public License as published by the 10 | * Free Software Foundation, either version 3 of the License, or (at your 11 | * option) any later version. 12 | * 13 | * Java Marine API is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 16 | * for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with Java Marine API. If not, see . 20 | */ 21 | package net.sf.marineapi.nmea.sentence; 22 | 23 | import java.util.List; 24 | 25 | import net.sf.marineapi.nmea.util.Measurement; 26 | 27 | /** 28 | *

29 | * Transducer measurements. Measurements are delivered in sets containing four 30 | * fields; transducer type, measurement value, unit of measurement and 31 | * transducer name. There may be any number of sets like this, each describing a 32 | * sensor. Notice that inserting too many measuments in one sentence may result 33 | * in exceeding the maximum sentence length (82 chars). 34 | * 35 | * @see net.sf.marineapi.nmea.util.Measurement 36 | * @author Robert Huitema, Kimmo Tuukkanen 37 | */ 38 | public interface XDRSentence extends Sentence { 39 | 40 | /** 41 | * Adds specified measurement in sentence placing it last. Multiple 42 | * measurements are inserted in given order. 43 | * 44 | * @param m Measurements to add. 45 | */ 46 | void addMeasurement(Measurement... m); 47 | 48 | /** 49 | * Returns all measurements. 50 | * 51 | * @return List of measurements, ordered as they appear in sentence. 52 | */ 53 | List getMeasurements(); 54 | 55 | /** 56 | * Set single measurement. Overwrites all existing values and adjusts the 57 | * number of data fields to minimum required by one measurement (4). 58 | * 59 | * @param m Measurement to set. 60 | */ 61 | void setMeasurement(Measurement m); 62 | 63 | /** 64 | * Set multiple measurements in given order. Overwrites all existing values 65 | * and adjusts the number of data fields as required by given measurements. 66 | * 67 | * @param measurements List of measurements to set. 68 | */ 69 | void setMeasurements(List measurements); 70 | } 71 | --------------------------------------------------------------------------------