00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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