1 // native.cxx -- FGFS "Native" protocal class
3 // Written by Curtis Olson, started November 1999.
5 // Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <simgear/debug/logstream.hxx>
25 #include <simgear/math/fg_geodesy.hxx>
26 #include <simgear/timing/fg_time.hxx>
28 #include "iochannel.hxx"
32 FGNative::FGNative() {
35 FGNative::~FGNative() {
39 // open hailing frequencies
40 bool FGNative::open() {
42 FG_LOG( FG_IO, FG_ALERT, "This shouldn't happen, but the channel "
43 << "is already in use, ignoring" );
47 FGIOChannel *io = get_io_channel();
49 if ( ! io->open( get_direction() ) ) {
50 FG_LOG( FG_IO, FG_ALERT, "Error opening channel communication layer." );
60 // process work for this port
61 bool FGNative::process() {
62 FGIOChannel *io = get_io_channel();
63 int length = sizeof(*cur_fdm_state);
65 if ( get_direction() == out ) {
66 // cout << "size of cur_fdm_state = " << length << endl;
68 if ( ! io->write( (char *)(& buf), length ) ) {
69 FG_LOG( FG_IO, FG_ALERT, "Error writing data." );
72 } else if ( get_direction() == in ) {
73 if ( io->get_type() == fgFileType ) {
74 if ( io->read( (char *)(& buf), length ) == length ) {
75 FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
79 while ( io->read( (char *)(& buf), length ) == length ) {
80 FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
91 bool FGNative::close() {
92 FGIOChannel *io = get_io_channel();
96 if ( ! io->close() ) {