void GPRSCall::activateGPRS() {
connect(activateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readGPRS()));
activateProcess
->start
("pppd call gprs-airtel",
QIODevice::ReadOnly);
}
void GPRSCall::readGPRS()
{
str = activateProcess->readAllStandardOutput();
qDebug() << str;
if(str.contains("local IP address")) {
emit gprsResponse(tr("GPRS Activated Successfully<br>IP : ")+ipAddress);
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readGPRS()));
} else if(str.contains("script failed") || str.contains("Serial link disconnected")) {
emit gprsResponse(tr("GPRS Activation Failed"));
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readGPRS()));
} else if(str.contains("ttyUSB0 is locked")) {
emit gprsResponse(tr("GPRS Activation Failed"));
}
else if(str.contains("Modem hangup")) {
emit gprsResponse(tr("Modem Hangup"));
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readGPRS()));
}
}
/*Obtains the IP Address from the conncted network interrface*/
{
QList<QNetworkAddressEntry> ipList = iface.addressEntries();
for (int i = 0; i < ipList.size(); ++i)
return ipList.at(i).ip().toString();
return "No Link";
}
/********************GPRS Deactivation********************/
/*GPRS Disconnect Script is called from a process in ReadOnly Mode*/
void GPRSCall::deactivateGPRS()
{
connect(deactivateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(closeGPRS()));
deactivateProcess
->start
("sh /opt/Resources/gprs_disconnect.sh",
QIODevice::ReadOnly);
delay(1);///add Stopping PPP interface to readyreadstandarouuput method...
}
/***************Read Deactivation Script Output***************/
/*Invoked form Disconnect Script to read its output and display
the status to the user*/
void GPRSCall::closeGPRS()
{
str = deactivateProcess->readAllStandardOutput();
if(str.contains("Stopping PPP interface ")) {
emit gprsResponse(tr("GPRS Deactivation Success"));
deactivateProcess->disconnect(deactivateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(closeGPRS()));
}
}
void GPRSCall::activateGPRS() {
QProcess *activateProcess;
activateProcess = new QProcess();
connect(activateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readGPRS()));
activateProcess->start("pppd call gprs-airtel",QIODevice::ReadOnly);
}
void GPRSCall::readGPRS()
{
str = activateProcess->readAllStandardOutput();
qDebug() << str;
if(str.contains("local IP address")) {
QString ipAddress=getip("ppp0");
emit gprsResponse(tr("GPRS Activated Successfully<br>IP : ")+ipAddress);
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readGPRS()));
} else if(str.contains("script failed") || str.contains("Serial link disconnected")) {
emit gprsResponse(tr("GPRS Activation Failed"));
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readGPRS()));
} else if(str.contains("ttyUSB0 is locked")) {
emit gprsResponse(tr("GPRS Activation Failed"));
}
else if(str.contains("Modem hangup")) {
emit gprsResponse(tr("Modem Hangup"));
activateProcess->disconnect(activateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readGPRS()));
}
}
/*Obtains the IP Address from the conncted network interrface*/
QString GPRSCall::getip(QString dev)
{
QNetworkInterface iface = QNetworkInterface::interfaceFromName(dev);
QList<QNetworkAddressEntry> ipList = iface.addressEntries();
for (int i = 0; i < ipList.size(); ++i)
return ipList.at(i).ip().toString();
return "No Link";
}
/********************GPRS Deactivation********************/
/*GPRS Disconnect Script is called from a process in ReadOnly Mode*/
void GPRSCall::deactivateGPRS()
{
connect(deactivateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(closeGPRS()));
deactivateProcess->start("sh /opt/Resources/gprs_disconnect.sh",QIODevice::ReadOnly);
delay(1);///add Stopping PPP interface to readyreadstandarouuput method...
}
/***************Read Deactivation Script Output***************/
/*Invoked form Disconnect Script to read its output and display
the status to the user*/
void GPRSCall::closeGPRS()
{
str = deactivateProcess->readAllStandardOutput();
if(str.contains("Stopping PPP interface ")) {
emit gprsResponse(tr("GPRS Deactivation Success"));
deactivateProcess->disconnect(deactivateProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(closeGPRS()));
}
}
To copy to clipboard, switch view to plain text mode
Note : USing QT 4.8.1 version & Linux 2.6.36.4 armv5tejl GNU/Linux
Bookmarks