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

Diff of /smsdaemon/ModemTransceiver.cpp

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

revision 50 by torben, Wed Jun 11 10:31:42 2008 UTC revision 59 by torben, Wed Jun 11 19:42:24 2008 UTC
# Line 4  Line 4 
4  #include <iostream>  #include <iostream>
5    
6  #include <string>  #include <string>
 #include <cstring>  
7  #include <stdexcept>  #include <stdexcept>
8    
9  #include <sys/time.h>  #include <sys/time.h>
# Line 26  using namespace std; Line 25  using namespace std;
25  GsmModem::GsmModem(SerialPort& serialport)  GsmModem::GsmModem(SerialPort& serialport)
26  : m_port(serialport)  : m_port(serialport)
27  {  {
         Init();  
28  }  }
29    
30    
# Line 49  string GsmModem::Command(string command, Line 47  string GsmModem::Command(string command,
47  {  {
48          time_t  start,now;          time_t  start,now;
49          start = time(0);          start = time(0);
50            _timeout = false;
51    
52          if (term != "> ")          if (term != "> ")
53                  command.append("\r"); //Dont append CarriageReturn if sending SMS                  command.append("\r"); //Dont append CarriageReturn if sending SMS
# Line 74  string GsmModem::Command(string command, Line 73  string GsmModem::Command(string command,
73          if ( (now-start) > 10 )          if ( (now-start) > 10 )
74          {          {
75                  Common::instance()->logMessage( string("GsmModem::Command time out --") + command);                  Common::instance()->logMessage( string("GsmModem::Command time out --") + command);
76                            _timeout = true;
77              break;              break;
78          }          }
79          }          }
# Line 119  vector<SMS> GsmModem::ReadSms(bool readA Line 119  vector<SMS> GsmModem::ReadSms(bool readA
119          return retval;          return retval;
120  }  }
121    
122    
123    void GsmModem::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00"
124    {
125            Common::instance()->logMessage( string("SMS pdu send") );
126    
127            Command("AT+CMGF=0");
128            Util::Sleep(2);
129    
130            string line1 = "AT+CMGS=";
131            line1.append( Util::str_formatint(len) );
132            line1.append("\r");
133    
134    
135            Command(line1,"> ");
136    
137            pdu.append("\032"); // \032 == Ctrl+Z
138            Command( pdu );
139            Util::Sleep( 50 );
140            Common::instance()->smsCounter.outgoing++;
141    }
142    
143  void GsmModem::SendSms(string to, string message)  void GsmModem::SendSms(string to, string message)
144  {  {
145          Common::instance()->logMessage( string("SMS send to ") + to);          Common::instance()->logMessage( string("SMS send to ") + to);
# Line 169  int  GsmModem::DeleteAllSms() Line 190  int  GsmModem::DeleteAllSms()
190    
191  void GsmModem::Init()  void GsmModem::Init()
192  {  {
193            Command( "AT" );
194            if (_timeout)
195                    throw std::runtime_error("Modem did not respond!");
196    
197          Command( "ATZ" ); //Reset any previous setup          Command( "ATZ" ); //Reset any previous setup
198    
199          Command( "AT\\Q3" ); //Hardware flow control          Command( "AT\\Q3" ); //Hardware flow control
200    
201          Command( "ATE0" ); //Disable echo          Command( "ATE0" ); //Disable echo
# Line 182  void GsmModem::Init() Line 208  void GsmModem::Init()
208                    
209          //Enter pin code ??          //Enter pin code ??
210  }  }
211    
212    

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

  ViewVC Help
Powered by ViewVC 1.1.20