00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "OrbitPropObserver.h"
00014
00015 using namespace std;
00016
00017
00018 OrbitPropObserver::OrbitPropObserver( )
00019 {
00020 Initialize( );
00021 }
00022
00023
00024
00025
00026
00027 OrbitPropObserver::OrbitPropObserver( TiXmlHandle handle, Whorl* ptr_whorl )
00028 {
00029 m_whorl = ptr_whorl;
00030
00031 Initialize( );
00032
00033
00034 Parse( handle );
00035 }
00036
00037
00038 OrbitPropObserver::~OrbitPropObserver( )
00039 { }
00040
00041
00042
00043 int OrbitPropObserver::Initialize( )
00044 {
00045
00046
00047 static const char HOST[] = "severian.aoe.vt.edu";
00048 static const unsigned short PORT = 30002;
00049
00050 try
00051 {
00052
00053
00054 m_clientSocket = new ClientSocket;
00055 m_clientSocket -> Connect( HOST, PORT );
00056
00057
00058 cerr << "Connected to Propagator Host. " << endl;
00059
00060 }
00061 catch ( SocketException& e )
00062 {
00063 std::cout << "Exception was caught:" << e.description() << "\n";
00064 }
00065
00066 m_ECIVector.initialize(6);
00067
00068
00069 m_vehicleID = 1;
00070
00071
00072 m_currentTime = Now( );
00073
00074
00075 m_acceleration.initialize(3);
00076
00077
00078
00079
00080 m_mass = 100;
00081
00082 return( 0 );
00083 }
00084
00085
00086
00087
00088 void OrbitPropObserver::Parse( TiXmlHandle handle )
00089 {
00090
00091 }
00092
00093
00094 int OrbitPropObserver::Run( )
00095 {
00096 m_currentTime = Now( );
00097
00098
00099 m_ECIVector = GetState( m_clientSocket, m_vehicleID, m_currentTime.GetSeconds( ), m_acceleration, m_mass );
00100
00101
00102 m_SpaceVehicleOsculatingCOE.SetOsculatingOrbitalElements( m_ECIVector/1000 );
00103
00104
00105 m_SpaceVehicleMeanCOE = m_SpaceVehicleOsculatingCOE.GetMeanOrbitalElements( ) ;
00106
00107
00108 m_whorl->SetECI( m_ECIVector );
00109
00110
00111 m_whorl->SetOscCOE( m_SpaceVehicleOsculatingCOE.GetOsculatingOrbitalElements( ) );
00112
00113
00114 m_whorl->SetCOE( m_SpaceVehicleMeanCOE );
00115
00116 return( 0 );
00117 }
00118
00119 Vector OrbitPropObserver::GetState( ClientSocket *_clientSocket, int _vehicleID, double _currentTime, CAMdoubleVector _acceleration, double _newMass )
00120 {
00121 ostringstream dataOut;
00122 dataOut.precision( 18 );
00123 dataOut << "SC" << _vehicleID << " " << "GET_STATE" << " " << _currentTime << " " << _acceleration(1)
00124 << " " << _acceleration(2) << " " << _acceleration(3) << " " << _newMass << endl;
00125
00126
00127 string reply;
00128 try
00129 {
00130
00131 *_clientSocket << dataOut.str( );
00132
00133 *_clientSocket >> reply;
00134 }
00135 catch ( SocketException& e )
00136 {
00137 std::cout << "Exception was caught:" << e.description() << "\n";
00138 }
00139
00140 return ( ParseState( reply ) );
00141 }
00142
00143 Vector OrbitPropObserver::ParseState( string _reply )
00144 {
00145 stringstream parseString;
00146 parseString.str( _reply );
00147
00148 string command;
00149 CAMdoubleVector ECIVector(6);
00150
00151 parseString >> command;
00152
00153 if( command =="Failure" )
00154 {
00155 cerr << "BAD RESPONSE from SERVER " << endl;
00156 }
00157 if( command == "STATE" )
00158 {
00159 for ( int iterator = 1; iterator < 7; iterator++ )
00160 {
00161 parseString >> ECIVector( iterator );
00162 }
00163 }
00164 else
00165 {
00166 cerr << "ERROR in Parsing LOOP" << endl;
00167 }
00168
00169 return ( ECIVector );
00170 };
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183