author | josef <josef> | 2002-10-17 21:32:37 (UTC) |
---|---|---|
committer | josef <josef> | 2002-10-17 21:32:37 (UTC) |
commit | 667e17b43b6de0bfce7ab83cb132a0f454a428f0 (patch) (unidiff) | |
tree | 2dbc5bf1e83f7961845b847e92fce61e428f8512 | |
parent | 1acda09af779926cc0756d5e5cdf4a67b9dece98 (diff) | |
download | opie-667e17b43b6de0bfce7ab83cb132a0f454a428f0.zip opie-667e17b43b6de0bfce7ab83cb132a0f454a428f0.tar.gz opie-667e17b43b6de0bfce7ab83cb132a0f454a428f0.tar.bz2 |
- make modem dialup widget really work
- still todo: communication after dialing number, and error checks
-rw-r--r-- | noncore/apps/opie-console/dialer.cpp | 73 | ||||
-rw-r--r-- | noncore/apps/opie-console/dialer.h | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/io_modem.cpp | 2 |
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 | |||
@@ -8,2 +8,3 @@ | |||
8 | #include <qtimer.h> | 8 | #include <qtimer.h> |
9 | #include <qmessagebox.h> | ||
9 | 10 | ||
@@ -11,2 +12,4 @@ | |||
11 | #include <string.h> | 12 | #include <string.h> |
13 | #include <fcntl.h> | ||
14 | #include <errno.h> | ||
12 | 15 | ||
@@ -46,4 +49,4 @@ | |||
46 | 49 | ||
47 | Dialer::Dialer(const Profile& profile, QWidget *parent, const char *name) | 50 | Dialer::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 | { |
@@ -52,4 +55,10 @@ Dialer::Dialer(const Profile& profile, QWidget *parent, const char *name) | |||
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); |
@@ -94,3 +103,3 @@ void Dialer::slotAutostart() | |||
94 | { | 103 | { |
95 | state = state_preinit; | 104 | //state = state_preinit; |
96 | dial(m_profile.readEntry("Number")); | 105 | dial(m_profile.readEntry("Number")); |
@@ -104,2 +113,3 @@ void Dialer::dial(const QString& number) | |||
104 | { | 113 | { |
114 | state = state_preinit; | ||
105 | trydial(number); | 115 | trydial(number); |
@@ -120,4 +130,5 @@ void Dialer::trydial(const QString& number) | |||
120 | switchState(state_preinit); | 130 | switchState(state_preinit); |
121 | // ... | 131 | send("+++ATH"); |
122 | QString response = receive(); | 132 | send(""); |
133 | //QString response = receive(); | ||
123 | } | 134 | } |
@@ -127,5 +138,7 @@ void Dialer::trydial(const QString& number) | |||
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 | } |
@@ -138,2 +151,4 @@ void Dialer::trydial(const QString& number) | |||
138 | QString response3 = receive(); | 151 | QString response3 = receive(); |
152 | if(!response3.contains("\nOK\r")) | ||
153 | reset(); | ||
139 | } | 154 | } |
@@ -146,2 +161,4 @@ void Dialer::trydial(const QString& number) | |||
146 | QString response4 = receive(); | 161 | QString response4 = receive(); |
162 | if(!response4.contains("\nOK\r")) | ||
163 | reset(); | ||
147 | } | 164 | } |
@@ -152,4 +169,12 @@ void Dialer::trydial(const QString& number) | |||
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 | } |
@@ -168,3 +193,6 @@ void Dialer::send(const QString& msg) | |||
168 | 193 | ||
169 | termination = m_profile.readEntry("Termination"); | 194 | qWarning("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"; |
@@ -173,3 +201,3 @@ void Dialer::send(const QString& msg) | |||
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) |
@@ -182,4 +210,25 @@ QString 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; |
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 | |||
@@ -14,3 +14,3 @@ class Dialer : public QDialog | |||
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(); |
@@ -47,2 +47,3 @@ class Dialer : public QDialog | |||
47 | const Profile& m_profile; | 47 | const Profile& m_profile; |
48 | int m_fd; | ||
48 | }; | 49 | }; |
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 | |||
@@ -26,3 +26,3 @@ bool IOModem::open() { | |||
26 | 26 | ||
27 | Dialer d(m_profile); | 27 | Dialer d(m_profile, rawIO()); |
28 | 28 | ||