]> git.mxchange.org Git - flightgear.git/blob - src/Network/opengc.cxx
Revert to pre-wind-sticking ground reaction forces until they can be debugged.
[flightgear.git] / src / Network / opengc.cxx
1 // opengc.cxx -- 
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16 //
17
18 #include <simgear/debug/logstream.hxx>
19 #include <simgear/io/iochannel.hxx>
20
21 #include <vector>
22
23 #include "opengc.hxx"
24 #include <FDM/flight.hxx>
25 #include <Main/globals.hxx>
26 #include <Cockpit/radiostack.hxx>
27
28 SG_USING_STD(vector);
29
30 FGOpenGC::FGOpenGC() {
31 }
32
33 FGOpenGC::~FGOpenGC() {
34 }
35
36 // open hailing frequencies
37 bool FGOpenGC::open() {
38     if ( is_enabled() ) {
39         SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel " 
40                 << "is already in use, ignoring" );
41         return false;
42     }
43
44     SGIOChannel *io = get_io_channel();
45
46     if ( ! io->open( get_direction() ) ) {
47         SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." );
48         return false;
49     }
50
51     set_enabled( true );
52
53     return true;
54 }
55
56
57 static void collect_data( const FGInterface *fdm, ogcFGData *data ) {
58     //static void collect_data( ogcFGData *data ) {
59
60     FGEngInterface      *p_engine[4];  // four is enough unless you're a BUF
61
62     p_engine[0] = cur_fdm_state->get_engine(0);
63
64     data->latitude = fdm->get_Longitude_deg();   
65     data->longitude = cur_fdm_state->get_Latitude_deg();
66
67     data->pitch = cur_fdm_state->get_Theta_deg();
68     data->bank = cur_fdm_state->get_Phi_deg();
69     data->heading = cur_fdm_state->get_Psi_deg();
70     data->altitude = cur_fdm_state->get_Altitude();
71     data->v_kcas = cur_fdm_state->get_V_calibrated_kts();
72     data->vvi = cur_fdm_state->get_Climb_Rate();
73
74     data->magvar = globals->get_mag()->get_magvar();
75
76 // engine data, for now set the 2nd engine equal to the first
77
78     data->rpm[0] = p_engine[0]->get_RPM();
79     data->rpm[1] = p_engine[0]->get_RPM();
80
81     data->epr[0] = p_engine[0]->get_Manifold_Pressure();
82     data->epr[1] = p_engine[0]->get_Manifold_Pressure();
83
84     data->egt[0] = p_engine[0]->get_EGT();
85     data->egt[1] = p_engine[0]->get_EGT();
86
87     data->oil_pressure[0] = p_engine[0]->get_Oil_Pressure();
88     data->oil_pressure[1] = p_engine[0]->get_Oil_Pressure();
89
90
91 // navigation data
92 // Once OPenGC develops a comparable navaids database some of this will not be required
93
94 //data->nav1_ident = current_radiostack->get_nav1_ident();
95     data->nav1_freq = current_radiostack->get_nav1_freq();
96     data->nav1_radial = current_radiostack->get_nav1_sel_radial();
97     data->nav1_course_dev = current_radiostack->get_nav1_heading_needle_deflection(); 
98
99     //data->nav1_ident = current_radiostack->get_nav1_ident();
100     data->nav2_freq = current_radiostack->get_nav2_freq();
101     data->nav2_radial = current_radiostack->get_nav2_sel_radial();
102     data->nav2_course_dev = current_radiostack->get_nav2_heading_needle_deflection(); 
103
104 }
105
106 static void distribute_data( const ogcFGData *data, FGInterface *chunk ) {
107     // just a place holder until the CDU is developed
108         
109 }
110
111 // process work for this port
112 bool FGOpenGC::process() {
113     SGIOChannel *io = get_io_channel();
114     int length = sizeof(buf);
115
116     if ( get_direction() == SG_IO_OUT ) {
117         collect_data( cur_fdm_state, &buf );
118         //collect_data( &buf );
119         if ( ! io->write( (char *)(& buf), length ) ) {
120             SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
121             return false;
122         }
123     } else if ( get_direction() == SG_IO_IN ) {
124         if ( io->get_type() == sgFileType ) {
125             if ( io->read( (char *)(& buf), length ) == length ) {
126                 SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
127                 distribute_data( &buf, cur_fdm_state );
128             }
129         } else {
130             while ( io->read( (char *)(& buf), length ) == length ) {
131                 SG_LOG( SG_IO, SG_DEBUG, "Success reading data." );
132                 distribute_data( &buf, cur_fdm_state );
133             }
134         }
135     }
136
137     return true;
138 }
139
140
141 // close the channel
142 bool FGOpenGC::close() {
143     SGIOChannel *io = get_io_channel();
144
145     set_enabled( false );
146
147     if ( ! io->close() ) {
148         return false;
149     }
150
151     return true;
152 }