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  
18  package org.orekit.files.ccsds.ndm.adm.acm;
19  
20  import java.util.Collections;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.orekit.data.DataContext;
25  import org.orekit.files.ccsds.ndm.NdmConstituent;
26  import org.orekit.files.ccsds.ndm.adm.AdmHeader;
27  import org.orekit.files.ccsds.section.Segment;
28  import org.orekit.files.general.AttitudeEphemerisFile;
29  import org.orekit.utils.IERSConventions;
30  import org.orekit.utils.TimeStampedAngularCoordinates;
31  
32  /** This class gathers the informations present in the Attitude Comprehensive Message (ACM).
33   * @author Luc Maisonobe
34   * @since 12.0
35   */
36  public class Acm extends NdmConstituent<AdmHeader, Segment<AcmMetadata, AcmData>>
37      implements AttitudeEphemerisFile<TimeStampedAngularCoordinates, AttitudeStateHistory> {
38  
39      /** Root element for XML messages. */
40      public static final String ROOT = "acm";
41  
42      /** Key for format version. */
43      public static final String FORMAT_VERSION_KEY = "CCSDS_ACM_VERS";
44  
45      /** Attitude line element for XML messages. */
46      public static final String ATT_LINE = "attLine";
47  
48      /** Covariance line element for XML messages. */
49      public static final String COV_LINE = "covLine";
50  
51      /** Default name for unknown object. */
52      public static final String UNKNOWN_OBJECT = "UNKNOWN";
53  
54      /** Simple constructor.
55       * @param header file header
56       * @param segments ile segments
57       * @param conventions IERS conventions
58       * @param dataContext used for creating frames, time scales, etc.
59       */
60      public Acm(final AdmHeader header, final List<Segment<AcmMetadata, AcmData>> segments,
61                 final IERSConventions conventions, final DataContext dataContext) {
62          super(header, segments, conventions, dataContext);
63      }
64  
65      /** Get the metadata from the single {@link #getSegments() segment}.
66       * @return metadata from the single {@link #getSegments() segment}
67       */
68      public AcmMetadata getMetadata() {
69          return getSegments().get(0).getMetadata();
70      }
71  
72      /** Get the data from the single {@link #getSegments() segment}.
73       * @return data from the single {@link #getSegments() segment}
74       */
75      public AcmData getData() {
76          return getSegments().get(0).getData();
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public Map<String, AcmSatelliteEphemeris> getSatellites() {
82          // the ACM file has only one segment and a deep structure
83          // the real ephemeris is buried within the attitude state time history logical block
84          final String name;
85          if (getMetadata().getObjectName() != null) {
86              name = getMetadata().getObjectName();
87          } else if (getMetadata().getInternationalDesignator() != null) {
88              name = getMetadata().getInternationalDesignator();
89          } else if (getMetadata().getObjectDesignator() != null) {
90              name = getMetadata().getObjectDesignator();
91          } else {
92              name = UNKNOWN_OBJECT;
93          }
94          final List<AttitudeStateHistory> histories = getSegments().get(0).getData().getAttitudeBlocks();
95          return (histories == null) ?
96                 Collections.emptyMap() :
97                 Collections.singletonMap(name, new AcmSatelliteEphemeris(name, histories));
98      }
99  
100 }