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.definitions;
18  
19  import org.orekit.errors.OrekitException;
20  import org.orekit.errors.OrekitMessages;
21  
22  /** Frames used in CCSDS Attitude Data Messages for the spacecraft body.
23   * @author Luc Maisonobe
24   * @since 11.0
25   */
26  public class SpacecraftBodyFrame {
27  
28      /** Equipment on which the frame is located. */
29      public enum BaseEquipment {
30  
31          /** Accelerometer. */
32          ACC,
33  
34          /** Actuator: could denote reaction wheels, solar arrays, thrusters, etc.. */
35          ACTUATOR,
36  
37          /** Autonomous Star Tracker. */
38          AST,
39  
40          /** Coarse Sun Sensor. */
41          CSS,
42  
43          /** Digital Sun Sensor. */
44          DSS,
45  
46          /** Earth Sensor Assembly. */
47          ESA,
48  
49          /** Gyro reference frame (this name was used in ADM V1.0 (CCSDS 504.0-B-1). */
50          GYRO,
51  
52          /** Gyro reference frame (this name is used in SANA registry https://sanaregistry.org/r/spacecraft_body_reference_frames/). */
53          GYRO_FRAME,
54  
55          /** Inertial Measurement Unit. */
56          IMU_FRAME,
57  
58          /** Instrument. */
59          INSTRUMENT,
60  
61          /** Magnetic Torque Assembly. */
62          MTA,
63  
64          /** Reaction Wheel. */
65          RW,
66  
67          /** Solar Array. */
68          SA,
69  
70          /** Spacecraft Body. */
71          SC_BODY,
72  
73          /** Sensor. */
74          SENSOR,
75  
76          /** Star Tracker. */
77          STARTRACKER,
78  
79          /** Three Axis Magnetometer. */
80          TAM;
81  
82      }
83  
84      /** Equipment on which the frame is located. */
85      private final BaseEquipment baseEquipment;
86  
87      /** Frame label. */
88      private final String label;
89  
90      /** Simple constructor.
91       * @param baseEquipment equipment on which the frame is located
92       * @param label frame label
93       */
94      public SpacecraftBodyFrame(final BaseEquipment baseEquipment, final String label) {
95          this.baseEquipment = baseEquipment;
96          this.label         = label;
97      }
98  
99      /** Get the quipment on which the frame is located.
100      * @return equipment on which the frame is located
101      */
102     public BaseEquipment getBaseEquipment() {
103         return baseEquipment;
104     }
105 
106     /** Get the frame label.
107      * @return frame label
108      */
109     public String getLabel() {
110         return label;
111     }
112 
113     /** {@inheritDoc}
114      * <p>
115      * The CCSDS composite name combines the {@link #getBaseEquipment() base equipment}
116      * and the {@link #getLabel()}
117      * </p>
118      * @return CCSDS composite name
119      */
120     @Override
121     public String toString() {
122         return getBaseEquipment().name() + "_" + getLabel();
123     }
124 
125     /** Build an instance from a normalized descriptor.
126      * <p>
127      * Normalized strings have '_' characters replaced by spaces,
128      * and multiple spaces collapsed as one space only.
129      * </p>
130      * @param descriptor normalized descriptor
131      * @return parsed body frame
132      */
133     public static SpacecraftBodyFrame parse(final String descriptor) {
134         final int separatorIndex = descriptor.lastIndexOf('_');
135         if (separatorIndex >= 0) {
136             try {
137                 final String equipmentName = descriptor.substring(0, separatorIndex);
138                 return new SpacecraftBodyFrame(BaseEquipment.valueOf(equipmentName),
139                                           descriptor.substring(separatorIndex + 1));
140             } catch (IllegalArgumentException iae) {
141                 // ignored, errors are handled below
142             }
143         }
144         throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME, descriptor);
145     }
146 
147 }