Rearrange stuff so it makes more sense
This commit is contained in:
@@ -191,6 +191,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool autoBaud(unsigned long timeout = 10000L) {
|
bool autoBaud(unsigned long timeout = 10000L) {
|
||||||
|
streamWrite(GF("AAAAAAA")); // extra A's to help detect the baud rate
|
||||||
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) {
|
||||||
@@ -262,7 +263,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SIM card & Networ Operator functions
|
* SIM card functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool simUnlock(const char *pin) {
|
bool simUnlock(const char *pin) {
|
||||||
@@ -292,85 +293,6 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSignalQuality() {
|
|
||||||
sendAT(GF("+CSQ"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
|
||||||
return 99;
|
|
||||||
}
|
|
||||||
int res = stream.readStringUntil(',').toInt();
|
|
||||||
waitResponse();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getGsmLocation() {
|
|
||||||
sendAT(GF("+CIPGSMLOC=1,1"));
|
|
||||||
if (waitResponse(GF(GSM_NL "+CIPGSMLOC:")) != 1) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
String res = stream.readStringUntil('\n');
|
|
||||||
waitResponse();
|
|
||||||
res.trim();
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool setGsmBusy(bool busy = true) {
|
|
||||||
sendAT(GF("+GSMBUSY="), busy ? 1 : 0);
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool callAnswer() {
|
|
||||||
sendAT(GF("A"));
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool callNumber(const String& number) {
|
|
||||||
sendAT(GF("D"), number);
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool callHangup(const String& number) {
|
|
||||||
sendAT(GF("H"), number);
|
|
||||||
return waitResponse() == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
|
||||||
sendAT(GF("+CMGF=1"));
|
|
||||||
waitResponse();
|
|
||||||
sendAT(GF("+CMGS=\""), number, GF("\""));
|
|
||||||
if (waitResponse(GF(">")) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
stream.print(text);
|
|
||||||
stream.write((char)0x1A);
|
|
||||||
return waitResponse(60000L) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
|
|
||||||
sendAT(GF("+CMGF=1"));
|
|
||||||
waitResponse();
|
|
||||||
sendAT(GF("+CSCS=\"HEX\""));
|
|
||||||
waitResponse();
|
|
||||||
sendAT(GF("+CSMP=17,167,0,8"));
|
|
||||||
waitResponse();
|
|
||||||
|
|
||||||
sendAT(GF("+CMGS=\""), number, GF("\""));
|
|
||||||
if (waitResponse(GF(">")) != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t* t = (uint16_t*)text;
|
|
||||||
for (size_t i=0; i<len; i++) {
|
|
||||||
uint8_t c = t[i] >> 8;
|
|
||||||
if (c < 0x10) { stream.print('0'); }
|
|
||||||
stream.print(c, HEX);
|
|
||||||
c = t[i] & 0xFF;
|
|
||||||
if (c < 0x10) { stream.print('0'); }
|
|
||||||
stream.print(c, HEX);
|
|
||||||
}
|
|
||||||
stream.write((char)0x1A);
|
|
||||||
return waitResponse(60000L) == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
sendAT(GF("+CPIN?"));
|
sendAT(GF("+CPIN?"));
|
||||||
@@ -412,13 +334,25 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Generic network functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
int getSignalQuality() {
|
||||||
|
sendAT(GF("+CSQ"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
||||||
|
return 99;
|
||||||
|
}
|
||||||
|
int res = stream.readStringUntil(',').toInt();
|
||||||
|
waitResponse();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||||
RegStatus s = getRegistrationStatus();
|
RegStatus s = getRegistrationStatus();
|
||||||
if (s == REG_OK_HOME || s == REG_OK_ROAMING) {
|
if (s == REG_OK_HOME || s == REG_OK_ROAMING) {
|
||||||
return true;
|
return true;
|
||||||
} else if (s == REG_UNREGISTERED) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
@@ -515,20 +449,86 @@ public:
|
|||||||
* Phone Call functions
|
* Phone Call functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
bool setGsmBusy(bool busy = true) {
|
||||||
|
sendAT(GF("+GSMBUSY="), busy ? 1 : 0);
|
||||||
|
return waitResponse() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool callAnswer() {
|
||||||
|
sendAT(GF("A"));
|
||||||
|
return waitResponse() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool callNumber(const String& number) {
|
||||||
|
sendAT(GF("D"), number);
|
||||||
|
return waitResponse() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool callHangup(const String& number) {
|
||||||
|
sendAT(GF("H"), number);
|
||||||
|
return waitResponse() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Messaging functions
|
* Messaging functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO
|
||||||
void sendUSSD() {
|
void sendUSSD() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendSMS() {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("+CMGS=\""), number, GF("\""));
|
||||||
|
if (waitResponse(GF(">")) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
stream.print(text);
|
||||||
|
stream.write((char)0x1A);
|
||||||
|
return waitResponse(60000L) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
|
||||||
|
sendAT(GF("+CMGF=1"));
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("+CSCS=\"HEX\""));
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("+CSMP=17,167,0,8"));
|
||||||
|
waitResponse();
|
||||||
|
|
||||||
|
sendAT(GF("+CMGS=\""), number, GF("\""));
|
||||||
|
if (waitResponse(GF(">")) != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t* t = (uint16_t*)text;
|
||||||
|
for (size_t i=0; i<len; i++) {
|
||||||
|
uint8_t c = t[i] >> 8;
|
||||||
|
if (c < 0x10) { stream.print('0'); }
|
||||||
|
stream.print(c, HEX);
|
||||||
|
c = t[i] & 0xFF;
|
||||||
|
if (c < 0x10) { stream.print('0'); }
|
||||||
|
stream.print(c, HEX);
|
||||||
|
}
|
||||||
|
stream.write((char)0x1A);
|
||||||
|
return waitResponse(60000L) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Location functions
|
* Location functions
|
||||||
*/
|
*/
|
||||||
void getLocation() {
|
|
||||||
|
String getGsmLocation() {
|
||||||
|
sendAT(GF("+CIPGSMLOC=1,1"));
|
||||||
|
if (waitResponse(GF(GSM_NL "+CIPGSMLOC:")) != 1) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String res = stream.readStringUntil('\n');
|
||||||
|
waitResponse();
|
||||||
|
res.trim();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -578,6 +578,7 @@ private:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
stream.write((uint8_t*)buff, len);
|
stream.write((uint8_t*)buff, len);
|
||||||
|
stream.flush();
|
||||||
if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) {
|
if (waitResponse(GF(GSM_NL "DATA ACCEPT:")) != 1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user