Added extra responses for AI for XBee

This commit is contained in:
Sara Damiano
2018-09-19 09:44:46 -04:00
parent 837a189806
commit 2423b9fdf2
5 changed files with 23 additions and 19 deletions

View File

@@ -229,10 +229,7 @@ public:
if (ret_val) guardTime = 125; if (ret_val) guardTime = 125;
sendAT(GF("HS")); // Get the "Hardware Series"; sendAT(GF("HS")); // Get the "Hardware Series";
String res = readResponse(); int intRes = readResponseInt();
char buf[4] = {0,}; // Set up buffer for response
res.toCharArray(buf, 4);
int intRes = strtol(buf, 0, 16);
beeType = (XBeeType)intRes; beeType = (XBeeType)intRes;
exitCommand(); exitCommand();
@@ -299,7 +296,7 @@ public:
if (!commandMode()) return modemInf; // Try up to 10 times for the init if (!commandMode()) return modemInf; // Try up to 10 times for the init
sendAT(GF("HS")); // Get the "Hardware Series" sendAT(GF("HS")); // Get the "Hardware Series"
modemInf += readResponse(); modemInf += readResponseString();
exitCommand(); exitCommand();
return modemInf; return modemInf;
@@ -402,7 +399,7 @@ public:
String getSimCCID() { String getSimCCID() {
if (!commandMode()) return ""; // Return immediately if (!commandMode()) return ""; // Return immediately
sendAT(GF("S#")); sendAT(GF("S#"));
String res = readResponse(); String res = readResponseString();
exitCommand(); exitCommand();
return res; return res;
} }
@@ -410,7 +407,7 @@ public:
String getIMEI() { String getIMEI() {
if (!commandMode()) return ""; // Return immediately if (!commandMode()) return ""; // Return immediately
sendAT(GF("IM")); sendAT(GF("IM"));
String res = readResponse(); String res = readResponseString();
exitCommand(); exitCommand();
return res; return res;
} }
@@ -423,10 +420,7 @@ public:
if (!commandMode()) return REG_UNKNOWN; // Return immediately if (!commandMode()) return REG_UNKNOWN; // Return immediately
sendAT(GF("AI")); sendAT(GF("AI"));
String res = readResponse(); int intRes = readResponseInt();
char buf[3] = {0,}; // Set up buffer for response
res.toCharArray(buf, 3);
int intRes = strtol(buf, 0, 16);
RegStatus stat = REG_UNKNOWN; RegStatus stat = REG_UNKNOWN;
switch (beeType){ switch (beeType){
@@ -475,13 +469,18 @@ public:
writeChanges(); writeChanges();
stat = REG_UNKNOWN; stat = REG_UNKNOWN;
} }
else if(intRes == 0x2B) { // 0x2B USB Direct active.
stat = REG_UNKNOWN;
}
else if(intRes == 0x2C) // 0x2C Cellular component is in PSM (power save mode).
stat = REG_UNKNOWN;
else if(intRes == 0x2F) { // 0x2F Bypass mode active. else if(intRes == 0x2F) { // 0x2F Bypass mode active.
sendAT(GF("AP0")); // Set back to transparent mode sendAT(GF("AP0")); // Set back to transparent mode
waitResponse(); waitResponse();
writeChanges(); writeChanges();
stat = REG_UNKNOWN; stat = REG_UNKNOWN;
} }
else if(intRes == 0xFF) // 0xFF Device is currently scanning for the configured SSID. else if(intRes == 0xFF) // 0xFF Initializing.
stat = REG_SEARCHING; stat = REG_SEARCHING;
else stat = REG_UNKNOWN; else stat = REG_UNKNOWN;
break; break;
@@ -495,7 +494,7 @@ public:
String getOperator() { String getOperator() {
if (!commandMode()) return ""; // Return immediately if (!commandMode()) return ""; // Return immediately
sendAT(GF("MN")); sendAT(GF("MN"));
String res = readResponse(); String res = readResponseString();
exitCommand(); exitCommand();
return res; return res;
} }
@@ -508,11 +507,8 @@ public:
if (!commandMode()) return 0; // Return immediately if (!commandMode()) return 0; // Return immediately
if (beeType == XBEE_S6B_WIFI) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity if (beeType == XBEE_S6B_WIFI) sendAT(GF("LM")); // ask for the "link margin" - the dB above sensitivity
else sendAT(GF("DB")); // ask for the cell strength in dBm else sendAT(GF("DB")); // ask for the cell strength in dBm
String res = readResponse(); // it works better if we read in as a string int intRes = readResponseInt();
exitCommand(); exitCommand();
char buf[3] = {0,}; // Set up buffer for response
res.toCharArray(buf, 3);
int intRes = strtol(buf, 0, 16);
if (beeType == XBEE_S6B_WIFI) return -93 + intRes; // the maximum sensitivity is -93dBm if (beeType == XBEE_S6B_WIFI) return -93 + intRes; // the maximum sensitivity is -93dBm
else return -1*intRes; // need to convert to negative number else return -1*intRes; // need to convert to negative number
} }
@@ -576,7 +572,7 @@ fail:
sendAT(GF("MY")); sendAT(GF("MY"));
String IPaddr; IPaddr.reserve(16); String IPaddr; IPaddr.reserve(16);
// wait for the response - this response can be very slow // wait for the response - this response can be very slow
IPaddr = readResponse(30000); IPaddr = readResponseString(30000);
exitCommand(); exitCommand();
IPaddr.trim(); IPaddr.trim();
return IPaddr; return IPaddr;
@@ -840,7 +836,7 @@ finish:
waitResponse(); waitResponse();
} }
String readResponse(uint32_t timeout = 1000) { String readResponseString(uint32_t timeout = 1000) {
TINY_GSM_YIELD(); TINY_GSM_YIELD();
unsigned long startMillis = millis(); unsigned long startMillis = millis();
while (!stream.available() && millis() - startMillis < timeout) {}; while (!stream.available() && millis() - startMillis < timeout) {};
@@ -850,6 +846,14 @@ finish:
return res; return res;
} }
int readResponseInt(uint32_t timeout = 1000) {
String res = readResponseString(timeout);
char buf[3] = {0,}; // Set up buffer for response
res.toCharArray(buf, 3);
int intRes = strtol(buf, 0, 16);
return intRes;
}
public: public:
Stream& stream; Stream& stream;