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

Diff of /smsdaemon/ModemTransceiver.cpp

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

revision 59 by torben, Wed Jun 11 19:42:24 2008 UTC revision 72 by torben, Fri Jun 13 08:37:19 2008 UTC
# Line 17  Line 17 
17  #include "util.h"  #include "util.h"
18  #include "common.h"  #include "common.h"
19    
20    #include "SmsPdu.h"
21    
22  using namespace std;  using namespace std;
23    
# Line 73  string GsmModem::Command(string command, Line 74  string GsmModem::Command(string command,
74          if ( (now-start) > 10 )          if ( (now-start) > 10 )
75          {          {
76                  Common::instance()->logMessage( string("GsmModem::Command time out --") + command);                  Common::instance()->logMessage( string("GsmModem::Command time out --") + command);
77                            Common::instance()->logMessage( string("Modem responded: ") + Util::str_trim(response) );
78                          _timeout = true;                          _timeout = true;
79              break;              break;
80          }          }
# Line 88  string GsmModem::Command(string command, Line 90  string GsmModem::Command(string command,
90    
91  vector<SMS> GsmModem::ReadSms(bool readAll)  vector<SMS> GsmModem::ReadSms(bool readAll)
92  {  {
93    
94            Command( "AT+CMGF=1" ); //Set SMS format to text
95    
96          const string search = "+CMGL: ";          const string search = "+CMGL: ";
97          std::string cmd = "AT+CMGL";          std::string cmd = "AT+CMGL";
98          if (readAll)          if (readAll)
# Line 140  void GsmModem::SendSmsPdu(std::string pd Line 145  void GsmModem::SendSmsPdu(std::string pd
145          Common::instance()->smsCounter.outgoing++;          Common::instance()->smsCounter.outgoing++;
146  }  }
147    
148  void GsmModem::SendSms(string to, string message)  void GsmModem::SendSms(string to, string message, bool allowMultipart)
149  {  {
150          Common::instance()->logMessage( string("SMS send to ") + to);          Common::instance()->logMessage( string("SMS send to ") + to);
151    
152          Command("AT+CMGF=1");///Allways telling the format makes the application more stable          if (to.at(0) == '+')
153          Util::Sleep(2);                  to.erase(0,0);
   
         string line1 = "AT+CMGS=";  
         line1.append(to);  
         line1.append("\r");  
154    
155          Command(line1,"> ");          vector<PduInfo> pdu_vec = SmsPdu::CreateSmsPdu(to, message, allowMultipart);
156    
157          if (message.length() > 160)          for (unsigned i=0; i<pdu_vec.size(); ++i)
158          {          {
159                  message = message.substr(0,160);                  PduInfo& pdu = pdu_vec[i];
                 Common::instance()->logMessage( "Trunkating message! ");  
         }  
   
         message.append("\032"); // \032 == Ctrl+Z  
   
         Command( message ); //In textmode limit to 160 bytes  
160    
161                    SendSmsPdu(pdu.pdu, pdu.len);
162            }
163    
         Util::Sleep(50); //Give the modem some time to send the sms and be ready again  
         Common::instance()->smsCounter.outgoing++;  
164  }  }
165    
166  void GsmModem::DeleteSms(std::string smsIndex)  void GsmModem::DeleteSms(std::string smsIndex)
# Line 200  void GsmModem::Init() Line 195  void GsmModem::Init()
195    
196          Command( "ATE0" ); //Disable echo          Command( "ATE0" ); //Disable echo
197    
         Command( "AT+CMGF=1" ); //Set SMS format to text  
   
198          Command ("AT^SM20=0,0" ); //No SM20 compability          Command ("AT^SM20=0,0" ); //No SM20 compability
199    
200          //Set RealTimeClock ??          //Set RealTimeClock ??
# Line 210  void GsmModem::Init() Line 203  void GsmModem::Init()
203  }  }
204    
205    
206    
207    
208    void DebugGsmModem::SendSms(std::string to, std::string message, bool allowMultipart)
209    {
210            _to=to;
211            _message = message;
212            _multipart = allowMultipart;
213    
214            if (_print)
215            {
216                    cout << "DebugGsmModem::SendSms --------------" << endl;
217                    cout << "To:        " << to << endl;;
218                    cout << "Message:   " << message << endl;
219                    cout << "Multipart: " << allowMultipart << endl;
220    
221            }
222    }
223    

Legend:
Removed from v.59  
changed lines
  Added in v.72

  ViewVC Help
Powered by ViewVC 1.1.20