--- smsdaemon/GsmModem.cpp 2008/06/16 11:39:33 93 +++ smsdaemon/GsmModem.cpp 2008/12/07 15:51:02 142 @@ -8,7 +8,7 @@ #include -#include "SerialPort.h" +#include "serialport/SerialPort.h" #include "GsmModem.h" @@ -16,6 +16,7 @@ #include "common.h" #include "SmsPdu.h" +#include "SmsHelper.h" using namespace std; @@ -109,7 +110,7 @@ string sms_entry = result.substr(0,endpos); - retval.push_back( SMS::FromPduString(sms_entry) );; + retval.push_back( SmsHelper::FromPduString(sms_entry) );; if (endpos == string::npos) break; @@ -148,7 +149,7 @@ if (to.at(0) == '+') to.erase(0,0); - vector pdu_vec = SmsPdu::CreateSmsPdu(to, message, allowMultipart); + vector pdu_vec = SmsPdu::CreateSmsPdu(to, Util::str_latin2gsm(message), allowMultipart); for (unsigned i=0; ilogMessage( "All PDU's send"); } @@ -172,13 +174,56 @@ for (unsigned int i= 0; i 10) + throw std::runtime_error("Sim card timed out:"); + Util::Sleep(100); + } + +} + +void GsmModem::HandlePincode() +{ + string result = Command("AT+CPIN?"); + result = Util::str_trim(result); + result.erase(result.length() -2, 2); //remove trailing ok + result = Util::str_trim(result); + if (result != "+CPIN: READY") + { + if (result == "+CPIN: SIM PIN") + { + Command("AT^SSET=1"); + result = Command("AT+CPIN=0067"); + if ( result.substr(result.length()-4, 4) != "OK\r\n") + throw std::runtime_error(string("Illegal pincode: ") + result); + + WaitForSimcard(); + } + else + { + throw std::runtime_error(string("AT+CPIN? returned unhandled code: ") + result); + } + + } +} + void GsmModem::Init() { Command( "AT" ); @@ -197,9 +242,7 @@ //Command("AT+CGSMS=2"); //SMS over GPRS preferred - //Set RealTimeClock ?? - - //Enter pin code ?? + HandlePincode(); }