/********************************************************************/ /* Program Assignment: driver2 for cp */ /* Name: cmo */ /* Date: Sept. 25, 2003 */ /* Description: Illustrates access of array entries as */ /* doubles or char */ /********************************************************************/ /********************************************************************/ /* Listing Contents: */ /* General comments */ /* Reuse Instructions */ /* Compilation Instructions */ /* Source Code */ /********************************************************************/ /********************************************************************/ /* General comments */ /* See GCS spec, pp. 59-62 for requirements. */ /* All page number mentioned refer to this document. */ /********************************************************************/ /********************************************************************/ /* Reuse Instructions: */ /* Limited potential */ /********************************************************************/ /********************************************************************/ /* Compilation Instructions: */ /* This program can be compiled by itself using: */ /* g++ -g -o driverv1 driver2.cpp cpv3.o */ /* However, to test the module a Makefile should be */ /* used to link it with a test harness and a data file */ /* must be used to input data. GCS will use this */ /* module within its own format */ /********************************************************************/ using namespace std; #include // Give access to declartations for global variables #include "/home/cs350/term.projects/include.files/external.h" #include "/home/cs350/term.projects/include.files/guidance_state.h" #include "/home/cs350/term.projects/include.files/run_parameters.h" #include "/home/cs350/term.projects/include.files/sensor_output.h" // Declare globals struct guidance_state gs; struct external ex; struct run_parameters rp; struct sensor_output so; extern void cp(); int main() { // Set up vars so that ex.packet can be treated both as array of // 16 bit ints with the name ex.packet and 8 bit chars with the // name char_packet. char *char_packet; char_packet = (char *) ex.packet; // init some vars that effect cp logic. for ( int i=0; i<3; i++ ) ex.ae_cmd[i] = i; gs.ae_status = 1; gs.ae_temp = 2; for ( int i=0; i<5; i++ ) so.ar_altitude[i] = i+20; for ( int i=0; i<4; i++ ) gs.ar_status[i] = 0; so.atmospheric_temp=25; for ( int i=0; i<3; i++ ) for ( int j=0; j<5; j++ ) so.a_acceleration[i][j] = i+j; for ( int i=0; i<3; i++ ) for ( int j=0; j<3; j++ ) gs.a_status[i][j]=0; ex.chute_released = 1; rp.comm_sync_pattern = 123; gs.contour_crossed = 1; gs.c_status = 0; ex.frame_counter = 10; for ( int i=0; i< 5; i++ ) gs.gp_altitude[i] = i; for ( int i=0; i<3; i++ ) for ( int j=0; j<3; j++ ) for ( int k=0; k<5; k++ ) gs.gp_attitude[i][j][k] = i+j+k; gs.gp_phase = 1; for ( int i=0; i<3; i++ ) for ( int j=0; j<3; j++ ) gs.gp_rotation[i][j] = i+j; for ( int i=0; i<3; i++ ) for ( int j=0; j<5; j++ ) gs.gp_velocity[i][j] = i+j; for ( int i=0; i<3; i++ ) for ( int j=0; j<3; j++ ) gs.gp_rotation[i][j] = i+j; for ( int i=0; i<4; i++ ) gs.frame_beam_unlocked[i] = i; gs.g_status = 0; for ( int i=0; i<5; i++ ) gs.k_alt[i] = i; for ( int i=0; i<3; i++ ) for ( int j=0; j<3; j++ ) for ( int k=0; k<5; k++ ) gs.k_matrix[i][j][k] = i+j+k; gs.pe_integral = 5; ex.re_cmd = 1; gs.re_status = 0; cout << "Enter an int value for subframe_counter (1, 2, or 3)" << endl; cin >> ex.subframe_counter; for ( int i=0; i<4; i++ ) gs.tdlr_state[i] = i; for ( int i=0; i<4; i++ ) gs.tdlr_status[i] = i; for ( int i=0; i<3; i++ ) for ( int j=0; j<5; j++ ) so.tdlr_velocity[i][j] = i+j; so.td_sensed = 0; gs.tds_status = 0; gs.te_integral = 1.0; for ( int i=0; i<2; i++ ) gs.ts_status[i] = i; gs.velocity_error = 1.0; gs.ye_integral = 1.0; cp(); // Print part of packet. for ( int i=0; i<15; i++ ) cout << "ex.packet[" << i << "] = " << ex.packet[i] << endl; // Extract double from packet array double ExtVal; char * doubleArray; doubleArray = (char *) &ExtVal; for ( int i = 0; i<8; i++ ) doubleArray[ i ] = char_packet[ i+ 7 ]; cout << "so.ar_altitude[0]: " << so.ar_altitude[0] << endl; cout << "GetPacket val: " << ExtVal << endl; }