summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore 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
@@ -6,9 +6,12 @@
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.
@@ -44,14 +47,20 @@
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);
@@ -92,7 +101,7 @@ void Dialer::reset()
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
@@ -102,6 +111,7 @@ void Dialer::dial(const QString& number)
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;
@@ -118,16 +128,19 @@ void Dialer::trydial(const QString& number)
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)
@@ -136,6 +149,8 @@ void Dialer::trydial(const QString& number)
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)
@@ -144,14 +159,24 @@ void Dialer::trydial(const QString& number)
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)
@@ -166,12 +191,15 @@ void Dialer::send(const QString& 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();
@@ -180,8 +208,29 @@ void Dialer::send(const QString& msg)
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
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
@@ -12,7 +12,7 @@ class 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:
@@ -45,6 +45,7 @@ class Dialer : public QDialog
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
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
@@ -24,7 +24,7 @@ bool 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)