author | hash <hash> | 2002-10-09 20:34:13 (UTC) |
---|---|---|
committer | hash <hash> | 2002-10-09 20:34:13 (UTC) |
commit | 091480d5d5fbe22e2f8f9814af3767cc08913236 (patch) (unidiff) | |
tree | aba1ad94996339691f94586739cee911098a10c2 | |
parent | 907c53e8024f2a44795ce35890b686fbe1b7be9e (diff) | |
download | opie-091480d5d5fbe22e2f8f9814af3767cc08913236.zip opie-091480d5d5fbe22e2f8f9814af3767cc08913236.tar.gz opie-091480d5d5fbe22e2f8f9814af3767cc08913236.tar.bz2 |
thought it not work because the terminal echo, but i copied some code that
enables/disables echoing from minicom, and it still doesnt work.
-rw-r--r-- | noncore/apps/opie-console/sz_transfer.cpp | 111 |
1 files changed, 109 insertions, 2 deletions
diff --git a/noncore/apps/opie-console/sz_transfer.cpp b/noncore/apps/opie-console/sz_transfer.cpp index a5af2be..41917c0 100644 --- a/noncore/apps/opie-console/sz_transfer.cpp +++ b/noncore/apps/opie-console/sz_transfer.cpp | |||
@@ -3,6 +3,105 @@ | |||
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> | ||
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 | |||
21 | static struct termios savetty; | ||
22 | int 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 | |||
6 | 105 | ||
7 | SzTransfer::SzTransfer(Type t, IOLayer *layer) : FileTransferLayer(layer), m_t(t) | 106 | SzTransfer::SzTransfer(Type t, IOLayer *layer) : FileTransferLayer(layer), m_t(t) |
8 | { | 107 | { |
@@ -18,6 +117,8 @@ void SzTransfer::sendFile(const QFile& file) { | |||
18 | 117 | ||
19 | void SzTransfer::sendFile(const QString& file) { | 118 | void SzTransfer::sendFile(const QString& file) { |
20 | 119 | ||
120 | //setcbreak(2); /* raw no echo */ | ||
121 | |||
21 | proc = new OProcess; | 122 | proc = new OProcess; |
22 | *proc << "sz"; | 123 | *proc << "sz"; |
23 | *proc << "-v" << "-v" << "-v" << "-b" << file; | 124 | *proc << "-v" << "-v" << "-v" << "-b" << file; |
@@ -35,7 +136,7 @@ void SzTransfer::sendFile(const QString& file) { | |||
35 | 136 | ||
36 | void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) { | 137 | void SzTransfer::SzReceivedStdout(OProcess *, char *buffer, int buflen) { |
37 | 138 | ||
38 | qWarning("recieved from sz %d bytes", buflen); | 139 | //qWarning("recieved from sz %d bytes", buflen); |
39 | 140 | ||
40 | QByteArray data(buflen); | 141 | QByteArray data(buflen); |
41 | data.fill(*buffer, buflen); | 142 | data.fill(*buffer, buflen); |
@@ -54,7 +155,8 @@ void SzTransfer::SzReceivedStderr(OProcess *, char *buffer, int length) { | |||
54 | 155 | ||
55 | void SzTransfer::receivedStdin(const QByteArray &data) { | 156 | void SzTransfer::receivedStdin(const QByteArray &data) { |
56 | 157 | ||
57 | qWarning("recieved from io_serial %d bytes", data.size()); | 158 | //qWarning("recieved from io_serial %d bytes", data.size()); |
159 | |||
58 | // recieved data from the io layer goes to sz | 160 | // recieved data from the io layer goes to sz |
59 | proc->writeStdin(data.data(), data.size()); | 161 | proc->writeStdin(data.data(), data.size()); |
60 | 162 | ||
@@ -63,7 +165,12 @@ void SzTransfer::receivedStdin(const QByteArray &data) { | |||
63 | void SzTransfer::sent() { | 165 | void SzTransfer::sent() { |
64 | 166 | ||
65 | qWarning("sent file"); | 167 | qWarning("sent file"); |
168 | |||
169 | //setcbreak(0); /* default */ | ||
170 | |||
171 | |||
66 | delete proc; | 172 | delete proc; |
67 | disconnect(layer(), SIGNAL(received(const QByteArray &)), | 173 | disconnect(layer(), SIGNAL(received(const QByteArray &)), |
68 | this, SLOT(receivedStdin(const QByteArray &))); | 174 | this, SLOT(receivedStdin(const QByteArray &))); |
175 | |||
69 | } | 176 | } |