1   /* Copyright 2022-2026 Luc Maisonobe
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.propagation.analytical.gnss.data;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.Field;
21  import org.hipparchus.util.FastMath;
22  import org.orekit.time.FieldAbsoluteDate;
23  
24  import java.util.function.Function;
25  
26  /**
27   * Base class for GNSS navigation messages.
28   * @param <T> type of the field elements
29   * @param <O> type of the orbital elements (non-field version)
30   * @author Luc Maisonobe
31   * @since 13.0
32   *
33   * @see FieldGPSLegacyNavigationMessage
34   * @see FieldGalileoNavigationMessage
35   * @see FieldBeidouLegacyNavigationMessage
36   * @see FieldQZSSLegacyNavigationMessage
37   * @see FieldNavicLegacyNavigationMessage
38   */
39  public abstract class FieldAbstractNavigationMessage<T extends CalculusFieldElement<T>,
40                                                       O extends AbstractNavigationMessage<O>>
41      extends FieldAbstractAlmanac<T, O> {
42  
43      /** Time of clock epoch. */
44      private FieldAbsoluteDate<T> epochToc;
45  
46      /** Transmission time. */
47      private T transmissionTime;
48  
49      /** Message type.
50       * @since 14.0
51       */
52      private final String type;
53  
54      /** Constructor from non-field instance.
55       * @param field    field to which elements belong
56       * @param original regular non-field instance
57       */
58      protected FieldAbstractNavigationMessage(final Field<T> field, final O original) {
59          super(field, original);
60          setEpochToc(new FieldAbsoluteDate<>(field, original.getEpochToc()));
61          setTransmissionTime(field.getZero().newInstance(original.getTransmissionTime()));
62          this.type = original.getNavigationMessageType();
63      }
64  
65      /** Constructor from different field instance.
66       * @param <V> type of the old field elements
67       * @param original regular non-field instance
68       * @param converter for field elements
69       */
70      protected <V extends CalculusFieldElement<V>> FieldAbstractNavigationMessage(final Function<V, T> converter,
71                                                                                   final FieldAbstractNavigationMessage<V, O> original) {
72          super(converter, original);
73          setEpochToc(new FieldAbsoluteDate<>(getMu().getField(), original.getEpochToc().toAbsoluteDate()));
74          setTransmissionTime(converter.apply(original.getTransmissionTime()));
75          this.type = original.getNavigationMessageType();
76      }
77  
78      /** Get navigation message type.
79       * @return the navigation message type
80       * @since 14.0
81       */
82      public String getNavigationMessageType() {
83          return type;
84      }
85  
86      /**
87       * Getter for Square Root of Semi-Major Axis (√m).
88       * @return Square Root of Semi-Major Axis (√m)
89       */
90      public T getSqrtA() {
91          return FastMath.sqrt(getSma());
92      }
93  
94      /**
95       * Setter for the Square Root of Semi-Major Axis (√m).
96       * <p>
97       * In addition, this method set the value of the Semi-Major Axis.
98       * </p>
99       * @param sqrtA the Square Root of Semi-Major Axis (√m)
100      */
101     public void setSqrtA(final T sqrtA) {
102         setSma(sqrtA.square());
103     }
104 
105     /**
106      * Getter for the time of clock epoch.
107      * @return the time of clock epoch
108      */
109     public FieldAbsoluteDate<T> getEpochToc() {
110         return epochToc;
111     }
112 
113     /**
114      * Setter for the time of clock epoch.
115      * @param epochToc the epoch to set
116      */
117     public void setEpochToc(final FieldAbsoluteDate<T> epochToc) {
118         this.epochToc = epochToc;
119     }
120 
121     /**
122      * Getter for transmission time.
123      * @return transmission time
124      */
125     public T getTransmissionTime() {
126         return transmissionTime;
127     }
128 
129     /**
130      * Setter for transmission time.
131      * @param transmissionTime transmission time
132      */
133     public void setTransmissionTime(final T transmissionTime) {
134         this.transmissionTime = transmissionTime;
135     }
136 
137 }