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

cellular/Cellular.h

Committer:
sgodinez
Date:
2013-12-16
Revision:
19:38794784e009
Parent:
17:2d7c4ea7491b
Child:
23:bc6f98a1eb22

File content as of revision 19:38794784e009:

#ifndef CELLULAR_H
#define CELLULAR_H

#include "IPStack.h"
#include "MTSBufferedIO.h"
#include "mbed.h"
#include <string>
#include <vector>

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);

    Code test();
    Code echoOff(bool state);
    int getSignalStrength();
    std::string getPhoneNumber();
    Registration getRegistration();
    Code setApn(const std::string& apn);
    Code setDns(const std::string& apn);
    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;

    MTSBufferedIO* io;
    bool echoMode;
    
    bool pppConnected;
    std::string apn;
    
    Mode mode;
    bool socketOpened;
    bool socketCloseable;
    unsigned int local_port;
    std::string local_address;
    unsigned int host_port;
    std::string host_address;

    Cellular();
    Cellular(MTSBufferedIO* io);
    
};

#endif /* CELLULAR_H */