Skip to content

Commit dbee761

Browse files
sandeepmistryRocketct
authored andcommitted
Add GSM::setTimeout(...) and GPRS::setTimeout(...) API's to set timeout of begin
1 parent d106fda commit dbee761

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ begin KEYWORD2
2727
shutdown KEYWORD2
2828
gatVoiceCallStatus KEYWORD2
2929
ready KEYWORD2
30+
setTimeout KEYWORD2
3031
voiceCall KEYWORD2
3132
answerCall KEYWORD2
3233
hangCall KEYWORD2

src/GPRS.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ GPRS::GPRS() :
4848
_apn(NULL),
4949
_username(NULL),
5050
_password(NULL),
51-
_status(IDLE)
51+
_status(IDLE),
52+
_timeout(0)
5253
{
5354
MODEM.addUrcHandler(this);
5455
}
@@ -68,7 +69,14 @@ GSM3_NetworkStatus_t GPRS::attachGPRS(const char* apn, const char* user_name, co
6869
_status = CONNECTING;
6970

7071
if (synchronous) {
72+
unsigned long start = millis();
73+
7174
while (ready() == 0) {
75+
if (_timeout && !((millis() - start) < _timeout)) {
76+
_state = ERROR;
77+
break;
78+
}
79+
7280
delay(100);
7381
}
7482
} else {
@@ -312,6 +320,11 @@ IPAddress GPRS::getIPAddress()
312320
return IPAddress(0, 0, 0, 0);
313321
}
314322

323+
void GPRS::setTimeout(unsigned long timeout)
324+
{
325+
_timeout = timeout;
326+
}
327+
315328
int GPRS::hostByName(const char* hostname, IPAddress& result)
316329
{
317330
String response;

src/GPRS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class GPRS : public ModemUrcHandler {
8080
*/
8181
IPAddress getIPAddress();
8282

83+
void setTimeout(unsigned long timeout);
8384

8485
int hostByName(const char* hostname, IPAddress& result);
8586
int hostByName(const String &hostname, IPAddress& result) { return hostByName(hostname.c_str(), result); }
@@ -100,6 +101,7 @@ class GPRS : public ModemUrcHandler {
100101
GSM3_NetworkStatus_t _status;
101102
String _response;
102103
int _pingResult;
104+
unsigned long _timeout;
103105
};
104106

105107
#endif

src/GSM.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ enum {
4646
GSM::GSM(bool debug) :
4747
_state(ERROR),
4848
_readyState(0),
49-
_pin(NULL)
49+
_pin(NULL),
50+
_timeout(0)
5051
{
5152
if (debug) {
5253
MODEM.debug();
@@ -63,7 +64,14 @@ GSM3_NetworkStatus_t GSM::begin(const char* pin, bool restart, bool synchronous)
6364
_readyState = READY_STATE_CHECK_SIM;
6465

6566
if (synchronous) {
67+
unsigned long start = millis();
68+
6669
while (ready() == 0) {
70+
if (_timeout && !((millis() - start) < _timeout)) {
71+
_state = ERROR;
72+
break;
73+
}
74+
6775
delay(100);
6876
}
6977
} else {
@@ -315,6 +323,11 @@ int GSM::ready()
315323
return ready;
316324
}
317325

326+
void GSM::setTimeout(unsigned long timeout)
327+
{
328+
_timeout = timeout;
329+
}
330+
318331
unsigned long GSM::getTime()
319332
{
320333
String response;

src/GSM.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class GSM {
6666
*/
6767
int ready();
6868

69+
void setTimeout(unsigned long timeout);
70+
6971
unsigned long getTime();
7072
unsigned long getLocalTime();
7173

@@ -77,6 +79,7 @@ class GSM {
7779
int _readyState;
7880
const char* _pin;
7981
String _response;
82+
unsigned long _timeout;
8083
};
8184

8285
#endif

0 commit comments

Comments
 (0)