SpinStabilizedKey.java

  1. /* Copyright 2002-2022 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. import org.orekit.files.ccsds.definitions.Units;
  19. import org.orekit.files.ccsds.utils.ContextBinding;
  20. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  21. import org.orekit.files.ccsds.utils.lexical.TokenType;
  22. import org.orekit.utils.units.Unit;

  23. /** Keys for {@link SpinStabilized APM spin-stabilized} entries.
  24.  * @author Bryan Cazabonne
  25.  * @since 10.2
  26.  */
  27. public enum SpinStabilizedKey {

  28.     /** Comment entry. */
  29.     COMMENT((token, context, container) ->
  30.             token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),

  31.     /** First reference frame entry. */
  32.     SPIN_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),

  33.     /** Second reference frame entry. */
  34.     SPIN_FRAME_B((token, context, container) -> {
  35.         if (token.getType() == TokenType.ENTRY) {
  36.             container.checkNotNull(container.getEndpoints().getFrameA(), SPIN_FRAME_A);
  37.             final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
  38.             return token.processAsFrame(container.getEndpoints()::setFrameB, context,
  39.                                         aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
  40.         }
  41.         return true;
  42.     }),

  43.     /** Rotation direction entry. */
  44.     SPIN_DIR((token, context, container) -> {
  45.         if (token.getType() == TokenType.ENTRY) {
  46.             container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
  47.         }
  48.         return true;
  49.     }),

  50.     /** Spin right ascension entry. */
  51.     SPIN_ALPHA((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  52.                                                                     container::setSpinAlpha)),

  53.     /** Spin declination entry. */
  54.     SPIN_DELTA((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  55.                                                                     container::setSpinDelta)),

  56.     /** Spin phase entry. */
  57.     SPIN_ANGLE((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  58.                                                                     container::setSpinAngle)),

  59.     /** Spin angular velocity entry. */
  60.     SPIN_ANGLE_VEL((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  61.                                                                         container::setSpinAngleVel)),

  62.     /** Nutation angle entry. */
  63.     NUTATION((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  64.                                                                   container::setNutation)),

  65.     /** Nutation period entry. */
  66.     NUTATION_PER((token, context, container) -> token.processAsDouble(Unit.SECOND, context.getParsedUnitsBehavior(),
  67.                                                                       container::setNutationPeriod)),

  68.     /** Nutation phase entry. */
  69.     NUTATION_PHASE((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  70.                                                                         container::setNutationPhase));

  71.     /** Processing method. */
  72.     private final TokenProcessor processor;

  73.     /** Simple constructor.
  74.      * @param processor processing method
  75.      */
  76.     SpinStabilizedKey(final TokenProcessor processor) {
  77.         this.processor = processor;
  78.     }

  79.     /** Process one token.
  80.      * @param token token to process
  81.      * @param context context binding
  82.      * @param container container to fill
  83.      * @return true of token was accepted
  84.      */
  85.     public boolean process(final ParseToken token, final ContextBinding context, final SpinStabilized container) {
  86.         return processor.process(token, context, container);
  87.     }

  88.     /** Interface for processing one token. */
  89.     interface TokenProcessor {
  90.         /** Process one token.
  91.          * @param token token to process
  92.          * @param context context binding
  93.          * @param container container to fill
  94.          * @return true of token was accepted
  95.          */
  96.         boolean process(ParseToken token, ContextBinding context, SpinStabilized container);
  97.     }

  98. }