SpinStabilizedKey.java

  1. /* Copyright 2002-2024 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 (only for ADM V1). */
  32.     SPIN_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),

  33.     /** First reference frame entry.
  34.      * @since 12.0
  35.      */
  36.     REF_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),

  37.     /** Second reference frame entry (only for ADM V1). */
  38.     SPIN_FRAME_B((token, context, container) -> {
  39.         if (token.getType() == TokenType.ENTRY) {
  40.             container.checkNotNull(container.getEndpoints().getFrameA(), SPIN_FRAME_A.name());
  41.             final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
  42.             return token.processAsFrame(container.getEndpoints()::setFrameB, context,
  43.                                         aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
  44.         }
  45.         return true;
  46.     }),

  47.     /** Second reference frame entry.
  48.      * @since 12.0
  49.      */
  50.     REF_FRAME_B((token, context, container) -> {
  51.         if (token.getType() == TokenType.ENTRY) {
  52.             container.checkNotNull(container.getEndpoints().getFrameA(), REF_FRAME_A.name());
  53.             final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
  54.             return token.processAsFrame(container.getEndpoints()::setFrameB, context,
  55.                                         aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
  56.         }
  57.         return true;
  58.     }),

  59.     /** Rotation direction entry (only for ADM V1). */
  60.     SPIN_DIR((token, context, container) -> {
  61.         if (token.getType() == TokenType.ENTRY) {
  62.             container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
  63.         }
  64.         return true;
  65.     }),

  66.     /** Spin right ascension entry. */
  67.     SPIN_ALPHA((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  68.                                                                     container::setSpinAlpha)),

  69.     /** Spin declination entry. */
  70.     SPIN_DELTA((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  71.                                                                     container::setSpinDelta)),

  72.     /** Spin phase entry. */
  73.     SPIN_ANGLE((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  74.                                                                     container::setSpinAngle)),

  75.     /** Spin angular velocity entry. */
  76.     SPIN_ANGLE_VEL((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  77.                                                                         container::setSpinAngleVel)),

  78.     /** Nutation angle entry. */
  79.     NUTATION((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  80.                                                                   container::setNutation)),

  81.     /** Nutation period entry. */
  82.     NUTATION_PER((token, context, container) -> token.processAsDouble(Unit.SECOND, context.getParsedUnitsBehavior(),
  83.                                                                       container::setNutationPeriod)),

  84.     /** Nutation phase entry. */
  85.     NUTATION_PHASE((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  86.                                                                         container::setNutationPhase)),

  87.     /** Momentum right ascension entry.
  88.      * @since 12.0
  89.      */
  90.     MOMENTUM_ALPHA((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  91.                                                                         container::setMomentumAlpha)),

  92.     /** Momentum declination entry.
  93.      * @since 12.0
  94.      */
  95.     MOMENTUM_DELTA((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(),
  96.                                                                         container::setMomentumDelta)),

  97.     /** Nutation velocity entry.
  98.      * @since 12.0
  99.      */
  100.     NUTATION_VEL((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  101.                                                                       container::setNutationVel));

  102.     /** Processing method. */
  103.     private final transient TokenProcessor processor;

  104.     /** Simple constructor.
  105.      * @param processor processing method
  106.      */
  107.     SpinStabilizedKey(final TokenProcessor processor) {
  108.         this.processor = processor;
  109.     }

  110.     /** Process one token.
  111.      * @param token token to process
  112.      * @param context context binding
  113.      * @param container container to fill
  114.      * @return true of token was accepted
  115.      */
  116.     public boolean process(final ParseToken token, final ContextBinding context, final SpinStabilized container) {
  117.         return processor.process(token, context, container);
  118.     }

  119.     /** Interface for processing one token. */
  120.     interface TokenProcessor {
  121.         /** Process one token.
  122.          * @param token token to process
  123.          * @param context context binding
  124.          * @param container container to fill
  125.          * @return true of token was accepted
  126.          */
  127.         boolean process(ParseToken token, ContextBinding context, SpinStabilized container);
  128.     }

  129. }