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:
mfiore
Date:
Wed Dec 18 16:04:57 2013 +0000
Revision:
29:7408b1bdad37
Parent:
23:bc6f98a1eb22
Child:
30:06c756af6c5c
add cellular->reset() function (may need to be changed to HW reset); fixed bug in Endpoint code; added correct handling of DCD and DTR lines to/from radio

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
mfiore 29:7408b1bdad37 55 /** A method to reset the Multi-Tech Socket Modem. This command brings down the
mfiore 29:7408b1bdad37 56 * PPP link if it is up. After this function is called, at least 30 seconds should
mfiore 29:7408b1bdad37 57 * be allowed for the cellular radio to come back up before any other Cellular
mfiore 29:7408b1bdad37 58 * functions are called.
mfiore 29:7408b1bdad37 59 */
mfiore 29:7408b1bdad37 60 /** this needs to be investigated. After we tell the radio to reset and wait 30 seconds,
mfiore 29:7408b1bdad37 61 * we can't seem to get it to respond to even a simple signal strength query.
mfiore 29:7408b1bdad37 62 */
sgodinez 11:134435d8a2d5 63 virtual void reset();
sgodinez 11:134435d8a2d5 64
sgodinez 11:134435d8a2d5 65 //Cellular Radio Specific
sgodinez 11:134435d8a2d5 66 std::string sendCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR);
sgodinez 11:134435d8a2d5 67 Code sendBasicCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR);
sgodinez 11:134435d8a2d5 68
jengbrecht 23:bc6f98a1eb22 69 /** A method for testing command access to the radio. This method sends the
jengbrecht 23:bc6f98a1eb22 70 * command "AT" to the radio, which is a standard radio test to see if you
jengbrecht 23:bc6f98a1eb22 71 * have command access to the radio.
jengbrecht 23:bc6f98a1eb22 72 *
jengbrecht 23:bc6f98a1eb22 73 * @returns the standard AT Code enumeration.
jengbrecht 23:bc6f98a1eb22 74 */
sgodinez 11:134435d8a2d5 75 Code test();
jengbrecht 23:bc6f98a1eb22 76
jengbrecht 23:bc6f98a1eb22 77 /** A method for configuring command ehco capability on the radio. This command
jengbrecht 23:bc6f98a1eb22 78 * sets whether sent characters are echoed back from the radio, in which case you
jengbrecht 23:bc6f98a1eb22 79 * will receive back every command you send.
jengbrecht 23:bc6f98a1eb22 80 *
jengbrecht 23:bc6f98a1eb22 81 * @param state if true echo will be turned off, otherwise it will be turned on.
jengbrecht 23:bc6f98a1eb22 82 * @returns the standard AT Code enumeration.
jengbrecht 23:bc6f98a1eb22 83 */
mfiore 29:7408b1bdad37 84 Code echo(bool state);
jengbrecht 23:bc6f98a1eb22 85
jengbrecht 23:bc6f98a1eb22 86 /** A method for getting the signal strength of the radio. This method allows you to
jengbrecht 23:bc6f98a1eb22 87 * get a value that maps to signal strength in dBm. Here 0-1 is Poor, 2-9 is Marginal,
jengbrecht 23:bc6f98a1eb22 88 * 10-14 is Ok, 15-19 is Good, and 20+ is Excellent. If you get a result of 99 the
jengbrecht 23:bc6f98a1eb22 89 * signal strength is not known or not detectable.
jengbrecht 23:bc6f98a1eb22 90 *
jengbrecht 23:bc6f98a1eb22 91 * @returns an integer representing the signal strength.
jengbrecht 23:bc6f98a1eb22 92 */
jengbrecht 0:563b70517320 93 int getSignalStrength();
sgodinez 5:93e889a5abc6 94 std::string getPhoneNumber();
sgodinez 5:93e889a5abc6 95 Registration getRegistration();
sgodinez 11:134435d8a2d5 96 Code setApn(const std::string& apn);
sgodinez 11:134435d8a2d5 97 Code setDns(const std::string& apn);
jengbrecht 23:bc6f98a1eb22 98 bool ping(const std::string& address = "8.8.8.8");
sgodinez 17:2d7c4ea7491b 99 Code setSocketCloseable(bool enabled = true); //ETX closes socket (ETX and DLE in payload are escaped with DLE)
sgodinez 4:6561c9128c6f 100
sgodinez 4:6561c9128c6f 101 //SMS
sgodinez 4:6561c9128c6f 102 Code sendSMS(const std::string& phoneNumber, const std::string& message);
sgodinez 4:6561c9128c6f 103 Code sendSMS(const Sms& sms);
sgodinez 4:6561c9128c6f 104 std::vector<Cellular::Sms> getReceivedSms();
sgodinez 4:6561c9128c6f 105 Code deleteAllReceivedSms();
sgodinez 4:6561c9128c6f 106 Code deleteOnlyReceivedReadSms();
sgodinez 19:38794784e009 107
sgodinez 13:0af863114629 108
jengbrecht 0:563b70517320 109 private:
jengbrecht 23:bc6f98a1eb22 110 static Cellular* instance; //Static pointer to the single Cellular object.
sgodinez 19:38794784e009 111
jengbrecht 23:bc6f98a1eb22 112 MTSBufferedIO* io; //IO interface obect that the radio is accessed through.
jengbrecht 23:bc6f98a1eb22 113 bool echoMode; //Specifies if the echo mode is currently enabled.
sgodinez 11:134435d8a2d5 114
jengbrecht 23:bc6f98a1eb22 115 bool pppConnected; //Specifies if a PPP session is currently connected.
jengbrecht 23:bc6f98a1eb22 116 std::string apn; //A string that holds the APN for the radio.
sgodinez 11:134435d8a2d5 117
jengbrecht 23:bc6f98a1eb22 118 Mode mode;
jengbrecht 23:bc6f98a1eb22 119 bool socketOpened; //Specifies if a Socket is presently opened.
jengbrecht 23:bc6f98a1eb22 120 bool socketCloseable; //Specifies is a Socket can be closed.
jengbrecht 23:bc6f98a1eb22 121 unsigned int local_port;
sgodinez 13:0af863114629 122 std::string local_address;
sgodinez 11:134435d8a2d5 123 unsigned int host_port;
sgodinez 11:134435d8a2d5 124 std::string host_address;
mfiore 29:7408b1bdad37 125 DigitalIn* dcd;
mfiore 29:7408b1bdad37 126 DigitalOut* dtr;
sgodinez 11:134435d8a2d5 127
jengbrecht 23:bc6f98a1eb22 128 Cellular(); //Private constructor, use the getInstance() method.
mfiore 29:7408b1bdad37 129 Cellular(MTSBufferedIO* io); //Private constructor, use the getInstance() method.
sgodinez 11:134435d8a2d5 130
jengbrecht 0:563b70517320 131 };
jengbrecht 0:563b70517320 132
jengbrecht 0:563b70517320 133 #endif /* CELLULAR_H */