95 lines
2.0 KiB
C++
95 lines
2.0 KiB
C++
//
|
|
// Socket
|
|
//
|
|
|
|
/* prevent multiple inclusions */
|
|
#ifndef __SerialIO__
|
|
#define __SerialIO__
|
|
|
|
/* includes *****************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
|
|
#include <termios.h>
|
|
#include <sys/time.h>
|
|
|
|
#include "netlib.h"
|
|
|
|
/* defines ******************************************************************/
|
|
|
|
/* macros *******************************************************************/
|
|
|
|
/* structs & typedefs *******************************************************/
|
|
|
|
/* c class definitions ******************************************************/
|
|
|
|
/** \class
|
|
*
|
|
* Serial I/O wrapper and support class, Linux only
|
|
*/
|
|
|
|
class SerialIO {
|
|
// public data
|
|
public:
|
|
|
|
// protected data
|
|
protected:
|
|
|
|
// private data
|
|
private:
|
|
int m_fd; // handle
|
|
unsigned long m_sentcnt; // # bytes sent
|
|
unsigned long m_recvcnt; // # bytes recv
|
|
|
|
// serial config
|
|
struct termios termios;
|
|
|
|
// public methods
|
|
public:
|
|
// constructors
|
|
SerialIO();
|
|
|
|
// destructor
|
|
virtual ~SerialIO();
|
|
|
|
// public methods
|
|
|
|
// control
|
|
int GetFd( void ) { return m_fd; };
|
|
|
|
void SetBaud( int baud );
|
|
void SetCanonical( bool canonical, int bs=0, int wt=0 );
|
|
void Canonical(void) { SetCanonical(true); };
|
|
void NonCanonical(void) { SetCanonical(false); };
|
|
|
|
// i/o
|
|
int Open( const char *dev, int baud );
|
|
int Read( void *buf, int len );
|
|
int Write( const void *buf, int len );
|
|
void Close( void );
|
|
|
|
// status
|
|
unsigned long GetBytesSent(void) {return m_sentcnt;};
|
|
unsigned long GetBytesRecv(void) {return m_recvcnt;};
|
|
|
|
// virtual functions (must be overridden!)
|
|
|
|
// exceptions
|
|
class SerialIOException
|
|
{
|
|
char *toString(void) { return strerror(errno); };
|
|
};
|
|
|
|
// private methods
|
|
private:
|
|
};
|
|
|
|
#endif
|