A library for talking to Multi-Tech's Cellular SocketModem Devices.

Dependents:   M2X_dev axeda_wrapper_dev MTS_M2x_Example1 MTS_Cellular_Connect_Example ... more

Committer:
jengbrecht
Date:
Tue Dec 17 18:49:06 2013 +0000
Revision:
23:bc6f98a1eb22
Parent:
19:38794784e009
Child:
27:8e6188cbcfd4
Child:
29:7408b1bdad37
Added Ping Command and some documentation to Cellular.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jengbrecht 0:563b70517320 1 #ifndef CELLULAR_H
jengbrecht 0:563b70517320 2 #define CELLULAR_H
jengbrecht 0:563b70517320 3
sgodinez 11:134435d8a2d5 4 #include "IPStack.h"
sgodinez 11:134435d8a2d5 5 #include "MTSBufferedIO.h"
jengbrecht 0:563b70517320 6 #include "mbed.h"
jengbrecht 0:563b70517320 7 #include <string>
sgodinez 4:6561c9128c6f 8 #include <vector>
jengbrecht 0:563b70517320 9
jengbrecht 23:bc6f98a1eb22 10 #define PINGDELAY 3
jengbrecht 23:bc6f98a1eb22 11 #define PINGNUM 4
jengbrecht 23:bc6f98a1eb22 12
sgodinez 11:134435d8a2d5 13 class Cellular : virtual IPStack
jengbrecht 0:563b70517320 14 {
jengbrecht 0:563b70517320 15 public:
jengbrecht 0:563b70517320 16 enum Code {
jengbrecht 0:563b70517320 17 OK, ERROR, NO_RESPONSE, FAILURE
jengbrecht 0:563b70517320 18 };
jengbrecht 0:563b70517320 19
jengbrecht 0:563b70517320 20 enum ESC_CHAR {
sgodinez 13:0af863114629 21 CR, CTRL_Z, NONE
jengbrecht 0:563b70517320 22 };
jengbrecht 0:563b70517320 23
jengbrecht 0:563b70517320 24 enum Registration {
jengbrecht 0:563b70517320 25 NOT_REGISTERED, REGISTERED, SEARCHING, DENIED, UNKNOWN, ROAMING
jengbrecht 0:563b70517320 26 };
jengbrecht 0:563b70517320 27
sgodinez 4:6561c9128c6f 28 struct Sms {
sgodinez 4:6561c9128c6f 29 std::string phoneNumber;
sgodinez 4:6561c9128c6f 30 std::string message;
sgodinez 4:6561c9128c6f 31 std::string timestamp;
sgodinez 4:6561c9128c6f 32 };
sgodinez 4:6561c9128c6f 33
sgodinez 4:6561c9128c6f 34
jengbrecht 0:563b70517320 35 ~Cellular();
sgodinez 19:38794784e009 36
sgodinez 19:38794784e009 37 static Cellular* getInstance();
sgodinez 19:38794784e009 38 static Cellular* getInstance(MTSBufferedIO* io);
jengbrecht 0:563b70517320 39
sgodinez 11:134435d8a2d5 40 virtual bool connect(); // Parameters for this function will vary between devices!!!
sgodinez 11:134435d8a2d5 41 virtual void disconnect();
sgodinez 11:134435d8a2d5 42 virtual bool isConnected();
jengbrecht 0:563b70517320 43
sgodinez 11:134435d8a2d5 44 // Used for TCPSocketConnection & UDPSocketConnection
sgodinez 11:134435d8a2d5 45 virtual bool bind(unsigned int port);
sgodinez 11:134435d8a2d5 46 virtual bool open(const std::string& address, unsigned int port, Mode mode);
sgodinez 11:134435d8a2d5 47 virtual bool isOpen();
sgodinez 17:2d7c4ea7491b 48 virtual bool close();
sgodinez 11:134435d8a2d5 49 virtual int read(char* data, int max, int timeout = -1);
sgodinez 11:134435d8a2d5 50 virtual int write(char* data, int length, int timeout = -1);
sgodinez 11:134435d8a2d5 51 virtual unsigned int readable();
sgodinez 11:134435d8a2d5 52 virtual unsigned int writeable();
sgodinez 11:134435d8a2d5 53
sgodinez 11:134435d8a2d5 54 //Other
sgodinez 11:134435d8a2d5 55 virtual void reset();
sgodinez 11:134435d8a2d5 56
sgodinez 11:134435d8a2d5 57 //Cellular Radio Specific
sgodinez 11:134435d8a2d5 58 std::string sendCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR);
sgodinez 11:134435d8a2d5 59 Code sendBasicCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR);
sgodinez 11:134435d8a2d5 60
jengbrecht 23:bc6f98a1eb22 61 /** A method for testing command access to the radio. This method sends the
jengbrecht 23:bc6f98a1eb22 62 * command "AT" to the radio, which is a standard radio test to see if you
jengbrecht 23:bc6f98a1eb22 63 * have command access to the radio.
jengbrecht 23:bc6f98a1eb22 64 *
jengbrecht 23:bc6f98a1eb22 65 * @returns the standard AT Code enumeration.
jengbrecht 23:bc6f98a1eb22 66 */
sgodinez 11:134435d8a2d5 67 Code test();
jengbrecht 23:bc6f98a1eb22 68
jengbrecht 23:bc6f98a1eb22 69 /** A method for configuring command ehco capability on the radio. This command
jengbrecht 23:bc6f98a1eb22 70 * sets whether sent characters are echoed back from the radio, in which case you
jengbrecht 23:bc6f98a1eb22 71 * will receive back every command you send.
jengbrecht 23:bc6f98a1eb22 72 *
jengbrecht 23:bc6f98a1eb22 73 * @param state if true echo will be turned off, otherwise it will be turned on.
jengbrecht 23:bc6f98a1eb22 74 * @returns the standard AT Code enumeration.
jengbrecht 23:bc6f98a1eb22 75 */
jengbrecht 0:563b70517320 76 Code echoOff(bool state);
jengbrecht 23:bc6f98a1eb22 77
jengbrecht 23:bc6f98a1eb22 78 /** A method for getting the signal strength of the radio. This method allows you to
jengbrecht 23:bc6f98a1eb22 79 * get a value that maps to signal strength in dBm. Here 0-1 is Poor, 2-9 is Marginal,
jengbrecht 23:bc6f98a1eb22 80 * 10-14 is Ok, 15-19 is Good, and 20+ is Excellent. If you get a result of 99 the
jengbrecht 23:bc6f98a1eb22 81 * signal strength is not known or not detectable.
jengbrecht 23:bc6f98a1eb22 82 *
jengbrecht 23:bc6f98a1eb22 83 * @returns an integer representing the signal strength.
jengbrecht 23:bc6f98a1eb22 84 */
jengbrecht 0:563b70517320 85 int getSignalStrength();
sgodinez 5:93e889a5abc6 86 std::string getPhoneNumber();
sgodinez 5:93e889a5abc6 87 Registration getRegistration();
sgodinez 11:134435d8a2d5 88 Code setApn(const std::string& apn);
sgodinez 11:134435d8a2d5 89 Code setDns(const std::string& apn);
jengbrecht 23:bc6f98a1eb22 90 bool ping(const std::string& address = "8.8.8.8");
sgodinez 17:2d7c4ea7491b 91 Code setSocketCloseable(bool enabled = true); //ETX closes socket (ETX and DLE in payload are escaped with DLE)
sgodinez 4:6561c9128c6f 92
sgodinez 4:6561c9128c6f 93 //SMS
sgodinez 4:6561c9128c6f 94 Code sendSMS(const std::string& phoneNumber, const std::string& message);
sgodinez 4:6561c9128c6f 95 Code sendSMS(const Sms& sms);
sgodinez 4:6561c9128c6f 96 std::vector<Cellular::Sms> getReceivedSms();
sgodinez 4:6561c9128c6f 97 Code deleteAllReceivedSms();
sgodinez 4:6561c9128c6f 98 Code deleteOnlyReceivedReadSms();
sgodinez 19:38794784e009 99
sgodinez 13:0af863114629 100
jengbrecht 0:563b70517320 101 private:
jengbrecht 23:bc6f98a1eb22 102 static Cellular* instance; //Static pointer to the single Cellular object.
sgodinez 19:38794784e009 103
jengbrecht 23:bc6f98a1eb22 104 MTSBufferedIO* io; //IO interface obect that the radio is accessed through.
jengbrecht 23:bc6f98a1eb22 105 bool echoMode; //Specifies if the echo mode is currently enabled.
sgodinez 11:134435d8a2d5 106
jengbrecht 23:bc6f98a1eb22 107 bool pppConnected; //Specifies if a PPP session is currently connected.
jengbrecht 23:bc6f98a1eb22 108 std::string apn; //A string that holds the APN for the radio.
sgodinez 11:134435d8a2d5 109
jengbrecht 23:bc6f98a1eb22 110 Mode mode;
jengbrecht 23:bc6f98a1eb22 111 bool socketOpened; //Specifies if a Socket is presently opened.
jengbrecht 23:bc6f98a1eb22 112 bool socketCloseable; //Specifies is a Socket can be closed.
jengbrecht 23:bc6f98a1eb22 113 unsigned int local_port;
sgodinez 13:0af863114629 114 std::string local_address;
sgodinez 11:134435d8a2d5 115 unsigned int host_port;
sgodinez 11:134435d8a2d5 116 std::string host_address;
sgodinez 11:134435d8a2d5 117
jengbrecht 23:bc6f98a1eb22 118 Cellular(); //Private constructor, use the getInstance() method.
jengbrecht 23:bc6f98a1eb22 119 Cellular(MTSBufferedIO* io); //Private constructor, use the getInstance method.
sgodinez 11:134435d8a2d5 120
jengbrecht 0:563b70517320 121 };
jengbrecht 0:563b70517320 122
jengbrecht 0:563b70517320 123 #endif /* CELLULAR_H */