26 |
GsmModem::GsmModem(SerialPort& serialport) |
GsmModem::GsmModem(SerialPort& serialport) |
27 |
: m_port(serialport) |
: m_port(serialport) |
28 |
{ |
{ |
|
Init(); |
|
29 |
} |
} |
30 |
|
|
31 |
|
|
43 |
return str; |
return str; |
44 |
} |
} |
45 |
|
|
46 |
|
|
47 |
string GsmModem::Command(string command, string term) |
string GsmModem::Command(string command, string term) |
48 |
{ |
{ |
49 |
time_t start,now; |
time_t start,now; |
50 |
start = time(0); |
start = time(0); |
51 |
|
_timeout = false; |
52 |
|
|
53 |
|
if (term != "> ") |
54 |
|
command.append("\r"); //Dont append CarriageReturn if sending SMS |
55 |
|
|
|
command.append("\r"); |
|
56 |
m_port.Write(command); |
m_port.Write(command); |
57 |
|
|
58 |
Util::Sleep(25); |
Util::Sleep(1); |
59 |
string response = GetResponse(); |
string response = GetResponse(); |
60 |
|
|
|
|
|
61 |
unsigned int tlen = term.length(); |
unsigned int tlen = term.length(); |
62 |
while ( 1 ) |
while ( 1 ) |
63 |
{ |
{ |
68 |
} |
} |
69 |
|
|
70 |
response += GetResponse(); |
response += GetResponse(); |
71 |
Util::Sleep(25); |
Util::Sleep(1); |
72 |
|
|
73 |
now = time(0); |
now = time(0); |
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 |
|
_timeout = true; |
78 |
break; |
break; |
79 |
} |
} |
|
|
|
|
|
|
80 |
} |
} |
81 |
|
|
82 |
Util::Sleep(5); |
Util::Sleep(5); |
133 |
|
|
134 |
Command(line1,"> "); |
Command(line1,"> "); |
135 |
|
|
136 |
|
if (message.length() > 160) |
137 |
|
{ |
138 |
|
message = message.substr(0,160); |
139 |
|
Common::instance()->logMessage( "Trunkating message! "); |
140 |
|
} |
141 |
|
|
142 |
|
message.append("\032"); // \032 == Ctrl+Z |
143 |
|
|
144 |
|
Command( message ); //In textmode limit to 160 bytes |
145 |
|
|
|
message.append("\032\r"); // \032 == Ctrl+Z |
|
146 |
|
|
|
Command(message); |
|
147 |
Util::Sleep(50); //Give the modem some time to send the sms and be ready again |
Util::Sleep(50); //Give the modem some time to send the sms and be ready again |
148 |
|
Common::instance()->smsCounter.outgoing++; |
149 |
} |
} |
150 |
|
|
151 |
void GsmModem::DeleteSms(std::string smsIndex) |
void GsmModem::DeleteSms(std::string smsIndex) |
171 |
void GsmModem::Init() |
void GsmModem::Init() |
172 |
{ |
{ |
173 |
Command( "ATZ" ); //Reset any previous setup |
Command( "ATZ" ); //Reset any previous setup |
174 |
|
if (_timeout) |
175 |
|
throw std::runtime_error("Modem did not respond!"); |
176 |
|
|
177 |
Command( "AT\\Q3" ); //Hardware flow control |
Command( "AT\\Q3" ); //Hardware flow control |
178 |
|
|
179 |
Command( "ATE0" ); //Disable echo |
Command( "ATE0" ); //Disable echo |