mirror of
https://github.com/KevinMidboe/TinyGSM.git
synced 2025-10-29 18:00:18 +00:00
Moved modem functions to pre-processor macros
This commit is contained in:
@@ -174,31 +174,11 @@ public:
|
||||
return "Quectel BG96";
|
||||
}
|
||||
|
||||
void setBaud(unsigned long baud) {
|
||||
sendAT(GF("+IPR="), baud);
|
||||
}
|
||||
TINY_GSM_MODEM_SET_BAUD_IPR()
|
||||
|
||||
bool testAT(unsigned long timeout = 10000L) {
|
||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||
sendAT(GF(""));
|
||||
if (waitResponse(200) == 1) return true;
|
||||
delay(100);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TINY_GSM_MODEM_TEST_AT()
|
||||
|
||||
void maintain() {
|
||||
for (int mux = 0; mux < TINY_GSM_MUX_COUNT; mux++) {
|
||||
GsmClient* sock = sockets[mux];
|
||||
if (sock && sock->got_data) {
|
||||
sock->got_data = false;
|
||||
sock->sock_available = modemGetAvailable(mux);
|
||||
}
|
||||
}
|
||||
while (stream.available()) {
|
||||
waitResponse(10, NULL, NULL);
|
||||
}
|
||||
}
|
||||
TINY_GSM_MODEM_MAINTAIN_CHECK_SOCKS()
|
||||
|
||||
bool factoryDefault() {
|
||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||
@@ -209,17 +189,7 @@ public:
|
||||
return waitResponse() == 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
TINY_GSM_MODEM_GET_INFO_ATI()
|
||||
|
||||
bool hasSSL() {
|
||||
return false; // TODO: For now
|
||||
@@ -268,14 +238,11 @@ public:
|
||||
* SIM card functions
|
||||
*/
|
||||
|
||||
bool simUnlock(const char *pin) {
|
||||
sendAT(GF("+CPIN=\""), pin, GF("\""));
|
||||
return waitResponse() == 1;
|
||||
}
|
||||
TINY_GSM_MODEM_SIM_UNLOCK_CPIN()
|
||||
|
||||
String getSimCCID() {
|
||||
sendAT(GF("+ICCID"));
|
||||
if (waitResponse(GF(GSM_NL "+ICCID:")) != 1) {
|
||||
sendAT(GF("+QCCID"));
|
||||
if (waitResponse(GF(GSM_NL "+QCCID:")) != 1) {
|
||||
return "";
|
||||
}
|
||||
String res = stream.readStringUntil('\n');
|
||||
@@ -284,16 +251,7 @@ public:
|
||||
return res;
|
||||
}
|
||||
|
||||
String getIMEI() {
|
||||
sendAT(GF("+GSN"));
|
||||
if (waitResponse(GF(GSM_NL)) != 1) {
|
||||
return "";
|
||||
}
|
||||
String res = stream.readStringUntil('\n');
|
||||
waitResponse();
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
TINY_GSM_MODEM_GET_IMEI_GSN()
|
||||
|
||||
SimStatus getSimStatus(unsigned long timeout = 10000L) {
|
||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||
@@ -314,56 +272,22 @@ public:
|
||||
return SIM_ERROR;
|
||||
}
|
||||
|
||||
RegStatus getRegistrationStatus() {
|
||||
sendAT(GF("+CREG?"));
|
||||
if (waitResponse(GF(GSM_NL "+CREG:")) != 1) {
|
||||
return REG_UNKNOWN;
|
||||
}
|
||||
streamSkipUntil(','); // Skip format (0)
|
||||
int status = stream.readStringUntil('\n').toInt();
|
||||
waitResponse();
|
||||
return (RegStatus)status;
|
||||
}
|
||||
TINY_GSM_MODEM_GET_REGISTRATION_XREG(CREG)
|
||||
|
||||
String getOperator() {
|
||||
sendAT(GF("+COPS?"));
|
||||
if (waitResponse(GF(GSM_NL "+COPS:")) != 1) {
|
||||
return "";
|
||||
}
|
||||
streamSkipUntil('"'); // Skip mode and format
|
||||
String res = stream.readStringUntil('"');
|
||||
waitResponse();
|
||||
return res;
|
||||
}
|
||||
TINY_GSM_MODEM_GET_OPERATOR_COPS()
|
||||
|
||||
/*
|
||||
* Generic network functions
|
||||
*/
|
||||
|
||||
int16_t getSignalQuality() {
|
||||
sendAT(GF("+CSQ"));
|
||||
if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
|
||||
return 99;
|
||||
}
|
||||
int res = stream.readStringUntil(',').toInt();
|
||||
waitResponse();
|
||||
return res;
|
||||
}
|
||||
TINY_GSP_MODEM_GET_CSQ()
|
||||
|
||||
bool isNetworkConnected() {
|
||||
RegStatus s = getRegistrationStatus();
|
||||
return (s == REG_OK_HOME || s == REG_OK_ROAMING);
|
||||
}
|
||||
|
||||
bool waitForNetwork(unsigned long timeout = 60000L) {
|
||||
for (unsigned long start = millis(); millis() - start < timeout; ) {
|
||||
if (isNetworkConnected()) {
|
||||
return true;
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TINY_GSM_MODEM_WAIT_FOR_NETWORK()
|
||||
|
||||
/*
|
||||
* GPRS functions
|
||||
@@ -400,18 +324,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isGprsConnected() {
|
||||
sendAT(GF("+CGATT?"));
|
||||
if (waitResponse(GF(GSM_NL "+CGATT:")) != 1) {
|
||||
return false;
|
||||
}
|
||||
int res = stream.readStringUntil('\n').toInt();
|
||||
waitResponse();
|
||||
if (res != 1)
|
||||
return false;
|
||||
|
||||
return localIP() != IPAddress(0,0,0,0);
|
||||
}
|
||||
TINY_GSP_MODEM_GET_GPRS_IP_CONNECTED()
|
||||
|
||||
/*
|
||||
* IP Address functions
|
||||
@@ -646,37 +559,7 @@ public:
|
||||
Utilities
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
void streamWrite(T last) {
|
||||
stream.print(last);
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
void streamWrite(T head, Args... tail) {
|
||||
stream.print(head);
|
||||
streamWrite(tail...);
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void sendAT(Args... cmd) {
|
||||
streamWrite("AT", cmd..., GSM_NL);
|
||||
stream.flush();
|
||||
TINY_GSM_YIELD();
|
||||
//DBG("### AT:", cmd...);
|
||||
}
|
||||
|
||||
bool streamSkipUntil(const 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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TINY_GSP_MODEM_STREAM_UTILITIES()
|
||||
|
||||
// TODO: Optimize this!
|
||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||
|
||||
Reference in New Issue
Block a user