SpinStabilizedWriter.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 java.io.IOException;

  19. import org.orekit.files.ccsds.definitions.Units;
  20. import org.orekit.files.ccsds.ndm.adm.AttitudeEndpoints;
  21. import org.orekit.files.ccsds.section.AbstractWriter;
  22. import org.orekit.files.ccsds.utils.generation.Generator;
  23. import org.orekit.utils.units.Unit;

  24. /** Writer for spin stabilized data.
  25.  * @author Luc Maisonobe
  26.  * @since 11.0
  27.  */
  28. class SpinStabilizedWriter extends AbstractWriter {

  29.     /** Format version.
  30.      * @since 12.0
  31.      */
  32.     private final double formatVersion;

  33.     /** Spin stabilized block. */
  34.     private final SpinStabilized spinStabilized;

  35.     /** Create a writer.
  36.      * @param formatVersion format version
  37.      * @param xmlTag name of the XML tag surrounding the section
  38.      * @param kvnTag name of the KVN tag surrounding the section (may be null)
  39.      * @param spinStabilized spin stabilized data to write
  40.      */
  41.     SpinStabilizedWriter(final double formatVersion, final String xmlTag, final String kvnTag,
  42.                          final SpinStabilized spinStabilized) {
  43.         super(xmlTag, kvnTag);
  44.         this.formatVersion  = formatVersion;
  45.         this.spinStabilized = spinStabilized;
  46.     }

  47.     /** {@inheritDoc} */
  48.     @Override
  49.     protected void writeContent(final Generator generator) throws IOException {

  50.         generator.writeComments(spinStabilized.getComments());

  51.         // endpoints
  52.         if (formatVersion < 2.0) {
  53.             generator.writeEntry(SpinStabilizedKey.SPIN_FRAME_A.name(), spinStabilized.getEndpoints().getFrameA().getName(), null, true);
  54.             generator.writeEntry(SpinStabilizedKey.SPIN_FRAME_B.name(), spinStabilized.getEndpoints().getFrameB().getName(), null, true);
  55.             generator.writeEntry(SpinStabilizedKey.SPIN_DIR.name(),
  56.                                  spinStabilized.getEndpoints().isA2b() ? AttitudeEndpoints.A2B : AttitudeEndpoints.B2A,
  57.                                                                        null, true);
  58.         } else {
  59.             generator.writeEntry(SpinStabilizedKey.REF_FRAME_A.name(), spinStabilized.getEndpoints().getFrameA().getName(), null, true);
  60.             generator.writeEntry(SpinStabilizedKey.REF_FRAME_B.name(), spinStabilized.getEndpoints().getFrameB().getName(), null, true);
  61.         }

  62.         // spin
  63.         generator.writeEntry(SpinStabilizedKey.SPIN_ALPHA.name(),     spinStabilized.getSpinAlpha(), Unit.DEGREE,        true);
  64.         generator.writeEntry(SpinStabilizedKey.SPIN_DELTA.name(),     spinStabilized.getSpinDelta(), Unit.DEGREE,        true);
  65.         generator.writeEntry(SpinStabilizedKey.SPIN_ANGLE.name(),     spinStabilized.getSpinAngle(), Unit.DEGREE,        true);
  66.         generator.writeEntry(SpinStabilizedKey.SPIN_ANGLE_VEL.name(), spinStabilized.getSpinAngleVel(), Units.DEG_PER_S, true);

  67.         if (spinStabilized.hasMomentum()) {
  68.             // momentum
  69.             generator.writeEntry(SpinStabilizedKey.MOMENTUM_ALPHA.name(), spinStabilized.getMomentumAlpha(), Unit.DEGREE,     true);
  70.             generator.writeEntry(SpinStabilizedKey.MOMENTUM_DELTA.name(), spinStabilized.getMomentumDelta(), Unit.DEGREE,     true);
  71.             generator.writeEntry(SpinStabilizedKey.NUTATION_VEL.name(),   spinStabilized.getNutationVel(),   Units.DEG_PER_S, true);
  72.         } else if (spinStabilized.hasNutation()) {
  73.             // nutation
  74.             generator.writeEntry(SpinStabilizedKey.NUTATION.name(),       spinStabilized.getNutation(),       Unit.DEGREE, true);
  75.             generator.writeEntry(SpinStabilizedKey.NUTATION_PER.name(),   spinStabilized.getNutationPeriod(), Unit.SECOND, true);
  76.             generator.writeEntry(SpinStabilizedKey.NUTATION_PHASE.name(), spinStabilized.getNutationPhase(),  Unit.DEGREE, true);
  77.         }

  78.     }

  79. }