Browse Source

Reordered some functions in the XBee

v_master
Sara Damiano 6 years ago
parent
commit
9f25adc2db
1 changed files with 45 additions and 44 deletions
  1. +45
    -44
      src/TinyGsmClientXBee.h

+ 45
- 44
src/TinyGsmClientXBee.h View File

@ -724,6 +724,11 @@ public:
Utilities
*/
void streamClear(void) {
TINY_GSM_YIELD();
while (stream.available()) { stream.read(); }
}
template<typename T>
void streamWrite(T last) {
stream.print(last);
@ -735,50 +740,6 @@ public:
streamWrite(tail...);
}
void streamClear(void) {
TINY_GSM_YIELD();
while (stream.available()) { stream.read(); }
}
bool commandMode(int retries = 2) {
int triesMade = 0;
bool success = false;
streamClear(); // Empty everything in the buffer before starting
while (!success and triesMade < retries) {
// Cannot send anything for 1 "guard time" before entering command mode
// Default guard time is 1s, but the init fxn decreases it to 250 ms
delay(guardTime);
streamWrite(GF("+++")); // enter command mode
DBG("+++");
success = (1 == waitResponse(guardTime*2));
triesMade ++;
}
return success;
}
bool writeChanges(void) {
sendAT(GF("WR")); // Write changes to flash
if (1 != waitResponse()) return false;
sendAT(GF("AC")); // Apply changes
if (1 != waitResponse()) return false;
return true;
}
void exitCommand(void) {
sendAT(GF("CN")); // Exit command mode
waitResponse();
}
String readResponse(uint32_t timeout = 1000) {
TINY_GSM_YIELD();
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < timeout) {};
String res = stream.readStringUntil('\r'); // lines end with carriage returns
res.trim();
DBG("<<< ", res);
return res;
}
template<typename... Args>
void sendAT(Args... cmd) {
streamWrite("AT", cmd..., GSM_NL);
@ -843,6 +804,7 @@ finish:
DBG("<<< ", data);
}
}
DBG('<', index, '>');
return index;
}
@ -860,6 +822,45 @@ finish:
return waitResponse(1000, r1, r2, r3, r4, r5);
}
bool commandMode(int retries = 2) {
int triesMade = 0;
bool success = false;
streamClear(); // Empty everything in the buffer before starting
while (!success and triesMade < retries) {
// Cannot send anything for 1 "guard time" before entering command mode
// Default guard time is 1s, but the init fxn decreases it to 250 ms
delay(guardTime);
streamWrite(GF("+++")); // enter command mode
DBG("+++");
success = (1 == waitResponse(guardTime*2));
triesMade ++;
}
return success;
}
bool writeChanges(void) {
sendAT(GF("WR")); // Write changes to flash
if (1 != waitResponse()) return false;
sendAT(GF("AC")); // Apply changes
if (1 != waitResponse()) return false;
return true;
}
void exitCommand(void) {
sendAT(GF("CN")); // Exit command mode
waitResponse();
}
String readResponse(uint32_t timeout = 1000) {
TINY_GSM_YIELD();
unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < timeout) {};
String res = stream.readStringUntil('\r'); // lines end with carriage returns
res.trim();
DBG("<<< ", res);
return res;
}
public:
Stream& stream;


Loading…
Cancel
Save