--- smsdaemon/GsmModem.cpp 2008/06/10 13:29:19 34 +++ smsdaemon/GsmModem.cpp 2008/06/16 11:39:33 93 @@ -2,12 +2,9 @@ */ #include - #include -#include #include -#include #include @@ -18,6 +15,7 @@ #include "util.h" #include "common.h" +#include "SmsPdu.h" using namespace std; @@ -26,7 +24,6 @@ GsmModem::GsmModem(SerialPort& serialport) : m_port(serialport) { - Init(); } @@ -49,6 +46,7 @@ { time_t start,now; start = time(0); + _timeout = false; if (term != "> ") command.append("\r"); //Dont append CarriageReturn if sending SMS @@ -74,24 +72,27 @@ if ( (now-start) > 10 ) { Common::instance()->logMessage( string("GsmModem::Command time out --") + command); + Common::instance()->logMessage( string("Modem responded: ") + Util::str_trim(response) ); + _timeout = true; break; } } Util::Sleep(5); -// cout << response.length() << ":" << response << endl; -// DumpString(response); return response; } vector GsmModem::ReadSms(bool readAll) { + + Command( "AT+CMGF=0" ); //Set SMS format to PDU + const string search = "+CMGL: "; std::string cmd = "AT+CMGL"; if (readAll) - cmd.append("=ALL"); + cmd.append("=4"); string result = Command(cmd); @@ -108,7 +109,7 @@ string sms_entry = result.substr(0,endpos); - retval.push_back( SMS::FromRawString(sms_entry) );; + retval.push_back( SMS::FromPduString(sms_entry) );; if (endpos == string::npos) break; @@ -119,24 +120,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,"> "); + pdu.append("\032"); // \032 == Ctrl+Z + Command( pdu ); + Util::Sleep( 50 ); + Common::instance()->smsCounter.outgoing++; +} + +void GsmModem::SendSms(string to, string message, bool allowMultipart) +{ + Common::instance()->logMessage( string("SMS send to ") + to); + + if (to.at(0) == '+') + to.erase(0,0); + + vector pdu_vec = SmsPdu::CreateSmsPdu(to, message, allowMultipart); - message.append("\032"); // \032 == Ctrl+Z + for (unsigned i=0; i