--- smsdaemon/ModemTransceiver.cpp 2008/12/12 12:13:05 178 +++ smsdaemon/ModemTransceiver.cpp 2008/12/12 12:54:27 180 @@ -18,7 +18,6 @@ #include "ConfigFile.h" #include "SmsPdu.h" -#include "SmsHelper.h" #include "Exceptions.h" using namespace std; @@ -26,7 +25,7 @@ ModemTransceiver::ModemTransceiver(SerialPort& serialport) -: m_port(serialport) + : m_port(serialport) { } @@ -72,14 +71,14 @@ response += GetResponse(); Util::Sleep(1); - now = time(0); - if ( (now-start) > 10 ) - { - Logger::logMessage( string("ModemTransceiver::Command time out --") + command); + now = time(0); + if ( (now-start) > 10 ) + { + Logger::logMessage( string("ModemTransceiver::Command time out --") + command); Logger::logMessage( string("Modem responded: ") + Util::str_trim(response) ); _timeout = true; - break; - } + break; + } } Util::Sleep(5); @@ -99,7 +98,7 @@ cmd.append("=4"); string result = Command(cmd); - + vector retval; if (result.find(search) == string::npos) return retval; @@ -111,13 +110,13 @@ { unsigned int endpos = result.find(search,5); - + string sms_entry = result.substr(0,endpos); - try + try { - SMS sms = SmsHelper::FromPduString(sms_entry); - + SMS sms = FromPduString(sms_entry); + retval.push_back( sms ); } catch (smsnotfoundexception& e) //do nothing @@ -126,7 +125,7 @@ if (endpos == string::npos) break; - + result = result.substr(endpos, result.length() - endpos); } @@ -227,7 +226,7 @@ result = Command( string("AT+CPIN=")+pin ); if ( result.substr(result.length()-4, 4) != "OK\r\n") throw std::runtime_error(string("Illegal pincode: ") + result); - + WaitForSimcard(); } else @@ -260,3 +259,64 @@ } +SMS ModemTransceiver::FromRawString(const std::string& input) +{ + std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " + + std::vector lines = Util::str_split(smsline, "\r\n"); + std::vector fields = Util::str_split(lines[0],","); + + std::string body; + for (unsigned i=1; i 0) + body += "\r\n"; + body += body_line; + } + } + + body = Util::str_trim(body); + + SMS sms; + + sms.SetIndex( fields[0] ); + + + std::string sender = fields[2]; + sender = Util::str_replace(sender, "\""); + sms.SetSender(sender); + + std::string timestamp = fields[4] + std::string(",") + fields[5]; + timestamp = Util::str_replace(timestamp, "\""); + sms.SetTimestamp(timestamp); + + sms.SetMessage( body ); + + return sms; +} + +SMS ModemTransceiver::FromPduString(const std::string& input) +{ + std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " + + std::vector lines = Util::str_split(smsline, "\r\n"); + std::vector fields = Util::str_split(lines[0],","); + + std::string index = fields[0]; + DeleteSms(index); + + SMS sms = SmsPdu::ParseSmsPdu(lines[1]); + + sms.SetIndex(index); + + return sms; +} + + + +