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 |
|
|
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 |
} |
} |
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) |
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) |
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 ?? |
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 |
|
|