summaryrefslogtreecommitdiff
path: root/noncore
authorzecke <zecke>2002-10-24 20:43:25 (UTC)
committer zecke <zecke>2002-10-24 20:43:25 (UTC)
commit81a2bb8073b95d438911a62a7f4d8244ef58e20a (patch) (side-by-side diff)
tree2521c88de626caf818b715776934da204d6b0f8f /noncore
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 (limited to 'noncore') (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
@@ -68,213 +68,221 @@ Dialer::Dialer(const Profile& profile, int fd, QWidget *parent, const char *name
status->setFrameStyle(QFrame::Panel | QFrame::Sunken);
cancel = new QPushButton(QObject::tr("Cancel"), this);
vbox = new QVBoxLayout(this, 2);
vbox->add(desc);
vbox->add(progress);
vbox->add(status);
vbox->add(cancel);
connect(cancel, SIGNAL(clicked()), SLOT(slotCancel()));
show();
QTimer::singleShot(500, this, SLOT(slotAutostart()));
}
Dialer::~Dialer()
{
}
void Dialer::setHangupOnly()
{
state = state_cancel;
usercancel = 1;
+ send("+++ATH\r");
}
void Dialer::slotCancel()
{
if(state != state_online)
{
usercancel = 1;
reset();
}
- else accept();
+ else {
+ accept();
+ }
}
void Dialer::reset()
{
qWarning("reset");
switchState(state_cancel);
}
void Dialer::slotAutostart()
{
//state = state_preinit;
dial(m_profile.readEntry("Number"));
}
void Dialer::dial(const QString& number)
{
while(state != state_online)
{
if(!usercancel)
{
state = state_preinit;
trydial(number);
}
else break;
}
if(usercancel)
{
// modem hangup
trydial(QString::null);
reject();
}
}
void Dialer::trydial(const QString& number)
{
qWarning("TryDial:%s", number.latin1() );
if(state != state_cancel) switchState(state_preinit);
if(cleanshutdown)
{
qWarning("HangupString " + m_profile.readEntry("HangupString"));
- send(m_profile.readEntry("HangupString"));
- //send("+++ATH");
- send("");
+ //send(m_profile.readEntry("HangupString"));
+ send("+++ATH\r");
+ //send("");
}
if(state != state_cancel)
{
switchState(state_init);
//send("ATZ");
qWarning("Init String " + m_profile.readEntry("InitString") );
// send(m_profile.readEntry("InitString", "AT"));
send("AT\r");
QString response2 = receive();
if(!response2.contains("\nOK\r"))
reset();
}
/* if(state != state_cancel)
{
switchState(state_options);
qWarning("ATM3l3");
send("ATM3L3\r");
QString response3 = receive();
if(!response3.contains("\nOK\r"))
reset();
}
*/
if(state != state_cancel)
{
switchState(state_dialtone);
send("ATX1\r");
QString response4 = receive();
if(!response4.contains("\nOK\r"))
reset();
}
if(state != state_cancel)
{
qWarning("progress");
switchState(state_dialing);
send(QString("ATDT %1\r").arg(number));
// send(QString("%1 %2").arg(m_profile.readEntry("DialPrefix1")).arg(number));
QString response5 = receive();
- if(!response5.contains("\n" + m_profile.readEntry("DefaultConnect")))
+ if(!response5.contains("CONNECT") )
{
if(response5.contains("BUSY"))
switchState(state_dialing);
else
{
QMessageBox::warning(this,
QObject::tr("Failure"),
QObject::tr("Dialing the number failed."));
slotCancel();
}
}
}
+
if(state != state_cancel)
{
- switchState(state_online);
+ state = state_online;
+ slotCancel();
}
}
void Dialer::send(const QString& msg)
{
QString m = msg;
int bytes;
QString termination;
qWarning("Sending: %s", m.latin1());
/* termination = "\r";
//termination = m_profile.readEntry("Termination");
if(termination == "\n") m = m + "\n";
else if(termination == "\r") m = m + "\r";
else m = m + "\r\n";
*/
m = m.replace(QRegExp("\n"), "\r");
bytes = ::write(m_fd, m.local8Bit(), strlen(m.local8Bit()));
if(bytes < 0)
{
reset();
}
}
QString Dialer::receive()
{
QString buf;
char buffer[1024];
int ret;
int counter = 0;
while(1)
{
ret = ::read(m_fd, buffer, sizeof(buffer));
if(ret > 0)
{
for(int i = 0; i < ret; i++)
buffer[i] = buffer[i] & 0x7F;
buffer[ret] = 0;
- //qWarning("Got: '%s'", buffer);
+ qWarning("Got: %s", buffer);
buf.append(QString(buffer));
if(buf.contains("OK") || buf.contains("ERROR") || buf.contains("CONNECT") || (buf.contains("BUSY")))
{
//qWarning("Receiving: '%s'", buf.latin1());
cleanshutdown = 1;
return buf;
- }
+ }else if (buf.contains("NO CARRIER") || buf.contains("NO DIALTONE") ) {
+ cleanshutdown = 1;
+ return QString::null;
+ }
}
else if(ret < 0)
{
if(errno != EAGAIN) reset();
else if(!(counter++ % 100)) qApp->processEvents();
}
else if(!(counter++ % 100)) qApp->processEvents();
if(usercancel) return QString::null;
}
cleanshutdown = 1;
return QString::null;
}
void Dialer::switchState(int newstate)
{
int oldstate = state;
state = newstate;
switch(state)
{
case state_cancel:
status->setText(QObject::tr("Cancelling..."));
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
@@ -1,47 +1,49 @@
#include "io_modem.h"
#include "dialer.h"
IOModem::IOModem( const Profile &profile )
: IOSerial( profile ) {
m_profile = profile;
}
IOModem::~IOModem() {
}
void IOModem::close() {
// Hangup, discarding result
- int fd = rawIO();
- Dialer d(m_profile, fd);
+// int fd = rawIO();
+ internDetach();
+ Dialer d(m_profile, m_fd);
d.setHangupOnly();
- d.exec();
- closeRawIO(fd);
+ //d.exec();
+ internAttach();
+// closeRawIO(fd);
IOSerial::close();
}
bool IOModem::open() {
bool ret = IOSerial::open();
if(!ret) return false;
// int fd = rawIO();
internDetach();
Dialer d(m_profile, m_fd);
int result = d.exec();
internAttach();
// closeRawIO(fd);
if(result == QDialog::Accepted)
{
return true;
}
else
{
close();
return false;
}
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,29 +1,31 @@
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <unistd.h>
+#include <stdio.h>
+
#include "io_serial.h"
IOSerial::IOSerial(const Profile &config) : IOLayer(config) {
m_read = 0l;
m_error = 0l;
m_fd = 0;
m_connected = false;
reload(config);
}
IOSerial::~IOSerial() {
if (m_fd) {
close();
}
}
void IOSerial::send(const QByteArray &data) {
if (m_fd) {
write(m_fd, data.data(), data.size());
} else {
emit error(Refuse, tr("Not connected"));
}
}
@@ -143,48 +145,53 @@ int IOSerial::baud(int baud) const {
case 2400: return B2400; break;
case 4800: return B4800; break;
case 9600: return B9600; break;
case 19200: return B19200; break;
case 38400: return B38400; break;
case 57600: return B57600; break;
case 115200: return B115200; break;
}
return -1;
}
void IOSerial::errorOccured() {
emit error(ClosedUnexpected, strerror(errno));
close();
}
void IOSerial::dataArrived() {
QByteArray array(4097);
int len = read(m_fd, array.data(), 4096);
if (len == 0)
close();
if (len < 0)
return;
+ qWarning("got from layer");
+ for (int i = 0; i < len; i++ ) {
+ printf("%c", array[i] );
+ }
+ printf("\n");
array.resize( len );
emit received(array);
}
QString IOSerial::identifier() const {
return "serial";
}
QString IOSerial::name() const {
return "RS232 Serial IO Layer";
}
int IOSerial::rawIO()const {
if (m_read )
disconnect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
if (m_error )
disconnect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
int fd = ::open(m_device, O_RDWR );
return fd;
};
void IOSerial::closeRawIO(int fd) {
if (m_read )
connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));