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
@@ -76,42 +76,45 @@ Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name
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{
@@ -127,35 +130,35 @@ void Dialer::dial(const QString& number)
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 {
@@ -174,49 +177,51 @@ void Dialer::trydial(const QString& number)
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";
@@ -233,40 +238,43 @@ void Dialer::send(const QString& msg)
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)
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
@@ -3,37 +3,39 @@
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)
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,21 +1,23 @@
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}
@@ -151,32 +153,37 @@ int IOSerial::baud(int baud) const {
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()));