--- smsdaemon/GsmModem.cpp 2008/06/11 10:31:42 50 +++ smsdaemon/GsmModem.cpp 2008/06/12 12:43:29 63 @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -18,6 +17,7 @@ #include "util.h" #include "common.h" +#include "SmsPdu.h" using namespace std; @@ -26,7 +26,6 @@ GsmModem::GsmModem(SerialPort& serialport) : m_port(serialport) { - Init(); } @@ -49,6 +48,7 @@ { time_t start,now; start = time(0); + _timeout = false; if (term != "> ") command.append("\r"); //Dont append CarriageReturn if sending SMS @@ -74,6 +74,7 @@ if ( (now-start) > 10 ) { Common::instance()->logMessage( string("GsmModem::Command time out --") + command); + _timeout = true; break; } } @@ -88,6 +89,9 @@ vector GsmModem::ReadSms(bool readAll) { + + Command( "AT+CMGF=1" ); //Set SMS format to text + const string search = "+CMGL: "; std::string cmd = "AT+CMGL"; if (readAll) @@ -119,32 +123,43 @@ return retval; } -void GsmModem::SendSms(string to, string message) + +void GsmModem::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00" { - Common::instance()->logMessage( string("SMS send to ") + to); + Common::instance()->logMessage( string("SMS pdu send") ); - Command("AT+CMGF=1");///Allways telling the format makes the application more stable + Command("AT+CMGF=0"); Util::Sleep(2); string line1 = "AT+CMGS="; - line1.append(to); + line1.append( Util::str_formatint(len) ); line1.append("\r"); + Command(line1,"> "); - if (message.length() > 160) - { - message = message.substr(0,160); - Common::instance()->logMessage( "Trunkating message! "); - } + pdu.append("\032"); // \032 == Ctrl+Z + Command( pdu ); + Util::Sleep( 50 ); + Common::instance()->smsCounter.outgoing++; +} - message.append("\032"); // \032 == Ctrl+Z +void GsmModem::SendSms(string to, string message, bool allowMultipart) +{ + Common::instance()->logMessage( string("SMS send to ") + to); - Command( message ); //In textmode limit to 160 bytes + if (to.at(0) == '+') + to.erase(0,0); + vector pdu_vec = SmsPdu::CreateSmsPdu(to, message, allowMultipart); + + for (unsigned i=0; ismsCounter.outgoing++; } void GsmModem::DeleteSms(std::string smsIndex) @@ -169,16 +184,21 @@ 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 - Command( "AT+CMGF=1" ); //Set SMS format to text - Command ("AT^SM20=0,0" ); //No SM20 compability //Set RealTimeClock ?? //Enter pin code ?? } + +