/** \file
 *
 *  Contains the SimResultStruct class declaration.
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef SIMRESULTSTRUCT_H_
#define SIMRESULTSTRUCT_H_

/**
 *  A struct of values that is passed from the Simulator to the LRAUV,
 *  with the results from one timestep of the simulator.
 *
 *  \ingroup modules_simulator
 */
#include <sys/types.h>

struct SimResultStruct
{
    static const int MAX_SCIENCE_VALUES = 4;

    union
    {
        char errorMessage_[ 50 * 4 ];
        struct
        {
            int8_t errorPad_;         // 4-byte position 0
            int16_t utmZone_;
            int8_t northernHemi_;
            float propOmega_;         // 4-byte position 1
            float propThrust_;        // 4-byte position 2
            float propTorque_;        // 4-byte position 3
            float rudderAngle_;       // 4-byte position 4
            float elevatorAngle_;     // 4-byte position 5
            float massPosition_;      // 4-byte position 6
            float buoyancyPosition_;  // 4-byte position 7
            float depth_;             // 4-byte position 8
            float roll_;              // 4-byte position 9
            float pitch_;             // 4-byte position 10
            float heading_;           // 4-byte position 11
            float speed_;             // 4-byte position 12
            double latitudeDeg_;      // 8-byte position 13
            double longitudeDeg_;     // 8-byte position 15
            float netBuoy_;           // 4-byte position 16
            float forceX_;            // 4-byte position 17
            float forceY_;            // 4-byte position 18
            float forceZ_;            // 4-byte position 19
            double posX_;             // 8-byte position 20
            double posY_;             // 8-byte position 22
            float posZ_;              // 4-byte position 24
            float posRoll_;           // 4-byte position 25
            float posPitch_;          // 4-byte position 26
            float posHeading_;        // 4-byte position 27
            float posXDot_;           // 4-byte position 28
            float posYDot_;           // 4-byte position 29
            float posZDot_;           // 4-byte position 30
            float rateU_;             // 4-byte position 31
            float rateV_;             // 4-byte position 32
            float rateW_;             // 4-byte position 33
            float rateP_;             // 4-byte position 34
            float rateQ_;             // 4-byte position 35
            float rateR_;             // 4-byte position 36
            float northCurrent_;      // 4-byte position 37
            float eastCurrent_;       // 4-byte position 38
            float vertCurrent_;       // 4-byte position 39
            float magneticVariation_; // 4-byte position 40
            float soundSpeed_;        // 4-byte position 41
            float temperature_;       // 4-byte position 42
            float salinity_;          // 4-byte position 43
            float density_;           // 4-byte position 44
            float values_[MAX_SCIENCE_VALUES]; // 4-byte position 45-48
            double timeGz_;           // 4-byte position 49-50
            double batteryVoltage_;   // 8-byte position 51
            double batteryCurrent_;   // 8-byte position 53
            double batteryCharge_;    // 8-byte position 55
            double batteryPercentage_;// 8-byte position 57
        };
    };

    /// Constructor
    SimResultStruct()
        : errorPad_( 0 ),
          utmZone_( -1 ),
          northernHemi_( 0 ),
          propOmega_( nanf( "" ) ),
          propThrust_( nanf( "" ) ),
          propTorque_( nanf( "" ) ),
          rudderAngle_( nanf( "" ) ),
          elevatorAngle_( nanf( "" ) ),
          massPosition_( nanf( "" ) ),
          buoyancyPosition_( nanf( "" ) ),
          depth_( nanf( "" ) ),
          roll_( nanf( "" ) ),
          pitch_( nanf( "" ) ),
          heading_( nanf( "" ) ),
          speed_( nanf( "" ) ),
          latitudeDeg_( nan( "" ) ),
          longitudeDeg_( nan( "" ) ),
          netBuoy_( nanf( "" ) ),
          forceX_( nanf( "" ) ),
          forceY_( nanf( "" ) ),
          forceZ_( nanf( "" ) ),
          posX_( nanf( "" ) ),
          posY_( nanf( "" ) ),
          posZ_( nanf( "" ) ),
          posRoll_( nanf( "" ) ),
          posPitch_( nanf( "" ) ),
          posHeading_( nanf( "" ) ),
          posXDot_( nanf( "" ) ),
          posYDot_( nanf( "" ) ),
          posZDot_( nanf( "" ) ),
          rateU_( nanf( "" ) ),
          rateV_( nanf( "" ) ),
          rateW_( nanf( "" ) ),
          rateP_( nanf( "" ) ),
          rateQ_( nanf( "" ) ),
          rateR_( nanf( "" ) ),
          northCurrent_( nanf( "" ) ),
          eastCurrent_( nanf( "" ) ),
          vertCurrent_( nanf( "" ) ),
          magneticVariation_( nanf( "" ) ),
          soundSpeed_( nanf( "" ) ),
          temperature_( nanf( "" ) ),
          salinity_( nanf( "" ) ),
          density_( nanf( "" ) ),
          timeGz_( nanf( "" ) ),
          batteryVoltage_( nanf( "" ) ),
          batteryCurrent_( nanf( "" ) ),
          batteryCharge_( nanf( "" ) ),
          batteryPercentage_( nanf( "" ) )
    {
        *errorMessage_ = 0;
        for( int i = 0; i < MAX_SCIENCE_VALUES; ++i )
        {
            values_[i] = nanf( "" );
        }
    }

};

#endif /* SIMRESULTSTRUCT_H_ */
