Simple detection for LE910-NA1 modules

Fork of MTS-Cellular by MultiTech

Committer:
Mike Fiore
Date:
Tue May 20 15:21:06 2014 -0500
Revision:
3:04046eebaef5
Parent:
1:f155d94d6f3a
Child:
4:1f63354b8d1b
rename SMC and SMCIP files to EasyIP and UIP, remove RadioInterface code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 1:f155d94d6f3a 1 #include "Cellular.h"
Mike Fiore 1:f155d94d6f3a 2 #include "MTSText.h"
Mike Fiore 1:f155d94d6f3a 3
Mike Fiore 1:f155d94d6f3a 4 using namespace mts;
Mike Fiore 1:f155d94d6f3a 5
Mike Fiore 1:f155d94d6f3a 6 std::string Cellular::getRegistrationNames(Registration registration)
Mike Fiore 1:f155d94d6f3a 7 {
Mike Fiore 1:f155d94d6f3a 8 switch(registration) {
Mike Fiore 1:f155d94d6f3a 9 case NOT_REGISTERED:
Mike Fiore 1:f155d94d6f3a 10 return "NOT_REGISTERED";
Mike Fiore 1:f155d94d6f3a 11 case REGISTERED:
Mike Fiore 1:f155d94d6f3a 12 return "REGISTERED";
Mike Fiore 1:f155d94d6f3a 13 case SEARCHING:
Mike Fiore 1:f155d94d6f3a 14 return "SEARCHING";
Mike Fiore 1:f155d94d6f3a 15 case DENIED:
Mike Fiore 1:f155d94d6f3a 16 return "DENIED";
Mike Fiore 1:f155d94d6f3a 17 case UNKNOWN:
Mike Fiore 1:f155d94d6f3a 18 return "UNKNOWN";
Mike Fiore 1:f155d94d6f3a 19 case ROAMING:
Mike Fiore 1:f155d94d6f3a 20 return "ROAMING";
Mike Fiore 1:f155d94d6f3a 21 default:
Mike Fiore 1:f155d94d6f3a 22 return "UNKNOWN ENUM";
Mike Fiore 1:f155d94d6f3a 23 }
Mike Fiore 1:f155d94d6f3a 24 }
Mike Fiore 1:f155d94d6f3a 25
Mike Fiore 1:f155d94d6f3a 26 Code Cellular::test()
Mike Fiore 1:f155d94d6f3a 27 {
Mike Fiore 1:f155d94d6f3a 28 int i = 0;
Mike Fiore 1:f155d94d6f3a 29 while (sendBasicCommand("AT", 1000) != SUCCESS) {
Mike Fiore 1:f155d94d6f3a 30 i++;
Mike Fiore 1:f155d94d6f3a 31 if (i >= 30) {
Mike Fiore 1:f155d94d6f3a 32 printf("[ERROR] Could not talk to radio after 30 tries\r\n");
Mike Fiore 1:f155d94d6f3a 33 i = 0;
Mike Fiore 1:f155d94d6f3a 34 }
Mike Fiore 1:f155d94d6f3a 35 wait(1);
Mike Fiore 1:f155d94d6f3a 36 }
Mike Fiore 1:f155d94d6f3a 37 return SUCCESS;
Mike Fiore 1:f155d94d6f3a 38 }
Mike Fiore 1:f155d94d6f3a 39
Mike Fiore 1:f155d94d6f3a 40 int Cellular::getSignalStrength()
Mike Fiore 1:f155d94d6f3a 41 {
Mike Fiore 1:f155d94d6f3a 42 string response = sendCommand("AT+CSQ", 1000);
Mike Fiore 1:f155d94d6f3a 43 if (response.find("OK") == string::npos) {
Mike Fiore 1:f155d94d6f3a 44 return -1;
Mike Fiore 1:f155d94d6f3a 45 }
Mike Fiore 1:f155d94d6f3a 46 int start = response.find(':');
Mike Fiore 1:f155d94d6f3a 47 int stop = response.find(',', start);
Mike Fiore 1:f155d94d6f3a 48 string signal = response.substr(start + 2, stop - start - 2);
Mike Fiore 1:f155d94d6f3a 49 int value;
Mike Fiore 1:f155d94d6f3a 50 sscanf(signal.c_str(), "%d", &value);
Mike Fiore 1:f155d94d6f3a 51 return value;
Mike Fiore 1:f155d94d6f3a 52 }
Mike Fiore 1:f155d94d6f3a 53
Mike Fiore 1:f155d94d6f3a 54 Cellular::Registration Cellular::getRegistration()
Mike Fiore 1:f155d94d6f3a 55 {
Mike Fiore 1:f155d94d6f3a 56 string response = sendCommand("AT+CREG?", 5000);
Mike Fiore 1:f155d94d6f3a 57 if (response.find("OK") == string::npos) {
Mike Fiore 1:f155d94d6f3a 58 return UNKNOWN;
Mike Fiore 1:f155d94d6f3a 59 }
Mike Fiore 1:f155d94d6f3a 60 int start = response.find(',');
Mike Fiore 1:f155d94d6f3a 61 int stop = response.find(' ', start);
Mike Fiore 1:f155d94d6f3a 62 string regStat = response.substr(start + 1, stop - start - 1);
Mike Fiore 1:f155d94d6f3a 63 int value;
Mike Fiore 1:f155d94d6f3a 64 sscanf(regStat.c_str(), "%d", &value);
Mike Fiore 1:f155d94d6f3a 65 switch (value) {
Mike Fiore 1:f155d94d6f3a 66 case 0:
Mike Fiore 1:f155d94d6f3a 67 return NOT_REGISTERED;
Mike Fiore 1:f155d94d6f3a 68 case 1:
Mike Fiore 1:f155d94d6f3a 69 return REGISTERED;
Mike Fiore 1:f155d94d6f3a 70 case 2:
Mike Fiore 1:f155d94d6f3a 71 return SEARCHING;
Mike Fiore 1:f155d94d6f3a 72 case 3:
Mike Fiore 1:f155d94d6f3a 73 return DENIED;
Mike Fiore 1:f155d94d6f3a 74 case 4:
Mike Fiore 1:f155d94d6f3a 75 return UNKNOWN;
Mike Fiore 1:f155d94d6f3a 76 case 5:
Mike Fiore 1:f155d94d6f3a 77 return ROAMING;
Mike Fiore 1:f155d94d6f3a 78 }
Mike Fiore 1:f155d94d6f3a 79 return UNKNOWN;
Mike Fiore 1:f155d94d6f3a 80 }