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

Diff of /smsdaemon/ModemTransceiver.cpp

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

smsdaemon/GsmModem.cpp revision 135 by torben, Sun Dec 7 08:58:15 2008 UTC smsdaemon/ModemTransceiver.cpp revision 158 by torben, Mon Dec 8 21:49:49 2008 UTC
# Line 10  Line 10 
10    
11  #include "serialport/SerialPort.h"  #include "serialport/SerialPort.h"
12    
13  #include "GsmModem.h"  #include "ModemTransceiver.h"
14    
15  #include "util.h"  #include "Util.h"
16  #include "common.h"  #include "Common.h"
17    #include "Logger.h"
18    
19  #include "SmsPdu.h"  #include "SmsPdu.h"
20    #include "SmsHelper.h"
21    
22  using namespace std;  using namespace std;
23    
24    
25    
26  GsmModem::GsmModem(SerialPort& serialport)  ModemTransceiver::ModemTransceiver(SerialPort& serialport)
27  : m_port(serialport)  : m_port(serialport)
28  {  {
29  }  }
30    
31    
32    
33  string GsmModem::GetResponse()  string ModemTransceiver::GetResponse()
34  {  {
35    
36          SerialPort::DataBuffer buf;          SerialPort::DataBuffer buf;
# Line 42  string GsmModem::GetResponse() Line 44  string GsmModem::GetResponse()
44  }  }
45    
46    
47  string GsmModem::Command(string command, string term)  string ModemTransceiver::Command(string command, string term)
48  {  {
49          time_t  start,now;          time_t  start,now;
50          start = time(0);          start = time(0);
# Line 71  string GsmModem::Command(string command, Line 73  string GsmModem::Command(string command,
73          now = time(0);          now = time(0);
74          if ( (now-start) > 10 )          if ( (now-start) > 10 )
75          {          {
76                  Common::instance()->logMessage( string("GsmModem::Command time out --") + command);                  Logger::logMessage( string("ModemTransceiver::Command time out --") + command);
77                          Common::instance()->logMessage( string("Modem responded: ") + Util::str_trim(response) );                          Logger::logMessage( string("Modem responded: ") + Util::str_trim(response) );
78                          _timeout = true;                          _timeout = true;
79              break;              break;
80          }          }
# Line 84  string GsmModem::Command(string command, Line 86  string GsmModem::Command(string command,
86          return response;          return response;
87  }  }
88    
89  vector<SMS> GsmModem::ReadSms(bool readAll)  vector<SMS> ModemTransceiver::ReadSms(bool readAll)
90  {  {
91    
92          Command( "AT+CMGF=0" ); //Set SMS format to PDU          Command( "AT+CMGF=0" ); //Set SMS format to PDU
# Line 109  vector<SMS> GsmModem::ReadSms(bool readA Line 111  vector<SMS> GsmModem::ReadSms(bool readA
111    
112                                    
113                  string sms_entry = result.substr(0,endpos);                  string sms_entry = result.substr(0,endpos);
114                  retval.push_back( SMS::FromPduString(sms_entry) );;                  retval.push_back( SmsHelper::FromPduString(sms_entry) );;
115    
116                  if (endpos == string::npos)                  if (endpos == string::npos)
117                          break;                          break;
# Line 121  vector<SMS> GsmModem::ReadSms(bool readA Line 123  vector<SMS> GsmModem::ReadSms(bool readA
123  }  }
124    
125    
126  void GsmModem::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00"  void ModemTransceiver::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00"
127  {  {
128          Common::instance()->logMessage( string("SMS pdu send") );          Logger::logMessage( string("SMS pdu send") );
129    
130          Command("AT+CMGF=0");          Command("AT+CMGF=0");
131          Util::Sleep(2);          Util::Sleep(2);
# Line 141  void GsmModem::SendSmsPdu(std::string pd Line 143  void GsmModem::SendSmsPdu(std::string pd
143          Common::instance()->smsCounter.outgoing++;          Common::instance()->smsCounter.outgoing++;
144  }  }
145    
146  void GsmModem::SendSms(string to, string message, bool allowMultipart)  void ModemTransceiver::SendSms(string to, string message, bool allowMultipart)
147  {  {
148          Common::instance()->logMessage( string("SMS send to ") + to);          Logger::logMessage( string("SMS send to ") + to);
149    
150          if (to.at(0) == '+')          if (to.at(0) == '+')
151                  to.erase(0,0);                  to.erase(0,0);
# Line 156  void GsmModem::SendSms(string to, string Line 158  void GsmModem::SendSms(string to, string
158    
159                  SendSmsPdu(pdu.pdu, pdu.len);                  SendSmsPdu(pdu.pdu, pdu.len);
160          }          }
161            Logger::logMessage( "All PDU's send");
162    
163  }  }
164    
165  void GsmModem::DeleteSms(std::string smsIndex)  void ModemTransceiver::DeleteSms(std::string smsIndex)
166  {  {
167          string cmd = "AT+CMGD=";          string cmd = "AT+CMGD=";
168          cmd.append(smsIndex);          cmd.append(smsIndex);
169          Command(cmd);          Command(cmd);
170  }  }
171    
172  int  GsmModem::DeleteAllSms()  int  ModemTransceiver::DeleteAllSms()
173  {  {
174          vector<SMS> sms = ReadSms(true);          vector<SMS> sms = ReadSms(true);
175    
176          for (unsigned int i= 0; i<sms.size(); ++i)          for (unsigned int i= 0; i<sms.size(); ++i)
177          {          {
178                  DeleteSms( sms[i].sms_index);                  DeleteSms( sms[i].GetIndex() );
179          }          }
180          return sms.size();          return sms.size();
181  }  }
182    
183    
184    
185  void GsmModem::WaitForSimcard()  void ModemTransceiver::WaitForSimcard()
186  {  {
187          int start = time(0);          int start = time(0);
188          string result;          string result;
# Line 197  void GsmModem::WaitForSimcard() Line 200  void GsmModem::WaitForSimcard()
200    
201  }  }
202    
203  void GsmModem::HandlePincode()  void ModemTransceiver::HandlePincode()
204  {  {
205          string result = Command("AT+CPIN?");          string result = Command("AT+CPIN?");
206          result = Util::str_trim(result);          result = Util::str_trim(result);
# Line 222  void GsmModem::HandlePincode() Line 225  void GsmModem::HandlePincode()
225          }          }
226  }  }
227    
228  void GsmModem::Init()  void ModemTransceiver::Init()
229  {  {
230          Command( "AT" );          Command( "AT" );
231          if (_timeout)          if (_timeout)
# Line 244  void GsmModem::Init() Line 247  void GsmModem::Init()
247  }  }
248    
249    
   
   
 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;  
   
         }  
 }  
   

Legend:
Removed from v.135  
changed lines
  Added in v.158

  ViewVC Help
Powered by ViewVC 1.1.20