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  
19  import org.orekit.files.ccsds.definitions.AdMethodType;
20  import org.orekit.files.ccsds.definitions.Units;
21  import org.orekit.files.ccsds.utils.ContextBinding;
22  import org.orekit.files.ccsds.utils.lexical.ParseToken;
23  import org.orekit.files.ccsds.utils.lexical.TokenType;
24  
25  
26  /** Keys for {@link AttitudeDetermination attitude determination data} entries.
27   * @author Luc Maisonobe
28   * @since 12.0
29   */
30  public enum AttitudeDeterminationKey {
31  
32      /** Comment entry. */
33      COMMENT((token, parser, context, container) ->
34              token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),
35  
36      /** Identification number. */
37      AD_ID((token, parser, context, container) -> token.processAsFreeTextString(container::setId)),
38  
39      /** Identification of previous attitude determination. */
40      AD_PREV_ID((token, parser, context, container) -> token.processAsFreeTextString(container::setPrevId)),
41  
42      /** Attitude determination method. */
43      AD_METHOD((token, parser, context, container) -> token.processAsEnum(AdMethodType.class, container::setMethod)),
44  
45      /** Source of attitude estimate. */
46      ATTITUDE_SOURCE((token, parser, context, container) -> token.processAsFreeTextString(container::setSource)),
47  
48      /** Rotation sequence entry. */
49      EULER_ROT_SEQ((token, parser, context, container) -> token.processAsRotationOrder(container::setEulerRotSeq)),
50  
51      /** Number of states. */
52      NUMBER_STATES((token, parser, context, container) -> token.processAsInteger(container::setNbStates)),
53  
54      /** Attitude states. */
55      ATTITUDE_STATES((token, parser, context, container) -> token.processAsEnum(AttitudeElementsType.class, container::setAttitudeStates)),
56  
57      /** Type of attitude error state. */
58      COV_TYPE((token, parser, context, container) -> token.processAsEnum(AttitudeCovarianceType.class, container::setCovarianceType)),
59  
60      /** Reference frame defining the starting point of the transformation. */
61      REF_FRAME_A((token, parser, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, false)),
62  
63      /** Reference frame defining the end point of the transformation. */
64      REF_FRAME_B((token, parser, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameB, context, false, false, true)),
65  
66      /** Attitude rate states. */
67      RATE_STATES((token, parser, context, container) -> token.processAsEnum(RateElementsType.class, container::setRateStates)),
68  
69      /** Rate random walk if {@link #RATE_STATES} is {@link RateElementsType#GYRO_BIAS}. */
70      SIGMA_U((token, parser, context, container) -> token.processAsDouble(Units.DEG_PER_S_3_2, context.getParsedUnitsBehavior(),
71                                                                           container::setSigmaU)),
72  
73      /** Angle random walk if {@link #RATE_STATES} is {@link RateElementsType#GYRO_BIAS}. */
74      SIGMA_V((token, parser, context, container) -> token.processAsDouble(Units.DEG_PER_S_1_2, context.getParsedUnitsBehavior(),
75                                                                           container::setSigmaV)),
76  
77      /** Process noise standard deviation if {@link #RATE_STATES} is {@link RateElementsType#ANGVEL}. */
78      RATE_PROCESS_NOISE_STDDEV((token, parser, context, container) -> token.processAsDouble(Units.DEG_PER_S_3_2, context.getParsedUnitsBehavior(),
79                                                                                             container::setRateProcessNoiseStdDev)),
80  
81      /** Sensor block sub-structure. */
82      SENSOR((token, parser, context, container) -> parser.manageAttitudeDeterminationSensorSection(token.getType() == TokenType.START));
83  
84      /** Processing method. */
85      private final transient TokenProcessor processor;
86  
87      /** Simple constructor.
88       * @param processor processing method
89       */
90      AttitudeDeterminationKey(final TokenProcessor processor) {
91          this.processor = processor;
92      }
93  
94      /** Process an token.
95       * @param token token to process
96       * @param parser ACM file parser
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 AcmParser parser, final ContextBinding context,
102                            final AttitudeDetermination container) {
103         return processor.process(token, parser, context, container);
104     }
105 
106     /** Interface for processing one token. */
107     interface TokenProcessor {
108         /** Process one token.
109          * @param token token to process
110          * @param parser ACM file parser
111          * @param context context binding
112          * @param container container to fill
113          * @return true of token was accepted
114          */
115         boolean process(ParseToken token, AcmParser parser, ContextBinding context, AttitudeDetermination container);
116     }
117 
118 }