Cellular library for MTS Socket Modem Arduino Shield devices from Multi-Tech Systems
Dependents: mtsas mtsas mtsas mtsas
Cellular/Cellular.cpp
- Committer:
- Mike Fiore
- Date:
- 2014-05-20
- Revision:
- 4:1f63354b8d1b
- Parent:
- 3:04046eebaef5
- Child:
- 7:0ee8e69a3e9c
File content as of revision 4:1f63354b8d1b:
#include "mbed.h" #include "Cellular.h" #include "MTSText.h" #include "MTSLog.h" using namespace mts; std::string Cellular::getRegistrationNames(Registration registration) { switch(registration) { case NOT_REGISTERED: return "NOT_REGISTERED"; case REGISTERED: return "REGISTERED"; case SEARCHING: return "SEARCHING"; case DENIED: return "DENIED"; case UNKNOWN: return "UNKNOWN"; case ROAMING: return "ROAMING"; default: return "UNKNOWN ENUM"; } } Code Cellular::test() { int i = 0; while (sendBasicCommand("AT", 1000) != SUCCESS) { i++; if (i >= 30) { logError("Could not talk to radio after 30 tries"); i = 0; } wait(1); } return SUCCESS; } int Cellular::getSignalStrength() { string response = sendCommand("AT+CSQ", 1000); if (response.find("OK") == string::npos) { return -1; } int start = response.find(':'); int stop = response.find(',', start); string signal = response.substr(start + 2, stop - start - 2); int value; sscanf(signal.c_str(), "%d", &value); return value; } Cellular::Registration Cellular::getRegistration() { string response = sendCommand("AT+CREG?", 5000); if (response.find("OK") == string::npos) { return UNKNOWN; } int start = response.find(','); int stop = response.find(' ', start); string regStat = response.substr(start + 1, stop - start - 1); int value; sscanf(regStat.c_str(), "%d", &value); switch (value) { case 0: return NOT_REGISTERED; case 1: return REGISTERED; case 2: return SEARCHING; case 3: return DENIED; case 4: return UNKNOWN; case 5: return ROAMING; } return UNKNOWN; }