decodeHex16bit support for sendUSSD
This commit is contained in:
@@ -446,7 +446,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
String sendUSSD(const String& code) {
|
String sendUSSD(const String& code) {
|
||||||
sendAT(GF("+CSCS=HEX"));
|
sendAT(GF("+CMGF=1"));
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("+CSCS=\"HEX\""));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
sendAT(GF("+CUSD=1,\""), code, GF("\",15"));
|
sendAT(GF("+CUSD=1,\""), code, GF("\",15"));
|
||||||
if (waitResponse(10000L) != 1) {
|
if (waitResponse(10000L) != 1) {
|
||||||
@@ -462,6 +464,8 @@ public:
|
|||||||
|
|
||||||
if (dcs == 15) {
|
if (dcs == 15) {
|
||||||
return decodeHex7bit(hex);
|
return decodeHex7bit(hex);
|
||||||
|
} else if (dcs == 72) {
|
||||||
|
return decodeHex16bit(hex);
|
||||||
} else {
|
} else {
|
||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
@@ -539,8 +543,8 @@ private:
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool modemGetConnected(uint8_t mux) { //TODO mux?
|
bool modemGetConnected(uint8_t mux) {
|
||||||
sendAT(GF("+CIPSTATUS"));
|
sendAT(GF("+CIPSTATUS")); //TODO mux?
|
||||||
int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), GF(",\"INITIAL\""));
|
int res = waitResponse(GF(",\"CONNECTED\""), GF(",\"CLOSED\""), GF(",\"CLOSING\""), GF(",\"INITIAL\""));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
return 1 == res;
|
return 1 == res;
|
||||||
@@ -571,6 +575,25 @@ private:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String decodeHex16bit(String &instr) {
|
||||||
|
String result;
|
||||||
|
for (unsigned i=0; i<instr.length(); i+=4) {
|
||||||
|
char buf[4] = { 0, };
|
||||||
|
buf[0] = instr[i];
|
||||||
|
buf[1] = instr[i+1];
|
||||||
|
char b = strtol(buf, NULL, 16);
|
||||||
|
if (b) { // If high byte is non-zero, we can't handle it ;(
|
||||||
|
b = '?';
|
||||||
|
} else {
|
||||||
|
buf[0] = instr[i+2];
|
||||||
|
buf[1] = instr[i+3];
|
||||||
|
b = strtol(buf, NULL, 16);
|
||||||
|
}
|
||||||
|
result += b;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
|
@@ -257,7 +257,7 @@ public:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
res.replace(GSM_NL "OK" GSM_NL, "");
|
res.replace(GSM_NL "OK" GSM_NL, "");
|
||||||
res.replace(GSM_NL, "");
|
res.replace(GSM_NL, " ");
|
||||||
res.trim();
|
res.trim();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -537,7 +537,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
String sendUSSD(const String& code) {
|
String sendUSSD(const String& code) {
|
||||||
sendAT(GF("+CSCS=\"8859-1\""));
|
sendAT(GF("+CMGF=1"));
|
||||||
|
waitResponse();
|
||||||
|
sendAT(GF("+CSCS=\"HEX\""));
|
||||||
waitResponse();
|
waitResponse();
|
||||||
sendAT(GF("+CUSD=1,\""), code, GF("\""));
|
sendAT(GF("+CUSD=1,\""), code, GF("\""));
|
||||||
if (waitResponse() != 1) {
|
if (waitResponse() != 1) {
|
||||||
@@ -547,9 +549,17 @@ public:
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
stream.readStringUntil('"');
|
stream.readStringUntil('"');
|
||||||
String res = stream.readStringUntil('"');
|
String hex = stream.readStringUntil('"');
|
||||||
stream.readStringUntil('\n');
|
stream.readStringUntil(',');
|
||||||
return res;
|
int dcs = stream.readStringUntil('\n').toInt();
|
||||||
|
|
||||||
|
if (dcs == 15) {
|
||||||
|
return decodeHex8bit(hex);
|
||||||
|
} else if (dcs == 72) {
|
||||||
|
return decodeHex16bit(hex);
|
||||||
|
} else {
|
||||||
|
return hex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sendSMS(const String& number, const String& text) {
|
bool sendSMS(const String& number, const String& text) {
|
||||||
@@ -717,6 +727,37 @@ private:
|
|||||||
return 1 == res;
|
return 1 == res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String decodeHex8bit(String &instr) {
|
||||||
|
String result;
|
||||||
|
for (unsigned i=0; i<instr.length(); i+=2) {
|
||||||
|
char buf[4] = { 0, };
|
||||||
|
buf[0] = instr[i];
|
||||||
|
buf[1] = instr[i+1];
|
||||||
|
char b = strtol(buf, NULL, 16);
|
||||||
|
result += b;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String decodeHex16bit(String &instr) {
|
||||||
|
String result;
|
||||||
|
for (unsigned i=0; i<instr.length(); i+=4) {
|
||||||
|
char buf[4] = { 0, };
|
||||||
|
buf[0] = instr[i];
|
||||||
|
buf[1] = instr[i+1];
|
||||||
|
char b = strtol(buf, NULL, 16);
|
||||||
|
if (b) { // If high byte is non-zero, we can't handle it ;(
|
||||||
|
b = '?';
|
||||||
|
} else {
|
||||||
|
buf[0] = instr[i+2];
|
||||||
|
buf[1] = instr[i+3];
|
||||||
|
b = strtol(buf, NULL, 16);
|
||||||
|
}
|
||||||
|
result += b;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
|
Reference in New Issue
Block a user