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 
00028 using namespace std;
00029 
00030 SerialEcho::SerialEcho(const char *device, 
00031                        int priority, int stacksize) :
00032   TTYSession( device, priority, stacksize ) {
00033 
00034   cout << "Creating SerialEcho" << endl;
00035 
00036   if (!(*this)) {
00037     throw xError();
00038     ::exit(1);
00039   } else {
00040     cout << "modem ready" << endl;
00041   }
00042 
00043   interactive(false);
00044 
00045   if (setSpeed(38400)) cout << getErrorString() << endl;
00046   if (setCharBits(8)) cout << getErrorString() << endl;
00047   if (setParity(Serial::parityNone)) cout << getErrorString() << endl;
00048   if (setStopBits(1)) cout << getErrorString() << endl;
00049   if (setFlowControl(Serial::flowHard)) cout << getErrorString() << endl;
00050 
00051   cout << "config done" << endl;
00052 }
00053 
00054 void SerialEcho::run() {
00055   char* s = new char[getBufferSize()];
00056 
00057   cout << "start monitor" << endl;
00058 
00059   while (s[0] != 'X') {
00060     while (isPending(Serial::pendingInput)) {
00061       cout.put( TTYStream::get() );
00062     } 
00063     sleep(500);
00064   }
00065 
00066   cout << "end of monitor" << endl;
00067 
00068   delete [] s;
00069   
00070   exit();
00071 }
00072 

Generated on Thu Nov 9 19:30:51 2006 for GNU CommonC++ by  doxygen 1.5.1