Skip to content

Commit d6e325b

Browse files
FrancMunozsandeepmistry
authored andcommitted
Delay upto 20ms to wait SARA
1 parent 919c66b commit d6e325b

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Modem.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int ModemClass::begin(bool restart)
4343
pinMode(_resetPin, OUTPUT);
4444
digitalWrite(_resetPin, HIGH);
4545
delay(100);
46-
digitalWrite(_resetPin, LOW);
46+
digitalWrite(_resetPin, LOW);
4747
} else {
4848
if (!autosense()) {
4949
return 0;
@@ -63,7 +63,7 @@ int ModemClass::begin(bool restart)
6363
if (waitForResponse() != 1) {
6464
return 0;
6565
}
66-
66+
6767
_uart->end();
6868
delay(100);
6969
_uart->begin(_baud);
@@ -171,6 +171,9 @@ void ModemClass::send(const char* command)
171171
delay(5);
172172
}
173173

174+
unsigned long dif=millis()-_uartMillis;
175+
if(dif<20) delay(20-dif);
176+
174177
_uart->println(command);
175178
_uart->flush();
176179
_atCommandState = AT_COMMAND_IDLE;
@@ -182,7 +185,7 @@ void ModemClass::sendf(const char *fmt, ...)
182185
char buf[BUFSIZ];
183186

184187
va_list ap;
185-
va_start((ap), (fmt));
188+
va_start((ap), (fmt));
186189
vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
187190
va_end(ap);
188191

@@ -217,6 +220,7 @@ void ModemClass::poll()
217220
{
218221
while (_uart->available()) {
219222
char c = _uart->read();
223+
_uartMillis=millis();
220224

221225
if (_debug) {
222226
Serial.write(c);
@@ -227,7 +231,7 @@ void ModemClass::poll()
227231
switch (_atCommandState) {
228232
case AT_COMMAND_IDLE:
229233
default: {
230-
234+
231235
if (_buffer.startsWith("AT") && _buffer.endsWith("\r\n")) {
232236
_atCommandState = AT_RECEIVING_RESPONSE;
233237
_buffer = "";
@@ -240,7 +244,7 @@ void ModemClass::poll()
240244
_urcHandlers[i]->handleUrc(_buffer);
241245
}
242246
}
243-
}
247+
}
244248

245249
_buffer = "";
246250
}
@@ -252,7 +256,7 @@ void ModemClass::poll()
252256
if (c == '\n') {
253257
int responseResultIndex = _buffer.lastIndexOf("OK\r\n");
254258
if (responseResultIndex != -1) {
255-
_ready = 1;
259+
_ready = 1;
256260
} else {
257261
responseResultIndex = _buffer.lastIndexOf("ERROR\r\n");
258262
if (responseResultIndex != -1) {

src/Modem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ModemClass {
5858
int ready();
5959
void poll();
6060
void setResponseDataStorage(String* responseDataStorage);
61-
61+
6262
void addUrcHandler(ModemUrcHandler* handler);
6363
void removeUrcHandler(ModemUrcHandler* handler);
6464

@@ -68,6 +68,7 @@ class ModemClass {
6868
int _resetPin;
6969
int _dtrPin;
7070
bool _lowPowerMode;
71+
unsigned long _uartMillis;
7172

7273
enum {
7374
AT_COMMAND_IDLE,

0 commit comments

Comments
 (0)