author | zecke <zecke> | 2002-10-24 20:11:15 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-24 20:11:15 (UTC) |
commit | 56c10d4383d5de607727ca8bd1ef1b9c8e2e3047 (patch) (unidiff) | |
tree | e484aa872b706c665f5e8ea756cc4754df887c33 | |
parent | 91e3749c56ce2fd1280ff2114ba3dc9301181b6d (diff) | |
download | opie-56c10d4383d5de607727ca8bd1ef1b9c8e2e3047.zip opie-56c10d4383d5de607727ca8bd1ef1b9c8e2e3047.tar.gz opie-56c10d4383d5de607727ca8bd1ef1b9c8e2e3047.tar.bz2 |
intent to fix modem
-rw-r--r-- | noncore/apps/opie-console/dialer.cpp | 28 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_modem.cpp | 8 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_serial.cpp | 22 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_serial.h | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/test/senderui.cpp | 10 |
5 files changed, 54 insertions, 16 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp index 5056040..ce2b688 100644 --- a/noncore/apps/opie-console/dialer.cpp +++ b/noncore/apps/opie-console/dialer.cpp | |||
@@ -1,301 +1,311 @@ | |||
1 | #include "dialer.h" | 1 | #include "dialer.h" |
2 | 2 | ||
3 | #include <qlayout.h> | 3 | #include <qlayout.h> |
4 | #include <qprogressbar.h> | 4 | #include <qprogressbar.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qpushbutton.h> | 6 | #include <qpushbutton.h> |
7 | #include <qapp.h> | 7 | #include <qapp.h> |
8 | #include <qtimer.h> | 8 | #include <qtimer.h> |
9 | #include <qmessagebox.h> | 9 | #include <qmessagebox.h> |
10 | 10 | ||
11 | #include <unistd.h> | 11 | #include <unistd.h> |
12 | #include <string.h> | 12 | #include <string.h> |
13 | #include <fcntl.h> | 13 | #include <fcntl.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | 15 | ||
16 | // State machine: | When an error occurs, we don't have to | 16 | // State machine: | When an error occurs, we don't have to |
17 | // | reset everything. | 17 | // | reset everything. |
18 | // (init) <------+ | But if the user wants to reset, | 18 | // (init) <------+ | But if the user wants to reset, |
19 | // | | | we stop dialing immediately. | 19 | // | | | we stop dialing immediately. |
20 | // v | | | 20 | // v | | |
21 | // (options) ----+ | Following the state machine is necessary | 21 | // (options) ----+ | Following the state machine is necessary |
22 | // | \ | to get determinable results. | 22 | // | \ | to get determinable results. |
23 | // v ^ | | 23 | // v ^ | |
24 | // (dial) ----+ | | 24 | // (dial) ----+ | |
25 | // | ^ | | 25 | // | ^ | |
26 | // v | | | 26 | // v | | |
27 | // (online) --+ | | 27 | // (online) --+ | |
28 | // | | | 28 | // | | |
29 | // v | | 29 | // v | |
30 | 30 | ||
31 | 31 | ||
32 | // from atconfigdialog | 32 | // from atconfigdialog |
33 | //initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) ); | 33 | //initStringLine->setText( config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ) ); |
34 | //resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) ); | 34 | //resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) ); |
35 | //dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 35 | //dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
36 | //dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 36 | //dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
37 | //dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 37 | //dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
38 | //dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 38 | //dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
39 | //dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 39 | //dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
40 | //dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 40 | //dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
41 | //connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) ); | 41 | //connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) ); |
42 | //hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) ); | 42 | //hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) ); |
43 | 43 | ||
44 | // from modemconfigwidget | 44 | // from modemconfigwidget |
45 | //int rad_flow = prof.readNumEntry("Flow"); | 45 | //int rad_flow = prof.readNumEntry("Flow"); |
46 | //int rad_parity = prof.readNumEntry("Parity"); | 46 | //int rad_parity = prof.readNumEntry("Parity"); |
47 | //int speed = prof.readNumEntry("Speed"); | 47 | //int speed = prof.readNumEntry("Speed"); |
48 | //QString number = prof.readEntry("Number"); | 48 | //QString number = prof.readEntry("Number"); |
49 | 49 | ||
50 | Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name) | 50 | Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name) |
51 | : QDialog(parent, name, true), m_fd(fd), m_profile(profile) | 51 | : QDialog(parent, name, true), m_fd(fd), m_profile(profile) |
52 | { | 52 | { |
53 | QVBoxLayout *vbox; | 53 | QVBoxLayout *vbox; |
54 | QLabel *desc; | 54 | QLabel *desc; |
55 | 55 | ||
56 | //m_profile.writeEntry("InitString", "ATZ"); | 56 | //m_profile.writeEntry("InitString", "ATZ"); |
57 | //m_profile.writeEntry("DialPrefix1", "ATDT"); | 57 | //m_profile.writeEntry("DialPrefix1", "ATDT"); |
58 | //m_profile.writeEntry("Termination", "\n"); | 58 | //m_profile.writeEntry("Termination", "\n"); |
59 | 59 | ||
60 | usercancel = 0; | 60 | usercancel = 0; |
61 | cleanshutdown = 0; | 61 | cleanshutdown = 0; |
62 | 62 | ||
63 | fcntl(m_fd, F_SETFL, O_NONBLOCK); | 63 | //fcntl(m_fd, F_SETFL, O_NONBLOCK); |
64 | 64 | ||
65 | desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); | 65 | desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); |
66 | progress = new QProgressBar(this); | 66 | progress = new QProgressBar(this); |
67 | status = new QLabel("", this); | 67 | status = new QLabel("", this); |
68 | status->setFrameStyle(QFrame::Panel | QFrame::Sunken); | 68 | status->setFrameStyle(QFrame::Panel | QFrame::Sunken); |
69 | cancel = new QPushButton(QObject::tr("Cancel"), this); | 69 | cancel = new QPushButton(QObject::tr("Cancel"), this); |
70 | 70 | ||
71 | vbox = new QVBoxLayout(this, 2); | 71 | vbox = new QVBoxLayout(this, 2); |
72 | vbox->add(desc); | 72 | vbox->add(desc); |
73 | vbox->add(progress); | 73 | vbox->add(progress); |
74 | vbox->add(status); | 74 | vbox->add(status); |
75 | vbox->add(cancel); | 75 | vbox->add(cancel); |
76 | 76 | ||
77 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); | 77 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); |
78 | 78 | ||
79 | show(); | 79 | show(); |
80 | 80 | ||
81 | QTimer::singleShot(500, this, SLOT(slotAutostart())); | 81 | QTimer::singleShot(500, this, SLOT(slotAutostart())); |
82 | } | 82 | } |
83 | 83 | ||
84 | Dialer::~Dialer() | 84 | Dialer::~Dialer() |
85 | { | 85 | { |
86 | } | 86 | } |
87 | 87 | ||
88 | void Dialer::setHangupOnly() | 88 | void Dialer::setHangupOnly() |
89 | { | 89 | { |
90 | state = state_cancel; | 90 | state = state_cancel; |
91 | usercancel = 1; | 91 | usercancel = 1; |
92 | } | 92 | } |
93 | 93 | ||
94 | void Dialer::slotCancel() | 94 | void Dialer::slotCancel() |
95 | { | 95 | { |
96 | if(state != state_online) | 96 | if(state != state_online) |
97 | { | 97 | { |
98 | usercancel = 1; | 98 | usercancel = 1; |
99 | reset(); | 99 | reset(); |
100 | } | 100 | } |
101 | else accept(); | 101 | else accept(); |
102 | } | 102 | } |
103 | 103 | ||
104 | void Dialer::reset() | 104 | void Dialer::reset() |
105 | { | 105 | { |
106 | qWarning("reset"); | ||
106 | switchState(state_cancel); | 107 | switchState(state_cancel); |
107 | } | 108 | } |
108 | 109 | ||
109 | void Dialer::slotAutostart() | 110 | void Dialer::slotAutostart() |
110 | { | 111 | { |
111 | //state = state_preinit; | 112 | //state = state_preinit; |
112 | dial(m_profile.readEntry("Number")); | 113 | dial(m_profile.readEntry("Number")); |
113 | } | 114 | } |
114 | 115 | ||
115 | void Dialer::dial(const QString& number) | 116 | void Dialer::dial(const QString& number) |
116 | { | 117 | { |
117 | while(state != state_online) | 118 | while(state != state_online) |
118 | { | 119 | { |
119 | if(!usercancel) | 120 | if(!usercancel) |
120 | { | 121 | { |
121 | state = state_preinit; | 122 | state = state_preinit; |
122 | trydial(number); | 123 | trydial(number); |
123 | } | 124 | } |
124 | else break; | 125 | else break; |
125 | } | 126 | } |
126 | 127 | ||
127 | if(usercancel) | 128 | if(usercancel) |
128 | { | 129 | { |
129 | // modem hangup | 130 | // modem hangup |
130 | trydial(QString::null); | 131 | trydial(QString::null); |
131 | reject(); | 132 | reject(); |
132 | } | 133 | } |
133 | } | 134 | } |
134 | 135 | ||
135 | void Dialer::trydial(const QString& number) | 136 | void Dialer::trydial(const QString& number) |
136 | { | 137 | { |
138 | qWarning("TryDial:%s", number.latin1() ); | ||
137 | if(state != state_cancel) switchState(state_preinit); | 139 | if(state != state_cancel) switchState(state_preinit); |
138 | if(cleanshutdown) | 140 | if(cleanshutdown) |
139 | { | 141 | { |
142 | qWarning("HangupString " + m_profile.readEntry("HangupString")); | ||
140 | send(m_profile.readEntry("HangupString")); | 143 | send(m_profile.readEntry("HangupString")); |
141 | //send("+++ATH"); | 144 | //send("+++ATH"); |
142 | send(""); | 145 | send(""); |
143 | } | 146 | } |
144 | 147 | ||
145 | if(state != state_cancel) | 148 | if(state != state_cancel) |
146 | { | 149 | { |
147 | switchState(state_init); | 150 | switchState(state_init); |
148 | //send("ATZ"); | 151 | //send("ATZ"); |
149 | send(m_profile.readEntry("InitString")); | 152 | qWarning("Init String " + m_profile.readEntry("InitString") ); |
153 | // send(m_profile.readEntry("InitString", "AT")); | ||
154 | send("AT\r"); | ||
150 | QString response2 = receive(); | 155 | QString response2 = receive(); |
151 | if(!response2.contains("\nOK\r")) | 156 | if(!response2.contains("\nOK\r")) |
152 | reset(); | 157 | reset(); |
153 | } | 158 | } |
154 | 159 | ||
155 | if(state != state_cancel) | 160 | /*if(state != state_cancel) |
156 | { | 161 | { |
157 | switchState(state_options); | 162 | switchState(state_options); |
158 | 163 | ||
159 | send("ATM3L3"); | 164 | qWarning("ATM3l3"); |
165 | send("ATM3L3\r"); | ||
160 | QString response3 = receive(); | 166 | QString response3 = receive(); |
161 | if(!response3.contains("\nOK\r")) | 167 | if(!response3.contains("\nOK\r")) |
162 | reset(); | 168 | reset(); |
163 | } | 169 | } |
170 | */ | ||
164 | 171 | ||
165 | if(state != state_cancel) | 172 | if(state != state_cancel) |
166 | { | 173 | { |
167 | switchState(state_dialtone); | 174 | switchState(state_dialtone); |
168 | 175 | ||
169 | send("ATX1"); | 176 | send("ATX1\r"); |
170 | QString response4 = receive(); | 177 | QString response4 = receive(); |
171 | if(!response4.contains("\nOK\r")) | 178 | if(!response4.contains("\nOK\r")) |
172 | reset(); | 179 | reset(); |
173 | } | 180 | } |
174 | 181 | ||
175 | if(state != state_cancel) | 182 | if(state != state_cancel) |
176 | { | 183 | { |
184 | qWarning("progress"); | ||
177 | switchState(state_dialing); | 185 | switchState(state_dialing); |
178 | 186 | ||
179 | //send(QString("ATDT %1").arg(number)); | 187 | send(QString("ATDT %1\r").arg(number)); |
180 | send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); | 188 | // send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); |
181 | QString response5 = receive(); | 189 | QString response5 = receive(); |
182 | if(!response5.contains("\n" + m_profile.readEntry("DefaultConnect"))) | 190 | if(!response5.contains("\n" + m_profile.readEntry("DefaultConnect"))) |
183 | { | 191 | { |
184 | if(response5.contains("BUSY")) | 192 | if(response5.contains("BUSY")) |
185 | switchState(state_dialing); | 193 | switchState(state_dialing); |
186 | else | 194 | else |
187 | { | 195 | { |
188 | QMessageBox::warning(this, | 196 | QMessageBox::warning(this, |
189 | QObject::tr("Failure"), | 197 | QObject::tr("Failure"), |
190 | QObject::tr("Dialing the number failed.")); | 198 | QObject::tr("Dialing the number failed.")); |
191 | slotCancel(); | 199 | slotCancel(); |
192 | } | 200 | } |
193 | } | 201 | } |
194 | } | 202 | } |
195 | 203 | ||
196 | if(state != state_cancel) | 204 | if(state != state_cancel) |
197 | { | 205 | { |
198 | switchState(state_online); | 206 | switchState(state_online); |
199 | } | 207 | } |
200 | } | 208 | } |
201 | 209 | ||
202 | void Dialer::send(const QString& msg) | 210 | void Dialer::send(const QString& msg) |
203 | { | 211 | { |
204 | QString m = msg; | 212 | QString m = msg; |
205 | int bytes; | 213 | int bytes; |
206 | QString termination; | 214 | QString termination; |
207 | 215 | ||
208 | //qWarning("Sending: '%s'", m.latin1()); | 216 | qWarning("Sending: %s", m.latin1()); |
209 | 217 | ||
210 | termination = "\r"; | 218 | /*termination = "\r"; |
211 | //termination = m_profile.readEntry("Termination"); | 219 | //termination = m_profile.readEntry("Termination"); |
212 | if(termination == "\n") m = m + "\n"; | 220 | if(termination == "\n") m = m + "\n"; |
213 | else if(termination == "\r") m = m + "\r"; | 221 | else if(termination == "\r") m = m + "\r"; |
214 | else m = m + "\r\n"; | 222 | else m = m + "\r\n"; |
223 | */ | ||
224 | m = m.replace(QRegExp("\n"), "\r"); | ||
215 | 225 | ||
216 | bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); | 226 | bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); |
217 | if(bytes < 0) | 227 | if(bytes < 0) |
218 | { | 228 | { |
219 | reset(); | 229 | reset(); |
220 | } | 230 | } |
221 | } | 231 | } |
222 | 232 | ||
223 | QString Dialer::receive() | 233 | QString Dialer::receive() |
224 | { | 234 | { |
225 | QString buf; | 235 | QString buf; |
226 | char buffer[1024]; | 236 | char buffer[1024]; |
227 | int ret; | 237 | int ret; |
228 | int counter = 0; | 238 | int counter = 0; |
229 | 239 | ||
230 | while(1) | 240 | while(1) |
231 | { | 241 | { |
232 | ret = ::read(m_fd, buffer, sizeof(buffer)); | 242 | ret = ::read(m_fd, buffer, sizeof(buffer)); |
233 | 243 | ||
234 | if(ret > 0) | 244 | if(ret > 0) |
235 | { | 245 | { |
236 | for(int i = 0; i < ret; i++) | 246 | for(int i = 0; i < ret; i++) |
237 | buffer[i] = buffer[i] & 0x7F; | 247 | buffer[i] = buffer[i] & 0x7F; |
238 | buffer[ret] = 0; | 248 | buffer[ret] = 0; |
239 | //qWarning("Got: '%s'", buffer); | 249 | //qWarning("Got: '%s'", buffer); |
240 | buf.append(QString(buffer)); | 250 | buf.append(QString(buffer)); |
241 | if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY"))) | 251 | if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY"))) |
242 | { | 252 | { |
243 | //qWarning("Receiving: '%s'", buf.latin1()); | 253 | //qWarning("Receiving: '%s'", buf.latin1()); |
244 | cleanshutdown = 1; | 254 | cleanshutdown = 1; |
245 | return buf; | 255 | return buf; |
246 | } | 256 | } |
247 | } | 257 | } |
248 | else if(ret < 0) | 258 | else if(ret < 0) |
249 | { | 259 | { |
250 | if(errno != EAGAIN) reset(); | 260 | if(errno != EAGAIN) reset(); |
251 | else if(!(counter++ % 100)) qApp->processEvents(); | 261 | else if(!(counter++ % 100)) qApp->processEvents(); |
252 | } | 262 | } |
253 | else if(!(counter++ % 100)) qApp->processEvents(); | 263 | else if(!(counter++ % 100)) qApp->processEvents(); |
254 | 264 | ||
255 | if(usercancel) return QString::null; | 265 | if(usercancel) return QString::null; |
256 | } | 266 | } |
257 | 267 | ||
258 | cleanshutdown = 1; | 268 | cleanshutdown = 1; |
259 | return QString::null; | 269 | return QString::null; |
260 | } | 270 | } |
261 | 271 | ||
262 | void Dialer::switchState(int newstate) | 272 | void Dialer::switchState(int newstate) |
263 | { | 273 | { |
264 | int oldstate = state; | 274 | int oldstate = state; |
265 | state = newstate; | 275 | state = newstate; |
266 | 276 | ||
267 | switch(state) | 277 | switch(state) |
268 | { | 278 | { |
269 | case state_cancel: | 279 | case state_cancel: |
270 | status->setText(QObject::tr("Cancelling...")); | 280 | status->setText(QObject::tr("Cancelling...")); |
271 | progress->setProgress(0); | 281 | progress->setProgress(0); |
272 | break; | 282 | break; |
273 | case state_preinit: | 283 | case state_preinit: |
274 | status->setText(QObject::tr("Searching modem")); | 284 | status->setText(QObject::tr("Searching modem")); |
275 | progress->setProgress(10); | 285 | progress->setProgress(10); |
276 | break; | 286 | break; |
277 | case state_init: | 287 | case state_init: |
278 | status->setText(QObject::tr("Initializing...")); | 288 | status->setText(QObject::tr("Initializing...")); |
279 | progress->setProgress(20); | 289 | progress->setProgress(20); |
280 | break; | 290 | break; |
281 | case state_options: | 291 | case state_options: |
282 | status->setText(QObject::tr("Reset speakers")); | 292 | status->setText(QObject::tr("Reset speakers")); |
283 | progress->setProgress(30); | 293 | progress->setProgress(30); |
284 | break; | 294 | break; |
285 | case state_dialtone: | 295 | case state_dialtone: |
286 | status->setText(QObject::tr("Turning off dialtone")); | 296 | status->setText(QObject::tr("Turning off dialtone")); |
287 | progress->setProgress(40); | 297 | progress->setProgress(40); |
288 | break; | 298 | break; |
289 | case state_dialing: | 299 | case state_dialing: |
290 | if(oldstate != state_dialing) status->setText(QObject::tr("Dial number")); | 300 | if(oldstate != state_dialing) status->setText(QObject::tr("Dial number")); |
291 | else status->setText(QObject::tr("Line busy, redialing number")); | 301 | else status->setText(QObject::tr("Line busy, redialing number")); |
292 | progress->setProgress(50); | 302 | progress->setProgress(50); |
293 | break; | 303 | break; |
294 | case state_online: | 304 | case state_online: |
295 | status->setText(QObject::tr("Connection established")); | 305 | status->setText(QObject::tr("Connection established")); |
296 | progress->setProgress(100); | 306 | progress->setProgress(100); |
297 | cancel->setText(QObject::tr("Dismiss")); | 307 | cancel->setText(QObject::tr("Dismiss")); |
298 | break; | 308 | break; |
299 | } | 309 | } |
300 | } | 310 | } |
301 | 311 | ||
diff --git a/noncore/apps/opie-console/io_modem.cpp b/noncore/apps/opie-console/io_modem.cpp index d4ea0b2..b7901b9 100644 --- a/noncore/apps/opie-console/io_modem.cpp +++ b/noncore/apps/opie-console/io_modem.cpp | |||
@@ -1,91 +1,93 @@ | |||
1 | 1 | ||
2 | #include "io_modem.h" | 2 | #include "io_modem.h" |
3 | 3 | ||
4 | #include "dialer.h" | 4 | #include "dialer.h" |
5 | 5 | ||
6 | IOModem::IOModem( const Profile &profile ) | 6 | IOModem::IOModem( const Profile &profile ) |
7 | : IOSerial( profile ) { | 7 | : IOSerial( profile ) { |
8 | m_profile = profile; | 8 | m_profile = profile; |
9 | } | 9 | } |
10 | 10 | ||
11 | 11 | ||
12 | IOModem::~IOModem() { | 12 | IOModem::~IOModem() { |
13 | 13 | ||
14 | } | 14 | } |
15 | 15 | ||
16 | 16 | ||
17 | void IOModem::close() { | 17 | void IOModem::close() { |
18 | // Hangup, discarding result | 18 | // Hangup, discarding result |
19 | int fd = rawIO(); | 19 | int fd = rawIO(); |
20 | Dialer d(m_profile, fd); | 20 | Dialer d(m_profile, fd); |
21 | d.setHangupOnly(); | 21 | d.setHangupOnly(); |
22 | d.exec(); | 22 | d.exec(); |
23 | closeRawIO(fd); | 23 | closeRawIO(fd); |
24 | 24 | ||
25 | IOSerial::close(); | 25 | IOSerial::close(); |
26 | } | 26 | } |
27 | 27 | ||
28 | bool IOModem::open() { | 28 | bool IOModem::open() { |
29 | bool ret = IOSerial::open(); | 29 | bool ret = IOSerial::open(); |
30 | if(!ret) return false; | 30 | if(!ret) return false; |
31 | 31 | ||
32 | int fd = rawIO(); | 32 | //int fd = rawIO(); |
33 | Dialer d(m_profile, fd); | 33 | internDetach(); |
34 | Dialer d(m_profile, m_fd); | ||
34 | 35 | ||
35 | int result = d.exec(); | 36 | int result = d.exec(); |
36 | closeRawIO(fd); | 37 | internAttach(); |
38 | //closeRawIO(fd); | ||
37 | if(result == QDialog::Accepted) | 39 | if(result == QDialog::Accepted) |
38 | { | 40 | { |
39 | return true; | 41 | return true; |
40 | } | 42 | } |
41 | else | 43 | else |
42 | { | 44 | { |
43 | close(); | 45 | close(); |
44 | return false; | 46 | return false; |
45 | } | 47 | } |
46 | } | 48 | } |
47 | 49 | ||
48 | void IOModem::reload( const Profile &config ) { | 50 | void IOModem::reload( const Profile &config ) { |
49 | 51 | ||
50 | m_device = config.readEntry("Device", MODEM_DEFAULT_DEVICE); | 52 | m_device = config.readEntry("Device", MODEM_DEFAULT_DEVICE); |
51 | m_baud = config.readNumEntry("Baud", MODEM_DEFAULT_BAUD); | 53 | m_baud = config.readNumEntry("Baud", MODEM_DEFAULT_BAUD); |
52 | m_parity = config.readNumEntry("Parity", MODEM_DEFAULT_PARITY); | 54 | m_parity = config.readNumEntry("Parity", MODEM_DEFAULT_PARITY); |
53 | m_dbits = config.readNumEntry("DataBits", MODEM_DEFAULT_DBITS); | 55 | m_dbits = config.readNumEntry("DataBits", MODEM_DEFAULT_DBITS); |
54 | m_sbits = config.readNumEntry("StopBits", MODEM_DEFAULT_SBITS); | 56 | m_sbits = config.readNumEntry("StopBits", MODEM_DEFAULT_SBITS); |
55 | m_flow = config.readNumEntry("Flow", MODEM_DEFAULT_FLOW); | 57 | m_flow = config.readNumEntry("Flow", MODEM_DEFAULT_FLOW); |
56 | 58 | ||
57 | m_initString = config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ); | 59 | m_initString = config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ); |
58 | m_resetString = config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ); | 60 | m_resetString = config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ); |
59 | m_dialPref1 = config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ); | 61 | m_dialPref1 = config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ); |
60 | m_dialSuf1 = config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ); | 62 | m_dialSuf1 = config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ); |
61 | m_dialPref2 = config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ); | 63 | m_dialPref2 = config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ); |
62 | m_dialSuf2 = config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ); | 64 | m_dialSuf2 = config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ); |
63 | m_dialPref3 = config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ); | 65 | m_dialPref3 = config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ); |
64 | m_dialSuf3 = config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ); | 66 | m_dialSuf3 = config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ); |
65 | m_connect = config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ); | 67 | m_connect = config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ); |
66 | m_hangup = config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ); | 68 | m_hangup = config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ); |
67 | m_cancel = config.readEntry("CancelString", MODEM_DEFAULT_CANCEL_STRING ); | 69 | m_cancel = config.readEntry("CancelString", MODEM_DEFAULT_CANCEL_STRING ); |
68 | m_dialTime = config.readNumEntry("DialTime", MODEM_DEFAULT_DIAL_TIME ); | 70 | m_dialTime = config.readNumEntry("DialTime", MODEM_DEFAULT_DIAL_TIME ); |
69 | m_delayRedial = config.readNumEntry("DelayRedial", MODEM_DEFAULT_DELAY_REDIAL ); | 71 | m_delayRedial = config.readNumEntry("DelayRedial", MODEM_DEFAULT_DELAY_REDIAL ); |
70 | m_numberTries = config.readNumEntry("NumberTries", MODEM_DEFAULT_NUMBER_TRIES ); | 72 | m_numberTries = config.readNumEntry("NumberTries", MODEM_DEFAULT_NUMBER_TRIES ); |
71 | m_dtrDropTime = config.readNumEntry("DTRDRopTime", MODEM_DEFAULT_DTR_DROP_TIME ); | 73 | m_dtrDropTime = config.readNumEntry("DTRDRopTime", MODEM_DEFAULT_DTR_DROP_TIME ); |
72 | m_bpsDetect = config.readBoolEntry("BPSDetect", MODEM_DEFAULT_BPS_DETECT ); | 74 | m_bpsDetect = config.readBoolEntry("BPSDetect", MODEM_DEFAULT_BPS_DETECT ); |
73 | m_dcdLines = config.readBoolEntry("DCDLines", MODEM_DEFAULT_DCD_LINES ); | 75 | m_dcdLines = config.readBoolEntry("DCDLines", MODEM_DEFAULT_DCD_LINES ); |
74 | m_multiLineUntag = config.readBoolEntry("MultiLineUntag", MODEM_DEFAULT_MULTI_LINE_UNTAG ); | 76 | m_multiLineUntag = config.readBoolEntry("MultiLineUntag", MODEM_DEFAULT_MULTI_LINE_UNTAG ); |
75 | } | 77 | } |
76 | 78 | ||
77 | 79 | ||
78 | QString IOModem::identifier() const { | 80 | QString IOModem::identifier() const { |
79 | return "modem"; | 81 | return "modem"; |
80 | } | 82 | } |
81 | 83 | ||
82 | QString IOModem::name() const { | 84 | QString IOModem::name() const { |
83 | return "Modem IO Layer"; | 85 | return "Modem IO Layer"; |
84 | } | 86 | } |
85 | 87 | ||
86 | void IOModem::slotExited(OProcess* proc ){ | 88 | void IOModem::slotExited(OProcess* proc ){ |
87 | close(); | 89 | close(); |
88 | /* delete it afterwards */ | 90 | /* delete it afterwards */ |
89 | delete proc; | 91 | delete proc; |
90 | } | 92 | } |
91 | 93 | ||
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp index e6d1688..0540d9e 100644 --- a/noncore/apps/opie-console/io_serial.cpp +++ b/noncore/apps/opie-console/io_serial.cpp | |||
@@ -1,206 +1,228 @@ | |||
1 | 1 | ||
2 | #include <fcntl.h> | 2 | #include <fcntl.h> |
3 | #include <termios.h> | 3 | #include <termios.h> |
4 | #include <errno.h> | 4 | #include <errno.h> |
5 | #include <unistd.h> | 5 | #include <unistd.h> |
6 | #include "io_serial.h" | 6 | #include "io_serial.h" |
7 | 7 | ||
8 | IOSerial::IOSerial(const Profile &config) : IOLayer(config) { | 8 | IOSerial::IOSerial(const Profile &config) : IOLayer(config) { |
9 | m_read = 0l; | 9 | m_read = 0l; |
10 | m_error = 0l; | 10 | m_error = 0l; |
11 | m_fd = 0; | 11 | m_fd = 0; |
12 | m_connected = false; | 12 | m_connected = false; |
13 | reload(config); | 13 | reload(config); |
14 | } | 14 | } |
15 | 15 | ||
16 | 16 | ||
17 | IOSerial::~IOSerial() { | 17 | IOSerial::~IOSerial() { |
18 | if (m_fd) { | 18 | if (m_fd) { |
19 | close(); | 19 | close(); |
20 | } | 20 | } |
21 | } | 21 | } |
22 | 22 | ||
23 | void IOSerial::send(const QByteArray &data) { | 23 | void IOSerial::send(const QByteArray &data) { |
24 | if (m_fd) { | 24 | if (m_fd) { |
25 | write(m_fd, data.data(), data.size()); | 25 | write(m_fd, data.data(), data.size()); |
26 | } else { | 26 | } else { |
27 | emit error(Refuse, tr("Not connected")); | 27 | emit error(Refuse, tr("Not connected")); |
28 | } | 28 | } |
29 | } | 29 | } |
30 | 30 | ||
31 | void IOSerial::close() { | 31 | void IOSerial::close() { |
32 | if (m_fd) { | 32 | if (m_fd) { |
33 | delete m_read; | 33 | delete m_read; |
34 | delete m_error; | 34 | delete m_error; |
35 | ::close(m_fd); | 35 | ::close(m_fd); |
36 | m_fd = 0; | 36 | m_fd = 0; |
37 | m_connected = false; | 37 | m_connected = false; |
38 | } else { | 38 | } else { |
39 | m_connected = false; | 39 | m_connected = false; |
40 | emit error(Refuse, tr("Not connected")); | 40 | emit error(Refuse, tr("Not connected")); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | bool IOSerial::open() { | 44 | bool IOSerial::open() { |
45 | if (!m_fd) { | 45 | if (!m_fd) { |
46 | struct termios tty; | 46 | struct termios tty; |
47 | m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); | 47 | m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); |
48 | if (m_fd < 0) { | 48 | if (m_fd < 0) { |
49 | emit error(CouldNotOpen, strerror(errno)); | 49 | emit error(CouldNotOpen, strerror(errno)); |
50 | m_fd = 0; | 50 | m_fd = 0; |
51 | return FALSE; | 51 | return FALSE; |
52 | } | 52 | } |
53 | tcgetattr(m_fd, &tty); | 53 | tcgetattr(m_fd, &tty); |
54 | 54 | ||
55 | /* Baud rate */ | 55 | /* Baud rate */ |
56 | int speed = baud(m_baud); | 56 | int speed = baud(m_baud); |
57 | if (speed == -1) { | 57 | if (speed == -1) { |
58 | emit error(Refuse, tr("Invalid baud rate")); | 58 | emit error(Refuse, tr("Invalid baud rate")); |
59 | } | 59 | } |
60 | cfsetospeed(&tty, speed); | 60 | cfsetospeed(&tty, speed); |
61 | cfsetispeed(&tty, speed); | 61 | cfsetispeed(&tty, speed); |
62 | 62 | ||
63 | /* Take care of Space / Mark parity */ | 63 | /* Take care of Space / Mark parity */ |
64 | if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { | 64 | if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { |
65 | m_dbits = 8; | 65 | m_dbits = 8; |
66 | } | 66 | } |
67 | 67 | ||
68 | /* Data bits */ | 68 | /* Data bits */ |
69 | switch (m_dbits) { | 69 | switch (m_dbits) { |
70 | case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; | 70 | case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; |
71 | case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; | 71 | case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; |
72 | case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; | 72 | case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; |
73 | case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; | 73 | case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; |
74 | default: break; | 74 | default: break; |
75 | } | 75 | } |
76 | 76 | ||
77 | /* Raw, no echo mode */ | 77 | /* Raw, no echo mode */ |
78 | tty.c_iflag = IGNBRK; | 78 | tty.c_iflag = IGNBRK; |
79 | tty.c_lflag = 0; | 79 | tty.c_lflag = 0; |
80 | tty.c_oflag = 0; | 80 | tty.c_oflag = 0; |
81 | tty.c_cflag |= CLOCAL | CREAD; | 81 | tty.c_cflag |= CLOCAL | CREAD; |
82 | 82 | ||
83 | /* Stop bits */ | 83 | /* Stop bits */ |
84 | if (m_sbits == 2) { | 84 | if (m_sbits == 2) { |
85 | tty.c_cflag |= CSTOPB; | 85 | tty.c_cflag |= CSTOPB; |
86 | } else { | 86 | } else { |
87 | tty.c_cflag &= ~CSTOPB; | 87 | tty.c_cflag &= ~CSTOPB; |
88 | } | 88 | } |
89 | 89 | ||
90 | tty.c_cc[VMIN] = 1; | 90 | tty.c_cc[VMIN] = 1; |
91 | tty.c_cc[VTIME] = 5; | 91 | tty.c_cc[VTIME] = 5; |
92 | 92 | ||
93 | /* Flow control */ | 93 | /* Flow control */ |
94 | if (m_flow & FlowSW) | 94 | if (m_flow & FlowSW) |
95 | tty.c_iflag |= IXON | IXOFF; | 95 | tty.c_iflag |= IXON | IXOFF; |
96 | else | 96 | else |
97 | tty.c_iflag &= ~(IXON|IXOFF|IXANY); | 97 | tty.c_iflag &= ~(IXON|IXOFF|IXANY); |
98 | 98 | ||
99 | if (m_flow & FlowHW) | 99 | if (m_flow & FlowHW) |
100 | tty.c_cflag |= CRTSCTS; | 100 | tty.c_cflag |= CRTSCTS; |
101 | else | 101 | else |
102 | tty.c_cflag &= ~CRTSCTS; | 102 | tty.c_cflag &= ~CRTSCTS; |
103 | 103 | ||
104 | /* Parity */ | 104 | /* Parity */ |
105 | tty.c_cflag &= ~(PARENB | PARODD); | 105 | tty.c_cflag &= ~(PARENB | PARODD); |
106 | if (m_parity & ParityEven) | 106 | if (m_parity & ParityEven) |
107 | tty.c_cflag |= PARENB; | 107 | tty.c_cflag |= PARENB; |
108 | else if (m_parity & ParityOdd) | 108 | else if (m_parity & ParityOdd) |
109 | tty.c_cflag |= (PARENB | PARODD); | 109 | tty.c_cflag |= (PARENB | PARODD); |
110 | 110 | ||
111 | /* Set the changes */ | 111 | /* Set the changes */ |
112 | tcsetattr(m_fd, TCSANOW, &tty); | 112 | tcsetattr(m_fd, TCSANOW, &tty); |
113 | 113 | ||
114 | /* Notifications on read & errors */ | 114 | /* Notifications on read & errors */ |
115 | m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); | 115 | m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); |
116 | m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); | 116 | m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); |
117 | connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); | 117 | connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); |
118 | connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); | 118 | connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); |
119 | m_connected = false; | 119 | m_connected = false; |
120 | return TRUE; | 120 | return TRUE; |
121 | } else { | 121 | } else { |
122 | emit error(Refuse, tr("Device is already connected")); | 122 | emit error(Refuse, tr("Device is already connected")); |
123 | m_fd = 0; | 123 | m_fd = 0; |
124 | return FALSE; | 124 | return FALSE; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | void IOSerial::reload(const Profile &config) { | 128 | void IOSerial::reload(const Profile &config) { |
129 | m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); | 129 | m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); |
130 | m_baud = config.readNumEntry("Speed", SERIAL_DEFAULT_BAUD); | 130 | m_baud = config.readNumEntry("Speed", SERIAL_DEFAULT_BAUD); |
131 | m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); | 131 | m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); |
132 | m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); | 132 | m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); |
133 | m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); | 133 | m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); |
134 | m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); | 134 | m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); |
135 | 135 | ||
136 | } | 136 | } |
137 | 137 | ||
138 | int IOSerial::baud(int baud) const { | 138 | int 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 | ||
154 | void IOSerial::errorOccured() { | 154 | void IOSerial::errorOccured() { |
155 | emit error(ClosedUnexpected, strerror(errno)); | 155 | emit error(ClosedUnexpected, strerror(errno)); |
156 | close(); | 156 | close(); |
157 | } | 157 | } |
158 | 158 | ||
159 | void IOSerial::dataArrived() { | 159 | void IOSerial::dataArrived() { |
160 | QByteArray array(4097); | 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 | ||
171 | QString IOSerial::identifier() const { | 171 | QString IOSerial::identifier() const { |
172 | return "serial"; | 172 | return "serial"; |
173 | } | 173 | } |
174 | 174 | ||
175 | QString IOSerial::name() const { | 175 | QString IOSerial::name() const { |
176 | return "RS232 Serial IO Layer"; | 176 | return "RS232 Serial IO Layer"; |
177 | } | 177 | } |
178 | int IOSerial::rawIO()const { | 178 | int IOSerial::rawIO()const { |
179 | if (m_read ) | 179 | if (m_read ) |
180 | disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); | 180 | disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); |
181 | if (m_error ) | 181 | if (m_error ) |
182 | disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); | 182 | disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); |
183 | 183 | ||
184 | int fd = ::open(m_device, O_RDWR ); | 184 | int fd = ::open(m_device, O_RDWR ); |
185 | 185 | ||
186 | return fd; | 186 | return fd; |
187 | }; | 187 | }; |
188 | void IOSerial::closeRawIO(int fd) { | 188 | void IOSerial::closeRawIO(int fd) { |
189 | if (m_read ) | 189 | if (m_read ) |
190 | connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); | 190 | connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); |
191 | if (m_error ) | 191 | if (m_error ) |
192 | connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); | 192 | connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); |
193 | 193 | ||
194 | ::close( fd ); | 194 | ::close( fd ); |
195 | } | 195 | } |
196 | QBitArray IOSerial::supports()const { | 196 | QBitArray IOSerial::supports()const { |
197 | QBitArray ar(3); | 197 | QBitArray ar(3); |
198 | ar[0] = ar[2] = 0; | 198 | ar[0] = ar[2] = 0; |
199 | ar[1] = 1; | 199 | ar[1] = 1; |
200 | 200 | ||
201 | return ar; | 201 | return ar; |
202 | } | 202 | } |
203 | 203 | ||
204 | bool IOSerial::isConnected() { | 204 | bool IOSerial::isConnected() { |
205 | return m_connected; | 205 | return m_connected; |
206 | } | 206 | } |
207 | |||
208 | /* | ||
209 | * this is used to give the | ||
210 | * class below IOSerial | ||
211 | * the possibility of | ||
212 | * exclusive usage | ||
213 | */ | ||
214 | void IOSerial::internDetach() { | ||
215 | if (m_read ) | ||
216 | disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); | ||
217 | if (m_error ) | ||
218 | disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); | ||
219 | } | ||
220 | /* | ||
221 | * give power back | ||
222 | */ | ||
223 | void IOSerial::internAttach() { | ||
224 | if (m_read ) | ||
225 | connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); | ||
226 | if (m_error ) | ||
227 | connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); | ||
228 | } | ||
diff --git a/noncore/apps/opie-console/io_serial.h b/noncore/apps/opie-console/io_serial.h index 7a1ea1d..edceac6 100644 --- a/noncore/apps/opie-console/io_serial.h +++ b/noncore/apps/opie-console/io_serial.h | |||
@@ -1,70 +1,72 @@ | |||
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 | ||
17 | class IOSerial : public IOLayer { | 17 | class IOSerial : public IOLayer { |
18 | Q_OBJECT | 18 | Q_OBJECT |
19 | public: | 19 | public: |
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; | 38 | int rawIO()const; |
39 | void closeRawIO(int fd ); | 39 | void closeRawIO(int fd ); |
40 | QBitArray supports()const; | 40 | QBitArray supports()const; |
41 | bool isConnected(); | 41 | bool isConnected(); |
42 | /*signals: | 42 | /*signals: |
43 | void received(const QByteArray &); | 43 | void received(const QByteArray &); |
44 | void error(int, const QString &); | 44 | void error(int, const QString &); |
45 | */ | 45 | */ |
46 | public slots: | 46 | public slots: |
47 | void send(const QByteArray &); | 47 | void send(const QByteArray &); |
48 | bool open(); | 48 | bool open(); |
49 | void close(); | 49 | void close(); |
50 | void reload(const Profile &); | 50 | void reload(const Profile &); |
51 | protected: | 51 | protected: |
52 | int baud(int baud) const; | 52 | int baud(int baud) const; |
53 | void internDetach(); | ||
54 | void internAttach(); | ||
53 | protected slots: | 55 | protected slots: |
54 | void dataArrived(); | 56 | void dataArrived(); |
55 | void errorOccured(); | 57 | void errorOccured(); |
56 | protected: | 58 | protected: |
57 | QSocketNotifier *m_read; | 59 | QSocketNotifier *m_read; |
58 | QSocketNotifier *m_error; | 60 | QSocketNotifier *m_error; |
59 | QString m_device; | 61 | QString m_device; |
60 | int m_baud; | 62 | int m_baud; |
61 | int m_parity; | 63 | int m_parity; |
62 | int m_dbits; | 64 | int m_dbits; |
63 | int m_sbits; | 65 | int m_sbits; |
64 | int m_flow; | 66 | int m_flow; |
65 | int m_fd; | 67 | int m_fd; |
66 | bool m_connected; | 68 | bool m_connected; |
67 | 69 | ||
68 | }; | 70 | }; |
69 | 71 | ||
70 | #endif /* OPIE_IO_SERIAL */ | 72 | #endif /* OPIE_IO_SERIAL */ |
diff --git a/noncore/apps/opie-console/test/senderui.cpp b/noncore/apps/opie-console/test/senderui.cpp index 2ce3f6d..4026808 100644 --- a/noncore/apps/opie-console/test/senderui.cpp +++ b/noncore/apps/opie-console/test/senderui.cpp | |||
@@ -1,75 +1,77 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
4 | #include <sys/termios.h> | 4 | #include <sys/termios.h> |
5 | 5 | ||
6 | #include <qmultilineedit.h> | 6 | #include <qmultilineedit.h> |
7 | #include <qsocketnotifier.h> | 7 | #include <qsocketnotifier.h> |
8 | 8 | ||
9 | #include "../profile.h" | 9 | #include "../profile.h" |
10 | #include "../io_serial.h" | 10 | #include "../io_serial.h" |
11 | #include "../filetransfer.h" | 11 | #include "../filetransfer.h" |
12 | #include "../filereceive.h" | 12 | #include "../filereceive.h" |
13 | 13 | ||
14 | #include <opie/oprocess.h> | 14 | #include <opie/oprocess.h> |
15 | 15 | ||
16 | #include "senderui.h" | 16 | #include "senderui.h" |
17 | 17 | ||
18 | SenderUI::SenderUI() | 18 | SenderUI::SenderUI() |
19 | : Sender() { | 19 | : Sender() { |
20 | 20 | ||
21 | /* we do that manually */ | 21 | /* we do that manually */ |
22 | Profile prof; | 22 | Profile prof; |
23 | QString str = "/dev/ttyS0"; | 23 | QString str = "/dev/bty0"; |
24 | prof.writeEntry("Device",str ); | 24 | prof.writeEntry("Device",str ); |
25 | prof.writeEntry("Baud", 115200 ); | 25 | prof.writeEntry("Baud", 19200 ); |
26 | 26 | ||
27 | qWarning("prof " + prof.readEntry("Device") + " " + str); | 27 | qWarning("prof " + prof.readEntry("Device") + " " + str); |
28 | ser = new IOSerial(prof); | 28 | ser = new IOSerial(prof); |
29 | connect(ser, SIGNAL(received(const QByteArray& ) ), | 29 | connect(ser, SIGNAL(received(const QByteArray& ) ), |
30 | this, SLOT(got(const QByteArray&) ) ); | 30 | this, SLOT(got(const QByteArray&) ) ); |
31 | 31 | ||
32 | if ( ser->open() ) | 32 | if ( ser->open() ) |
33 | qWarning("opened!!!"); | 33 | qWarning("opened!!!"); |
34 | else | 34 | else |
35 | qWarning("could not open"); | 35 | qWarning("could not open"); |
36 | 36 | ||
37 | 37 | ||
38 | } | 38 | } |
39 | SenderUI::~SenderUI() { | 39 | SenderUI::~SenderUI() { |
40 | 40 | ||
41 | } | 41 | } |
42 | void SenderUI::slotSendFile() { | 42 | void SenderUI::slotSendFile() { |
43 | 43 | ||
44 | sz = new FileTransfer(FileTransfer::SY, ser); | 44 | sz = new FileTransfer(FileTransfer::SY, ser); |
45 | sz->sendFile("/home/ich/bootopie-v06-13.jffs2"); | 45 | sz->sendFile("/home/ich/bootopie-v06-13.jffs2"); |
46 | 46 | ||
47 | connect (sz, SIGNAL(sent()), | 47 | connect (sz, SIGNAL(sent()), |
48 | this, SLOT(fileTransComplete())); | 48 | this, SLOT(fileTransComplete())); |
49 | } | 49 | } |
50 | 50 | ||
51 | void SenderUI::slotSend() { | 51 | void SenderUI::slotSend() { |
52 | QCString str = MultiLineEdit1->text().utf8(); | 52 | QCString str = MultiLineEdit1->text().utf8(); |
53 | qWarning("sending: %s", str.data() ); | 53 | qWarning("sending: %s", str.data() ); |
54 | str = str.replace( QRegExp("\n"), "\r"); | ||
54 | ser->send( str ); | 55 | ser->send( str ); |
55 | } | 56 | } |
56 | void SenderUI::got(const QByteArray& ar) { | 57 | void SenderUI::got(const QByteArray& ar) { |
58 | qWarning("got:"); | ||
57 | for ( uint i = 0; i < ar.count(); i++ ) { | 59 | for ( uint i = 0; i < ar.count(); i++ ) { |
58 | printf("%c", ar[i] ); | 60 | printf("%c", ar[i] ); |
59 | } | 61 | } |
60 | //printf("\n"); | 62 | printf("\n"); |
61 | } | 63 | } |
62 | 64 | ||
63 | void SenderUI::fileTransComplete() { | 65 | void SenderUI::fileTransComplete() { |
64 | 66 | ||
65 | qWarning("file transfer complete"); | 67 | qWarning("file transfer complete"); |
66 | } | 68 | } |
67 | void SenderUI::send() { | 69 | void SenderUI::send() { |
68 | 70 | ||
69 | } | 71 | } |
70 | void SenderUI::slotRev(){ | 72 | void SenderUI::slotRev(){ |
71 | qWarning("Going to receive!"); | 73 | qWarning("Going to receive!"); |
72 | FileReceive *rev = new FileReceive( FileReceive::SZ, ser ); | 74 | FileReceive *rev = new FileReceive( FileReceive::SZ, ser ); |
73 | rev->receive(); | 75 | rev->receive(); |
74 | 76 | ||
75 | } \ No newline at end of file | 77 | } |