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.
Dependents: M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more
cellular/Cellular.h
- Committer:
- jengbrecht
- Date:
- 2013-12-17
- Revision:
- 23:bc6f98a1eb22
- Parent:
- 19:38794784e009
- Child:
- 27:8e6188cbcfd4
- Child:
- 29:7408b1bdad37
File content as of revision 23:bc6f98a1eb22:
#ifndef CELLULAR_H
#define CELLULAR_H
#include "IPStack.h"
#include "MTSBufferedIO.h"
#include "mbed.h"
#include <string>
#include <vector>
#define PINGDELAY 3
#define PINGNUM 4
class Cellular : virtual IPStack
{
public:
enum Code {
OK, ERROR, NO_RESPONSE, FAILURE
};
enum ESC_CHAR {
CR, CTRL_Z, NONE
};
enum Registration {
NOT_REGISTERED, REGISTERED, SEARCHING, DENIED, UNKNOWN, ROAMING
};
struct Sms {
std::string phoneNumber;
std::string message;
std::string timestamp;
};
~Cellular();
static Cellular* getInstance();
static Cellular* getInstance(MTSBufferedIO* io);
virtual bool connect(); // Parameters for this function will vary between devices!!!
virtual void disconnect();
virtual bool isConnected();
// Used for TCPSocketConnection & UDPSocketConnection
virtual bool bind(unsigned int port);
virtual bool open(const std::string& address, unsigned int port, Mode mode);
virtual bool isOpen();
virtual bool close();
virtual int read(char* data, int max, int timeout = -1);
virtual int write(char* data, int length, int timeout = -1);
virtual unsigned int readable();
virtual unsigned int writeable();
//Other
virtual void reset();
//Cellular Radio Specific
std::string sendCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR);
Code sendBasicCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR);
/** A method for testing command access to the radio. This method sends the
* command "AT" to the radio, which is a standard radio test to see if you
* have command access to the radio.
*
* @returns the standard AT Code enumeration.
*/
Code test();
/** A method for configuring command ehco capability on the radio. This command
* sets whether sent characters are echoed back from the radio, in which case you
* will receive back every command you send.
*
* @param state if true echo will be turned off, otherwise it will be turned on.
* @returns the standard AT Code enumeration.
*/
Code echoOff(bool state);
/** A method for getting the signal strength of the radio. This method allows you to
* get a value that maps to signal strength in dBm. Here 0-1 is Poor, 2-9 is Marginal,
* 10-14 is Ok, 15-19 is Good, and 20+ is Excellent. If you get a result of 99 the
* signal strength is not known or not detectable.
*
* @returns an integer representing the signal strength.
*/
int getSignalStrength();
std::string getPhoneNumber();
Registration getRegistration();
Code setApn(const std::string& apn);
Code setDns(const std::string& apn);
bool ping(const std::string& address = "8.8.8.8");
Code setSocketCloseable(bool enabled = true); //ETX closes socket (ETX and DLE in payload are escaped with DLE)
//SMS
Code sendSMS(const std::string& phoneNumber, const std::string& message);
Code sendSMS(const Sms& sms);
std::vector<Cellular::Sms> getReceivedSms();
Code deleteAllReceivedSms();
Code deleteOnlyReceivedReadSms();
private:
static Cellular* instance; //Static pointer to the single Cellular object.
MTSBufferedIO* io; //IO interface obect that the radio is accessed through.
bool echoMode; //Specifies if the echo mode is currently enabled.
bool pppConnected; //Specifies if a PPP session is currently connected.
std::string apn; //A string that holds the APN for the radio.
Mode mode;
bool socketOpened; //Specifies if a Socket is presently opened.
bool socketCloseable; //Specifies is a Socket can be closed.
unsigned int local_port;
std::string local_address;
unsigned int host_port;
std::string host_address;
Cellular(); //Private constructor, use the getInstance() method.
Cellular(MTSBufferedIO* io); //Private constructor, use the getInstance method.
};
#endif /* CELLULAR_H */
uIP Socket Modem Shield (Outdated - see below)