18 |
#include "ConfigFile.h" |
#include "ConfigFile.h" |
19 |
|
|
20 |
#include "SmsPdu.h" |
#include "SmsPdu.h" |
|
#include "SmsHelper.h" |
|
21 |
#include "Exceptions.h" |
#include "Exceptions.h" |
22 |
|
|
23 |
using namespace std; |
using namespace std; |
25 |
|
|
26 |
|
|
27 |
ModemTransceiver::ModemTransceiver(SerialPort& serialport) |
ModemTransceiver::ModemTransceiver(SerialPort& serialport) |
28 |
: m_port(serialport) |
: m_port(serialport) |
29 |
{ |
{ |
30 |
} |
} |
31 |
|
|
71 |
response += GetResponse(); |
response += GetResponse(); |
72 |
Util::Sleep(1); |
Util::Sleep(1); |
73 |
|
|
74 |
now = time(0); |
now = time(0); |
75 |
if ( (now-start) > 10 ) |
if ( (now-start) > 10 ) |
76 |
{ |
{ |
77 |
Logger::logMessage( string("ModemTransceiver::Command time out --") + command); |
Logger::logMessage( string("ModemTransceiver::Command time out --") + command); |
78 |
Logger::logMessage( string("Modem responded: ") + Util::str_trim(response) ); |
Logger::logMessage( string("Modem responded: ") + Util::str_trim(response) ); |
79 |
_timeout = true; |
_timeout = true; |
80 |
break; |
break; |
81 |
} |
} |
82 |
} |
} |
83 |
|
|
84 |
Util::Sleep(5); |
Util::Sleep(5); |
98 |
cmd.append("=4"); |
cmd.append("=4"); |
99 |
|
|
100 |
string result = Command(cmd); |
string result = Command(cmd); |
101 |
|
|
102 |
vector<SMS> retval; |
vector<SMS> retval; |
103 |
if (result.find(search) == string::npos) |
if (result.find(search) == string::npos) |
104 |
return retval; |
return retval; |
110 |
{ |
{ |
111 |
unsigned int endpos = result.find(search,5); |
unsigned int endpos = result.find(search,5); |
112 |
|
|
113 |
|
|
114 |
string sms_entry = result.substr(0,endpos); |
string sms_entry = result.substr(0,endpos); |
115 |
|
|
116 |
try |
try |
117 |
{ |
{ |
118 |
SMS sms = SmsHelper::FromPduString(sms_entry); |
SMS sms = FromPduString(sms_entry); |
119 |
|
|
120 |
retval.push_back( sms ); |
retval.push_back( sms ); |
121 |
} |
} |
122 |
catch (smsnotfoundexception& e) //do nothing |
catch (smsnotfoundexception& e) //do nothing |
125 |
|
|
126 |
if (endpos == string::npos) |
if (endpos == string::npos) |
127 |
break; |
break; |
128 |
|
|
129 |
result = result.substr(endpos, result.length() - endpos); |
result = result.substr(endpos, result.length() - endpos); |
130 |
} |
} |
131 |
|
|
226 |
result = Command( string("AT+CPIN=")+pin ); |
result = Command( string("AT+CPIN=")+pin ); |
227 |
if ( result.substr(result.length()-4, 4) != "OK\r\n") |
if ( result.substr(result.length()-4, 4) != "OK\r\n") |
228 |
throw std::runtime_error(string("Illegal pincode: ") + result); |
throw std::runtime_error(string("Illegal pincode: ") + result); |
229 |
|
|
230 |
WaitForSimcard(); |
WaitForSimcard(); |
231 |
} |
} |
232 |
else |
else |
259 |
} |
} |
260 |
|
|
261 |
|
|
262 |
|
SMS ModemTransceiver::FromRawString(const std::string& input) |
263 |
|
{ |
264 |
|
std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " |
265 |
|
|
266 |
|
std::vector<std::string> lines = Util::str_split(smsline, "\r\n"); |
267 |
|
std::vector<std::string> fields = Util::str_split(lines[0],","); |
268 |
|
|
269 |
|
std::string body; |
270 |
|
for (unsigned i=1; i<lines.size(); ++i) |
271 |
|
{ |
272 |
|
std::string body_line = lines[i]; |
273 |
|
|
274 |
|
|
275 |
|
if (body_line != "") |
276 |
|
{ |
277 |
|
if (body.length() > 0) |
278 |
|
body += "\r\n"; |
279 |
|
body += body_line; |
280 |
|
} |
281 |
|
} |
282 |
|
|
283 |
|
body = Util::str_trim(body); |
284 |
|
|
285 |
|
SMS sms; |
286 |
|
|
287 |
|
sms.SetIndex( fields[0] ); |
288 |
|
|
289 |
|
|
290 |
|
std::string sender = fields[2]; |
291 |
|
sender = Util::str_replace(sender, "\""); |
292 |
|
sms.SetSender(sender); |
293 |
|
|
294 |
|
std::string timestamp = fields[4] + std::string(",") + fields[5]; |
295 |
|
timestamp = Util::str_replace(timestamp, "\""); |
296 |
|
sms.SetTimestamp(timestamp); |
297 |
|
|
298 |
|
sms.SetMessage( body ); |
299 |
|
|
300 |
|
return sms; |
301 |
|
} |
302 |
|
|
303 |
|
SMS ModemTransceiver::FromPduString(const std::string& input) |
304 |
|
{ |
305 |
|
std::string smsline = input.substr(7, input.length() -7); //strip "+CMGL: " |
306 |
|
|
307 |
|
std::vector<std::string> lines = Util::str_split(smsline, "\r\n"); |
308 |
|
std::vector<std::string> fields = Util::str_split(lines[0],","); |
309 |
|
|
310 |
|
std::string index = fields[0]; |
311 |
|
DeleteSms(index); |
312 |
|
|
313 |
|
SMS sms = SmsPdu::ParseSmsPdu(lines[1]); |
314 |
|
|
315 |
|
sms.SetIndex(index); |
316 |
|
|
317 |
|
return sms; |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|