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 |
|
|
89 |
|
|
90 |
vector<SMS> GsmModem::ReadSms(bool readAll) |
vector<SMS> GsmModem::ReadSms(bool readAll) |
91 |
{ |
{ |
92 |
|
|
93 |
|
Command( "AT+CMGF=1" ); //Set SMS format to text |
94 |
|
|
95 |
const string search = "+CMGL: "; |
const string search = "+CMGL: "; |
96 |
std::string cmd = "AT+CMGL"; |
std::string cmd = "AT+CMGL"; |
97 |
if (readAll) |
if (readAll) |
144 |
Common::instance()->smsCounter.outgoing++; |
Common::instance()->smsCounter.outgoing++; |
145 |
} |
} |
146 |
|
|
147 |
void GsmModem::SendSms(string to, string message) |
void GsmModem::SendSms(string to, string message, bool allowMultipart) |
148 |
{ |
{ |
149 |
Common::instance()->logMessage( string("SMS send to ") + to); |
Common::instance()->logMessage( string("SMS send to ") + to); |
150 |
|
|
151 |
Command("AT+CMGF=1");///Allways telling the format makes the application more stable |
if (to.at(0) == '+') |
152 |
Util::Sleep(2); |
to.erase(0,0); |
|
|
|
|
string line1 = "AT+CMGS="; |
|
|
line1.append(to); |
|
|
line1.append("\r"); |
|
153 |
|
|
154 |
Command(line1,"> "); |
vector<PduInfo> pdu_vec = SmsPdu::CreateSmsPdu(to, message, allowMultipart); |
155 |
|
|
156 |
if (message.length() > 160) |
for (unsigned i=0; i<pdu_vec.size(); ++i) |
157 |
{ |
{ |
158 |
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 |
|
159 |
|
|
160 |
|
SendSmsPdu(pdu.pdu, pdu.len); |
161 |
|
} |
162 |
|
|
|
Util::Sleep(50); //Give the modem some time to send the sms and be ready again |
|
|
Common::instance()->smsCounter.outgoing++; |
|
163 |
} |
} |
164 |
|
|
165 |
void GsmModem::DeleteSms(std::string smsIndex) |
void GsmModem::DeleteSms(std::string smsIndex) |
194 |
|
|
195 |
Command( "ATE0" ); //Disable echo |
Command( "ATE0" ); //Disable echo |
196 |
|
|
|
Command( "AT+CMGF=1" ); //Set SMS format to text |
|
|
|
|
197 |
Command ("AT^SM20=0,0" ); //No SM20 compability |
Command ("AT^SM20=0,0" ); //No SM20 compability |
198 |
|
|
199 |
//Set RealTimeClock ?? |
//Set RealTimeClock ?? |