1998-11-16 13:53:01 +00:00
|
|
|
// serial.hxx -- Unix serial I/O support
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started November 1998.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1998 Curtis L. Olson - curt@flightgear.org
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _SERIAL_HXX
|
|
|
|
#define _SERIAL_HXX
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
# error This library requires C++
|
|
|
|
#endif
|
|
|
|
|
1999-02-02 20:13:23 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
1998-11-16 13:53:01 +00:00
|
|
|
|
1999-02-02 20:13:23 +00:00
|
|
|
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
1998-11-16 13:53:01 +00:00
|
|
|
|
1999-02-26 22:07:53 +00:00
|
|
|
#include <Include/compiler.h>
|
|
|
|
#include STL_STRING
|
|
|
|
FG_USING_STD(string);
|
|
|
|
|
1998-11-16 13:53:01 +00:00
|
|
|
// if someone know how to do this all with C++ streams let me know
|
1998-11-30 17:15:29 +00:00
|
|
|
// #include <stdio.h>
|
1998-11-16 13:53:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class fgSERIAL
|
|
|
|
{
|
1999-02-02 20:13:23 +00:00
|
|
|
#if defined( WIN32 ) && !defined( __CYGWIN__) && !defined( __CYGWIN32__ )
|
|
|
|
typedef HANDLE fd_type;
|
|
|
|
#else
|
|
|
|
typedef int fd_type;
|
|
|
|
#endif
|
1998-11-16 13:53:01 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
1999-02-02 20:13:23 +00:00
|
|
|
fd_type fd;
|
1998-11-16 13:53:01 +00:00
|
|
|
bool dev_open;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
fgSERIAL();
|
|
|
|
fgSERIAL(const string& device, int baud);
|
|
|
|
|
|
|
|
~fgSERIAL();
|
|
|
|
|
|
|
|
bool open_port(const string& device);
|
|
|
|
bool close_port();
|
|
|
|
bool set_baud(int baud);
|
|
|
|
string read_port();
|
|
|
|
int write_port(const string& value);
|
|
|
|
|
|
|
|
inline bool is_enabled() { return dev_open; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _SERIAL_HXX
|
|
|
|
|
|
|
|
|