serialecho.cpp

00001 /**********************************************************************
00002  * C/C++ Source: serialecho.cc
00003  *
00004  * Defines the methods for the SerialEcho class
00005  *
00006  * @author:  Gary Lawrence Murphy <garym@canada.com>
00007  * Copyright:  2000 TeleDynamics Communications Inc (www.teledyn.com)
00008  ********************************************************************
00009  */
00010 // Copyright (C) 1999-2000 Teledynamics Communications Inc.
00011 //
00012 // This program is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU General Public License as published by
00014 // the Free Software Foundation; either version 2 of the License, or
00015 // (at your option) any later version.
00016 //
00017 // This program is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this program; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00025 
00026 #include "serialecho.h"
00027 #ifndef WIN32
00028 #include <cstdlib>
00029 #endif
00030 
00031 using namespace std;
00032 
00033 SerialEcho::SerialEcho(const char *device,
00034                    int priority, int stacksize) :
00035   TTYSession( device, priority, stacksize ) {
00036 
00037   cout << "Creating SerialEcho" << endl;
00038 
00039   if (!(*this)) {
00040         throw xError();
00041         ::exit(1);
00042   } else {
00043         cout << "modem ready" << endl;
00044   }
00045 
00046   interactive(false);
00047 
00048   if (setSpeed(38400)) cout << getErrorString() << endl;
00049   if (setCharBits(8)) cout << getErrorString() << endl;
00050   if (setParity(Serial::parityNone)) cout << getErrorString() << endl;
00051   if (setStopBits(1)) cout << getErrorString() << endl;
00052   if (setFlowControl(Serial::flowHard)) cout << getErrorString() << endl;
00053 
00054   cout << "config done" << endl;
00055 }
00056 
00057 void SerialEcho::run() {
00058   char* s = new char[getBufferSize()];
00059 
00060   cout << "start monitor" << endl;
00061 
00062   while (s[0] != 'X') {
00063         while (isPending(Serial::pendingInput)) {
00064           cout.put( TTYStream::get() );
00065                 }
00066         sleep(500);
00067   }
00068 
00069   cout << "end of monitor" << endl;
00070 
00071   delete [] s;
00072 
00073   exit();
00074 }
00075 

Generated on Tue Apr 7 05:52:06 2009 for GNU CommonC++ by  doxygen 1.4.7