resync U201
This commit is contained in:
		@@ -40,9 +40,22 @@ enum RegStatus {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//                   Declaration of the TinyGsmU201 Class
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//============================================================================//
 | 
			
		||||
 | 
			
		||||
class TinyGsmU201
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//                          The U201 Client Class
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//============================================================================//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
class GsmClient : public Client
 | 
			
		||||
@@ -109,7 +122,7 @@ public:
 | 
			
		||||
 | 
			
		||||
  virtual int available() {
 | 
			
		||||
    TINY_GSM_YIELD();
 | 
			
		||||
    if (!rx.size()) {
 | 
			
		||||
    if (!rx.size() && sock_connected) {
 | 
			
		||||
      at->maintain();
 | 
			
		||||
    }
 | 
			
		||||
    return rx.size() + sock_available;
 | 
			
		||||
@@ -172,6 +185,13 @@ private:
 | 
			
		||||
  RxFifo        rx;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//                          The Secure U201 Client Class
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//============================================================================//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class GsmClientSecure : public GsmClient
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
@@ -192,6 +212,13 @@ public:
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//                          The U201 Modem Functions
 | 
			
		||||
//============================================================================//
 | 
			
		||||
//============================================================================//
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
#ifdef GSM_DEFAULT_STREAM
 | 
			
		||||
@@ -305,6 +332,8 @@ public:
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool sleepEnable(bool enable = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
   * SIM card functions
 | 
			
		||||
   */
 | 
			
		||||
@@ -355,17 +384,6 @@ public:
 | 
			
		||||
    return SIM_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  RegStatus getRegistrationStatus() {
 | 
			
		||||
    sendAT(GF("+CGREG?"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) {
 | 
			
		||||
      return REG_UNKNOWN;
 | 
			
		||||
    }
 | 
			
		||||
    streamSkipUntil(','); // Skip format (0)
 | 
			
		||||
    int status = stream.readStringUntil('\n').toInt();
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    return (RegStatus)status;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getOperator() {
 | 
			
		||||
    sendAT(GF("+COPS?"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
 | 
			
		||||
@@ -381,6 +399,17 @@ public:
 | 
			
		||||
   * Generic network functions
 | 
			
		||||
   */
 | 
			
		||||
 | 
			
		||||
   RegStatus getRegistrationStatus() {
 | 
			
		||||
     sendAT(GF("+CGREG?"));
 | 
			
		||||
     if (waitResponse(GF(GSM_NL "+CGREG:")) != 1) {
 | 
			
		||||
       return REG_UNKNOWN;
 | 
			
		||||
     }
 | 
			
		||||
     streamSkipUntil(','); // Skip format (0)
 | 
			
		||||
     int status = stream.readStringUntil('\n').toInt();
 | 
			
		||||
     waitResponse();
 | 
			
		||||
     return (RegStatus)status;
 | 
			
		||||
   }
 | 
			
		||||
 | 
			
		||||
  int getSignalQuality() {
 | 
			
		||||
    sendAT(GF("+CSQ"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
 | 
			
		||||
@@ -406,6 +435,28 @@ public:
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getLocalIP() {
 | 
			
		||||
    sendAT(GF("+UPSND=0,0"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) {
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    streamSkipUntil(',');  // Skip PSD profile
 | 
			
		||||
    streamSkipUntil('\"'); // Skip request type
 | 
			
		||||
    String res = stream.readStringUntil('\"');
 | 
			
		||||
    if (waitResponse() != 1) {
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  IPAddress localIP() {
 | 
			
		||||
    return TinyGsmIpFromString(getLocalIP());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
   * WiFi functions
 | 
			
		||||
   */
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
   * GPRS functions
 | 
			
		||||
   */
 | 
			
		||||
@@ -471,24 +522,6 @@ public:
 | 
			
		||||
    return localIP() != 0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getLocalIP() {
 | 
			
		||||
    sendAT(GF("+UPSND=0,0"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL "+UPSND:")) != 1) {
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    streamSkipUntil(',');  // Skip PSD profile
 | 
			
		||||
    streamSkipUntil('\"'); // Skip request type
 | 
			
		||||
    String res = stream.readStringUntil('\"');
 | 
			
		||||
    if (waitResponse() != 1) {
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  IPAddress localIP() {
 | 
			
		||||
    return TinyGsmIpFromString(getLocalIP());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
   * Phone Call functions
 | 
			
		||||
   */
 | 
			
		||||
@@ -649,9 +682,13 @@ public:
 | 
			
		||||
    streamWrite(tail...);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool streamSkipUntil(char c) { //TODO: timeout
 | 
			
		||||
    while (true) {
 | 
			
		||||
      while (!stream.available()) { TINY_GSM_YIELD(); }
 | 
			
		||||
  bool streamSkipUntil(char c) {
 | 
			
		||||
    const unsigned long timeout = 1000L;
 | 
			
		||||
    unsigned long startMillis = millis();
 | 
			
		||||
    while (millis() - startMillis < timeout) {
 | 
			
		||||
      while (millis() - startMillis < timeout && !stream.available()) {
 | 
			
		||||
        TINY_GSM_YIELD();
 | 
			
		||||
      }
 | 
			
		||||
      if (stream.read() == c)
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
@@ -663,7 +700,7 @@ public:
 | 
			
		||||
    streamWrite("AT", cmd..., GSM_NL);
 | 
			
		||||
    stream.flush();
 | 
			
		||||
    TINY_GSM_YIELD();
 | 
			
		||||
    //DBG("### AT:", cmd...);
 | 
			
		||||
    DBG("### AT:", cmd...);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // TODO: Optimize this!
 | 
			
		||||
@@ -671,12 +708,12 @@ public:
 | 
			
		||||
                       GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
 | 
			
		||||
                       GsmConstStr r3=GFP(GSM_CME_ERROR), GsmConstStr r4=NULL, GsmConstStr r5=NULL)
 | 
			
		||||
  {
 | 
			
		||||
    /*String r1s(r1); r1s.trim();
 | 
			
		||||
    String r1s(r1); r1s.trim();
 | 
			
		||||
    String r2s(r2); r2s.trim();
 | 
			
		||||
    String r3s(r3); r3s.trim();
 | 
			
		||||
    String r4s(r4); r4s.trim();
 | 
			
		||||
    String r5s(r5); r5s.trim();
 | 
			
		||||
    DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);*/
 | 
			
		||||
    DBG("### ..:", r1s, ",", r2s, ",", r3s, ",", r4s, ",", r5s);
 | 
			
		||||
    data.reserve(64);
 | 
			
		||||
    int index = 0;
 | 
			
		||||
    unsigned long startMillis = millis();
 | 
			
		||||
@@ -727,6 +764,7 @@ finish:
 | 
			
		||||
      }
 | 
			
		||||
      data = "";
 | 
			
		||||
    }
 | 
			
		||||
    DBG('<', index, '>');
 | 
			
		||||
    return index;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user