AttitudeManeuverKey.java

  1. /* Copyright 2022-2025 Luc Maisonobe
  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.acm;

  18. import org.hipparchus.geometry.euclidean.threed.Rotation;
  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. /** Keys for {@link AttitudeManeuver attitude maneuver} entries.
  25.  * @author Luc Maisonobe
  26.  * @since 12.0
  27.  */
  28. public enum AttitudeManeuverKey {

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

  32.     /** Maneuver identification number. */
  33.     MAN_ID((token, context, container) -> token.processAsFreeTextString(container::setID)),

  34.     /** Identification number of previous maneuver. */
  35.     MAN_PREV_ID((token, context, container) -> token.processAsFreeTextString(container::setPrevID)),

  36.     /** Purpose of the maneuver. */
  37.     MAN_PURPOSE((token, context, container) -> token.processAsFreeTextString(container::setManPurpose)),

  38.     /** Start time of actual maneuver, relative to t₀. */
  39.     MAN_BEGIN_TIME((token, context, container) -> token.processAsDouble(Unit.SECOND, context.getParsedUnitsBehavior(),
  40.                                                                         container::setBeginTime)),

  41.     /** End time of actual maneuver, relative to t₀. */
  42.     MAN_END_TIME((token, context, container) -> token.processAsDouble(Unit.SECOND, context.getParsedUnitsBehavior(),
  43.                                                                       container::setEndTime)),

  44.     /** Duration. */
  45.     MAN_DURATION((token, context, container) -> token.processAsDouble(Unit.SECOND, context.getParsedUnitsBehavior(),
  46.                                                                       container::setDuration)),

  47.     /** Actuator used. */
  48.     ACTUATOR_USED((token, context, container) -> token.processAsFreeTextString(container::setActuatorUsed)),

  49.     /** Target momentum. */
  50.     TARGET_MOMENTUM((token, context, container) -> token.processAsVector(Units.N_M_S, context.getParsedUnitsBehavior(),
  51.                                                                          container::setTargetMomentum)),

  52.     /** Target momentum frame. */
  53.     TARGET_MOM_FRAME((token, context, container) -> token.processAsFrame(container::setTargetMomFrame, context, true, true, true)),

  54.     /** Target attitude. */
  55.     TARGET_ATTITUDE((token, context, container) -> {
  56.         try {
  57.             if (token.getType() == TokenType.ENTRY) {
  58.                 final String[] fields = token.getRawContent().split("\\p{Space}+");
  59.                 if (fields.length == 4) {
  60.                     container.setTargetAttitude(new Rotation(Double.parseDouble(fields[3]),
  61.                                                              Double.parseDouble(fields[0]),
  62.                                                              Double.parseDouble(fields[1]),
  63.                                                              Double.parseDouble(fields[2]),
  64.                                                              true));
  65.                     return true;
  66.                 }
  67.             } else {
  68.                 return true;
  69.             }
  70.         } catch (NumberFormatException nfe) {
  71.             // ignored, error handled below, together with wrong number of fields
  72.         }
  73.         throw token.generateException(null);
  74.     }),

  75.     /** Target spin rate. */
  76.     TARGET_SPINRATE((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  77.                                                                           container::setTargetSpinRate));

  78.     /** Processing method. */
  79.     private final transient TokenProcessor processor;

  80.     /** Simple constructor.
  81.      * @param processor processing method
  82.      */
  83.     AttitudeManeuverKey(final TokenProcessor processor) {
  84.         this.processor = processor;
  85.     }

  86.     /** Process an token.
  87.      * @param token token to process
  88.      * @param context context binding
  89.      * @param data data to fill
  90.      * @return true of token was accepted
  91.      */
  92.     public boolean process(final ParseToken token, final ContextBinding context, final AttitudeManeuver data) {
  93.         return processor.process(token, context, data);
  94.     }

  95.     /** Interface for processing one token. */
  96.     interface TokenProcessor {
  97.         /** Process one token.
  98.          * @param token token to process
  99.          * @param context context binding
  100.          * @param data data to fill
  101.          * @return true of token was accepted
  102.          */
  103.         boolean process(ParseToken token, ContextBinding context, AttitudeManeuver data);
  104.     }

  105. }