1   /* Copyright 2002-2021 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.ndm.adm.aem;
18  
19  import org.orekit.files.ccsds.definitions.Units;
20  import org.orekit.files.ccsds.utils.ContextBinding;
21  import org.orekit.files.ccsds.utils.lexical.ParseToken;
22  import org.orekit.utils.units.Unit;
23  
24  
25  /** Keys for {@link AttitudeEntry attitude entries} in XML messages.
26   * @author Luc Maisonobe
27   * @since 11.0
28   */
29  public enum AttitudeEntryKey {
30  
31      /** Quaternion state sub-section. */
32      quaternionState((token, context, container) -> true),
33  
34      /** Quaternion/derivative sub-section. */
35      quaternionDerivative((token, context, container) -> true),
36  
37      /** Quaternion/rate sub-section. */
38      quaternionEulerRate((token, context, container) -> true),
39  
40      /** Euler angle sub-section. */
41      eulerAngle((token, context, container) -> true),
42  
43      /** Euler angle/rate sub-section. */
44      eulerAngleRate((token, context, container) -> true),
45  
46      /** Spin sub-section. */
47      spin((token, context, container) -> true),
48  
49      /** Spin/nutation sub-section. */
50      spinNutation((token, context, container) -> true),
51  
52      /** Quaternion sub-sub-section. */
53      quaternion((token, context, container) -> true),
54  
55      /** Quaternion rate sub-sub-section. */
56      quaternionRate((token, context, container) -> true),
57  
58      /** Rotation angles sub-sub-section. */
59      rotationAngles((token, context, container) -> true),
60  
61      /** Rotation rates sub-sub-section. */
62      rotationRates((token, context, container) -> true),
63  
64      /** Entry epoch. */
65      EPOCH((token, context, container) -> token.processAsDate(container::setEpoch, context)),
66  
67      /** Quaternion first vectorial component. */
68      Q1((token, context, container) -> token.processAsIndexedDouble(container.getMetadata().isFirst() ? 1 : 0,
69                                                                     Unit.ONE, context.getParsedUnitsBehavior(),
70                                                                     container::setComponent)),
71  
72      /** Quaternion second vectorial component. */
73      Q2((token, context, container) -> token.processAsIndexedDouble(container.getMetadata().isFirst() ? 2 : 1,
74                                                                     Unit.ONE, context.getParsedUnitsBehavior(),
75                                                                     container::setComponent)),
76  
77      /** Quaternion third vectorial component. */
78      Q3((token, context, container) -> token.processAsIndexedDouble(container.getMetadata().isFirst() ? 3 : 2,
79                                                                     Unit.ONE, context.getParsedUnitsBehavior(),
80                                                                     container::setComponent)),
81  
82      /** Quaternion scalar component. */
83      QC((token, context, container) -> token.processAsIndexedDouble(container.getMetadata().isFirst() ? 0 : 3,
84                                                                     Unit.ONE, context.getParsedUnitsBehavior(),
85                                                                     container::setComponent)),
86  
87      /** Quaternion first vectorial component. */
88      Q1_DOT((token, context, container) -> token.processAsIndexedDouble(container.getMetadata().isFirst() ? 5 : 4,
89                                                                         Units.ONE_PER_S, context.getParsedUnitsBehavior(),
90                                                                         container::setComponent)),
91  
92      /** Quaternion second vectorial component. */
93      Q2_DOT((token, context, container) -> token.processAsIndexedDouble(container.getMetadata().isFirst() ? 6 : 5,
94                                                                         Units.ONE_PER_S, context.getParsedUnitsBehavior(),
95                                                                         container::setComponent)),
96  
97      /** Quaternion third vectorial component. */
98      Q3_DOT((token, context, container) -> token.processAsIndexedDouble(container.getMetadata().isFirst() ? 7 : 6,
99                                                                         Units.ONE_PER_S, context.getParsedUnitsBehavior(),
100                                                                        container::setComponent)),
101 
102     /** Quaternion scalar component. */
103     QC_DOT((token, context, container) -> token.processAsIndexedDouble(container.getMetadata().isFirst() ? 4 : 7,
104                                                                        Units.ONE_PER_S, context.getParsedUnitsBehavior(),
105                                                                        container::setComponent)),
106 
107     /** Rotation about X axis. */
108     X_ANGLE((token, context, container) -> token.processAsLabeledDouble('X', Unit.DEGREE, context.getParsedUnitsBehavior(),
109                                                                         container::setAngle)),
110 
111     /** Rotation about Y axis. */
112     Y_ANGLE((token, context, container) -> token.processAsLabeledDouble('Y', Unit.DEGREE, context.getParsedUnitsBehavior(),
113                                                                         container::setAngle)),
114 
115     /** Rotation about Z axis. */
116     Z_ANGLE((token, context, container) -> token.processAsLabeledDouble('Z', Unit.DEGREE, context.getParsedUnitsBehavior(),
117                                                                         container::setAngle)),
118 
119     /** Rotation about X axis. */
120     X_RATE((token, context, container) -> token.processAsLabeledDouble('X',
121                                                                        Units.DEG_PER_S, context.getParsedUnitsBehavior(),
122                                                                        container::setRate)),
123 
124     /** Rotation about Y axis. */
125     Y_RATE((token, context, container) -> token.processAsLabeledDouble('Y',
126                                                                        Units.DEG_PER_S, context.getParsedUnitsBehavior(),
127                                                                        container::setRate)),
128 
129     /** Rotation about Z axis. */
130     Z_RATE((token, context, container) -> token.processAsLabeledDouble('Z',
131                                                                        Units.DEG_PER_S, context.getParsedUnitsBehavior(),
132                                                                        container::setRate)),
133 
134     /** Right ascension of spin axis vector. */
135     SPIN_ALPHA((token, context, container) -> token.processAsIndexedDouble(0, Unit.DEGREE, context.getParsedUnitsBehavior(),
136                                                                            container::setComponent)),
137 
138     /** Declination of spin axis vector. */
139     SPIN_DELTA((token, context, container) -> token.processAsIndexedDouble(1, Unit.DEGREE, context.getParsedUnitsBehavior(),
140                                                                            container::setComponent)),
141 
142     /** Phase of satellite about spin axis. */
143     SPIN_ANGLE((token, context, container) -> token.processAsIndexedDouble(2, Unit.DEGREE, context.getParsedUnitsBehavior(),
144                                                                            container::setComponent)),
145 
146     /** angular velocity of satellite around spin axis. */
147     SPIN_ANGLE_VEL((token, context, container) -> token.processAsIndexedDouble(3, Units.DEG_PER_S, context.getParsedUnitsBehavior(),
148                                                                                container::setComponent)),
149 
150     /** Nutation angle entry. */
151     NUTATION((token, context, container) -> token.processAsIndexedDouble(4, Units.DEG_PER_S, context.getParsedUnitsBehavior(),
152                                                                          container::setComponent)),
153 
154     /** Nutation period entry. */
155     NUTATION_PER((token, context, container) -> token.processAsIndexedDouble(5, Unit.SECOND, context.getParsedUnitsBehavior(),
156                                                                              container::setComponent)),
157 
158     /** Nutation phase entry. */
159     NUTATION_PHASE((token, context, container) -> token.processAsIndexedDouble(6, Unit.DEGREE, context.getParsedUnitsBehavior(),
160                                                                                container::setComponent));
161 
162     /** Processing method. */
163     private final TokenProcessor processor;
164 
165     /** Simple constructor.
166      * @param processor processing method
167      */
168     AttitudeEntryKey(final TokenProcessor processor) {
169         this.processor = processor;
170     }
171 
172     /** Process an token.
173      * @param token token to process
174      * @param context context binding
175      * @param container container to fill
176      * @return true of token was accepted
177      */
178     public boolean process(final ParseToken token, final ContextBinding context, final AttitudeEntry container) {
179         return processor.process(token, context, container);
180     }
181 
182     /** Interface for processing one token. */
183     interface TokenProcessor {
184         /** Process one token.
185          * @param token token to process
186          * @param context context binding
187          * @param container container to fill
188          * @return true of token was accepted
189          */
190         boolean process(ParseToken token, ContextBinding context, AttitudeEntry container);
191     }
192 
193 }