Rearrange stuff so it makes more sense

This commit is contained in:
Volodymyr Shymanskyy
2017-09-02 19:04:58 +03:00
parent 1c6141f25c
commit 8cf9571a2f

View File

@@ -15,6 +15,8 @@
#define TINY_GSM_RX_BUFFER 256 #define TINY_GSM_RX_BUFFER 256
#endif #endif
#define TINY_GSM_MUX_COUNT 2
#include <TinyGsmCommon.h> #include <TinyGsmCommon.h>
#define GSM_NL "\r\n" #define GSM_NL "\r\n"
@@ -234,7 +236,7 @@ public:
} }
/* /*
* SIM card & Networ Operator functions * SIM card functions
*/ */
bool simUnlock(const char *pin) { bool simUnlock(const char *pin) {
@@ -264,45 +266,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;
}
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("+CSCS=\"gsm\""));
waitResponse();
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;
}
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?"));
@@ -344,13 +307,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);
} }
@@ -402,20 +377,49 @@ public:
* Phone Call functions * Phone Call functions
*/ */
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("+CSCS=\"gsm\""));
waitResponse();
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;
} }
/* /*
* Location functions * Location functions
*/ */
void getLocation() {
void getGsmLocation() {
} }
/* /*
@@ -592,7 +596,7 @@ finish:
private: private:
Stream& stream; Stream& stream;
GsmClient* sockets[2]; GsmClient* sockets[TINY_GSM_MUX_COUNT];
}; };
typedef TinyGsm::GsmClient TinyGsmClient; typedef TinyGsm::GsmClient TinyGsmClient;