blob: 17bbba721aa31d3353b70b037e22b73a5c4034ee [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001/**********************************************************************
2 * C/C++ Source: serialecho.cc
3 *
4 * Defines the methods for the SerialEcho class
5 *
6 * @author: Gary Lawrence Murphy <garym@canada.com>
7 * Copyright: 2000 TeleDynamics Communications Inc (www.teledyn.com)
8 ********************************************************************
9 */
10// Copyright (C) 1999-2000 Teledynamics Communications Inc.
11//
12// This program is free software; you can redistribute it and/or modify
13// it under the terms of the GNU General Public License as published by
14// the Free Software Foundation; either version 2 of the License, or
15// (at your option) any later version.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26#include "serialecho.h"
27#ifndef WIN32
28#include <cstdlib>
29#endif
30
31using namespace std;
32
33SerialEcho::SerialEcho(const char *device,
34 int priority, int stacksize) :
35 TTYSession( device, priority, stacksize ) {
36
37 cout << "Creating SerialEcho" << endl;
38
39 if (!(*this)) {
40 throw xError();
41 ::exit(1);
42 } else {
43 cout << "modem ready" << endl;
44 }
45
46 interactive(false);
47
48 if (setSpeed(38400)) cout << getErrorString() << endl;
49 if (setCharBits(8)) cout << getErrorString() << endl;
50 if (setParity(Serial::parityNone)) cout << getErrorString() << endl;
51 if (setStopBits(1)) cout << getErrorString() << endl;
52 if (setFlowControl(Serial::flowHard)) cout << getErrorString() << endl;
53
54 cout << "config done" << endl;
55}
56
57void SerialEcho::run() {
58 char* s = new char[getBufferSize()];
59
60 cout << "start monitor" << endl;
61
62 while (s[0] != 'X') {
63 while (isPending(Serial::pendingInput)) {
64 cout.put( TTYStream::get() );
65 }
66 sleep(500);
67 }
68
69 cout << "end of monitor" << endl;
70
71 delete [] s;
72
73 exit();
74}
75