--- smsdaemon/GsmModem.cpp 2008/06/17 08:14:12 104 +++ smsdaemon/GsmModem.cpp 2008/06/17 17:47:37 105 @@ -179,6 +179,49 @@ +void GsmModem::WaitForSimcard() +{ + int start = time(0); + string result; + + + while (result != "^SSIM READY") + { + result += GetResponse(); + result = Util::str_trim(result); + + if ( (time(0) - start) > 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 +240,7 @@ //Command("AT+CGSMS=2"); //SMS over GPRS preferred - //Set RealTimeClock ?? - - //Enter pin code ?? + HandlePincode(); }