--- smsdaemon/GsmModem.cpp 2008/06/10 12:58:30 33 +++ smsdaemon/GsmModem.cpp 2008/06/11 19:42:24 59 @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -26,7 +25,6 @@ GsmModem::GsmModem(SerialPort& serialport) : m_port(serialport) { - Init(); } @@ -44,18 +42,21 @@ return str; } + string GsmModem::Command(string command, string term) { time_t start,now; start = time(0); + _timeout = false; + + if (term != "> ") + command.append("\r"); //Dont append CarriageReturn if sending SMS - command.append("\r"); m_port.Write(command); - Util::Sleep(25); + Util::Sleep(1); string response = GetResponse(); - unsigned int tlen = term.length(); while ( 1 ) { @@ -66,16 +67,15 @@ } response += GetResponse(); - Util::Sleep(25); + Util::Sleep(1); now = time(0); if ( (now-start) > 10 ) { Common::instance()->logMessage( string("GsmModem::Command time out --") + command); + _timeout = true; break; } - - } Util::Sleep(5); @@ -119,6 +119,27 @@ return retval; } + +void GsmModem::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00" +{ + Common::instance()->logMessage( string("SMS pdu send") ); + + Command("AT+CMGF=0"); + Util::Sleep(2); + + string line1 = "AT+CMGS="; + line1.append( Util::str_formatint(len) ); + line1.append("\r"); + + + Command(line1,"> "); + + pdu.append("\032"); // \032 == Ctrl+Z + Command( pdu ); + Util::Sleep( 50 ); + Common::instance()->smsCounter.outgoing++; +} + void GsmModem::SendSms(string to, string message) { Common::instance()->logMessage( string("SMS send to ") + to); @@ -132,11 +153,19 @@ Command(line1,"> "); + if (message.length() > 160) + { + message = message.substr(0,160); + Common::instance()->logMessage( "Trunkating message! "); + } + + message.append("\032"); // \032 == Ctrl+Z + + Command( message ); //In textmode limit to 160 bytes - message.append("\032\r"); // \032 == Ctrl+Z - Command(message); Util::Sleep(50); //Give the modem some time to send the sms and be ready again + Common::instance()->smsCounter.outgoing++; } void GsmModem::DeleteSms(std::string smsIndex) @@ -161,7 +190,12 @@ void GsmModem::Init() { + Command( "AT" ); + if (_timeout) + throw std::runtime_error("Modem did not respond!"); + Command( "ATZ" ); //Reset any previous setup + Command( "AT\\Q3" ); //Hardware flow control Command( "ATE0" ); //Disable echo @@ -174,3 +208,5 @@ //Enter pin code ?? } + +