summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-24 20:43:25 (UTC)
committer zecke <zecke>2002-10-24 20:43:25 (UTC)
commit81a2bb8073b95d438911a62a7f4d8244ef58e20a (patch) (unidiff)
tree2521c88de626caf818b715776934da204d6b0f8f
parent0fc598a0ee9151f82f5a78383645a758d5f6cad9 (diff)
downloadopie-81a2bb8073b95d438911a62a7f4d8244ef58e20a.zip
opie-81a2bb8073b95d438911a62a7f4d8244ef58e20a.tar.gz
opie-81a2bb8073b95d438911a62a7f4d8244ef58e20a.tar.bz2
Modem is now working
Kindly called from Germany to Switzerland via rfcomm( affix) + Nokia6210 + Vodafone... But now it's working might be a hangup problem somewhere
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/dialer.cpp24
-rw-r--r--noncore/apps/opie-console/io_modem.cpp10
-rw-r--r--noncore/apps/opie-console/io_serial.cpp7
3 files changed, 29 insertions, 12 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp
index ce2b688..8524422 100644
--- a/noncore/apps/opie-console/dialer.cpp
+++ b/noncore/apps/opie-console/dialer.cpp
@@ -1,311 +1,319 @@
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
50Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name) 50Dialer::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
84Dialer::~Dialer() 84Dialer::~Dialer()
85{ 85{
86} 86}
87 87
88void Dialer::setHangupOnly() 88void Dialer::setHangupOnly()
89{ 89{
90 state = state_cancel; 90 state = state_cancel;
91 usercancel = 1; 91 usercancel = 1;
92 send("+++ATH\r");
92} 93}
93 94
94void Dialer::slotCancel() 95void Dialer::slotCancel()
95{ 96{
96 if(state != state_online) 97 if(state != state_online)
97 { 98 {
98 usercancel = 1; 99 usercancel = 1;
99 reset(); 100 reset();
100 } 101 }
101 else accept(); 102 else {
103 accept();
104 }
102} 105}
103 106
104void Dialer::reset() 107void Dialer::reset()
105{ 108{
106 qWarning("reset"); 109 qWarning("reset");
107 switchState(state_cancel); 110 switchState(state_cancel);
108} 111}
109 112
110void Dialer::slotAutostart() 113void Dialer::slotAutostart()
111{ 114{
112 //state = state_preinit; 115 //state = state_preinit;
113 dial(m_profile.readEntry("Number")); 116 dial(m_profile.readEntry("Number"));
114} 117}
115 118
116void Dialer::dial(const QString& number) 119void Dialer::dial(const QString& number)
117{ 120{
118 while(state != state_online) 121 while(state != state_online)
119 { 122 {
120 if(!usercancel) 123 if(!usercancel)
121 { 124 {
122 state = state_preinit; 125 state = state_preinit;
123 trydial(number); 126 trydial(number);
124 } 127 }
125 else break; 128 else break;
126 } 129 }
127 130
128 if(usercancel) 131 if(usercancel)
129 { 132 {
130 // modem hangup 133 // modem hangup
131 trydial(QString::null); 134 trydial(QString::null);
132 reject(); 135 reject();
133 } 136 }
134} 137}
135 138
136void Dialer::trydial(const QString& number) 139void Dialer::trydial(const QString& number)
137{ 140{
138 qWarning("TryDial:%s", number.latin1() ); 141 qWarning("TryDial:%s", number.latin1() );
139 if(state != state_cancel) switchState(state_preinit); 142 if(state != state_cancel) switchState(state_preinit);
140 if(cleanshutdown) 143 if(cleanshutdown)
141 { 144 {
142 qWarning("HangupString " + m_profile.readEntry("HangupString")); 145 qWarning("HangupString " + m_profile.readEntry("HangupString"));
143 send(m_profile.readEntry("HangupString")); 146 //send(m_profile.readEntry("HangupString"));
144 //send("+++ATH"); 147 send("+++ATH\r");
145 send(""); 148 //send("");
146 } 149 }
147 150
148 if(state != state_cancel) 151 if(state != state_cancel)
149 { 152 {
150 switchState(state_init); 153 switchState(state_init);
151 //send("ATZ"); 154 //send("ATZ");
152 qWarning("Init String " + m_profile.readEntry("InitString") ); 155 qWarning("Init String " + m_profile.readEntry("InitString") );
153 // send(m_profile.readEntry("InitString", "AT")); 156 // send(m_profile.readEntry("InitString", "AT"));
154 send("AT\r"); 157 send("AT\r");
155 QString response2 = receive(); 158 QString response2 = receive();
156 if(!response2.contains("\nOK\r")) 159 if(!response2.contains("\nOK\r"))
157 reset(); 160 reset();
158 } 161 }
159 162
160 /*if(state != state_cancel) 163 /*if(state != state_cancel)
161 { 164 {
162 switchState(state_options); 165 switchState(state_options);
163 166
164 qWarning("ATM3l3"); 167 qWarning("ATM3l3");
165 send("ATM3L3\r"); 168 send("ATM3L3\r");
166 QString response3 = receive(); 169 QString response3 = receive();
167 if(!response3.contains("\nOK\r")) 170 if(!response3.contains("\nOK\r"))
168 reset(); 171 reset();
169 } 172 }
170*/ 173*/
171 174
172 if(state != state_cancel) 175 if(state != state_cancel)
173 { 176 {
174 switchState(state_dialtone); 177 switchState(state_dialtone);
175 178
176 send("ATX1\r"); 179 send("ATX1\r");
177 QString response4 = receive(); 180 QString response4 = receive();
178 if(!response4.contains("\nOK\r")) 181 if(!response4.contains("\nOK\r"))
179 reset(); 182 reset();
180 } 183 }
181 184
182 if(state != state_cancel) 185 if(state != state_cancel)
183 { 186 {
184 qWarning("progress"); 187 qWarning("progress");
185 switchState(state_dialing); 188 switchState(state_dialing);
186 189
187 send(QString("ATDT %1\r").arg(number)); 190 send(QString("ATDT %1\r").arg(number));
188 // send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); 191 // send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number));
189 QString response5 = receive(); 192 QString response5 = receive();
190 if(!response5.contains("\n" + m_profile.readEntry("DefaultConnect"))) 193 if(!response5.contains("CONNECT") )
191 { 194 {
192 if(response5.contains("BUSY")) 195 if(response5.contains("BUSY"))
193 switchState(state_dialing); 196 switchState(state_dialing);
194 else 197 else
195 { 198 {
196 QMessageBox::warning(this, 199 QMessageBox::warning(this,
197 QObject::tr("Failure"), 200 QObject::tr("Failure"),
198 QObject::tr("Dialing the number failed.")); 201 QObject::tr("Dialing the number failed."));
199 slotCancel(); 202 slotCancel();
200 } 203 }
201 } 204 }
202 } 205 }
203 206
207
204 if(state != state_cancel) 208 if(state != state_cancel)
205 { 209 {
206 switchState(state_online); 210 state = state_online;
211 slotCancel();
207 } 212 }
208} 213}
209 214
210void Dialer::send(const QString& msg) 215void Dialer::send(const QString& msg)
211{ 216{
212 QString m = msg; 217 QString m = msg;
213 int bytes; 218 int bytes;
214 QString termination; 219 QString termination;
215 220
216 qWarning("Sending: %s", m.latin1()); 221 qWarning("Sending: %s", m.latin1());
217 222
218 /*termination = "\r"; 223 /*termination = "\r";
219 //termination = m_profile.readEntry("Termination"); 224 //termination = m_profile.readEntry("Termination");
220 if(termination == "\n") m = m + "\n"; 225 if(termination == "\n") m = m + "\n";
221 else if(termination == "\r") m = m + "\r"; 226 else if(termination == "\r") m = m + "\r";
222 else m = m + "\r\n"; 227 else m = m + "\r\n";
223*/ 228*/
224 m = m.replace(QRegExp("\n"), "\r"); 229 m = m.replace(QRegExp("\n"), "\r");
225 230
226 bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit())); 231 bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit()));
227 if(bytes < 0) 232 if(bytes < 0)
228 { 233 {
229 reset(); 234 reset();
230 } 235 }
231} 236}
232 237
233QString Dialer::receive() 238QString Dialer::receive()
234{ 239{
235 QString buf; 240 QString buf;
236 char buffer[1024]; 241 char buffer[1024];
237 int ret; 242 int ret;
238 int counter = 0; 243 int counter = 0;
239 244
240 while(1) 245 while(1)
241 { 246 {
242 ret = ::read(m_fd, buffer, sizeof(buffer)); 247 ret = ::read(m_fd, buffer, sizeof(buffer));
243 248
244 if(ret > 0) 249 if(ret > 0)
245 { 250 {
246 for(int i = 0; i < ret; i++) 251 for(int i = 0; i < ret; i++)
247 buffer[i] = buffer[i] & 0x7F; 252 buffer[i] = buffer[i] & 0x7F;
248 buffer[ret] = 0; 253 buffer[ret] = 0;
249 //qWarning("Got: '%s'", buffer); 254 qWarning("Got: %s", buffer);
250 buf.append(QString(buffer)); 255 buf.append(QString(buffer));
251 if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY"))) 256 if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY")))
252 { 257 {
253 //qWarning("Receiving: '%s'", buf.latin1()); 258 //qWarning("Receiving: '%s'", buf.latin1());
254 cleanshutdown = 1; 259 cleanshutdown = 1;
255 return buf; 260 return buf;
256 } 261 }else if (buf.contains("NO CARRIER") || buf.contains("NO DIALTONE") ) {
262 cleanshutdown = 1;
263 return QString::null;
264 }
257 } 265 }
258 else if(ret < 0) 266 else if(ret < 0)
259 { 267 {
260 if(errno != EAGAIN) reset(); 268 if(errno != EAGAIN) reset();
261 else if(!(counter++ % 100)) qApp->processEvents(); 269 else if(!(counter++ % 100)) qApp->processEvents();
262 } 270 }
263 else if(!(counter++ % 100)) qApp->processEvents(); 271 else if(!(counter++ % 100)) qApp->processEvents();
264 272
265 if(usercancel) return QString::null; 273 if(usercancel) return QString::null;
266 } 274 }
267 275
268 cleanshutdown = 1; 276 cleanshutdown = 1;
269 return QString::null; 277 return QString::null;
270} 278}
271 279
272void Dialer::switchState(int newstate) 280void Dialer::switchState(int newstate)
273{ 281{
274 int oldstate = state; 282 int oldstate = state;
275 state = newstate; 283 state = newstate;
276 284
277 switch(state) 285 switch(state)
278 { 286 {
279 case state_cancel: 287 case state_cancel:
280 status->setText(QObject::tr("Cancelling...")); 288 status->setText(QObject::tr("Cancelling..."));
281 progress->setProgress(0); 289 progress->setProgress(0);
282 break; 290 break;
283 case state_preinit: 291 case state_preinit:
284 status->setText(QObject::tr("Searching modem")); 292 status->setText(QObject::tr("Searching modem"));
285 progress->setProgress(10); 293 progress->setProgress(10);
286 break; 294 break;
287 case state_init: 295 case state_init:
288 status->setText(QObject::tr("Initializing...")); 296 status->setText(QObject::tr("Initializing..."));
289 progress->setProgress(20); 297 progress->setProgress(20);
290 break; 298 break;
291 case state_options: 299 case state_options:
292 status->setText(QObject::tr("Reset speakers")); 300 status->setText(QObject::tr("Reset speakers"));
293 progress->setProgress(30); 301 progress->setProgress(30);
294 break; 302 break;
295 case state_dialtone: 303 case state_dialtone:
296 status->setText(QObject::tr("Turning off dialtone")); 304 status->setText(QObject::tr("Turning off dialtone"));
297 progress->setProgress(40); 305 progress->setProgress(40);
298 break; 306 break;
299 case state_dialing: 307 case state_dialing:
300 if(oldstate != state_dialing) status->setText(QObject::tr("Dial number")); 308 if(oldstate != state_dialing) status->setText(QObject::tr("Dial number"));
301 else status->setText(QObject::tr("Line busy, redialing number")); 309 else status->setText(QObject::tr("Line busy, redialing number"));
302 progress->setProgress(50); 310 progress->setProgress(50);
303 break; 311 break;
304 case state_online: 312 case state_online:
305 status->setText(QObject::tr("Connection established")); 313 status->setText(QObject::tr("Connection established"));
306 progress->setProgress(100); 314 progress->setProgress(100);
307 cancel->setText(QObject::tr("Dismiss")); 315 cancel->setText(QObject::tr("Dismiss"));
308 break; 316 break;
309 } 317 }
310} 318}
311 319
diff --git a/noncore/apps/opie-console/io_modem.cpp b/noncore/apps/opie-console/io_modem.cpp
index b7901b9..896c24f 100644
--- a/noncore/apps/opie-console/io_modem.cpp
+++ b/noncore/apps/opie-console/io_modem.cpp
@@ -1,93 +1,95 @@
1 1
2#include "io_modem.h" 2#include "io_modem.h"
3 3
4#include "dialer.h" 4#include "dialer.h"
5 5
6IOModem::IOModem( const Profile &profile ) 6IOModem::IOModem( const Profile &profile )
7 : IOSerial( profile ) { 7 : IOSerial( profile ) {
8 m_profile = profile; 8 m_profile = profile;
9} 9}
10 10
11 11
12IOModem::~IOModem() { 12IOModem::~IOModem() {
13 13
14} 14}
15 15
16 16
17void IOModem::close() { 17void 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 internDetach();
21 Dialer d(m_profile, m_fd);
21 d.setHangupOnly(); 22 d.setHangupOnly();
22 d.exec(); 23 //d.exec();
23 closeRawIO(fd); 24 internAttach();
25 //closeRawIO(fd);
24 26
25 IOSerial::close(); 27 IOSerial::close();
26} 28}
27 29
28bool IOModem::open() { 30bool IOModem::open() {
29 bool ret = IOSerial::open(); 31 bool ret = IOSerial::open();
30 if(!ret) return false; 32 if(!ret) return false;
31 33
32 //int fd = rawIO(); 34 //int fd = rawIO();
33 internDetach(); 35 internDetach();
34 Dialer d(m_profile, m_fd); 36 Dialer d(m_profile, m_fd);
35 37
36 int result = d.exec(); 38 int result = d.exec();
37 internAttach(); 39 internAttach();
38 //closeRawIO(fd); 40 //closeRawIO(fd);
39 if(result == QDialog::Accepted) 41 if(result == QDialog::Accepted)
40 { 42 {
41 return true; 43 return true;
42 } 44 }
43 else 45 else
44 { 46 {
45 close(); 47 close();
46 return false; 48 return false;
47 } 49 }
48} 50}
49 51
50void IOModem::reload( const Profile &config ) { 52void IOModem::reload( const Profile &config ) {
51 53
52 m_device = config.readEntry("Device", MODEM_DEFAULT_DEVICE); 54 m_device = config.readEntry("Device", MODEM_DEFAULT_DEVICE);
53 m_baud = config.readNumEntry("Baud", MODEM_DEFAULT_BAUD); 55 m_baud = config.readNumEntry("Baud", MODEM_DEFAULT_BAUD);
54 m_parity = config.readNumEntry("Parity", MODEM_DEFAULT_PARITY); 56 m_parity = config.readNumEntry("Parity", MODEM_DEFAULT_PARITY);
55 m_dbits = config.readNumEntry("DataBits", MODEM_DEFAULT_DBITS); 57 m_dbits = config.readNumEntry("DataBits", MODEM_DEFAULT_DBITS);
56 m_sbits = config.readNumEntry("StopBits", MODEM_DEFAULT_SBITS); 58 m_sbits = config.readNumEntry("StopBits", MODEM_DEFAULT_SBITS);
57 m_flow = config.readNumEntry("Flow", MODEM_DEFAULT_FLOW); 59 m_flow = config.readNumEntry("Flow", MODEM_DEFAULT_FLOW);
58 60
59 m_initString = config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING ); 61 m_initString = config.readEntry("InitString", MODEM_DEFAULT_INIT_STRING );
60 m_resetString = config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ); 62 m_resetString = config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING );
61 m_dialPref1 = config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ); 63 m_dialPref1 = config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 );
62 m_dialSuf1 = config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ); 64 m_dialSuf1 = config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 );
63 m_dialPref2 = config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ); 65 m_dialPref2 = config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 );
64 m_dialSuf2 = config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ); 66 m_dialSuf2 = config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 );
65 m_dialPref3 = config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ); 67 m_dialPref3 = config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 );
66 m_dialSuf3 = config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ); 68 m_dialSuf3 = config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 );
67 m_connect = config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ); 69 m_connect = config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING );
68 m_hangup = config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ); 70 m_hangup = config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING );
69 m_cancel = config.readEntry("CancelString", MODEM_DEFAULT_CANCEL_STRING ); 71 m_cancel = config.readEntry("CancelString", MODEM_DEFAULT_CANCEL_STRING );
70 m_dialTime = config.readNumEntry("DialTime", MODEM_DEFAULT_DIAL_TIME ); 72 m_dialTime = config.readNumEntry("DialTime", MODEM_DEFAULT_DIAL_TIME );
71 m_delayRedial = config.readNumEntry("DelayRedial", MODEM_DEFAULT_DELAY_REDIAL ); 73 m_delayRedial = config.readNumEntry("DelayRedial", MODEM_DEFAULT_DELAY_REDIAL );
72 m_numberTries = config.readNumEntry("NumberTries", MODEM_DEFAULT_NUMBER_TRIES ); 74 m_numberTries = config.readNumEntry("NumberTries", MODEM_DEFAULT_NUMBER_TRIES );
73 m_dtrDropTime = config.readNumEntry("DTRDRopTime", MODEM_DEFAULT_DTR_DROP_TIME ); 75 m_dtrDropTime = config.readNumEntry("DTRDRopTime", MODEM_DEFAULT_DTR_DROP_TIME );
74 m_bpsDetect = config.readBoolEntry("BPSDetect", MODEM_DEFAULT_BPS_DETECT ); 76 m_bpsDetect = config.readBoolEntry("BPSDetect", MODEM_DEFAULT_BPS_DETECT );
75 m_dcdLines = config.readBoolEntry("DCDLines", MODEM_DEFAULT_DCD_LINES ); 77 m_dcdLines = config.readBoolEntry("DCDLines", MODEM_DEFAULT_DCD_LINES );
76 m_multiLineUntag = config.readBoolEntry("MultiLineUntag", MODEM_DEFAULT_MULTI_LINE_UNTAG ); 78 m_multiLineUntag = config.readBoolEntry("MultiLineUntag", MODEM_DEFAULT_MULTI_LINE_UNTAG );
77} 79}
78 80
79 81
80QString IOModem::identifier() const { 82QString IOModem::identifier() const {
81 return "modem"; 83 return "modem";
82} 84}
83 85
84QString IOModem::name() const { 86QString IOModem::name() const {
85 return "Modem IO Layer"; 87 return "Modem IO Layer";
86} 88}
87 89
88void IOModem::slotExited(OProcess* proc ){ 90void IOModem::slotExited(OProcess* proc ){
89 close(); 91 close();
90 /* delete it afterwards */ 92 /* delete it afterwards */
91 delete proc; 93 delete proc;
92} 94}
93 95
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index 0540d9e..03e92dd 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -1,228 +1,235 @@
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 <stdio.h>
7
6#include "io_serial.h" 8#include "io_serial.h"
7 9
8IOSerial::IOSerial(const Profile &config) : IOLayer(config) { 10IOSerial::IOSerial(const Profile &config) : IOLayer(config) {
9 m_read = 0l; 11 m_read = 0l;
10 m_error = 0l; 12 m_error = 0l;
11 m_fd = 0; 13 m_fd = 0;
12 m_connected = false; 14 m_connected = false;
13 reload(config); 15 reload(config);
14} 16}
15 17
16 18
17IOSerial::~IOSerial() { 19IOSerial::~IOSerial() {
18 if (m_fd) { 20 if (m_fd) {
19 close(); 21 close();
20 } 22 }
21} 23}
22 24
23void IOSerial::send(const QByteArray &data) { 25void IOSerial::send(const QByteArray &data) {
24 if (m_fd) { 26 if (m_fd) {
25 write(m_fd, data.data(), data.size()); 27 write(m_fd, data.data(), data.size());
26 } else { 28 } else {
27 emit error(Refuse, tr("Not connected")); 29 emit error(Refuse, tr("Not connected"));
28 } 30 }
29} 31}
30 32
31void IOSerial::close() { 33void IOSerial::close() {
32 if (m_fd) { 34 if (m_fd) {
33 delete m_read; 35 delete m_read;
34 delete m_error; 36 delete m_error;
35 ::close(m_fd); 37 ::close(m_fd);
36 m_fd = 0; 38 m_fd = 0;
37 m_connected = false; 39 m_connected = false;
38 } else { 40 } else {
39 m_connected = false; 41 m_connected = false;
40 emit error(Refuse, tr("Not connected")); 42 emit error(Refuse, tr("Not connected"));
41 } 43 }
42} 44}
43 45
44bool IOSerial::open() { 46bool IOSerial::open() {
45 if (!m_fd) { 47 if (!m_fd) {
46 struct termios tty; 48 struct termios tty;
47 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); 49 m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK);
48 if (m_fd < 0) { 50 if (m_fd < 0) {
49 emit error(CouldNotOpen, strerror(errno)); 51 emit error(CouldNotOpen, strerror(errno));
50 m_fd = 0; 52 m_fd = 0;
51 return FALSE; 53 return FALSE;
52 } 54 }
53 tcgetattr(m_fd, &tty); 55 tcgetattr(m_fd, &tty);
54 56
55 /* Baud rate */ 57 /* Baud rate */
56 int speed = baud(m_baud); 58 int speed = baud(m_baud);
57 if (speed == -1) { 59 if (speed == -1) {
58 emit error(Refuse, tr("Invalid baud rate")); 60 emit error(Refuse, tr("Invalid baud rate"));
59 } 61 }
60 cfsetospeed(&tty, speed); 62 cfsetospeed(&tty, speed);
61 cfsetispeed(&tty, speed); 63 cfsetispeed(&tty, speed);
62 64
63 /* Take care of Space / Mark parity */ 65 /* Take care of Space / Mark parity */
64 if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { 66 if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) {
65 m_dbits = 8; 67 m_dbits = 8;
66 } 68 }
67 69
68 /* Data bits */ 70 /* Data bits */
69 switch (m_dbits) { 71 switch (m_dbits) {
70 case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; 72 case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break;
71 case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; 73 case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break;
72 case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; 74 case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break;
73 case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; 75 case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break;
74 default: break; 76 default: break;
75 } 77 }
76 78
77 /* Raw, no echo mode */ 79 /* Raw, no echo mode */
78 tty.c_iflag = IGNBRK; 80 tty.c_iflag = IGNBRK;
79 tty.c_lflag = 0; 81 tty.c_lflag = 0;
80 tty.c_oflag = 0; 82 tty.c_oflag = 0;
81 tty.c_cflag |= CLOCAL | CREAD; 83 tty.c_cflag |= CLOCAL | CREAD;
82 84
83 /* Stop bits */ 85 /* Stop bits */
84 if (m_sbits == 2) { 86 if (m_sbits == 2) {
85 tty.c_cflag |= CSTOPB; 87 tty.c_cflag |= CSTOPB;
86 } else { 88 } else {
87 tty.c_cflag &= ~CSTOPB; 89 tty.c_cflag &= ~CSTOPB;
88 } 90 }
89 91
90 tty.c_cc[VMIN] = 1; 92 tty.c_cc[VMIN] = 1;
91 tty.c_cc[VTIME] = 5; 93 tty.c_cc[VTIME] = 5;
92 94
93 /* Flow control */ 95 /* Flow control */
94 if (m_flow & FlowSW) 96 if (m_flow & FlowSW)
95 tty.c_iflag |= IXON | IXOFF; 97 tty.c_iflag |= IXON | IXOFF;
96 else 98 else
97 tty.c_iflag &= ~(IXON|IXOFF|IXANY); 99 tty.c_iflag &= ~(IXON|IXOFF|IXANY);
98 100
99 if (m_flow & FlowHW) 101 if (m_flow & FlowHW)
100 tty.c_cflag |= CRTSCTS; 102 tty.c_cflag |= CRTSCTS;
101 else 103 else
102 tty.c_cflag &= ~CRTSCTS; 104 tty.c_cflag &= ~CRTSCTS;
103 105
104 /* Parity */ 106 /* Parity */
105 tty.c_cflag &= ~(PARENB | PARODD); 107 tty.c_cflag &= ~(PARENB | PARODD);
106 if (m_parity & ParityEven) 108 if (m_parity & ParityEven)
107 tty.c_cflag |= PARENB; 109 tty.c_cflag |= PARENB;
108 else if (m_parity & ParityOdd) 110 else if (m_parity & ParityOdd)
109 tty.c_cflag |= (PARENB | PARODD); 111 tty.c_cflag |= (PARENB | PARODD);
110 112
111 /* Set the changes */ 113 /* Set the changes */
112 tcsetattr(m_fd, TCSANOW, &tty); 114 tcsetattr(m_fd, TCSANOW, &tty);
113 115
114 /* Notifications on read & errors */ 116 /* Notifications on read & errors */
115 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); 117 m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
116 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); 118 m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this);
117 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 119 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
118 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 120 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
119 m_connected = false; 121 m_connected = false;
120 return TRUE; 122 return TRUE;
121 } else { 123 } else {
122 emit error(Refuse, tr("Device is already connected")); 124 emit error(Refuse, tr("Device is already connected"));
123 m_fd = 0; 125 m_fd = 0;
124 return FALSE; 126 return FALSE;
125 } 127 }
126} 128}
127 129
128void IOSerial::reload(const Profile &config) { 130void IOSerial::reload(const Profile &config) {
129 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); 131 m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE);
130 m_baud = config.readNumEntry("Speed", SERIAL_DEFAULT_BAUD); 132 m_baud = config.readNumEntry("Speed", SERIAL_DEFAULT_BAUD);
131 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); 133 m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY);
132 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); 134 m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS);
133 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); 135 m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS);
134 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); 136 m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW);
135 137
136} 138}
137 139
138int IOSerial::baud(int baud) const { 140int IOSerial::baud(int baud) const {
139 switch (baud) { 141 switch (baud) {
140 case 300: return B300; break; 142 case 300: return B300; break;
141 case 600: return B600; break; 143 case 600: return B600; break;
142 case 1200: return B1200; break; 144 case 1200: return B1200; break;
143 case 2400: return B2400; break; 145 case 2400: return B2400; break;
144 case 4800: return B4800; break; 146 case 4800: return B4800; break;
145 case 9600: return B9600; break; 147 case 9600: return B9600; break;
146 case 19200: return B19200; break; 148 case 19200: return B19200; break;
147 case 38400: return B38400; break; 149 case 38400: return B38400; break;
148 case 57600: return B57600; break; 150 case 57600: return B57600; break;
149 case 115200: return B115200; break; 151 case 115200: return B115200; break;
150 } 152 }
151 return -1; 153 return -1;
152} 154}
153 155
154void IOSerial::errorOccured() { 156void IOSerial::errorOccured() {
155 emit error(ClosedUnexpected, strerror(errno)); 157 emit error(ClosedUnexpected, strerror(errno));
156 close(); 158 close();
157} 159}
158 160
159void IOSerial::dataArrived() { 161void IOSerial::dataArrived() {
160 QByteArray array(4097); 162 QByteArray array(4097);
161 163
162 int len = read(m_fd, array.data(), 4096); 164 int len = read(m_fd, array.data(), 4096);
163 if (len == 0) 165 if (len == 0)
164 close(); 166 close();
165 if (len < 0) 167 if (len < 0)
166 return; 168 return;
169 qWarning("got from layer");
170 for (int i = 0; i < len; i++ ) {
171 printf("%c", array[i] );
172 }
173 printf("\n");
167 array.resize( len ); 174 array.resize( len );
168 emit received(array); 175 emit received(array);
169} 176}
170 177
171QString IOSerial::identifier() const { 178QString IOSerial::identifier() const {
172 return "serial"; 179 return "serial";
173} 180}
174 181
175QString IOSerial::name() const { 182QString IOSerial::name() const {
176 return "RS232 Serial IO Layer"; 183 return "RS232 Serial IO Layer";
177} 184}
178int IOSerial::rawIO()const { 185int IOSerial::rawIO()const {
179 if (m_read ) 186 if (m_read )
180 disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 187 disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
181 if (m_error ) 188 if (m_error )
182 disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 189 disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
183 190
184 int fd = ::open(m_device, O_RDWR ); 191 int fd = ::open(m_device, O_RDWR );
185 192
186 return fd; 193 return fd;
187}; 194};
188void IOSerial::closeRawIO(int fd) { 195void IOSerial::closeRawIO(int fd) {
189 if (m_read ) 196 if (m_read )
190 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 197 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
191 if (m_error ) 198 if (m_error )
192 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 199 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
193 200
194 ::close( fd ); 201 ::close( fd );
195} 202}
196QBitArray IOSerial::supports()const { 203QBitArray IOSerial::supports()const {
197 QBitArray ar(3); 204 QBitArray ar(3);
198 ar[0] = ar[2] = 0; 205 ar[0] = ar[2] = 0;
199 ar[1] = 1; 206 ar[1] = 1;
200 207
201 return ar; 208 return ar;
202} 209}
203 210
204bool IOSerial::isConnected() { 211bool IOSerial::isConnected() {
205 return m_connected; 212 return m_connected;
206} 213}
207 214
208/* 215/*
209 * this is used to give the 216 * this is used to give the
210 * class below IOSerial 217 * class below IOSerial
211 * the possibility of 218 * the possibility of
212 * exclusive usage 219 * exclusive usage
213 */ 220 */
214void IOSerial::internDetach() { 221void IOSerial::internDetach() {
215 if (m_read ) 222 if (m_read )
216 disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 223 disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
217 if (m_error ) 224 if (m_error )
218 disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 225 disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
219} 226}
220/* 227/*
221 * give power back 228 * give power back
222 */ 229 */
223void IOSerial::internAttach() { 230void IOSerial::internAttach() {
224 if (m_read ) 231 if (m_read )
225 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); 232 connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
226 if (m_error ) 233 if (m_error )
227 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); 234 connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
228} 235}