From a69e2cc976f4e0b762572a6fc3f34f32c46b08d5 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 30 Nov 2001 23:56:28 +0000 Subject: [PATCH] Added Network/opengc.cxx Network/opengc.hxx Network/opengc_data.hxx This is John Wojnaroski's initial implimentation of an interface to the OpenGC glass cockpit displays. --- src/Main/fg_io.cxx | 6 ++ src/Main/options.cxx | 4 + src/Network/Makefile.am | 1 + src/Network/opengc.cxx | 152 ++++++++++++++++++++++++++++++++++++ src/Network/opengc.hxx | 55 +++++++++++++ src/Network/opengc_data.hxx | 73 +++++++++++++++++ 6 files changed, 291 insertions(+) create mode 100644 src/Network/opengc.cxx create mode 100644 src/Network/opengc.hxx create mode 100644 src/Network/opengc_data.hxx diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index 8df8a559a..ba1ce3681 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,11 @@ static FGProtocol *parse_port_config( const string& config ) if ( protocol == "atlas" ) { FGAtlas *atlas = new FGAtlas; io = atlas; + } else if ( protocol == "opengc" ) { + // char wait; + // printf("Parsed opengc\n"); cin >> wait; + FGOpenGC *opengc = new FGOpenGC; + io = opengc; } else if ( protocol == "garmin" ) { FGGarmin *garmin = new FGGarmin; io = garmin; diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 3ede60f65..ee3cf6763 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -798,6 +798,10 @@ parse_option (const string& arg) add_channel( "native_ctrls", arg.substr(15) ); } else if ( arg.find( "--native-fdm=" ) == 0 ) { add_channel( "native_fdm", arg.substr(13) ); + } else if ( arg.find( "--opengc=" ) == 0 ) { + // char stop; + // cout << "Adding channel for OpenGC Display" << endl; cin >> stop; + add_channel( "opengc", arg.substr(10) ); } else if ( arg.find( "--garmin=" ) == 0 ) { add_channel( "garmin", arg.substr(9) ); } else if ( arg.find( "--nmea=" ) == 0 ) { diff --git a/src/Network/Makefile.am b/src/Network/Makefile.am index 361da9c30..5a65aa5fd 100644 --- a/src/Network/Makefile.am +++ b/src/Network/Makefile.am @@ -10,6 +10,7 @@ libNetwork_a_SOURCES = \ native_ctrls.cxx native_ctrls.hxx \ native_fdm.cxx native_fdm.hxx \ nmea.cxx nmea.hxx \ + opengc.cxx opengc.hxx opengc_data.hxx \ props.cxx props.hxx \ pve.cxx pve.hxx \ raw_ctrls.hxx raw_fdm.hxx \ diff --git a/src/Network/opengc.cxx b/src/Network/opengc.cxx new file mode 100644 index 000000000..c2524b49a --- /dev/null +++ b/src/Network/opengc.cxx @@ -0,0 +1,152 @@ +// opengc.cxx -- +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include +#include + +#include + +#include "opengc.hxx" +#include +#include
+#include + +SG_USING_STD(vector); + +FGOpenGC::FGOpenGC() { +} + +FGOpenGC::~FGOpenGC() { +} + +// open hailing frequencies +bool FGOpenGC::open() { + if ( is_enabled() ) { + SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel " + << "is already in use, ignoring" ); + return false; + } + + SGIOChannel *io = get_io_channel(); + + if ( ! io->open( get_direction() ) ) { + SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." ); + return false; + } + + set_enabled( true ); + + return true; +} + + +static void collect_data( const FGInterface *fdm, ogcFGData *data ) { + //static void collect_data( ogcFGData *data ) { + + FGEngInterface *p_engine[4]; // four is enough unless you're a BUF + + p_engine[0] = cur_fdm_state->get_engine(0); + + data->latitude = fdm->get_Longitude_deg(); + data->longitude = cur_fdm_state->get_Latitude_deg(); + + data->pitch = cur_fdm_state->get_Theta_deg(); + data->bank = cur_fdm_state->get_Phi_deg(); + data->heading = cur_fdm_state->get_Psi_deg(); + data->altitude = cur_fdm_state->get_Altitude(); + data->v_kcas = cur_fdm_state->get_V_calibrated_kts(); + data->vvi = cur_fdm_state->get_Climb_Rate(); + + data->magvar = globals->get_mag()->get_magvar(); + +// engine data, for now set the 2nd engine equal to the first + + data->rpm[0] = p_engine[0]->get_RPM(); + data->rpm[1] = p_engine[0]->get_RPM(); + + data->epr[0] = p_engine[0]->get_Manifold_Pressure(); + data->epr[1] = p_engine[0]->get_Manifold_Pressure(); + + data->egt[0] = p_engine[0]->get_EGT(); + data->egt[1] = p_engine[0]->get_EGT(); + + data->oil_pressure[0] = p_engine[0]->get_Oil_Pressure(); + data->oil_pressure[1] = p_engine[0]->get_Oil_Pressure(); + + +// navigation data +// Once OPenGC develops a comparable navaids database some of this will not be required + +//data->nav1_ident = current_radiostack->get_nav1_ident(); + data->nav1_freq = current_radiostack->get_nav1_freq(); + data->nav1_radial = current_radiostack->get_nav1_sel_radial(); + data->nav1_course_dev = current_radiostack->get_nav1_heading_needle_deflection(); + + //data->nav1_ident = current_radiostack->get_nav1_ident(); + data->nav2_freq = current_radiostack->get_nav2_freq(); + data->nav2_radial = current_radiostack->get_nav2_sel_radial(); + data->nav2_course_dev = current_radiostack->get_nav2_heading_needle_deflection(); + +} + +static void distribute_data( const ogcFGData *data, FGInterface *chunk ) { + // just a place holder until the CDU is developed + +} + +// process work for this port +bool FGOpenGC::process() { + SGIOChannel *io = get_io_channel(); + int length = sizeof(buf); + + if ( get_direction() == SG_IO_OUT ) { + collect_data( cur_fdm_state, &buf ); + //collect_data( &buf ); + if ( ! io->write( (char *)(& buf), length ) ) { + SG_LOG( SG_IO, SG_ALERT, "Error writing data." ); + return false; + } + } else if ( get_direction() == SG_IO_IN ) { + if ( io->get_type() == sgFileType ) { + if ( io->read( (char *)(& buf), length ) == length ) { + SG_LOG( SG_IO, SG_DEBUG, "Success reading data." ); + distribute_data( &buf, cur_fdm_state ); + } + } else { + while ( io->read( (char *)(& buf), length ) == length ) { + SG_LOG( SG_IO, SG_DEBUG, "Success reading data." ); + distribute_data( &buf, cur_fdm_state ); + } + } + } + + return true; +} + + +// close the channel +bool FGOpenGC::close() { + SGIOChannel *io = get_io_channel(); + + set_enabled( false ); + + if ( ! io->close() ) { + return false; + } + + return true; +} diff --git a/src/Network/opengc.hxx b/src/Network/opengc.hxx new file mode 100644 index 000000000..33266cc6d --- /dev/null +++ b/src/Network/opengc.hxx @@ -0,0 +1,55 @@ +// opengc.hxx -- +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + + +#ifndef _FG_OPENGC_HXX +#define _FG_OPENGC_HXX + +#include + +#include STL_STRING + +#include + +#include "protocol.hxx" +#include "opengc_data.hxx" + +class FGOpenGC : public FGProtocol, public FGInterface, public FGEngInterface { + + ogcFGData buf; + int length; + +public: + + FGOpenGC(); + ~FGOpenGC(); + + // open hailing frequencies + bool open(); + + // process work for this port + bool process(); + + // close the channel + bool close(); + + +}; + +#endif // _FG_OPENGC_HXX + + diff --git a/src/Network/opengc_data.hxx b/src/Network/opengc_data.hxx new file mode 100644 index 000000000..f057139ac --- /dev/null +++ b/src/Network/opengc_data.hxx @@ -0,0 +1,73 @@ +// opengc.hxx -- define shared flight model parameters +// +// Version 1.0 by J. Wojnaroski for interface to Open Glass Displays +// Date: Nov 18,2001 + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#ifndef _OPENGC_HXX +#define _OPENGC_HXX + +#ifndef __cplusplus +# error This library requires C++ +#endif + +class ogcFGData { + +public: + + // flight parameters + + double pitch; + double bank; + double heading; + double altitude; + double altitude_agl; + double v_kcas; + double groundspeed; + double vvi; + + // position + + double latitude; + double longitude; + double magvar; + + // engine data + + double rpm[4]; + double epr[4]; + double egt[4]; + double fuel_flow[4]; + double oil_pressure[4]; + + // navigation data + + double nav1_freq; + double nav1_radial; + double nav1_course_dev; + + double nav2_freq; + double nav2_radial; + double nav2_course_dev; + + // some other locations to add stuff in + double d_ogcdata[16]; + float f_ogcdata[16]; + int i_ogcdata[16]; +}; + +#endif // _OPENGC_HXX -- 2.39.5