--- smsdaemon/GsmModem.cpp 2008/12/07 10:15:44 136 +++ smsdaemon/ModemTransceiver.cpp 2008/12/12 12:13:05 178 @@ -10,25 +10,29 @@ #include "serialport/SerialPort.h" -#include "GsmModem.h" +#include "ModemTransceiver.h" -#include "util.h" -#include "common.h" +#include "Util.h" +#include "Common.h" +#include "Logger.h" +#include "ConfigFile.h" #include "SmsPdu.h" +#include "SmsHelper.h" +#include "Exceptions.h" using namespace std; -GsmModem::GsmModem(SerialPort& serialport) +ModemTransceiver::ModemTransceiver(SerialPort& serialport) : m_port(serialport) { } -string GsmModem::GetResponse() +string ModemTransceiver::GetResponse() { SerialPort::DataBuffer buf; @@ -42,7 +46,7 @@ } -string GsmModem::Command(string command, string term) +string ModemTransceiver::Command(string command, string term) { time_t start,now; start = time(0); @@ -71,8 +75,8 @@ now = time(0); if ( (now-start) > 10 ) { - Common::instance()->logMessage( string("GsmModem::Command time out --") + command); - Common::instance()->logMessage( string("Modem responded: ") + Util::str_trim(response) ); + Logger::logMessage( string("ModemTransceiver::Command time out --") + command); + Logger::logMessage( string("Modem responded: ") + Util::str_trim(response) ); _timeout = true; break; } @@ -84,7 +88,7 @@ return response; } -vector GsmModem::ReadSms(bool readAll) +vector ModemTransceiver::ReadSms(bool readAll) { Command( "AT+CMGF=0" ); //Set SMS format to PDU @@ -109,7 +113,16 @@ string sms_entry = result.substr(0,endpos); - retval.push_back( SMS::FromPduString(sms_entry) );; + + try + { + SMS sms = SmsHelper::FromPduString(sms_entry); + + retval.push_back( sms ); + } + catch (smsnotfoundexception& e) //do nothing + { + } if (endpos == string::npos) break; @@ -121,9 +134,9 @@ } -void GsmModem::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00" +void ModemTransceiver::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00" { - Common::instance()->logMessage( string("SMS pdu send") ); + Logger::logMessage( string("SMS pdu send") ); Command("AT+CMGF=0"); Util::Sleep(2); @@ -141,9 +154,9 @@ Common::instance()->smsCounter.outgoing++; } -void GsmModem::SendSms(string to, string message, bool allowMultipart) +void ModemTransceiver::SendSms(string to, string message, bool allowMultipart) { - Common::instance()->logMessage( string("SMS send to ") + to); + Logger::logMessage( string("SMS send to ") + to); if (to.at(0) == '+') to.erase(0,0); @@ -156,31 +169,31 @@ SendSmsPdu(pdu.pdu, pdu.len); } - Common::instance()->logMessage( "All PDU's send"); + Logger::logMessage( "All PDU's send"); } -void GsmModem::DeleteSms(std::string smsIndex) +void ModemTransceiver::DeleteSms(std::string smsIndex) { string cmd = "AT+CMGD="; cmd.append(smsIndex); Command(cmd); } -int GsmModem::DeleteAllSms() +int ModemTransceiver::DeleteAllSms() { vector sms = ReadSms(true); for (unsigned int i= 0; iGetConfigfile()->GetValue("gsmmodem","pin"); + string result = Command("AT+CPIN?"); result = Util::str_trim(result); result.erase(result.length() -2, 2); //remove trailing ok @@ -209,7 +224,7 @@ if (result == "+CPIN: SIM PIN") { Command("AT^SSET=1"); - result = Command("AT+CPIN=0067"); + result = Command( string("AT+CPIN=")+pin ); if ( result.substr(result.length()-4, 4) != "OK\r\n") throw std::runtime_error(string("Illegal pincode: ") + result); @@ -223,7 +238,7 @@ } } -void GsmModem::Init() +void ModemTransceiver::Init() { Command( "AT" ); if (_timeout) @@ -245,21 +260,3 @@ } - - -void DebugGsmModem::SendSms(std::string to, std::string message, bool allowMultipart) -{ - _to=to; - _message = message; - _multipart = allowMultipart; - - if (_print) - { - cout << "DebugGsmModem::SendSms --------------" << endl; - cout << "To: " << to << endl;; - cout << "Message: " << message << endl; - cout << "Multipart: " << allowMultipart << endl; - - } -} -