RtcmCorrectionMessage.java

  1. /* Copyright 2002-2024 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.messages.rtcm.correction;

  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;

  23. import org.orekit.gnss.SatelliteSystem;
  24. import org.orekit.gnss.metric.messages.rtcm.RtcmMessage;

  25. /**
  26.  * The RTCM Correction Message types provide elements
  27.  * to calculate GNSS satellite corrections.
  28.  * Corrections are orbit and clock corrections.
  29.  *
  30.  * @author Bryan Cazabonne
  31.  * @since 12.0
  32.  * @param <H> type of the header
  33.  * @param <D> type of the data
  34.  *
  35.  */
  36. public class RtcmCorrectionMessage<H extends RtcmCorrectionHeader, D extends RtcmCorrectionData> extends RtcmMessage<D> {

  37.     /** Message header. */
  38.     private final H header;

  39.     /** Satellite system. */
  40.     private final SatelliteSystem system;

  41.     /**
  42.      * Constructor.
  43.      * @param system satellite system associated to the message
  44.      * @param typeCode message number
  45.      * @param header message header
  46.      * @param data message data
  47.      */
  48.     public RtcmCorrectionMessage(final int typeCode, final SatelliteSystem system,
  49.                                  final H header, final List<D> data) {
  50.         super(typeCode, data);
  51.         this.header = header;
  52.         this.system = system;
  53.     }

  54.     /**
  55.      * Get the header.
  56.      * @return header
  57.      */
  58.     public H getHeader() {
  59.         return header;
  60.     }

  61.     /**
  62.      * Get the satellite system associated to the message.
  63.      * @return the satellite system
  64.      */
  65.     public SatelliteSystem getSatelliteSystem() {
  66.         return system;
  67.     }

  68.     /**
  69.      * Get the all data parsed in the RTCM correction message.
  70.      * <p>
  71.      * Key: satellite identifier (e.g. "G01")
  72.      * </p>
  73.      * @return the all data for the parsed message
  74.      */
  75.     public Map<String, List<D>> getDataMap() {

  76.         // Initialize map
  77.         final Map<String, List<D>> data = new HashMap<>();

  78.         // Loop on parsed data and fill map
  79.         for (final D currentData : getData()) {
  80.             final int satId = currentData.getSatelliteID();
  81.             final String idString = satId < 10 ? "0" + String.valueOf(satId) : String.valueOf(satId);
  82.             final String id = getSatelliteSystem().getKey() + idString;
  83.             data.putIfAbsent(id, new ArrayList<>());
  84.             data.get(id).add(currentData);
  85.         }

  86.         // Return an unmodifiable map of the parsed data
  87.         return Collections.unmodifiableMap(data);

  88.     }

  89. }