DataStreamRecord.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.gnss.metric.ntrip;

  18. import java.util.ArrayList;
  19. import java.util.List;
  20. import java.util.regex.Matcher;
  21. import java.util.regex.Pattern;
  22. import java.util.stream.Collectors;
  23. import java.util.stream.Stream;

  24. import org.hipparchus.util.FastMath;

  25. /** Data stream record in source table.
  26.  * @author Luc Maisonobe
  27.  * @since 11.0
  28.  */
  29. public class DataStreamRecord extends Record {

  30.     /** Pattern for delimiting messages. */
  31.     private static final Pattern SEPARATOR = Pattern.compile(",");

  32.     /** Message pattern. */
  33.     private static final Pattern PATTERN = Pattern.compile("^([^()]+)(?:\\(([0-9]+)\\))?$");

  34.     /** Data format. */
  35.     private final DataFormat format;

  36.     /** Streamed messages. */
  37.     private final List<StreamedMessage> formatDetails;

  38.     /** Carrier phase. */
  39.     private final CarrierPhase carrierPhase;

  40.     /** Navigation systems. */
  41.     private final List<NavigationSystem> systems;

  42.     /** Latitude (rad). */
  43.     private final double latitude;

  44.     /** Longitude (rad). */
  45.     private final double longitude;

  46.     /** Indicator for required NMEA. */
  47.     private final boolean nmeaRequired;

  48.     /** Indicator for networked streams. */
  49.     private final boolean networked;

  50.     /** Authentication method. */
  51.     private final Authentication authentication;

  52.     /** Indicator for required fees. */
  53.     private final boolean fees;

  54.     /** Bit rate. */
  55.     private int bitRate;

  56.     /** Build a data stream record by parsing a source table line.
  57.      * @param line source table line
  58.      */
  59.     public DataStreamRecord(final String line) {
  60.         super(line);
  61.         this.format         = DataFormat.getDataFormat(getField(3));

  62.         final String[] detailsFields = SEPARATOR.split(getField(4));
  63.         this.formatDetails           = new ArrayList<>(detailsFields.length);
  64.         for (final String field : detailsFields) {
  65.             if (!field.isEmpty()) {
  66.                 final Matcher matcher = PATTERN.matcher(field);
  67.                 if (matcher.matches() && matcher.start(2) >= 0) {
  68.                     formatDetails.add(new StreamedMessage(matcher.group(1),
  69.                                                           Integer.parseInt(matcher.group(2))));
  70.                 } else {
  71.                     formatDetails.add(new StreamedMessage(field, -1));
  72.                 }
  73.             }
  74.         }

  75.         this.carrierPhase   = CarrierPhase.getCarrierPhase(getField(5));
  76.         this.systems        = Stream.
  77.                               of(getField(6).split("\\+")).
  78.                               map(NavigationSystem::getNavigationSystem).
  79.                               collect(Collectors.toList());
  80.         this.latitude       = FastMath.toRadians(Double.parseDouble(getField(9)));
  81.         this.longitude      = FastMath.toRadians(Double.parseDouble(getField(10)));
  82.         this.nmeaRequired   = Integer.parseInt(getField(11)) != 0;
  83.         this.networked      = Integer.parseInt(getField(12)) != 0;
  84.         this.authentication = Authentication.getAuthentication(getField(15));
  85.         this.fees           = getField(16).equals("Y");
  86.         this.bitRate        = Integer.parseInt(getField(17));
  87.     }

  88.     /** {@inheritDoc} */
  89.     @Override
  90.     public RecordType getRecordType() {
  91.         return RecordType.STR;
  92.     }

  93.     /** Get the mount point.
  94.      * @return mount point
  95.      */
  96.     public String getMountPoint() {
  97.         return getField(1);
  98.     }

  99.     /** Get the source identifier.
  100.      * @return source identifier
  101.      */
  102.     public String getSourceIdentifier() {
  103.         return getField(2);
  104.     }

  105.     /** Get the data format.
  106.      * @return data format
  107.      */
  108.     public DataFormat getFormat() {
  109.         return format;
  110.     }

  111.     /** Get the format details.
  112.      * @return format details
  113.      */
  114.     public List<StreamedMessage> getFormatDetails() {
  115.         return formatDetails;
  116.     }

  117.     /** Get the carrier phase.
  118.      * @return carrier phase
  119.      */
  120.     public CarrierPhase getCarrierPhase() {
  121.         return carrierPhase;
  122.     }

  123.     /** Get the navigation systems.
  124.      * @return navigation systems
  125.      */
  126.     public List<NavigationSystem> getNavigationSystems() {
  127.         return systems;
  128.     }

  129.     /** Get the network.
  130.      * @return network
  131.      */
  132.     public String getNetwork() {
  133.         return getField(7);
  134.     }

  135.     /** Get the country.
  136.      * @return country
  137.      */
  138.     public String getCountry() {
  139.         return getField(8);
  140.     }

  141.     /** Get the latitude.
  142.      * @return latitude (rad)
  143.      */
  144.     public double getLatitude() {
  145.         return latitude;
  146.     }

  147.     /** Get the longitude.
  148.      * @return longitude (rad)
  149.      */
  150.     public double getLongitude() {
  151.         return longitude;
  152.     }

  153.     /** Check if NMEA message must be sent to caster.
  154.      * @return true if NMEA message must be sent to caster
  155.      */
  156.     public boolean isNMEARequired() {
  157.         return nmeaRequired;
  158.     }

  159.     /** Check if the stream is generated from a network of stations.
  160.      * @return true if stream  is generated from a network of stations
  161.      */
  162.     public boolean isNetworked() {
  163.         return networked;
  164.     }

  165.     /** Get the hardware or software generator.
  166.      * @return hardware or software generator
  167.      */
  168.     public String getGenerator() {
  169.         return getField(13);
  170.     }

  171.     /** Get the compression/encryption algorithm applied.
  172.      * @return compression/encryption algorithm applied
  173.      */
  174.     public String getCompressionEncryption() {
  175.         return getField(14);
  176.     }

  177.     /** Get the authentication method.
  178.      * @return authentication method
  179.      */
  180.     public Authentication getAuthentication() {
  181.         return authentication;
  182.     }

  183.     /** Check if fees are required.
  184.      * @return true if fees are required
  185.      */
  186.     public boolean areFeesRequired() {
  187.         return fees;
  188.     }

  189.     /** Get the bit rate.
  190.      * @return bit rate
  191.      */
  192.     public int getBitRate() {
  193.         return bitRate;
  194.     }

  195. }