Browse Source

Fix most obvious stuff

v_master
Volodymyr Shymanskyy 7 years ago
parent
commit
4aca7f1871
1 changed files with 45 additions and 26 deletions
  1. +45
    -26
      src/TinyGsmClientU201.h

+ 45
- 26
src/TinyGsmClientU201.h View File

@ -108,7 +108,7 @@ public:
virtual int available() { virtual int available() {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
if (!rx.size() && sock_connected) {
if (!rx.size()) {
at->maintain(); at->maintain();
} }
return rx.size() + sock_available; return rx.size() + sock_available;
@ -129,7 +129,7 @@ public:
// TODO: Read directly into user buffer? // TODO: Read directly into user buffer?
at->maintain(); at->maintain();
if (sock_available > 0) { if (sock_available > 0) {
at->modemRead(rx.free(), mux);
sock_available -= at->modemRead(TinyGsmMin((uint16_t)rx.free(), sock_available), mux);
} else { } else {
break; break;
} }
@ -233,8 +233,8 @@ public:
for (unsigned long start = millis(); millis() - start < timeout; ) { for (unsigned long start = millis(); millis() - start < timeout; ) {
sendAT(GF("")); sendAT(GF(""));
if (waitResponse(200) == 1) { if (waitResponse(200) == 1) {
delay(100);
return true;
delay(100);
return true;
} }
delay(100); delay(100);
} }
@ -261,7 +261,17 @@ public:
return waitResponse() == 1; return waitResponse() == 1;
} }
String getModemInfo() TINY_GSM_ATTR_NOT_IMPLEMENTED;
String getModemInfo() {
sendAT(GF("I"));
String res;
if (waitResponse(1000L, res) != 1) {
return "";
}
res.replace(GSM_NL "OK" GSM_NL, "");
res.replace(GSM_NL, " ");
res.trim();
return res;
}
bool hasSSL() { bool hasSSL() {
return true; return true;
@ -285,6 +295,15 @@ public:
bool poweroff() TINY_GSM_ATTR_NOT_IMPLEMENTED; bool poweroff() TINY_GSM_ATTR_NOT_IMPLEMENTED;
bool radioOff() {
sendAT(GF("+CFUN=0"));
if (waitResponse(10000L) != 1) {
return false;
}
delay(3000);
return true;
}
/* /*
* SIM card functions * SIM card functions
*/ */
@ -393,7 +412,7 @@ public:
gprsDisconnect(); gprsDisconnect();
sendAT(GF("+CGATT=1")); sendAT(GF("+CGATT=1"));
waitResponse(5000L);
waitResponse(60000L);
sendAT(GF("+UPSD=0,1,\""), apn, '"'); sendAT(GF("+UPSD=0,1,\""), apn, '"');
waitResponse(); waitResponse();
@ -411,13 +430,14 @@ public:
waitResponse(); waitResponse();
sendAT(GF("+UPSDA=0,3")); sendAT(GF("+UPSDA=0,3"));
waitResponse(6000L);
waitResponse(60000L);
// Open a GPRS context // Open a GPRS context
sendAT(GF("+UPSND=0,8")); sendAT(GF("+UPSND=0,8"));
if (waitResponse(GF(",8,1")) != 1) { if (waitResponse(GF(",8,1")) != 1) {
return false; return false;
} }
waitResponse();
return true; return true;
} }
@ -443,20 +463,20 @@ public:
if (res != 1) if (res != 1)
return false; return false;
sendAT(GF("+CIFSR"));
if (waitResponse() != 1)
return false;
return true;
return localIP() != 0;
} }
String getLocalIP() { String getLocalIP() {
sendAT(GF("+CIFSR;E0"));
String res;
if (waitResponse(10000L, res) != 1) {
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.trim();
return res; return res;
} }
@ -468,7 +488,7 @@ public:
* Phone Call functions * Phone Call functions
*/ */
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_IMPLEMENTED;
bool setGsmBusy(bool busy = true) TINY_GSM_ATTR_NOT_AVAILABLE;
bool callAnswer() TINY_GSM_ATTR_NOT_IMPLEMENTED; bool callAnswer() TINY_GSM_ATTR_NOT_IMPLEMENTED;
@ -493,7 +513,7 @@ public:
String getGsmLocation() { String getGsmLocation() {
sendAT(GF("+ULOC=2,3,0,120,1")); sendAT(GF("+ULOC=2,3,0,120,1"));
if (waitResponse(GF(GSM_NL "+UULOC:")) != 1) {
if (waitResponse(30000L, GF(GSM_NL "+UULOC:")) != 1) {
return ""; return "";
} }
String res = stream.readStringUntil('\n'); String res = stream.readStringUntil('\n');
@ -505,20 +525,19 @@ public:
/* /*
* Battery functions * Battery functions
*/ */
// Use: float vBatt = modem.getBattVoltage() / 1000.0;
uint16_t getBattVoltage() {
sendAT(GF("+CIND"));
uint16_t getBattVoltage() TINY_GSM_ATTR_NOT_AVAILABLE;
int getBattPercent() {
sendAT(GF("+CIND?"));
if (waitResponse(GF(GSM_NL "+CIND:")) != 1) { if (waitResponse(GF(GSM_NL "+CIND:")) != 1) {
return 0; return 0;
} }
uint16_t res = stream.readStringUntil(',').toInt();
int res = stream.readStringUntil(',').toInt();
waitResponse(); waitResponse();
return res; return res;
} }
int getBattPercent() TINY_GSM_ATTR_NOT_IMPLEMENTED;
protected: protected:
bool modemConnect(const char* host, uint16_t port, uint8_t* mux, bool ssl = false) { bool modemConnect(const char* host, uint16_t port, uint8_t* mux, bool ssl = false) {
@ -542,14 +561,14 @@ protected:
int modemSend(const void* buff, size_t len, uint8_t mux) { int modemSend(const void* buff, size_t len, uint8_t mux) {
sendAT(GF("+USOWR="), mux, ',', len); sendAT(GF("+USOWR="), mux, ',', len);
if (waitResponse(GF("@")) != 1) { if (waitResponse(GF("@")) != 1) {
return -1;
return 0;
} }
// 50ms delay, see AT manual section 25.10.4 // 50ms delay, see AT manual section 25.10.4
delay(50); delay(50);
stream.write((uint8_t*)buff, len); stream.write((uint8_t*)buff, len);
stream.flush(); stream.flush();
if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) { if (waitResponse(GF(GSM_NL "+USOWR:")) != 1) {
return -1;
return 0;
} }
streamSkipUntil(','); // Skip mux streamSkipUntil(','); // Skip mux
return stream.readStringUntil('\n').toInt(); return stream.readStringUntil('\n').toInt();


Loading…
Cancel
Save