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.files.ccsds.utils;
18
19 import java.util.function.BooleanSupplier;
20 import java.util.function.DoubleSupplier;
21 import java.util.function.Supplier;
22
23 import org.orekit.data.DataContext;
24 import org.orekit.files.ccsds.definitions.TimeSystem;
25 import org.orekit.files.ccsds.ndm.ParsedUnitsBehavior;
26 import org.orekit.time.AbsoluteDate;
27 import org.orekit.utils.IERSConventions;
28
29 /** Context for parsing/writing Navigation Data Message.
30 * <p>
31 * This class is a facade providing late binding access to data.
32 * Late binding is mainly useful at parse time as it allows some data to be set up
33 * during parsing itself. This is used for example to access {@link #getTimeSystem()
34 * time system} that is generally parsed from metadata block, and used later on
35 * within the same metadata block.
36 * </p>
37 * @author Luc Maisonobe
38 * @since 11.0
39 */
40 public class ContextBinding {
41
42 /** Behavior adopted for units that have been parsed from a CCSDS message. */
43 private final Supplier<ParsedUnitsBehavior> behaviorSupplier;
44
45 /** Supplier for IERS conventions to use. */
46 private final Supplier<IERSConventions> conventionsSupplier;
47
48 /** Supplier for simple or accurate EOP interpolation indicator. */
49 private final BooleanSupplier simpleEOPSupplier;
50
51 /** Supplier for data context. */
52 private final Supplier<DataContext> dataContextSupplier;
53
54 /** Supplier for reference date for mission elapsed time (MET), mission relative time (MRT),
55 * or spacecraft clock (SCLK) time systems. */
56 private final Supplier<AbsoluteDate> referenceDateSupplier;
57
58 /** Supplier for reference system for interpreting dates. */
59 private final Supplier<TimeSystem> timeSystemSupplier;
60
61 /** Supplier for clock count at reference date in spacecraft clock (SCLK) time system. */
62 private final DoubleSupplier clockCountSupplier;
63
64 /** Supplier for clock rate in spacecraft clock (SCLK) time system. */
65 private final DoubleSupplier clockRateSupplier;
66
67 /** Create a new context.
68 * @param conventionsSupplier supplier for IERS conventions to use
69 * @param simpleEOPSupplier supplier for simple or accurate EOP interpolation indicator
70 * @param dataContextSupplier supplier for data context to use
71 * @param behaviorSupplier supplier for behavior to adopt on unit
72 * @param referenceDateSupplier supplier for reference date for mission elapsed time (MET),
73 * mission relative time (MRT), or spacecraft clock (SCLK) time systems
74 * @param timeSystemSupplier supplier for reference system for interpreting dates
75 * @param clockCountSupplier supplier for clock count at reference date in spacecraft clock (SCLK) time system
76 * @param clockRateSupplier supplier for clock rate in spacecraft clock (SCLK) time system
77 */
78 public ContextBinding(final Supplier<IERSConventions> conventionsSupplier,
79 final BooleanSupplier simpleEOPSupplier,
80 final Supplier<DataContext> dataContextSupplier,
81 final Supplier<ParsedUnitsBehavior> behaviorSupplier,
82 final Supplier<AbsoluteDate> referenceDateSupplier,
83 final Supplier<TimeSystem> timeSystemSupplier,
84 final DoubleSupplier clockCountSupplier,
85 final DoubleSupplier clockRateSupplier) {
86 this.behaviorSupplier = behaviorSupplier;
87 this.conventionsSupplier = conventionsSupplier;
88 this.simpleEOPSupplier = simpleEOPSupplier;
89 this.dataContextSupplier = dataContextSupplier;
90 this.referenceDateSupplier = referenceDateSupplier;
91 this.timeSystemSupplier = timeSystemSupplier;
92 this.clockCountSupplier = clockCountSupplier;
93 this.clockRateSupplier = clockRateSupplier;
94 }
95
96 /** Get the behavior to adopt for handling parsed units.
97 * @return behavior to adopt for handling parsed units
98 */
99 public ParsedUnitsBehavior getParsedUnitsBehavior() {
100 return behaviorSupplier.get();
101 }
102
103 /** Get IERS conventions.
104 * @return IERS conventions to use while parsing
105 */
106 public IERSConventions getConventions() {
107 return conventionsSupplier.get();
108 }
109
110 /** Get EOP interpolation method.
111 * @return true if tidal effects are ignored when interpolating EOP
112 */
113 public boolean isSimpleEOP() {
114 return simpleEOPSupplier.getAsBoolean();
115 }
116
117 /** Get the data context used for getting frames, time scales, and celestial bodies.
118 * @return the data context.
119 */
120 public DataContext getDataContext() {
121 return dataContextSupplier.get();
122 }
123
124 /** Get initial date.
125 * @return reference date to use while parsing
126 */
127 public AbsoluteDate getReferenceDate() {
128 return referenceDateSupplier.get();
129 }
130
131 /** Get the time system.
132 * @return time system
133 */
134 public TimeSystem getTimeSystem() {
135 return timeSystemSupplier.get();
136 }
137
138 /** Get clock count.
139 * @return clock count at reference date
140 */
141 public double getClockCount() {
142 return clockCountSupplier.getAsDouble();
143 }
144
145 /** Get clock rate.
146 * @return clock rate (in clock ticks per SI second)
147 */
148 public double getClockRate() {
149 return clockRateSupplier.getAsDouble();
150 }
151
152 }