Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MTS-Cellular by
Cellular/Cellular.cpp
- Committer:
- Mike Fiore
- Date:
- 2014-05-20
- Revision:
- 3:04046eebaef5
- Parent:
- 1:f155d94d6f3a
- Child:
- 4:1f63354b8d1b
File content as of revision 3:04046eebaef5:
#include "Cellular.h" #include "MTSText.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) { printf("[ERROR] Could not talk to radio after 30 tries\r\n"); 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; }