/[projects]/smsdaemon/ModemTransceiver.cpp
ViewVC logotype

Diff of /smsdaemon/ModemTransceiver.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 149 by torben, Sun Dec 7 20:58:41 2008 UTC revision 178 by torben, Fri Dec 12 12:13:05 2008 UTC
# Line 12  Line 12 
12    
13  #include "ModemTransceiver.h"  #include "ModemTransceiver.h"
14    
15  #include "util.h"  #include "Util.h"
16  #include "common.h"  #include "Common.h"
17    #include "Logger.h"
18    #include "ConfigFile.h"
19    
20  #include "SmsPdu.h"  #include "SmsPdu.h"
21  #include "SmsHelper.h"  #include "SmsHelper.h"
22    #include "Exceptions.h"
23    
24  using namespace std;  using namespace std;
25    
# Line 72  string ModemTransceiver::Command(string Line 75  string ModemTransceiver::Command(string
75          now = time(0);          now = time(0);
76          if ( (now-start) > 10 )          if ( (now-start) > 10 )
77          {          {
78                  Common::instance()->logMessage( string("ModemTransceiver::Command time out --") + command);                  Logger::logMessage( string("ModemTransceiver::Command time out --") + command);
79                          Common::instance()->logMessage( string("Modem responded: ") + Util::str_trim(response) );                          Logger::logMessage( string("Modem responded: ") + Util::str_trim(response) );
80                          _timeout = true;                          _timeout = true;
81              break;              break;
82          }          }
# Line 110  vector<SMS> ModemTransceiver::ReadSms(bo Line 113  vector<SMS> ModemTransceiver::ReadSms(bo
113    
114                                    
115                  string sms_entry = result.substr(0,endpos);                  string sms_entry = result.substr(0,endpos);
116                  retval.push_back( SmsHelper::FromPduString(sms_entry) );;  
117                    try
118                    {
119                            SMS sms = SmsHelper::FromPduString(sms_entry);
120            
121                            retval.push_back( sms );
122                    }
123                    catch (smsnotfoundexception& e) //do nothing
124                    {
125                    }
126    
127                  if (endpos == string::npos)                  if (endpos == string::npos)
128                          break;                          break;
# Line 124  vector<SMS> ModemTransceiver::ReadSms(bo Line 136  vector<SMS> ModemTransceiver::ReadSms(bo
136    
137  void ModemTransceiver::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00"  void ModemTransceiver::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00"
138  {  {
139          Common::instance()->logMessage( string("SMS pdu send") );          Logger::logMessage( string("SMS pdu send") );
140    
141          Command("AT+CMGF=0");          Command("AT+CMGF=0");
142          Util::Sleep(2);          Util::Sleep(2);
# Line 144  void ModemTransceiver::SendSmsPdu(std::s Line 156  void ModemTransceiver::SendSmsPdu(std::s
156    
157  void ModemTransceiver::SendSms(string to, string message, bool allowMultipart)  void ModemTransceiver::SendSms(string to, string message, bool allowMultipart)
158  {  {
159          Common::instance()->logMessage( string("SMS send to ") + to);          Logger::logMessage( string("SMS send to ") + to);
160    
161          if (to.at(0) == '+')          if (to.at(0) == '+')
162                  to.erase(0,0);                  to.erase(0,0);
# Line 157  void ModemTransceiver::SendSms(string to Line 169  void ModemTransceiver::SendSms(string to
169    
170                  SendSmsPdu(pdu.pdu, pdu.len);                  SendSmsPdu(pdu.pdu, pdu.len);
171          }          }
172          Common::instance()->logMessage( "All PDU's send");          Logger::logMessage( "All PDU's send");
173    
174  }  }
175    
# Line 201  void ModemTransceiver::WaitForSimcard() Line 213  void ModemTransceiver::WaitForSimcard()
213    
214  void ModemTransceiver::HandlePincode()  void ModemTransceiver::HandlePincode()
215  {  {
216            string pin = Common::instance()->GetConfigfile()->GetValue("gsmmodem","pin");
217    
218          string result = Command("AT+CPIN?");          string result = Command("AT+CPIN?");
219          result = Util::str_trim(result);          result = Util::str_trim(result);
220          result.erase(result.length() -2, 2); //remove trailing ok          result.erase(result.length() -2, 2); //remove trailing ok
# Line 210  void ModemTransceiver::HandlePincode() Line 224  void ModemTransceiver::HandlePincode()
224                  if (result == "+CPIN: SIM PIN")                  if (result == "+CPIN: SIM PIN")
225                  {                  {
226                          Command("AT^SSET=1");                          Command("AT^SSET=1");
227                          result = Command("AT+CPIN=0067");                          result = Command( string("AT+CPIN=")+pin  );
228                          if ( result.substr(result.length()-4, 4) != "OK\r\n")                          if ( result.substr(result.length()-4, 4) != "OK\r\n")
229                                  throw std::runtime_error(string("Illegal pincode: ") + result);                                  throw std::runtime_error(string("Illegal pincode: ") + result);
230                                                    

Legend:
Removed from v.149  
changed lines
  Added in v.178

  ViewVC Help
Powered by ViewVC 1.1.20