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 20:00:20 2013 +0000
Revision:
17:2d7c4ea7491b
Parent:
13:0af863114629
Child:
19:38794784e009
TCP send / receive working.  close() still requires some finesse when other end disconnects.

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