summaryrefslogtreecommitdiff
path: root/noncore/apps
Unidiff
Diffstat (limited to 'noncore/apps') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-console/dialer.cpp73
-rw-r--r--noncore/apps/opie-console/dialer.h3
-rw-r--r--noncore/apps/opie-console/io_modem.cpp2
3 files changed, 64 insertions, 14 deletions
diff --git a/noncore/apps/opie-console/dialer.cpp b/noncore/apps/opie-console/dialer.cpp
index 89a0e8d..10c16ef 100644
--- a/noncore/apps/opie-console/dialer.cpp
+++ b/noncore/apps/opie-console/dialer.cpp
@@ -3,15 +3,18 @@
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 10
10#include <unistd.h> 11#include <unistd.h>
11#include <string.h> 12#include <string.h>
13#include <fcntl.h>
14#include <errno.h>
12 15
13// State machine: | When an error occurs, we don't have to 16// State machine: | When an error occurs, we don't have to
14// | reset everything. 17// | reset everything.
15// (init) <------+ | But if the user wants to reset, 18// (init) <------+ | But if the user wants to reset,
16// | | | we stop dialing immediately. 19// | | | we stop dialing immediately.
17// v | | 20// v | |
@@ -41,20 +44,26 @@
41// from modemconfigwidget 44// from modemconfigwidget
42//int rad_flow = prof.readNumEntry("Flow"); 45//int rad_flow = prof.readNumEntry("Flow");
43//int rad_parity = prof.readNumEntry("Parity"); 46//int rad_parity = prof.readNumEntry("Parity");
44//int speed = prof.readNumEntry("Speed"); 47//int speed = prof.readNumEntry("Speed");
45//QString number = prof.readEntry("Number"); 48//QString number = prof.readEntry("Number");
46 49
47Dialer::Dialer(const Profile& profile, QWidget *parent, const char *name) 50Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name)
48: QDialog(parent, name, true), m_profile(profile) 51: QDialog(parent, name, true), m_fd(fd), m_profile(profile)
49{ 52{
50 QVBoxLayout *vbox; 53 QVBoxLayout *vbox;
51 QLabel *desc; 54 QLabel *desc;
52 55
56 //m_profile.writeEntry("InitString", "ATZ");
57 //m_profile.writeEntry("DialPrefix1", "ATDT");
58 //m_profile.writeEntry("Termination", "\n");
59
53 usercancel = 0; 60 usercancel = 0;
54 61
62 fcntl(m_fd, F_SETFL, O_NONBLOCK);
63
55 desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this); 64 desc = new QLabel(QObject::tr("Dialing number: %1").arg(m_profile.readEntry("Number")), this);
56 progress = new QProgressBar(this); 65 progress = new QProgressBar(this);
57 status = new QLabel("", this); 66 status = new QLabel("", this);
58 status->setFrameStyle(QFrame::Panel | QFrame::Sunken); 67 status->setFrameStyle(QFrame::Panel | QFrame::Sunken);
59 cancel = new QPushButton(QObject::tr("Cancel"), this); 68 cancel = new QPushButton(QObject::tr("Cancel"), this);
60 69
@@ -89,22 +98,23 @@ void Dialer::reset()
89{ 98{
90 switchState(state_cancel); 99 switchState(state_cancel);
91} 100}
92 101
93void Dialer::slotAutostart() 102void Dialer::slotAutostart()
94{ 103{
95 state = state_preinit; 104 //state = state_preinit;
96 dial(m_profile.readEntry("Number")); 105 dial(m_profile.readEntry("Number"));
97} 106}
98 107
99void Dialer::dial(const QString& number) 108void Dialer::dial(const QString& number)
100{ 109{
101 while(state != state_online) 110 while(state != state_online)
102 { 111 {
103 if(!usercancel) 112 if(!usercancel)
104 { 113 {
114 state = state_preinit;
105 trydial(number); 115 trydial(number);
106 } 116 }
107 else break; 117 else break;
108 } 118 }
109 119
110 if(usercancel) 120 if(usercancel)
@@ -115,46 +125,61 @@ void Dialer::dial(const QString& number)
115 125
116void Dialer::trydial(const QString& number) 126void Dialer::trydial(const QString& number)
117{ 127{
118 if(state != state_cancel) 128 if(state != state_cancel)
119 { 129 {
120 switchState(state_preinit); 130 switchState(state_preinit);
121 // ... 131 send("+++ATH");
122 QString response = receive(); 132 send("");
133 //QString response = receive();
123 } 134 }
124 135
125 if(state != state_cancel) 136 if(state != state_cancel)
126 { 137 {
127 switchState(state_init); 138 switchState(state_init);
128 //send("ATZ"); 139 send("ATZ");
129 send(m_profile.readEntry("InitString")); 140 //send(m_profile.readEntry("InitString"));
130 QString response2 = receive(); 141 QString response2 = receive();
142 if(!response2.contains("\nOK\r"))
143 reset();
131 } 144 }
132 145
133 if(state != state_cancel) 146 if(state != state_cancel)
134 { 147 {
135 switchState(state_options); 148 switchState(state_options);
136 149
137 send("ATM0L0"); 150 send("ATM0L0");
138 QString response3 = receive(); 151 QString response3 = receive();
152 if(!response3.contains("\nOK\r"))
153 reset();
139 } 154 }
140 155
141 if(state != state_cancel) 156 if(state != state_cancel)
142 { 157 {
143 switchState(state_dialtone); 158 switchState(state_dialtone);
144 159
145 send("ATX1"); 160 send("ATX1");
146 QString response4 = receive(); 161 QString response4 = receive();
162 if(!response4.contains("\nOK\r"))
163 reset();
147 } 164 }
148 165
149 if(state != state_cancel) 166 if(state != state_cancel)
150 { 167 {
151 switchState(state_dialing); 168 switchState(state_dialing);
152 169
153 send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number)); 170 send(QString("ATDT %1").arg(number));
171 //send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number));
154 QString response5 = receive(); 172 QString response5 = receive();
173 if(!response5.contains("\nOK\r"))
174 {
175 QMessageBox::warning(this,
176 QObject::tr("Failure"),
177 QObject::tr("Dialing the number failed."));
178 slotCancel();
179 }
155 } 180 }
156 181
157 if(state != state_cancel) 182 if(state != state_cancel)
158 { 183 {
159 switchState(state_online); 184 switchState(state_online);
160 } 185 }
@@ -163,28 +188,52 @@ void Dialer::trydial(const QString& number)
163void Dialer::send(const QString& msg) 188void Dialer::send(const QString& msg)
164{ 189{
165 QString m = msg; 190 QString m = msg;
166 int bytes; 191 int bytes;
167 QString termination; 192 QString termination;
168 193
169 termination = m_profile.readEntry("Termination"); 194qWarning("Sending: '%s'", m.latin1());
195
196 termination = "\r";
197 //termination = m_profile.readEntry("Termination");
170 if(termination == "\n") m = m + "\n"; 198 if(termination == "\n") m = m + "\n";
171 else if(termination == "\r") m = m + "\r"; 199 else if(termination == "\r") m = m + "\r";
172 else m = m + "\r\n"; 200 else m = m + "\r\n";
173 201
174 bytes = write(0, m.local8Bit(), strlen(m.local8Bit())); 202 bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit()));
175 if(bytes < 0) 203 if(bytes < 0)
176 { 204 {
177 reset(); 205 reset();
178 } 206 }
179} 207}
180 208
181QString Dialer::receive() 209QString Dialer::receive()
182{ 210{
183 for(int i = 0; i < 200000;i++) 211 char buffer[1024];
184 qApp->processEvents(); 212 int ret;
213
214 while(1)
215 {
216 ret = ::read(m_fd, buffer, sizeof(buffer));
217
218 if(ret > 0)
219 {
220 for(int i = 0; i < ret; i++)
221 buffer[i] = buffer[i] & 0x7F;
222 buffer[ret] = 0;
223 qWarning("Receiving: '%s'", buffer);
224 return QString(buffer);
225 }
226 else if(ret < 0)
227 {
228 if(errno != EAGAIN) reset();
229 }
230 }
231
232 //for(int i = 0; i < 200000;i++)
233 //qApp->processEvents();
185 return QString::null; 234 return QString::null;
186} 235}
187 236
188void Dialer::switchState(int newstate) 237void Dialer::switchState(int newstate)
189{ 238{
190 int oldstate = state; 239 int oldstate = state;
diff --git a/noncore/apps/opie-console/dialer.h b/noncore/apps/opie-console/dialer.h
index 09cc5ca..4011880 100644
--- a/noncore/apps/opie-console/dialer.h
+++ b/noncore/apps/opie-console/dialer.h
@@ -9,13 +9,13 @@ class QLabel;
9class QProgressBar; 9class QProgressBar;
10 10
11class Dialer : public QDialog 11class Dialer : public QDialog
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14 public: 14 public:
15 Dialer(const Profile& profile, QWidget *parent = NULL, const char *name = NULL); 15 Dialer(const Profile& profile, int fd, QWidget *parent = NULL, const char *name = NULL);
16 ~Dialer(); 16 ~Dialer();
17 17
18 public slots: 18 public slots:
19 void slotCancel(); 19 void slotCancel();
20 void slotAutostart(); 20 void slotAutostart();
21 21
@@ -42,10 +42,11 @@ class Dialer : public QDialog
42 QLabel *status; 42 QLabel *status;
43 QProgressBar *progress; 43 QProgressBar *progress;
44 QPushButton *cancel; 44 QPushButton *cancel;
45 int state; 45 int state;
46 int usercancel; 46 int usercancel;
47 const Profile& m_profile; 47 const Profile& m_profile;
48 int m_fd;
48}; 49};
49 50
50#endif 51#endif
51 52
diff --git a/noncore/apps/opie-console/io_modem.cpp b/noncore/apps/opie-console/io_modem.cpp
index 41f553b..c04aad1 100644
--- a/noncore/apps/opie-console/io_modem.cpp
+++ b/noncore/apps/opie-console/io_modem.cpp
@@ -21,13 +21,13 @@ void IOModem::close() {
21} 21}
22 22
23bool IOModem::open() { 23bool IOModem::open() {
24 bool ret = IOSerial::open(); 24 bool ret = IOSerial::open();
25 if(!ret) return false; 25 if(!ret) return false;
26 26
27 Dialer d(m_profile); 27 Dialer d(m_profile, rawIO());
28 28
29 int result = d.exec(); 29 int result = d.exec();
30 if(result == QDialog::Accepted) 30 if(result == QDialog::Accepted)
31 { 31 {
32 return true; 32 return true;
33 } 33 }