10 |
|
|
11 |
#include "serialport/SerialPort.h" |
#include "serialport/SerialPort.h" |
12 |
|
|
13 |
#include "GsmModem.h" |
#include "ModemTransceiver.h" |
14 |
|
|
15 |
#include "util.h" |
#include "util.h" |
16 |
#include "common.h" |
#include "common.h" |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
GsmModem::GsmModem(SerialPort& serialport) |
ModemTransceiver::ModemTransceiver(SerialPort& serialport) |
26 |
: m_port(serialport) |
: m_port(serialport) |
27 |
{ |
{ |
28 |
} |
} |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
string GsmModem::GetResponse() |
string ModemTransceiver::GetResponse() |
33 |
{ |
{ |
34 |
|
|
35 |
SerialPort::DataBuffer buf; |
SerialPort::DataBuffer buf; |
43 |
} |
} |
44 |
|
|
45 |
|
|
46 |
string GsmModem::Command(string command, string term) |
string ModemTransceiver::Command(string command, string term) |
47 |
{ |
{ |
48 |
time_t start,now; |
time_t start,now; |
49 |
start = time(0); |
start = time(0); |
72 |
now = time(0); |
now = time(0); |
73 |
if ( (now-start) > 10 ) |
if ( (now-start) > 10 ) |
74 |
{ |
{ |
75 |
Common::instance()->logMessage( string("GsmModem::Command time out --") + command); |
Common::instance()->logMessage( string("ModemTransceiver::Command time out --") + command); |
76 |
Common::instance()->logMessage( string("Modem responded: ") + Util::str_trim(response) ); |
Common::instance()->logMessage( string("Modem responded: ") + Util::str_trim(response) ); |
77 |
_timeout = true; |
_timeout = true; |
78 |
break; |
break; |
85 |
return response; |
return response; |
86 |
} |
} |
87 |
|
|
88 |
vector<SMS> GsmModem::ReadSms(bool readAll) |
vector<SMS> ModemTransceiver::ReadSms(bool readAll) |
89 |
{ |
{ |
90 |
|
|
91 |
Command( "AT+CMGF=0" ); //Set SMS format to PDU |
Command( "AT+CMGF=0" ); //Set SMS format to PDU |
122 |
} |
} |
123 |
|
|
124 |
|
|
125 |
void GsmModem::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00" |
void ModemTransceiver::SendSmsPdu(std::string pdu, int len) //pdu inclussive leading "00" |
126 |
{ |
{ |
127 |
Common::instance()->logMessage( string("SMS pdu send") ); |
Common::instance()->logMessage( string("SMS pdu send") ); |
128 |
|
|
142 |
Common::instance()->smsCounter.outgoing++; |
Common::instance()->smsCounter.outgoing++; |
143 |
} |
} |
144 |
|
|
145 |
void GsmModem::SendSms(string to, string message, bool allowMultipart) |
void ModemTransceiver::SendSms(string to, string message, bool allowMultipart) |
146 |
{ |
{ |
147 |
Common::instance()->logMessage( string("SMS send to ") + to); |
Common::instance()->logMessage( string("SMS send to ") + to); |
148 |
|
|
161 |
|
|
162 |
} |
} |
163 |
|
|
164 |
void GsmModem::DeleteSms(std::string smsIndex) |
void ModemTransceiver::DeleteSms(std::string smsIndex) |
165 |
{ |
{ |
166 |
string cmd = "AT+CMGD="; |
string cmd = "AT+CMGD="; |
167 |
cmd.append(smsIndex); |
cmd.append(smsIndex); |
168 |
Command(cmd); |
Command(cmd); |
169 |
} |
} |
170 |
|
|
171 |
int GsmModem::DeleteAllSms() |
int ModemTransceiver::DeleteAllSms() |
172 |
{ |
{ |
173 |
vector<SMS> sms = ReadSms(true); |
vector<SMS> sms = ReadSms(true); |
174 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
void GsmModem::WaitForSimcard() |
void ModemTransceiver::WaitForSimcard() |
185 |
{ |
{ |
186 |
int start = time(0); |
int start = time(0); |
187 |
string result; |
string result; |
199 |
|
|
200 |
} |
} |
201 |
|
|
202 |
void GsmModem::HandlePincode() |
void ModemTransceiver::HandlePincode() |
203 |
{ |
{ |
204 |
string result = Command("AT+CPIN?"); |
string result = Command("AT+CPIN?"); |
205 |
result = Util::str_trim(result); |
result = Util::str_trim(result); |
224 |
} |
} |
225 |
} |
} |
226 |
|
|
227 |
void GsmModem::Init() |
void ModemTransceiver::Init() |
228 |
{ |
{ |
229 |
Command( "AT" ); |
Command( "AT" ); |
230 |
if (_timeout) |
if (_timeout) |
246 |
} |
} |
247 |
|
|
248 |
|
|
|
|
|
|
|
|
|
void DebugGsmModem::SendSms(std::string to, std::string message, bool allowMultipart) |
|
|
{ |
|
|
_to=to; |
|
|
_message = message; |
|
|
_multipart = allowMultipart; |
|
|
|
|
|
if (_print) |
|
|
{ |
|
|
cout << "DebugGsmModem::SendSms --------------" << endl; |
|
|
cout << "To: " << to << endl;; |
|
|
cout << "Message: " << message << endl; |
|
|
cout << "Multipart: " << allowMultipart << endl; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
std::vector<SMS> DebugGsmModem::ReadSms(bool readAll) |
|
|
{ |
|
|
vector<SMS> result; |
|
|
return result; |
|
|
} |
|