-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 | |||
@@ -1,27 +1,30 @@ | |||
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 | 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 | | |
18 | // (options) ----+ | Following the state machine is necessary | 21 | // (options) ----+ | Following the state machine is necessary |
19 | // | \ | to get determinable results. | 22 | // | \ | to get determinable results. |
20 | // v ^ | | 23 | // v ^ | |
21 | // (dial) ----+ | | 24 | // (dial) ----+ | |
22 | // | ^ | | 25 | // | ^ | |
23 | // v | | | 26 | // v | | |
24 | // (online) --+ | | 27 | // (online) --+ | |
25 | // | | | 28 | // | | |
26 | // v | | 29 | // v | |
27 | 30 | ||
@@ -31,40 +34,46 @@ | |||
31 | //resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) ); | 34 | //resetStringLine->setText( config.readEntry("ResetString", MODEM_DEFAULT_RESET_STRING ) ); |
32 | //dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 35 | //dialPref1Line->setText( config.readEntry("DialPrefix1", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
33 | //dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 36 | //dialSuf1Line->setText( config.readEntry("DialSuffix1", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
34 | //dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 37 | //dialPref2Line->setText( config.readEntry("DialPrefix2", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
35 | //dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 38 | //dialSuf2Line->setText( config.readEntry("DialSuffix2", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
36 | //dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) ); | 39 | //dialPref3Line->setText( config.readEntry("DialPrefix3", MODEM_DEFAULT_DIAL_PREFIX1 ) ); |
37 | //dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); | 40 | //dialSuf3Line->setText( config.readEntry("DialSuffix3", MODEM_DEFAULT_DIAL_SUFFIX1 ) ); |
38 | //connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) ); | 41 | //connectLine->setText( config.readEntry("DefaultConnect" MODEM_DEFAULT_CONNECT_STRING ) ); |
39 | //hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) ); | 42 | //hangupLine->setText( config.readEntry("HangupString", MODEM_DEFAULT_HANGUP_STRING ) ); |
40 | 43 | ||
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 | ||
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 | { |
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 | ||
61 | vbox = new QVBoxLayout(this, 2); | 70 | vbox = new QVBoxLayout(this, 2); |
62 | vbox->add(desc); | 71 | vbox->add(desc); |
63 | vbox->add(progress); | 72 | vbox->add(progress); |
64 | vbox->add(status); | 73 | vbox->add(status); |
65 | vbox->add(cancel); | 74 | vbox->add(cancel); |
66 | 75 | ||
67 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); | 76 | connect(cancel, SIGNAL(clicked()), SLOT(slotCancel())); |
68 | 77 | ||
69 | show(); | 78 | show(); |
70 | 79 | ||
@@ -79,122 +88,162 @@ void Dialer::slotCancel() | |||
79 | { | 88 | { |
80 | if(state != state_online) | 89 | if(state != state_online) |
81 | { | 90 | { |
82 | usercancel = 1; | 91 | usercancel = 1; |
83 | reset(); | 92 | reset(); |
84 | } | 93 | } |
85 | else accept(); | 94 | else accept(); |
86 | } | 95 | } |
87 | 96 | ||
88 | void Dialer::reset() | 97 | void Dialer::reset() |
89 | { | 98 | { |
90 | switchState(state_cancel); | 99 | switchState(state_cancel); |
91 | } | 100 | } |
92 | 101 | ||
93 | void Dialer::slotAutostart() | 102 | 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")); |
97 | } | 106 | } |
98 | 107 | ||
99 | void Dialer::dial(const QString& number) | 108 | void 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) |
111 | { | 121 | { |
112 | reject(); | 122 | reject(); |
113 | } | 123 | } |
114 | } | 124 | } |
115 | 125 | ||
116 | void Dialer::trydial(const QString& number) | 126 | void 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 | } |
161 | } | 186 | } |
162 | 187 | ||
163 | void Dialer::send(const QString& msg) | 188 | void 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"); | 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"; |
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 | ||
181 | QString Dialer::receive() | 209 | 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; |
186 | } | 235 | } |
187 | 236 | ||
188 | void Dialer::switchState(int newstate) | 237 | void Dialer::switchState(int newstate) |
189 | { | 238 | { |
190 | int oldstate = state; | 239 | int oldstate = state; |
191 | state = newstate; | 240 | state = newstate; |
192 | 241 | ||
193 | switch(state) | 242 | switch(state) |
194 | { | 243 | { |
195 | case state_cancel: | 244 | case state_cancel: |
196 | status->setText(QObject::tr("Cancelling...")); | 245 | status->setText(QObject::tr("Cancelling...")); |
197 | progress->setProgress(0); | 246 | progress->setProgress(0); |
198 | break; | 247 | break; |
199 | case state_preinit: | 248 | case state_preinit: |
200 | status->setText(QObject::tr("Searching modem")); | 249 | status->setText(QObject::tr("Searching modem")); |
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 | |||
@@ -1,51 +1,52 @@ | |||
1 | #ifndef DIALER_H | 1 | #ifndef DIALER_H |
2 | #define DIALER_H | 2 | #define DIALER_H |
3 | 3 | ||
4 | #include <qdialog.h> | 4 | #include <qdialog.h> |
5 | 5 | ||
6 | #include "profile.h" | 6 | #include "profile.h" |
7 | 7 | ||
8 | class QLabel; | 8 | class QLabel; |
9 | class QProgressBar; | 9 | class QProgressBar; |
10 | 10 | ||
11 | class Dialer : public QDialog | 11 | 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: |
19 | void slotCancel(); | 19 | void slotCancel(); |
20 | void slotAutostart(); | 20 | void slotAutostart(); |
21 | 21 | ||
22 | private: | 22 | private: |
23 | void switchState(int newstate); | 23 | void switchState(int newstate); |
24 | void reset(); | 24 | void reset(); |
25 | void dial(const QString& number); | 25 | void dial(const QString& number); |
26 | void trydial(const QString& number); | 26 | void trydial(const QString& number); |
27 | 27 | ||
28 | void send(const QString& msg); | 28 | void send(const QString& msg); |
29 | QString receive(); | 29 | QString receive(); |
30 | 30 | ||
31 | enum States | 31 | enum States |
32 | { | 32 | { |
33 | state_cancel, | 33 | state_cancel, |
34 | state_preinit, | 34 | state_preinit, |
35 | state_init, | 35 | state_init, |
36 | state_options, | 36 | state_options, |
37 | state_dialtone, | 37 | state_dialtone, |
38 | state_dialing, | 38 | state_dialing, |
39 | state_online | 39 | state_online |
40 | }; | 40 | }; |
41 | 41 | ||
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 | |||
@@ -11,33 +11,33 @@ IOModem::IOModem( const Profile &profile ) | |||
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 | // maybe do a hangup here just in case...? | 18 | // maybe do a hangup here just in case...? |
19 | 19 | ||
20 | IOSerial::close(); | 20 | IOSerial::close(); |
21 | } | 21 | } |
22 | 22 | ||
23 | bool IOModem::open() { | 23 | 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) |
31 | { | 31 | { |
32 | return true; | 32 | return true; |
33 | } | 33 | } |
34 | else | 34 | else |
35 | { | 35 | { |
36 | close(); | 36 | close(); |
37 | return false; | 37 | return false; |
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | void IOModem::reload( const Profile &config ) { | 41 | void IOModem::reload( const Profile &config ) { |
42 | 42 | ||
43 | m_device = config.readEntry("Device", MODEM_DEFAULT_DEVICE); | 43 | m_device = config.readEntry("Device", MODEM_DEFAULT_DEVICE); |