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:
sgodinez
Date:
Mon Dec 16 23:02:22 2013 +0000
Revision:
19:38794784e009
Parent:
17:2d7c4ea7491b
Child:
23:bc6f98a1eb22
Changed Cellular class to singleton (not thread safe)

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
sgodinez 11:134435d8a2d5 10 class Cellular : virtual IPStack
jengbrecht 0:563b70517320 11 {
jengbrecht 0:563b70517320 12 public:
jengbrecht 0:563b70517320 13 enum Code {
jengbrecht 0:563b70517320 14 OK, ERROR, NO_RESPONSE, FAILURE
jengbrecht 0:563b70517320 15 };
jengbrecht 0:563b70517320 16
jengbrecht 0:563b70517320 17 enum ESC_CHAR {
sgodinez 13:0af863114629 18 CR, CTRL_Z, NONE
jengbrecht 0:563b70517320 19 };
jengbrecht 0:563b70517320 20
jengbrecht 0:563b70517320 21 enum Registration {
jengbrecht 0:563b70517320 22 NOT_REGISTERED, REGISTERED, SEARCHING, DENIED, UNKNOWN, ROAMING
jengbrecht 0:563b70517320 23 };
jengbrecht 0:563b70517320 24
sgodinez 4:6561c9128c6f 25 struct Sms {
sgodinez 4:6561c9128c6f 26 std::string phoneNumber;
sgodinez 4:6561c9128c6f 27 std::string message;
sgodinez 4:6561c9128c6f 28 std::string timestamp;
sgodinez 4:6561c9128c6f 29 };
sgodinez 4:6561c9128c6f 30
sgodinez 4:6561c9128c6f 31
jengbrecht 0:563b70517320 32 ~Cellular();
sgodinez 19:38794784e009 33
sgodinez 19:38794784e009 34 static Cellular* getInstance();
sgodinez 19:38794784e009 35 static Cellular* getInstance(MTSBufferedIO* io);
jengbrecht 0:563b70517320 36
sgodinez 11:134435d8a2d5 37 virtual bool connect(); // Parameters for this function will vary between devices!!!
sgodinez 11:134435d8a2d5 38 virtual void disconnect();
sgodinez 11:134435d8a2d5 39 virtual bool isConnected();
jengbrecht 0:563b70517320 40
sgodinez 11:134435d8a2d5 41 // Used for TCPSocketConnection & UDPSocketConnection
sgodinez 11:134435d8a2d5 42 virtual bool bind(unsigned int port);
sgodinez 11:134435d8a2d5 43 virtual bool open(const std::string& address, unsigned int port, Mode mode);
sgodinez 11:134435d8a2d5 44 virtual bool isOpen();
sgodinez 17:2d7c4ea7491b 45 virtual bool close();
sgodinez 11:134435d8a2d5 46 virtual int read(char* data, int max, int timeout = -1);
sgodinez 11:134435d8a2d5 47 virtual int write(char* data, int length, int timeout = -1);
sgodinez 11:134435d8a2d5 48 virtual unsigned int readable();
sgodinez 11:134435d8a2d5 49 virtual unsigned int writeable();
sgodinez 11:134435d8a2d5 50
sgodinez 11:134435d8a2d5 51 //Other
sgodinez 11:134435d8a2d5 52 virtual void reset();
sgodinez 11:134435d8a2d5 53
sgodinez 11:134435d8a2d5 54 //Cellular Radio Specific
sgodinez 11:134435d8a2d5 55 std::string sendCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR);
sgodinez 11:134435d8a2d5 56 Code sendBasicCommand(std::string command, int timeoutMillis, ESC_CHAR esc = CR);
sgodinez 11:134435d8a2d5 57
sgodinez 11:134435d8a2d5 58 Code test();
jengbrecht 0:563b70517320 59 Code echoOff(bool state);
jengbrecht 0:563b70517320 60 int getSignalStrength();
sgodinez 5:93e889a5abc6 61 std::string getPhoneNumber();
sgodinez 5:93e889a5abc6 62 Registration getRegistration();
sgodinez 11:134435d8a2d5 63 Code setApn(const std::string& apn);
sgodinez 11:134435d8a2d5 64 Code setDns(const std::string& apn);
sgodinez 17:2d7c4ea7491b 65 Code setSocketCloseable(bool enabled = true); //ETX closes socket (ETX and DLE in payload are escaped with DLE)
sgodinez 4:6561c9128c6f 66
sgodinez 4:6561c9128c6f 67 //SMS
sgodinez 4:6561c9128c6f 68 Code sendSMS(const std::string& phoneNumber, const std::string& message);
sgodinez 4:6561c9128c6f 69 Code sendSMS(const Sms& sms);
sgodinez 4:6561c9128c6f 70 std::vector<Cellular::Sms> getReceivedSms();
sgodinez 4:6561c9128c6f 71 Code deleteAllReceivedSms();
sgodinez 4:6561c9128c6f 72 Code deleteOnlyReceivedReadSms();
sgodinez 19:38794784e009 73
sgodinez 13:0af863114629 74
jengbrecht 0:563b70517320 75 private:
sgodinez 19:38794784e009 76 static Cellular* instance;
sgodinez 19:38794784e009 77
sgodinez 19:38794784e009 78 MTSBufferedIO* io;
sgodinez 13:0af863114629 79 bool echoMode;
sgodinez 11:134435d8a2d5 80
sgodinez 11:134435d8a2d5 81 bool pppConnected;
sgodinez 11:134435d8a2d5 82 std::string apn;
sgodinez 11:134435d8a2d5 83
sgodinez 11:134435d8a2d5 84 Mode mode;
sgodinez 11:134435d8a2d5 85 bool socketOpened;
sgodinez 17:2d7c4ea7491b 86 bool socketCloseable;
sgodinez 11:134435d8a2d5 87 unsigned int local_port;
sgodinez 13:0af863114629 88 std::string local_address;
sgodinez 11:134435d8a2d5 89 unsigned int host_port;
sgodinez 11:134435d8a2d5 90 std::string host_address;
sgodinez 11:134435d8a2d5 91
sgodinez 19:38794784e009 92 Cellular();
sgodinez 19:38794784e009 93 Cellular(MTSBufferedIO* io);
sgodinez 11:134435d8a2d5 94
jengbrecht 0:563b70517320 95 };
jengbrecht 0:563b70517320 96
jengbrecht 0:563b70517320 97 #endif /* CELLULAR_H */