summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp142
-rw-r--r--noncore/apps/opie-console/filetransfer.h38
-rw-r--r--noncore/apps/opie-console/io_layer.cpp3
-rw-r--r--noncore/apps/opie-console/io_layer.h7
-rw-r--r--noncore/apps/opie-console/io_serial.cpp7
-rw-r--r--noncore/apps/opie-console/io_serial.h1
-rw-r--r--noncore/apps/opie-console/sz_transfer.cpp121
7 files changed, 212 insertions, 107 deletions
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
new file mode 100644
index 0000000..78982bd
--- a/dev/null
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -0,0 +1,142 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <errno.h>
4#include <fcntl.h>
5#include <unistd.h>
6
7#include <qcstring.h>
8#include <qsocketnotifier.h>
9
10#include <opie/oprocess.h>
11
12#include "filetransfer.h"
13
14bool FileTransfer::terminate = false;
15pid_t FileTransfer::m_pid;
16
17FileTransfer::FileTransfer( Type t, IOLayer* lay )
18 : FileTransferLayer( lay ), m_type( t ) {
19 signal( SIGCHLD, signal_handler );
20}
21FileTransfer::~FileTransfer() {
22}
23
24/**
25 * now we will send the file.
26 *
27 * we request an fd. The IOLayer should be closed
28 * then we will setup a pipe for progress communication
29 * then we will dup2 the m_fd in the forked process
30 * to do direct IO from and to the fd
31 */
32void FileTransfer::sendFile( const QString& file ) {
33 m_fd = layer()->rawIO();
34//
35// m_fd = ::open("/dev/ttyS0", O_RDWR);
36
37
38 if ( pipe( m_comm ) < 0 )
39 m_comm[0] = m_comm[1] = 0;
40 if ( pipe( m_info ) < 0 )
41 m_info[0] = m_info[1] = 0;
42
43 qWarning("output:"+file );
44 m_pid = fork();
45 switch( m_pid ) {
46 case 0:{
47 setupChild();
48 /* exec */
49 char* verbose = "-vv";
50 char* binray = "-b";
51
52
53 /* we should never return from here */
54 execlp("sz", "sz", verbose, binray, file.latin1(), NULL );
55
56 /* communication for error!*/
57 char resultByte =1;
58 if (m_info[1] )
59 write(m_info[1], &resultByte, 1 );
60 _exit( -1 );
61 break;
62 }
63 default:{
64 if ( m_info[1] )
65 close( m_info[1] );
66 if ( m_info[0] ) for (;;) {
67 char resultByte; int len;
68 len = read(m_info[0], &resultByte, 1 );
69 /* len == 1 start up failed */
70 if ( len == 1 )
71 return;
72 if ( len == -1 )
73 if ( (errno == ECHILD ) || (errno == EINTR ) )
74 continue;
75
76 // len == 0 or something like this
77 break;
78 }
79 if ( m_info[0] )
80 close( m_info[0] );
81
82 terminate = false;
83 fd_set fds;
84 struct timeval timeout;
85 int sel;
86
87 /* replace by QSocketNotifier!!! */
88 while (!terminate) {
89 FD_ZERO( &fds );
90 FD_SET( m_comm[0], &fds );
91 sel = select( m_comm[0]+1, &fds, NULL, NULL, &timeout );
92 if (sel ) {
93 if ( FD_ISSET(m_comm[0], &fds ) ) {
94 printf("out:");
95 QByteArray ar(4096);
96 int len = read(m_comm[0], ar.data(), 4096 );
97 for (int i = 0; i < len; i++ ) {
98 // printf("%c", ar[i] );
99 }
100 printf("\n");
101 }
102 }
103 }
104 break;
105 }
106 }
107}
108void FileTransfer::sendFile( const QFile& file ) {
109 sendFile( file.name() );
110}
111void FileTransfer::signal_handler(int ) {
112 int status;
113 signal( SIGCHLD, signal_handler );
114 waitpid( m_pid, &status, WNOHANG );
115 terminate = true;
116}
117void FileTransfer::setupChild() {
118 /*
119 * we do not want to read from our
120 * information channel
121 */
122 if (m_info[0] )
123 close(m_info[0] );
124 /*
125 * FD_CLOEXEC will close the
126 * fd on successfull exec
127 */
128 if (m_info[1] )
129 fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
130
131 if (m_comm[0] )
132 close( m_comm[0] );
133 /*
134 * now set the communication
135 * m_fd STDIN_FILENO
136 * STDOUT_FILENO
137 * STDERR_FILENO
138 */
139 dup2( m_fd, STDIN_FILENO );
140 dup2( m_fd, STDOUT_FILENO );
141 dup2( m_comm[1], STDERR_FILENO );
142}
diff --git a/noncore/apps/opie-console/filetransfer.h b/noncore/apps/opie-console/filetransfer.h
new file mode 100644
index 0000000..06c6d12
--- a/dev/null
+++ b/noncore/apps/opie-console/filetransfer.h
@@ -0,0 +1,38 @@
1#ifndef OPIE_FILE_TRANSFER_H
2#define OPIE_FILE_TRANSFER_H
3
4#include <sys/types.h>
5
6#include <qfile.h>
7
8#include "file_layer.h"
9
10class QSocketNotifier;
11class OProcess;
12class FileTransfer : public FileTransferLayer{
13 Q_OBJECT
14public:
15 enum Type {
16 SZ = 0,
17 SX,
18 SY
19 };
20 FileTransfer( Type t, IOLayer* );
21 ~FileTransfer();
22
23 void sendFile( const QString& file );
24 void sendFile( const QFile& );
25
26private slots:
27 void setupChild();
28private:
29 static pid_t m_pid;
30 int m_fd;
31 int m_info[2];
32 int m_comm[2];
33 Type m_type;
34 static void signal_handler(int);
35 static bool terminate;
36};
37
38#endif
diff --git a/noncore/apps/opie-console/io_layer.cpp b/noncore/apps/opie-console/io_layer.cpp
index 563a252..79d47f5 100644
--- a/noncore/apps/opie-console/io_layer.cpp
+++ b/noncore/apps/opie-console/io_layer.cpp
@@ -1,14 +1,17 @@
1#include "io_layer.h" 1#include "io_layer.h"
2 2
3IOLayer::IOLayer() 3IOLayer::IOLayer()
4 : QObject() 4 : QObject()
5{ 5{
6} 6}
7 7
8IOLayer::IOLayer(const Profile &) 8IOLayer::IOLayer(const Profile &)
9 : QObject() 9 : QObject()
10{ 10{
11} 11}
12 12
13IOLayer::~IOLayer() { 13IOLayer::~IOLayer() {
14} 14}
15int IOLayer::rawIO()const{
16 return -1;
17}
diff --git a/noncore/apps/opie-console/io_layer.h b/noncore/apps/opie-console/io_layer.h
index b891b2b..7745021 100644
--- a/noncore/apps/opie-console/io_layer.h
+++ b/noncore/apps/opie-console/io_layer.h
@@ -1,87 +1,94 @@
1#ifndef OPIE_IO_LAYER_H 1#ifndef OPIE_IO_LAYER_H
2#define OPIE_IO_LAYER_H 2#define OPIE_IO_LAYER_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qpe/config.h> 5#include <qpe/config.h>
6 6
7#include "profile.h" 7#include "profile.h"
8 8
9/** 9/**
10 * This is the base class for IO Layers 10 * This is the base class for IO Layers
11 * It will used to sent and recv data( QByteArray ) 11 * It will used to sent and recv data( QByteArray )
12 * it 12 * it
13 */ 13 */
14class IOLayer : public QObject { 14class IOLayer : public QObject {
15 Q_OBJECT 15 Q_OBJECT
16public: 16public:
17 enum Error { 17 enum Error {
18 NoError = -1, 18 NoError = -1,
19 Refuse = 0, 19 Refuse = 0,
20 CouldNotOpen =1, 20 CouldNotOpen =1,
21 ClosedUnexpected =2, 21 ClosedUnexpected =2,
22 ClosedError =3, 22 ClosedError =3,
23 Terminate = 4 23 Terminate = 4
24 /* add more errors here */ 24 /* add more errors here */
25 }; 25 };
26 /** 26 /**
27 * a small c'tor 27 * a small c'tor
28 */ 28 */
29 IOLayer(); 29 IOLayer();
30 30
31 /** 31 /**
32 * create an IOLayer instance from a config file 32 * create an IOLayer instance from a config file
33 * the currently set group stores the profile/session 33 * the currently set group stores the profile/session
34 * information 34 * information
35 */ 35 */
36 IOLayer( const Profile& ); 36 IOLayer( const Profile& );
37 37
38 /** 38 /**
39 * destructor 39 * destructor
40 */ 40 */
41 virtual ~IOLayer(); 41 virtual ~IOLayer();
42 42
43 /** 43 /**
44 * a small internal identifier 44 * a small internal identifier
45 */ 45 */
46 virtual QString identifier() const = 0; 46 virtual QString identifier() const = 0;
47 47
48 /** 48 /**
49 * a short name 49 * a short name
50 */ 50 */
51 virtual QString name() const = 0; 51 virtual QString name() const = 0;
52
53 /**
54 * a file descriptor which opens
55 * the device for io but does not
56 * do any ioctling on it...
57 */
58 virtual int rawIO()const;
52signals: 59signals:
53 /** 60 /**
54 * received input as QCString 61 * received input as QCString
55 */ 62 */
56 virtual void received( const QByteArray& ) = 0; 63 virtual void received( const QByteArray& ) = 0;
57 64
58 /** 65 /**
59 * an error occured 66 * an error occured
60 * int for the error number 67 * int for the error number
61 * and QString for a text 68 * and QString for a text
62 */ 69 */
63 virtual void error( int, const QString& ) = 0; 70 virtual void error( int, const QString& ) = 0;
64 71
65public slots: 72public slots:
66 /** 73 /**
67 * send a QCString to the device 74 * send a QCString to the device
68 */ 75 */
69 virtual void send( const QByteArray& ) = 0; 76 virtual void send( const QByteArray& ) = 0;
70 77
71 /** 78 /**
72 * bool open 79 * bool open
73 */ 80 */
74 virtual bool open() = 0; 81 virtual bool open() = 0;
75 82
76 /** 83 /**
77 * close the io 84 * close the io
78 */ 85 */
79 virtual void close() = 0; 86 virtual void close() = 0;
80 87
81 /** 88 /**
82 * closes and reloads the settings 89 * closes and reloads the settings
83 */ 90 */
84 virtual void reload( const Profile& ) = 0; 91 virtual void reload( const Profile& ) = 0;
85}; 92};
86 93
87#endif 94#endif
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index 929aeff..845f4be 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -64,114 +64,119 @@ bool IOSerial::open() {
64 m_dbits = 8; 64 m_dbits = 8;
65 } 65 }
66 66
67 /* Data bits */ 67 /* Data bits */
68 switch (m_dbits) { 68 switch (m_dbits) {
69 case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; 69 case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break;
70 case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; 70 case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break;
71 case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; 71 case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break;
72 case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; 72 case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break;
73 default: break; 73 default: break;
74 } 74 }
75 75
76 /* Raw, no echo mode */ 76 /* Raw, no echo mode */
77 tty.c_iflag = IGNBRK; 77 tty.c_iflag = IGNBRK;
78 tty.c_lflag = 0; 78 tty.c_lflag = 0;
79 tty.c_oflag = 0; 79 tty.c_oflag = 0;
80 tty.c_cflag |= CLOCAL | CREAD; 80 tty.c_cflag |= CLOCAL | CREAD;
81 81
82 /* Stop bits */ 82 /* Stop bits */
83 if (m_sbits == 2) { 83 if (m_sbits == 2) {
84 tty.c_cflag |= CSTOPB; 84 tty.c_cflag |= CSTOPB;
85 } else { 85 } else {
86 tty.c_cflag &= ~CSTOPB; 86 tty.c_cflag &= ~CSTOPB;
87 } 87 }
88 88
89 tty.c_cc[VMIN] = 1; 89 tty.c_cc[VMIN] = 1;
90 tty.c_cc[VTIME] = 5; 90 tty.c_cc[VTIME] = 5;
91 91
92 /* Flow control */ 92 /* Flow control */
93 if (m_flow & FlowSW) 93 if (m_flow & FlowSW)
94 tty.c_iflag |= IXON | IXOFF; 94 tty.c_iflag |= IXON | IXOFF;
95 else 95 else
96 tty.c_iflag &= ~(IXON|IXOFF|IXANY); 96 tty.c_iflag &= ~(IXON|IXOFF|IXANY);
97 97
98 if (m_flow & FlowHW) 98 if (m_flow & FlowHW)
99 tty.c_cflag |= CRTSCTS; 99 tty.c_cflag |= CRTSCTS;
100 else 100 else
101 tty.c_cflag &= ~CRTSCTS; 101 tty.c_cflag &= ~CRTSCTS;
102 102
103 /* Parity */ 103 /* Parity */
104 tty.c_cflag &= ~(PARENB | PARODD); 104 tty.c_cflag &= ~(PARENB | PARODD);
105 if (m_parity & ParityEven) 105 if (m_parity & ParityEven)
106 tty.c_cflag |= PARENB; 106 tty.c_cflag |= PARENB;
107 else if (m_parity & ParityOdd) 107 else if (m_parity & ParityOdd)
108 tty.c_cflag |= (PARENB | PARODD); 108 tty.c_cflag |= (PARENB | PARODD);
109 109
110 /* Set the changes */ 110 /* Set the changes */
111 tcsetattr(m_fd, TCSANOW, &tty); 111 tcsetattr(m_fd, TCSANOW, &tty);
112 112
113 /* Notifications on read & errors */ 113 /* Notifications on read & errors */
114 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); 114 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
115 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); 115 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this);
116 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 116 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
117 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 117 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
118 return TRUE; 118 return TRUE;
119 } else { 119 } else {
120 qWarning("opened"); 120 qWarning("opened");
121 emit error(Refuse, tr("Device is already connected")); 121 emit error(Refuse, tr("Device is already connected"));
122 m_fd = 0; 122 m_fd = 0;
123 return FALSE; 123 return FALSE;
124 } 124 }
125} 125}
126 126
127void IOSerial::reload(const Profile &config) { 127void IOSerial::reload(const Profile &config) {
128 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); 128 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE);
129 qWarning( "Dev" +m_device ); 129 qWarning( "Dev" +m_device );
130 qWarning( "Conf:" +config.readEntry("Device") ); 130 qWarning( "Conf:" +config.readEntry("Device") );
131 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD); 131 m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD);
132 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); 132 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY);
133 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); 133 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS);
134 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); 134 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS);
135 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); 135 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW);
136} 136}
137 137
138int IOSerial::baud(int baud) const { 138int IOSerial::baud(int baud) const {
139 switch (baud) { 139 switch (baud) {
140 case 300: return B300; break; 140 case 300: return B300; break;
141 case 600: return B600; break; 141 case 600: return B600; break;
142 case 1200: return B1200; break; 142 case 1200: return B1200; break;
143 case 2400: return B2400; break; 143 case 2400: return B2400; break;
144 case 4800: return B4800; break; 144 case 4800: return B4800; break;
145 case 9600: return B9600; break; 145 case 9600: return B9600; break;
146 case 19200: return B19200; break; 146 case 19200: return B19200; break;
147 case 38400: return B38400; break; 147 case 38400: return B38400; break;
148 case 57600: return B57600; break; 148 case 57600: return B57600; break;
149 case 115200: return B115200; break; 149 case 115200: return B115200; break;
150 } 150 }
151 return -1; 151 return -1;
152} 152}
153 153
154void IOSerial::errorOccured() { 154void IOSerial::errorOccured() {
155 emit error(ClosedUnexpected, strerror(errno)); 155 emit error(ClosedUnexpected, strerror(errno));
156 close(); 156 close();
157} 157}
158 158
159void IOSerial::dataArrived() { 159void IOSerial::dataArrived() {
160 QByteArray array(4096); 160 QByteArray array(4097);
161 161
162 int len = read(m_fd, array.data(), 4096); 162 int len = read(m_fd, array.data(), 4096);
163 if (len == 0) 163 if (len == 0)
164 close(); 164 close();
165 if (len < 0) 165 if (len < 0)
166 return; 166 return;
167 array.resize( len ); 167 array.resize( len );
168 emit received(array); 168 emit received(array);
169} 169}
170 170
171QString IOSerial::identifier() const { 171QString IOSerial::identifier() const {
172 return "serial"; 172 return "serial";
173} 173}
174 174
175QString IOSerial::name() const { 175QString IOSerial::name() const {
176 return "RS232 Serial IO Layer"; 176 return "RS232 Serial IO Layer";
177} 177}
178int IOSerial::rawIO()const {
179 int fd = ::open(m_device, O_RDWR );
180
181 return fd;
182};
diff --git a/noncore/apps/opie-console/io_serial.h b/noncore/apps/opie-console/io_serial.h
index 521dac6..00a6d2c 100644
--- a/noncore/apps/opie-console/io_serial.h
+++ b/noncore/apps/opie-console/io_serial.h
@@ -1,63 +1,64 @@
1#ifndef OPIE_IO_SERIAL 1#ifndef OPIE_IO_SERIAL
2#define OPIE_IO_SERIAL 2#define OPIE_IO_SERIAL
3 3
4#include <qsocketnotifier.h> 4#include <qsocketnotifier.h>
5#include "io_layer.h" 5#include "io_layer.h"
6 6
7/* Default values to be used if the profile information is incomplete */ 7/* Default values to be used if the profile information is incomplete */
8#define SERIAL_DEFAULT_DEVICE "/dev/ttyS0" 8#define SERIAL_DEFAULT_DEVICE "/dev/ttyS0"
9#define SERIAL_DEFAULT_BAUD 9600 9#define SERIAL_DEFAULT_BAUD 9600
10#define SERIAL_DEFAULT_PARITY 0 10#define SERIAL_DEFAULT_PARITY 0
11#define SERIAL_DEFAULT_DBITS 8 11#define SERIAL_DEFAULT_DBITS 8
12#define SERIAL_DEFAULT_SBITS 1 12#define SERIAL_DEFAULT_SBITS 1
13#define SERIAL_DEFAULT_FLOW 0 13#define SERIAL_DEFAULT_FLOW 0
14 14
15/* IOSerial implements a RS232 IO Layer */ 15/* IOSerial implements a RS232 IO Layer */
16 16
17class IOSerial : public IOLayer { 17class IOSerial : public IOLayer {
18 Q_OBJECT 18 Q_OBJECT
19public: 19public:
20 enum Parity { 20 enum Parity {
21 ParityNone = 0, 21 ParityNone = 0,
22 ParityEven, 22 ParityEven,
23 ParityOdd, 23 ParityOdd,
24 ParitySpace, 24 ParitySpace,
25 ParityMark 25 ParityMark
26 }; 26 };
27 27
28 enum Flow { 28 enum Flow {
29 FlowHW = 0x01, 29 FlowHW = 0x01,
30 FlowSW = 0x02 30 FlowSW = 0x02
31 }; 31 };
32 32
33 IOSerial(const Profile &); 33 IOSerial(const Profile &);
34 ~IOSerial(); 34 ~IOSerial();
35 35
36 QString identifier() const; 36 QString identifier() const;
37 QString name() const; 37 QString name() const;
38 int rawIO()const;
38signals: 39signals:
39 void received(const QByteArray &); 40 void received(const QByteArray &);
40 void error(int, const QString &); 41 void error(int, const QString &);
41public slots: 42public slots:
42 void send(const QByteArray &); 43 void send(const QByteArray &);
43 bool open(); 44 bool open();
44 void close(); 45 void close();
45 void reload(const Profile &); 46 void reload(const Profile &);
46protected: 47protected:
47 int baud(int baud) const; 48 int baud(int baud) const;
48protected slots: 49protected slots:
49 void dataArrived(); 50 void dataArrived();
50 void errorOccured(); 51 void errorOccured();
51protected: 52protected:
52 QSocketNotifier *m_read; 53 QSocketNotifier *m_read;
53 QSocketNotifier *m_error; 54 QSocketNotifier *m_error;
54 QString m_device; 55 QString m_device;
55 int m_baud; 56 int m_baud;
56 int m_parity; 57 int m_parity;
57 int m_dbits; 58 int m_dbits;
58 int m_sbits; 59 int m_sbits;
59 int m_flow; 60 int m_flow;
60 int m_fd; 61 int m_fd;
61}; 62};
62 63
63#endif /* OPIE_IO_SERIAL */ 64#endif /* OPIE_IO_SERIAL */
diff --git a/noncore/apps/opie-console/sz_transfer.cpp b/noncore/apps/opie-console/sz_transfer.cpp
index 41917c0..0a315cf 100644
--- a/noncore/apps/opie-console/sz_transfer.cpp
+++ b/noncore/apps/opie-console/sz_transfer.cpp
@@ -1,176 +1,85 @@
1 1
2#include "sz_transfer.h" 2#include "sz_transfer.h"
3#include <qfile.h> 3#include <qfile.h>
4#include <opie/oprocess.h> 4#include <opie/oprocess.h>
5#include <stdio.h> 5#include <stdio.h>
6#include <sys/termios.h> 6#include <sys/termios.h>
7 7
8/* following function ripped out of minicom's sysdep2.c */
9
10
11/*
12 * Set cbreak mode.
13 * Mode 0 = normal.
14 * Mode 1 = cbreak, no echo
15 * Mode 2 = raw, no echo.
16 * Mode 3 = only return erasechar (for wkeys.c)
17 *
18 * Returns: the current erase character.
19 */
20
21static struct termios savetty;
22int setcbreak(int mode)
23{
24#if 1
25 struct termios tty;
26 static int init = 0;
27 static int erasechar;
28
29
30 if (init == 0) {
31 tcgetattr(0, &savetty);
32 erasechar = savetty.c_cc[VERASE];
33 init++;
34 }
35
36 if (mode == 3) return(erasechar);
37
38
39
40 /* Always return to default settings first */
41 tcsetattr(0, TCSADRAIN, &savetty);
42
43 if (mode == 0) {
44 return(erasechar);
45 }
46
47 tcgetattr(0, &tty);
48 if (mode == 1) {
49 tty.c_oflag &= ~OPOST;
50 tty.c_lflag &= ~(XCASE|ECHONL|NOFLSH);
51 tty.c_lflag &= ~(ICANON | ISIG | ECHO);
52 tty.c_iflag &= ~(ICRNL|INLCR);
53 tty.c_cflag |= CREAD;
54 tty.c_cc[VTIME] = 5;
55 tty.c_cc[VMIN] = 1;
56 }
57 if (mode == 2) { /* raw */
58 tty.c_iflag &= ~(IGNBRK | IGNCR | INLCR | ICRNL | IUCLC |
59 IXANY | IXON | IXOFF | INPCK | ISTRIP);
60 tty.c_iflag |= (BRKINT | IGNPAR);
61 tty.c_oflag &= ~OPOST;
62 tty.c_lflag &= ~(XCASE|ECHONL|NOFLSH);
63 tty.c_lflag &= ~(ICANON | ISIG | ECHO);
64 tty.c_cflag |= CREAD;
65 tty.c_cc[VTIME] = 5;
66 tty.c_cc[VMIN] = 1;
67 }
68 tcsetattr(0, TCSADRAIN, &tty);
69 return(erasechar);
70#else
71 struct sgttyb args;
72 static int init = 0;
73 static int erasechar;
74
75 if (init == 0) {
76 (void) ioctl(0, TIOCGETP, &savetty);
77 (void) ioctl(0, TIOCGETC, &savetty2);
78 erasechar = savetty.sg_erase;
79 init++;
80 }
81
82 if (mode == 3) return(erasechar);
83
84 if (mode == 0) {
85 (void) ioctl(0, TIOCSETP, &savetty);
86 (void) ioctl(0, TIOCSETC, &savetty2);
87 return(erasechar);
88 }
89
90 (void) ioctl(0, TIOCGETP, &args);
91 if (mode == 1) {
92 args.sg_flags |= CBREAK;
93 args.sg_flags &= ~(ECHO|RAW);
94 }
95 if (mode == 2) {
96 args.sg_flags |= RAW;
97 args.sg_flags &= ~(ECHO|CBREAK);
98 }
99 (void) ioctl(0, TIOCSETP, &args);
100 return(erasechar);
101#endif
102
103}
104 8
105 9
106SzTransfer::SzTransfer(Type t, IOLayer *layer) : FileTransferLayer(layer), m_t(t) 10SzTransfer::SzTransfer(Type t, IOLayer *layer) : FileTransferLayer(layer), m_t(t)
107{ 11{
108} 12}
109 13
110SzTransfer::~SzTransfer() { 14SzTransfer::~SzTransfer() {
111} 15}
112 16
113void SzTransfer::sendFile(const QFile& file) { 17void SzTransfer::sendFile(const QFile& file) {
114 18
115 sendFile(file.name()); 19 sendFile(file.name());
116} 20}
117 21
118void SzTransfer::sendFile(const QString& file) { 22void SzTransfer::sendFile(const QString& file) {
119 23
120 //setcbreak(2); /* raw no echo */ 24 //setcbreak(2); /* raw no echo */
121 25
122 proc = new OProcess; 26 proc = new OProcess;
123 *proc << "sz"; 27 *proc << "sz";
124 *proc << "-v" << "-v" << "-v" << "-b" << file; 28 *proc << "-v" << "-v" << "-b" << file;
125 connect(proc, SIGNAL(processExited(OProcess *)), 29 connect(proc, SIGNAL(processExited(OProcess *)),
126 this, SLOT(sent())); 30 this, SLOT(sent()));
127 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)), 31 connect(proc, SIGNAL(receivedStdout(OProcess *, char *, int)),
128 this, SLOT(SzReceivedStdout(OProcess *, char *, int))); 32 this, SLOT(SzReceivedStdout(OProcess *, char *, int)));
129 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)), 33 connect(proc, SIGNAL(receivedStderr(OProcess *, char *, int)),
130 this, SLOT(SzReceivedStderr(OProcess *, char *, int))); 34 this, SLOT(SzReceivedStderr(OProcess *, char *, int)));
131 connect(layer(), SIGNAL(received(const QByteArray &)), 35 connect(layer(), SIGNAL(received(const QByteArray &)),
132 this, SLOT(receivedStdin(const QByteArray &))); 36 this, SLOT(receivedStdin(const QByteArray &)));
133 proc->start(OProcess::NotifyOnExit, OProcess::All); 37 proc->start(OProcess::NotifyOnExit, OProcess::All);
134 38
135} 39}
136 40
137void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) { 41void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) {
138 42
139 //qWarning("recieved from sz %d bytes", buflen); 43 qWarning("recieved from sz on stdout %d bytes", buflen);
140 44
141 QByteArray data(buflen); 45 QByteArray data(buflen);
142 data.fill(*buffer, buflen); 46 data.fill(*buffer, buflen);
47 for (uint i = 0; i < data.count(); i++ ) {
48 printf("%c", buffer[i] );
49 }
50 printf("\n");
143 51
144 // send out through the io layer 52 // send out through the io layer
145 (layer())->send(data); 53 layer()->send(data);
146} 54}
147 55
148void SzTransfer::SzReceivedStderr(OProcess *, char *buffer, int length) { 56void SzTransfer::SzReceivedStderr(OProcess *, char *buffer, int length) {
149 57
150 // parse and show data in a progress dialog/widget 58 // parse and show data in a progress dialog/widget
151 printf("\n"); 59 printf("stderr:\n");
152 for (int i = 0; i < length; i++) 60 //for (int i = 0; i < length; i++)
153 printf("%c", buffer[i]); 61 // printf("%c", buffer[i]);
62 //printf("\n");
154} 63}
155 64
156void SzTransfer::receivedStdin(const QByteArray &data) { 65void SzTransfer::receivedStdin(const QByteArray &data) {
157 66
158 //qWarning("recieved from io_serial %d bytes", data.size()); 67 qWarning("recieved from io_serial %d bytes", data.size());
159 68
160 // recieved data from the io layer goes to sz 69 // recieved data from the io layer goes to sz
161 proc->writeStdin(data.data(), data.size()); 70 proc->writeStdin(data.data(), data.size());
162 71
163} 72}
164 73
165void SzTransfer::sent() { 74void SzTransfer::sent() {
166 75
167 qWarning("sent file"); 76 qWarning("sent file");
168 77
169 //setcbreak(0); /* default */ 78 //setcbreak(0); /* default */
170 79
171 80
172 delete proc; 81 delete proc;
173 disconnect(layer(), SIGNAL(received(const QByteArray &)), 82 disconnect(layer(), SIGNAL(received(const QByteArray &)),
174 this, SLOT(receivedStdin(const QByteArray &))); 83 this, SLOT(receivedStdin(const QByteArray &)));
175 84
176} 85}