Unified interface a bit more
This commit is contained in:
@@ -315,6 +315,17 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WiFi functions
|
||||||
|
*/
|
||||||
|
bool networkConnect(const char* ssid, const char* pwd) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool networkDisconnect() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
*/
|
*/
|
||||||
|
@@ -233,6 +233,17 @@ public:
|
|||||||
return waitResponse(10000L) == 1;
|
return waitResponse(10000L) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GPRS functions
|
||||||
|
*/
|
||||||
|
bool gprsConnect(const char* apn, const char* user, const char* pwd) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gprsDisconnect() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Public Utilities */
|
/* Public Utilities */
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void sendAT(Args... cmd) {
|
void sendAT(Args... cmd) {
|
||||||
|
@@ -324,6 +324,17 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WiFi functions
|
||||||
|
*/
|
||||||
|
bool networkConnect(const char* ssid, const char* pwd) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool networkDisconnect() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
*/
|
*/
|
||||||
@@ -529,7 +540,6 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int modemConnect(const char* host, uint16_t port, uint8_t mux) {
|
int modemConnect(const char* host, uint16_t port, uint8_t mux) {
|
||||||
int rsp = 0;
|
|
||||||
for (int i=0; i<3; i++) {
|
for (int i=0; i<3; i++) {
|
||||||
String ip = dnsIpQuery(host);
|
String ip = dnsIpQuery(host);
|
||||||
|
|
||||||
|
@@ -331,6 +331,17 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WiFi functions
|
||||||
|
*/
|
||||||
|
bool networkConnect(const char* ssid, const char* pwd) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool networkDisconnect() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
*/
|
*/
|
||||||
@@ -570,21 +581,21 @@ public:
|
|||||||
index = 5;
|
index = 5;
|
||||||
goto finish;
|
goto finish;
|
||||||
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
} else if (data.endsWith(GF(GSM_NL "+CIPRXGET:"))) {
|
||||||
|
index = 6;
|
||||||
String mode = streamReadUntil(',');
|
String mode = streamReadUntil(',');
|
||||||
if (mode.toInt() == 1) {
|
if (mode.toInt() == 1) {
|
||||||
mux = streamReadUntil('\n').toInt();
|
mux = streamReadUntil('\n').toInt();
|
||||||
gotData = true;
|
gotData = true;
|
||||||
data = "";
|
|
||||||
} else {
|
} else {
|
||||||
data += mode;
|
data += mode;
|
||||||
}
|
}
|
||||||
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
|
} else if (data.endsWith(GF("CLOSED" GSM_NL))) {
|
||||||
|
index = 7;
|
||||||
int nl = data.lastIndexOf(GSM_NL, data.length()-8);
|
int nl = data.lastIndexOf(GSM_NL, data.length()-8);
|
||||||
int coma = data.indexOf(',', nl+2);
|
int coma = data.indexOf(',', nl+2);
|
||||||
mux = data.substring(nl+2, coma).toInt();
|
mux = data.substring(nl+2, coma).toInt();
|
||||||
if (mux) {
|
if (mux) {
|
||||||
sockets[mux]->sock_connected = false;
|
sockets[mux]->sock_connected = false;
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -595,7 +606,6 @@ public:
|
|||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG("### Unhandled:", data);
|
DBG("### Unhandled:", data);
|
||||||
}
|
}
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
data.trim();
|
data.trim();
|
||||||
@@ -604,11 +614,11 @@ public:
|
|||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
DBG(GSM_NL, "<<< ", data);
|
DBG(GSM_NL, "<<< ", data);
|
||||||
}
|
}
|
||||||
data = "";
|
|
||||||
}
|
}
|
||||||
if (gotData) {
|
if (gotData) {
|
||||||
sockets[mux]->sock_available = modemGetAvailable(mux);
|
sockets[mux]->sock_available = modemGetAvailable(mux);
|
||||||
}
|
}
|
||||||
|
data = "";
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,11 +684,11 @@ private:
|
|||||||
buf[0] = streamRead();
|
buf[0] = streamRead();
|
||||||
buf[1] = streamRead();
|
buf[1] = streamRead();
|
||||||
char c = strtol(buf, NULL, 16);
|
char c = strtol(buf, NULL, 16);
|
||||||
// DBG(c);
|
DBG(c);
|
||||||
#else
|
#else
|
||||||
while (!stream.available()) {}
|
while (!stream.available()) {}
|
||||||
char c = streamRead();
|
char c = streamRead();
|
||||||
// DBG(c);
|
DBG(c);
|
||||||
#endif
|
#endif
|
||||||
sockets[mux]->rx.put(c);
|
sockets[mux]->rx.put(c);
|
||||||
}
|
}
|
||||||
|
@@ -323,7 +323,7 @@ public:
|
|||||||
/*
|
/*
|
||||||
* GPRS functions
|
* GPRS functions
|
||||||
*/
|
*/
|
||||||
bool gprsConnect(const char* apn) {
|
bool gprsConnect(const char* apn, const char* user = "", const char* pw = "") {
|
||||||
|
|
||||||
commandMode();
|
commandMode();
|
||||||
|
|
||||||
@@ -380,25 +380,6 @@ public:
|
|||||||
DBG(GSM_NL, ">>> AT:", cmd...);
|
DBG(GSM_NL, ">>> AT:", cmd...);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool commandMode(void){
|
|
||||||
delay(1000); // cannot send anything for 1 second before entering command mode
|
|
||||||
streamWrite("+++"); // enter command mode
|
|
||||||
waitResponse(1100);
|
|
||||||
return 1 == waitResponse(1100); // wait another second for an "OK\r"
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeChanges(void){
|
|
||||||
streamWrite("ATWR", GSM_NL); // Write changes to flash
|
|
||||||
waitResponse();
|
|
||||||
streamWrite("ATAC", GSM_NL); // Apply changes
|
|
||||||
waitResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
void exitCommand(void){
|
|
||||||
streamWrite("ATCN", GSM_NL); // Exit command mode
|
|
||||||
waitResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Optimize this!
|
// TODO: Optimize this!
|
||||||
uint8_t waitResponse(uint32_t timeout, String& data,
|
uint8_t waitResponse(uint32_t timeout, String& data,
|
||||||
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
GsmConstStr r1=GFP(GSM_OK), GsmConstStr r2=GFP(GSM_ERROR),
|
||||||
@@ -541,6 +522,25 @@ private:
|
|||||||
return return_string;
|
return return_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool commandMode(void){
|
||||||
|
delay(1000); // cannot send anything for 1 second before entering command mode
|
||||||
|
streamWrite(GF("+++")); // enter command mode
|
||||||
|
waitResponse(1100);
|
||||||
|
return 1 == waitResponse(1100); // wait another second for an "OK\r"
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeChanges(void){
|
||||||
|
sendAT(GF("WR")); // Write changes to flash
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("AC")); // Apply changes
|
||||||
|
waitResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void exitCommand(void){
|
||||||
|
sendAT(GF("CN")); // Exit command mode
|
||||||
|
waitResponse();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Stream& stream;
|
Stream& stream;
|
||||||
GsmClient* sockets[1];
|
GsmClient* sockets[1];
|
||||||
|
Reference in New Issue
Block a user