12 |
|
|
13 |
#include "ModemTransceiver.h" |
#include "ModemTransceiver.h" |
14 |
|
|
15 |
#include "util.h" |
#include "Util.h" |
16 |
#include "common.h" |
#include "Common.h" |
17 |
|
#include "Logger.h" |
18 |
|
#include "ConfigFile.h" |
19 |
|
|
20 |
#include "SmsPdu.h" |
#include "SmsPdu.h" |
21 |
#include "SmsHelper.h" |
#include "SmsHelper.h" |
74 |
now = time(0); |
now = time(0); |
75 |
if ( (now-start) > 10 ) |
if ( (now-start) > 10 ) |
76 |
{ |
{ |
77 |
Common::instance()->logMessage( string("ModemTransceiver::Command time out --") + command); |
Logger::logMessage( string("ModemTransceiver::Command time out --") + command); |
78 |
Common::instance()->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 |
} |
} |
126 |
|
|
127 |
void ModemTransceiver::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00" |
void ModemTransceiver::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00" |
128 |
{ |
{ |
129 |
Common::instance()->logMessage( string("SMS pdu send") ); |
Logger::logMessage( string("SMS pdu send") ); |
130 |
|
|
131 |
Command("AT+CMGF=0"); |
Command("AT+CMGF=0"); |
132 |
Util::Sleep(2); |
Util::Sleep(2); |
146 |
|
|
147 |
void ModemTransceiver::SendSms(string to, string message, bool allowMultipart) |
void ModemTransceiver::SendSms(string to, string message, bool allowMultipart) |
148 |
{ |
{ |
149 |
Common::instance()->logMessage( string("SMS send to ") + to); |
Logger::logMessage( string("SMS send to ") + to); |
150 |
|
|
151 |
if (to.at(0) == '+') |
if (to.at(0) == '+') |
152 |
to.erase(0,0); |
to.erase(0,0); |
159 |
|
|
160 |
SendSmsPdu(pdu.pdu, pdu.len); |
SendSmsPdu(pdu.pdu, pdu.len); |
161 |
} |
} |
162 |
Common::instance()->logMessage( "All PDU's send"); |
Logger::logMessage( "All PDU's send"); |
163 |
|
|
164 |
} |
} |
165 |
|
|
203 |
|
|
204 |
void ModemTransceiver::HandlePincode() |
void ModemTransceiver::HandlePincode() |
205 |
{ |
{ |
206 |
|
string pin = Common::instance()->GetConfigfile()->GetValue("gsmmodem","pin"); |
207 |
|
|
208 |
string result = Command("AT+CPIN?"); |
string result = Command("AT+CPIN?"); |
209 |
result = Util::str_trim(result); |
result = Util::str_trim(result); |
210 |
result.erase(result.length() -2, 2); //remove trailing ok |
result.erase(result.length() -2, 2); //remove trailing ok |
214 |
if (result == "+CPIN: SIM PIN") |
if (result == "+CPIN: SIM PIN") |
215 |
{ |
{ |
216 |
Command("AT^SSET=1"); |
Command("AT^SSET=1"); |
217 |
result = Command("AT+CPIN=0067"); |
result = Command( string("AT+CPIN=")+pin ); |
218 |
if ( result.substr(result.length()-4, 4) != "OK\r\n") |
if ( result.substr(result.length()-4, 4) != "OK\r\n") |
219 |
throw std::runtime_error(string("Illegal pincode: ") + result); |
throw std::runtime_error(string("Illegal pincode: ") + result); |
220 |
|
|