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.apm;
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.files.ccsds.utils.lexical.TokenType;
23  import org.orekit.utils.units.Unit;
24  
25  /** Keys for {@link SpinStabilized APM spin-stabilized} entries.
26   * @author Bryan Cazabonne
27   * @since 10.2
28   */
29  public enum SpinStabilizedKey {
30  
31      /** Comment entry. */
32      COMMENT((token, context, container) ->
33              token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),
34  
35      /** First reference frame entry. */
36      SPIN_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),
37  
38      /** Second reference frame entry. */
39      SPIN_FRAME_B((token, context, container) -> {
40          if (token.getType() == TokenType.ENTRY) {
41              container.checkNotNull(container.getEndpoints().getFrameA(), SPIN_FRAME_A);
42              final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
43              return token.processAsFrame(container.getEndpoints()::setFrameB, context,
44                                          aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
45          }
46          return true;
47      }),
48  
49      /** Rotation direction entry. */
50      SPIN_DIR((token, context, container) -> {
51          if (token.getType() == TokenType.ENTRY) {
52              container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
53          }
54          return true;
55      }),
56  
57      /** Spin right ascension entry. */
58      SPIN_ALPHA((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
59                                                                      container::setSpinAlpha)),
60  
61      /** Spin declination entry. */
62      SPIN_DELTA((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
63                                                                      container::setSpinDelta)),
64  
65      /** Spin phase entry. */
66      SPIN_ANGLE((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
67                                                                      container::setSpinAngle)),
68  
69      /** Spin angular velocity entry. */
70      SPIN_ANGLE_VEL((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
71                                                                          container::setSpinAngleVel)),
72  
73      /** Nutation angle entry. */
74      NUTATION((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
75                                                                    container::setNutation)),
76  
77      /** Nutation period entry. */
78      NUTATION_PER((token, context, container) -> token.processAsDouble(Unit.SECOND, context.getParsedUnitsBehavior(),
79                                                                        container::setNutationPeriod)),
80  
81      /** Nutation phase entry. */
82      NUTATION_PHASE((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
83                                                                          container::setNutationPhase));
84  
85      /** Processing method. */
86      private final TokenProcessor processor;
87  
88      /** Simple constructor.
89       * @param processor processing method
90       */
91      SpinStabilizedKey(final TokenProcessor processor) {
92          this.processor = processor;
93      }
94  
95      /** Process one token.
96       * @param token token to process
97       * @param context context binding
98       * @param container container to fill
99       * @return true of token was accepted
100      */
101     public boolean process(final ParseToken token, final ContextBinding context, final SpinStabilized container) {
102         return processor.process(token, context, container);
103     }
104 
105     /** Interface for processing one token. */
106     interface TokenProcessor {
107         /** Process one token.
108          * @param token token to process
109          * @param context context binding
110          * @param container container to fill
111          * @return true of token was accepted
112          */
113         boolean process(ParseToken token, ContextBinding context, SpinStabilized container);
114     }
115 
116 }